sbLocalDatabaseCascadeFilterSet.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 __SBLOCALDATABASECASCADEFILTERSET_H__
28 #define __SBLOCALDATABASECASCADEFILTERSET_H__
29 
31 
32 #include <nsAutoPtr.h>
33 #include <nsCOMPtr.h>
34 #include <nsCOMArray.h>
35 #include <nsHashKeys.h>
36 #include <nsISerializable.h>
37 #include <nsIStringEnumerator.h>
38 #include <nsStringGlue.h>
39 #include <nsTArray.h>
40 #include <nsTHashtable.h>
41 
42 #include <sbICascadeFilterSet.h>
43 #include <sbILocalDatabaseAsyncGUIDArray.h>
44 #include <sbIMediaListListener.h>
45 #include <sbLibraryUtils.h>
46 #include <sbWeakReference.h>
47 
48 class nsIArray;
49 class nsIMutableArray;
50 class nsIObjectInputStream;
51 class nsIObjectOutputStream;
60 class sbIMediaListView;
63 
65 
67  public sbICascadeFilterSet,
69 {
70  typedef nsTArray<nsString> sbStringArray;
71 
72 public:
74  NS_DECL_SBICASCADEFILTERSET
75  NS_DECL_SBIMEDIALISTLISTENER
76 
79 
80  nsresult Init(sbLocalDatabaseLibrary* aLibrary,
81  sbILocalDatabaseAsyncGUIDArray* aProtoArray,
83 
85 
86  nsresult AddFilters(sbILibraryConstraintBuilder* aBuilder,
87  PRBool* aChanged);
88 
89  nsresult AddSearches(sbILibraryConstraintBuilder* aBuilder,
90  PRBool* aChanged);
91 
92  nsresult ClearFilters();
93 
94  nsresult ClearSearches();
95 
96  void ClearMediaListView();
97 
98  nsresult OnGetLength(PRUint32 aIndex, PRUint32 aLength);
99 
101 
102 private:
103  struct sbFilterSpec {
104  sbFilterSpec() :
105  isSearch(PR_FALSE),
106  cachedValueCount(0),
107  invalidationPending(PR_FALSE)
108  {
109  }
110 
111  PRBool isSearch;
112  nsString property;
113  sbStringArray propertyList;
114  sbStringArray values;
115  nsCOMPtr<sbILocalDatabaseAsyncGUIDArray> array;
116  nsRefPtr<sbLocalDatabaseTreeView> treeView;
117  nsRefPtr<sbLocalDatabaseCascadeFilterSetArrayListener> arrayListener;
118  PRUint32 cachedValueCount;
119  PRBool invalidationPending;
120  };
121 
122  nsresult ConfigureArray(PRUint32 aIndex);
123 
124  nsresult ConfigureFilterArray(sbFilterSpec* aSpec,
125  const nsAString& aSortProperty);
126 
127  nsresult InvalidateFilter(sbFilterSpec& aFilter);
128 
129  nsresult UpdateListener(PRBool aRemoveListener = PR_TRUE);
130 
131  nsresult ApplyConstraintFilters(sbILocalDatabaseGUIDArray* aArray);
132 
133  // This callback is meant to be used with mListeners.
134  // aUserData should be a sbICascadeFilterSetListener pointer.
135  static PLDHashOperator PR_CALLBACK
136  OnValuesChangedCallback(nsISupportsHashKey* aKey,
137  void* aUserData);
138 
139  // The library this filter set is associated with
140  nsRefPtr<sbLocalDatabaseLibrary> mLibrary;
141 
142  // The media list view this filter set is associated with. This pointer
143  // will be set to null when the associated view gets deleted
144  sbLocalDatabaseMediaListView* mMediaListView;
145 
146  // The media list we listen to for changes
147  nsCOMPtr<sbIMediaList> mMediaList;
148 
149  // Prototypical array that is cloned to provide each filter's data
150  nsCOMPtr<sbILocalDatabaseAsyncGUIDArray> mProtoArray;
151 
152  // Current filter configuration
153  nsTArray<sbFilterSpec> mFilters;
154 
155  // Change listeners
156  nsTHashtable<nsISupportsHashKey> mListeners;
157 
158  // Is our media list in a batch
159  sbLibraryBatchHelper mBatchHelper;
160 };
161 
165 {
167 
168 public:
170  NS_DECL_SBILOCALDATABASEASYNCGUIDARRAYLISTENER
171 
172  nsresult Init(sbLocalDatabaseCascadeFilterSet *aCascadeFilterSet);
173 
174 private:
175  nsCOMPtr<nsIWeakReference> mWeakCascadeFilterSet;
176  sbLocalDatabaseCascadeFilterSet* mCascadeFilterSet;
177  PRUint32 mIndex;
178 };
179 
181 {
182 public:
184  NS_DECL_NSISTRINGENUMERATOR
185 
187 
188 private:
189  nsCOMPtr<sbILocalDatabaseAsyncGUIDArray> mArray;
190  PRUint32 mNextIndex;
191 };
192 
194 {
196  typedef nsTArray<nsString> sbStringArray;
197 public:
199  NS_DECL_NSISERIALIZABLE
200 
201  nsresult ToString(nsAString& aStr);
202 
203  struct Spec {
204  PRBool isSearch;
205  nsString property;
206  sbStringArray propertyList;
207  sbStringArray values;
208  nsRefPtr<sbLocalDatabaseTreeViewState> treeViewState;
209  };
210 
211 protected:
212  nsTArray<Spec> mFilters;
213 };
214 
215 #endif /* __SBLOCALDATABASECASCADEFILTERSET_H__ */
216 
nsresult AddConfiguration(sbILocalDatabaseGUIDArray *aArray)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
nsRefPtr< sbLocalDatabaseTreeViewState > treeViewState
nsresult AddFilters(sbILibraryConstraintBuilder *aBuilder, PRBool *aChanged)
NS_DECL_ISUPPORTS NS_DECL_SBICASCADEFILTERSET NS_DECL_SBIMEDIALISTLISTENER sbLocalDatabaseCascadeFilterSet(sbLocalDatabaseMediaListView *aMediaListView)
inArray array
NS_DECL_ISUPPORTS NS_DECL_SBILOCALDATABASEASYNCGUIDARRAYLISTENER nsresult Init(sbLocalDatabaseCascadeFilterSet *aCascadeFilterSet)
Cascade filter management for a media list.
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
nsresult GetState(sbLocalDatabaseCascadeFilterSetState **aState)
boolean isSearch(in unsigned short aIndex)
Determine if the filter at a given index is a search filter.
nsresult Init(sbLocalDatabaseLibrary *aLibrary, sbILocalDatabaseAsyncGUIDArray *aProtoArray, sbLocalDatabaseCascadeFilterSetState *aState)
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...
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
nsresult AddSearches(sbILibraryConstraintBuilder *aBuilder, PRBool *aChanged)
nsISerializable
NS_DECL_ISUPPORTS NS_DECL_NSISTRINGENUMERATOR sbGUIDArrayPrimarySortEnumerator(sbILocalDatabaseAsyncGUIDArray *aArray)
NS_DECL_ISUPPORTS NS_DECL_NSISERIALIZABLE nsresult ToString(nsAString &aStr)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
restoreWindow aState
nsresult OnGetLength(PRUint32 aIndex, PRUint32 aLength)
var treeView