sbPlayQueueService.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 __SB_PLAYQUEUESERVICE_H__
26 #define __SB_PLAYQUEUESERVICE_H__
27 
33 #include <nsAutoPtr.h>
34 #include <nsCOMPtr.h>
35 #include <nsTArray.h>
36 #include <nsIObserver.h>
37 #include <nsIGenericFactory.h>
38 #include <nsIWeakReference.h>
39 #include <nsTHashtable.h>
40 #include <nsHashKeys.h>
41 
42 #include <sbILibrary.h>
43 #include <sbILocalDatabaseLibraryCopyListener.h>
44 #include <sbIMediacoreEvent.h>
45 #include <sbIMediacoreEventListener.h>
46 #include <sbIMediacoreManager.h>
47 #include <sbIMediaListListener.h>
48 #include <sbIPlayQueueService.h>
49 #include <sbLibraryUtils.h>
50 
53 
54 class nsIStringBundle;
55 class sbIMediaItem;
56 class sbIMediaList;
57 class sbIDataRemote;
59 
61  public sbIMediaListListener,
64  public nsIObserver
65 {
67 
68 public:
70  NS_DECL_SBIPLAYQUEUESERVICE
71  NS_DECL_SBIMEDIALISTLISTENER
72  NS_DECL_SBIMEDIACOREEVENTLISTENER
73  NS_DECL_SBILOCALDATABASELIBRARYCOPYLISTENER
74  NS_DECL_NSIOBSERVER
75 
77  virtual ~sbPlayQueueService();
78 
79  static NS_METHOD RegisterSelf(nsIComponentManager* aCompMgr,
80  nsIFile* aPath,
81  const char* aLoaderStr,
82  const char* aType,
83  const nsModuleComponentInfo* aInfo);
84 
85  nsresult Init();
86 
87  void SetIgnoreListListener(PRBool aIgnore) {
88  mIgnoreListListener = aIgnore;
89  }
90 
91 private:
92 
93  void Finalize();
94 
98  nsCOMPtr<sbIMediaList> mMediaList;
99 
103  nsCOMPtr<sbILibrary> mLibrary;
104 
110  PRUint32 mIndex;
111 
116  PRBool mInitialized;
117 
121  PRBool mExplicitStop;
122 
127  PRUint32 mBatchRemovalIndex;
128 
133  PRBool mBatchBeginAllHistory;
134 
138  PRBool mIgnoreListListener;
139 
144  PRBool mSequencerOnQueue;
145 
149  PRBool mSequencerPlayingOrPaused;
150 
153  PRBool mOperationInProgress;
154 
158  sbLibraryBatchHelper mBatchHelper;
159 
164  nsTArray<nsString> mRemovedItemGUIDs;
165 
169  nsRefPtr<sbPlayQueueLibraryListener> mLibraryListener;
170 
174  nsCOMPtr<nsIWeakReference> mWeakMediacoreManager;
175 
179  nsresult QueueNextInternal(sbIMediaItem* aMediaItem,
180  PRUint32 aInsertBeforeIndex);
181 
186  nsresult QueueNextInternal(sbIMediaList* aMediaList,
187  PRUint32 aInsertBeforeIndex);
188 
192  nsresult QueueLastInternal(sbIMediaItem* aMediaItem);
193 
197  nsresult QueueLastInternal(sbIMediaList* aMediaList);
198 
199  nsresult RefreshIndexFromView();
200 
207  nsresult CreateMediaList();
208 
212  nsresult InitLibrary();
213 
217  nsresult InitMediaList();
218 
223  nsresult SetIndexToPlayingTrack();
224 
229  nsresult OnViewChange(sbIMediacoreEvent* aEvent);
230 
235  nsresult OnTrackChange(sbIMediacoreEvent* aEvent);
236 
241  nsresult OnTrackIndexChange(sbIMediacoreEvent* aEvent);
242 
246  nsTHashtable<nsISupportsHashKey> mListeners;
247 
251  nsresult NotifyQueueOperationStarted();
252 
256  nsresult NotifyQueueOperationCompleted();
257 
262  static PLDHashOperator PR_CALLBACK
263  OnIndexUpdatedCallback(nsISupportsHashKey* aKey,
264  void* aUserData);
265 
269  static PLDHashOperator PR_CALLBACK
270  OnQueueStartedCallback(nsISupportsHashKey* aKey,
271  void* aUserData);
272 
276  static PLDHashOperator PR_CALLBACK
277  OnQueueCompletedCallback(nsISupportsHashKey* aKey,
278  void* aUserData);
279 
283  nsRefPtr<sbPlayQueueExternalLibraryListener> mExternalListener;
284 
289  nsRefPtr<sbPlayQueueAsyncListener> mAsyncListener;
290 };
291 
294 {
295 public:
297  NS_DECL_SBIADDMEDIAITEMSLISTENER
298 
300  virtual ~sbPlayQueueAsyncListener();
301 
302  nsresult Init();
303 
304 private:
305  void Finalize();
306 
310  sbPlayQueueService* mService;
311 
315  nsCOMPtr<nsIStringBundle> mBundle;
316 
320  nsCOMPtr<sbIDataRemote> mDataRemote;
321 
325  nsString mQueueName;
326 };
327 
328 #define SB_PLAYQUEUESERVICE_CONTRACTID \
329  "@songbirdnest.com/Songbird/playqueue/service;1"
330 #define SB_PLAYQUEUESERVICE_CLASSNAME \
331  "Songbird Play Queue Service"
332 #define SB_PLAYQUEUESERVICE_CID \
333  { 0xe6407d63, 0x33d2, 0x402e, \
334  { 0xa1, 0x66, 0x3d, 0x6b, 0xc7, 0x85, 0xa4, 0x8e } }
335 
336 #endif /* __SB_PLAYQUEUESERVICE_H__ */
_updateCookies aPath
static NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
void SetIgnoreListListener(PRBool aIgnore)
Interface used to listen for items being copied from a library.
A brief description of the contents of this interface.
An interface for accessing, and binding to, stored data.
Helper class to listen to external libraries and sync properties.
Interface used to listen to changes to a media list.
Definition of the sbIMediacoreEvent interface.
NS_DECL_ISUPPORTS NS_DECL_SBIPLAYQUEUESERVICE NS_DECL_SBIMEDIALISTLISTENER NS_DECL_SBIMEDIACOREEVENTLISTENER NS_DECL_SBILOCALDATABASELIBRARYCOPYLISTENER NS_DECL_NSIOBSERVER sbPlayQueueService()
Interface for use with async methods on sbIMediaList. NOTE: this interface is now deprecated...
Service for interacting with the Play Queue.
NS_DECL_ISUPPORTS NS_DECL_SBIADDMEDIAITEMSLISTENER sbPlayQueueAsyncListener(sbPlayQueueService *aService)
Interface that defines a single item of media in the system.
Helper class to listen to play queue library notifications.