28 #include <sbILibraryManager.h>
29 #include <sbILibrary.h>
30 #include <sbIMediaExportAgentService.h>
32 #include <nsICategoryManager.h>
33 #include <nsIObserverService.h>
34 #include <nsIClassInfoImpl.h>
35 #include <nsIProgrammingLanguage.h>
36 #include <nsIThread.h>
37 #include <nsIProxyObjectManager.h>
38 #include <nsIRunnable.h>
39 #include <nsIThreadManager.h>
40 #include <nsThreadUtils.h>
41 #include <nsIThreadPool.h>
42 #include <nsIUpdateService.h>
44 #include <nsAutoPtr.h>
45 #include <nsArrayUtils.h>
46 #include <nsDirectoryServiceUtils.h>
47 #include <nsComponentManagerUtils.h>
48 #include <nsServiceManagerUtils.h>
68 typename T::const_iterator
const aGuidStringListEnd,
72 NS_ENSURE_ARG_POINTER(aMediaList);
73 NS_ENSURE_ARG_POINTER(aRetVal);
78 nsString mediaListName;
79 rv = aMediaList->GetName(mediaListName);
80 NS_ENSURE_SUCCESS(rv, rv);
81 LOG(
"%s: Enumerate items by guids on media list '%s'",
82 __FUNCTION__, NS_ConvertUTF16toUTF8(mediaListName).
get());
85 nsCOMPtr<sbIMutablePropertyArray> properties =
87 NS_ENSURE_SUCCESS(rv, rv);
91 typename T::const_iterator iter;
92 for (iter = aGuidStringListBegin; iter != aGuidStringListEnd; ++iter) {
93 rv = properties->AppendProperty(guidProperty, *iter);
94 NS_ENSURE_SUCCESS(rv, rv);
97 nsRefPtr<sbMediaListEnumArrayHelper> enumHelper =
99 NS_ENSURE_TRUE(enumHelper, NS_ERROR_OUT_OF_MEMORY);
101 rv = aMediaList->EnumerateItemsByProperties(
105 NS_ENSURE_SUCCESS(rv, rv);
107 return enumHelper->GetMediaItemsArray(aRetVal);
133 sbMediaExportService::sbMediaExportService()
134 : mIsRunning(PR_FALSE)
148 LOG(
"%s: Starting the export service", __FUNCTION__);
152 do_GetService(
"@mozilla.org/observer-service;1", &rv);
153 NS_ENSURE_SUCCESS(rv, rv);
155 rv = observerService->AddObserver(
this,
158 NS_ENSURE_SUCCESS(rv, rv);
160 rv = observerService->AddObserver(
this,
163 NS_ENSURE_SUCCESS(rv, rv);
165 rv = observerService->AddObserver(
this,
"songbird-shutdown", PR_FALSE);
166 NS_ENSURE_SUCCESS(rv, rv);
170 NS_ENSURE_TRUE(mPrefController, NS_ERROR_OUT_OF_MEMORY);
172 rv = mPrefController->Init(
this);
173 NS_ENSURE_SUCCESS(rv, rv);
181 LOG(
"%s: Internal initializing the export service", __FUNCTION__);
184 if (!mPrefController->GetShouldExportAnyMedia()) {
188 mIsRunning = PR_TRUE;
192 nsCOMPtr<sbILibrary> mainLibrary;
194 NS_ENSURE_SUCCESS(rv, rv);
197 NS_ENSURE_SUCCESS(rv, rv);
200 if (mPrefController->GetShouldExportPlaylists() ||
201 mPrefController->GetShouldExportSmartPlaylists())
203 nsCOMPtr<nsIArray> foundPlaylists;
204 rv = mainLibrary->GetItemsByProperty(
206 NS_LITERAL_STRING(
"1"),
207 getter_AddRefs(foundPlaylists));
208 NS_ENSURE_SUCCESS(rv, rv);
211 rv = foundPlaylists->GetLength(&length);
212 NS_ENSURE_SUCCESS(rv, rv);
214 for (PRUint32
i = 0;
i < length;
i++) {
215 nsCOMPtr<sbIMediaList> curMediaList =
216 do_QueryElementAt(foundPlaylists,
i, &rv);
217 if (NS_FAILED(rv) || !curMediaList) {
218 NS_WARNING(
"ERROR: Could not get the current playlist from an array!");
222 PRBool shouldWatch = PR_FALSE;
224 if (NS_SUCCEEDED(rv) && shouldWatch) {
226 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
227 "ERROR: Could not start listening to a media list!");
238 LOG(
"%s: Shutting down export service", __FUNCTION__);
242 do_GetService(
"@mozilla.org/observer-service;1", &rv);
243 NS_ENSURE_SUCCESS(rv, rv);
246 NS_ENSURE_SUCCESS(rv, rv);
249 NS_ENSURE_SUCCESS(rv, rv);
251 rv = mPrefController->Shutdown();
252 NS_ENSURE_SUCCESS(rv, rv);
255 nsCOMPtr<nsIUpdateManager> updateMgr =
256 do_GetService(
"@mozilla.org/updates/update-manager;1", &rv);
257 NS_ENSURE_SUCCESS(rv, rv);
259 PRBool hasPendingUpdates = PR_FALSE;
261 rv = updateMgr->GetUpdateCount(&updateCount);
262 NS_ENSURE_SUCCESS(rv, rv);
264 LOG(
"%s: Found %i updates", __FUNCTION__, updateCount);
266 if (updateCount > 0) {
267 for (PRInt32
i = 0;
i < updateCount && !hasPendingUpdates;
i++) {
268 nsCOMPtr<nsIUpdate> curUpdate;
269 rv = updateMgr->GetUpdateAt(
i, getter_AddRefs(curUpdate));
275 rv = curUpdate->GetState(state);
283 if (state.EqualsLiteral(
"pending")) {
284 hasPendingUpdates = PR_TRUE;
288 if (hasPendingUpdates) {
293 nsCOMPtr<sbIMediaExportAgentService> agentService =
295 if (NS_SUCCEEDED(rv) && agentService) {
297 rv = agentService->KillActiveAgents();
298 NS_ENSURE_SUCCESS(rv, rv);
302 rv = agentService->UnregisterExportAgent();
303 NS_ENSURE_SUCCESS(rv, rv);
314 LOG(
"%s: Removing listeners from all media lists", __FUNCTION__);
320 for (PRInt32
i = 0;
i < mObservedMediaLists.Count();
i++) {
321 nsCOMPtr<sbIMediaList> curMediaList = mObservedMediaLists[
i];
323 NS_WARNING(
"Could not get a the media list reference!");
327 rv = curMediaList->RemoveListener(
this);
328 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
329 "Could not remove media list listener!");
333 rv = curMediaList->GetGuid(listGuid);
334 NS_ENSURE_SUCCESS(rv, rv);
335 LOG(
"%s: Removing listener for media list '%s'",
336 __FUNCTION__, NS_ConvertUTF16toUTF8(listGuid).
get());
342 for (PRInt32
i = 0;
i < mObservedSmartMediaLists.Count();
i++) {
343 nsCOMPtr<sbILocalDatabaseSmartMediaList> curSmartList =
344 mObservedSmartMediaLists[
i];
346 NS_WARNING(
"Could not get a smart media list reference!");
350 rv = curSmartList->RemoveSmartMediaListListener(
this);
351 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
352 "Could not remove the smart media list listener!");
356 rv = curSmartList->GetGuid(listGuid);
357 NS_ENSURE_SUCCESS(rv, rv);
358 LOG(
"%s: Removing listener for smart media list '%s'",
359 __FUNCTION__, NS_ConvertUTF16toUTF8(listGuid).
get());
363 mObservedMediaLists.Clear();
364 mObservedSmartMediaLists.Clear();
367 mAddedItemsMap.clear();
368 mAddedMediaList.clear();
369 mRemovedMediaLists.clear();
371 mIsRunning = PR_FALSE;
379 const PRBool aNewPrefValue)
381 LOG(
"%s: '%s' pref changed : %s",
383 NS_ConvertUTF16toUTF8(aPrefName).
get(),
384 (aNewPrefValue ?
"true" :
"false"));
390 if (!mIsRunning && mPrefController->GetShouldExportAnyMedia()) {
392 NS_ENSURE_SUCCESS(rv, rv);
395 else if (mIsRunning && !mPrefController->GetShouldExportAnyMedia()) {
397 NS_ENSURE_SUCCESS(rv, rv);
402 nsCOMPtr<sbIMediaExportAgentService> agentService =
404 if (NS_SUCCEEDED(rv) && agentService) {
405 rv = agentService->UnregisterExportAgent();
406 NS_ENSURE_SUCCESS(rv, rv);
416 NS_ENSURE_ARG_POINTER(aMediaList);
422 rv = aMediaList->GetGuid(listGuid);
423 NS_ENSURE_SUCCESS(rv, rv);
424 LOG(
"%s: Adding listener for media list '%s",
425 __FUNCTION__, NS_ConvertUTF16toUTF8(listGuid).
get());
429 rv = aMediaList->GetType(listType);
430 NS_ENSURE_SUCCESS(rv, rv);
432 if (listType.EqualsLiteral(
"smart")) {
434 nsCOMPtr<sbILocalDatabaseSmartMediaList> smartList =
435 do_QueryInterface(aMediaList, &rv);
436 NS_ENSURE_SUCCESS(rv, rv);
438 rv = smartList->AddSmartMediaListListener(
this);
439 NS_ENSURE_SUCCESS(rv, rv);
441 NS_ENSURE_TRUE(mObservedSmartMediaLists.AppendObject(smartList),
446 if (!mFilteredProperties) {
447 mFilteredProperties =
449 NS_ENSURE_SUCCESS(rv, rv);
451 rv = mFilteredProperties->SetStrict(PR_FALSE);
452 NS_ENSURE_SUCCESS(rv, rv);
455 rv = mFilteredProperties->AppendProperty(
458 NS_ENSURE_SUCCESS(rv, rv);
461 rv = mFilteredProperties->AppendProperty(
464 NS_ENSURE_SUCCESS(rv, rv);
467 rv = mFilteredProperties->AppendProperty(
470 NS_ENSURE_SUCCESS(rv, rv);
478 rv = aMediaList->AddListener(
this, PR_FALSE, flags, nsnull);
479 NS_ENSURE_SUCCESS(rv, rv);
481 NS_ENSURE_TRUE(mObservedMediaLists.AppendObject(aMediaList),
490 PRBool *aShouldWatch)
492 NS_ENSURE_ARG_POINTER(aMediaList);
493 NS_ENSURE_ARG_POINTER(aShouldWatch);
495 *aShouldWatch = PR_FALSE;
499 nsString mediaListName;
500 rv = aMediaList->GetName(mediaListName);
501 NS_ENSURE_SUCCESS(rv, rv);
502 LOG(
"%s: Deciding if medialist '%s' should be watched.",
503 __FUNCTION__, NS_ConvertUTF16toUTF8(mediaListName).
get());
511 if (NS_FAILED(rv) || propValue.EqualsLiteral(
"download")) {
518 if (NS_SUCCEEDED(rv) && !propValue.IsEmpty()) {
525 if (NS_FAILED(rv) || propValue.EqualsLiteral(
"1")) {
532 if (NS_FAILED(rv) || propValue.EqualsLiteral(
"1")) {
537 rv = aMediaList->GetType(propValue);
538 NS_ENSURE_SUCCESS(rv, rv);
540 if (propValue.EqualsLiteral(
"simple") &&
541 !mPrefController->GetShouldExportPlaylists())
546 if (propValue.EqualsLiteral(
"smart") &&
547 !mPrefController->GetShouldExportSmartPlaylists())
553 *aShouldWatch = PR_TRUE;
561 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
562 "ERROR: Could not begin exporting songbird data!");
570 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
571 "ERROR: Could not notify the listeners!");
577 LOG(
"%s: Writing recorded media changes to task file", __FUNCTION__);
581 LOG(
"%s: Starting to export data", __FUNCTION__);
589 NS_ENSURE_TRUE(mTaskWriter, NS_ERROR_OUT_OF_MEMORY);
591 rv = mTaskWriter->Init();
592 NS_ENSURE_SUCCESS(rv, rv);
595 if (mPrefController->GetShouldExportAnyPlaylists()) {
597 NS_ENSURE_SUCCESS(rv, rv);
600 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not notify listeners!");
603 NS_ENSURE_SUCCESS(rv, rv);
606 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not notify listeners!");
608 if (mPrefController->GetShouldExportSmartPlaylists()) {
610 NS_ENSURE_SUCCESS(rv, rv);
613 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not notify listeners!");
618 if (mPrefController->GetShouldExportTracks()) {
620 NS_ENSURE_SUCCESS(rv, rv);
622 NS_ENSURE_SUCCESS(rv, rv);
626 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not notify listeners!");
628 rv = mTaskWriter->Finish();
629 NS_ENSURE_SUCCESS(rv, rv);
632 LOG(
"%s: Done exporting data", __FUNCTION__);
634 mAddedMediaList.clear();
635 mAddedItemsMap.clear();
636 mRemovedMediaLists.clear();
640 NS_ENSURE_SUCCESS(rv, rv);
643 if (mPrefController->GetShouldStartExportAgent()) {
644 nsCOMPtr<sbIMediaExportAgentService> agentService =
646 if (NS_SUCCEEDED(rv) && agentService) {
647 rv = agentService->StartExportAgent();
648 NS_ENSURE_SUCCESS(rv, rv);
658 if (mAddedMediaList.size() == 0) {
662 LOG(
"%s: Writing added media lists", __FUNCTION__);
664 NS_ENSURE_TRUE(mTaskWriter, NS_ERROR_UNEXPECTED);
667 rv = mTaskWriter->WriteAddedMediaListsHeader();
668 NS_ENSURE_SUCCESS(rv, rv);
674 for (next = begin; next != end; ++
next) {
675 nsCOMPtr<sbIMediaList> curMediaList;
677 if (NS_FAILED(rv) || !curMediaList) {
678 NS_WARNING(
"ERROR: Could not get a media list by GUID!");
682 rv = mTaskWriter->WriteMediaListName(curMediaList);
683 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
684 "ERROR: Could not write the added media list name!");
695 if (mRemovedMediaLists.size() == 0) {
699 LOG(
"%s: Writing removed media lists", __FUNCTION__);
701 NS_ENSURE_TRUE(mTaskWriter, NS_ERROR_UNEXPECTED);
704 rv = mTaskWriter->WriteRemovedMediaListsHeader();
705 NS_ENSURE_SUCCESS(rv, rv);
711 for (next = begin; next != end; ++
next) {
712 rv = mTaskWriter->WriteEscapedString(*next);
713 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
714 "ERROR: Could not write the removed media list name!");
725 if (mAddedItemsMap.size() == 0) {
729 LOG(
"%s: Writing %i media lists with added media items",
730 __FUNCTION__, mAddedItemsMap.size());
732 NS_ENSURE_TRUE(mTaskWriter, NS_ERROR_UNEXPECTED);
735 nsCOMPtr<sbILibrary> mainLibrary;
737 NS_ENSURE_SUCCESS(rv, rv);
739 nsString mainLibraryGuid;
740 rv = mainLibrary->GetGuid(mainLibraryGuid);
741 NS_ENSURE_SUCCESS(rv, rv);
747 for (next = begin; next != end; ++
next) {
748 nsString curMediaListGuid(next->first);
749 nsCOMPtr<sbIMediaList> curParentList;
751 if (NS_FAILED(rv) || !curParentList) {
752 NS_WARNING(
"ERROR: Could not look up a media list by guid!");
757 if (mainLibraryGuid.Equals(curMediaListGuid)) {
758 rv = mTaskWriter->WriteAddedMediaItemsListHeader(curParentList, PR_TRUE);
760 rv = mTaskWriter->WriteAddedMediaItemsListHeader(curParentList);
763 NS_WARNING(
"ERROR: Could not write the media item list header!");
767 nsCOMPtr<nsIArray> addedMediaItems;
768 rv = EnumerateItemsByGuids<sbStringList>(next->second.begin(),
771 getter_AddRefs(addedMediaItems));
772 if (NS_FAILED(rv) || !addedMediaItems) {
773 NS_WARNING(
"ERROR: Could not enumerate media items by guid!");
779 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
780 "ERROR: Could not write out the media items!");
789 TRACE(
"%s: Writing %i updated media items",
791 mUpdatedItems.size());
792 if (mUpdatedItems.empty()) {
796 NS_ENSURE_STATE(mTaskWriter);
800 nsCOMPtr<sbILibrary> mainLibrary;
802 NS_ENSURE_SUCCESS(rv, rv);
804 nsCOMPtr<nsIArray> updatedMediaItems;
805 rv = EnumerateItemsByGuids<sbStringSet>(mUpdatedItems.begin(),
808 getter_AddRefs(updatedMediaItems));
809 if (NS_FAILED(rv) || !updatedMediaItems) {
810 NS_WARNING(
"ERROR: Could not enumerate media items by guid!");
811 return NS_ERROR_FAILURE;;
814 rv = mTaskWriter->WriteUpdatedMediaItemsListHeader();
815 NS_ENSURE_SUCCESS(rv, rv);
818 rv = updatedMediaItems->GetLength(&length);
819 NS_ENSURE_SUCCESS(rv, rv);
821 PRUint32 updatedtemDelta = 0;
823 for (PRUint32
i = 0;
i < length;
i++) {
824 nsCOMPtr<sbIMediaItem> curMediaItem =
825 do_QueryElementAt(updatedMediaItems,
i, &rv);
826 if (NS_FAILED(rv) || !curMediaItem) {
827 NS_WARNING(
"ERROR: Could not get a mediaitem from an array!");
831 rv = mTaskWriter->WriteUpdatedTrack(curMediaItem);
832 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
833 "ERROR: Could not write a smartlist mediaitem!");
841 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
842 "ERROR: Could not notify the listeners!");
847 if (updatedtemDelta > 0) {
849 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
850 "ERROR: Could not notify the listeners!");
859 if (mUpdatedSmartMediaLists.size() == 0) {
863 LOG(
"%s: Writing updated smart playlists", __FUNCTION__);
865 NS_ENSURE_TRUE(mTaskWriter, NS_ERROR_UNEXPECTED);
871 for (next = begin; next != end; ++
next) {
874 nsCOMPtr<sbIMediaList> curSmartMediaList;
876 if (NS_FAILED(rv) || !curSmartMediaList) {
877 NS_WARNING(
"ERROR: Could not get a smart list by GUID!");
881 nsRefPtr<sbMediaListEnumArrayHelper> enumHelper =
883 NS_ENSURE_TRUE(enumHelper, NS_ERROR_OUT_OF_MEMORY);
885 rv = curSmartMediaList->EnumerateAllItems(
888 NS_ENSURE_SUCCESS(rv, rv);
890 nsCOMPtr<nsIArray> mediaItems;
891 rv = enumHelper->GetMediaItemsArray(getter_AddRefs(mediaItems));
892 NS_ENSURE_SUCCESS(rv, rv);
895 rv = mediaItems->GetLength(&length);
896 NS_ENSURE_SUCCESS(rv, rv);
902 rv = mTaskWriter->WriteUpdatedSmartPlaylistHeader(curSmartMediaList);
904 NS_WARNING(
"ERROR: Could not write the updated smartlist header!");
910 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
911 "ERROR: Could not write out the media items!");
920 NS_ENSURE_ARG_POINTER(aItemsArray);
923 nsresult rv = aItemsArray->GetLength(&length);
924 NS_ENSURE_SUCCESS(rv, rv);
926 PRUint32 addedItemDelta = 0;
928 for (PRUint32
i = 0;
i < length;
i++) {
929 nsCOMPtr<sbIMediaItem> curMediaItem =
930 do_QueryElementAt(aItemsArray,
i, &rv);
931 if (NS_FAILED(rv) || !curMediaItem) {
932 NS_WARNING(
"ERROR: Could not get a mediaitem from an array!");
936 rv = mTaskWriter->WriteAddedTrack(curMediaItem);
937 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
938 "ERROR: Could not write a smartlist mediaitem!");
946 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
947 "ERROR: Could not notify the listeners!");
952 if (addedItemDelta > 0) {
954 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
955 "ERROR: Could not notify the listeners!");
965 LOG(
"%s: Getting item by GUID '%s'",
966 __FUNCTION__, NS_ConvertUTF16toUTF8(aItemGuid).
get());
969 nsCOMPtr<sbILibrary> mainLibrary;
971 NS_ENSURE_SUCCESS(rv, rv);
973 nsString mainLibraryGuid;
974 rv = mainLibrary->GetGuid(mainLibraryGuid);
975 NS_ENSURE_SUCCESS(rv, rv);
977 nsCOMPtr<sbIMediaList> itemAsList;
980 if (mainLibraryGuid.Equals(aItemGuid)) {
981 itemAsList = do_QueryInterface(mainLibrary, &rv);
982 NS_ENSURE_SUCCESS(rv, rv);
985 nsCOMPtr<sbIMediaItem> mediaItem;
986 rv = mainLibrary->GetItemByGuid(aItemGuid, getter_AddRefs(mediaItem));
987 NS_ENSURE_SUCCESS(rv, rv);
989 itemAsList = do_QueryInterface(mediaItem, &rv);
990 NS_ENSURE_SUCCESS(rv, rv);
993 itemAsList.swap(*aMediaList);
1000 LOG(
"%s: updating listeners of job progress", __FUNCTION__);
1003 if (!NS_IsMainThread()) {
1006 nsCOMPtr<nsIThread> mainThread;
1007 rv = NS_GetMainThread(getter_AddRefs(mainThread));
1008 NS_ENSURE_SUCCESS(rv, rv);
1010 nsCOMPtr<nsIRunnable> runnable =
1012 NS_ENSURE_TRUE(runnable, NS_ERROR_OUT_OF_MEMORY);
1014 return mainThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
1017 for (PRInt32
i = 0;
i < mJobListeners.Count();
i++) {
1018 rv = mJobListeners[
i]->OnJobProgress(
this);
1019 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
1020 "Could not notify job progress listener!");
1029 return !mAddedItemsMap.empty() ||
1030 !mUpdatedItems.empty() ||
1031 !mAddedMediaList.empty() ||
1032 !mRemovedMediaLists.empty() ||
1033 !mUpdatedSmartMediaLists.empty();
1040 sbMediaExportService::GetHasPendingChanges(PRBool *aHasPendingChanges)
1042 NS_ENSURE_ARG_POINTER(aHasPendingChanges);
1045 LOG(
"%s: Media-export service has pending changes == %s",
1046 __FUNCTION__, (*aHasPendingChanges ?
"true" :
"false"));
1052 sbMediaExportService::ExportSongbirdData()
1054 LOG(
"%s: Exporting songbird data (manual trigger)", __FUNCTION__);
1059 NS_ENSURE_SUCCESS(rv, rv);
1063 nsCOMPtr<nsIThreadPool> threadPoolService =
1065 NS_ENSURE_SUCCESS(rv, rv);
1067 nsCOMPtr<nsIRunnable> runnable =
1069 NS_ENSURE_TRUE(runnable, NS_ERROR_OUT_OF_MEMORY);
1071 return threadPoolService->Dispatch(runnable, NS_DISPATCH_NORMAL);
1078 sbMediaExportService::Observe(
nsISupports *aSubject,
1080 const PRUnichar *
aData)
1082 NS_ENSURE_ARG_POINTER(aTopic);
1084 LOG(
"%s: Topic '%s' observed", __FUNCTION__, aTopic);
1090 do_GetService(
"@mozilla.org/observer-service;1", &rv);
1091 NS_ENSURE_SUCCESS(rv, rv);
1094 NS_ENSURE_SUCCESS(rv, rv);
1097 NS_ENSURE_SUCCESS(rv, rv);
1101 NS_ENSURE_SUCCESS(rv, rv);
1111 sbMediaExportService::OnItemAdded(
sbIMediaList *aMediaList,
1116 LOG(
"%s: Media Item Added!", __FUNCTION__);
1118 NS_ENSURE_ARG_POINTER(aMediaList);
1119 NS_ENSURE_ARG_POINTER(aMediaItem);
1124 rv = aMediaItem->GetGuid(itemGuid);
1125 NS_ENSURE_SUCCESS(rv, rv);
1128 nsCOMPtr<sbIMediaList> itemAsList = do_QueryInterface(aMediaItem, &rv);
1129 if (itemAsList && NS_SUCCEEDED(rv)) {
1130 if (mPrefController->GetShouldExportPlaylists() ||
1131 mPrefController->GetShouldExportSmartPlaylists())
1134 PRBool shouldWatchList = PR_FALSE;
1136 if (NS_SUCCEEDED(rv) && shouldWatchList) {
1138 NS_ENSURE_SUCCESS(rv, rv);
1140 mAddedMediaList.push_back(itemGuid);
1146 nsCOMPtr<sbILibrary> mainLibrary;
1148 NS_ENSURE_SUCCESS(rv, rv);
1149 if (SameCOMIdentity(mainLibrary, aMediaList)) {
1153 nsString itunesGuid;
1156 if (NS_SUCCEEDED(rv) && !itunesGuid.IsEmpty()) {
1163 rv = aMediaList->GetGuid(listGuid);
1164 NS_ENSURE_SUCCESS(rv, rv);
1169 if (guidIter == mAddedItemsMap.end()) {
1172 std::pair<sbMediaListItemMapIter, bool> insertedPair =
1175 NS_ENSURE_TRUE(insertedPair.second, NS_ERROR_FAILURE);
1176 guidIter = insertedPair.first;
1179 guidIter->second.push_back(itemGuid);
1186 sbMediaExportService::OnBeforeItemRemoved(
sbIMediaList *aMediaList,
1196 sbMediaExportService::OnAfterItemRemoved(
sbIMediaList *aMediaList,
1198 PRUint32 aIndex, PRBool *_retval)
1200 LOG(
"%s: After Media Item Removed!!", __FUNCTION__);
1202 if (mPrefController->GetShouldExportPlaylists() ||
1203 mPrefController->GetShouldExportSmartPlaylists())
1206 nsCOMPtr<sbIMediaList> itemAsList = do_QueryInterface(aMediaItem, &rv);
1207 if (NS_SUCCEEDED(rv) && itemAsList) {
1213 rv = itemAsList->GetType(type);
1214 NS_ENSURE_SUCCESS(rv, rv);
1216 if (type.EqualsLiteral(
"smart")) {
1217 nsCOMPtr<sbILocalDatabaseSmartMediaList> itemAsSmartList =
1218 do_QueryInterface(itemAsList, &rv);
1219 NS_ENSURE_SUCCESS(rv, rv);
1221 PRInt32 index = mObservedSmartMediaLists.IndexOf(itemAsSmartList);
1224 rv = itemAsList->GetName(listName);
1225 NS_ENSURE_SUCCESS(rv, rv);
1227 rv = itemAsSmartList->RemoveSmartMediaListListener(
this);
1228 NS_ENSURE_SUCCESS(rv, rv);
1230 mRemovedMediaLists.push_back(listName);
1234 PRInt32 index = mObservedMediaLists.IndexOf(itemAsList);
1237 rv = itemAsList->GetName(listName);
1238 NS_ENSURE_SUCCESS(rv, rv);
1240 mRemovedMediaLists.push_back(listName);
1242 rv = itemAsList->RemoveListener(
this);
1243 NS_ENSURE_SUCCESS(rv, rv);
1245 NS_WARN_IF_FALSE(mObservedMediaLists.RemoveObjectAt(index),
1246 "Could not remove the media list from the observed lists array!");
1256 sbMediaExportService::OnItemUpdated(
sbIMediaList *aMediaList,
1261 LOG(
"%s: Media Item Updated!!", __FUNCTION__);
1263 NS_ENSURE_ARG_POINTER(aMediaList);
1264 NS_ENSURE_ARG_POINTER(aMediaItem);
1265 NS_ENSURE_ARG_POINTER(aProperties);
1266 NS_ENSURE_ARG_POINTER(aRetVal);
1269 *aRetVal = PR_FALSE;
1274 nsCOMPtr<sbILibrary> mainLib;
1276 NS_ENSURE_SUCCESS(rv, rv);
1277 NS_ASSERTION(SameCOMIdentity(mainLib, aMediaList),
1278 "sbMediaExportService::OnItemUpdated: unexpected media list");
1282 nsCOMPtr<sbIMediaList> itemAsList = do_QueryInterface(aMediaItem, &rv);
1283 if (itemAsList && NS_SUCCEEDED(rv)) {
1288 nsString contentUrl;
1291 if (NS_FAILED(rv)) {
1297 nsString itunesGuid;
1300 if (NS_FAILED(rv)) {
1302 NS_NOTREACHED(
"not implemented");
1303 return NS_ERROR_NOT_IMPLEMENTED;
1307 rv = aMediaItem->GetGuid(itemGuid);
1308 NS_ENSURE_SUCCESS(rv, rv);
1311 mUpdatedItems.insert(itemGuid);
1317 sbMediaExportService::OnItemMoved(
sbIMediaList *aMediaList,
1318 PRUint32 aFromIndex,
1322 LOG(
"%s: Media Item Moved!", __FUNCTION__);
1326 sbMediaExportService::OnBeforeListCleared(
sbIMediaList *aMediaList,
1327 PRBool aExcludeLists,
1330 LOG(
"%s: Media List Before Cleared!", __FUNCTION__);
1335 sbMediaExportService::OnListCleared(
sbIMediaList *aMediaList,
1336 PRBool aExcludeLists,
1339 LOG(
"%s: Media List Cleared!", __FUNCTION__);
1344 sbMediaExportService::OnBatchBegin(
sbIMediaList *aMediaList)
1346 LOG(
"%s: Media List Batch Begin!", __FUNCTION__);
1351 sbMediaExportService::OnBatchEnd(
sbIMediaList *aMediaList)
1353 LOG(
"%s: Media List Batch End!", __FUNCTION__);
1363 NS_ENSURE_ARG_POINTER(aSmartMediaList);
1367 rv = aSmartMediaList->GetGuid(listGuid);
1368 NS_ENSURE_SUCCESS(rv, rv);
1370 LOG(
"%s: Observing updated smart media list for '%s'",
1371 __FUNCTION__, NS_ConvertUTF16toUTF8(listGuid).
get());
1374 mUpdatedSmartMediaLists.end(),
1376 if (result == mUpdatedSmartMediaLists.end()) {
1377 mUpdatedSmartMediaLists.push_back(listGuid);
1387 sbMediaExportService::GetStatus(PRUint16 *aStatus)
1389 NS_ENSURE_ARG_POINTER(aStatus);
1395 sbMediaExportService::GetBlocked(PRBool *aBlocked)
1397 NS_ENSURE_ARG_POINTER(aBlocked);
1398 *aBlocked = PR_FALSE;
1403 sbMediaExportService::GetStatusText(nsAString & aStatusText)
1406 NS_LITERAL_STRING(
"mediaexport.shutdowntaskname"));
1410 sbMediaExportService::GetTitleText(nsAString & aTitleText)
1417 sbMediaExportService::GetProgress(PRUint32 *aProgress)
1419 NS_ENSURE_ARG_POINTER(aProgress);
1420 *aProgress = mProgress;
1425 sbMediaExportService::GetTotal(PRUint32 *aTotal)
1427 NS_ENSURE_ARG_POINTER(aTotal);
1433 sbMediaExportService::GetErrorCount(PRUint32 *aErrorCount)
1435 NS_ENSURE_ARG_POINTER(aErrorCount);
1444 NS_ENSURE_ARG_POINTER(aRetVal);
1453 NS_ENSURE_ARG_POINTER(aListener);
1454 NS_ENSURE_TRUE(mJobListeners.AppendObject(aListener), NS_ERROR_FAILURE);
1461 NS_ENSURE_ARG_POINTER(aListener);
1462 NS_WARN_IF_FALSE(mJobListeners.RemoveObject(aListener),
1463 "Could not remove the job progress listener!");
1471 sbMediaExportService::GetNeedsToRunTask(PRBool *aNeedsToRunTask)
1473 NS_ENSURE_ARG_POINTER(aNeedsToRunTask);
1476 *aNeedsToRunTask = PR_FALSE;
1478 rv = GetHasPendingChanges(aNeedsToRunTask);
1479 NS_ENSURE_SUCCESS(rv, rv);
1481 if (!*aNeedsToRunTask && mPrefController->GetShouldExportAnyMedia()) {
1485 nsCOMPtr<nsIFile> taskFileParentFolder;
1486 rv = NS_GetSpecialDirectory(NS_APP_APPLICATION_REGISTRY_DIR,
1487 getter_AddRefs(taskFileParentFolder));
1488 NS_ENSURE_SUCCESS(rv, rv);
1492 nsCOMPtr<nsISimpleEnumerator> dirEnum;
1493 rv = taskFileParentFolder->GetDirectoryEntries(getter_AddRefs(dirEnum));
1494 NS_ENSURE_SUCCESS(rv, rv);
1496 PRBool hasTaskFile = PR_FALSE;
1498 while ((NS_SUCCEEDED(dirEnum->HasMoreElements(&hasMore))) &&
hasMore) {
1499 nsCOMPtr<nsISupports> curItem;
1500 rv = dirEnum->GetNext(getter_AddRefs(curItem));
1501 if (NS_FAILED(rv)) {
1505 nsCOMPtr<nsIFile> curFile = do_QueryInterface(curItem, &rv);
1506 if (NS_FAILED(rv) || !curFile) {
1510 nsString curFileName;
1511 rv = curFile->GetLeafName(curFileName);
1512 if (NS_FAILED(rv)) {
1517 hasTaskFile = PR_TRUE;
1524 nsCOMPtr<sbIMediaExportAgentService> agentService =
1526 if (NS_SUCCEEDED(rv) && agentService) {
1527 PRBool isAgentRunning = PR_FALSE;
1528 rv = agentService->GetIsAgentRunning(&isAgentRunning);
1529 if (NS_SUCCEEDED(rv) && !isAgentRunning) {
1530 *aNeedsToRunTask = PR_TRUE;
1536 if (*aNeedsToRunTask) {
1539 mTotal = mAddedMediaList.size();
1540 mTotal += mRemovedMediaLists.size();
1545 for (listNext = listBegin; listNext != listEnd; ++listNext) {
1546 nsCOMPtr<sbIMediaList> curUpdatedList;
1548 NS_ENSURE_SUCCESS(rv, rv);
1551 rv = curUpdatedList->GetLength(&length);
1552 NS_ENSURE_SUCCESS(rv, rv);
1560 for (next = begin; next != end; ++
next) {
1561 mTotal += next->second.size();
1565 LOG(
"%s: Export service needs to run at shutdown == %s",
1566 __FUNCTION__, (*aNeedsToRunTask ?
"true" :
"false"));
1572 sbMediaExportService::StartTask()
1574 LOG(
"%s: Starting export service shutdown task...", __FUNCTION__);
1578 return ExportSongbirdData();
1587 const char *aLoaderStr,
1589 const nsModuleComponentInfo *aInfo)
1591 NS_ENSURE_ARG_POINTER(aCompMgr);
1592 NS_ENSURE_ARG_POINTER(aPath);
1593 NS_ENSURE_ARG_POINTER(aLoaderStr);
1594 NS_ENSURE_ARG_POINTER(aType);
1595 NS_ENSURE_ARG_POINTER(aInfo);
1597 nsresult rv = NS_ERROR_UNEXPECTED;
1598 nsCOMPtr<nsICategoryManager> catMgr =
1599 do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
1600 NS_ENSURE_SUCCESS(rv, rv);
1602 rv = catMgr->AddCategoryEntry(
"app-startup",
1606 PR_TRUE, PR_TRUE, nsnull);
1607 NS_ENSURE_SUCCESS(rv, rv);
#define SB_PRLOG_SETUP(x)
#define SB_PROPERTY_MEDIALISTNAME
const SB_LIBRARY_MANAGER_READY_TOPIC
static nsCOMPtr< nsIObserverService > observerService
#define SB_LIBRARY_MANAGER_SHUTDOWN_TOPIC
#define SB_PROPERTY_ISSUBSCRIPTION
Generic interface for exposing long running jobs to the UI.
sbDeviceFirmwareAutoCheckForUpdate prototype flags
#define SB_PROPERTY_HIDDEN
const unsigned short STATUS_SUCCEEDED
Constant indicating that the job has completed.
const unsigned short STATUS_RUNNING
Constant indicating that the job is active.
Songbird Thread Pool Service.
nsresult SBGetLocalizedString(nsAString &aString, const nsAString &aKey, const nsAString &aDefault, class nsIStringBundle *aStringBundle)
StringArrayEnumerator prototype hasMore
Implemented to receive notifications from sbIJobProgress interfaces.
nsresult GetMainLibrary(sbILibrary **aMainLibrary)
#define SB_PROPERTY_ISLIST
#define SB_PROPERTY_CUSTOMTYPE
#define SB_PROPERTY_CONTENTURL
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
#define SB_PROPERTY_ITUNES_GUID
_getSelectedPageStyle s i
#define SB_UNUSED_IN_RELEASE(decl)
_updateTextAndScrollDataForFrame aData