sbLocalDatabaseSimpleMediaList.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #ifndef __SBLOCALDATABASESIMPLEMEDIALIST_H__
26 #define __SBLOCALDATABASESIMPLEMEDIALIST_H__
27 
29 #include <sbILocalDatabaseSimpleMediaList.h>
30 #include <sbIMediaListListener.h>
31 #include <sbIOrderableMediaList.h>
32 #include <nsIClassInfo.h>
33 
34 #include <nsStringGlue.h>
35 #include <nsCOMArray.h>
36 #include <nsHashKeys.h>
37 #include <nsInterfaceHashtable.h>
38 #include <nsTHashtable.h>
39 #include <prlock.h>
40 
41 class nsIMutableArray;
43 class sbIDatabaseQuery;
45 class sbIMediaItem;
46 class sbIMediaList;
47 class sbIMediaListView;
50 
54 {
55 public:
58 
59  NS_DECL_ISUPPORTS_INHERITED
60  NS_DECL_NSICLASSINFO
61  NS_DECL_SBILOCALDATABASESIMPLEMEDIALIST
62  NS_DECL_SBIORDERABLEMEDIALIST
63 
66 
67  nsresult Init(sbLocalDatabaseLibrary* aLibrary,
68  const nsAString& aGuid);
69 
70  // override base class
71  NS_IMETHOD GetType(nsAString& aType);
72  NS_IMETHOD GetItemByGuid(const nsAString& aGuid, sbIMediaItem** _retval);
73  NS_IMETHOD Contains(sbIMediaItem* aMediaItem, PRBool* _retval);
74  NS_IMETHOD Add(sbIMediaItem *aMediaItem);
75  NS_IMETHOD AddItem(sbIMediaItem * aMediaItem, sbIMediaItem ** aNewMediaItem);
76  NS_IMETHOD AddAll(sbIMediaList *aMediaList);
77  NS_IMETHOD AddSome(nsISimpleEnumerator *aMediaItems);
78  NS_IMETHOD AddMediaItems(nsISimpleEnumerator *aMediaItems, sbIAddMediaItemsListener *aListener, PRBool aAsync);
79  NS_IMETHOD Remove(sbIMediaItem* aMediaItem);
80  NS_IMETHOD RemoveByIndex(PRUint32 aIndex);
81  NS_IMETHOD RemoveSome(nsISimpleEnumerator* aMediaItems);
82  NS_IMETHOD Clear();
84  sbIMediaListView** _retval);
85 
86  NS_IMETHOD GetDefaultSortProperty(nsAString& aProperty);
87 
88  nsresult AddSomeAsyncInternal(nsISimpleEnumerator *aMediaItems,
89  nsISupports *aListener,
90  PRUint32 aStartingIndex,
91  nsAString& aStartingOrdinal);
92 
93 private:
94  nsresult UpdateLastModifiedTime();
95 
96  nsresult ExecuteAggregateQuery(const nsAString& aQuery, nsAString& aValue);
97 
98  nsresult UpdateOrdinalByIndex(PRUint32 aIndex, const nsAString& aOrdinal);
99 
100  nsresult MoveSomeInternal(PRUint32* aFromIndexArray,
101  PRUint32 aFromIndexArrayCount,
102  PRUint32 aToIndex,
103  const nsAString& aOrdinalRoot);
104 
105  nsresult GetNextOrdinal(nsAString& aValue);
106 
107  nsresult GetBeforeOrdinal(PRUint32 aIndex, nsAString& aValue);
108 
109  nsresult AddToLastPathSegment(nsAString& aPath, PRInt32 aToAdd);
110 
111  PRUint32 CountLevels(const nsAString& aPath);
112 
113  nsresult CreateQueries();
114 
115  nsresult NotifyCopyListener(sbIMediaItem *aSourceItem,
116  sbIMediaItem *aDestItem);
117 
118 private:
119  // Query to get the media item id for a given guid, constrained to the
120  // items within this simple media list
121  nsString mGetMediaItemIdForGuidQuery;
122 
123  // Query to insert a new item into this list
124  nsString mInsertIntoListQuery;
125 
126  // Query to update the ordinal of a media item in this list
127  nsString mUpdateListItemOrdinalQuery;
128 
129  // Query to delete an item from the list
130  nsString mDeleteFirstListItemQuery;
131 
132  // Query to delete the entire contents of the list
133  nsString mDeleteAllQuery;
134 
135  // Query to delete an item with a given ordinal
136  nsString mDeleteListItemByOrdinalQuery;
137 
138  // Get last ordinal
139  nsString mGetLastOrdinalQuery;
140 
141  // Get first ordinal
142  nsString mGetFirstOrdinalQuery;
143 
144  // Copy Listener
145  nsCOMPtr<sbILocalDatabaseMediaListCopyListener> mCopyListener;
146 
147  // Keep a list of guids that should be notified after removal
148  nsTHashtable<nsStringHashKey> mShouldNotifyAfterRemove;
149 };
150 
159 {
160 public:
162  NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
163 
165  PRUint32 aStartingIndex,
166  const nsAString& aStartingOrdinal,
167  nsISupports * aListener = nsnull)
168  : mFriendList(aList),
169  mStartingIndex(aStartingIndex),
170  mStartingOrdinal(aStartingOrdinal)
171  {
172  if (aListener) {
173  mAsyncListener = do_QueryInterface(aListener);
174  mAddListener = do_QueryInterface(aListener);
175  }
176  }
177 
178 private:
179  // Not meant to be implemented. This makes it a compiler error to
180  // attempt to create an object on the heap.
181  static void* operator new(size_t /*size*/) CPP_THROW_NEW { return 0; }
182  static void operator delete(void* /*memory*/) { }
183 
184  sbLocalDatabaseSimpleMediaList* mFriendList;
185  PRUint32 mStartingIndex;
186  nsString mStartingOrdinal;
192  nsCOMArray<sbIMediaItem> mItemList;
199  nsInterfaceHashtable<nsISupportsHashKey, sbIMediaItem> mItemsToCreateOrAdd;
200  nsCOMPtr<sbILibrary> mListLibrary;
201  nsCOMPtr<sbIAddMediaItemsListener> mAddListener;
202  nsCOMPtr<sbIMediaListAsyncListener> mAsyncListener;
203 
208  nsresult UpdateItemsInForeignLib(nsIArray * aExistingItems,
209  nsIArray * aNewItems);
210 };
211 
213 {
214 public:
216  NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
217 
219  : mFriendList(aList),
220  mItemEnumerated(PR_FALSE)
221  {
222  NS_ASSERTION(mFriendList, "Null pointer!");
223  }
224 
225 private:
226  // Not meant to be implemented. This makes it a compiler error to
227  // attempt to create an object on the heap.
228  static void* operator new(size_t /*size*/) CPP_THROW_NEW { return 0; }
229  static void operator delete(void* /*memory*/) { }
230 
231  sbLocalDatabaseSimpleMediaList* mFriendList;
232  nsCOMPtr<sbIDatabaseQuery> mDBQuery;
233  nsCOMArray<sbIMediaItem> mNotificationList;
234  nsTArray<PRUint32> mNotificationIndexes;
235  PRBool mItemEnumerated;
236 };
237 
238 #endif /* __SBLOCALDATABASESIMPLEMEDIALIST_H__ */
NS_IMETHOD GetItemByGuid(const nsAString &aGuid, sbIMediaItem **_retval)
NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSICLASSINFO NS_DECL_SBILOCALDATABASESIMPLEMEDIALIST NS_DECL_SBIORDERABLEMEDIALIST sbLocalDatabaseSimpleMediaList()
_updateCookies aPath
NS_IMETHOD CreateView(sbIMediaListViewState *aState, sbIMediaListView **_retval)
NS_IMETHOD RemoveSome(nsISimpleEnumerator *aMediaItems)
Interface used to enumerate the items in a media list.
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIALISTENUMERATIONLISTENER sbSimpleMediaListInsertingEnumerationListener(sbLocalDatabaseSimpleMediaList *aList, PRUint32 aStartingIndex, const nsAString &aStartingOrdinal, nsISupports *aListener=nsnull)
onPageChanged aValue
Definition: FeedWriter.js:1395
NS_IMETHOD AddSome(nsISimpleEnumerator *aMediaItems)
A brief description of the contents of this interface.
NS_IMETHOD Contains(sbIMediaItem *aMediaItem, PRBool *_retval)
NS_IMETHOD Add(sbIMediaItem *aMediaItem)
A distinct view on a given media list.
nsresult AddSomeAsyncInternal(nsISimpleEnumerator *aMediaItems, nsISupports *aListener, PRUint32 aStartingIndex, nsAString &aStartingOrdinal)
Saved state of a media list view.
NS_IMETHOD AddAll(sbIMediaList *aMediaList)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
Media lists that implement this interface support custom ordering.
NS_IMETHOD Remove(sbIMediaItem *aMediaItem)
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIALISTENUMERATIONLISTENER sbSimpleMediaListRemovingEnumerationListener(sbLocalDatabaseSimpleMediaList *aList)
NS_IMETHOD AddItem(sbIMediaItem *aMediaItem, sbIMediaItem **aNewMediaItem)
NS_IMETHOD GetDefaultSortProperty(nsAString &aProperty)
An object responsible for executing SQL queries on the database.
Interface that defines a single item of media in the system.
restoreWindow aState
NS_IMETHOD AddMediaItems(nsISimpleEnumerator *aMediaItems, sbIAddMediaItemsListener *aListener, PRBool aAsync)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]