sbLocalDatabaseMediaListViewSelection.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_LOCALDATABASEMEDIALISTVIEWSELECTION_H__
28 #define __SB_LOCALDATABASEMEDIALISTVIEWSELECTION_H__
29 
30 #include "sbIMediaListViewSelection.h"
31 #include "sbSelectionListUtils.h"
32 
33 #include <nsAutoPtr.h>
34 #include <nsCOMPtr.h>
35 #include <nsDataHashtable.h>
36 #include <nsIClassInfo.h>
37 #include <nsISimpleEnumerator.h>
38 #include <nsISerializable.h>
39 #include <nsITimer.h>
40 #include <nsStringGlue.h>
41 #include <nsTArray.h>
42 #include <nsTObserverArray.h>
43 #include <sbILibrary.h>
44 #include <sbILocalDatabaseGUIDArray.h>
45 
47 
49 {
50 public:
52  NS_DECL_SBIMEDIALISTVIEWSELECTION
53 
55 
56  nsresult Init(sbILibrary* aLibrary,
57  const nsAString& aListGUID,
59  PRBool aIsLibrary,
61 
62  nsresult ConfigurationChanged();
63 
65 
66 private:
67  typedef nsresult (*PR_CALLBACK sbSelectionEnumeratorCallbackFunc)
68  (PRUint32 aIndex, const nsAString& aId, const nsAString& aGuid, void* aUserData);
69 
70  nsresult GetUniqueIdForIndex(PRUint32 aIndex, nsAString& aId);
71 
72  nsresult GetUniqueIdForIndex(PRInt32 aIndex, nsAString& aId);
73 
74  nsresult GetIndexForUniqueId(const nsAString& aId,
75  PRUint32* aIndex);
76 
77  static void DelayedSelectNotification(nsITimer* aTimer, void* aClosure);
78 
79  nsresult AddToSelection(PRUint32 aIndex);
80  nsresult RemoveFromSelection(PRUint32 aIndex);
81  inline void CheckSelectAll() {
82  if (mLength > 1)
83  mSelectionIsAll = (mSelection.Count() == mLength);
84  else
85  mSelectionIsAll = PR_FALSE;
86 
87  if (mSelectionIsAll) {
88  mSelection.Clear();
89  }
90  }
91 
92 #ifdef DEBUG
93  void LogSelection();
94 #endif
95 
96  typedef nsTObserverArray<nsCOMPtr<sbIMediaListViewSelectionListener> > sbObserverArray;
97  sbObserverArray mObservers;
98 
99  sbSelectionList mSelection;
100  PRBool mSelectionIsAll;
101  PRInt32 mCurrentIndex;
102  nsString mCurrentUID;
103 
104  nsCOMPtr<sbILibrary> mLibrary;
105  nsString mListGUID;
106 
107  nsCOMPtr<nsITimer> mSelectTimer;
108 
109  // A weak reference to the view's array. We're owned by the view so this
110  // will never go away
112  PRBool mIsLibrary;
113 
114  PRUint32 mLength;
115  PRBool mSelectionNotificationsSuppressed;
116 };
117 
123 {
124 public:
126  mSelection(aSelection)
127  {
128  NS_ASSERTION(aSelection, "aSelection is null");
129 #ifdef DEBUG
130  nsresult rv =
131 #endif
132  mSelection->SetSelectionNotificationsSuppressed(PR_TRUE);
133  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set");
134  }
135 
137  {
138 #ifdef DEBUG
139  nsresult rv =
140 #endif
141  mSelection->SetSelectionNotificationsSuppressed(PR_FALSE);
142  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to unset");
143  }
144 
145 private:
146  sbIMediaListViewSelection* mSelection;
147 };
148 
150 {
152 public:
154  NS_DECL_NSISERIALIZABLE
155 
156  nsresult Init();
157  nsresult ToString(nsAString& aStr);
158 
160 
161 protected:
162  PRInt32 mCurrentIndex;
165 };
166 
168  public nsIClassInfo
169 {
170 public:
172  NS_DECL_NSISIMPLEENUMERATOR
173  NS_DECL_NSICLASSINFO
174 
176 
177  nsresult AddGuid(const nsAString& aGuid, PRUint32 aIndex);
178 
179 private:
180  struct Item {
181  PRUint32 index;
182  nsString guid;
183  };
184 
185  nsresult GetNextItem();
186 
187  PRBool mInitalized;
188  nsCOMPtr<sbILibrary> mLibrary;
189  nsTArray<Item> mItems;
190  PRUint32 mNextIndex;
191  nsCOMPtr<sbIMediaItem> mNextItem;
192  PRUint32 mNextItemIndex;
193 };
194 
196  public nsIClassInfo
197 {
198 public:
200  NS_DECL_NSISIMPLEENUMERATOR
201  NS_DECL_NSICLASSINFO
202 
204  sbILocalDatabaseGUIDArray* aArray);
205 
206 private:
207  nsresult Init();
208 
209  nsTArray<nsString> mGUIDArray;
210  nsCOMPtr<sbILibrary> mLibrary;
211  nsCOMPtr<sbILocalDatabaseGUIDArray> mArray;
212  PRUint32 mNextIndex;
213  PRBool mInitalized;
214 };
215 
221  public nsIClassInfo
222 {
223 public:
225  NS_DECL_NSISIMPLEENUMERATOR
226  NS_DECL_NSICLASSINFO
227 
229 
230 private:
231  nsCOMPtr<nsISimpleEnumerator> mIndexedEnumerator;
232 };
233 
234 #endif /* __SB_LOCALDATABASEMEDIALISTVIEWSELECTION_H__ */
nsDataHashtable< nsStringHashKey, nsString > sbSelectionList
nsresult GetState(sbLocalDatabaseMediaListViewSelectionState **aState)
NS_DECL_ISUPPORTS NS_DECL_NSISIMPLEENUMERATOR NS_DECL_NSICLASSINFO sbIndexedGUIDArrayEnumerator(sbILibrary *aLibrary, sbILocalDatabaseGUIDArray *aArray)
Manage the selection of items within a view. This interface is a subset of nsITreeViewSelection. Note that if you are part of the user interface, you probably want to be calling nsITreeView.selection instead - otherwise things can get subtly out of sync.
NS_DECL_ISUPPORTS NS_DECL_NSISERIALIZABLE nsresult Init()
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
NS_DECL_ISUPPORTS NS_DECL_NSISIMPLEENUMERATOR NS_DECL_NSICLASSINFO sbIndexedToUnindexedMediaItemEnumerator(nsISimpleEnumerator *aEnumerator)
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIALISTVIEWSELECTION sbLocalDatabaseMediaListViewSelection()
nsresult Init(sbILibrary *aLibrary, const nsAString &aListGUID, sbILocalDatabaseGUIDArray *aArray, PRBool aIsLibrary, sbLocalDatabaseMediaListViewSelectionState *aState)
Use scope to manage the notifications suppressed flag on the view selection so it does not accidental...
An unwrapper for sbGUIDArrayToIndexedMediaItemEnumerator to return unwrapped sbIMediaItems with no in...
void * aClosure
Definition: sbArray.cpp:52
nsISerializable
Media library abstraction.
Definition: sbILibrary.idl:82
nsresult AddGuid(const nsAString &aGuid, PRUint32 aIndex)
sbAutoSelectNotificationsSuppressed(sbIMediaListViewSelection *aSelection)
restoreWindow aState
NS_DECL_ISUPPORTS NS_DECL_NSISIMPLEENUMERATOR NS_DECL_NSICLASSINFO sbGUIDArrayToIndexedMediaItemEnumerator(sbILibrary *aLibrary)