sbLibraryUtils.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 
26 #ifndef __SBLIBRARYUTILS_H__
27 #define __SBLIBRARYUTILS_H__
28 
29 // Mozilla inclues
30 #include <nsCOMArray.h>
31 #include <nsCOMPtr.h>
32 #include <pratom.h>
33 #include <nsServiceManagerUtils.h>
34 #include <nsComponentManagerUtils.h>
35 #include <nsStringAPI.h>
36 
37 // Mozilla interfaces
38 #include <nsIMutableArray.h>
39 
40 // Songbird includes
41 #include <sbMemoryUtils.h>
42 
43 // Songbird interfaces
44 #include <sbILibrary.h>
45 #include <sbILibraryManager.h>
46 
47 class sbIMediaItem;
48 class sbILibrary;
49 class nsIIOService;
51 
53 {
54 public:
56  mDepth(0)
57  {
58  MOZ_COUNT_CTOR(sbLibraryBatchHelper);
59  }
60 
62  {
63  MOZ_COUNT_DTOR(sbLibraryBatchHelper);
64  }
65 
66  void Begin()
67  {
68  NS_ASSERTION(mDepth >= 0, "Illegal batch depth, mismatched calls!");
69  PR_AtomicIncrement(&mDepth);
70  }
71 
72  void End()
73  {
74 #ifdef DEBUG
75  PRInt32 depth = PR_AtomicDecrement(&mDepth);
76  NS_ASSERTION(depth >= 0, "Illegal batch depth, mismatched calls!");
77 #else
78  PR_AtomicDecrement(&mDepth);
79 #endif
80  }
81 
82  PRUint32 Depth()
83  {
84  return (PRUint32) mDepth;
85  }
86 
87  PRBool IsActive()
88  {
89  return mDepth > 0;
90  }
91 
92 private:
93  PRInt32 mDepth;
94 };
95 
97 {
98 public:
107  static nsresult GetItemInLibrary(/* in */ sbIMediaItem * aItem,
108  /* in */ sbILibrary * aLibrary,
109  /* out */ sbIMediaItem **_retval);
110 
122  static nsresult FindItemsWithSameURL(sbIMediaItem * aMediaItem,
123  sbIMediaList * aMediaList,
124  nsIMutableArray * aCopies);
125 
136  static nsresult FindCopiesByID(sbIMediaItem * aMediaItem,
137  sbIMediaList * aList,
138  nsIMutableArray * aCopies);
139 
148  static nsresult FindOriginalsByID(sbIMediaItem * aMediaItem,
149  sbIMediaList * aList,
150  nsIMutableArray * aCopies);
157  static nsresult GetOriginItem(/* in */ sbIMediaItem* aItem,
158  /* out */ sbIMediaItem** _retval);
167  static nsresult GetContentLength(/* in */ sbIMediaItem * aItem,
168  /* out */ PRInt64 * _retval = nsnull);
169 
176  static nsresult SetContentLength(/* in */ sbIMediaItem * aItem,
177  /* in */ nsIURI * aURI);
178 
193  static nsresult GetContentURI(/* in */ nsIURI* aURI,
194  /* out */ nsIURI** _retval,
195  /* in */ nsIIOService * aIOService = nsnull);
196 
204  static nsresult GetMediaListContentType(/* in */ sbIMediaList *aMediaList,
205  /* out */ PRUint16 *aListContentType);
206 
217  static nsresult GetFileContentURI(/* in */ nsIFile* aFile,
218  /* out */ nsIURI** _retval);
219 
220  static nsresult GetItemsByProperty(sbIMediaList * aMediaList,
221  nsAString const & aPropertyName,
222  nsAString const & aValue,
223  nsCOMArray<sbIMediaItem> & aMediaItems);
224 
231  static nsresult GetMediaListByContentType(sbILibrary * aLibrary,
232  PRUint32 aContentType,
233  nsIArray ** aMediaLists);
234 
240  static PRUint32 GetEqualOperator(sbIPropertyOperator ** aOperator);
241 
249  static nsresult SuggestUniqueNameForPlaylist(
250  /* in */ sbILibrary *aLibrary,
251  /* in */ nsAString const & aListName,
252  /* out */ nsAString & aName);
262  static nsresult LinkCopy(sbIMediaItem * aOriginal, sbIMediaItem * aCopy);
263 };
264 
268 inline
269 nsresult GetMainLibrary(sbILibrary ** aMainLibrary) {
270  nsresult rv;
271  nsCOMPtr<sbILibraryManager> libManager =
272  do_GetService("@songbirdnest.com/Songbird/library/Manager;1", &rv);
273  NS_ENSURE_SUCCESS(rv, rv);
274 
275  nsCOMPtr<sbILibrary> mainLibrary;
276  return libManager->GetMainLibrary(aMainLibrary);
277 }
278 
282 inline
283 PRBool sbIsMainLibrary(sbILibrary * aLibrary)
284 {
285  NS_ENSURE_ARG_POINTER(aLibrary);
286 
287  nsresult rv;
288 
289  nsCOMPtr<sbILibrary> mainLibrary;
290  rv = GetMainLibrary(getter_AddRefs(mainLibrary));
291  NS_ENSURE_SUCCESS(rv, PR_FALSE);
292 
293  PRBool isEqual;
294  rv = mainLibrary->Equals(aLibrary, &isEqual);
295  NS_ENSURE_SUCCESS(rv, PR_FALSE);
296 
297  return isEqual;
298 }
299 
303 inline
304 nsresult GetMainLibraryId(nsAString & aLibraryId) {
305 
306  nsCOMPtr<sbILibrary> mainLibrary;
307  nsresult rv = GetMainLibrary(getter_AddRefs(mainLibrary));
308  NS_ENSURE_SUCCESS(rv, rv);
309 
310  return mainLibrary->GetGuid(aLibraryId);
311 }
312 
313 //
314 // Auto-disposal class wrappers.
315 //
316 // sbAutoRemoveMediaItem Wrapper to auto-remove a media item from its
317 // library.
318 //
319 
320 SB_AUTO_NULL_CLASS(sbAutoRemoveMediaItem,
321  nsCOMPtr<sbIMediaItem>,
322  {
323  nsCOMPtr<sbILibrary> library;
324  nsresult rv = mValue->GetLibrary(getter_AddRefs(library));
325  if (NS_SUCCEEDED(rv))
326  library->Remove(mValue);
327  });
328 
329 #endif // __SBLIBRARYUTILS_H__
330 
static nsresult GetItemsByProperty(sbIMediaList *aMediaList, nsAString const &aPropertyName, nsAString const &aValue, nsCOMArray< sbIMediaItem > &aMediaItems)
static nsresult LinkCopy(sbIMediaItem *aOriginal, sbIMediaItem *aCopy)
Links a copy to its original. It will take into account the libraries the items belong to...
static nsresult GetContentLength(sbIMediaItem *aItem, PRInt64 *_retval=nsnull)
static nsresult GetItemInLibrary(sbIMediaItem *aItem, sbILibrary *aLibrary, sbIMediaItem **_retval)
onPageChanged aValue
Definition: FeedWriter.js:1395
static nsresult GetMediaListByContentType(sbILibrary *aLibrary, PRUint32 aContentType, nsIArray **aMediaLists)
static nsresult GetFileContentURI(nsIFile *aFile, nsIURI **_retval)
Return a library content URI for the file specified by aFile. Special processing is required to conve...
static nsresult FindCopiesByID(sbIMediaItem *aMediaItem, sbIMediaList *aList, nsIMutableArray *aCopies)
static nsresult SetContentLength(sbIMediaItem *aItem, nsIURI *aURI)
static nsresult GetOriginItem(sbIMediaItem *aItem, sbIMediaItem **_retval)
static nsresult GetContentURI(nsIURI *aURI, nsIURI **_retval, nsIIOService *aIOService=nsnull)
Return a library content URI for the URI specified by aURI. A library content URI is a specially form...
SB_AUTO_NULL_CLASS(sbAutoRemoveMediaItem, nsCOMPtr< sbIMediaItem >,{nsCOMPtr< sbILibrary > library;nsresult rv=mValue->GetLibrary(getter_AddRefs(library));if(NS_SUCCEEDED(rv)) library->Remove(mValue);})
A brief description of the contents of this interface.
An interface to represent an operator that may act upon a property.
PRBool sbIsMainLibrary(sbILibrary *aLibrary)
static nsresult SuggestUniqueNameForPlaylist(sbILibrary *aLibrary, nsAString const &aListName, nsAString &aName)
Suggest a unique name for playlist.
static nsresult GetMediaListContentType(sbIMediaList *aMediaList, PRUint16 *aListContentType)
Return a media list content type.
Media library abstraction.
Definition: sbILibrary.idl:82
static nsresult FindOriginalsByID(sbIMediaItem *aMediaItem, sbIMediaList *aList, nsIMutableArray *aCopies)
static nsresult FindItemsWithSameURL(sbIMediaItem *aMediaItem, sbIMediaList *aMediaList, nsIMutableArray *aCopies)
_updateCookies aName
nsresult GetMainLibrary(sbILibrary **aMainLibrary)
Interface that defines a single item of media in the system.
static PRUint32 GetEqualOperator(sbIPropertyOperator **aOperator)
nsresult GetMainLibraryId(nsAString &aLibraryId)