30 #include <nsArrayUtils.h>
31 #include <nsAutoLock.h>
32 #include <nsComponentManagerUtils.h>
33 #include <nsServiceManagerUtils.h>
34 #include <nsIClassInfoImpl.h>
35 #include <nsIObjectInputStream.h>
36 #include <nsIObjectOutputStream.h>
37 #include <nsIProgrammingLanguage.h>
38 #include <nsIProperty.h>
39 #include <nsITreeView.h>
41 #include <nsIVariant.h>
42 #include <nsIWeakReferenceUtils.h>
45 #include <sbICascadeFilterSet.h>
46 #include <sbIDatabaseQuery.h>
47 #include <sbILibrary.h>
48 #include <sbILibraryConstraints.h>
49 #include <sbILocalDatabaseAsyncGUIDArray.h>
50 #include <sbILocalDatabaseSimpleMediaList.h>
51 #include <sbIMediaItem.h>
52 #include <sbIMediaList.h>
53 #include <sbIPropertyInfo.h>
54 #include <sbISQLBuilder.h>
55 #include <sbIMediaList.h>
73 #define DEFAULT_FETCH_SIZE 300
86 , mSelection(aSelection) {
87 mArray->SuppressInvalidation(PR_TRUE);
91 mArray->SuppressInvalidation(PR_FALSE);
92 mSelection->ConfigurationChanged();
95 nsCOMPtr<sbILocalDatabaseGUIDArray> mArray;
96 nsRefPtr<sbLocalDatabaseMediaListViewSelection> mSelection;
123 static PRLogModuleInfo* sMediaListViewLog = nsnull;
124 #define TRACE(args) if (sMediaListViewLog) PR_LOG(sMediaListViewLog, PR_LOG_DEBUG, args)
125 #define LOG(args) if (sMediaListViewLog) PR_LOG(sMediaListViewLog, PR_LOG_WARN, args)
131 PLDHashOperator PR_CALLBACK
132 sbLocalDatabaseMediaListView::AddValuesToArrayCallback(nsStringHashKey::KeyType aKey,
136 NS_ASSERTION(aEntry,
"Null entry in the hash?!");
137 NS_ASSERTION(aUserData,
"Null userData!");
139 nsCOMPtr<sbIMutablePropertyArray> propertyArray =
141 NS_ASSERTION(propertyArray,
"Could not cast user data");
143 PRUint32
length = aEntry->Length();
146 rv = propertyArray->AppendProperty(aKey, aEntry->ElementAt(
i));
147 NS_ENSURE_SUCCESS(rv, PL_DHASH_STOP);
150 return PL_DHASH_NEXT;
153 PLDHashOperator PR_CALLBACK
154 sbLocalDatabaseMediaListView::AddKeysToStringArrayCallback(nsStringHashKey::KeyType aKey,
158 NS_ASSERTION(aEntry,
"Null entry in the hash?!");
159 NS_ASSERTION(aUserData,
"Null userData!");
162 NS_ASSERTION(stringArray,
"Could not cast user data");
164 nsString* appended = stringArray->AppendElement(aKey);
165 NS_ENSURE_TRUE(appended, PL_DHASH_STOP);
167 return PL_DHASH_NEXT;
175 PLDHashOperator PR_CALLBACK
176 sbLocalDatabaseMediaListView::AddListenersToCOMArray(nsISupportsHashKey* aEntry,
179 sbViewListenerArray*
array =
static_cast<sbViewListenerArray*
>(aUserData);
180 NS_ASSERTION(array,
"Null aUserData!");
183 NS_ASSERTION(entry,
"Null entry in hash!");
186 nsCOMPtr<sbIMediaListViewListener>
listener = do_QueryInterface(entry, &rv);
188 nsWeakPtr maybeWeak = do_QueryInterface(entry, &rv);
189 NS_ASSERTION(NS_SUCCEEDED(rv),
"Listener doesn't QI to anything useful!");
191 listener = do_QueryReferent(maybeWeak);
195 return PL_DHASH_REMOVE;
199 PRBool success = array->AppendObject(listener);
200 NS_ENSURE_TRUE(success, PL_DHASH_STOP);
202 return PL_DHASH_NEXT;
207 nsAString& aDefaultSortProperty,
208 PRUint32 aMediaListId) :
210 mMediaList(aMediaList),
211 mDefaultSortProperty(aDefaultSortProperty),
212 mMediaListId(aMediaListId),
213 mListenerTableLock(nsnull),
214 mInvalidatePending(PR_FALSE)
216 NS_ASSERTION(aLibrary,
"aLibrary is null");
217 NS_ASSERTION(aMediaList,
"aMediaList is null");
226 MOZ_COUNT_CTOR(sbLocalDatabaseMediaListView);
228 if (!sMediaListViewLog) {
229 sMediaListViewLog = PR_NewLogModule(
"sbLocalDatabaseMediaListView");
232 TRACE((
"sbLocalDatabaseMediaListView[0x%.8x] - Constructed",
this));
237 TRACE((
"sbLocalDatabaseMediaListView[0x%.8x] - Destructed",
this));
238 MOZ_COUNT_DTOR(sbLocalDatabaseMediaListView);
241 nsCOMPtr<sbIMediaListListener> listener =
243 mMediaList->RemoveListener(listener);
246 if (mCascadeFilterSet) {
247 mCascadeFilterSet->ClearMediaListView();
251 mTreeView->ClearMediaListView();
254 if (mListenerTableLock) {
255 nsAutoLock::DestroyLock(mListenerTableLock);
265 aState->ToString(buff);
267 TRACE((
"sbLocalDatabaseMediaListView[0x%.8x] - Init %s",
268 this, NS_LossyConvertUTF16toASCII(buff).
get()));
273 nsCOMPtr<sbILocalDatabaseMediaListViewState> state;
275 state = do_QueryInterface(aState, &rv);
276 NS_ENSURE_SUCCESS(rv, NS_ERROR_INVALID_ARG);
279 PRBool success = mListenerTable.Init();
280 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
283 nsAutoLock::NewLock(
"sbLocalDatabaseMediaListView::mListenerTableLock");
284 NS_ENSURE_TRUE(mListenerTableLock, NS_ERROR_OUT_OF_MEMORY);
287 NS_ENSURE_SUCCESS(rv, rv);
291 nsAutoString databaseGuid;
292 rv = mLibrary->GetDatabaseGuid(databaseGuid);
293 NS_ENSURE_SUCCESS(rv, rv);
295 rv = mArray->SetDatabaseGUID(databaseGuid);
296 NS_ENSURE_SUCCESS(rv, rv);
298 nsCOMPtr<sbILocalDatabasePropertyCache> propertyCache;
299 rv = mLibrary->GetPropertyCache(getter_AddRefs(propertyCache));
300 NS_ENSURE_SUCCESS(rv, rv);
302 rv = mArray->SetPropertyCache(propertyCache);
303 NS_ENSURE_SUCCESS(rv, rv);
305 nsCOMPtr<nsIURI> databaseLocation;
306 rv = mLibrary->GetDatabaseLocation(getter_AddRefs(databaseLocation));
307 NS_ENSURE_SUCCESS(rv, rv);
309 if (databaseLocation) {
310 rv = mArray->SetDatabaseLocation(databaseLocation);
311 NS_ENSURE_SUCCESS(rv, rv);
314 if (mMediaListId == 0) {
315 rv = mArray->SetBaseTable(NS_LITERAL_STRING(
"media_items"));
316 NS_ENSURE_SUCCESS(rv, rv);
319 rv = mArray->SetBaseTable(NS_LITERAL_STRING(
"simple_media_lists"));
320 NS_ENSURE_SUCCESS(rv, rv);
322 rv = mArray->SetBaseConstraintColumn(NS_LITERAL_STRING(
"media_item_id"));
323 NS_ENSURE_SUCCESS(rv, rv);
325 rv = mArray->SetBaseConstraintValue(mMediaListId);
326 NS_ENSURE_SUCCESS(rv, rv);
329 nsCOMPtr<sbILocalDatabaseGUIDArrayLengthCache> lengthCache;
330 rv = mLibrary->GetLengthCache(getter_AddRefs(lengthCache));
331 NS_ENSURE_SUCCESS(rv, rv);
333 rv = mArray->SetLengthCache(lengthCache);
334 NS_ENSURE_SUCCESS(rv, rv);
337 NS_ENSURE_SUCCESS(rv, rv);
339 rv = CreateQueries();
340 NS_ENSURE_SUCCESS(rv, rv);
342 nsRefPtr<sbLocalDatabaseMediaListViewSelectionState> selectionState;
343 nsCOMPtr<sbIMutablePropertyArray> sort;
345 rv = state->GetSort(getter_AddRefs(sort));
346 NS_ENSURE_SUCCESS(rv, rv);
348 rv = state->GetSearch(getter_AddRefs(mViewSearch));
349 NS_ENSURE_SUCCESS(rv, rv);
351 rv = state->GetFilter(getter_AddRefs(mViewFilter));
352 NS_ENSURE_SUCCESS(rv, rv);
354 rv = state->GetSelection(getter_AddRefs(selectionState));
355 NS_ENSURE_SUCCESS(rv, rv);
359 rv = mMediaList->GetGuid(guid);
360 NS_ENSURE_SUCCESS(rv, rv);
362 nsCOMPtr<sbILocalDatabaseGUIDArray> syncArray =
363 do_QueryInterface(mArray, &rv);
364 NS_ENSURE_SUCCESS(rv, rv);
367 NS_ENSURE_TRUE(mSelection, NS_ERROR_OUT_OF_MEMORY);
368 rv = mSelection->Init(mLibrary,
373 NS_ENSURE_SUCCESS(rv, rv);
375 rv = SetSortInternal(sort);
376 NS_ENSURE_SUCCESS(rv, rv);
378 rv = mSelection->ConfigurationChanged();
379 NS_ENSURE_SUCCESS(rv, rv);
383 nsRefPtr<sbLocalDatabaseCascadeFilterSetState> filterSetState;
384 rv = state->GetFilterSet(getter_AddRefs(filterSetState));
385 NS_ENSURE_SUCCESS(rv, rv);
387 if (filterSetState) {
388 nsCOMPtr<sbILocalDatabaseAsyncGUIDArray> guidArray;
389 rv = mArray->CloneAsyncArray(getter_AddRefs(guidArray));
390 NS_ENSURE_SUCCESS(rv, rv);
392 nsRefPtr<sbLocalDatabaseCascadeFilterSet> filterSet =
394 NS_ENSURE_TRUE(filterSet, NS_ERROR_OUT_OF_MEMORY);
396 rv = filterSet->Init(mLibrary, guidArray, filterSetState);
397 NS_ENSURE_SUCCESS(rv, rv);
399 mCascadeFilterSet = filterSet;
402 nsRefPtr<sbLocalDatabaseTreeViewState> treeViewState;
403 rv = state->GetTreeViewState(getter_AddRefs(treeViewState));
406 NS_ENSURE_TRUE(tree, NS_ERROR_OUT_OF_MEMORY);
408 rv = tree->Init(
this, mArray, nsnull, treeViewState);
409 NS_ENSURE_SUCCESS(rv, rv);
418 already_AddRefed<sbLocalDatabaseMediaListBase>
421 NS_ASSERTION(mMediaList,
"mMediaList is null");
430 NS_ASSERTION(mArray,
"mArray is null");
435 sbLocalDatabaseMediaListView::GetMediaList(
sbIMediaList** aMediaList)
437 NS_ENSURE_ARG_POINTER(aMediaList);
439 NS_IF_ADDREF(*aMediaList = mMediaList);
444 sbLocalDatabaseMediaListView::GetLength(PRUint32* aFilteredLength)
446 NS_ENSURE_ARG_POINTER(aFilteredLength);
448 nsresult rv = mArray->GetLength(aFilteredLength);
449 NS_ENSURE_SUCCESS(rv, rv);
455 sbLocalDatabaseMediaListView::GetTreeView(
nsITreeView** aTreeView)
458 NS_ENSURE_ARG_POINTER(aTreeView);
465 NS_ENSURE_TRUE(tree, NS_ERROR_OUT_OF_MEMORY);
467 rv = tree->Init(
this, mArray, mViewSort, nsnull);
468 NS_ENSURE_SUCCESS(rv, rv);
473 NS_ADDREF(*aTreeView = mTreeView);
481 NS_ENSURE_ARG_POINTER(aCascadeFilterSet);
485 if (!mCascadeFilterSet) {
486 nsCOMPtr<sbILocalDatabaseAsyncGUIDArray> guidArray;
487 rv = mArray->CloneAsyncArray(getter_AddRefs(guidArray));
488 NS_ENSURE_SUCCESS(rv, rv);
490 nsRefPtr<sbLocalDatabaseCascadeFilterSet> filterSet =
492 NS_ENSURE_TRUE(filterSet, NS_ERROR_OUT_OF_MEMORY);
494 rv = filterSet->Init(mLibrary, guidArray, nsnull);
495 NS_ENSURE_SUCCESS(rv, rv);
497 mCascadeFilterSet = filterSet;
500 NS_ADDREF(*aCascadeFilterSet = mCascadeFilterSet);
505 sbLocalDatabaseMediaListView::GetItemByIndex(PRUint32 aIndex,
508 NS_ENSURE_ARG_POINTER(_retval);
513 rv = mArray->GetGuidByIndex(aIndex, guid);
514 NS_ENSURE_SUCCESS(rv, rv);
516 nsCOMPtr<sbIMediaItem> item;
517 rv = mLibrary->GetMediaItem(guid, getter_AddRefs(item));
518 NS_ENSURE_SUCCESS(rv, rv);
520 NS_ADDREF(*_retval = item);
525 sbLocalDatabaseMediaListView::GetIndexForItem(
sbIMediaItem* aMediaItem,
528 NS_ENSURE_ARG_POINTER(aMediaItem);
529 NS_ENSURE_ARG_POINTER(_retval);
532 nsresult rv = aMediaItem->GetGuid(guid);
533 NS_ENSURE_SUCCESS(rv, rv);
535 rv = mArray->GetFirstIndexByGuid(guid, _retval);
536 if (rv == NS_ERROR_NOT_AVAILABLE) {
539 NS_ENSURE_SUCCESS(rv, rv);
545 sbLocalDatabaseMediaListView::GetUnfilteredIndex(PRUint32 aIndex,
548 NS_ENSURE_ARG_POINTER(_retval);
555 if (mMediaListId == 0) {
557 rv = mArray->GetGuidByIndex(aIndex, guid);
558 NS_ENSURE_SUCCESS(rv, rv);
560 nsCOMPtr<sbIMediaItem> item;
561 rv = mMediaList->GetItemByGuid(guid, getter_AddRefs(item));
562 NS_ENSURE_SUCCESS(rv, rv);
564 rv = mMediaList->IndexOf(item, 0, _retval);
565 NS_ENSURE_SUCCESS(rv, rv);
571 nsAutoString ordinal;
572 rv = mArray->GetOrdinalByIndex(aIndex, ordinal);
573 NS_ENSURE_SUCCESS(rv, rv);
575 nsCOMPtr<sbILocalDatabaseSimpleMediaList> sml =
576 do_QueryInterface(NS_ISUPPORTS_CAST(
sbIMediaList*, mMediaList), &rv);
577 NS_ENSURE_SUCCESS(rv, rv);
579 rv = sml->GetIndexByOrdinal(ordinal, _retval);
580 NS_ENSURE_SUCCESS(rv, rv);
587 sbLocalDatabaseMediaListView::GetViewItemUIDForIndex(PRUint32 aIndex,
593 rv = mArray->GetRowidByIndex(aIndex, &rowid);
594 NS_ENSURE_SUCCESS(rv, rv);
596 PRUint32 mediaItemid;
597 rv = mArray->GetMediaItemIdByIndex(aIndex, &mediaItemid);
598 NS_ENSURE_SUCCESS(rv, rv);
604 _retval.AppendInt(mediaItemid);
610 sbLocalDatabaseMediaListView::GetIndexForViewItemUID(
const nsAString& aViewItemUID,
613 NS_ENSURE_ARG_POINTER(_retval);
617 rv = mArray->GetIndexByViewItemUID(aViewItemUID, _retval);
618 NS_ENSURE_SUCCESS(rv, rv);
624 sbLocalDatabaseMediaListView::GetDistinctValuesForProperty(
const nsAString& aPropertyID,
627 NS_ENSURE_ARG_POINTER(_retval);
629 nsCOMPtr<sbILocalDatabaseGUIDArray> guidArray;
630 nsresult rv = mArray->Clone(getter_AddRefs(guidArray));
631 NS_ENSURE_SUCCESS(rv, rv);
633 rv = guidArray->SetIsDistinct(PR_TRUE);
634 NS_ENSURE_SUCCESS(rv, rv);
636 rv = guidArray->ClearSorts();
637 NS_ENSURE_SUCCESS(rv, rv);
639 rv = guidArray->AddSort(aPropertyID, PR_TRUE);
640 NS_ENSURE_SUCCESS(rv, rv);
644 NS_ENSURE_TRUE(enumerator, NS_ERROR_OUT_OF_MEMORY);
646 NS_ADDREF(*_retval = enumerator);
653 NS_ENSURE_ARG_POINTER(_retval);
657 nsCOMPtr<sbIMediaListViewState> state;
658 rv = GetState(getter_AddRefs(state));
659 NS_ENSURE_SUCCESS(rv, rv);
661 nsRefPtr<sbLocalDatabaseMediaListView>
664 mDefaultSortProperty,
666 NS_ENSURE_TRUE(
clone, NS_ERROR_OUT_OF_MEMORY);
668 rv =
clone->Init(state);
669 NS_ENSURE_SUCCESS(rv, rv);
671 NS_ADDREF(*_retval =
clone);
678 NS_ENSURE_ARG_POINTER(_retval);
682 nsCOMPtr<sbIMutablePropertyArray> sort;
683 rv = ClonePropertyArray(mViewSort, getter_AddRefs(sort));
684 NS_ENSURE_SUCCESS(rv, rv);
686 nsRefPtr<sbLocalDatabaseMediaListViewSelectionState> selectionState;
687 rv = mSelection->GetState(getter_AddRefs(selectionState));
688 NS_ENSURE_SUCCESS(rv, rv);
690 nsRefPtr<sbLocalDatabaseCascadeFilterSetState> filterSetState;
691 if (mCascadeFilterSet) {
692 rv = mCascadeFilterSet->GetState(getter_AddRefs(filterSetState));
693 NS_ENSURE_SUCCESS(rv, rv);
696 nsRefPtr<sbLocalDatabaseTreeViewState> treeViewState;
698 rv = mTreeView->GetState(getter_AddRefs(treeViewState));
699 NS_ENSURE_SUCCESS(rv, rv);
702 nsRefPtr<sbLocalDatabaseMediaListViewState> state =
709 NS_ENSURE_TRUE(state, NS_ERROR_OUT_OF_MEMORY);
710 NS_ADDREF(*_retval = state);
719 NS_ENSURE_ARG_POINTER(aListener);
722 nsCOMPtr<nsISupports> supports = do_QueryInterface(aListener, &rv);
723 NS_ENSURE_SUCCESS(rv, rv);
726 nsWeakPtr weakRef = do_GetWeakReference(supports, &rv);
727 NS_ENSURE_SUCCESS(rv, rv);
729 supports = do_QueryInterface(weakRef, &rv);
730 NS_ENSURE_SUCCESS(rv, rv);
733 nsAutoLock lock(mListenerTableLock);
734 if (mListenerTable.GetEntry(supports)) {
735 NS_WARNING(
"Attempted to add the same listener twice!");
739 if (!mListenerTable.PutEntry(supports)) {
740 NS_WARNING(
"Failed to add entry to listener table");
741 return NS_ERROR_FAILURE;
749 NS_ENSURE_ARG_POINTER(aListener);
752 nsCOMPtr<nsISupports> supports = do_QueryInterface(aListener, &rv);
753 NS_ENSURE_SUCCESS(rv, rv);
755 nsCOMPtr<nsISupports> weakSupports;
760 nsCOMPtr<nsISupportsWeakReference> maybeWeak = do_QueryInterface(supports, &rv);
761 if (NS_SUCCEEDED(rv)) {
762 nsWeakPtr weakRef = do_GetWeakReference(supports, &rv);
763 NS_ENSURE_SUCCESS(rv, rv);
765 weakSupports = do_QueryInterface(weakRef, &rv);
766 NS_ENSURE_SUCCESS(rv, rv);
769 nsAutoLock lock(mListenerTableLock);
772 if (weakSupports && mListenerTable.GetEntry(weakSupports)) {
773 supports = weakSupports;
776 NS_WARN_IF_FALSE(mListenerTable.GetEntry(supports),
777 "Attempted to remove a listener that was never added!");
779 mListenerTable.RemoveEntry(supports);
787 NS_ENSURE_ARG_POINTER(aSelection);
788 NS_IF_ADDREF(*aSelection = mSelection);
793 sbLocalDatabaseMediaListView::RemoveSelectedMediaItems()
795 nsString viewContentType;
797 PRUint32 viewLength = 0;
798 nsresult rv = GetLength(&viewLength);
799 NS_ENSURE_SUCCESS(rv, rv);
801 PRInt32 selectionLength = 0;
802 rv = mSelection->GetCount(&selectionLength);
803 NS_ENSURE_SUCCESS(rv, rv);
805 PRUint32 filterCount = 0;
807 rv = mViewFilter->GetGroupCount(&filterCount);
808 NS_ENSURE_SUCCESS(rv, rv);
813 nsCOMPtr<sbILibraryConstraintBuilder> audioViewBuilder =
815 NS_ENSURE_SUCCESS(rv, rv);
818 NS_LITERAL_STRING(
"0"),
820 NS_ENSURE_SUCCESS(rv, rv);
822 rv = audioViewBuilder->Intersect(nsnull);
823 NS_ENSURE_SUCCESS(rv, rv);
826 NS_LITERAL_STRING(
"0"),
828 NS_ENSURE_SUCCESS(rv, rv);
830 rv = audioViewBuilder->Intersect(nsnull);
831 NS_ENSURE_SUCCESS(rv, rv);
834 NS_LITERAL_STRING(
"audio"),
836 NS_ENSURE_SUCCESS(rv, rv);
838 nsCOMPtr<sbILibraryConstraintBuilder> videoViewBuilder =
840 NS_ENSURE_SUCCESS(rv, rv);
843 NS_LITERAL_STRING(
"0"),
845 NS_ENSURE_SUCCESS(rv, rv);
847 rv = videoViewBuilder->Intersect(nsnull);
848 NS_ENSURE_SUCCESS(rv, rv);
851 NS_LITERAL_STRING(
"0"),
853 NS_ENSURE_SUCCESS(rv, rv);
855 rv = videoViewBuilder->Intersect(nsnull);
856 NS_ENSURE_SUCCESS(rv, rv);
859 NS_LITERAL_STRING(
"video"),
861 NS_ENSURE_SUCCESS(rv, rv);
863 nsCOMPtr<sbILibraryConstraint> audioViewConstraint;
864 rv = audioViewBuilder->Get(getter_AddRefs(audioViewConstraint));
865 NS_ENSURE_SUCCESS(rv, rv);
867 nsCOMPtr<sbILibraryConstraint> videoViewConstraint;
868 rv = videoViewBuilder->Get(getter_AddRefs(videoViewConstraint));
869 NS_ENSURE_SUCCESS(rv, rv);
871 PRBool isEqualToAudioView = PR_FALSE;
872 rv = mViewFilter->Equals(audioViewConstraint, &isEqualToAudioView);
873 NS_ENSURE_SUCCESS(rv, rv);
875 PRBool isEqualToVideoView = PR_FALSE;
876 rv = mViewFilter->Equals(videoViewConstraint, &isEqualToVideoView);
877 NS_ENSURE_SUCCESS(rv, rv);
879 if(isEqualToAudioView) {
881 viewContentType = NS_LITERAL_STRING(
"audio");
883 else if(isEqualToVideoView) {
885 viewContentType = NS_LITERAL_STRING(
"video");
890 PRUint32 searchCount = 0;
892 rv = mViewSearch->GetGroupCount(&searchCount);
893 NS_ENSURE_SUCCESS(rv, rv);
896 PRBool cfsIsFiltering = PR_FALSE;
898 if(mCascadeFilterSet) {
899 PRUint16 cfsCount = 0;
900 rv = mCascadeFilterSet->GetLength(&cfsCount);
901 NS_ENSURE_SUCCESS(rv, rv);
903 for(PRUint16 current = 0; current < cfsCount; ++current) {
904 nsCOMPtr<nsIArray> filterConfig;
906 rv = mCascadeFilterSet->Get(current, getter_AddRefs(filterConfig));
907 NS_ENSURE_SUCCESS(rv, rv);
910 rv = filterConfig->GetLength(&length);
911 NS_ENSURE_SUCCESS(rv, rv);
914 cfsIsFiltering = PR_TRUE;
920 PRBool isSelected = PR_FALSE;
921 PRInt32 currentIndex;
922 rv = mSelection->GetCurrentIndex(¤tIndex);
923 NS_ENSURE_SUCCESS(rv, rv);
925 rv = mSelection->IsIndexSelected(currentIndex, &isSelected);
926 NS_ENSURE_SUCCESS(rv, rv);
933 if((PRInt32(viewLength) == selectionLength) && !filterCount && !searchCount && !cfsIsFiltering) {
936 if(mMediaListId == 0) {
937 rv = mLibrary->ClearItemsByType(viewContentType);
938 NS_ENSURE_SUCCESS(rv, rv);
942 rv = mMediaList->Clear();
943 NS_ENSURE_SUCCESS(rv, rv);
948 rv = mSelection->GetSelectedIndexedMediaItems(getter_AddRefs(selection));
949 NS_ENSURE_SUCCESS(rv, rv);
951 rv = mLibrary->RemoveSelected(selection,
this);
952 NS_ENSURE_SUCCESS(rv, rv);
957 rv = mSelection->SelectNone();
958 NS_ENSURE_SUCCESS(rv, rv);
968 NS_ENSURE_ARG_POINTER(aSource);
969 NS_ENSURE_ARG_POINTER(_retval);
973 nsCOMPtr<sbIMutablePropertyArray>
clone =
975 NS_ENSURE_SUCCESS(rv, rv);
978 rv = aSource->GetValidated(&strict);
979 NS_ENSURE_SUCCESS(rv, rv);
981 rv = clone->SetStrict(strict);
982 NS_ENSURE_SUCCESS(rv, rv);
984 PRUint32 propertyCount;
985 rv = aSource->GetLength(&propertyCount);
986 NS_ENSURE_SUCCESS(rv, rv);
988 for (PRUint32
i = 0;
i < propertyCount;
i++) {
989 nsCOMPtr<sbIProperty> property;
990 rv = aSource->GetPropertyAt(
i, getter_AddRefs(property));
991 NS_ENSURE_SUCCESS(rv, rv);
994 rv =
property->GetId(propertyID);
995 NS_ENSURE_SUCCESS(rv, rv);
998 rv =
property->GetValue(value);
999 NS_ENSURE_SUCCESS(rv, rv);
1001 rv = clone->AppendProperty(propertyID, value);
1002 NS_ENSURE_SUCCESS(rv, rv);
1005 NS_ADDREF(*_retval = clone);
1012 nsStringArray * aPropertiesToIgnore,
1013 PRBool* aHasCommonProperty)
1015 NS_ASSERTION(aBag1,
"aBag1 is null");
1016 NS_ASSERTION(aBag2,
"aBag2 is null");
1017 NS_ASSERTION(aHasCommonProperty,
"aHasCommonProperty is null");
1020 nsresult rv = aBag1->GetLength(&length);
1021 NS_ENSURE_SUCCESS(rv, rv);
1024 nsCOMPtr<sbIProperty> property;
1025 rv = aBag1->GetPropertyAt(
i, getter_AddRefs(property));
1026 NS_ENSURE_SUCCESS(rv, rv);
1028 nsString propertyID;
1029 rv =
property->GetId(propertyID);
1030 NS_ENSURE_SUCCESS(rv, rv);
1033 if (!aPropertiesToIgnore ||
1034 aPropertiesToIgnore->IndexOf(propertyID) == -1) {
1036 rv = aBag2->GetPropertyValue(propertyID, junk);
1037 if (NS_SUCCEEDED(rv)) {
1038 *aHasCommonProperty = PR_TRUE;
1044 *aHasCommonProperty = PR_FALSE;
1051 PRBool* aHasCommonProperty)
1053 NS_ASSERTION(aBag,
"aBag is null");
1054 NS_ASSERTION(aConstraint,
"aConstraint is null");
1055 NS_ASSERTION(aHasCommonProperty,
"aHasCommonProperty is null");
1058 nsresult rv = aBag->GetLength(&length);
1059 NS_ENSURE_SUCCESS(rv, rv);
1062 nsCOMPtr<sbIProperty> property;
1063 rv = aBag->GetPropertyAt(
i, getter_AddRefs(property));
1064 NS_ENSURE_SUCCESS(rv, rv);
1066 nsString propertyID;
1067 rv =
property->GetId(propertyID);
1068 NS_ENSURE_SUCCESS(rv, rv);
1070 PRUint32 groupCount;
1071 rv = aConstraint->GetGroupCount(&groupCount);
1072 NS_ENSURE_SUCCESS(rv, rv);
1074 for (PRUint32 j = 0; j < groupCount; j++) {
1075 nsCOMPtr<sbILibraryConstraintGroup>
group;
1076 rv = aConstraint->GetGroup(j, getter_AddRefs(group));
1077 NS_ENSURE_SUCCESS(rv, rv);
1080 rv = group->HasProperty(propertyID, &hasProperty);
1081 NS_ENSURE_SUCCESS(rv, rv);
1084 *aHasCommonProperty = PR_TRUE;
1090 *aHasCommonProperty = PR_FALSE;
1096 sbLocalDatabaseMediaListView::ShouldCauseInvalidation(
sbIPropertyArray* aProperties,
1097 PRBool* aShouldCauseInvalidation)
1099 NS_ASSERTION(aProperties,
"aProperties is null");
1100 NS_ASSERTION(aShouldCauseInvalidation,
"aShouldCauseInvalidation is null");
1104 *aShouldCauseInvalidation = PR_TRUE;
1110 nsCOMPtr<sbIPropertyArray> props;
1111 rv = GetCurrentSort(getter_AddRefs(props));
1112 NS_ENSURE_SUCCESS(rv, rv);
1113 rv = HasCommonProperty(aProperties, props, &mIgnoreSystemProperties, &hasCommon);
1114 NS_ENSURE_SUCCESS(rv, rv);
1120 nsCOMPtr<sbIProperty>
property = nsnull;
1121 rv = props->GetPropertyAt(0, getter_AddRefs(property));
1122 if (NS_SUCCEEDED(rv) && property) {
1123 nsString propertyID;
1124 rv =
property->GetId(propertyID);
1125 NS_ENSURE_SUCCESS(rv, rv);
1127 nsCOMPtr<sbIPropertyInfo> propertyInfo;
1128 nsCOMPtr<sbIPropertyManager> propertyManager =
1130 NS_ENSURE_SUCCESS(rv, rv);
1131 rv = propertyManager->GetPropertyInfo(propertyID,
1132 getter_AddRefs(propertyInfo));
1133 NS_ENSURE_SUCCESS(rv, rv);
1135 nsCOMPtr<sbIPropertyArray> secondarySort = nsnull;
1136 rv = propertyInfo->GetSecondarySort(getter_AddRefs(secondarySort));
1138 if (NS_SUCCEEDED(rv) && secondarySort) {
1139 rv = HasCommonProperty(aProperties, secondarySort, &mIgnoreSystemProperties, &hasCommon);
1140 NS_ENSURE_SUCCESS(rv, rv);
1148 nsCOMPtr<sbILibraryConstraint>
filter;
1149 rv = GetFilterConstraint(getter_AddRefs(filter));
1150 NS_ENSURE_SUCCESS(rv, rv);
1152 rv = HasCommonProperty(aProperties, filter, &hasCommon);
1153 NS_ENSURE_SUCCESS(rv, rv);
1160 nsCOMPtr<sbILibraryConstraint>
search;
1161 rv = GetSearchConstraint(getter_AddRefs(search));
1162 NS_ENSURE_SUCCESS(rv, rv);
1164 rv = HasCommonProperty(aProperties, search, &hasCommon);
1165 NS_ENSURE_SUCCESS(rv, rv);
1171 *aShouldCauseInvalidation = PR_FALSE;
1177 sbLocalDatabaseMediaListView::UpdateListener(PRBool aRemoveListener)
1181 nsCOMPtr<sbIMediaListListener> listener =
1184 if (aRemoveListener) {
1185 rv = mMediaList->RemoveListener(listener);
1205 rv = mMediaList->AddListener(listener,
1213 sbLocalDatabaseMediaListView::NotifyListenersInternal(ListenerFunc aListenerFunc)
1215 sbViewListenerArray listeners;
1220 nsAutoLock lock(mListenerTableLock);
1221 mListenerTable.EnumerateEntries(AddListenersToCOMArray, &listeners);
1226 PRInt32
count = listeners.Count();
1227 for (PRInt32 index = 0; index <
count; index++) {
1229 (listener->*aListenerFunc)(thisPtr);
1236 NS_ENSURE_ARG_POINTER(aFilterConstraint);
1241 nsCOMPtr<sbILibraryConstraintBuilder> builder =
1243 NS_ENSURE_SUCCESS(rv, rv);
1245 rv = builder->IncludeConstraint(mViewFilter, nsnull);
1246 NS_ENSURE_SUCCESS(rv, rv);
1248 nsCOMPtr<sbILibraryConstraint> constraint;
1249 rv = builder->Get(getter_AddRefs(constraint));
1250 NS_ENSURE_SUCCESS(rv, rv);
1252 NS_ADDREF(*aFilterConstraint = constraint);
1255 *aFilterConstraint = nsnull;
1265 NS_ENSURE_ARG_POINTER(aFilterConstraint);
1269 nsCOMPtr<sbILibraryConstraintBuilder> builder =
1271 NS_ENSURE_SUCCESS(rv, rv);
1274 rv = builder->IncludeConstraint(mViewFilter, nsnull);
1275 NS_ENSURE_SUCCESS(rv, rv);
1279 PRBool changed = PR_FALSE;
1280 if (mCascadeFilterSet) {
1281 rv = mCascadeFilterSet->AddFilters(builder, &changed);
1282 NS_ENSURE_SUCCESS(rv, rv);
1285 if (mViewFilter || changed) {
1286 nsCOMPtr<sbILibraryConstraint> constraint;
1287 rv = builder->Get(getter_AddRefs(constraint));
1288 NS_ENSURE_SUCCESS(rv, rv);
1290 NS_ADDREF(*aFilterConstraint = constraint);
1293 *aFilterConstraint = nsnull;
1307 if (aFilterConstraint) {
1308 PRUint32 groupCount;
1309 rv = aFilterConstraint->GetGroupCount(&groupCount);
1310 NS_ENSURE_SUCCESS(rv, rv);
1312 for (PRUint32
i = 0;
i < groupCount;
i++) {
1313 nsCOMPtr<sbILibraryConstraintGroup>
group;
1314 rv = aFilterConstraint->GetGroup(
i, getter_AddRefs(group));
1315 NS_ENSURE_SUCCESS(rv, rv);
1317 nsCOMPtr<nsIStringEnumerator> properties;
1318 rv = group->GetProperties(getter_AddRefs(properties));
1319 NS_ENSURE_SUCCESS(rv, rv);
1322 rv = properties->GetNext(junk);
1323 NS_ENSURE_SUCCESS(rv, rv);
1326 rv = properties->HasMore(&HasMore);
1327 NS_ENSURE_SUCCESS(rv, rv);
1330 return NS_ERROR_INVALID_ARG;
1335 mViewFilter = aFilterConstraint;
1338 if (!aFilterConstraint && mCascadeFilterSet) {
1339 rv = mCascadeFilterSet->ClearFilters();
1340 NS_ENSURE_SUCCESS(rv, rv);
1344 NS_ENSURE_SUCCESS(rv, rv);
1356 NS_ENSURE_ARG_POINTER(aSearchConstraint);
1360 nsCOMPtr<sbILibraryConstraintBuilder> builder =
1362 NS_ENSURE_SUCCESS(rv, rv);
1365 rv = builder->IncludeConstraint(mViewSearch, nsnull);
1366 NS_ENSURE_SUCCESS(rv, rv);
1370 PRBool changed = PR_FALSE;
1371 if (mCascadeFilterSet) {
1372 rv = mCascadeFilterSet->AddSearches(builder, &changed);
1373 NS_ENSURE_SUCCESS(rv, rv);
1376 if (mViewSearch || changed) {
1377 nsCOMPtr<sbILibraryConstraint> constraint;
1378 rv = builder->Get(getter_AddRefs(constraint));
1379 NS_ENSURE_SUCCESS(rv, rv);
1381 NS_ADDREF(*aSearchConstraint = constraint);
1384 *aSearchConstraint = nsnull;
1399 if (aSearchConstraint) {
1400 PRUint32 groupCount;
1401 rv = aSearchConstraint->GetGroupCount(&groupCount);
1402 NS_ENSURE_SUCCESS(rv, rv);
1405 NS_ENSURE_TRUE(groupCount == 1, NS_ERROR_INVALID_ARG);
1407 nsCOMPtr<sbILibraryConstraintGroup> firstGroup;
1408 rv = aSearchConstraint->GetGroup(0, getter_AddRefs(firstGroup));
1409 NS_ENSURE_SUCCESS(rv, rv);
1411 nsCOMPtr<nsIStringEnumerator> firstGroupProperties;
1412 rv = firstGroup->GetProperties(getter_AddRefs(firstGroupProperties));
1413 NS_ENSURE_SUCCESS(rv, rv);
1416 rv = firstGroupProperties->GetNext(property);
1417 NS_ENSURE_SUCCESS(rv, rv);
1421 rv = firstGroupProperties->HasMore(&hasMore);
1422 NS_ENSURE_FALSE(hasMore, NS_ERROR_INVALID_ARG);
1425 nsCOMPtr<nsIStringEnumerator> values;
1426 rv = firstGroup->GetValues(property, getter_AddRefs(values));
1427 NS_ENSURE_SUCCESS(rv, rv);
1429 PRBool hasMoreValues;
1430 while (NS_SUCCEEDED(values->HasMore(&hasMoreValues)) && hasMoreValues) {
1432 rv = values->GetNext(value);
1433 NS_ENSURE_SUCCESS(rv, rv);
1435 if (value.IsEmpty()) {
1436 return NS_ERROR_INVALID_ARG;
1441 mViewSearch = aSearchConstraint;
1444 if (!aSearchConstraint && mCascadeFilterSet) {
1445 rv = mCascadeFilterSet->ClearSearches();
1446 NS_ENSURE_SUCCESS(rv, rv);
1450 NS_ENSURE_SUCCESS(rv, rv);
1460 sbLocalDatabaseMediaListView::GetSortableProperties(
nsIStringEnumerator** aSortableProperties)
1462 NS_ENSURE_ARG_POINTER(aSortableProperties);
1464 return NS_ERROR_NOT_IMPLEMENTED;
1468 sbLocalDatabaseMediaListView::GetCurrentSort(
sbIPropertyArray** aCurrentSort)
1470 NS_ENSURE_ARG_POINTER(aCurrentSort);
1471 NS_ENSURE_STATE(mViewSort);
1473 NS_ADDREF(*aCurrentSort = mViewSort);
1480 nsresult rv = SetSortInternal(aSort);
1481 NS_ENSURE_SUCCESS(rv, rv);
1493 rv = ClonePropertyArray(aSort, getter_AddRefs(mViewSort));
1494 NS_ENSURE_SUCCESS(rv, rv);
1499 NS_ENSURE_SUCCESS(rv, rv);
1501 rv = mViewSort->SetStrict(PR_FALSE);
1502 NS_ENSURE_SUCCESS(rv, rv);
1505 nsCOMPtr<nsIArray> array = do_QueryInterface(mViewSort, &rv);
1506 NS_ENSURE_SUCCESS(rv, rv);
1509 rv = array->GetLength(&length);
1510 NS_ENSURE_SUCCESS(rv, rv);
1514 rv = mViewSort->AppendProperty(mDefaultSortProperty,
1515 NS_LITERAL_STRING(
"a"));
1516 NS_ENSURE_SUCCESS(rv, rv);
1520 NS_ENSURE_SUCCESS(rv, rv);
1522 rv = UpdateListener(PR_FALSE);
1523 NS_ENSURE_SUCCESS(rv, rv);
1532 sbLocalDatabaseMediaListView::ClearSort()
1537 nsCOMPtr<nsIMutableArray> array = do_QueryInterface(mViewSort, &rv);
1538 NS_ENSURE_SUCCESS(rv, rv);
1540 rv = array->Clear();
1541 NS_ENSURE_SUCCESS(rv, rv);
1543 rv = SetSort(nsnull);
1544 NS_ENSURE_SUCCESS(rv, rv);
1555 sbLocalDatabaseMediaListView::OnItemAdded(
sbIMediaList* aMediaList,
1558 PRBool* aNoMoreForBatch)
1560 NS_ENSURE_ARG_POINTER(aMediaList);
1561 NS_ENSURE_ARG_POINTER(aMediaItem);
1562 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
1565 mInvalidatePending = PR_TRUE;
1566 *aNoMoreForBatch = PR_TRUE;
1571 nsresult rv = Invalidate(PR_TRUE);
1572 NS_ENSURE_SUCCESS(rv, rv);
1574 *aNoMoreForBatch = PR_FALSE;
1579 sbLocalDatabaseMediaListView::OnBeforeItemRemoved(
sbIMediaList* aMediaList,
1582 PRBool* aNoMoreForBatch)
1584 NS_ENSURE_ARG_POINTER(aMediaList);
1585 NS_ENSURE_ARG_POINTER(aMediaItem);
1586 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
1590 *aNoMoreForBatch = PR_TRUE;
1595 sbLocalDatabaseMediaListView::OnAfterItemRemoved(
sbIMediaList* aMediaList,
1598 PRBool* aNoMoreForBatch)
1600 NS_ENSURE_ARG_POINTER(aMediaList);
1601 NS_ENSURE_ARG_POINTER(aMediaItem);
1602 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
1605 mInvalidatePending = PR_TRUE;
1606 *aNoMoreForBatch = PR_TRUE;
1611 nsresult rv = Invalidate(PR_TRUE);
1612 NS_ENSURE_SUCCESS(rv, rv);
1614 *aNoMoreForBatch = PR_FALSE;
1619 sbLocalDatabaseMediaListView::OnItemUpdated(
sbIMediaList* aMediaList,
1622 PRBool* aNoMoreForBatch)
1624 NS_ENSURE_ARG_POINTER(aMediaList);
1625 NS_ENSURE_ARG_POINTER(aMediaItem);
1626 NS_ENSURE_ARG_POINTER(aProperties);
1627 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
1631 aProperties->ToString(buff);
1632 TRACE((
"sbLocalDatabaseMediaListView[0x%.8x] - OnItemUpdated %s",
1633 this, NS_ConvertUTF16toUTF8(buff).
get()));
1640 PRBool shouldInvalidate;
1642 shouldInvalidate = PR_FALSE;
1643 mInvalidatePending = PR_TRUE;
1644 *aNoMoreForBatch = PR_TRUE;
1649 rv = ShouldCauseInvalidation(aProperties, &shouldInvalidate);
1650 NS_ENSURE_SUCCESS(rv, rv);
1651 *aNoMoreForBatch = PR_FALSE;
1654 if (shouldInvalidate) {
1657 nsresult rv = Invalidate(PR_TRUE);
1658 NS_ENSURE_SUCCESS(rv, rv);
1666 rv = aMediaItem->GetGuid(guid);
1667 NS_ENSURE_SUCCESS(rv, rv);
1669 rv = mTreeView->InvalidateRowsByGuid(guid);
1670 NS_ENSURE_SUCCESS(rv, rv);
1678 sbLocalDatabaseMediaListView::OnItemMoved(
sbIMediaList* aMediaList,
1679 PRUint32 aFromIndex,
1681 PRBool* aNoMoreForBatch)
1683 NS_ENSURE_ARG_POINTER(aMediaList);
1684 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
1687 mInvalidatePending = PR_TRUE;
1688 *aNoMoreForBatch = PR_TRUE;
1693 nsresult rv = Invalidate(PR_FALSE);
1694 NS_ENSURE_SUCCESS(rv, rv);
1696 *aNoMoreForBatch = PR_FALSE;
1701 sbLocalDatabaseMediaListView::OnBeforeListCleared(
sbIMediaList* aMediaList,
1702 PRBool aExcludeLists,
1703 PRBool* aNoMoreForBatch)
1705 NS_ENSURE_ARG_POINTER(aMediaList);
1706 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
1710 *aNoMoreForBatch = PR_TRUE;
1715 sbLocalDatabaseMediaListView::OnListCleared(
sbIMediaList* aMediaList,
1716 PRBool aExcludeLists,
1717 PRBool* aNoMoreForBatch)
1719 NS_ENSURE_ARG_POINTER(aMediaList);
1720 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
1723 mInvalidatePending = PR_TRUE;
1724 *aNoMoreForBatch = PR_TRUE;
1729 nsresult rv = Invalidate(PR_TRUE);
1730 NS_ENSURE_SUCCESS(rv, rv);
1732 *aNoMoreForBatch = PR_FALSE;
1737 sbLocalDatabaseMediaListView::OnBatchBegin(
sbIMediaList* aMediaList)
1739 mBatchHelper.
Begin();
1742 mTreeView->SetShouldPreventRebuild(PR_TRUE);
1749 sbLocalDatabaseMediaListView::OnBatchEnd(
sbIMediaList* aMediaList)
1754 if (mInvalidatePending) {
1757 nsresult rv = Invalidate(PR_TRUE);
1758 NS_ENSURE_SUCCESS(rv, rv);
1760 mInvalidatePending = PR_FALSE;
1768 mTreeView->SetShouldPreventRebuild(PR_FALSE);
1769 mTreeView->Rebuild();
1783 rv = mArray->ClearFilters();
1784 NS_ENSURE_SUCCESS(rv, rv);
1790 PRUint32 groupCount;
1791 rv = mViewFilter->GetGroupCount(&groupCount);
1792 NS_ENSURE_SUCCESS(rv, rv);
1794 for (PRUint32
i = 0;
i < groupCount;
i++) {
1796 nsCOMPtr<sbILibraryConstraintGroup>
group;
1797 rv = mViewFilter->GetGroup(
i, getter_AddRefs(group));
1798 NS_ENSURE_SUCCESS(rv, rv);
1800 nsCOMPtr<nsIStringEnumerator> properties;
1801 rv = group->GetProperties(getter_AddRefs(properties));
1802 NS_ENSURE_SUCCESS(rv, rv);
1806 rv = properties->GetNext(property);
1807 NS_ENSURE_SUCCESS(rv, rv);
1809 nsCOMPtr<nsIStringEnumerator> values;
1810 rv = group->GetValues(property, getter_AddRefs(values));
1811 NS_ENSURE_SUCCESS(rv, rv);
1816 nsCOMPtr<sbIPropertyInfo> info;
1817 rv = mPropMan->GetPropertyInfo(property, getter_AddRefs(info));
1818 NS_ENSURE_SUCCESS(rv, rv);
1820 nsCOMPtr<nsIStringEnumerator> sortable =
1822 NS_ENSURE_TRUE(sortable, NS_ERROR_OUT_OF_MEMORY);
1828 rv = mArray->AddFilter(property, values, PR_FALSE);
1829 NS_ENSURE_SUCCESS(rv, rv);
1837 PRUint32 groupCount;
1838 rv = mViewSearch->GetGroupCount(&groupCount);
1839 NS_ENSURE_SUCCESS(rv, rv);
1843 nsCOMPtr<sbILibraryConstraintGroup> firstGroup;
1844 rv = mViewSearch->GetGroup(0, getter_AddRefs(firstGroup));
1845 NS_ENSURE_SUCCESS(rv, rv);
1847 nsCOMPtr<nsIStringEnumerator> firstGroupProperties;
1848 rv = firstGroup->GetProperties(getter_AddRefs(firstGroupProperties));
1849 NS_ENSURE_SUCCESS(rv, rv);
1852 while (NS_SUCCEEDED(firstGroupProperties->HasMore(&hasMore)) && hasMore) {
1854 rv = firstGroupProperties->GetNext(property);
1855 NS_ENSURE_SUCCESS(rv, rv);
1858 sbStringArray allValues;
1859 for (PRUint32
i = 0;
i < groupCount;
i++) {
1860 nsCOMPtr<sbILibraryConstraintGroup>
group;
1861 rv = mViewSearch->GetGroup(
i, getter_AddRefs(group));
1862 NS_ENSURE_SUCCESS(rv, rv);
1864 nsCOMPtr<nsIStringEnumerator> values;
1865 rv = group->GetValues(property, getter_AddRefs(values));
1866 NS_ENSURE_SUCCESS(rv, rv);
1868 PRBool hasMoreValues;
1869 while (NS_SUCCEEDED(values->HasMore(&hasMoreValues)) && hasMoreValues) {
1871 rv = values->GetNext(value);
1872 NS_ENSURE_SUCCESS(rv, rv);
1874 nsString* added = allValues.AppendElement(value);
1875 NS_ENSURE_TRUE(added, NS_ERROR_OUT_OF_MEMORY);
1878 nsCOMPtr<nsIStringEnumerator> allValuesEnum =
1880 NS_ENSURE_TRUE(allValuesEnum, NS_ERROR_OUT_OF_MEMORY);
1885 nsCOMPtr<sbIPropertyInfo> info;
1886 rv = mPropMan->GetPropertyInfo(property, getter_AddRefs(info));
1887 NS_ENSURE_SUCCESS(rv, rv);
1889 nsCOMPtr<nsIStringEnumerator> sortable =
1891 NS_ENSURE_TRUE(sortable, NS_ERROR_OUT_OF_MEMORY);
1893 allValuesEnum = sortable;
1896 rv = mArray->AddFilter(property, allValuesEnum, PR_TRUE);
1897 NS_ENSURE_SUCCESS(rv, rv);
1903 if (mCascadeFilterSet) {
1904 rv = mCascadeFilterSet->AddConfiguration(mArray);
1905 NS_ENSURE_SUCCESS(rv, rv);
1909 rv = mArray->ClearSorts();
1910 NS_ENSURE_SUCCESS(rv, rv);
1912 PRBool hasSorts = PR_FALSE;
1914 PRUint32 propertyCount;
1915 rv = mViewSort->GetLength(&propertyCount);
1916 NS_ENSURE_SUCCESS(rv, rv);
1918 for (PRUint32 index = 0; index < propertyCount; index++) {
1920 nsCOMPtr<sbIProperty> property;
1921 rv = mViewSort->GetPropertyAt(index, getter_AddRefs(property));
1922 NS_ENSURE_SUCCESS(rv, rv);
1924 nsString propertyID;
1925 rv =
property->GetId(propertyID);
1926 NS_ENSURE_SUCCESS(rv, rv);
1929 rv =
property->GetValue(value);
1930 NS_ENSURE_SUCCESS(rv, rv);
1932 mArray->AddSort(propertyID, value.EqualsLiteral(
"a"));
1933 NS_ENSURE_SUCCESS(rv, rv);
1941 mArray->AddSort(mDefaultSortProperty, PR_TRUE);
1942 NS_ENSURE_SUCCESS(rv, rv);
1946 if (aClearTreeSelection) {
1947 rv = mSelection->SelectNone();
1948 NS_ENSURE_SUCCESS(rv, rv);
1955 sbLocalDatabaseMediaListView::MakeStandardQuery(
sbIDatabaseQuery** _retval)
1958 nsCOMPtr<sbIDatabaseQuery> query =
1960 NS_ENSURE_SUCCESS(rv, rv);
1962 nsAutoString databaseGuid;
1963 rv = mLibrary->GetDatabaseGuid(databaseGuid);
1964 NS_ENSURE_SUCCESS(rv, rv);
1966 rv = query->SetDatabaseGUID(databaseGuid);
1967 NS_ENSURE_SUCCESS(rv, rv);
1969 nsCOMPtr<nsIURI> databaseLocation;
1970 rv = mLibrary->GetDatabaseLocation(getter_AddRefs(databaseLocation));
1971 NS_ENSURE_SUCCESS(rv, rv);
1973 if (databaseLocation) {
1974 rv = query->SetDatabaseLocation(databaseLocation);
1975 NS_ENSURE_SUCCESS(rv, rv);
1978 rv = query->SetAsyncQuery(PR_FALSE);
1979 NS_ENSURE_SUCCESS(rv, rv);
1981 NS_ADDREF(*_retval = query);
1986 sbLocalDatabaseMediaListView::CreateQueries()
1990 nsCOMPtr<sbISQLSelectBuilder> builder =
1992 NS_ENSURE_SUCCESS(rv, rv);
1994 nsCOMPtr<sbISQLBuilderCriterion> criterion;
1997 rv = builder->SetDistinct(PR_TRUE);
1998 NS_ENSURE_SUCCESS(rv, rv);
2000 rv = builder->AddColumn(NS_LITERAL_STRING(
"_rp"),
2001 NS_LITERAL_STRING(
"obj"));
2002 NS_ENSURE_SUCCESS(rv, rv);
2004 if (mMediaListId == 0) {
2005 rv = builder->SetBaseTableName(NS_LITERAL_STRING(
"properties"));
2006 NS_ENSURE_SUCCESS(rv, rv);
2008 rv = builder->SetBaseTableAlias(NS_LITERAL_STRING(
"_p"));
2009 NS_ENSURE_SUCCESS(rv, rv);
2011 rv = builder->SetDistinct(PR_TRUE);
2012 NS_ENSURE_SUCCESS(rv, rv);
2014 rv = builder->AddColumn(NS_LITERAL_STRING(
"_rp"),
2015 NS_LITERAL_STRING(
"obj"));
2016 NS_ENSURE_SUCCESS(rv, rv);
2019 NS_LITERAL_STRING(
"resource_properties"),
2020 NS_LITERAL_STRING(
"_rp"),
2021 NS_LITERAL_STRING(
"property_id"),
2022 NS_LITERAL_STRING(
"_p"),
2023 NS_LITERAL_STRING(
"property_id"));
2024 NS_ENSURE_SUCCESS(rv, rv);
2026 rv = builder->CreateMatchCriterionParameter(NS_LITERAL_STRING(
"_p"),
2027 NS_LITERAL_STRING(
"property_name"),
2029 getter_AddRefs(criterion));
2030 NS_ENSURE_SUCCESS(rv, rv);
2032 rv = builder->AddCriterion(criterion);
2033 NS_ENSURE_SUCCESS(rv, rv);
2036 rv = builder->SetBaseTableName(NS_LITERAL_STRING(
"media_items"));
2037 NS_ENSURE_SUCCESS(rv, rv);
2039 rv = builder->SetBaseTableAlias(NS_LITERAL_STRING(
"_mi"));
2040 NS_ENSURE_SUCCESS(rv, rv);
2043 NS_LITERAL_STRING(
"simple_media_lists"),
2044 NS_LITERAL_STRING(
"_sml"),
2045 NS_LITERAL_STRING(
"member_media_item_id"),
2046 NS_LITERAL_STRING(
"_mi"),
2047 NS_LITERAL_STRING(
"media_item_id"));
2048 NS_ENSURE_SUCCESS(rv, rv);
2050 rv = builder->CreateMatchCriterionLong(NS_LITERAL_STRING(
"_sml"),
2051 NS_LITERAL_STRING(
"media_item_id"),
2054 getter_AddRefs(criterion));
2055 NS_ENSURE_SUCCESS(rv, rv);
2057 rv = builder->AddCriterion(criterion);
2058 NS_ENSURE_SUCCESS(rv, rv);
2061 NS_LITERAL_STRING(
"resource_properties"),
2062 NS_LITERAL_STRING(
"_rp"),
2063 NS_LITERAL_STRING(
"guid"),
2064 NS_LITERAL_STRING(
"_mi"),
2065 NS_LITERAL_STRING(
"guid"));
2066 NS_ENSURE_SUCCESS(rv, rv);
2069 NS_LITERAL_STRING(
"properties"),
2070 NS_LITERAL_STRING(
"_p"),
2071 NS_LITERAL_STRING(
"property_id"),
2072 NS_LITERAL_STRING(
"_rp"),
2073 NS_LITERAL_STRING(
"property_id"));
2074 NS_ENSURE_SUCCESS(rv, rv);
2076 rv = builder->CreateMatchCriterionParameter(NS_LITERAL_STRING(
"_p"),
2077 NS_LITERAL_STRING(
"property_name"),
2079 getter_AddRefs(criterion));
2080 NS_ENSURE_SUCCESS(rv, rv);
2082 rv = builder->AddCriterion(criterion);
2083 NS_ENSURE_SUCCESS(rv, rv);
2086 rv = builder->AddOrder(NS_LITERAL_STRING(
"_rp"),
2087 NS_LITERAL_STRING(
"obj_sortable"),
2089 NS_ENSURE_SUCCESS(rv, rv);
2091 rv = builder->ToString(mDistinctPropertyValuesQuery);
2092 NS_ENSURE_SUCCESS(rv, rv);
2098 sbLocalDatabaseMediaListView::Invalidate(PRBool aInvalidateLength)
2100 LOG((
"sbLocalDatabaseMediaListView[0x%.8x] - Invalidate",
this));
2104 rv = mArray->Invalidate(aInvalidateLength);
2105 NS_ENSURE_SUCCESS(rv, rv);
2108 rv = mSelection->ConfigurationChanged();
2109 NS_ENSURE_SUCCESS(rv, rv);
2116 sbLocalDatabaseMediaListView::GetInterfaces(PRUint32* count, nsIID*** array)
2118 return NS_CI_INTERFACE_GETTER_NAME(sbLocalDatabaseMediaListView)(
count,
array);
2122 sbLocalDatabaseMediaListView::GetHelperForLanguage(PRUint32
language,
2130 sbLocalDatabaseMediaListView::GetContractID(
char** aContractID)
2132 *aContractID = nsnull;
2137 sbLocalDatabaseMediaListView::GetClassDescription(
char** aClassDescription)
2139 *aClassDescription = nsnull;
2144 sbLocalDatabaseMediaListView::GetClassID(nsCID** aClassID)
2151 sbLocalDatabaseMediaListView::GetImplementationLanguage(PRUint32* aImplementationLanguage)
2153 *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
2158 sbLocalDatabaseMediaListView::GetFlags(PRUint32 *aFlags)
2165 sbLocalDatabaseMediaListView::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc)
2167 return NS_ERROR_NOT_AVAILABLE;
2174 mPropertyInfo(aPropertyInfo),
2177 NS_ASSERTION(aPropertyInfo,
"aPropertyInfo is null");
2178 NS_ASSERTION(aValues,
"aValues is null");
2182 sbMakeSortableStringEnumerator::HasMore(PRBool* _retval)
2184 return mValues->HasMore(_retval);
2188 sbMakeSortableStringEnumerator::GetNext(nsAString& _retval)
2193 rv = mValues->GetNext(value);
2194 NS_ENSURE_SUCCESS(rv, rv);
2196 rv = mPropertyInfo->MakeSortable(value, _retval);
2197 NS_ENSURE_SUCCESS(rv, rv);
#define SB_PROPERTY_PLAYCOUNT
#define SONGBIRD_DATABASEQUERY_CONTRACTID
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
nsTArray< nsString > sbStringArray
Cascade filter management for a media list.
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
#define SB_PROPERTY_HIDDEN
virtual ~sbSuppressArrayInvalidationView()
#define SB_LOCALDATABASE_ASYNCGUIDARRAY_CONTRACTID
static PRBool SB_IsTopLevelProperty(PRUint32 aPropertyDBID)
#define SB_PROPERTY_LASTPLAYTIME
#define SONGBIRD_LIBRARY_CONSTRAINTBUILDER_CONTRACTID
#define SB_PROPERTYMANAGER_CONTRACTID
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
#define SB_SQLBUILDER_SELECT_CONTRACTID
function search(aFolderId, aSearchStr, aExpectedScopeButtonId)
#define SB_PROPERTY_CONTENTTYPE
An interface used to describe a metadata property for use by the UI and other sbILibrary interfaces (...
const unsigned long JOIN_INNER
StringArrayEnumerator prototype hasMore
sbSuppressArrayInvalidationView(sbILocalDatabaseGUIDArray *aArray, sbLocalDatabaseMediaListViewSelection *aSelection)
An object responsible for executing SQL queries on the database.
#define SB_PROPERTY_LASTSKIPTIME
#define SB_PROPERTY_ISLIST
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
_getSelectedPageStyle s i
Array filter(tab.attributes, function(aAttr){return(_this.xulAttributes.indexOf(aAttr.name) >-1);}).forEach(tab.removeAttribute
#define SB_PROPERTY_SKIPCOUNT
const unsigned long MATCH_EQUALS
Songbird Database Object Definition.