52 #include <sbIDeviceEvent.h>
53 #include <sbIDeviceLibraryMediaSyncSettings.h>
56 #include <nsArrayUtils.h>
71 sbIPDDevice::PrefInitialize()
77 mPrefLock = nsAutoLock::NewLock("
sbIPDDevice::mPrefLock");
78 NS_ENSURE_TRUE(mPrefLock, NS_ERROR_OUT_OF_MEMORY);
81 autoFinalize.forget();
96 nsAutoLock::DestroyLock(mPrefLock);
106 sbIPDDevice::PrefConnect()
112 autoDisconnect(this);
115 rv = PrefConnectIPodPrefs();
116 NS_ENSURE_SUCCESS(rv, rv);
121 nsAutoLock autoPrefLock(mPrefLock);
122 mPrefConnected = PR_TRUE;
126 autoDisconnect.forget();
137 sbIPDDevice::PrefDisconnect()
142 nsAutoLock autoPrefLock(mPrefLock);
143 mPrefConnected = PR_FALSE;
147 PrefDisconnectIPodPrefs();
164 sbIPDDevice::GetMgmtType(PRUint32* aMgmtType)
167 NS_ASSERTION(aMgmtType,
"aMgmtType is null");
170 nsAutoLock autoPrefLock(mPrefLock);
171 NS_ENSURE_TRUE(mPrefConnected, NS_ERROR_NOT_AVAILABLE);
174 if (mIPodPrefs->music_mgmt_type == 0x00) {
177 if (mIPodPrefs->music_update_type == 0x01)
179 else if (mIPodPrefs->music_update_type == 0x02)
182 NS_WARNING(
"Unexpected management type preference.");
183 return NS_ERROR_UNEXPECTED;
198 sbIPDDevice::SetMgmtType(PRUint32 aMgmtType)
204 nsAutoLock autoPrefLock(mPrefLock);
205 NS_ENSURE_TRUE(mPrefConnected, NS_ERROR_NOT_AVAILABLE);
210 mIPodPrefs->music_mgmt_type = 0x00;
214 mIPodPrefs->music_mgmt_type = 0x01;
215 mIPodPrefs->music_update_type = 0x01;
219 mIPodPrefs->music_mgmt_type = 0x01;
220 mIPodPrefs->music_update_type = 0x02;
224 NS_WARNING(
"Invalid management type.");
225 return NS_ERROR_INVALID_ARG;
229 mIPodPrefsDirty = PR_TRUE;
236 NS_ENSURE_SUCCESS(rv, rv);
249 sbIPDDevice::GetIsSetUp(PRBool* aIsSetUp)
252 NS_ASSERTION(aIsSetUp,
"aIsSetUp is null");
255 nsAutoLock autoPrefLock(mPrefLock);
256 NS_ENSURE_TRUE(mPrefConnected, NS_ERROR_NOT_AVAILABLE);
259 *aIsSetUp = (mIPodPrefs->ipod_set_up ? PR_TRUE : PR_FALSE);
272 sbIPDDevice::SetIsSetUp(PRBool aIsSetUp)
278 nsAutoLock autoPrefLock(mPrefLock);
279 NS_ENSURE_TRUE(mPrefConnected, NS_ERROR_NOT_AVAILABLE);
282 mIPodPrefs->ipod_set_up = (aIsSetUp ? 0x01 : 0x00);
285 mIPodPrefsDirty = PR_TRUE;
292 NS_ENSURE_SUCCESS(rv, rv);
305 sbIPDDevice::GetSyncPlaylistList(nsIArray** aPlaylistList)
308 NS_ASSERTION(aPlaylistList,
"aPlaylistList is null");
314 nsAutoLock autoPrefLock(mPrefLock);
315 NS_ENSURE_TRUE(mPrefConnected, NS_ERROR_NOT_AVAILABLE);
318 nsCOMPtr<nsIMutableArray> playlistList =
319 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
320 NS_ENSURE_SUCCESS(rv, rv);
323 PRUint32 playlistCount = mSyncPlaylistList.Length();
324 for (PRUint32
i = 0;
i < playlistCount;
i++) {
327 nsCOMPtr<sbIMediaItem> mediaItem;
328 rv = IDMapGet(mSyncPlaylistList[
i], getter_AddRefs(mediaItem));
333 rv = playlistList->AppendElement(mediaItem, PR_FALSE);
334 NS_ENSURE_SUCCESS(rv, rv);
338 NS_ADDREF(*aPlaylistList = playlistList);
352 sbIPDDevice::SetSyncPlaylistList(nsIArray* aPlaylistList)
355 NS_ASSERTION(aPlaylistList,
"aPlaylistList is null");
363 nsAutoLock autoPrefLock(mPrefLock);
364 NS_ENSURE_TRUE(mPrefConnected, NS_ERROR_NOT_AVAILABLE);
367 PRUint32 playlistCount;
368 rv = aPlaylistList->GetLength(&playlistCount);
369 NS_ENSURE_SUCCESS(rv, rv);
372 mSyncPlaylistList.Clear();
373 success = mSyncPlaylistList.SetCapacity(playlistCount);
374 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
377 for (PRUint32 i = 0; i < playlistCount; i++) {
379 nsCOMPtr<sbIMediaItem> mediaItem = do_QueryElementAt(aPlaylistList,
382 NS_ENSURE_SUCCESS(rv, rv);
386 guint64* pPlaylistID;
387 rv = GetSyncPlaylist(mediaItem, &playlistID);
388 NS_ENSURE_SUCCESS(rv, rv);
389 pPlaylistID = mSyncPlaylistList.AppendElement(playlistID);
390 NS_ENSURE_TRUE(pPlaylistID, NS_ERROR_OUT_OF_MEMORY);
394 mSyncPlaylistListDirty = PR_TRUE;
401 NS_ENSURE_SUCCESS(rv, rv);
418 NS_ASSERTION(aPlaylist,
"aPlaylist is null");
425 nsAutoLock autoPrefLock(mPrefLock);
426 NS_ENSURE_TRUE(mPrefConnected, NS_ERROR_NOT_AVAILABLE);
430 rv = GetSyncPlaylist(aPlaylist, &playlistID);
431 NS_ENSURE_SUCCESS(rv, rv);
434 if (mSyncPlaylistList.Contains(playlistID))
438 guint64* appendSyncPlaylist;
439 appendSyncPlaylist = mSyncPlaylistList.AppendElement(playlistID);
440 NS_ENSURE_TRUE(appendSyncPlaylist, NS_ERROR_OUT_OF_MEMORY);
443 mSyncPlaylistListDirty = PR_TRUE;
450 NS_ENSURE_SUCCESS(rv, rv);
469 NS_ASSERTION(aPlaylist,
"aPlaylist is null");
477 nsTArray<guint64> iPodIDList;
478 rv = GetSBID(aPlaylist, sbID);
479 NS_ENSURE_SUCCESS(rv, rv);
480 rv = IDMapGet(sbID, iPodIDList);
481 if (NS_SUCCEEDED(rv) && !iPodIDList.IsEmpty()) {
482 *aIPodID = iPodIDList[0];
488 guint64 iPodID = (((guint64) g_random_int()) << 32) |
489 ((guint64) g_random_int());
490 rv = IDMapAdd(sbID, iPodID);
491 NS_ENSURE_SUCCESS(rv, rv);
516 sbIPDDevice::PrefConnectIPodPrefs()
518 GError* gError = NULL;
524 autoDisconnect(this);
527 mIPodPrefs = itdb_prefs_parse(mITDB->device, &gError);
531 g_error_free(gError);
534 NS_ENSURE_TRUE(mIPodPrefs, NS_ERROR_FAILURE);
537 guint64* syncPlaylistList;
538 int syncPlaylistCount;
539 success = itdb_update_playlists_read(mITDB->device,
546 g_error_free(gError);
549 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
550 sbAutoGMemPtr autoSyncPlaylistList(syncPlaylistList);
553 mSyncPlaylistList.Clear();
554 guint64* appendSyncPlaylistList =
555 mSyncPlaylistList.AppendElements(syncPlaylistList,
557 NS_ENSURE_TRUE(appendSyncPlaylistList, NS_ERROR_OUT_OF_MEMORY);
560 if (!(mIPodPrefs->valid_file)) {
562 mIPodPrefsDirty = PR_TRUE;
565 NS_ENSURE_SUCCESS(rv, rv);
569 rv = PrefInitializeSyncPartner();
570 NS_ENSURE_SUCCESS(rv, rv);
573 autoDisconnect.forget();
587 sbIPDDevice::PrefDisconnectIPodPrefs()
595 mSyncPlaylistList.Clear();
604 sbIPDDevice::PrefInitializeSyncPartner()
612 nsAutoString sbSyncPartnerID;
613 guint64 iPodSyncPartnerID = mIPodPrefs->music_lib_link_id;
614 rv = IDMapGet(iPodSyncPartnerID, sbSyncPartnerID);
615 if (rv == NS_ERROR_NOT_AVAILABLE) {
616 char sbSyncPartnerIDLiteral[64];
617 PR_snprintf(sbSyncPartnerIDLiteral,
618 sizeof(sbSyncPartnerIDLiteral),
620 (PRUint32) ((iPodSyncPartnerID >> 32) & 0xFFFFFFFF),
621 (PRUint32) (iPodSyncPartnerID & 0xFFFFFFFF));
622 sbSyncPartnerID.AssignLiteral(sbSyncPartnerIDLiteral);
624 NS_ENSURE_SUCCESS(rv, rv);
629 NS_LITERAL_STRING(
"SyncPartner"),
632 NS_ENSURE_SUCCESS(rv, rv);
nsresult CreateAndDispatchEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE, sbIDeviceEventTarget *aTarget=nsnull)
nsresult SetPreferenceInternalNoNotify(const nsAString &aPrefName, nsIVariant *aPrefValue, PRBool *aPrefChanged)
nsresult PushRequest(const PRUint32 aType, sbIMediaItem *aItem=nsnull, sbIMediaList *aList=nsnull, PRUint32 aIndex=PR_UINT32_MAX, PRUint32 aOtherIndex=PR_UINT32_MAX, nsISupports *aData=nsnull)
Songbird iPod Device Definitions.
Songbird iPod Device Logging Definitions.
#define SB_IPD_DEVICE_AUTO_INVOKE(aName, aMethod)
const unsigned long EVENT_DEVICE_PREFS_CHANGED
_getSelectedPageStyle s i