sbDeviceLibrarySyncSettings.cpp
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2011 POTI, Inc.
8  * http://www.songbirdnest.com
9  *
10  * This file may be licensed under the terms of of the
11  * GNU General Public License Version 2 (the ``GPL'').
12  *
13  * Software distributed under the License is distributed
14  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
15  * express or implied. See the GPL for the specific language
16  * governing rights and limitations.
17  *
18  * You should have received a copy of the GPL along with this
19  * program. If not, go to http://www.gnu.org/licenses/gpl.html
20  * or write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  *=END SONGBIRD GPL
24  */
25 
27 
28 // Mozilla includes
29 #include <nsArrayUtils.h>
30 #include <nsAutoLock.h>
31 #include <nsAutoPtr.h>
32 #include <nsILocalFile.h>
33 #include <nsThreadUtils.h>
34 
35 // Songbird local includes
36 #include "sbDeviceLibrary.h"
38 
39 // Songibrd includes
40 
41 #include <sbArrayUtils.h>
42 #include <sbDeviceUtils.h>
43 #include <sbIDevice.h>
44 #include <sbIPropertyArray.h>
45 #include <sbIPropertyManager.h>
46 #include <sbPropertiesCID.h>
48 #include <sbStandardProperties.h>
49 #include <sbStringUtils.h>
50 #include <sbVariantUtils.h>
51 
52 extern PLDHashOperator ArrayBuilder(nsISupports * aKey,
53  PRBool aData,
54  void* userArg);
55 
56 PRUint32 const LEGACY_MGMT_TYPE_MANUAL = 0x1;
57 
61 static void
63 {
64  // Legacy values from the old sync settings system
65  PRUint32 const LEGACY_SYNC_NONE = 0x0;
66  PRUint32 const LEGACY_SYNC_ALL = 0x2;
67  PRUint32 const LEGACY_MANUAL_SYNC_ALL = 0x3;
68  PRUint32 const LEGACY_SYNC_PLAYLISTS = 0x4;
69  PRUint32 const LEGACY_MANUAL_SYNC_PLAYLISTS = 0x5;
70 
71  switch (aValue) {
75  // aValue is already an acceptable value, no need to migrate
76  break;
77  case LEGACY_SYNC_NONE:
79  break;
80  case LEGACY_SYNC_ALL:
81  case LEGACY_MANUAL_SYNC_ALL:
83  break;
84  case LEGACY_SYNC_PLAYLISTS:
85  case LEGACY_MANUAL_SYNC_PLAYLISTS:
87  break;
88  default:
89  // unexpected aValue, default to SYNC_MGMT_NONE
91  break;
92  }
93 }
94 
96 
98  nsID const & aDeviceID,
99  nsAString const & aDeviceLibraryGuid)
100 {
101  return new sbDeviceLibrarySyncSettings(aDeviceID,
102  aDeviceLibraryGuid);
103 }
104 
105 sbDeviceLibrarySyncSettings::sbDeviceLibrarySyncSettings(
106  nsID const & aDeviceID,
107  nsAString const & aDeviceLibraryGuid) :
108  mDeviceID(aDeviceID),
109  mDeviceLibraryGuid(aDeviceLibraryGuid),
110  mLock(nsAutoLock::NewLock("sbDeviceLibrarySyncSettings"))
111 {
112  mMediaSettings.SetLength(sbIDeviceLibrary::MEDIATYPE_COUNT);
113 }
114 
115 sbDeviceLibrarySyncSettings::~sbDeviceLibrarySyncSettings()
116 {
117  nsAutoLock::DestroyLock(mLock);
118 }
119 
121  sbDeviceLibrarySyncSettings * aSource)
122 {
123  NS_ENSURE_ARG_POINTER(aSource);
124 
125  nsresult rv;
126 
127  // Check for assignment to self
128  // We can do a simple check since this will always be a
129  // simple object
130  if (this == aSource) {
131  return NS_OK;
132  }
133 
134  mDeviceID = aSource->mDeviceID;
135  mDeviceLibraryGuid = aSource->mDeviceLibraryGuid;
136 
137  // Copy the media setting entries
138  nsRefPtr<sbDeviceLibraryMediaSyncSettings> mediaSettings;
139  nsRefPtr<sbDeviceLibraryMediaSyncSettings> newMediaSettings;
140  for (PRUint32 mediaType = sbIDeviceLibrary::MEDIATYPE_AUDIO;
142  ++mediaType) {
143  mediaSettings = aSource->mMediaSettings[mediaType];
144  if (mediaSettings) {
145  rv = mediaSettings->CreateCopy(getter_AddRefs(newMediaSettings));
146  NS_ENSURE_SUCCESS(rv, rv);
147 
148  mMediaSettings[mediaType] = newMediaSettings;
149  }
150  }
151  return NS_OK;
152 }
153 
155  sbDeviceLibrarySyncSettings ** aSettings)
156 {
157  NS_ENSURE_ARG_POINTER(aSettings);
158  nsresult rv;
159 
160  nsRefPtr<sbDeviceLibrarySyncSettings> settings =
161  sbDeviceLibrarySyncSettings::New(mDeviceID, mDeviceLibraryGuid);
162  NS_ENSURE_TRUE(settings, NS_ERROR_OUT_OF_MEMORY);
163 
164  rv = settings->Assign(this);
165  NS_ENSURE_SUCCESS(rv, rv);
166 
167  settings.forget(aSettings);
168 
169  return NS_OK;
170 }
171 
172 
173 NS_IMETHODIMP
174 sbDeviceLibrarySyncSettings::GetMediaSettings(
175  PRUint32 aMediaType,
176  sbIDeviceLibraryMediaSyncSettings ** aMediaSettings)
177 {
178  NS_ASSERTION(mLock, "sbDeviceLibrarySyncSettings not initialized");
179 
180  nsAutoLock lock(mLock);
181  return GetMediaSettingsNoLock(aMediaType, aMediaSettings);
182 }
183 
184 nsresult
185 sbDeviceLibrarySyncSettings::GetMediaSettingsNoLock(
186  PRUint32 aMediaType,
187  sbIDeviceLibraryMediaSyncSettings ** aMediaSettings)
188 {
189  NS_ASSERTION(aMediaSettings,
190  "aMediaSettings is null in "
191  "DeviceLibrarySyncSettings::GetMediaSettingsNoLock");
192  nsRefPtr<sbDeviceLibraryMediaSyncSettings> newSettings =
193  mMediaSettings[aMediaType];
194  // If we don't have one, create a default one
195  if (!newSettings) {
196  newSettings = sbDeviceLibraryMediaSyncSettings::New(this,
197  aMediaType,
198  mLock);
199  NS_ENSURE_TRUE(newSettings, NS_ERROR_OUT_OF_MEMORY);
200 
201  mMediaSettings[aMediaType] = newSettings;
202  }
203  else {
204  newSettings->SetSyncSettings(this);
205  }
206 
207  *aMediaSettings =
208  static_cast<sbIDeviceLibraryMediaSyncSettings*>(newSettings.get());
209  newSettings.forget();
210 
211  return NS_OK;
212 }
213 
214 NS_IMETHODIMP
215 sbDeviceLibrarySyncSettings::GetSyncPlaylists(nsIArray ** aMediaLists)
216 {
217  NS_ASSERTION(mLock, "sbDeviceLibrarySyncSettings not initialized");
218  nsresult rv;
219 
220  nsCOMPtr<nsIMutableArray> allPlaylists =
221  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
222  NS_ENSURE_SUCCESS(rv, rv);
223 
224  nsAutoLock lock(mLock);
225 
226  nsCOMPtr<sbDeviceLibraryMediaSyncSettings> mediaSettings;
227  for (PRUint32 mediaType = sbIDeviceLibrary::MEDIATYPE_AUDIO;
229  ++mediaType) {
230 
231  mediaSettings = mMediaSettings[mediaType];
232  if (!mediaSettings) {
233  continue;
234  }
235 
236  PRUint32 mgmtType;
237  rv = mediaSettings->GetMgmtTypeNoLock(&mgmtType);
238  NS_ENSURE_SUCCESS(rv, rv);
239 
240  nsCOMPtr<nsIArray> playlists;
242  // TODO: removed buggy/deadlocky code. This is used by the code for
243  // determining whether things will fit on the device, but that code needs
244  // a total rewrite anyway.
245  }
247  rv = mediaSettings->GetSelectedPlaylistsNoLock(getter_AddRefs(playlists));
248  NS_ENSURE_SUCCESS(rv, rv);
249  }
250 
251  if (playlists) {
252  rv = sbAppendnsIArray(playlists, allPlaylists);
253  NS_ENSURE_SUCCESS(rv, rv);
254  }
255  }
256 
257  rv = CallQueryInterface(allPlaylists, aMediaLists);
258  NS_ENSURE_SUCCESS(rv, rv);
259 
260  return NS_OK;
261 }
262 
263 nsresult
264 sbDeviceLibrarySyncSettings::GetMgmtTypePref(sbIDevice * aDevice,
265  PRUint32 aContentType,
266  PRUint32 & aMgmtTypes)
267 {
268  NS_ENSURE_ARG_POINTER(aDevice);
269 
270  NS_ENSURE_ARG_RANGE(aContentType,
272  sbIDeviceLibrary::MEDIATYPE_COUNT - 1);
273 
274  nsresult rv;
275 
276  nsString prefKey;
277  rv = GetMgmtTypePrefKey(aContentType, prefKey);
278  NS_ENSURE_SUCCESS(rv, rv);
279 
280  nsCOMPtr<nsIVariant> var;
281  rv = aDevice->GetPreference(prefKey, getter_AddRefs(var));
282  NS_ENSURE_SUCCESS(rv, rv);
283 
284  // check if a value exists
285  PRUint16 dataType;
286  rv = var->GetDataType(&dataType);
287  PRUint32 mgmtType;
288  // If there is no value, set to manual
289  if (dataType == nsIDataType::VTYPE_VOID ||
290  dataType == nsIDataType::VTYPE_EMPTY)
291  {
293  } else {
294  // has a value
295  rv = var->GetAsUint32(&mgmtType);
296  NS_ENSURE_SUCCESS(rv, rv);
297 
298  MigrateLegacyMgmtValues(mgmtType);
299 
300  // Double check that it is a valid number
301  NS_ENSURE_ARG(
305 
306  }
307 
308  // Return the management type
309  aMgmtTypes = mgmtType;
310 
311  return NS_OK;
312 }
313 
314 nsresult
315 sbDeviceLibrarySyncSettings::GetImportPref(sbIDevice * aDevice,
316  PRUint32 aContentType,
317  PRBool & aImport)
318 {
319  NS_ENSURE_ARG_POINTER(aDevice);
320 
321  NS_ENSURE_ARG_RANGE(aContentType,
323  sbIDeviceLibrary::MEDIATYPE_COUNT - 1);
324 
325  nsresult rv;
326 
327  nsString prefKey;
328  rv = GetImportPrefKey(aContentType, prefKey);
329  NS_ENSURE_SUCCESS(rv, rv);
330 
331  nsCOMPtr<nsIVariant> var;
332  rv = aDevice->GetPreference(prefKey, getter_AddRefs(var));
333  NS_ENSURE_SUCCESS(rv, rv);
334 
335  // check if a value exists
336  PRUint16 dataType;
337  rv = var->GetDataType(&dataType);
338  // If there is no value default to false
339  if (dataType == nsIDataType::VTYPE_VOID ||
340  dataType == nsIDataType::VTYPE_EMPTY)
341  {
342  aImport = PR_FALSE;
343  } else {
344  // has a value
345  rv = var->GetAsBool(&aImport);
346  NS_ENSURE_SUCCESS(rv, rv);
347  }
348 
349  return NS_OK;
350 }
351 
352 template <class T>
353 nsresult
354 sbDeviceLibrarySyncSettings::WritePref(sbIDevice * aDevice,
355  nsAString const & aPrefKey,
356  T aValue)
357 {
358  NS_ENSURE_ARG_POINTER(aDevice);
359 
360  nsresult rv;
361 
362  rv = aDevice->SetPreference(aPrefKey, sbNewVariant(aValue));
363  NS_ENSURE_SUCCESS(rv, rv);
364 
365  return NS_OK;
366 }
367 
368 nsresult
369 sbDeviceLibrarySyncSettings::ReadAString(sbIDevice * aDevice,
370  nsAString const & aPrefKey,
371  nsAString & aString,
372  nsAString const & aDefault)
373 {
374  NS_ENSURE_ARG_POINTER(aDevice);
375 
376  nsresult rv;
377 
378  nsCOMPtr<nsIVariant> var;
379  rv = aDevice->GetPreference(aPrefKey, getter_AddRefs(var));
380  NS_ENSURE_SUCCESS(rv, rv);
381 
382  PRUint16 dataType;
383  rv = var->GetDataType(&dataType);
384  if (dataType == nsIDataType::VTYPE_VOID) {
385  aString = aDefault;
386  }
387  rv = var->GetAsAString(aString);
388  NS_ENSURE_SUCCESS(rv, rv);
389 
390  return NS_OK;
391 }
392 
393 nsresult
394 sbDeviceLibrarySyncSettings::ReadMediaSyncSettings(
395  sbIDevice * aDevice,
396  sbIDeviceLibrary * aDeviceLibrary,
397  PRUint32 aMediaType,
398  sbDeviceLibraryMediaSyncSettings ** aMediaSyncSettings)
399 {
400  NS_ENSURE_ARG_POINTER(aDevice);
401  NS_ENSURE_ARG_POINTER(aMediaSyncSettings);
402 
403  nsresult rv;
404 
405  nsRefPtr<sbDeviceLibraryMediaSyncSettings> settings =
406  sbDeviceLibraryMediaSyncSettings::New(this,
407  aMediaType,
408  mLock);
409  NS_ENSURE_TRUE(settings, NS_ERROR_OUT_OF_MEMORY);
410 
411  // Set the import flag
412  PRBool import;
413  rv = GetImportPref(aDevice, aMediaType, import);
414  NS_ENSURE_SUCCESS(rv, rv);
415  rv = settings->SetImport(import);
416  NS_ENSURE_SUCCESS(rv, rv);
417 
418  PRUint32 mgmtType;
419  rv = GetMgmtTypePref(aDevice, aMediaType, mgmtType);
420  NS_ENSURE_SUCCESS(rv, rv);
421  settings->SetMgmtType(mgmtType);
422 
423  nsCOMPtr<nsIArray> mediaLists;
424  nsString prefKey;
425  rv = settings->GetSyncPlaylistsNoLock(getter_AddRefs(mediaLists));
426  // Some media types won't have playlists
427  if (rv != NS_ERROR_NOT_AVAILABLE) {
428  NS_ENSURE_SUCCESS(rv, rv);
429 
430  settings->mPlaylistsSelection.Clear();
431 
432  PRUint32 count;
433  rv = mediaLists->GetLength(&count);
434  NS_ENSURE_SUCCESS(rv, rv);
435 
436  for (PRUint32 index = 0; index < count; ++index) {
437  nsCOMPtr<sbIMediaList> mediaList = do_QueryElementAt(mediaLists,
438  index,
439  &rv);
440  NS_ENSURE_SUCCESS(rv, rv);
441 
442  nsCOMPtr<nsISupports> supports = do_QueryInterface(mediaList, &rv);
443  NS_ENSURE_SUCCESS(rv, rv);
444 
445  PRBool added = settings->mPlaylistsSelection.Put(supports, PR_FALSE);
446  NS_ENSURE_TRUE(added, NS_ERROR_OUT_OF_MEMORY);
447  }
448  rv = GetSyncListsPrefKey(aMediaType, prefKey);
449  NS_ENSURE_SUCCESS(rv, rv);
450 
451  nsString mediaListGuids;
452  rv = ReadAString(aDevice, prefKey, mediaListGuids, nsString());
453 
454  nsCOMPtr<sbILibraryManager> libManager =
455  do_GetService("@songbirdnest.com/Songbird/library/Manager;1", &rv);
456  NS_ENSURE_SUCCESS(rv, rv);
457 
458  nsCOMPtr<sbILibrary> mainLibrary;
459  rv = libManager->GetMainLibrary(getter_AddRefs(mainLibrary));
460  NS_ENSURE_SUCCESS(rv, rv);
461 
462  nsTArray<nsString> mediaListGuidArray;
463  nsString_Split(mediaListGuids, NS_LITERAL_STRING(","), mediaListGuidArray);
464  count = mediaListGuidArray.Length();
465  for (PRUint32 index = 0; index < count; ++index) {
466  nsCOMPtr<sbIMediaItem> mediaItem;
467  rv = mainLibrary->GetItemByGuid(mediaListGuidArray[index],
468  getter_AddRefs(mediaItem));
469  if (rv != NS_ERROR_NOT_AVAILABLE) {
470  NS_ENSURE_SUCCESS(rv, rv);
471  nsCOMPtr<nsISupports> supports = do_QueryInterface(mediaItem, &rv);
472  NS_ENSURE_SUCCESS(rv, rv);
473 
474  // We don't want to add to this list just set them to true if they match
475  PRBool selected;
476  PRBool exists = settings->mPlaylistsSelection.Get(supports, &selected);
477  if (exists) {
478  PRBool added = settings->mPlaylistsSelection.Put(supports, PR_TRUE);
479  NS_ENSURE_TRUE(added, NS_ERROR_OUT_OF_MEMORY);
480  }
481  }
482  }
483  }
484 
485  rv = GetSyncFolderPrefKey(aMediaType, prefKey);
486  NS_ENSURE_SUCCESS(rv, rv);
487  rv = ReadAString(aDevice, prefKey, settings->mSyncFolder, nsString());
488  NS_ENSURE_SUCCESS(rv, rv);
489 
490  rv = GetSyncFromFolderPrefKey(aMediaType, prefKey);
491  NS_ENSURE_SUCCESS(rv, rv);
492 
493  nsString syncFromFolderString;
494  rv = ReadAString(aDevice, prefKey, syncFromFolderString, nsString());
495  NS_ENSURE_SUCCESS(rv, rv);
496 
497  if (!syncFromFolderString.IsEmpty()) {
498  nsCOMPtr<nsILocalFile> folder;
499  rv = NS_NewLocalFile(syncFromFolderString,
500  PR_TRUE,
501  getter_AddRefs(folder));
502  NS_ENSURE_SUCCESS(rv, rv);
503 
504  settings->mSyncFromFolder = folder;
505  }
506  settings.forget(aMediaSyncSettings);
507 
508  return NS_OK;
509 }
510 
511 nsresult
512 sbDeviceLibrarySyncSettings::WriteMediaSyncSettings(
513  sbIDevice * aDevice,
514  PRUint32 aMediaType,
515  sbDeviceLibraryMediaSyncSettings * aMediaSyncSettings)
516 {
517  NS_ENSURE_ARG_POINTER(aDevice);
518  NS_ENSURE_ARG_POINTER(aMediaSyncSettings);
519 
520  nsresult rv;
521 
522  nsString prefKey;
523  rv = GetMgmtTypePrefKey(aMediaType, prefKey);
524  NS_ENSURE_SUCCESS(rv, rv);
525 
526  rv = WritePref(aDevice,
527  prefKey,
528  aMediaSyncSettings->mSyncMgmtType);
529  NS_ENSURE_SUCCESS(rv, rv);
530 
531  rv = GetImportPrefKey(aMediaType, prefKey);
532  NS_ENSURE_SUCCESS(rv, rv);
533  rv = WritePref(aDevice,
534  prefKey,
535  aMediaSyncSettings->mImport);
536  NS_ENSURE_SUCCESS(rv, rv);
537 
538  rv = GetSyncFromFolderPrefKey(aMediaType, prefKey);
539  NS_ENSURE_SUCCESS(rv, rv);
540 
541  nsString syncFromFolderString;
542  if (aMediaSyncSettings->mSyncFromFolder) {
543  rv = aMediaSyncSettings->mSyncFromFolder->GetPath(syncFromFolderString);
544  NS_ENSURE_SUCCESS(rv, rv);
545  }
546  rv = WritePref(aDevice, prefKey, syncFromFolderString);
547  NS_ENSURE_SUCCESS(rv, rv);
548 
549  rv = GetSyncFolderPrefKey(aMediaType, prefKey);
550  NS_ENSURE_SUCCESS(rv, rv);
551 
552  rv = WritePref(aDevice, prefKey, aMediaSyncSettings->mSyncFolder);
553  NS_ENSURE_SUCCESS(rv, rv);
554 
555  // Ignore sync playlists writing for image.
556  if (aMediaType == sbIDeviceLibrary::MEDIATYPE_IMAGE)
557  return NS_OK;
558 
559  rv = GetSyncListsPrefKey(aMediaType, prefKey);
560  NS_ENSURE_SUCCESS(rv, rv);
561 
562  nsCOMPtr<nsIMutableArray> selected =
563  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
564  aMediaSyncSettings->mPlaylistsSelection.EnumerateRead(ArrayBuilder,
565  selected.get());
566 
567  PRUint32 count;
568  rv = selected->GetLength(&count);
569  NS_ENSURE_SUCCESS(rv, rv);
570 
571  nsString mediaListGuids;
572  nsCOMPtr<sbIMediaList> mediaList;
573  for (PRUint32 index = 0; index < count; ++index) {
574  if (count) {
575  mediaListGuids.Append(NS_LITERAL_STRING(","));
576  }
577  mediaList = do_QueryElementAt(selected, index, &rv);
578  NS_ENSURE_SUCCESS(rv, rv);
579 
580  nsString guid;
581  rv = mediaList->GetGuid(guid);
582  NS_ENSURE_SUCCESS(rv, rv);
583 
584  mediaListGuids.Append(guid);
585  }
586  rv = WritePref(aDevice, prefKey, mediaListGuids);
587  NS_ENSURE_SUCCESS(rv, rv);
588 
589  return NS_OK;
590 }
591 
592 nsresult
594  sbIDeviceLibrary * aDeviceLibrary)
595 {
596  NS_ENSURE_ARG_POINTER(aDevice);
597 
598  nsresult rv;
599 
600  nsRefPtr<sbDeviceLibraryMediaSyncSettings> mediaSettings;
601  for (PRUint32 mediaType = sbIDeviceLibrary::MEDIATYPE_AUDIO;
603  ++mediaType) {
604  if (mMediaSettings[mediaType]) {
605  rv = mediaSettings->Assign(mMediaSettings[mediaType]);
606  NS_ENSURE_SUCCESS(rv, rv);
607  }
608  else {
609  rv = ReadMediaSyncSettings(aDevice,
610  aDeviceLibrary,
611  mediaType,
612  getter_AddRefs(mediaSettings));
613  NS_ENSURE_SUCCESS(rv, rv);
614 
615  mMediaSettings[mediaType] = mediaSettings;
616  }
617  }
618  return NS_OK;
619 }
620 
621 NS_IMETHODIMP
622 sbDeviceLibrarySyncSettings::Write(sbIDevice * aDevice)
623 {
624  NS_ENSURE_ARG_POINTER(aDevice);
625 
626  nsresult rv;
627 
628  nsRefPtr<sbDeviceLibraryMediaSyncSettings> mediaSettings;
629  for (PRUint32 mediaType = sbIDeviceLibrary::MEDIATYPE_AUDIO;
631  ++mediaType) {
632  mediaSettings = mMediaSettings[mediaType];
633  if (mediaSettings) {
634  rv = WriteMediaSyncSettings(aDevice,
635  mediaType,
636  mediaSettings);
637  NS_ENSURE_SUCCESS(rv, rv);
638  }
639  }
640  return NS_OK;
641 }
642 
643 nsresult
644 sbDeviceLibrarySyncSettings::GetMgmtTypePrefKey(PRUint32 aContentType,
645  nsAString& aPrefKey)
646 {
647  NS_ENSURE_ARG_RANGE(aContentType,
649  sbIDeviceLibrary::MEDIATYPE_COUNT - 1);
650  NS_ENSURE_STATE(!mDeviceLibraryGuid.IsEmpty());
651 
652 
653  // Get the preference key
654  aPrefKey.Assign(NS_LITERAL_STRING(PREF_SYNC_PREFIX));
655  aPrefKey.Append(mDeviceLibraryGuid);
656  aPrefKey.AppendLiteral(PREF_SYNC_BRANCH PREF_SYNC_MGMTTYPE);
657 
658  aPrefKey.AppendLiteral(gMediaType[aContentType]);
659 
660  return NS_OK;
661 }
662 
663 nsresult
664 sbDeviceLibrarySyncSettings::GetImportPrefKey(PRUint32 aContentType,
665  nsAString& aPrefKey)
666 {
667  NS_ENSURE_ARG_RANGE(aContentType,
669  sbIDeviceLibrary::MEDIATYPE_COUNT - 1);
670  NS_ENSURE_STATE(!mDeviceLibraryGuid.IsEmpty());
671 
672 
673  // Get the preference key
674  aPrefKey.Assign(NS_LITERAL_STRING(PREF_SYNC_PREFIX));
675  aPrefKey.Append(mDeviceLibraryGuid);
676  aPrefKey.AppendLiteral(PREF_SYNC_BRANCH PREF_SYNC_IMPORT);
677 
678  aPrefKey.AppendLiteral(gMediaType[aContentType]);
679 
680  return NS_OK;
681 }
682 
683 nsresult
684 sbDeviceLibrarySyncSettings::GetSyncListsPrefKey(PRUint32 aContentType,
685  nsAString& aPrefKey)
686 {
687  NS_ENSURE_ARG_RANGE(aContentType,
689  sbIDeviceLibrary::MEDIATYPE_COUNT - 1);
690  NS_ENSURE_STATE(!mDeviceLibraryGuid.IsEmpty());
691 
692  // Get the preference key
693  aPrefKey.Assign(NS_LITERAL_STRING(PREF_SYNC_PREFIX));
694  aPrefKey.Append(mDeviceLibraryGuid);
695  aPrefKey.AppendLiteral(PREF_SYNC_BRANCH);
696  aPrefKey.AppendLiteral(PREF_SYNC_LISTS);
697  aPrefKey.AppendLiteral(gMediaType[aContentType]);
698 
699  return NS_OK;
700 }
701 
702 nsresult
703 sbDeviceLibrarySyncSettings::GetSyncFromFolderPrefKey(PRUint32 aContentType,
704  nsAString& aPrefKey)
705 {
706  NS_ENSURE_ARG_RANGE(aContentType,
708  sbIDeviceLibrary::MEDIATYPE_COUNT - 1);
709  NS_ENSURE_STATE(!mDeviceLibraryGuid.IsEmpty());
710 
711  // Get the preference key
712  aPrefKey.Assign(NS_LITERAL_STRING(PREF_SYNC_PREFIX));
713  aPrefKey.Append(mDeviceLibraryGuid);
714  aPrefKey.AppendLiteral(PREF_SYNC_BRANCH);
715  aPrefKey.AppendLiteral(PREF_SYNC_ROOT);
716  aPrefKey.AppendLiteral(gMediaType[aContentType]);
717 
718  return NS_OK;
719 }
720 
721 nsresult
722 sbDeviceLibrarySyncSettings::GetSyncFolderPrefKey(PRUint32 aContentType,
723  nsAString& aPrefKey)
724 {
725  NS_ENSURE_ARG_RANGE(aContentType,
727  sbIDeviceLibrary::MEDIATYPE_COUNT - 1);
728  NS_ENSURE_STATE(!mDeviceLibraryGuid.IsEmpty());
729 
730  // Get the preference key
731  aPrefKey.Assign(NS_LITERAL_STRING(PREF_SYNC_PREFIX));
732  aPrefKey.Append(mDeviceLibraryGuid);
733  aPrefKey.AppendLiteral(PREF_SYNC_BRANCH);
734  aPrefKey.AppendLiteral(PREF_SYNC_FOLDER);
735  aPrefKey.AppendLiteral(gMediaType[aContentType]);
736 
737  return NS_OK;
738 }
#define PREF_SYNC_MGMTTYPE
nsresult CreateCopy(sbDeviceLibrarySyncSettings **aSettings)
return NS_OK
PRUint32 const LEGACY_MGMT_TYPE_MANUAL
onPageChanged aValue
Definition: FeedWriter.js:1395
#define PREF_SYNC_PREFIX
#define PREF_SYNC_ROOT
nsresult sbAppendnsIArray(nsIArray *aSrc, nsIMutableArray *aDest, PRBool aWeak=PR_FALSE, PRUint32 aElementsToCopy=0)
Definition: sbArrayUtils.h:87
#define PREF_SYNC_LISTS
#define PREF_SYNC_FOLDER
Songbird Variant Utility Definitions.
#define PREF_SYNC_BRANCH
const unsigned long MEDIATYPE_AUDIO
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICELIBRARYSYNCSETTINGS nsresult Assign(sbDeviceLibrarySyncSettings *aSource)
const unsigned long MEDIATYPE_IMAGE
#define PREF_SYNC_IMPORT
var count
Definition: test_bug7406.js:32
void nsString_Split(const nsAString &aString, const nsAString &aDelimiter, nsTArray< nsString > &aSubStringArray)
static sbDeviceLibrarySyncSettings * New(nsID const &aDeviceID, nsAString const &aDeviceLibraryGuid)
_dialogDatepicker settings
NS_IMPL_ISUPPORTS1(sbDeviceLibrarySyncSettings, sbIDeviceLibrarySyncSettings)
char const *const gMediaType[]
PLDHashOperator ArrayBuilder(nsISupports *aKey, PRBool aData, void *userArg)
static void MigrateLegacyMgmtValues(PRUint32 &aValue)
const unsigned long MEDIATYPE_COUNT
nsresult Read(sbIDevice *aDevice, sbIDeviceLibrary *aDeviceLibrary)
_updateTextAndScrollDataForFrame aData