PlaylistCommandsManager.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 
30 #ifndef __PLAYLISTCOMMANDS_MANAGER_H__
31 #define __PLAYLISTCOMMANDS_MANAGER_H__
32 
33 #include <nsISupportsImpl.h>
34 #include <nsISupportsUtils.h>
35 #include <nsIStringBundle.h>
36 #include <nsStringGlue.h>
37 #include <sbILibrary.h>
38 #include "sbIMediaListListener.h"
39 #include "sbIPlaylistCommands.h"
40 #include "sbIPlaylistCommandsBuilder.h"
41 #include <nsCOMPtr.h>
42 #include <nsCOMArray.h>
43 #include <map>
44 
45 #ifndef NS_DECL_ISUPPORTS
46 #error
47 #endif
48 // DEFINES ====================================================================
49 #define SONGBIRD_PlaylistCommandsManager_CONTRACTID \
50  "@songbirdnest.com/Songbird/PlaylistCommandsManager;1"
51 #define SONGBIRD_PlaylistCommandsManager_CLASSNAME \
52  "Songbird Playlist Commands Manager Component"
53 #define SONGBIRD_PlaylistCommandsManager_CID \
54 { /* f89d8c28-406d-4d4b-9130-ecabe66a71e2 */ \
55  0xf89d8c28, 0x406d, 0x4d4b, \
56  { 0x91, 0x30, 0xec, 0xab, 0xe6, 0x6a, 0x71, 0xe2 } \
57 }
58 // CLASSES ====================================================================
59 
60 // Forward declare
62 
64 {
66 public:
68  NS_DECL_SBIPLAYLISTCOMMANDSMANAGER
69 
71  virtual ~CPlaylistCommandsManager();
72 
73 protected:
74  /* the key string will be a medialist's guid or medialist listType
75  * (e.g. "simple") depending on which the caller of register wants to
76  * register the sbIPlaylistCommandsBuilder for */
77  typedef std::map<nsString, nsCOMPtr<sbIPlaylistCommandsBuilder> > commandobjmap_t;
80  std::map<nsString, nsCOMPtr<sbIPlaylistCommands> > m_publishedCommands;
81 
82  typedef std::map<nsString, nsCOMArray<sbIPlaylistCommands> >
86 
87  typedef std::map<nsString, nsCOMPtr<LibraryPlaylistCommandsListener> >
90  /* Register a playlist command for a medialist guid and/or a medialist listType
91  * (e.g. "simple" or "smart"). An sbIPlaylistCommands object must be initialized
92  * with a unique id before it can be registered. This function will error if
93  * init() is not called on the param aCommandObj before attempting to register
94  * it.
95  * If null or an empty string is passed as the param guid or type, that param
96  * will be ignored. If both type and guid are null, this command does
97  * nothing. If both a type and guid are specified, the command object will
98  * be registered for both.
99  *
100  *@param map The commandobjmap_t to register the command object to. The options
101  * are m_PlaylistCommandObjMap for toolbar and media item context menus
102  * and m_ServicePaneCommandObjMap for context menus for service pane
103  * nodes
104  *@param aContextGUID The guid of a medialist for which the param command object
105  * should be registered to.
106  *@param aPlaylistType A medialist listType (e.g. "simple") for which the param
107  * command object should be registered. Thus appearing
108  * for all medialists of that type.
109  *@param aCommandObj The command object to be registered
110  */
111  NS_IMETHODIMP RegisterPlaylistCommands(commandobjmap_t *map,
112  const nsAString &aContextGUID,
113  const nsAString &aPlaylistType,
114  sbIPlaylistCommands *aCommandObj);
115 
116  /* Unregister a playlist command for a medialist guid and/or a medialist listType
117  * (e.g. "simple" or "smart"). If null or an empty string is passed as the
118  * param guid or type, that param will be ignored. If both type and guid
119  * are null, this command does nothing. If both a type and guid are specified,
120  * the command object will be unregistered from both.
121  *
122  *@param map The commandobjmap_t to unregister the command object from. The options
123  * are m_PlaylistCommandObjMap for toolbar and media item context menus
124  * and m_ServicePaneCommandObjMap for context menus for service pane
125  * nodes
126  *@param aContextGUID The guid of a medialist for which the param command object
127  * should be unregistered from.
128  *@param aPlaylistType A medialist listType (e.g. "simple") for which the param
129  * command object should be unregistered.
130  *@param aCommandObj The command object to be unregistered
131  */
132  NS_IMETHODIMP UnregisterPlaylistCommands(commandobjmap_t *map,
133  const nsAString &aContextGUID,
134  const nsAString &aPlaylistType,
135  sbIPlaylistCommands *aCommandObj);
136 
137 private:
138  typedef std::map<nsString, nsCOMArray<sbIPlaylistCommandsListener> > listenermap_t;
139  listenermap_t m_ListenerMap;
140 
141  /* Find a root playlist command in the param map registered for the param
142  * aSearchString. If no root playlist command is already registered, one
143  * is created and registered for aSearchString. The root command, found or
144  * newly created, is then returned.
145  *
146  *@param map The commandobjmap_t to look for the root command registered for
147  * aSearchString within. If a command is not found, a new command
148  * is created and added to this map as the value and aSearchString
149  * as key.
150  *@param aSearchString The string, probably a medialist type or guid, for
151  * which the root sbIPlaylistCommands object is desired.
152  *@return The root sbIPlaylistCommands object registered in the param map
153  * to the key aSearchString. If one was not present before this
154  * function was called, this function creates a new root comand, adds
155  * it to the map for the key aSearchString and returns the added command
156  * object
157  */
158  nsresult FindOrCreateRootCommand(commandobjmap_t *map,
159  const nsAString &aSearchString,
160  sbIPlaylistCommandsBuilder **_retval);
161 
162  /* Get the root sbIPlaylistCommands object for a medialist guid or type
163  * (e.g. "simple" or "smart"). If null or an empty string is passed as the
164  * param guid or type, that param will be ignored. If both type and guid
165  * are null, this command does nothing and will return null. If both a type
166  * and guid are specified, the guid object is returned first, if present,
167  * then the type is searched for
168  *
169  *@param map The commandobjmap_t to retrieve the command object from. The options
170  * are m_PlaylistCommandObjMap for toolbar and media item context menus
171  * and m_ServicePaneCommandObjMap for context menus for service pane
172  * nodes
173  *@param aContextGUID The guid of a medialist for which the root command object
174  * should be retrieved.
175  *@param aPlaylistType A medialist listType (e.g. "simple") for which the root
176  * command object should be retrieved.
177  *@return The root command object found for the guid or type specified.
178  * Returns nsnull if not found.
179  */
180  NS_IMETHODIMP GetPlaylistCommands(commandobjmap_t *map,
181  const nsAString &aContextGUID,
182  const nsAString &aPlaylistType,
183  sbIPlaylistCommands **_retval);
184 
185  /* Finds all root playlist commands that correspond to the param aContextGUID
186  * and/or aContextType, representing a medialist guid or listType respectively.
187  * There are two root sbIPlaylistCommands object for each medialist guid and
188  * type. One is the container for all servicepane menu commands, in the
189  * m_ServicePaneCommandObjMap, while the other is for mediaitem context menu
190  * and toolbar commands, stored in m_PlaylistCommandObjMap.
191  *
192  * If null or an empty string is provided as one of the params, guid or type,
193  * that param is ignored and only those root commands for the provided param
194  * are returned.
195  *
196  *@param aContextGUID The guid of a medialist for which the root command objects
197  * should be retrieved.
198  *@param aPlaylistType A medialist listType (e.g. "simple") for which the root
199  * command objects should be retrieved.
200  *@return An enumerator containing all root sbIPlaylistCommands objects that
201  * correspond to the provided aContextGuid and/or aContextType
202  */
203  nsresult FindAllRootCommands(const nsAString &aContextGUID,
204  const nsAString &aContextType,
205  nsISimpleEnumerator **_retval);
206 
207  /* Retrieves all medialists in aLibrary including the medialist represented
208  * by aLibrary itself.
209  *
210  *@param aLibrary The library for which all medialists should be retrieved
211  *@return All medialists in aLibrary including itself as a sbIMediaList
212  */
213  nsresult GetAllMediaListsForLibrary(sbILibrary *aLibrary,
214  nsIArray **_retval);
215 
216  /* Finds all root sbIPlaylistCommands objects for the param medialist guid
217  * and/or type and removes the param listener from those root commands.
218  *
219  * If null or an empty string is provided as one of guid or type, that param
220  * is ignored and the listener will only be removed from those root commands
221  * found for the provided param
222  *
223  *@param aContextGUID The guid of a medialist for which the root command objects
224  * should have the param aListener removed.
225  *@param aPlaylistType A medialist listType (e.g. "simple") for which the root
226  * command objects should have the param aListener removed.
227  *@param aListener The listener to be removed
228  */
229  nsresult RemoveListenerFromRootCommands(const nsString &aContextGUID,
230  const nsString &aPlaylistType,
231  sbIPlaylistCommandsListener *aListener);
232 
233  /* Removes the param aListener that is mapped to the key aSearchString in
234  * the map of saved listeners
235  *
236  *@param aSearchString The key in m_ListenerMap for which aListener should
237  * be removed as a saved listener.
238  *@param aListener The listener to be removed
239  */
240  nsresult RemoveListenerInListenerMap(const nsString &aSearchString,
241  sbIPlaylistCommandsListener *aListener);
242 
243 };
244 
246 {
247 public:
249  NS_DECL_SBIMEDIALISTLISTENER
250 
253 
254 private:
255  typedef CPlaylistCommandsManager::commandobjmap_t commandobjmap_t;
256  typedef CPlaylistCommandsManager::libraryGuidToCommandsMap_t libraryGuidToCommandsMap_t;
257 
258  CPlaylistCommandsManager* m_CmdMgr;
259 
260  nsresult HandleSavedLibraryCommands
261  (PRBool aIsRegistering,
262  libraryGuidToCommandsMap_t *aSavedCommandsMap,
263  commandobjmap_t *aRegistrationMap,
264  const nsAString &aLibraryGUID,
265  const nsAString &aListGUID);
266 
267  nsresult RegisterSavedLibraryCommands
268  (libraryGuidToCommandsMap_t *aSavedCommandsMap,
269  commandobjmap_t *aRegistrationMap,
270  const nsAString &aLibraryGUID,
271  const nsAString &aListGUID);
272 
273  nsresult UnregisterSavedLibraryCommands
274  (libraryGuidToCommandsMap_t *aSavedCommandsMap,
275  commandobjmap_t *aRegistrationMap,
276  const nsAString &aLibraryGUID,
277  const nsAString &aListGUID);
278 };
279 
280 
281 #endif // __PLAYLISTCOMMANDS_MANAGER_H__
282 
283 
A helper used to construct sbIPlaylistCommands interfaces.
NS_IMETHODIMP RegisterPlaylistCommands(commandobjmap_t *map, const nsAString &aContextGUID, const nsAString &aPlaylistType, sbIPlaylistCommands *aCommandObj)
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIALISTLISTENER LibraryPlaylistCommandsListener(CPlaylistCommandsManager *aCmdMgr)
libraryGuidToCommandsMap_t m_LibraryGuidToServicePaneCommandsMap
The interface for receiving notices when a Command Object is added to or removed from another Command...
NS_DECL_ISUPPORTS NS_DECL_SBIPLAYLISTCOMMANDSMANAGER CPlaylistCommandsManager()
std::map< nsString, nsCOMPtr< sbIPlaylistCommandsBuilder > > commandobjmap_t
Interface used to listen to changes to a media list.
commandobjmap_t m_ServicePaneCommandObjMap
libraryGuidToCommandsMap_t m_LibraryGuidToMenuOrToolbarCommandsMap
NS_IMETHODIMP UnregisterPlaylistCommands(commandobjmap_t *map, const nsAString &aContextGUID, const nsAString &aPlaylistType, sbIPlaylistCommands *aCommandObj)
Media library abstraction.
Definition: sbILibrary.idl:82
An interface that represents the set of command buttons and context menu items available on a display...
libraryGuidToLibraryListenerMap_t m_LibraryGuidToLibraryListenerMap
std::map< nsString, nsCOMPtr< LibraryPlaylistCommandsListener > > libraryGuidToLibraryListenerMap_t
std::map< nsString, nsCOMPtr< sbIPlaylistCommands > > m_publishedCommands
std::map< nsString, nsCOMArray< sbIPlaylistCommands > > libraryGuidToCommandsMap_t
The service used to register, unregister, and list playlist commands for a particular playlist guid o...