sbiTunesImporter.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2009 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #ifndef SBITUNESIMPORTER_H_
28 #define SBITUNESIMPORTER_H_
29 
30 #include <map>
31 #include <memory>
32 #include <vector>
33 
34 #include <nsDataHashtable.h>
35 #include <nsIRunnable.h>
36 #include <nsStringAPI.h>
37 
38 #include <sbILibraryImporter.h>
39 #include <sbIiTunesXMLParserListener.h>
40 
42 #include "sbiTunesImporterCommon.h"
43 #include "sbiTunesImporterStatus.h"
44 #include "sbiTunesSignature.h"
45 #include "sbiTunesXMLParser.h"
46 
47 // Mozilla forwards
48 class nsIArray;
49 class nsIIOService;
50 class nsIInputStream;
51 
52 // Songbird forwards
54 class sbILibrary;
57 class sbIMediaList;
58 class sbIPropertyArray;
59 #ifdef SB_ENABLE_TEST_HARNESS
60 class sbITimingService;
61 #endif
62 class sbPrefBranch;
63 
64 // Component constants
65 #define SBITUNESIMPORTER_CONTRACTID \
66  "@songbirdnest.com/Songbird/ITunesImporter;1"
67 #define SBITUNESIMPORTER_CLASSNAME \
68  "iTunes Library Importer"
69 // {56202248-E7AB-4e45-BFF3-F296844688C4}
70 #define SBITUNESIMPORTER_CID \
71 { 0x56202248, 0xe7ab, 0x4e45, { 0xbf, 0xf3, 0xf2, 0x96, 0x84, 0x46, 0x88, 0xc4 } }
72 
80 {
81 public:
82  enum OSType {
88  };
89 
91  NS_DECL_SBILIBRARYIMPORTER
92  NS_DECL_SBIITUNESXMLPARSERLISTENER
93 
98 
99 private:
100  virtual ~sbiTunesImporter();
101 
102  struct iTunesTrack;
106  static PRUint32 const BATCH_SIZE = 100;
110  static PRUint32 const DATA_FORMAT_VERSION = 2;
111 
112  // Various nCOMPtr handy typedefs
113  typedef nsCOMPtr<nsIThread> nsIThreadPtr;
114 
115  typedef nsCOMPtr<sbIAlbumArtFetcherSet> sbIAlbumArtFetcherSetPtr;
116  typedef nsCOMPtr<sbIMediacoreTypeSniffer> sbIMediacoreTypeSnifferPtr;
117  typedef nsCOMPtr<nsIInputStream> nsIInputStreamPtr;
118  typedef nsCOMPtr<nsIIOService> nsIIOServicePtr;
119  typedef nsCOMPtr<sbILibraryImporterListener> sbILibraryImporterListenerPtr;
120  typedef nsCOMPtr<sbILibrary> sbILibraryPtr;
121  typedef nsCOMPtr<sbILocalDatabaseLibrary> sbILocalDatabaseLibraryPtr;
122 #ifdef SB_ENABLE_TEST_HARNESS
123  typedef nsCOMPtr<sbITimingService> sbITimingServicePtr;
124 #endif
125  typedef nsRefPtr<sbiTunesXMLParser> sbiTunesXMLParserPtr;
129  typedef std::auto_ptr<sbiTunesImporterStatus> sbiTunesImporterStatusPtr;
133  typedef nsDataHashtable<nsStringHashKey, nsString> StringMap;
134 
138  typedef std::vector<iTunesTrack *> TrackBatch;
143  typedef std::map<nsString, nsString> TrackIDMap;
148  typedef std::map<nsString, PRUint32> TracksByID;
149 
153  struct iTunesTrack {
154  iTunesTrack();
155  ~iTunesTrack();
156  nsresult Initialize(sbIStringMap * aProperties);
157  nsString GetContentType(sbIStringMap *aProperties);
158  nsresult GetPropertyArray(sbIPropertyArray ** aPropertyArray);
159  nsresult GetTrackURI(sbiTunesImporter::OSType aOSType,
160  nsIIOService * aIOService,
161  sbiTunesSignature & aSignanture,
162  nsIURI ** aURI);
163  nsString mTrackID;
164  nsString mSBGuid;
165  StringMap mProperties;
166  nsCOMPtr<nsIURI> mURI;
167  };
168 
172  sbIAlbumArtFetcherSetPtr mAlbumArtFetcher;
176  PRBool mBatchEnded;
180  PRInt32 mDataFormatVersion;
184  PRBool mFoundChanges;
189  PRBool mImport;
193  PRBool mImportPlaylists;
197  nsIIOServicePtr mIOService;
201  nsIInputStreamPtr mStream;
206  sbiTunesDatabaseServices miTunesDBServices;
210  nsString miTunesLibID;
214  sbiTunesSignature miTunesLibSig;
219  sbILocalDatabaseLibraryPtr mLDBLibrary;
223  sbILibraryPtr mLibrary;
227  nsString mLibraryPath;
231  sbILibraryImporterListenerPtr mListener;
235  PRUint32 mMissingMediaCount;
239  OSType mOSType;
243  sbiTunesXMLParserPtr mParser;
247  nsString mPlaylistAction;
251  nsString mPlaylistBlacklist;
255  nsString mSongbirdFolderID;
259  sbiTunesImporterStatusPtr mStatus;
263 #ifdef SB_ENABLE_TEST_HARNESS
264  sbITimingServicePtr mTimingService;
265 #endif
266 
269  nsString mTimingServiceIdentifier;
273  PRUint32 mTrackCount;
277  TrackBatch mTrackBatch;
281  TrackIDMap mTrackIDMap;
285  sbIMediacoreTypeSnifferPtr mTypeSniffer;
289  PRUint32 mUnsupportedMediaCount;
293  PRInt64 mBytesRead;
294 
298  nsresult Cancel();
302  nsresult DBModified(sbPrefBranch & aPrefs,
303  nsAString const & aLibPath,
304  PRBool * aModified);
308  inline
309  static void DestructiTunesTrack(iTunesTrack * aTrack);
313  nsresult GetDirtyPlaylistAction(nsAString const & aPlaylistName,
314  nsAString & aAction);
318  OSType GetOSType();
326  nsresult ImportPlaylist(sbIStringMap *aProperties,
327  PRInt32 *aTrackIds,
328  PRUint32 aTrackIdsCount,
329  sbIMediaList * aMediaList);
335  nsresult ProcessCreatedItems(
336  nsIArray * aCreatedItems,
337  TracksByID const & aTrackMap);
343  nsresult ProcessNewItems(TracksByID & aTrackMap,
344  nsIArray ** aNewItems);
352  nsresult ProcessPlaylistItems(sbIMediaList * aMediaList,
353  PRInt32 * aTrackIds,
354  PRUint32 aTrackIdsCount);
358  nsresult ProcessTrackBatch();
362  nsresult ProcessUpdates();
366  nsresult Run();
372  PRBool ShouldImportPlaylist(sbIStringMap * aProperties);
376  nsresult UpdateProgress();
377 
378 };
379 
380 #endif /* SBITUNESIMPORTER_H_ */
Interface for importing external libraries.
nsCOMPtr< nsIArray > mProperties
A brief description of the contents of this interface.
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
Interface for an album art fetcher set. Instantiate as a component instance.
Media library abstraction.
Definition: sbILibrary.idl:82
An interface for running simple, time based, profiling.
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
nsCOMPtr< sbILibrary > sbILibraryPtr
NS_DECL_ISUPPORTS NS_DECL_SBILIBRARYIMPORTER NS_DECL_SBIITUNESXMLPARSERLISTENER sbiTunesImporter()