26 #ifndef __SBDEVICELIBRARY_H__
27 #define __SBDEVICELIBRARY_H__
29 #include <nsAutoPtr.h>
31 #include <nsInterfaceHashtable.h>
32 #include <nsIClassInfo.h>
33 #include <nsISimpleEnumerator.h>
35 #include <sbIDeviceEventListener.h>
36 #include <sbIDeviceLibrary.h>
37 #include <sbILibrary.h>
38 #include <sbIMediaListListener.h>
39 #include <sbILocalDatabaseSimpleMediaList.h>
40 #include <sbIPropertyArray.h>
42 #include <nsIPrefBranch.h>
51 #define SB_DECL_SBILIBRARY_OVERRIDES \
52 NS_IMETHOD CreateMediaItem(nsIURI *aContentUri, sbIPropertyArray *aProperties, PRBool aAllowDuplicates, sbIMediaItem **_retval); \
53 NS_IMETHOD CreateMediaItemIfNotExist(nsIURI *aContentUri, sbIPropertyArray *aProperties, sbIMediaItem **aResultItem, PRBool *_retval); \
54 NS_IMETHOD CreateMediaList(const nsAString & aType, sbIPropertyArray *aProperties, sbIMediaList **_retval); \
55 NS_IMETHOD GetDevice(sbIDevice * *aDevice); \
56 NS_IMETHOD ClearItems(); \
57 NS_IMETHOD ClearItemsByType(const nsAString &aContentType);
61 #define SB_FORWARD_SAFE_SBILIBRARY(_to) \
62 NS_IMETHOD GetSupportsForeignMediaItems(PRBool *aSupportsForeignMediaItems) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetSupportsForeignMediaItems(aSupportsForeignMediaItems); } \
63 NS_IMETHOD GetCreationParameters(nsIPropertyBag2 * *aCreationParameters) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetCreationParameters(aCreationParameters); } \
64 NS_IMETHOD GetFactory(sbILibraryFactory * *aFactory) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetFactory(aFactory); } \
65 NS_IMETHOD ContainsItemWithSameIdentity(sbIMediaItem* aMediaItem, PRBool* _retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->ContainsItemWithSameIdentity(aMediaItem, _retval); } \
66 NS_IMETHOD GetItemsWithSameIdentity(sbIMediaItem* aMediaItem, nsIArray** _retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemsWithSameIdentity(aMediaItem, _retval); } \
67 NS_IMETHOD Resolve(nsIURI *aUri, nsIChannel **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->Resolve(aUri, _retval); } \
68 NS_IMETHOD CopyMediaList(const nsAString & aType, sbIMediaList *aSource, PRBool aDontCopyContent, sbIMediaList **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->CopyMediaList(aType, aSource, aDontCopyContent, _retval); } \
69 NS_IMETHOD GetMediaItem(const nsAString & aGuid, sbIMediaItem **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetMediaItem(aGuid, _retval); } \
70 NS_IMETHOD GetDuplicate(sbIMediaItem *aMediaItem, sbIMediaItem **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetDuplicate(aMediaItem, _retval); } \
71 NS_IMETHOD GetMediaListTypes(nsIStringEnumerator * *aMediaListTypes) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetMediaListTypes(aMediaListTypes); } \
72 NS_IMETHOD RegisterMediaListFactory(sbIMediaListFactory *aFactory) { return !_to ? NS_ERROR_NULL_POINTER : _to->RegisterMediaListFactory(aFactory); } \
73 NS_IMETHOD Optimize(PRBool aAnalyzeOnly) { return !_to ? NS_ERROR_NULL_POINTER : _to->Optimize(aAnalyzeOnly); } \
74 NS_IMETHOD Flush(void) { return !_to ? NS_ERROR_NULL_POINTER : _to->Flush(); } \
75 NS_IMETHOD BatchCreateMediaItems(nsIArray *aURIArray, nsIArray *aPropertyArrayArray, PRBool aAllowDuplicates, nsIArray **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->BatchCreateMediaItems(aURIArray, aPropertyArrayArray, aAllowDuplicates, _retval); } \
76 NS_IMETHOD BatchCreateMediaItemsIfNotExist(nsIArray *aURIArray, nsIArray *aPropertyArrayArray, nsIArray **aResultItemArray, nsIArray **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->BatchCreateMediaItemsIfNotExist(aURIArray, aPropertyArrayArray, aResultItemArray, _retval); } \
77 NS_IMETHOD BatchCreateMediaItemsAsync(sbIBatchCreateMediaItemsListener *aListener, nsIArray *aURIArray, nsIArray *aPropertyArrayArray, PRBool aAllowDuplicates) { return !_to ? NS_ERROR_NULL_POINTER : _to->BatchCreateMediaItemsAsync(aListener, aURIArray, aPropertyArrayArray, aAllowDuplicates); }
81 #define SB_DECL_SBIMEDIALIST_OVERRIDES \
82 NS_IMETHOD Add(sbIMediaItem *aMediaItem); \
83 NS_IMETHOD AddItem(sbIMediaItem *aMediaItem, sbIMediaItem ** aNewMediaItem); \
84 NS_IMETHOD AddAll(sbIMediaList *aMediaList); \
85 NS_IMETHOD AddSome(nsISimpleEnumerator *aMediaItems); \
86 NS_IMETHOD AddMediaItems(nsISimpleEnumerator *aMediaItems, sbIAddMediaItemsListener *aListener, PRBool aAsync); \
87 NS_IMETHOD Clear(void);
89 #define SB_FORWARD_SAFE_SBIMEDIALIST(_to) \
90 NS_IMETHOD GetName(nsAString & aName) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetName(aName); } \
91 NS_IMETHOD SetName(const nsAString & aName) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetName(aName); } \
92 NS_IMETHOD GetType(nsAString & aType) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetType(aType); } \
93 NS_IMETHOD GetLength(PRUint32 *aLength) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetLength(aLength); } \
94 NS_IMETHOD GetIsEmpty(PRBool *aIsEmpty) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetIsEmpty(aIsEmpty); } \
95 NS_IMETHOD GetUserEditableContent(PRBool *aUserEditableContent) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetUserEditableContent(aUserEditableContent); } \
96 NS_IMETHOD GetItemByGuid(const nsAString & aGuid, sbIMediaItem **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemByGuid(aGuid, _retval); } \
97 NS_IMETHOD GetItemByIndex(PRUint32 aIndex, sbIMediaItem **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemByIndex(aIndex, _retval); } \
98 NS_IMETHOD GetListContentType(PRUint16 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetListContentType(_retval); } \
99 NS_IMETHOD EnumerateAllItems(sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return !_to ? NS_ERROR_NULL_POINTER : _to->EnumerateAllItems(aEnumerationListener, aEnumerationType); } \
100 NS_IMETHOD EnumerateItemsByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return !_to ? NS_ERROR_NULL_POINTER : _to->EnumerateItemsByProperty(aPropertyID, aPropertyValue, aEnumerationListener, aEnumerationType); } \
101 NS_IMETHOD EnumerateItemsByProperties(sbIPropertyArray *aProperties, sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return !_to ? NS_ERROR_NULL_POINTER : _to->EnumerateItemsByProperties(aProperties, aEnumerationListener, aEnumerationType); } \
102 NS_IMETHOD GetItemsByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, nsIArray **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemsByProperty(aPropertyID, aPropertyValue, _retval); } \
103 NS_IMETHOD GetItemCountByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, PRUint32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemCountByProperty(aPropertyID, aPropertyValue, _retval); } \
104 NS_IMETHOD GetItemsByProperties(sbIPropertyArray *aProperties, nsIArray **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemsByProperties(aProperties, _retval); } \
105 NS_IMETHOD IndexOf(sbIMediaItem *aMediaItem, PRUint32 aStartFrom, PRUint32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->IndexOf(aMediaItem, aStartFrom, _retval); } \
106 NS_IMETHOD LastIndexOf(sbIMediaItem *aMediaItem, PRUint32 aStartFrom, PRUint32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->LastIndexOf(aMediaItem, aStartFrom, _retval); } \
107 NS_IMETHOD Contains(sbIMediaItem *aMediaItem, PRBool *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->Contains(aMediaItem, _retval); } \
108 NS_IMETHOD Remove(sbIMediaItem *aMediaItem) { return !_to ? NS_ERROR_NULL_POINTER : _to->Remove(aMediaItem); } \
109 NS_IMETHOD RemoveByIndex(PRUint32 aIndex) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveByIndex(aIndex); } \
110 NS_IMETHOD RemoveSome(nsISimpleEnumerator *aMediaItems) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveSome(aMediaItems); } \
111 NS_IMETHOD AddListener(sbIMediaListListener *aListener, PRBool aOwnsWeak, PRUint32 aFlags, sbIPropertyArray *aPropertyFilter) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddListener(aListener, aOwnsWeak, aFlags, aPropertyFilter); } \
112 NS_IMETHOD RemoveListener(sbIMediaListListener *aListener) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveListener(aListener); } \
113 NS_IMETHOD CreateView(sbIMediaListViewState *aState, sbIMediaListView **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->CreateView(aState, _retval); } \
114 NS_IMETHOD RunInBatchMode(sbIMediaListBatchCallback *aCallback, nsISupports *aUserData) { return !_to ? NS_ERROR_NULL_POINTER : _to->RunInBatchMode(aCallback, aUserData); } \
115 NS_IMETHOD GetDistinctValuesForProperty(const nsAString & aPropertyID, nsIStringEnumerator **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetDistinctValuesForProperty(aPropertyID, _retval); }
117 #define SB_FORWARD_SAFE_SBIMEDIAITEM_MINUS_OVERRIDES(_to) \
118 NS_SCRIPTABLE NS_IMETHOD GetIsMutable(PRBool *aIsMutable) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetIsMutable(aIsMutable); } \
119 NS_SCRIPTABLE NS_IMETHOD GetItemController(sbIMediaItemController **aMediaItemController) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemController(aMediaItemController); } \
120 NS_SCRIPTABLE NS_IMETHOD GetMediaCreated(PRInt64 *aMediaCreated) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetMediaCreated(aMediaCreated); } \
121 NS_SCRIPTABLE NS_IMETHOD SetMediaCreated(PRInt64 aMediaCreated) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetMediaCreated(aMediaCreated); } \
122 NS_SCRIPTABLE NS_IMETHOD GetMediaUpdated(PRInt64 *aMediaUpdated) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetMediaUpdated(aMediaUpdated); } \
123 NS_SCRIPTABLE NS_IMETHOD SetMediaUpdated(PRInt64 aMediaUpdated) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetMediaUpdated(aMediaUpdated); } \
124 NS_SCRIPTABLE NS_IMETHOD GetContentSrc(nsIURI * *aContentSrc) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetContentSrc(aContentSrc); } \
125 NS_SCRIPTABLE NS_IMETHOD SetContentSrc(nsIURI * aContentSrc) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetContentSrc(aContentSrc); } \
126 NS_SCRIPTABLE NS_IMETHOD GetContentLength(PRInt64 *aContentLength) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetContentLength(aContentLength); } \
127 NS_SCRIPTABLE NS_IMETHOD SetContentLength(PRInt64 aContentLength) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetContentLength(aContentLength); } \
128 NS_SCRIPTABLE NS_IMETHOD GetContentType(nsAString & aContentType) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetContentType(aContentType); } \
129 NS_SCRIPTABLE NS_IMETHOD SetContentType(const nsAString & aContentType) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetContentType(aContentType); } \
130 NS_SCRIPTABLE NS_IMETHOD TestIsURIAvailable(nsIObserver *aObserver) { return !_to ? NS_ERROR_NULL_POINTER : _to->TestIsURIAvailable(aObserver); } \
131 NS_SCRIPTABLE NS_IMETHOD OpenInputStreamAsync(nsIStreamListener *aListener, nsISupports *aContext, nsIChannel **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->OpenInputStreamAsync(aListener, aContext, _retval); } \
132 NS_SCRIPTABLE NS_IMETHOD OpenInputStream(nsIInputStream **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->OpenInputStream(_retval); } \
133 NS_SCRIPTABLE NS_IMETHOD OpenOutputStream(nsIOutputStream **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->OpenOutputStream(_retval); } \
134 NS_SCRIPTABLE NS_IMETHOD ToString(nsAString & _retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->ToString(_retval); }
145 NS_DECL_SBIDEVICELIBRARY
146 NS_DECL_SBIMEDIALISTLISTENER
147 NS_DECL_SBILOCALDATABASEMEDIALISTCOPYLISTENER
148 NS_DECL_SBIDEVICEEVENTLISTENER
153 NS_FORWARD_SAFE_SBILIBRARYRESOURCE(mDeviceLibrary)
159 NS_ENSURE_ARG_POINTER(_retval);
169 (
const nsAString& aDeviceIdentifier,
183 static PLDHashOperator PR_CALLBACK
184 AddListenersToCOMArrayCallback(nsISupportsHashKey::KeyType aKey,
196 nsresult GetMgmtTypePrefKey(PRUint32 aContentType, nsAString& aPrefKey);
206 nsresult GetSyncListsPrefKey(PRUint32 aContentType, nsAString& aPrefKey);
215 nsresult GetSyncRootPrefKey(PRUint32 aContentType, nsAString& aPrefKey);
235 nsresult CreateDeviceLibrary(
const nsAString &aDeviceIdentifier,
236 nsIURI *aDeviceDatabaseURI);
246 nsresult RegisterDeviceLibrary();
260 nsresult UnregisterDeviceLibrary();
266 nsresult UpdateMainLibraryListeners(
273 nsresult UpdateIsReadOnly();
282 nsresult GetIsMgmtTypeSyncAll(PRBool* aIsMgmtTypeSyncAll);
291 nsresult GetIsMgmtTypeSyncList(PRBool* aIsMgmtTypeSyncList);
307 nsCOMPtr<sbILibrary> mDeviceLibrary;
312 nsCOMPtr<sbIDevice> mDevice;
317 nsRefPtr<sbLibraryUpdateListener> mMainLibraryListener;
322 nsCOMPtr<sbIMutablePropertyArray> mMainLibraryListenerFilter;
327 nsInterfaceHashtable<nsISupportsHashKey, sbIDeviceLibraryListener> mListeners;
332 nsRefPtr<sbDeviceLibrarySyncSettings> mSyncSettings;
336 #define PREF_SYNC_PREFIX "library."
337 #define PREF_SYNC_BRANCH ".sync."
338 #define PREF_SYNC_MGMTTYPE "mgmtType"
339 #define PREF_SYNC_IMPORT "import"
340 #define PREF_SYNC_LISTS "playlists"
341 #define PREF_SYNC_ROOT "root"
342 #define PREF_SYNC_FOLDER "syncFolder"
NS_DECL_ISUPPORTS NS_DECL_NSICLASSINFO NS_DECL_SBIDEVICELIBRARY NS_DECL_SBIMEDIALISTLISTENER NS_DECL_SBILOCALDATABASEMEDIALISTCOPYLISTENER NS_DECL_SBIDEVICEEVENTLISTENER sbDeviceLibrary(sbIDevice *aDevice)
char const *const gMediaType[]
#define SB_DECL_SBIMEDIALIST_OVERRIDES
#define SB_FORWARD_SAFE_SBIMEDIAITEM_MINUS_OVERRIDES(_to)
virtual ~sbDeviceLibrary()
#define SB_FORWARD_SAFE_SBIMEDIALIST(_to)
Interface used to listen to changes to a device library.
NS_IMETHODIMP GetLibrary(sbILibrary **_retval)
#define SB_FORWARD_SAFE_SBILIBRARY(_to)
Media library abstraction.
static nsresult GetDefaultDeviceLibraryDatabaseFile(const nsAString &aDeviceIdentifier, nsIFile **aDBFile)
#define SB_DECL_SBILIBRARY_OVERRIDES