sbLocalDatabaseSmartMediaListFactory.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 <sbIMediaList.h>
33 #include <sbIMediaItem.h>
34 #include <sbIPropertyArray.h>
35 
36 #include <nsAutoPtr.h>
37 #include <nsCOMPtr.h>
38 #include <nsComponentManagerUtils.h>
39 #include "sbLocalDatabaseCID.h"
41 #include <sbStandardProperties.h>
42 #include <sbPropertiesCID.h>
43 
44 #define SB_SMART_MEDIALIST_FACTORY_TYPE "smart"
45 //#ifdef METRICS_ENABLED
46 #define SB_SMART_MEDIALIST_METRICS_TYPE "smart"
47 //#endif
48 
51 
52 
55 NS_IMETHODIMP
56 sbLocalDatabaseSmartMediaListFactory::GetType(nsAString& aType)
57 {
58  aType.AssignLiteral(SB_SMART_MEDIALIST_FACTORY_TYPE);
59  return NS_OK;
60 }
61 
65 NS_IMETHODIMP
66 sbLocalDatabaseSmartMediaListFactory::GetContractID(nsACString& aContractID)
67 {
68  aContractID.AssignLiteral(SB_LOCALDATABASE_SMARTMEDIALISTFACTORY_CONTRACTID);
69  return NS_OK;
70 }
71 
75 NS_IMETHODIMP
76 sbLocalDatabaseSmartMediaListFactory::CreateMediaList(sbIMediaItem* aInner,
77  sbIMediaList** _retval)
78 {
79  NS_ENSURE_ARG_POINTER(aInner);
80  NS_ENSURE_ARG_POINTER(_retval);
81 
82  nsresult rv;
83 
84  // Get the guid of the media list used to store the query result of
85  // the smart media list
86  nsAutoString dataGuid;
87  rv = aInner->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_STORAGEGUID),
88  dataGuid);
89 
90  // If the dataGuid is not set, then this must be the first time we are
91  // instantiating this list
92  if (dataGuid.IsEmpty()) {
93 
94  // Create the simple media list used to store the query result and store the
95  // guid as a property of the list
96  nsCOMPtr<sbILibrary> library;
97  rv = aInner->GetLibrary(getter_AddRefs(library));
98  NS_ENSURE_SUCCESS(rv, rv);
99 
100  nsCOMPtr<sbIMutablePropertyArray> properties =
101  do_CreateInstance(SB_MUTABLEPROPERTYARRAY_CONTRACTID, &rv);
102  NS_ENSURE_SUCCESS(rv, rv);
103 
104  rv = properties->AppendProperty(NS_LITERAL_STRING(SB_PROPERTY_HIDDEN),
105  NS_LITERAL_STRING("1"));
106  NS_ENSURE_SUCCESS(rv, rv);
107 
108  nsCOMPtr<sbIMediaList> dataList;
109  rv = library->CreateMediaList(NS_LITERAL_STRING("simple"),
110  properties,
111  getter_AddRefs(dataList));
112  NS_ENSURE_SUCCESS(rv, rv);
113 
114  nsAutoString guid;
115  rv = dataList->GetGuid(guid);
116  NS_ENSURE_SUCCESS(rv, rv);
117 
118  rv = aInner->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_STORAGEGUID),
119  guid);
120  NS_ENSURE_SUCCESS(rv, rv);
121 
122  rv = dataList->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_ISREADONLY),
123  NS_LITERAL_STRING("1"));
124  NS_ENSURE_SUCCESS(rv, rv);
125 
126  rv = dataList->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_ISCONTENTREADONLY),
127  NS_LITERAL_STRING("1"));
128  NS_ENSURE_SUCCESS(rv, rv);
129  }
130 
131  nsRefPtr<sbLocalDatabaseSmartMediaList> newSmartList(
133  NS_ENSURE_TRUE(newSmartList, NS_ERROR_OUT_OF_MEMORY);
134 
135  rv = newSmartList->Init(aInner);
136  NS_ENSURE_SUCCESS(rv, rv);
137 
138 //#ifdef METRICS_ENABLED
139  // Get customType so we don't overwrite it. Grrrr.
140  nsAutoString customType;
141  rv = newSmartList->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_CUSTOMTYPE), customType );
142  if (customType.IsEmpty()) {
143  // Set new customType for use by metrics.
144  rv = newSmartList->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_CUSTOMTYPE),
145  NS_LITERAL_STRING(SB_SMART_MEDIALIST_METRICS_TYPE));
146  }
147 //#endif
148 
149  rv = newSmartList->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_ISCONTENTREADONLY),
150  NS_LITERAL_STRING("1"));
151  NS_ENSURE_SUCCESS(rv, rv);
152 
153  NS_ADDREF(*_retval = newSmartList);
154  return NS_OK;
155 }
return NS_OK
#define SB_PROPERTY_ISCONTENTREADONLY
#define SB_LOCALDATABASE_SMARTMEDIALISTFACTORY_CONTRACTID
#define SB_PROPERTY_HIDDEN
Factory for new media list instances.
#define SB_MUTABLEPROPERTYARRAY_CONTRACTID
A brief description of the contents of this interface.
#define SB_PROPERTY_STORAGEGUID
NS_IMPL_ISUPPORTS1(sbLocalDatabaseSmartMediaListFactory, sbIMediaListFactory) NS_IMETHODIMP sbLocalDatabaseSmartMediaListFactory
#define SB_PROPERTY_ISREADONLY
#define SB_SMART_MEDIALIST_FACTORY_TYPE
#define SB_SMART_MEDIALIST_METRICS_TYPE
Interface that defines a single item of media in the system.
#define SB_PROPERTY_CUSTOMTYPE