sbLocalDatabaseSimpleMediaListFactory.cpp
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 
28 
29 #include <sbIDatabaseQuery.h>
30 #include <sbILibrary.h>
31 #include <sbILocalDatabaseLibrary.h>
32 #include <sbIMediaItem.h>
33 
34 #include <nsAutoPtr.h>
35 #include <nsCOMPtr.h>
36 #include "sbLocalDatabaseCID.h"
38 
39 #include <sbStandardProperties.h>
40 
41 #define SB_SIMPLE_MEDIALIST_FACTORY_TYPE "simple"
42 //#ifdef METRICS_ENABLED
43 #define SB_SIMPLE_MEDIALIST_METRICS_TYPE "simple"
44 //#endif
45 
47 
48 
51 NS_IMETHODIMP
52 sbLocalDatabaseSimpleMediaListFactory::GetType(nsAString& aType)
53 {
54  aType.AssignLiteral(SB_SIMPLE_MEDIALIST_FACTORY_TYPE);
55  return NS_OK;
56 }
57 
61 NS_IMETHODIMP
62 sbLocalDatabaseSimpleMediaListFactory::GetContractID(nsACString& aContractID)
63 {
64  aContractID.AssignLiteral(SB_LOCALDATABASE_SIMPLEMEDIALISTFACTORY_CONTRACTID);
65  return NS_OK;
66 }
67 
71 NS_IMETHODIMP
72 sbLocalDatabaseSimpleMediaListFactory::CreateMediaList(sbIMediaItem* aInner,
73  sbIMediaList** _retval)
74 {
75  NS_ENSURE_ARG_POINTER(aInner);
76  NS_ENSURE_ARG_POINTER(_retval);
77 
78  nsCOMPtr<sbILibrary> library;
79  nsresult rv = aInner->GetLibrary(getter_AddRefs(library));
80  NS_ENSURE_SUCCESS(rv, rv);
81 
82  nsCOMPtr<sbILocalDatabaseLibrary> localLibrary =
83  do_QueryInterface(library, &rv);
84  NS_ENSURE_SUCCESS(rv, rv);
85 
86  sbLocalDatabaseLibrary* localLibraryPtr;
87  rv = localLibrary->GetNativeLibrary(&localLibraryPtr);
88  NS_ENSURE_SUCCESS(rv, rv);
89 
90  nsAutoString guid;
91  rv = aInner->GetGuid(guid);
92  NS_ENSURE_SUCCESS(rv, rv);
93 
94  nsRefPtr<sbLocalDatabaseSimpleMediaList>
95  newMediaList(new sbLocalDatabaseSimpleMediaList());
96  NS_ENSURE_TRUE(newMediaList, NS_ERROR_OUT_OF_MEMORY);
97 
98  rv = newMediaList->Init(localLibraryPtr, guid);
99  NS_ENSURE_SUCCESS(rv, rv);
100 
101 //#ifdef METRICS_ENABLED
102  // Get customType so we don't overwrite it. Grrrr.
103  nsAutoString customType;
104  rv = newMediaList->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_CUSTOMTYPE), customType );
105  if (customType.IsEmpty()) {
106  // Set new customType for use by metrics.
107  rv = newMediaList->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_CUSTOMTYPE),
108  NS_LITERAL_STRING(SB_SIMPLE_MEDIALIST_METRICS_TYPE));
109  }
110 //#endif
111 
112  // don't override sortable property
113  nsAutoString isSortable;
114  rv = newMediaList->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_ISSORTABLE), isSortable);
115  if (isSortable.IsEmpty()) {
116  // Set default sortable property
117  rv = newMediaList->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_ISSORTABLE),
118  NS_LITERAL_STRING("1"));
119  }
120 
121  NS_ADDREF(*_retval = newMediaList);
122  return NS_OK;
123 }
return NS_OK
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
Factory for new media list instances.
A brief description of the contents of this interface.
#define SB_PROPERTY_ISSORTABLE
#define SB_SIMPLE_MEDIALIST_METRICS_TYPE
#define SB_LOCALDATABASE_SIMPLEMEDIALISTFACTORY_CONTRACTID
already_AddRefed< sbLocalDatabaseLibrary > GetNativeLibrary()
Interface that defines a single item of media in the system.
#define SB_PROPERTY_CUSTOMTYPE
#define SB_SIMPLE_MEDIALIST_FACTORY_TYPE