sbLocalDatabaseDynamicMediaList.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2009 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27 */
28 
34 //------------------------------------------------------------------------------
35 //
36 // Songbird dynamic media list imported services.
37 //
38 //------------------------------------------------------------------------------
39 
40 // Self imports.
42 
43 // Local imports.
44 #include "sbLocalDatabaseCID.h"
45 
46 // Songbird imports.
47 #include <sbIDynamicPlaylistService.h>
48 #include <sbIMediaListFactory.h>
49 #include <sbStandardProperties.h>
50 
51 // Mozilla imports.
52 #include <nsAutoPtr.h>
53 #include <nsIClassInfoImpl.h>
54 #include <nsIProgrammingLanguage.h>
55 #include <nsMemory.h>
56 #include <nsServiceManagerUtils.h>
57 
58 
59 //------------------------------------------------------------------------------
60 //
61 // Songbird dynamic media list logging services.
62 //
63 //------------------------------------------------------------------------------
64 
65 /*
66  * To log this module, set the following environment variable:
67  * NSPR_LOG_MODULES=sbLocalDatabaseDynamicMediaList:5
68  */
69 
70 #ifdef PR_LOGGING
71 static PRLogModuleInfo* gLocalDatabaseDynamicMediaListLog = nsnull;
72 #define TRACE(args) PR_LOG(gLocalDatabaseDynamicMediaListLog, \
73  PR_LOG_DEBUG, \
74  args)
75 #define LOG(args) PR_LOG(gLocalDatabaseDynamicMediaListLog, PR_LOG_WARN, args)
76 #else
77 #define TRACE(args) /* nothing */
78 #define LOG(args) /* nothing */
79 #endif
80 
81 
82 //------------------------------------------------------------------------------
83 //
84 // Songbird dynamic media list nsISupports and nsIClassInfo implementation.
85 //
86 //------------------------------------------------------------------------------
87 
96 
101  sbIMediaItem,
102  sbIMediaList,
104 
105 // nsIClassInfo implementation.
106 NS_IMPL_THREADSAFE_CI(sbLocalDatabaseDynamicMediaList)
107 
108 
109 //------------------------------------------------------------------------------
110 //
111 // Songbird dynamic media list sbIDynamicMediaList implementation.
112 //
113 //------------------------------------------------------------------------------
114 
119 NS_IMETHODIMP
120 sbLocalDatabaseDynamicMediaList::Update()
121 {
122  // Trace execution.
123  TRACE(("sbLocalDatabaseDynamicMediaList[0x%p] - Update()", this));
124 
125  // Function variables.
126  nsresult rv;
127 
128  // Update the list.
129  nsCOMPtr<sbIDynamicPlaylistService> dynamicPlaylistService =
130  do_GetService("@songbirdnest.com/Songbird/Library/DynamicPlaylistService;1",
131  &rv);
132  NS_ENSURE_SUCCESS(rv, rv);
133  rv = dynamicPlaylistService->UpdateNow(this);
134  NS_ENSURE_SUCCESS(rv, rv);
135 
136  return NS_OK;
137 }
138 
139 
140 //------------------------------------------------------------------------------
141 //
142 // Songbird dynamic media list sbIMediaList implementation.
143 //
144 //------------------------------------------------------------------------------
145 
150 NS_IMETHODIMP
152 {
153  aType.Assign(NS_LITERAL_STRING("dynamic"));
154  return NS_OK;
155 }
156 
157 
158 //------------------------------------------------------------------------------
159 //
160 // Public Songbird dynamic media list services.
161 //
162 //------------------------------------------------------------------------------
163 
172 /* static */ nsresult
174  sbIMediaList** aMediaList)
175 {
176  // Validate arguments.
177  NS_ENSURE_ARG_POINTER(aInner);
178  NS_ENSURE_ARG_POINTER(aMediaList);
179 
180  // Function variables.
181  nsresult rv;
182 
183  // Create and initialize a dynamic media list.
184  nsRefPtr<sbLocalDatabaseDynamicMediaList>
185  dynamicMediaList = new sbLocalDatabaseDynamicMediaList();
186  NS_ENSURE_TRUE(dynamicMediaList, NS_ERROR_OUT_OF_MEMORY);
187  rv = dynamicMediaList->Initialize(aInner);
188  NS_ENSURE_SUCCESS(rv, rv);
189 
190  // Return results.
191  rv = CallQueryInterface(dynamicMediaList.get(), aMediaList);
192  NS_ENSURE_SUCCESS(rv, rv);
193 
194  return NS_OK;
195 }
196 
197 
203 {
204 }
205 
206 
207 //------------------------------------------------------------------------------
208 //
209 // Private Songbird dynamic media list services.
210 //
211 //------------------------------------------------------------------------------
212 
218 {
219  // Initialize the logging services.
220 #ifdef PR_LOGGING
221  if (!gLocalDatabaseDynamicMediaListLog) {
222  gLocalDatabaseDynamicMediaListLog =
223  PR_NewLogModule("sbLocalDatabaseDynamicMediaList");
224  }
225 #endif
226 }
227 
228 
236 nsresult
238 {
239  // Trace execution.
240  TRACE(("sbLocalDatabaseDynamicMediaList[0x%p] - Initialize(0x%p)",
241  this,
242  aInner));
243 
244  // Validate arguments.
245  NS_ENSURE_ARG_POINTER(aInner);
246 
247  // Function variables.
248  nsresult rv;
249 
250  // Create a base simple media list.
251  nsCOMPtr<sbIMediaListFactory> simpleMediaListFactory =
253  &rv);
254  NS_ENSURE_SUCCESS(rv, rv);
255  rv = simpleMediaListFactory->CreateMediaList(aInner,
256  getter_AddRefs(mBaseMediaList));
257  NS_ENSURE_SUCCESS(rv, rv);
258  mBaseLocalDatabaseMediaList = do_QueryInterface(mBaseMediaList, &rv);
259  NS_ENSURE_SUCCESS(rv, rv);
260 
261  // Set some dynamic media list properties.
262  nsAutoString customType;
263  mBaseMediaList->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_CUSTOMTYPE),
264  customType);
265  if (customType.IsEmpty()) {
266  rv = mBaseMediaList->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_CUSTOMTYPE),
267  NS_LITERAL_STRING("dynamic"));
268  NS_ENSURE_SUCCESS(rv, rv);
269  }
270  rv = mBaseMediaList->SetProperty
271  (NS_LITERAL_STRING(SB_PROPERTY_ISSUBSCRIPTION),
272  NS_LITERAL_STRING("1"));
273  NS_ENSURE_SUCCESS(rv, rv);
274 
275  return NS_OK;
276 }
277 
return NS_OK
static nsresult New(sbIMediaItem *aInner, sbIMediaList **aMediaList)
#define SB_PROPERTY_ISSUBSCRIPTION
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER6(sbDeviceLibrary, nsIClassInfo, sbIDeviceLibrary, sbILibrary, sbIMediaList, sbIMediaItem, sbILibraryResource) sbDeviceLibrary
NS_IMPL_THREADSAFE_CI(sbMediaListEnumeratorWrapper)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
NS_IMPL_THREADSAFE_ISUPPORTS7(sbLocalDatabaseDynamicMediaList, nsIClassInfo, nsISupportsWeakReference, sbILibraryResource, sbIMediaItem, sbIMediaList, sbIDynamicMediaList, sbILocalDatabaseMediaItem) NS_IMPL_CI_INTERFACE_GETTER6(sbLocalDatabaseDynamicMediaList
A brief description of the contents of this interface.
General interface to data resources.
nsCOMPtr< sbILocalDatabaseMediaItem > mBaseLocalDatabaseMediaList
Songbird Local Database Dynamic Media List Definitions.
NS_IMETHOD GetType(nsAString &aType)
The type of media list (eg "simple")
#define SB_LOCALDATABASE_SIMPLEMEDIALISTFACTORY_CONTRACTID
#define TRACE(args)
Interface that defines a single item of media in the system.
#define SB_PROPERTY_CUSTOMTYPE