28 #include <nsArrayUtils.h>
29 #include <nsAutoLock.h>
30 #include <nsAutoPtr.h>
31 #include <nsIProperties.h>
36 #include <sbIDeviceLibrary.h>
37 #include <sbIDeviceLibrarySyncSettings.h>
38 #include <sbILibrary.h>
39 #include <sbILibraryManager.h>
49 NS_ASSERTION(userArg,
"ArrayBuilder passed a null arg");
50 nsIMutableArray *
array =
static_cast<nsIMutableArray*
>(userArg);
52 nsresult rv = array->AppendElement(aKey, PR_FALSE);
53 NS_ENSURE_SUCCESS(rv, PL_DHASH_STOP);
67 sbDeviceLibraryMediaSyncSettings::New(
77 sbDeviceLibraryMediaSyncSettings::sbDeviceLibraryMediaSyncSettings(
83 mMediaType(aMediaType),
86 mSyncSettings(aSyncSettings)
88 mPlaylistsSelection.Init();
91 sbDeviceLibraryMediaSyncSettings::~sbDeviceLibraryMediaSyncSettings()
103 sbDeviceLibraryMediaSyncSettings::Assign(
108 mSyncMgmtType = aSettings->mSyncMgmtType;
109 mMediaType = aSettings->mMediaType;
110 mImport = aSettings->mImport;
112 rv = sbCopyHashtable<PlaylistHashtableTraits>(
113 aSettings->mPlaylistsSelection,
114 mPlaylistsSelection);
115 NS_ENSURE_SUCCESS(rv, rv);
116 mSyncFolder = aSettings->mSyncFolder;
117 rv = aSettings->mSyncFromFolder->Clone(getter_AddRefs(mSyncFromFolder));
118 NS_ENSURE_SUCCESS(rv, rv);
120 mLock = aSettings->mLock;
126 sbDeviceLibraryMediaSyncSettings::CreateCopy(
129 NS_ENSURE_ARG_POINTER(aSettings);
131 nsRefPtr<sbDeviceLibraryMediaSyncSettings> newSettings =
132 sbDeviceLibraryMediaSyncSettings::New(mSyncSettings,
136 newSettings->mSyncMgmtType = mSyncMgmtType;
137 rv = sbCopyHashtable<PlaylistHashtableTraits>(
139 newSettings->mPlaylistsSelection);
140 NS_ENSURE_SUCCESS(rv, rv);
142 newSettings->mImport = mImport;
144 newSettings->mSyncFolder = mSyncFolder;
145 if (mSyncFromFolder) {
146 rv = mSyncFromFolder->Clone(getter_AddRefs(newSettings->mSyncFromFolder));
147 NS_ENSURE_SUCCESS(rv, rv);
150 mSyncFromFolder = nsnull;
152 newSettings.forget(aSettings);
158 sbDeviceLibraryMediaSyncSettings::GetMgmtTypeNoLock(PRUint32 *aSyncMgmtType)
160 NS_ENSURE_ARG_POINTER(aSyncMgmtType);
161 *aSyncMgmtType = mSyncMgmtType;
166 sbDeviceLibraryMediaSyncSettings::GetMgmtType(PRUint32 *aSyncMgmtType)
168 NS_ENSURE_ARG_POINTER(aSyncMgmtType);
169 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
170 nsAutoLock lock(mLock);
171 *aSyncMgmtType = mSyncMgmtType;
177 sbDeviceLibraryMediaSyncSettings::GetLastActiveMgmtType
178 (PRUint32 *aLastActiveSyncMgmtType)
180 NS_ENSURE_ARG_POINTER(aLastActiveSyncMgmtType);
182 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
183 nsAutoLock lock(mLock);
184 *aLastActiveSyncMgmtType = mLastActiveSyncMgmtType;
189 sbDeviceLibraryMediaSyncSettings::SetMgmtType(PRUint32 aSyncMgmtType)
191 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
194 nsAutoLock lock(mLock);
196 mLastActiveSyncMgmtType = mSyncMgmtType;
198 mSyncMgmtType = aSyncMgmtType;
205 sbDeviceLibraryMediaSyncSettings::GetImport(PRBool *aImport)
207 NS_ENSURE_ARG_POINTER(aImport);
208 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
209 nsAutoLock lock(mLock);
210 *aImport = mImport ? PR_TRUE : PR_FALSE;
215 sbDeviceLibraryMediaSyncSettings::SetImport(PRBool aImport)
217 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
220 nsAutoLock lock(mLock);
221 mImport = aImport == PR_TRUE;
228 sbDeviceLibraryMediaSyncSettings::GetSelectedPlaylistsNoLock(
229 nsIArray ** aSelectedPlaylists)
231 NS_ENSURE_ARG_POINTER(aSelectedPlaylists);
234 nsCOMPtr<nsIMutableArray> selected =
235 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
237 mPlaylistsSelection.EnumerateRead(
ArrayBuilder, selected.get());
239 rv = CallQueryInterface(selected, aSelectedPlaylists);
240 NS_ENSURE_SUCCESS(rv, rv);
246 sbDeviceLibraryMediaSyncSettings::GetSelectedPlaylists(
247 nsIArray ** aSelectedPlaylists)
249 NS_ENSURE_ARG_POINTER(aSelectedPlaylists);
250 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
253 nsAutoLock lock(mLock);
255 rv = GetSelectedPlaylistsNoLock(aSelectedPlaylists);
256 NS_ENSURE_SUCCESS(rv, rv);
262 sbDeviceLibraryMediaSyncSettings::SetSelectedPlaylists(
263 nsIArray * aSelectedPlaylists)
265 NS_ENSURE_ARG_POINTER(aSelectedPlaylists);
266 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
271 nsAutoLock lock(mLock);
275 nsCOMPtr<nsISupports> medialist;
277 rv = aSelectedPlaylists->GetLength(&length);
278 NS_ENSURE_SUCCESS(rv, rv);
280 nsCOMPtr<nsISupports> supports;
281 for (PRUint32 index = 0; index < length; ++index) {
282 supports = do_QueryElementAt(aSelectedPlaylists, index, &rv);
283 NS_ENSURE_SUCCESS(rv, rv);
284 mPlaylistsSelection.Put(supports, PR_TRUE);
295 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
298 nsAutoLock lock(mLock);
299 nsCOMPtr<nsISupports> supports = do_QueryInterface(aPlaylist);
300 mPlaylistsSelection.Put(supports, aSelected);
307 sbDeviceLibraryMediaSyncSettings::GetPlaylistSelected(
sbIMediaList *aPlaylist,
310 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
311 nsAutoLock lock(mLock);
313 nsCOMPtr<nsISupports> supports = do_QueryInterface(aPlaylist);
314 PRBool exists = mPlaylistsSelection.Get(supports, aSelected);
316 *aSelected = PR_FALSE;
322 sbDeviceLibraryMediaSyncSettings::ClearSelectedPlaylists()
324 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
327 nsAutoLock lock(mLock);
335 sbDeviceLibraryMediaSyncSettings::GetSyncFolder(nsAString & aSyncFolder)
337 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
338 nsAutoLock lock(mLock);
340 aSyncFolder = mSyncFolder;
346 sbDeviceLibraryMediaSyncSettings::SetSyncFolder(
const nsAString & aSyncFolder)
348 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
351 nsAutoLock lock(mLock);
352 mSyncFolder = aSyncFolder;
359 sbDeviceLibraryMediaSyncSettings::GetSyncFromFolder(nsIFile ** aSyncFromFolder)
361 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
362 nsAutoLock lock(mLock);
366 *aSyncFromFolder = nsnull;
368 if (!mSyncFromFolder) {
369 nsCOMPtr<nsIProperties> directorySvc =
370 do_GetService(
"@mozilla.org/file/directory_service;1", &rv);
371 NS_ENSURE_SUCCESS(rv, rv);
374 rv = directorySvc->Has(
"Pics", &hasProperty);
375 NS_ENSURE_SUCCESS(rv, rv);
379 rv = directorySvc->Get(
"Pics",
381 getter_AddRefs(mSyncFromFolder));
382 NS_ENSURE_SUCCESS(rv, rv);
384 if (!mSyncFromFolder)
388 rv = mSyncFromFolder->Clone(aSyncFromFolder);
389 NS_ENSURE_SUCCESS(rv, rv);
394 sbDeviceLibraryMediaSyncSettings::SetSyncFromFolder(
395 nsIFile * aSyncFromFolder)
397 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
400 nsAutoLock lock(mLock);
401 nsresult rv = aSyncFromFolder->Clone(getter_AddRefs(mSyncFromFolder));
402 NS_ENSURE_SUCCESS(rv, rv);
409 sbDeviceLibraryMediaSyncSettings::GetSyncPlaylistsNoLock(
410 nsIArray ** aSyncPlaylists)
412 NS_ENSURE_ARG_POINTER(aSyncPlaylists);
417 PRUint32 contentType;
418 switch (mMediaType) {
426 return NS_ERROR_NOT_AVAILABLE;
428 nsCOMPtr<sbILibrary> library;
430 NS_ENSURE_SUCCESS(rv, rv);
435 NS_ENSURE_SUCCESS(rv, rv);
441 sbDeviceLibraryMediaSyncSettings::GetSyncPlaylists(nsIArray ** aSyncPlaylists)
443 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
445 nsAutoLock lock(mLock);
446 return GetSyncPlaylistsNoLock(aSyncPlaylists);
452 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
453 return NS_ERROR_NOT_IMPLEMENTED;
459 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
460 return NS_ERROR_NOT_IMPLEMENTED;
sbDeviceLibraryMediaSyncSettings::PlaylistSelection Hashtable
static nsresult GetMediaListByContentType(sbILibrary *aLibrary, PRUint32 aContentType, nsIArray **aMediaLists)
const unsigned long MEDIATYPE_AUDIO
const unsigned long MEDIATYPE_VIDEO
nsresult GetMainLibrary(sbILibrary **aMainLibrary)
_updateTextAndScrollDataForFrame aData