sbMediaExportService.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 sbMediaExportService_h_
28 #define sbMediaExportService_h_
29 
30 #include "sbMediaExportDefines.h"
32 #include <sbIShutdownJob.h>
33 #include <sbIJobProgress.h>
34 #include <sbIPropertyArray.h>
35 #include <nsIObserver.h>
36 #include <sbIMediaListListener.h>
37 #include <sbILocalDatabaseSmartMediaList.h>
38 #include <nsIComponentManager.h>
39 #include <nsIGenericFactory.h>
40 #include <nsIFile.h>
41 #include <nsIArray.h>
42 #include <nsCOMPtr.h>
43 #include <nsAutoPtr.h>
44 #include <nsCOMArray.h>
45 #include <nsIClassInfo.h>
46 #include <sbIMediaExportService.h>
47 #include <map>
49 
50 typedef std::map<nsString, sbStringList> sbMediaListItemMap;
51 typedef sbMediaListItemMap::value_type sbMediaListItemMapPair;
52 typedef sbMediaListItemMap::iterator sbMediaListItemMapIter;
53 
54 typedef std::map<nsString, nsString> sbSmartMediaListMap;
55 typedef sbSmartMediaListMap::value_type sbSmartMediaListMapPair;
56 typedef sbSmartMediaListMap::iterator sbSmartMediaListMapIter;
57 
58 
60  public nsIClassInfo,
61  public nsIObserver,
62  public sbIMediaListListener,
64  public sbIShutdownJob,
66 {
67 public:
69  virtual ~sbMediaExportService();
70 
71  nsresult Init();
72 
73  static NS_METHOD RegisterSelf(nsIComponentManager* aCompMgr,
74  nsIFile* aPath,
75  const char* aLoaderStr,
76  const char* aType,
77  const nsModuleComponentInfo *aInfo);
78 
79  // sbMediaExportPrefListener
80  NS_IMETHOD OnBoolPrefChanged(const nsAString & aPrefName,
81  const PRBool aNewPrefValue);
82 
84  NS_DECL_SBIMEDIAEXPORTSERVICE
85  NS_DECL_NSICLASSINFO
86  NS_DECL_NSIOBSERVER
87  NS_DECL_SBIMEDIALISTLISTENER
88  NS_DECL_SBILOCALDATABASESMARTMEDIALISTLISTENER
89  NS_DECL_SBIJOBPROGRESS
90  NS_DECL_SBISHUTDOWNJOB
91 
92 protected:
93  // Internal service startup handling
94  nsresult InitInternal();
95 
96  // Internal service shutdown handling
97  nsresult Shutdown();
98 
99  // Stop listening to all observed media lists and clear changes.
100  nsresult StopListeningMediaLists();
101 
102  // Media list listening utility methods
103  nsresult ListenToMediaList(sbIMediaList *aMediaList);
104  nsresult GetShouldWatchMediaList(sbIMediaList *aMediaList,
105  PRBool *aShouldWatch);
106 
107  // Background thread method to Write export data to disk.
108  void WriteExportData();
109 
110  // Background thread method to notify the listeners on the main thread.
111  void ProxyNotifyListeners();
112 
113  // Methods for writing the task file
114  nsresult WriteChangesToTaskFile();
115  nsresult WriteAddedMediaLists();
116  nsresult WriteRemovedMediaLists();
117  nsresult WriteAddedMediaItems();
118  nsresult WriteUpdatedMediaItems();
119  nsresult WriteUpdatedSmartPlaylists();
120  nsresult WriteMediaItemsArray(nsIArray *aItemsArray);
121 
122  // Lookup mediaitems by a guid list.
123  nsresult GetMediaListByGuid(const nsAString & aItemGuid,
124  sbIMediaList **aMediaList);
125 
126  // Notify job progress listeners.
127  nsresult NotifyListeners();
128 
129  // Returns true if there is some observed changes that have not been
130  // exported yet.
131  PRBool GetHasRecordedChanges();
132 
133 private:
134  // Core and changed item stuff:
135  nsRefPtr<sbMediaExportPrefController> mPrefController;
136  nsCOMPtr<sbIMutablePropertyArray> mFilteredProperties;
137  nsCOMArray<sbIMediaList> mObservedMediaLists;
138  nsCOMArray<sbILocalDatabaseSmartMediaList> mObservedSmartMediaLists;
139 
140  // a map of <media list guid> to array of <media item>s added to that list
141  sbMediaListItemMap mAddedItemsMap;
142  // a set of <media item guid>s of items changed in the library
143  sbStringSet mUpdatedItems;
144  // a list of <media list guid>s that were added to the library
145  sbStringList mAddedMediaList;
146  // a list of <media list guid>s that were removed from the library
147  sbStringList mRemovedMediaLists;
148  // a list of <media list guid>s of updated <smart media list>s
149  sbStringList mUpdatedSmartMediaLists;
150  PRBool mIsRunning;
151 
152  // Exporting stuff:
153  nsRefPtr<sbMediaExportTaskWriter> mTaskWriter;
154 
155  // sbIJobProgress / sbIShutdownJob stuff:
156  nsCOMArray<sbIJobProgressListener> mJobListeners;
157  PRUint32 mTotal;
158  PRUint32 mProgress;
159  PRUint16 mStatus;
160 };
161 
162 #endif // sbMediaExportService_h_
163 
_updateCookies aPath
sbSmartMediaListMap::iterator sbSmartMediaListMapIter
static NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
nsresult WriteMediaItemsArray(nsIArray *aItemsArray)
A brief description of the contents of this interface.
sbMediaListItemMap::value_type sbMediaListItemMapPair
std::map< nsString, sbStringList > sbMediaListItemMap
Interface used to listen to changes to a media list.
nsresult ListenToMediaList(sbIMediaList *aMediaList)
NS_IMETHOD OnBoolPrefChanged(const nsAString &aPrefName, const PRBool aNewPrefValue)
sbSmartMediaListMap::value_type sbSmartMediaListMapPair
nsresult GetShouldWatchMediaList(sbIMediaList *aMediaList, PRBool *aShouldWatch)
std::map< nsString, nsString > sbSmartMediaListMap
sbMediaListItemMap::iterator sbMediaListItemMapIter
std::set< nsString > sbStringSet
std::list< nsString > sbStringList
nsresult GetMediaListByGuid(const nsAString &aItemGuid, sbIMediaList **aMediaList)