30 #include <nsIClassInfoImpl.h>
31 #include <nsIProgrammingLanguage.h>
32 #include <nsIFileURL.h>
33 #include <nsIPrefBranch.h>
34 #include <nsIPrefService.h>
35 #include <nsISupportsPrimitives.h>
36 #include <nsIVariant.h>
37 #include <nsIWritablePropertyBag2.h>
45 #include <nsAppDirectoryServiceDefs.h>
46 #include <nsArrayUtils.h>
47 #include <nsAutoLock.h>
48 #include <nsAutoPtr.h>
49 #include <nsCOMArray.h>
51 #include <nsComponentManagerUtils.h>
52 #include <nsDirectoryServiceUtils.h>
54 #include <nsILocalFile.h>
56 #include <nsServiceManagerUtils.h>
57 #include <nsThreadUtils.h>
59 #include <nsXPCOMCIDInternal.h>
62 #include <sbIDevice.h>
63 #include <sbIDeviceCapabilities.h>
64 #include <sbIDeviceContent.h>
65 #include <sbIDeviceEvent.h>
66 #include <sbIDeviceEventTarget.h>
67 #include <sbIDeviceManager.h>
68 #include <sbIDeviceProperties.h>
69 #include <sbILibraryFactory.h>
70 #include <sbILibraryManager.h>
71 #include <sbILocalDatabaseSmartMediaList.h>
72 #include <sbIPrompter.h>
73 #include <sbIPropertyArray.h>
74 #include <sbIPropertyManager.h>
90 #define SB_AUDIO_SMART_PLAYLIST "<sbaudio>"
172 static PRLogModuleInfo* gDeviceLibraryLog = nsnull;
173 #define TRACE(args) PR_LOG(gDeviceLibraryLog, PR_LOG_DEBUG, args)
174 #define LOG(args) PR_LOG(gDeviceLibraryLog, PR_LOG_WARN, args)
185 if (!gDeviceLibraryLog) {
186 gDeviceLibraryLog = PR_NewLogModule(
"sbDeviceLibrary");
189 TRACE((
"DeviceLibrary[0x%.8x] - Constructed",
this));
197 nsAutoMonitor::DestroyMonitor(mMonitor);
200 TRACE((
"DeviceLibrary[0x%.8x] - Destructed",
this));
204 sbDeviceLibrary::Initialize(
const nsAString& aLibraryId)
206 NS_ENSURE_FALSE(mMonitor, NS_ERROR_ALREADY_INITIALIZED);
207 mMonitor = nsAutoMonitor::NewMonitor(__FILE__
"sbDeviceLibrary::mMonitor");
208 NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
210 NS_ENSURE_TRUE(succeeded, NS_ERROR_OUT_OF_MEMORY);
211 return CreateDeviceLibrary(aLibraryId, nsnull);
215 sbDeviceLibrary::Finalize()
220 if (mMainLibraryListener) {
221 nsCOMPtr<sbILibrary> mainLib;
223 NS_ASSERTION(NS_SUCCEEDED(rv),
"WTF this should never fail");
225 if (NS_SUCCEEDED(rv)) {
226 rv = mainLib->RemoveListener(mMainLibraryListener);
227 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"failed to remove main lib listener");
229 mMainLibraryListener = nsnull;
233 nsCOMPtr<sbIDeviceEventTarget>
234 deviceEventTarget = do_QueryInterface(mDevice, &rv);
235 if (NS_SUCCEEDED(rv))
236 deviceEventTarget->RemoveEventListener(
this);
239 if (mDeviceLibrary) {
240 nsCOMPtr<sbIMediaList> list = do_QueryInterface(mDeviceLibrary);
242 list->RemoveListener(
this);
246 UnregisterDeviceLibrary();
258 sbDeviceLibrary::CreateDeviceLibrary(
const nsAString &aDeviceIdentifier,
259 nsIURI *aDeviceDatabaseURI)
262 nsCOMPtr<sbILibraryFactory> libraryFactory =
264 NS_ENSURE_SUCCESS(rv, rv);
266 nsCOMPtr<nsIWritablePropertyBag2> libraryProps =
267 do_CreateInstance(NS_HASH_PROPERTY_BAG_CONTRACTID, &rv);
268 NS_ENSURE_SUCCESS(rv, rv);
270 nsCOMPtr<nsIFile> libraryFile;
271 if(aDeviceDatabaseURI) {
273 nsCOMPtr<nsIFileURL> furl = do_QueryInterface(aDeviceDatabaseURI, &rv);
274 NS_ENSURE_SUCCESS(rv, rv);
276 rv = furl->GetFile(getter_AddRefs(libraryFile));
277 NS_ENSURE_SUCCESS(rv, rv);
282 getter_AddRefs(libraryFile));
283 NS_ENSURE_SUCCESS(rv, rv);
286 rv = libraryProps->SetPropertyAsInterface(NS_LITERAL_STRING(
"databaseFile"),
288 NS_ENSURE_SUCCESS(rv, rv);
293 if(NS_SUCCEEDED(libraryFile->GetNativePath(str))) {
294 LOG((
"Attempting to create device library with file path %s", str.get()));
299 rv = libraryFactory->CreateLibrary(libraryProps,
300 getter_AddRefs(mDeviceLibrary));
301 NS_ENSURE_SUCCESS(rv, rv);
304 nsString deviceLibraryGuid;
305 rv = this->GetGuid(deviceLibraryGuid);
306 NS_ENSURE_SUCCESS(rv, rv);
308 rv = mDeviceLibrary->SetProperty
311 NS_ENSURE_SUCCESS(rv, rv);
316 NS_LITERAL_STRING(
"1"));
317 NS_ENSURE_SUCCESS(rv, rv);
320 rv = GetSyncSettings(getter_AddRefs(syncSettings));
321 NS_ENSURE_SUCCESS(rv, rv);
323 nsCOMPtr<sbIMediaList> list;
324 list = do_QueryInterface(mDeviceLibrary, &rv);
325 NS_ENSURE_SUCCESS(rv, rv);
328 rv = list->AddListener(
this,
337 NS_ENSURE_SUCCESS(rv, rv);
339 nsCOMPtr<sbILibrary> mainLib;
341 NS_ENSURE_SUCCESS(rv, rv);
345 nsCOMPtr<sbIDeviceEventTarget>
346 deviceEventTarget = do_QueryInterface(mDevice, &rv);
347 NS_ENSURE_SUCCESS(rv, rv);
348 rv = deviceEventTarget->AddEventListener(
this);
349 NS_ENSURE_SUCCESS(rv, rv);
352 mMainLibraryListener =
356 NS_ENSURE_TRUE(mMainLibraryListener, NS_ERROR_OUT_OF_MEMORY);
358 mMainLibraryListenerFilter = do_CreateInstance
360 NS_ENSURE_SUCCESS(rv, rv);
361 nsAutoString voidString;
362 voidString.SetIsVoid(PR_TRUE);
363 nsAutoString propertyID;
364 PRUint32 propertyCount =
366 for (PRUint32
i = 0;
i < propertyCount;
i++) {
368 rv = mMainLibraryListenerFilter->AppendProperty(propertyID, voidString);
369 NS_ENSURE_SUCCESS(rv, rv);
373 rv = UpdateMainLibraryListeners(syncSettings);
374 NS_ENSURE_SUCCESS(rv, rv);
376 nsCOMPtr<sbILocalDatabaseSimpleMediaList> simpleList;
377 simpleList = do_QueryInterface(list, &rv);
379 if(NS_SUCCEEDED(rv)) {
380 rv = simpleList->SetCopyListener(
this);
381 NS_ENSURE_SUCCESS(rv, rv);
385 "Failed to get sbILocalDatabaseSimpleMediaList interface. Copy Listener disabled.");
389 rv = UpdateIsReadOnly();
390 NS_ENSURE_SUCCESS(rv, rv);
392 rv = RegisterDeviceLibrary();
393 NS_ENSURE_SUCCESS(rv, rv);
399 sbDeviceLibrary::RegisterDeviceLibrary()
405 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
406 NS_ENSURE_SUCCESS(rv, rv);
408 return libraryManager->RegisterLibrary(
this, PR_FALSE);
412 sbDeviceLibrary::UnregisterDeviceLibrary()
417 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
418 NS_ENSURE_SUCCESS(rv, rv);
420 return libraryManager->UnregisterLibrary(
this);
425 (
const nsAString& aDeviceIdentifier,
428 NS_ENSURE_ARG_POINTER(aDBFile);
433 nsCOMPtr<nsIFile> libraryFile;
435 getter_AddRefs(libraryFile));
436 NS_ENSURE_SUCCESS(rv, rv);
438 rv = libraryFile->Append(NS_LITERAL_STRING(
"db"));
439 NS_ENSURE_SUCCESS(rv, rv);
441 PRBool exists = PR_FALSE;
442 rv = libraryFile->Exists(&exists);
443 NS_ENSURE_SUCCESS(rv, rv);
445 rv = libraryFile->Create(nsIFile::DIRECTORY_TYPE, 0700);
446 NS_ENSURE_SUCCESS(rv, rv);
449 nsAutoString filename(aDeviceIdentifier);
450 filename.AppendLiteral(
".db");
452 rv = libraryFile->Append(filename);
453 NS_ENSURE_SUCCESS(rv, rv);
455 libraryFile.forget(aDBFile);
461 sbDeviceLibrary::GetIsMgmtTypeSyncList(PRBool* aIsMgmtTypeSyncList)
463 NS_ASSERTION(aIsMgmtTypeSyncList,
"aIsMgmtTypeSyncList is null");
467 rv = GetSyncSettings(getter_AddRefs(syncSettings));
468 NS_ENSURE_SUCCESS(rv, rv);
470 PRBool isSyncList = PR_FALSE;
472 for (PRUint32 mediaType = 0;
479 nsCOMPtr<sbIDeviceLibraryMediaSyncSettings> mediaSyncSettings;
480 rv = syncSettings->GetMediaSettings(mediaType,
481 getter_AddRefs(mediaSyncSettings));
482 NS_ENSURE_SUCCESS(rv, rv);
484 rv = mediaSyncSettings->GetMgmtType(&mgmtType);
485 NS_ENSURE_SUCCESS(rv, rv);
494 isSyncList = PR_TRUE;
499 *aIsMgmtTypeSyncList = isSyncList;
504 sbDeviceLibrary::GetIsMgmtTypeSyncAll(PRBool* aIsMgmtTypeSyncAll)
506 NS_ASSERTION(aIsMgmtTypeSyncAll,
"aIsMgmtTypeSyncAll is null");
510 rv = GetSyncSettings(getter_AddRefs(syncSettings));
511 NS_ENSURE_SUCCESS(rv, rv);
513 nsCOMPtr<sbIDeviceLibraryMediaSyncSettings> mediaSyncSettings;
515 getter_AddRefs(mediaSyncSettings));
516 NS_ENSURE_SUCCESS(rv, rv);
520 rv = mediaSyncSettings->GetMgmtType(&mgmtType);
521 NS_ENSURE_SUCCESS(rv, rv);
524 *aIsMgmtTypeSyncAll = PR_TRUE;
527 *aIsMgmtTypeSyncAll = PR_FALSE;
534 sbDeviceLibrary::UpdateMainLibraryListeners(
537 NS_ENSURE_STATE(mDevice);
541 nsCOMPtr<sbILibrary> mainLib;
543 NS_ENSURE_SUCCESS(rv, rv);
548 rv = mainLib->AddListener(mMainLibraryListener,
554 mMainLibraryListenerFilter);
555 NS_ENSURE_SUCCESS(rv, rv);
561 sbDeviceLibrary::UpdateIsReadOnly()
566 nsCOMPtr<sbIDeviceProperties> baseDeviceProperties;
567 nsCOMPtr<nsIPropertyBag2> deviceProperties;
568 rv = mDevice->GetProperties(getter_AddRefs(baseDeviceProperties));
569 NS_ENSURE_SUCCESS(rv, rv);
570 rv = baseDeviceProperties->GetProperties(getter_AddRefs(deviceProperties));
571 NS_ENSURE_SUCCESS(rv, rv);
574 nsAutoString accessCompatibility;
575 rv = deviceProperties->GetPropertyAsAString
577 accessCompatibility);
579 accessCompatibility.Truncate();
582 if (accessCompatibility.Equals(NS_LITERAL_STRING(
"ro"))) {
584 NS_LITERAL_STRING(
"1"));
585 NS_ENSURE_SUCCESS(rv, rv);
592 str.SetIsVoid(PR_TRUE);
594 NS_ENSURE_SUCCESS(rv, rv);
600 sbDeviceLibrary::CreateSyncSettings()
606 NS_ENSURE_SUCCESS(rv, nsnull);
609 rv = mDevice->GetId(&deviceID);
610 NS_ENSURE_SUCCESS(rv, nsnull);
622 NS_ENSURE_ARG_POINTER(aSyncSettings);
626 nsAutoMonitor lock(mMonitor);
627 if (!mSyncSettings) {
628 mSyncSettings = CreateSyncSettings();
629 NS_ENSURE_TRUE(mSyncSettings, NS_ERROR_OUT_OF_MEMORY);
631 rv = mSyncSettings->Read(mDevice,
this);
632 NS_ENSURE_SUCCESS(rv, rv);
635 rv = CallQueryInterface(mSyncSettings.get(), aSyncSettings);
636 NS_ENSURE_SUCCESS(rv, rv);
642 sbDeviceLibrary::GetSyncListsPrefKey(PRUint32 aContentType,
645 NS_ENSURE_ARG_RANGE(aContentType,
648 NS_ENSURE_STATE(mDeviceLibrary);
652 nsresult rv = mDeviceLibrary->GetGuid(guid);
653 NS_ENSURE_SUCCESS(rv, rv);
657 aPrefKey.Append(guid);
660 aPrefKey.AppendLiteral(
gMediaType[aContentType]);
665 #define SB_NOTIFY_LISTENERS(call) \
666 nsCOMArray<sbIDeviceLibraryListener> listeners; \
668 nsAutoMonitor monitor(mMonitor); \
669 mListeners.EnumerateRead(AddListenersToCOMArrayCallback, &listeners); \
672 PRInt32 count = listeners.Count(); \
673 for (PRInt32 index = 0; index < count; index++) { \
674 nsCOMPtr<sbIDeviceLibraryListener> listener = listeners.ObjectAt(index); \
675 NS_ASSERTION(listener, "Null listener!"); \
683 #define SB_NOTIFY_LISTENERS_RETURN_FALSE(call) \
684 SB_NOTIFY_LISTENERS(call) \
685 *aNoMoreForBatch = PR_FALSE; \
687 #define SB_NOTIFY_LISTENERS_ASK_PERMISSION(call) \
688 PRBool mShouldProcceed = PR_TRUE; \
689 PRBool mPerformAction = PR_TRUE; \
691 nsCOMArray<sbIDeviceLibraryListener> listeners; \
693 nsAutoMonitor monitor(mMonitor); \
694 mListeners.EnumerateRead(AddListenersToCOMArrayCallback, &listeners); \
697 PRInt32 count = listeners.Count(); \
698 for (PRInt32 index = 0; index < count; index++) { \
699 nsCOMPtr<sbIDeviceLibraryListener> listener = listeners.ObjectAt(index); \
700 NS_ASSERTION(listener, "Null listener!"); \
702 if (!mShouldProcceed) { \
704 mPerformAction = PR_FALSE; \
713 NS_ENSURE_ARG_POINTER(aSyncSettings);
715 nsresult rv = SetSyncSettingsNoLock(aSyncSettings);
716 NS_ENSURE_SUCCESS(rv, rv);
719 rv = UpdateIsReadOnly();
720 NS_ENSURE_SUCCESS(rv, rv);
723 rv = UpdateMainLibraryListeners(mSyncSettings);
724 NS_ENSURE_SUCCESS(rv, rv);
730 sbDeviceLibrary::SetSyncSettingsNoLock(
733 NS_ENSURE_ARG_POINTER(aSyncSettings);
743 nsAutoMonitor monitor(mMonitor);
745 nsAutoLock lock(syncSettings->
GetLock());
748 rv = mSyncSettings->Assign(syncSettings);
749 NS_ENSURE_SUCCESS(rv, rv);
752 rv = syncSettings->
CreateCopy(getter_AddRefs(mSyncSettings));
753 NS_ENSURE_SUCCESS(rv, rv);
758 nsRefPtr<sbDeviceLibrarySyncSettings> copiedSyncSettings;
759 rv = mSyncSettings->CreateCopy(getter_AddRefs(copiedSyncSettings));
760 NS_ENSURE_SUCCESS(rv, rv);
766 rv = copiedSyncSettings->Write(mDevice);
767 NS_ENSURE_SUCCESS(rv, rv);
773 sbDeviceLibrary::GetSyncFolderListByType(PRUint32 aContentType,
776 NS_ENSURE_ARG_POINTER(_retval);
777 NS_ENSURE_ARG_RANGE(aContentType,
781 NS_ERROR_NOT_IMPLEMENTED);
785 nsCOMPtr<nsIMutableArray>
array =
786 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
787 NS_ENSURE_SUCCESS(rv, rv);
789 nsCOMPtr<sbIDeviceLibraryMediaSyncSettings> mediaSyncSettings;
792 getter_AddRefs(mediaSyncSettings));
793 NS_ENSURE_SUCCESS(rv, rv);
796 rv = mediaSyncSettings->GetMgmtType(&mgmtType);
797 NS_ENSURE_SUCCESS(rv, rv);
801 nsCOMPtr<nsIFile> rootFolder;
802 rv = mediaSyncSettings->GetSyncFromFolder(getter_AddRefs(rootFolder));
803 NS_ENSURE_SUCCESS(rv, rv);
806 rv = array->AppendElement(rootFolder, PR_FALSE);
807 NS_ENSURE_SUCCESS(rv, rv);
813 rv = GetSyncListsPrefKey(aContentType, prefKey);
814 NS_ENSURE_SUCCESS(rv, rv);
816 nsCOMPtr<nsIVariant> var;
817 rv = mDevice->GetPreference(prefKey, getter_AddRefs(var));
818 NS_ENSURE_SUCCESS(rv, rv);
820 nsAutoString foldersDSV;
821 rv = var->GetAsAString(foldersDSV);
822 NS_ENSURE_SUCCESS(rv, rv);
826 PRInt32 end = foldersDSV.FindChar(
'\1', start);
828 end = foldersDSV.Length();
830 while (end > start) {
832 nsDependentSubstring folderPath = Substring(foldersDSV, start, end - start);
834 nsCOMPtr<nsILocalFile> folder;
835 rv = NS_NewLocalFile(folderPath, PR_TRUE, getter_AddRefs(folder));
839 rv = array->AppendElement(folder, PR_FALSE);
840 NS_ENSURE_SUCCESS(rv, rv);
844 end = foldersDSV.FindChar(
'\1', start);
846 end = foldersDSV.Length();
850 NS_ADDREF(*_retval = array);
856 sbDeviceLibrary::SetSyncFolderListByType(PRUint32 aContentType,
857 nsIArray *aFolderList)
859 NS_ENSURE_ARG_POINTER(aFolderList);
860 NS_ENSURE_ARG_RANGE(aContentType,
864 NS_ERROR_NOT_IMPLEMENTED);
869 rv = aFolderList->GetLength(&length);
870 NS_ENSURE_SUCCESS(rv, rv);
873 nsAutoString foldersDSV;
874 for (PRUint32 i = 0; i <
length; i++) {
876 nsCOMPtr<nsIFile> folder = do_QueryElementAt(aFolderList, i, &rv);
877 NS_ENSURE_SUCCESS(rv, rv);
880 nsAutoString folderPath;
881 rv = folder->GetPath(folderPath);
882 NS_ENSURE_SUCCESS(rv, rv);
886 foldersDSV.AppendLiteral(
"\1");
887 foldersDSV.Append(folderPath);
892 rv = GetSyncListsPrefKey(aContentType, prefKey);
893 NS_ENSURE_SUCCESS(rv, rv);
896 rv = mDevice->SetPreference(prefKey,
sbNewVariant(foldersDSV));
897 NS_ENSURE_SUCCESS(rv, rv);
903 sbDeviceLibrary::Sync()
907 nsCOMPtr<sbIDevice>
device;
909 NS_ENSURE_SUCCESS(rv, rv);
911 "sbDeviceLibrary::GetDevice returned success with no device");
913 nsCOMPtr<sbILibraryManager> libraryManager =
914 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
915 NS_ENSURE_SUCCESS(rv, rv);
917 nsCOMPtr<sbILibrary> mainLib;
918 rv = libraryManager->GetMainLibrary(getter_AddRefs(mainLib));
919 NS_ENSURE_SUCCESS(rv, rv);
924 nsCOMPtr<sbIDeviceContent> content;
925 rv = device->GetContent(getter_AddRefs(content));
926 NS_ENSURE_SUCCESS(rv, rv);
928 nsCOMPtr<nsIArray> libraries;
929 rv = content->GetLibraries(getter_AddRefs(libraries));
930 NS_ENSURE_SUCCESS(rv, rv);
932 PRUint32 libraryCount;
933 rv = libraries->GetLength(&libraryCount);
934 NS_ENSURE_SUCCESS(rv, rv);
936 PRBool found = PR_FALSE;
937 for (PRUint32 index = 0; index < libraryCount; ++index) {
938 nsCOMPtr<sbIDeviceLibrary>
library =
939 do_QueryElementAt(libraries, index, &rv);
940 NS_ENSURE_SUCCESS(rv, rv);
942 if (SameCOMIdentity(NS_ISUPPORTS_CAST(sbILibrary*,
this), library)) {
948 "sbDeviceLibrary has device that doesn't hold this library");
952 nsCOMPtr<nsIWritablePropertyBag2> requestParams =
953 do_CreateInstance(NS_HASH_PROPERTY_BAG_CONTRACTID, &rv);
954 NS_ENSURE_SUCCESS(rv, rv);
956 rv = requestParams->SetPropertyAsInterface(NS_LITERAL_STRING(
"item"),
958 NS_ENSURE_SUCCESS(rv, rv);
960 rv = requestParams->SetPropertyAsInterface(NS_LITERAL_STRING(
"list"),
961 NS_ISUPPORTS_CAST(sbIMediaList*,
this));
962 NS_ENSURE_SUCCESS(rv, rv);
965 NS_ENSURE_SUCCESS(rv, rv);
968 rv = UpdateIsReadOnly();
969 NS_ENSURE_SUCCESS(rv, rv);
979 TRACE((
"sbDeviceLibrary[0x%x] - AddListener",
this));
980 NS_ENSURE_ARG_POINTER(aListener);
983 nsAutoMonitor monitor(mMonitor);
985 if (mListeners.Get(aListener, nsnull)) {
986 NS_WARNING(
"Trying to add a listener twice!");
993 nsCOMPtr<sbIDeviceLibraryListener> proxy;
997 NS_PROXY_SYNC | NS_PROXY_ALWAYS,
998 getter_AddRefs(proxy));
999 NS_ENSURE_SUCCESS(rv, rv);
1001 nsAutoMonitor monitor(mMonitor);
1004 PRBool success = mListeners.Put(aListener, proxy);
1005 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
1013 TRACE((
"sbLibraryManager[0x%x] - RemoveListener",
this));
1014 NS_ENSURE_ARG_POINTER(aListener);
1016 nsAutoMonitor monitor(mMonitor);
1019 if (!mListeners.Get(aListener, nsnull)) {
1020 NS_WARNING(
"Trying to remove a listener that was never added!");
1023 mListeners.Remove(aListener);
1038 PLDHashOperator PR_CALLBACK
1039 sbDeviceLibrary::AddListenersToCOMArrayCallback(nsISupportsHashKey::KeyType aKey,
1043 NS_ASSERTION(aKey,
"Null key in hashtable!");
1044 NS_ASSERTION(aEntry,
"Null entry in hashtable!");
1046 nsCOMArray<sbIDeviceLibraryListener>* array =
1047 static_cast<nsCOMArray<sbIDeviceLibraryListener>*
>(aUserData);
1049 PRBool success = array->AppendObject(aEntry);
1050 NS_ENSURE_TRUE(success, PL_DHASH_STOP);
1052 return PL_DHASH_NEXT;
1056 sbDeviceLibrary::OnBatchBegin(sbIMediaList* aMediaList)
1058 TRACE((
"sbDeviceLibrary[0x%x] - OnBatchBegin",
this));
1065 sbDeviceLibrary::OnBatchEnd(sbIMediaList* aMediaList)
1067 TRACE((
"sbDeviceLibrary[0x%x] - OnBatchEnd",
this));
1074 sbDeviceLibrary::OnItemAdded(sbIMediaList* aMediaList,
1075 sbIMediaItem* aMediaItem,
1077 PRBool* aNoMoreForBatch)
1079 TRACE((
"sbDeviceLibrary[0x%x] - OnItemAdded",
this));
1090 sbDeviceLibrary::OnBeforeItemRemoved(sbIMediaList* aMediaList,
1091 sbIMediaItem* aMediaItem,
1093 PRBool* aNoMoreForBatch)
1095 TRACE((
"sbDeviceLibrary[0x%x] - OnBeforeItemRemoved",
this));
1105 sbDeviceLibrary::OnAfterItemRemoved(sbIMediaList* aMediaList,
1106 sbIMediaItem* aMediaItem,
1108 PRBool* aNoMoreForBatch)
1110 TRACE((
"sbDeviceLibrary[0x%x] - OnAfterItemRemoved",
this));
1120 sbDeviceLibrary::OnItemUpdated(sbIMediaList *aMediaList,
1121 sbIMediaItem *aMediaItem,
1123 PRBool* aNoMoreForBatch)
1125 TRACE((
"sbDeviceLibrary[0x%x] - OnItemUpdated",
this));
1135 sbDeviceLibrary::OnItemMoved(sbIMediaList *aMediaList,
1136 PRUint32 aFromIndex,
1138 PRBool* aNoMoreForBatch)
1140 TRACE((
"sbDeviceLibrary[0x%x] - OnItemMoved",
this));
1150 sbDeviceLibrary::OnBeforeListCleared(sbIMediaList *aMediaList,
1151 PRBool aExcludeLists,
1152 PRBool* aNoMoreForBatch)
1154 TRACE((
"sbDeviceLibrary[0x%x] - OnListCleared",
this));
1163 sbDeviceLibrary::OnListCleared(sbIMediaList *aMediaList,
1164 PRBool aExcludeLists,
1165 PRBool* aNoMoreForBatch)
1167 TRACE((
"sbDeviceLibrary[0x%x] - OnListCleared",
this));
1176 sbDeviceLibrary::OnItemCopied(sbIMediaItem *aSourceItem,
1177 sbIMediaItem *aDestItem)
1179 TRACE((
"sbDeviceLibrary[0x%x] - OnItemCopied",
this));
1186 NS_IMETHODIMP sbDeviceLibrary::OnDeviceEvent(
sbIDeviceEvent* aEvent)
1192 rv = aEvent->GetType(&type);
1193 NS_ENSURE_SUCCESS(rv, rv);
1204 PRBool aAllowDuplicates,
1205 sbIMediaItem **_retval)
1207 NS_ASSERTION(mDeviceLibrary,
"mDeviceLibrary is null, call init first.");
1212 if (mPerformAction) {
1214 rv = mDeviceLibrary->CreateMediaItem(aContentUri,
1218 NS_ENSURE_SUCCESS(rv, rv);
1229 sbIMediaItem **aResultItem,
1232 NS_ASSERTION(mDeviceLibrary,
"mDeviceLibrary is null, call init first.");
1237 if (mPerformAction) {
1239 rv = mDeviceLibrary->CreateMediaItemIfNotExist(aContentUri,
1243 NS_ENSURE_SUCCESS(rv, rv);
1254 sbIMediaList **_retval)
1256 NS_ASSERTION(mDeviceLibrary,
"mDeviceLibrary is null, call init first.");
1260 if (mPerformAction) {
1261 return mDeviceLibrary->CreateMediaList(aType, aProperties, _retval);
1273 NS_ENSURE_ARG_POINTER(aDevice);
1274 NS_IF_ADDREF(*aDevice = mDevice);
1275 return *aDevice ?
NS_OK : NS_ERROR_UNEXPECTED;
1284 NS_ASSERTION(mDeviceLibrary,
"mDeviceLibrary is null, call init first.");
1285 return mDeviceLibrary->ClearItems();
1294 NS_ASSERTION(mDeviceLibrary,
"mDevice library is null, call init first.");
1295 return mDeviceLibrary->ClearItemsByType(aContentType);
1304 return AddItem(aMediaItem, nsnull);
1312 sbIMediaItem ** aNewMediaItem)
1314 NS_ASSERTION(mDeviceLibrary,
"mDeviceLibrary is null, call init first.");
1318 if (mPerformAction) {
1319 return mDeviceLibrary->AddItem(aMediaItem, aNewMediaItem);
1331 NS_ASSERTION(mDeviceLibrary,
"mDeviceLibrary is null, call init first.");
1334 if (mPerformAction) {
1336 return mDeviceLibrary->AddAll(aMediaList);
1357 NS_ASSERTION(mDeviceLibrary,
"mDeviceLibrary is null, call init first.");
1361 nsresult rv = NS_ERROR_UNEXPECTED;
1363 if (mPerformAction) {
1364 rv = mDeviceLibrary->AddMediaItems(aMediaItems, aListener, aAsync);
1365 NS_ENSURE_SUCCESS(rv, rv);
1377 NS_ASSERTION(mDeviceLibrary,
"mDeviceLibrary is null, call init first.");
1379 if (mPerformAction) {
1380 return mDeviceLibrary->Clear();
#define SB_PROPERTY_TOTALDISCS
#define SB_NOTIFY_LISTENERS_ASK_PERMISSION(call)
nsresult CreateCopy(sbDeviceLibrarySyncSettings **aSettings)
NS_DECL_ISUPPORTS NS_DECL_NSICLASSINFO NS_DECL_SBIDEVICELIBRARY NS_DECL_SBIMEDIALISTLISTENER NS_DECL_SBILOCALDATABASEMEDIALISTCOPYLISTENER NS_DECL_SBIDEVICEEVENTLISTENER sbDeviceLibrary(sbIDevice *aDevice)
NS_IMETHOD CreateMediaList(const nsAString &aType, sbIPropertyArray *aProperties, sbIMediaList **_retval)
#define SB_PROPERTY_MEDIALISTNAME
#define SB_PROPERTY_PLAYCOUNT
const unsigned long REQUEST_SYNC
#define SB_PROPERTY_SAMPLERATE
NS_IMETHOD AddAll(sbIMediaList *aMediaList)
#define SB_PROPERTY_LYRICS
readonly attribute sbIDevice device
Reference to the device that this library is stored on.
function succeeded(ch, cx, status, data)
#define SB_NOTIFY_LISTENERS_RETURN_FALSE(call)
#define SB_PROPERTY_ALBUMARTISTNAME
#define SB_PROPERTY_RATING
virtual ~sbDeviceLibrary()
#define SB_DEVICE_PROPERTY_ACCESS_COMPATIBILITY
NS_IMETHOD Add(sbIMediaItem *aMediaItem)
#define SB_PROPERTY_CONDUCTORNAME
#define SB_PROPERTY_HIDDEN
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER6(sbDeviceLibrary, nsIClassInfo, sbIDeviceLibrary, sbILibrary, sbIMediaList, sbIMediaItem, sbILibraryResource) sbDeviceLibrary
#define SB_PROPERTY_LYRICISTNAME
nsresult do_GetProxyForObject(nsIEventTarget *aTarget, REFNSIID aIID, nsISupports *aObj, PRInt32 aProxyType, void **aProxyObject)
Songbird Variant Utility Definitions.
#define SB_PROPERTY_LASTPLAYTIME
#define SB_PROPERTY_TOTALTRACKS
Interface used to listen to changes to a device library.
const unsigned long MEDIATYPE_AUDIO
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
#define SB_PROPERTY_BITRATE
const unsigned long MEDIATYPE_IMAGE
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
readonly attribute AString guid
The guid of this resource.
#define SB_PROPERTY_DONT_WRITE_METADATA
#define SB_PROPERTY_CONTENTLENGTH
#define SB_LOCALDATABASE_LIBRARYFACTORY_CONTRACTID
NS_IMETHOD CreateMediaItem(nsIURI *aContentUri, sbIPropertyArray *aProperties, PRBool aAllowDuplicates, sbIMediaItem **_retval)
#define SB_PROPERTY_GENRE
#define SB_PROPERTY_CONTENTTYPE
static sbDeviceLibrarySyncSettings * New(nsID const &aDeviceID, nsAString const &aDeviceLibraryGuid)
General interface to data resources.
#define SB_PROPERTY_SOFTWAREVENDOR
#define SB_PROPERTY_DURATION
#define SB_PROPERTY_ISREADONLY
#define SB_PROPERTY_COPYRIGHT
#define SB_PROPERTY_DISCNUMBER
#define SB_PROPERTY_DEVICE_LIBRARY_GUID
NS_IMETHOD AddMediaItems(nsISimpleEnumerator *aMediaItems, sbIAddMediaItemsListener *aListener, PRBool aAsync)
Media library abstraction.
#define SB_PROPERTY_ARTISTNAME
attribute sbIDeviceLibrarySyncSettings syncSettings
static const char * sbDeviceLibrarySyncUpdatePropertyTable[]
static nsresult GetDefaultDeviceLibraryDatabaseFile(const nsAString &aDeviceIdentifier, nsIFile **aDBFile)
#define SB_PROPERTY_RECORDLABELNAME
#define SB_PROPERTY_ALBUMNAME
char const *const gMediaType[]
#define SB_PROPERTY_LANGUAGE
#define SB_PROPERTY_COMPOSERNAME
#define SB_PROPERTY_PRODUCERNAME
#define SB_PROPERTY_LASTSKIPTIME
nsresult GetMainLibrary(sbILibrary **aMainLibrary)
static nsresult GetMediaSettings(sbIDeviceLibrary *aDevLib, PRUint32 aMediaType, sbIDeviceLibraryMediaSyncSettings **aMediaSettings)
#define SB_PROPERTY_TRACKNAME
NS_IMETHOD AddSome(nsISimpleEnumerator *aMediaItems)
#define SB_NOTIFY_LISTENERS(call)
#define SB_PROPERTY_COMMENT
#define SB_PROPERTY_COPYRIGHTURL
NS_IMETHOD GetDevice(sbIDevice **aDevice)
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
#define SB_PROPERTY_SUBTITLE
_getSelectedPageStyle s i
const unsigned long MEDIATYPE_COUNT
#define SB_PROPERTY_SKIPCOUNT
NS_IMETHOD ClearItemsByType(const nsAString &aContentType)
NS_IMETHOD AddItem(sbIMediaItem *aMediaItem, sbIMediaItem **aNewMediaItem)
NS_IMETHOD CreateMediaItemIfNotExist(nsIURI *aContentUri, sbIPropertyArray *aProperties, sbIMediaItem **aResultItem, PRBool *_retval)
#define SB_PROPERTY_TRACKNUMBER
#define SB_PROPERTY_ISPARTOFCOMPILATION