25 #ifndef __SBLOCALDATABASESMARTMEDIALIST_H__
26 #define __SBLOCALDATABASESMARTMEDIALIST_H__
28 #include <sbILocalDatabaseSmartMediaList.h>
29 #include <sbILocalDatabaseMediaItem.h>
32 #include <nsAutoPtr.h>
34 #include <nsCOMArray.h>
35 #include <nsDataHashtable.h>
36 #include <nsStringGlue.h>
37 #include <nsAutoLock.h>
39 #include <nsIClassInfo.h>
40 #include <nsIObserver.h>
42 #include <sbIMediaListListener.h>
43 #include <sbIPropertyArray.h>
57 typedef nsDataHashtable<nsStringHashKey, nsString>
sbStringMap;
60 #define NS_FORWARD_SAFE_SBIMEDIALIST_ALL_BUT_TYPEANDNAME(_to) \
61 NS_IMETHOD GetLength(PRUint32 *aLength) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetLength(aLength); } \
62 NS_IMETHOD GetItemByGuid(const nsAString & aGuid, sbIMediaItem **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemByGuid(aGuid, _retval); } \
63 NS_IMETHOD GetItemByIndex(PRUint32 aIndex, sbIMediaItem **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemByIndex(aIndex, _retval); } \
64 NS_IMETHOD EnumerateAllItems(sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return !_to ? NS_ERROR_NULL_POINTER : _to->EnumerateAllItems(aEnumerationListener, aEnumerationType); } \
65 NS_IMETHOD EnumerateItemsByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return !_to ? NS_ERROR_NULL_POINTER : _to->EnumerateItemsByProperty(aPropertyID, aPropertyValue, aEnumerationListener, aEnumerationType); } \
66 NS_IMETHOD EnumerateItemsByProperties(sbIPropertyArray *aProperties, sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return !_to ? NS_ERROR_NULL_POINTER : _to->EnumerateItemsByProperties(aProperties, aEnumerationListener, aEnumerationType); } \
67 NS_IMETHOD GetItemsByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, nsIArray **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemsByProperty(aPropertyID, aPropertyValue, _retval); } \
68 NS_IMETHOD GetItemCountByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, PRUint32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemCountByProperty(aPropertyID, aPropertyValue, _retval); } \
69 NS_IMETHOD GetItemsByProperties(sbIPropertyArray *aProperties, nsIArray **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetItemsByProperties(aProperties, _retval); } \
70 NS_IMETHOD IndexOf(sbIMediaItem *aMediaItem, PRUint32 aStartFrom, PRUint32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->IndexOf(aMediaItem, aStartFrom, _retval); } \
71 NS_IMETHOD LastIndexOf(sbIMediaItem *aMediaItem, PRUint32 aStartFrom, PRUint32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->LastIndexOf(aMediaItem, aStartFrom, _retval); } \
72 NS_IMETHOD Contains(sbIMediaItem *aMediaItem, PRBool *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->Contains(aMediaItem, _retval); } \
73 NS_IMETHOD GetIsEmpty(PRBool *aIsEmpty) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetIsEmpty(aIsEmpty); } \
74 NS_IMETHOD GetUserEditableContent(PRBool *aUserEditableContent) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetUserEditableContent(aUserEditableContent); } \
75 NS_IMETHOD Add(sbIMediaItem *aMediaItem) { return !_to ? NS_ERROR_NULL_POINTER : _to->Add(aMediaItem); } \
76 NS_IMETHOD AddItem(sbIMediaItem *aMediaItem, sbIMediaItem ** aNewMediaItem) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddItem(aMediaItem, aNewMediaItem); } \
77 NS_IMETHOD AddAll(sbIMediaList *aMediaList) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddAll(aMediaList); } \
78 NS_IMETHOD AddSome(nsISimpleEnumerator *aMediaItems) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddSome(aMediaItems); } \
79 NS_IMETHOD AddMediaItems(nsISimpleEnumerator *aMediaItems, sbIAddMediaItemsListener *aListener, PRBool aAsync) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddMediaItems(aMediaItems, aListener, aAsync); } \
80 NS_IMETHOD Remove(sbIMediaItem *aMediaItem) { return !_to ? NS_ERROR_NULL_POINTER : _to->Remove(aMediaItem); } \
81 NS_IMETHOD RemoveByIndex(PRUint32 aIndex) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveByIndex(aIndex); } \
82 NS_IMETHOD RemoveSome(nsISimpleEnumerator *aMediaItems) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveSome(aMediaItems); } \
83 NS_IMETHOD Clear(void) { return !_to ? NS_ERROR_NULL_POINTER : _to->Clear(); } \
84 NS_IMETHOD AddListener(sbIMediaListListener *aListener, PRBool aOwnsWeak, PRUint32 aFlags, sbIPropertyArray *aPropertyFilter) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddListener(aListener, aOwnsWeak, aFlags, aPropertyFilter); } \
85 NS_IMETHOD RemoveListener(sbIMediaListListener *aListener) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveListener(aListener); } \
86 NS_IMETHOD CreateView(sbIMediaListViewState* aState, sbIMediaListView **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->CreateView(aState, _retval); } \
87 NS_IMETHOD GetDistinctValuesForProperty(const nsAString& aPropertyID, nsIStringEnumerator** _retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetDistinctValuesForProperty(aPropertyID, _retval); } \
88 NS_IMETHOD RunInBatchMode(sbIMediaListBatchCallback *aCallback, nsISupports *aUserData) { return !_to ? NS_ERROR_NULL_POINTER : _to->RunInBatchMode(aCallback, aUserData); }
91 #define SB_FORWARD_SAFE_SBILOCALDATABASEMEDIAITEM(_to) \
92 NS_SCRIPTABLE NS_IMETHOD GetMediaItemId(PRUint32 *aMediaItemId) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetMediaItemId(aMediaItemId); } \
93 NS_SCRIPTABLE NS_IMETHOD GetPropertyBag(sbILocalDatabaseResourcePropertyBag * *aPropertyBag) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetPropertyBag(aPropertyBag); } \
94 NS_SCRIPTABLE NS_IMETHOD SetPropertyBag(sbILocalDatabaseResourcePropertyBag * aPropertyBag) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetPropertyBag(aPropertyBag); } \
95 NS_IMETHOD_(void) SetSuppressNotifications(PRBool aSuppress) { if (_to) _to->SetSuppressNotifications(aSuppress); }
102 NS_DECL_SBILOCALDATABASESMARTMEDIALISTCONDITION
105 const nsAString& aOperatorString,
106 const nsAString& aLeftValue,
107 const nsAString& aRightValue,
108 const nsAString& aDisplayUnit);
112 nsresult
ToString(nsAString& _retval);
125 nsCOMPtr<sbIPropertyOperator> mOperator;
135 typedef nsRefPtr<sbLocalDatabaseSmartMediaListCondition> sbRefPtrCondition;
136 typedef nsTArray<PRUint32> sbMediaItemIdArray;
139 NS_DECL_SBILOCALDATABASESMARTMEDIALIST
140 NS_DECL_SBIMEDIALISTLISTENER
144 NS_FORWARD_SAFE_SBIMEDIAITEM(mItem)
145 NS_FORWARD_SAFE_SBILIBRARYRESOURCE(mItem)
151 NS_IMETHOD
GetType(nsAString& aType);
153 NS_IMETHOD
SetName(const nsAString& aName);
165 nsresult RebuildMatchTypeNoneNotRandom();
167 nsresult RebuildMatchTypeNoneRandom();
169 nsresult RebuildMatchTypeAnyAll();
171 nsresult AddMediaItemsTempTable(const nsAutoString& tempTableName,
172 sbMediaItemIdArray& aArray,
176 nsresult GetRollingLimit(const nsAString& aSql,
177 PRUint32 aRollingLimitColumnIndex,
180 nsresult CreateSQLForCondition(sbRefPtrCondition& aCondition,
181 PRBool aIsLastCondition,
185 sbRefPtrCondition& aCondition,
189 const nsAString& aBaseTableAlias,
193 const nsAString& aBaseTableAlias);
195 nsresult CreateQueries();
197 nsresult GetCopyToListQuery(const nsAString& aTempTableName,
201 nsresult CreateTempTable(nsAString& aName);
203 nsresult DropTempTable(const nsAString& aName);
205 nsresult ExecuteQuery(const nsAString& aSql);
207 nsresult MakeTempTableName(nsAString& aName);
209 nsresult GetMediaItemIdRange(PRUint32* aMin, PRUint32* aMax);
211 nsresult GetRowCount(const nsAString& aTableName,
214 void ShuffleArray(sbMediaItemIdArray& aArray);
216 nsresult GetConditionNeedsNull(sbRefPtrCondition& aCondition,
218 PRBool &bNeedIsNull);
220 nsresult MediaListGuidToDB(nsAString &
val, PRUint32 &v);
222 PRInt64 ParseDateTime(nsAString &aDateTime);
224 PRInt64 StripTime(PRInt64 aDateTime);
226 void SPrintfInt64(nsAString &aString, PRInt64
aValue);
227 PRInt64 ScanfInt64d(nsAString &aString);
228 nsresult ScanfInt64(nsAString &aString, PRInt64 *aRetVal);
230 nsresult ReadConfiguration();
232 nsresult WriteConfiguration();
234 PRMonitor* mInnerMonitor;
240 PRMonitor* mConditionsMonitor;
241 nsTArray<sbRefPtrCondition> mConditions;
246 nsString mSelectPropertyID;
247 PRBool mSelectDirection;
248 PRBool mRandomSelection;
249 PRMonitor * mAutoUpdateMonitor;
250 PRUint32 mAutoUpdate;
251 PRUint32 mNotExistsMode;
257 PRMonitor * mListenersMonitor;
260 nsString mClearListQuery;
262 PRMonitor * mSourceMonitor;
263 nsString mSourceLibraryGuid;
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
Interface for building SELECT statements.
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
this _dialogInput val(dateText)
An interface used to describe a metadata property for use by the UI and other sbILibrary interfaces (...
Interface for SQL critera. This interface has no public methods as it is used only as a return type f...
An object responsible for executing SQL queries on the database.
Manager for system wide metadata properties.