27 #include <nsIMutableArray.h>
28 #include <nsIStringBundle.h>
29 #include <nsISimpleEnumerator.h>
30 #include <nsIStringEnumerator.h>
32 #include <nsIVariant.h>
33 #include <sbICascadeFilterSet.h>
34 #include <sbIDatabaseQuery.h>
35 #include <sbIDatabaseResult.h>
36 #include <sbIDevice.h>
37 #include <sbIDeviceManager.h>
38 #include <sbIFilterableMediaListView.h>
39 #include <sbILibrary.h>
40 #include <sbILocalDatabaseGUIDArray.h>
41 #include <sbILocalDatabaseLibrary.h>
42 #include <sbIMediaList.h>
43 #include <sbIMediaListListener.h>
44 #include <sbIMediaListView.h>
45 #include <sbIPropertyArray.h>
46 #include <sbIPropertyInfo.h>
47 #include <sbIPropertyManager.h>
48 #include <sbISearchableMediaListView.h>
49 #include <sbISortableMediaListView.h>
52 #include <nsAutoLock.h>
53 #include <nsComponentManagerUtils.h>
54 #include <nsServiceManagerUtils.h>
55 #include <nsHashKeys.h>
57 #include <nsNetUtil.h>
72 #define DEFAULT_PROPERTIES_URL "chrome://songbird/locale/songbird.properties"
79 : mFullArrayMonitor(nsnull),
81 mLockedEnumerationActive(PR_FALSE)
94 const nsAString& aGuid,
98 nsAutoMonitor::NewMonitor(
"sbLocalDatabaseMediaListBase::mFullArrayMonitor");
103 NS_ENSURE_SUCCESS(rv, rv);
106 NS_ENSURE_SUCCESS(rv, rv);
109 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
112 NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
115 NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
118 NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
121 NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
124 NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
129 already_AddRefed<sbLocalDatabaseLibrary>
132 NS_ASSERTION(
mLibrary,
"mLibrary is null!");
153 PLDHashOperator PR_CALLBACK
154 sbLocalDatabaseMediaListBase::AddFilterToGUIDArrayCallback(nsStringHashKey::KeyType aKey,
158 NS_ASSERTION(aEntry,
"Null entry in the hash?!");
159 NS_ASSERTION(aUserData,
"Null userData!");
162 nsCOMPtr<nsIStringEnumerator> valueEnum =
167 NS_ENSURE_TRUE(valueEnum, PL_DHASH_NEXT);
170 nsCOMPtr<sbILocalDatabaseGUIDArray> guidArray =
175 guidArray->AddFilter(aKey, valueEnum, PR_FALSE);
176 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"AddFilter failed!");
178 return PL_DHASH_NEXT;
188 return EnumerateItemsInternal(&enumerator, aEnumerationListener);
195 sbLocalDatabaseMediaListBase::EnumerateItemsByPropertyInternal(
const nsAString& aID,
200 nsCOMPtr<sbILocalDatabaseGUIDArray> guidArray;
201 nsresult rv = mFullArray->Clone(getter_AddRefs(guidArray));
202 NS_ENSURE_SUCCESS(rv, rv);
205 rv = guidArray->ClearFilters();
206 NS_ENSURE_SUCCESS(rv, rv);
209 rv = guidArray->AddFilter(aID, aValueEnum, PR_FALSE);
210 NS_ENSURE_SUCCESS(rv, rv);
215 return EnumerateItemsInternal(&enumerator, aEnumerationListener);
222 sbLocalDatabaseMediaListBase::EnumerateItemsByPropertiesInternal(sbStringArrayHash* aPropertiesHash,
225 nsCOMPtr<sbILocalDatabaseGUIDArray> guidArray;
226 nsresult rv = mFullArray->Clone(getter_AddRefs(guidArray));
227 NS_ENSURE_SUCCESS(rv, rv);
230 rv = guidArray->ClearFilters();
231 NS_ENSURE_SUCCESS(rv, rv);
235 PRUint32 filterCount =
236 aPropertiesHash->EnumerateRead(AddFilterToGUIDArrayCallback, guidArray);
240 PRUint32 hashCount = aPropertiesHash->Count();
241 NS_ENSURE_TRUE(filterCount == hashCount, NS_ERROR_UNEXPECTED);
245 return EnumerateItemsInternal(&enumerator, aEnumerationListener);
252 nsCOMPtr<sbIDatabaseQuery> query =
254 NS_ENSURE_SUCCESS(rv, rv);
256 nsAutoString databaseGuid;
257 rv =
mLibrary->GetDatabaseGuid(databaseGuid);
258 NS_ENSURE_SUCCESS(rv, rv);
260 rv = query->SetDatabaseGUID(databaseGuid);
261 NS_ENSURE_SUCCESS(rv, rv);
263 nsCOMPtr<nsIURI> databaseLocation;
264 rv =
mLibrary->GetDatabaseLocation(getter_AddRefs(databaseLocation));
265 NS_ENSURE_SUCCESS(rv, rv);
267 if (databaseLocation) {
268 rv = query->SetDatabaseLocation(databaseLocation);
269 NS_ENSURE_SUCCESS(rv, rv);
272 rv = query->SetAsyncQuery(PR_FALSE);
273 NS_ENSURE_SUCCESS(rv, rv);
275 NS_ADDREF(*_retval = query);
283 NS_ASSERTION(aProperties,
"aProperties is null");
284 NS_ASSERTION(_retval,
"_retval is null");
287 nsCOMPtr<sbIMutablePropertyArray> mutableArray =
289 NS_ENSURE_SUCCESS(rv, rv);
292 rv = GetLibrary(getter_AddRefs(library));
293 NS_ENSURE_SUCCESS(rv, rv);
295 PRBool hasContentType = PR_FALSE;
297 rv = aProperties->GetLength(&length);
298 NS_ENSURE_SUCCESS(rv, rv);
301 nsCOMPtr<sbIProperty> property;
302 rv = aProperties->GetPropertyAt(
i, getter_AddRefs(property));
303 NS_ENSURE_SUCCESS(rv, rv);
306 rv =
property->GetId(
id);
307 NS_ENSURE_SUCCESS(rv, rv);
315 rv =
property->GetValue(value);
316 NS_ENSURE_SUCCESS(rv, rv);
318 rv = mutableArray->AppendProperty(
id, value);
319 NS_ENSURE_SUCCESS(rv, rv);
322 hasContentType = PR_TRUE;
326 if (!hasContentType) {
329 NS_LITERAL_STRING(
"audio"));
332 NS_ADDREF(*_retval = mutableArray);
341 NS_ENSURE_ARG_POINTER(aSourceItem);
342 NS_ENSURE_ARG_POINTER(aProperties);
347 nsCOMPtr<sbIDeviceManager2> deviceMgr =
348 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
349 NS_ENSURE_SUCCESS(rv, rv);
351 nsCOMPtr<sbIDevice> targetDev;
352 rv = deviceMgr->GetDeviceForItem(static_cast<sbIMediaList *>(
this),
353 getter_AddRefs(targetDev));
354 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"GetDeviceForItem() failed");
360 PRBool targetIsDevice = (NS_SUCCEEDED(rv) && (targetDev != NULL));
363 nsCOMPtr<sbILibrary> originLib;
364 rv = aSourceItem->GetLibrary(getter_AddRefs(originLib));
365 NS_ENSURE_SUCCESS(rv, rv);
368 nsCOMPtr<sbILibrary> mainLib;
370 NS_ENSURE_SUCCESS(rv, rv);
377 NS_ENSURE_SUCCESS(rv, rv);
383 if (originLib == mainLib) {
385 rv = RemoveProperty(aProperties,
387 NS_ENSURE_SUCCESS(rv, rv);
390 rv = RemoveProperty(aProperties,
392 NS_ENSURE_SUCCESS(rv, rv);
396 if (targetIsDevice) {
397 rv = aProperties->AppendProperty(
399 NS_LITERAL_STRING(
"1"));
400 NS_ENSURE_SUCCESS(rv, rv);
403 else if (targetIsDevice) {
411 if (NS_SUCCEEDED(rv)) {
414 rv = aProperties->AppendProperty(
416 NS_LITERAL_STRING(
"1"));
417 NS_ENSURE_SUCCESS(rv, rv);
422 rv = aProperties->AppendProperty(
424 NS_LITERAL_STRING(
"0"));
425 NS_ENSURE_SUCCESS(rv, rv);
429 nsCOMPtr<sbILibrary> thisLibrary;
430 rv = GetLibrary(getter_AddRefs(thisLibrary));
431 NS_ENSURE_SUCCESS(rv, rv);
433 PRBool copyingToMainLibrary;
434 rv = thisLibrary->Equals(mainLib, ©ingToMainLibrary);
435 NS_ENSURE_SUCCESS(rv, rv);
438 if (!copyingToMainLibrary) {
440 nsAutoString originLibGuid;
441 rv = aProperties->GetPropertyValue(
444 if (rv == NS_ERROR_NOT_AVAILABLE || originLibGuid.IsEmpty()) {
445 rv = originLib->GetGuid(originLibGuid);
446 NS_ENSURE_SUCCESS(rv, rv);
447 rv = aProperties->AppendProperty(
450 NS_ENSURE_SUCCESS(rv, rv);
453 NS_ENSURE_SUCCESS(rv, rv);
457 nsAutoString originItemGuid;
458 rv = aProperties->GetPropertyValue(
461 if (rv == NS_ERROR_NOT_AVAILABLE || originItemGuid.IsEmpty()) {
462 rv = aSourceItem->GetGuid(originItemGuid);
463 NS_ENSURE_SUCCESS(rv, rv);
464 rv = aProperties->AppendProperty(
467 NS_ENSURE_SUCCESS(rv, rv);
470 NS_ENSURE_SUCCESS(rv, rv);
477 sbLocalDatabaseMediaListBase::RemoveProperty(
479 const nsAString & aProperty)
481 NS_ENSURE_ARG_POINTER(aPropertyArray);
486 nsCOMPtr<nsIMutableArray> mutableArray =
487 do_QueryInterface(aPropertyArray, &rv);
488 NS_ENSURE_SUCCESS(rv, rv);
491 rv = aPropertyArray->GetLength(&length);
492 NS_ENSURE_SUCCESS(rv, rv);
498 nsCOMPtr<sbIProperty> prop;
499 rv = aPropertyArray->GetPropertyAt(i, getter_AddRefs(prop));
500 NS_ENSURE_SUCCESS(rv, rv);
503 rv = prop->GetId(
id);
504 NS_ENSURE_SUCCESS(rv, rv);
509 if (
id == aProperty) {
510 rv = mutableArray->RemoveElementAt(i);
511 NS_ENSURE_SUCCESS(rv, rv);
533 nsresult rv = aEnumerator->HasMoreElements(&hasMore);
534 NS_ENSURE_SUCCESS(rv, rv);
540 nsCOMPtr<nsISupports> supports;
541 rv = aEnumerator->GetNext(getter_AddRefs(supports));
542 NS_ENSURE_SUCCESS(rv, rv);
544 nsCOMPtr<sbIMediaItem> item = do_QueryInterface(supports, &rv);
545 NS_ENSURE_SUCCESS(rv, rv);
548 rv = aListener->OnEnumeratedItem(
this, item, &stepResult);
549 NS_ENSURE_SUCCESS(rv, rv);
557 NS_NOTREACHED(
"Uh, how'd we get here?");
558 return NS_ERROR_UNEXPECTED;
562 sbLocalDatabaseMediaListBase::GetName(nsAString&
aName)
564 nsAutoString unlocalizedName;
567 NS_ENSURE_SUCCESS(rv, rv);
570 if (unlocalizedName.IsEmpty()) {
571 aName.Assign(unlocalizedName);
582 const PRUnichar *
start, *end;
583 PRUint32 length = unlocalizedName.BeginReading(&start, &end);
585 static const PRUnichar sAmp =
'&';
588 if (length <= 1 || *start != sAmp) {
589 aName.Assign(unlocalizedName);
595 nsDependentSubstring stringKey(start, end - start), propertiesURL;
597 static const PRUnichar sHash =
'#';
599 for (
const PRUnichar* current = start; current < end; current++) {
600 if (*current == sHash) {
601 stringKey.Rebind(current + 1, end - current - 1);
602 propertiesURL.Rebind(start, current - start);
608 nsCOMPtr<nsIStringBundleService> bundleService =
609 do_GetService(
"@mozilla.org/intl/stringbundle;1", &rv);
610 NS_ENSURE_SUCCESS(rv, rv);
612 nsCOMPtr<nsIStringBundle>
bundle;
614 if (!propertiesURL.IsEmpty()) {
615 nsCOMPtr<nsIURI> propertiesURI;
616 rv = NS_NewURI(getter_AddRefs(propertiesURI), propertiesURL);
618 if (NS_SUCCEEDED(rv)) {
619 PRBool schemeIsChrome;
620 rv = propertiesURI->SchemeIs(
"chrome", &schemeIsChrome);
622 if (NS_SUCCEEDED(rv) && schemeIsChrome) {
623 nsCAutoString propertiesSpec;
624 rv = propertiesURI->GetSpec(propertiesSpec);
626 if (NS_SUCCEEDED(rv)) {
627 rv = bundleService->CreateBundle(propertiesSpec.get(),
628 getter_AddRefs(bundle));
636 getter_AddRefs(bundle));
639 if (NS_SUCCEEDED(rv)) {
640 nsAutoString localizedName;
641 rv = bundle->GetStringFromName(stringKey.BeginReading(),
642 getter_Copies(localizedName));
643 if (NS_SUCCEEDED(rv)) {
644 aName.Assign(localizedName);
649 aName.Assign(unlocalizedName);
654 sbLocalDatabaseMediaListBase::SetName(
const nsAString& aName)
657 NS_ENSURE_SUCCESS(rv, rv);
663 sbLocalDatabaseMediaListBase::GetType(nsAString& aType)
665 NS_NOTREACHED(
"Not meant to be implemented in this base class");
666 return NS_ERROR_NOT_IMPLEMENTED;
670 sbLocalDatabaseMediaListBase::GetLength(PRUint32* aLength)
672 NS_ENSURE_ARG_POINTER(aLength);
677 nsresult rv = mFullArray->GetLength(aLength);
678 NS_ENSURE_SUCCESS(rv, rv);
684 sbLocalDatabaseMediaListBase::GetItemByGuid(
const nsAString& aGuid,
687 NS_ENSURE_ARG_POINTER(_retval);
689 nsCOMPtr<sbIMediaItem> item;
690 nsresult rv =
mLibrary->GetMediaItem(aGuid, getter_AddRefs(item));
691 NS_ENSURE_SUCCESS(rv, rv);
693 NS_ADDREF(*_retval = item);
698 sbLocalDatabaseMediaListBase::GetItemByIndex(PRUint32 aIndex,
701 NS_ENSURE_ARG_POINTER(_retval);
710 rv = mFullArray->GetGuidByIndex(aIndex, guid);
711 NS_ENSURE_SUCCESS(rv, rv);
714 nsCOMPtr<sbIMediaItem> item;
715 rv =
mLibrary->GetMediaItem(guid, getter_AddRefs(item));
716 NS_ENSURE_SUCCESS(rv, rv);
718 NS_ADDREF(*_retval = item);
723 sbLocalDatabaseMediaListBase::GetListContentType(PRUint16* aContentType)
725 NS_ENSURE_ARG_POINTER(aContentType);
737 nsAutoString customType;
740 NS_ENSURE_SUCCESS(rv, rv);
741 if (customType.Equals(NS_LITERAL_STRING(
"download")))
745 if (customType.Equals(NS_LITERAL_STRING(
"video-togo"))) {
751 rv = mFullArray->GetLength(&length);
752 NS_ENSURE_SUCCESS(rv, rv);
761 PRUint32 audioLength = 0, videoLength = 0;
763 NS_LITERAL_STRING(
"audio"),
765 NS_ENSURE_SUCCESS(rv, rv);
768 NS_LITERAL_STRING(
"video"),
770 NS_ENSURE_SUCCESS(rv, rv);
773 if (audioLength > 0) {
777 if (videoLength > 0) {
791 PRUint16 aEnumerationType)
793 NS_ENSURE_ARG_POINTER(aEnumerationListener);
797 switch (aEnumerationType) {
808 rv = aEnumerationListener->OnEnumerationBegin(
this, &stepResult);
810 if (NS_SUCCEEDED(rv)) {
812 rv = EnumerateAllItemsInternal(aEnumerationListener);
826 rv = aEnumerationListener->OnEnumerationBegin(
this, &stepResult);
828 if (NS_SUCCEEDED(rv)) {
830 rv = EnumerateAllItemsInternal(aEnumerationListener);
840 NS_NOTREACHED(
"Invalid enumeration type");
841 rv = NS_ERROR_INVALID_ARG;
845 aEnumerationListener->OnEnumerationEnd(
this, rv);
853 sbLocalDatabaseMediaListBase::EnumerateItemsByProperty(
const nsAString& aID,
856 PRUint16 aEnumerationType)
858 NS_ENSURE_ARG_POINTER(aEnumerationListener);
860 nsresult rv = NS_ERROR_UNEXPECTED;
863 NS_ENSURE_TRUE(!aID.IsEmpty(), NS_ERROR_INVALID_ARG);
866 nsCOMPtr<sbIPropertyManager> propMan =
868 NS_ENSURE_SUCCESS(rv, rv);
870 nsCOMPtr<sbIPropertyInfo> info;
871 rv = propMan->GetPropertyInfo(aID, getter_AddRefs(info));
872 NS_ENSURE_SUCCESS(rv, rv);
874 nsAutoString sortableValue;
875 rv = info->MakeSortable(aValue, sortableValue);
876 NS_ENSURE_SUCCESS(rv, rv);
880 nsString*
value = valueArray.AppendElement(sortableValue);
881 NS_ENSURE_TRUE(value, NS_ERROR_OUT_OF_MEMORY);
884 nsCOMPtr<nsIStringEnumerator> valueEnum =
886 NS_ENSURE_TRUE(valueEnum, NS_ERROR_OUT_OF_MEMORY);
888 switch (aEnumerationType) {
899 rv = aEnumerationListener->OnEnumerationBegin(
this, &stepResult);
901 if (NS_SUCCEEDED(rv)) {
903 rv = EnumerateItemsByPropertyInternal(aID, valueEnum,
904 aEnumerationListener);
918 rv = aEnumerationListener->OnEnumerationBegin(
this, &stepResult);
920 if (NS_SUCCEEDED(rv)) {
922 rv = EnumerateItemsByPropertyInternal(aID, valueEnum,
923 aEnumerationListener);
933 NS_NOTREACHED(
"Invalid enumeration type");
934 rv = NS_ERROR_INVALID_ARG;
938 aEnumerationListener->OnEnumerationEnd(
this, rv);
946 sbLocalDatabaseMediaListBase::EnumerateItemsByProperties(
sbIPropertyArray* aProperties,
948 PRUint16 aEnumerationType)
950 NS_ENSURE_ARG_POINTER(aProperties);
951 NS_ENSURE_ARG_POINTER(aEnumerationListener);
953 PRUint32 propertyCount;
954 nsresult rv = aProperties->GetLength(&propertyCount);
955 NS_ENSURE_SUCCESS(rv, rv);
959 NS_ENSURE_STATE(propertyCount);
968 sbStringArrayHash propertyHash;
972 propertyHash.Init(propertyCount);
974 nsCOMPtr<sbIPropertyManager> propMan =
976 NS_ENSURE_SUCCESS(rv, rv);
979 for (PRUint32 index = 0; index < propertyCount; index++) {
982 nsCOMPtr<sbIProperty> property;
983 rv = aProperties->GetPropertyAt(index, getter_AddRefs(property));
988 rv =
property->GetId(propertyID);
994 PRBool arrayExists = propertyHash.Get(propertyID, &stringArray);
1000 PRBool success = propertyHash.Put(propertyID, stringArray);
1002 NS_WARNING(
"Failed to add string array to property hash!");
1005 NS_DELETEXPCOM(stringArray);
1009 NS_ASSERTION(stringArray,
"Must have a valid pointer here!");
1012 nsString* valueString = stringArray->AppendElement();
1016 nsCOMPtr<sbIPropertyInfo> info;
1017 rv = propMan->GetPropertyInfo(propertyID, getter_AddRefs(info));
1021 rv =
property->GetValue(value);
1024 nsAutoString sortableValue;
1025 rv = info->MakeSortable(value, *valueString);
1029 switch (aEnumerationType) {
1039 PRUint16 stepResult;
1040 rv = aEnumerationListener->OnEnumerationBegin(
this, &stepResult);
1042 if (NS_SUCCEEDED(rv)) {
1044 rv = EnumerateItemsByPropertiesInternal(&propertyHash,
1045 aEnumerationListener);
1058 PRUint16 stepResult;
1059 rv = aEnumerationListener->OnEnumerationBegin(
this, &stepResult);
1061 if (NS_SUCCEEDED(rv)) {
1063 rv = EnumerateItemsByPropertiesInternal(&propertyHash,
1064 aEnumerationListener);
1074 NS_NOTREACHED(
"Invalid enumeration type");
1075 rv = NS_ERROR_INVALID_ARG;
1079 aEnumerationListener->OnEnumerationEnd(
this, rv);
1085 sbLocalDatabaseMediaListBase::GetItemsByProperty(
const nsAString & aPropertyID,
1086 const nsAString & aPropertyValue,
1089 NS_ENSURE_ARG_POINTER(_retval);
1091 nsRefPtr<sbLocalMediaListBaseEnumerationListener> enumerator;
1093 NS_ENSURE_TRUE(enumerator, NS_ERROR_OUT_OF_MEMORY);
1095 nsresult rv = enumerator->Init();
1096 NS_ENSURE_SUCCESS(rv, rv);
1098 rv = EnumerateItemsByProperty(aPropertyID,
1102 NS_ENSURE_SUCCESS(rv, rv);
1104 return enumerator->GetArray(_retval);
1108 sbLocalDatabaseMediaListBase::GetItemCountByProperty(
const nsAString & aPropertyID,
1109 const nsAString & aPropertyValue,
1112 NS_ENSURE_ARG_POINTER(_retval);
1114 nsRefPtr<sbLocalMediaListBaseEnumerationListener> enumerator;
1116 NS_ENSURE_TRUE(enumerator, NS_ERROR_OUT_OF_MEMORY);
1118 nsresult rv = enumerator->Init();
1119 NS_ENSURE_SUCCESS(rv, rv);
1121 rv = EnumerateItemsByProperty(aPropertyID,
1125 NS_ENSURE_SUCCESS(rv, rv);
1127 return enumerator->GetArrayLength(_retval);
1131 sbLocalDatabaseMediaListBase::GetItemsByProperties(
sbIPropertyArray *aProperties,
1134 NS_ENSURE_ARG_POINTER(aProperties);
1135 NS_ENSURE_ARG_POINTER(_retval);
1137 nsRefPtr<sbLocalMediaListBaseEnumerationListener> enumerator;
1139 NS_ENSURE_TRUE(enumerator, NS_ERROR_OUT_OF_MEMORY);
1141 nsresult rv = enumerator->Init();
1142 NS_ENSURE_SUCCESS(rv, rv);
1144 rv = EnumerateItemsByProperties(aProperties,
1147 NS_ENSURE_SUCCESS(rv, rv);
1149 rv = enumerator->GetArray(_retval);
1150 NS_ENSURE_SUCCESS(rv, rv);
1156 sbLocalDatabaseMediaListBase::IndexOf(
sbIMediaItem* aMediaItem,
1157 PRUint32 aStartFrom,
1160 NS_ENSURE_ARG_POINTER(aMediaItem);
1161 NS_ENSURE_ARG_POINTER(_retval);
1168 nsresult rv = mFullArray->GetLength(&count);
1169 NS_ENSURE_SUCCESS(rv, rv);
1172 NS_ENSURE_TRUE(count > 0, NS_ERROR_NOT_AVAILABLE);
1173 NS_ENSURE_ARG_MAX(aStartFrom, count - 1);
1175 nsAutoString testGUID;
1176 rv = aMediaItem->GetGuid(testGUID);
1177 NS_ENSURE_SUCCESS(rv, rv);
1179 for (PRUint32 index = aStartFrom; index <
count; index++) {
1180 nsAutoString itemGUID;
1181 rv = mFullArray->GetGuidByIndex(index, itemGUID);
1184 if (testGUID.Equals(itemGUID)) {
1190 return NS_ERROR_NOT_AVAILABLE;
1194 sbLocalDatabaseMediaListBase::LastIndexOf(
sbIMediaItem* aMediaItem,
1195 PRUint32 aStartFrom,
1198 NS_ENSURE_ARG_POINTER(aMediaItem);
1199 NS_ENSURE_ARG_POINTER(_retval);
1205 nsresult rv = mFullArray->GetLength(&count);
1206 NS_ENSURE_SUCCESS(rv, rv);
1209 NS_ENSURE_TRUE(count > 0, NS_ERROR_UNEXPECTED);
1210 NS_ENSURE_ARG_MAX(aStartFrom, count - 1);
1212 nsAutoString testGUID;
1213 rv = aMediaItem->GetGuid(testGUID);
1214 NS_ENSURE_SUCCESS(rv, rv);
1216 for (PRUint32 index = count - 1; index >= aStartFrom; index--) {
1217 nsAutoString itemGUID;
1218 rv = mFullArray->GetGuidByIndex(index, itemGUID);
1221 if (testGUID.Equals(itemGUID)) {
1226 return NS_ERROR_NOT_AVAILABLE;
1230 sbLocalDatabaseMediaListBase::Contains(
sbIMediaItem* aMediaItem,
1233 return NS_ERROR_NOT_IMPLEMENTED;
1237 sbLocalDatabaseMediaListBase::GetIsEmpty(PRBool* aIsEmpty)
1239 NS_ENSURE_ARG_POINTER(aIsEmpty);
1245 nsresult rv = mFullArray->GetLength(&length);
1246 NS_ENSURE_SUCCESS(rv, rv);
1248 *aIsEmpty = length == 0;
1253 sbLocalDatabaseMediaListBase::GetUserEditableContent(PRBool* aUserEditableContent)
1255 NS_ENSURE_ARG_POINTER(aUserEditableContent);
1261 NS_ENSURE_SUCCESS(rv, rv);
1263 *aUserEditableContent = !str.EqualsLiteral(
"1");
1269 sbLocalDatabaseMediaListBase::Add(
sbIMediaItem* aMediaItem)
1271 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1272 return NS_ERROR_NOT_IMPLEMENTED;
1276 sbLocalDatabaseMediaListBase::AddItem(
sbIMediaItem* aMediaItem,
1279 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1280 return NS_ERROR_NOT_IMPLEMENTED;
1284 sbLocalDatabaseMediaListBase::AddAll(
sbIMediaList* aMediaList)
1286 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1287 return NS_ERROR_NOT_IMPLEMENTED;
1293 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1294 return NS_ERROR_NOT_IMPLEMENTED;
1302 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1303 return NS_ERROR_NOT_IMPLEMENTED;
1307 sbLocalDatabaseMediaListBase::Remove(
sbIMediaItem* aMediaItem)
1309 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1310 return NS_ERROR_NOT_IMPLEMENTED;
1314 sbLocalDatabaseMediaListBase::RemoveByIndex(PRUint32 aIndex)
1316 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1317 return NS_ERROR_NOT_IMPLEMENTED;
1323 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1324 return NS_ERROR_NOT_IMPLEMENTED;
1328 sbLocalDatabaseMediaListBase::Clear()
1330 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1331 return NS_ERROR_NOT_IMPLEMENTED;
1357 NS_NOTREACHED(
"Not meant to be implemented in this base class");
1358 return NS_ERROR_NOT_IMPLEMENTED;
1362 sbLocalDatabaseMediaListBase::GetDistinctValuesForProperty(
const nsAString& aPropertyID,
1365 NS_ENSURE_ARG_POINTER(_retval);
1367 nsCOMPtr<sbILocalDatabaseGUIDArray> guidArray;
1368 nsresult rv = mFullArray->Clone(getter_AddRefs(guidArray));
1369 NS_ENSURE_SUCCESS(rv, rv);
1371 rv = guidArray->SetIsDistinct(PR_TRUE);
1372 NS_ENSURE_SUCCESS(rv, rv);
1374 rv = guidArray->ClearSorts();
1375 NS_ENSURE_SUCCESS(rv, rv);
1377 rv = guidArray->AddSort(aPropertyID, PR_TRUE);
1378 NS_ENSURE_SUCCESS(rv, rv);
1382 NS_ENSURE_TRUE(enumerator, NS_ERROR_OUT_OF_MEMORY);
1384 NS_ADDREF(*_retval = enumerator);
1392 NS_ENSURE_ARG_POINTER(aCallback);
1396 return aCallback->RunBatched(aUserData);
1406 NS_ASSERTION(aArray,
"Null value passed to ctor");
1409 NS_ASSERTION(NS_SUCCEEDED(rv),
"Could not get length");
1417 sbGUIDArrayValueEnumerator::HasMore(PRBool *_retval)
1419 NS_ENSURE_ARG_POINTER(_retval);
1421 *_retval = mNextIndex < mLength;
1426 sbGUIDArrayValueEnumerator::GetNext(nsAString& _retval)
1428 nsresult rv = mArray->GetSortPropertyValueByIndex(mNextIndex, _retval);
1429 NS_ENSURE_SUCCESS(rv, rv);
#define SB_PROPERTY_MEDIALISTNAME
#define SONGBIRD_DATABASEQUERY_CONTRACTID
#define SB_PROPERTY_ORIGINLIBRARYGUID
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
nsTArray< nsString > sbStringArray
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
#define SB_PROPERTY_ISCONTENTREADONLY
Simple class to make sure we notify listeners that a batch operation has completed every time they ar...
readonly attribute AString guid
The guid of this resource.
#define SB_PROPERTYMANAGER_CONTRACTID
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
#define SB_PROPERTY_CREATED
#define SB_PROPERTY_UPDATED
#define SB_PROPERTY_CONTENTTYPE
static nsresult GetProperty(nsIPropertyBag2 *aProperties, nsAString const &aProp, nsAString &aValue)
#define SB_PROPERTY_ORIGIN_IS_IN_MAIN_LIBRARY
static nsresult FindOriginalsByID(sbIMediaItem *aMediaItem, sbIMediaList *aList, nsIMutableArray *aCopies)
StringArrayEnumerator prototype hasMore
An object responsible for executing SQL queries on the database.
nsresult GetMainLibrary(sbILibrary **aMainLibrary)
~sbGUIDArrayValueEnumerator()
#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_ORIGINITEMGUID
_getSelectedPageStyle s i
#define SB_UNUSED_IN_RELEASE(decl)
Songbird Database Object Definition.