sbAlbumArtService.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2010 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
27 #ifndef __SB_ALBUMARTSERVICE_H__
28 #define __SB_ALBUMARTSERVICE_H__
29 
30 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 //
33 // Songbird album art service.
34 //
35 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
37 
43 //------------------------------------------------------------------------------
44 //
45 // Songbird album art service imported services.
46 //
47 //------------------------------------------------------------------------------
48 
49 // Songbird imports.
50 #include <sbIAlbumArtFetcher.h>
51 #include <sbIAlbumArtService.h>
52 #include <sbMemoryUtils.h>
53 #include <sbLibraryUtils.h>
54 
55 // Mozilla imports.
56 #include <nsCOMPtr.h>
57 #include <nsIFileStreams.h>
58 #include <nsIIOService.h>
59 #include <nsIMIMEService.h>
60 #include <nsIObserver.h>
61 #include <nsIObserverService.h>
62 #include <nsStringAPI.h>
63 #include <nsStringGlue.h>
64 #include <nsTArray.h>
65 #include <nsInterfaceHashtable.h>
66 #include <nsITimer.h>
67 
68 //------------------------------------------------------------------------------
69 //
70 // Songbird album art service defs.
71 //
72 //------------------------------------------------------------------------------
73 
74 //
75 // Songbird album art service component defs.
76 //
77 
78 #define SB_ALBUMARTSERVICE_CLASSNAME "sbAlbumArtService"
79 #define SB_ALBUMARTSERVICE_CID \
80  /* {8DF4920B-89AC-49A3-8552-D74D313C62B6} */ \
81  { \
82  0x8DF4920B, \
83  0x89AC, \
84  0x49A3, \
85  { 0x85, 0x52, 0xD7, 0x4D, 0x31, 0x3C, 0x62, 0xB6 } \
86  }
87 
88 //------------------------------------------------------------------------------
89 //
90 // Songbird album art service classes.
91 //
92 //------------------------------------------------------------------------------
93 
99  public nsIObserver
100 {
101  //----------------------------------------------------------------------------
102  //
103  // Public interface.
104  //
105  //----------------------------------------------------------------------------
106 
107 public:
108 
109  //
110  // Inherited interfaces.
111  //
112 
114  NS_DECL_SBIALBUMARTSERVICE
115  NS_DECL_NSIOBSERVER
116 
117 
118  //
119  // Public services.
120  //
121 
123 
124  virtual ~sbAlbumArtService();
125 
126  nsresult Initialize();
127 
128 
129  //----------------------------------------------------------------------------
130  //
131  // Private interface.
132  //
133  //----------------------------------------------------------------------------
134 
135 private:
136 
137  //
138  // Fetcher information.
139  //
140  // contractID Album art fetcher contract ID.
141  // fetcher Album art fetcher.
142  // priority Priority of the fetcher (used for sorting).
143  // enabled used to filter our disabled fetchers.
144  //
145 
146  class FetcherInfo
147  {
148  public:
149  nsCString contractID;
150  PRUint32 priority;
151  PRBool enabled;
152  PRBool local;
153 
154  // Defined for the Sort function on nsTArray. Overload "less then" operator
155  // with "<=" to make sure Sort returns the same result when priorities are
156  // the same.
157  PRBool operator<(const FetcherInfo& right) const {
158  return (priority <= right.priority);
159  };
160 
161  // This has to be defined for Sort as well, but is used for Searching.
162  PRBool operator==(const FetcherInfo& right) const {
163  return contractID.Equals(right.contractID);
164  }
165  };
166 
167  //
168  // mIOService I/O service.
169  // mMIMEService MIME service.
170  // mAlbumArtCacheDir Album art cache directory.
171  // mInitialized True if album art service initialized.
172  // mPrefsAvailable True if preferences are available.
173  // mFetcherInfoList List of fetcher information.
174  // mValidExtensionList List of valid album art file extensions.
175  // mTemporaryCache Hash of arbitrary data used by art fetchers
176  // mCacheFlushTimer Timer used to empty the temporary cache
177  //
178 
179  nsCOMPtr<nsIIOService> mIOService;
180  nsCOMPtr<nsIMIMEService> mMIMEService;
181  nsCOMPtr<nsIFile> mAlbumArtCacheDir;
182  PRBool mInitialized;
183  PRBool mPrefsAvailable;
184  nsTArray<FetcherInfo> mFetcherInfoList;
185  nsTArray<nsCString> mValidExtensionList;
186  nsInterfaceHashtable<nsStringHashKey, nsISupports>
187  mTemporaryCache;
188  nsCOMPtr<nsITimer> mCacheFlushTimer;
189 
190  //
191  // Internal services.
192  //
193 
194  //
195  // InitializeLibraryWatch
196  //
197 
198  nsresult InitializeLibraryWatch();
199 
200  void Finalize();
201 
202  nsresult GetAlbumArtCacheDir();
203 
204  nsresult GetAlbumArtFetcherInfo();
205 
206  nsresult UpdateAlbumArtFetcherInfo();
207 
208  nsresult GetCacheFileBaseName(const PRUint8* aData,
209  PRUint32 aDataLen,
210  nsACString& aFileBaseName);
211 
212  nsresult GetAlbumArtFileExtension(const nsACString& aMimeType,
213  nsACString& aFileExtension);
214 
215 };
216 
217 
218 //
219 // Auto-disposal class wrappers.
220 //
221 // sbAutoFileOutputStream Wrapper to auto close an nsIFileOutputStream.
222 //
223 
224 SB_AUTO_CLASS(sbAutoFileOutputStream,
225  nsCOMPtr<nsIFileOutputStream>,
226  mValue,
227  mValue->Close(),
228  mValue = nsnull);
229 
230 #endif // __SB_ALBUMARTSERVICE_H__
231 
bool operator==(sbFraction const &aLeft, sbFraction const &aRight)
Definition: sbFraction.h:166
NS_DECL_ISUPPORTS NS_DECL_SBIALBUMARTSERVICE NS_DECL_NSIOBSERVER sbAlbumArtService()
SB_AUTO_CLASS(sbAutoFileOutputStream, nsCOMPtr< nsIFileOutputStream >, mValue, mValue->Close(), mValue=nsnull)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
function right(ele) rect(ele).right
bool operator<(sbFraction const &aLeft, sbFraction const &aRight)
Definition: sbFraction.h:185
Interface for the album art service. Instantiate as a component service.
_updateTextAndScrollDataForFrame aData