sbMetadataJob.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-2008 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 
32 #ifndef SBMETADATAJOB_H_
33 #define SBMETADATAJOB_H_
34 
35 // INCLUDES ===================================================================
36 
37 #include <nscore.h>
38 #include <prlock.h>
39 #include <nsAutoLock.h>
40 #include <nsStringGlue.h>
41 #include <nsTArray.h>
42 #include <nsCOMArray.h>
43 #include <nsCOMPtr.h>
44 #include <nsAutoPtr.h>
45 #include <nsIClassInfo.h>
46 
47 #include <sbIAlbumArtListener.h>
48 #include <sbIMediaItem.h>
49 #include <sbIJobProgress.h>
50 #include <sbIJobProgressUI.h>
51 #include <sbIJobCancelable.h>
52 #include <sbIPropertyManager.h>
53 
55 
56 #include <set>
57 
58 // CLASSES ====================================================================
59 typedef std::set<nsString> sbStringSet;
60 
61 class sbMetadataJobItem;
64 
80 class sbMetadataJob : public nsIClassInfo,
81  public sbIJobProgressUI,
82  public sbIJobCancelable,
83  public sbIAlbumArtListener
84 {
86 
87 public:
89  NS_DECL_NSICLASSINFO
90  NS_DECL_SBIJOBPROGRESS
91  NS_DECL_SBIJOBPROGRESSUI
92  NS_DECL_SBIJOBCANCELABLE
93  NS_DECL_SBIALBUMARTLISTENER
94 
95  enum JobType
96  {
97  TYPE_READ = 0,
99  };
100 
101  sbMetadataJob();
102  virtual ~sbMetadataJob();
103 
116  nsresult Init(nsIArray *aMediaItemsArray,
117  nsIStringEnumerator* aRequiredProperties,
118  JobType aJobType);
119 
129  nsresult AppendMediaItems(nsIArray* aMediaItemsArray);
130 
135  nsresult AppendJobItem(sbMetadataJobItem* aJobItem);
136 
142  nsresult OnJobProgress();
143 
155  nsresult GetQueuedItem(PRBool aMainThreadOnly, sbMetadataJobItem** aJobItem);
156 
165  nsresult PutProcessedItem(sbMetadataJobItem* aJobItem);
166 
170  nsresult GetType(JobType* aJobType);
171 
177  nsresult SetBlocked(PRBool aBlocked);
178 
179 
180 private:
181 
190  nsresult SetUpHandlerForJobItem(sbMetadataJobItem* aJobItem);
191 
197  nsresult PrepareWriteItem(sbMetadataJobItem* aJobItem);
198 
204  nsresult HandleProcessedItem(sbMetadataJobItem *aJobItem);
205 
210  nsresult HandleWrittenItem(sbMetadataJobItem *aJobItem);
211 
217  nsresult DeferProcessedItemHandling(sbMetadataJobItem *aJobItem);
218 
225  nsresult CopyPropertiesToMediaItem(sbMetadataJobItem* aJobItem,
226  PRBool* aWillRetry);
227 
233  nsresult ReadAlbumArtwork(sbMetadataJobItem* aJobItem);
234 
245  nsresult HandleFailedItem(sbMetadataJobItem* aJobItem,
246  PRBool aShouldRetry = PR_FALSE,
247  PRBool *aWillRetry = nsnull);
248 
253  nsresult BatchCompleteItems();
254 
260  static nsresult RunLibraryBatch(nsISupports* aUserData);
261 
265  nsresult BatchCompleteItemsCallback();
266 
274  nsresult BeginLibraryBatch();
275  nsresult EndLibraryBatch();
276 
277 
281  nsresult CreateDefaultItemName(sbIMediaItem* aMediaItem,
282  nsAString& retval);
283 
288  nsresult AppendToPropertiesIfValid(sbIPropertyManager* aPropertyManager,
289  sbIMutablePropertyArray* aProperties,
290  const nsAString& aID,
291  const nsAString& aValue);
296  nsresult GetFileSize(sbIMediaItem* aMediaItem, PRInt64* aFileSize);
297 
301  nsresult LocalizeString(const nsAString& aName, nsAString& aValue);
302 
303 
304  // sbIJobProgress variables
305  PRUint16 mStatus;
306  PRBool mBlocked;
307  PRUint32 mCompletedItemCount;
308  PRUint32 mTotalItemCount;
309  nsTArray<nsString> mErrorMessages;
310  nsString mTitleText;
311  nsString mStatusText;
312  nsCOMArray<sbIJobProgressListener> mListeners;
313 
314  // TYPE_READ or TYPE_WRITE
315  JobType mJobType;
316 
317  // The library to which all items in this job belong
318  // (since batch operations are per-library)
319  nsCOMPtr<sbILibrary> mLibrary;
320 
321  // List of properties we require for this job
322  nsStringArray mRequiredProperties;
323 
324  // List of absolute paths that the watch folder service is ignoring.
325  sbStringSet mIgnoredContentPaths;
326 
327  // List of job items that MUST be processed on the
328  // main thread due to sbIMetadataHandler limitations
329  nsTArray<nsRefPtr<sbMetadataJobItem> > mMainThreadJobItems;
330  PRUint32 mNextMainThreadIndex;
331 
332  // List of job items that may be processed off of the main thread
333  // TODO consider using nsDeque
334  nsTArray<nsRefPtr<sbMetadataJobItem> > mBackgroundThreadJobItems;
335  PRUint32 mNextBackgroundThreadIndex;
336  PRLock* mBackgroundItemsLock;
337 
338  // Pointer to a list of items that have been returned from processing, but have
339  // not yet had their properties set.
340  // Used to perform sbIMediaItem.setProperties() batching.
341  nsAutoPtr<nsTArray<nsRefPtr<sbMetadataJobItem> > >
342  mProcessedBackgroundThreadItems;
343  PRLock* mProcessedBackgroundItemsLock;
344 
345  // Indicates that we've started a library batch, and need
346  // to close it before we complete
347  PRBool mInLibraryBatch;
348 
349  // Cached art fetcher instance
350  nsCOMPtr<sbIAlbumArtFetcherSet> mArtFetcher;
351 
352  nsCOMPtr<nsIStringBundle> mStringBundle;
353 };
354 
355 #endif // SBMETADATAJOB_H_
nsresult OnJobProgress()
Interface to control UI aspects of sbIJobProgress.
onPageChanged aValue
Definition: FeedWriter.js:1395
nsresult GetType(JobType *aJobType)
nsresult AppendMediaItems(nsIArray *aMediaItemsArray)
nsresult GetQueuedItem(PRBool aMainThreadOnly, sbMetadataJobItem **aJobItem)
virtual ~sbMetadataJob()
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
A component which is interested in the result of an album art fetch request.
std::set< nsString > sbStringSet
Definition: sbMetadataJob.h:59
nsresult PutProcessedItem(sbMetadataJobItem *aJobItem)
Interface for an album art fetcher set. Instantiate as a component instance.
nsresult SetBlocked(PRBool aBlocked)
nsresult Init(nsIArray *aMediaItemsArray, nsIStringEnumerator *aRequiredProperties, JobType aJobType)
nsresult AppendJobItem(sbMetadataJobItem *aJobItem)
_updateCookies aName
std::set< nsString > sbStringSet
Interface that defines a single item of media in the system.
Manager for system wide metadata properties.