sbLocalDatabaseMediaListView.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://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 */
26 
27 #ifndef __SB_LOCALDATABASEMEDIALISTVIEW_H__
28 #define __SB_LOCALDATABASEMEDIALISTVIEW_H__
29 
30 #include <nsCOMPtr.h>
31 #include <nsCOMArray.h>
32 #include <nsClassHashtable.h>
33 #include <nsHashKeys.h>
34 #include <nsIClassInfo.h>
35 #include <nsIStringEnumerator.h>
36 #include <nsStringGlue.h>
37 #include <nsTArray.h>
38 #include <nsTHashtable.h>
39 #include <prlock.h>
40 #include <sbIFilterableMediaListView.h>
41 #include <sbIMediaListListener.h>
42 #include <sbIMediaListView.h>
43 #include <sbIPropertyArray.h>
44 #include <sbIPropertyManager.h>
45 #include <sbISearchableMediaListView.h>
46 #include <sbISortableMediaListView.h>
47 #include <sbLibraryUtils.h>
48 #include <sbPropertiesCID.h>
49 #include <sbWeakReference.h>
50 
52 
53 class nsIURI;
54 class sbIDatabaseQuery;
55 class sbIDatabaseResult;
62 
64  public sbIMediaListView,
65  public sbIMediaListListener,
69  public nsIClassInfo
70 {
71 public:
73  NS_DECL_SBIMEDIALISTVIEW
74  NS_DECL_SBIMEDIALISTLISTENER
75  NS_DECL_SBIFILTERABLEMEDIALISTVIEW
76  NS_DECL_SBISEARCHABLEMEDIALISTVIEW
77  NS_DECL_SBISORTABLEMEDIALISTVIEW
78  NS_DECL_NSICLASSINFO
79 
81  sbLocalDatabaseMediaListBase* aMediaList,
82  nsAString& aDefaultSortProperty,
83  PRUint32 aMediaListId);
84 
86 
88 
89  already_AddRefed<sbLocalDatabaseMediaListBase> GetNativeMediaList();
90 
92 
93  nsresult UpdateViewArrayConfiguration(PRBool aClearTreeSelection);
94 
96  NotifyListenersInternal(&sbIMediaListViewListener::OnFilterChanged);
97  }
98 
100  NotifyListenersInternal(&sbIMediaListViewListener::OnSearchChanged);
101  }
102 
104  NotifyListenersInternal(&sbIMediaListViewListener::OnSortChanged);
105  }
106 
107  // Get the filter constraints set on the view. This excludes additional
108  // constraints from the CascadeFilterSet in this view.
109  nsresult GetViewConstraint(sbILibraryConstraint** aFilterConstraint);
110 
111 private:
112  typedef nsTArray<nsString> sbStringArray;
113  typedef nsCOMArray<sbIPropertyArray> sbPropertyArrayList;
114  typedef nsCOMArray<sbIMediaListViewListener> sbViewListenerArray;
115 
116  // This makes a typedef called ListenerFunc to any member function of
117  // sbIMediaListViewListener that has this signature:
118  // nsresult sbIMediaListViewListener::func(sbIMediaListView*)
119  typedef NS_STDCALL_FUNCPROTO(nsresult, ListenerFunc, sbIMediaListViewListener,
120  OnSortChanged, (sbIMediaListView*));
121 
122  static PLDHashOperator PR_CALLBACK
123  AddValuesToArrayCallback(nsStringHashKey::KeyType aKey,
124  sbStringArray* aEntry,
125  void* aUserData);
126 
127  static PLDHashOperator PR_CALLBACK
128  AddKeysToStringArrayCallback(nsStringHashKey::KeyType aKey,
129  sbStringArray* aEntry,
130  void* aUserData);
131 
132  static PLDHashOperator PR_CALLBACK
133  AddListenersToCOMArray(nsISupportsHashKey* aEntry,
134  void* aUserData);
135 
136  nsresult MakeStandardQuery(sbIDatabaseQuery** _retval);
137 
138  nsresult CreateQueries();
139 
140  nsresult Invalidate(PRBool aInvalidateLength = PR_FALSE);
141 
142  nsresult ClonePropertyArray(sbIPropertyArray* aSource,
143  sbIMutablePropertyArray** _retval);
144 
154  nsresult HasCommonProperty(sbIPropertyArray* aBag1,
155  sbIPropertyArray* aBag2,
156  nsStringArray * aPropertiesToIgnore,
157  PRBool* aHasCommonProperty);
158 
159  nsresult HasCommonProperty(sbIPropertyArray* aBag,
161  PRBool* aHasCommonProperty);
162 
163  nsresult ShouldCauseInvalidation(sbIPropertyArray* aProperties,
164  PRBool* aShouldCauseInvalidation);
165 
166  nsresult UpdateListener(PRBool aRemoveListener);
167 
168  void NotifyListenersInternal(ListenerFunc aListenerFunc);
169 
170  nsresult SetSortInternal(sbIPropertyArray* aSort);
171 
172 private:
173  nsRefPtr<sbLocalDatabaseLibrary> mLibrary;
174 
175  // Property Manager
176  nsCOMPtr<sbIPropertyManager> mPropMan;
177 
178  // The media list this view is of
179  nsRefPtr<sbLocalDatabaseMediaListBase> mMediaList;
180 
181  // The default sort property of the guid array
182  nsString mDefaultSortProperty;
183 
184  // Internal id of this media list, or 0 for the full library
185  PRUint32 mMediaListId;
186 
187  // Database guid and location
188  nsString mDatabaseGuid;
189  nsCOMPtr<nsIURI> mDatabaseLocation;
190 
191  // GUID array for this view instance
192  nsCOMPtr<sbILocalDatabaseAsyncGUIDArray> mArray;
193 
194  // Filter set for this view, if any
195  nsRefPtr<sbLocalDatabaseCascadeFilterSet> mCascadeFilterSet;
196 
197  // Tree view for this view, if any
198  nsRefPtr<sbLocalDatabaseTreeView> mTreeView;
199 
200  // Curent filter configuration
201  nsCOMPtr<sbILibraryConstraint> mViewFilter;
202 
203  // Current search configuration
204  nsCOMPtr<sbILibraryConstraint> mViewSearch;
205 
206  // Current sort configuration
207  nsCOMPtr<sbIMutablePropertyArray> mViewSort;
208 
209  // Query to return list of values for a given property
210  nsString mDistinctPropertyValuesQuery;
211 
212  // Whether we're in batch mode.
213  sbLibraryBatchHelper mBatchHelper;
214 
215  // The lock to protect our listener table.
216  PRLock* mListenerTableLock;
217 
218  // Our listener table, stores nsISupports entries that are either strong
219  // references to sbIMediaListViewListener instances or
220  // nsISupportsWeakReference instances (weak references to
221  // sbIMediaListViewListener instances).
222  nsTHashtable<nsISupportsHashKey> mListenerTable;
223 
224  // True when we should invalidate when batching ends
225  PRPackedBool mInvalidatePending;
226 
227  nsRefPtr<sbLocalDatabaseMediaListViewSelection> mSelection;
232  nsStringArray mIgnoreSystemProperties;
233 };
234 
236 {
237 public:
239  NS_DECL_NSISTRINGENUMERATOR
240 
242  nsIStringEnumerator* aValues);
243 
244 private:
245  nsCOMPtr<sbIPropertyInfo> mPropertyInfo;
246  nsCOMPtr<nsIStringEnumerator> mValues;
247 };
248 
249 #endif /* __SB_LOCALDATABASEMEDIALISTVIEW_H__ */
sbILocalDatabaseGUIDArray * GetGUIDArray()
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
nsTArray< nsString > sbStringArray
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
nsresult UpdateViewArrayConfiguration(PRBool aClearTreeSelection)
A distinct view on a given media list.
Interface used to listen to changes to a media list.
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
nsresult Init(sbIMediaListViewState *aState)
Control the search settings on a media list.
Saved state of a media list view.
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIALISTVIEW NS_DECL_SBIMEDIALISTLISTENER NS_DECL_SBIFILTERABLEMEDIALISTVIEW NS_DECL_SBISEARCHABLEMEDIALISTVIEW NS_DECL_SBISORTABLEMEDIALISTVIEW NS_DECL_NSICLASSINFO sbLocalDatabaseMediaListView(sbLocalDatabaseLibrary *aLibrary, sbLocalDatabaseMediaListBase *aMediaList, nsAString &aDefaultSortProperty, PRUint32 aMediaListId)
NS_DECL_ISUPPORTS NS_DECL_NSISTRINGENUMERATOR sbMakeSortableStringEnumerator(sbIPropertyInfo *aPropertyInfo, nsIStringEnumerator *aValues)
Control the filter settings on a media list.
An interface used to describe a metadata property for use by the UI and other sbILibrary interfaces (...
nsresult GetViewConstraint(sbILibraryConstraint **aFilterConstraint)
Saved state of a media list view.
An object containing the results of a database SELECT query.
already_AddRefed< sbLocalDatabaseMediaListBase > GetNativeMediaList()
An object responsible for executing SQL queries on the database.
Control the sort settings on a media list.
restoreWindow aState
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...