sbLocalDatabaseMediaListViewState.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 <sbILibraryConstraints.h>
30 #include <sbIPropertyArray.h>
31 
32 #include <nsIClassInfoImpl.h>
33 #include <nsIObjectInputStream.h>
34 #include <nsIObjectOutputStream.h>
35 #include <nsIMutableArray.h>
36 #include <nsIProgrammingLanguage.h>
37 #include <nsArrayUtils.h>
38 #include <nsComponentManagerUtils.h>
39 #include <nsMemory.h>
40 
41 static NS_DEFINE_CID(kMediaListViewStateCID,
43 
49 
50 NS_IMPL_CI_INTERFACE_GETTER4(sbLocalDatabaseMediaListViewState,
55 
56 sbLocalDatabaseMediaListViewState::sbLocalDatabaseMediaListViewState() :
57  mInitialized(PR_FALSE)
58 {
59 }
60 
62  sbILibraryConstraint* aSearch,
63  sbILibraryConstraint* aFilter,
66  sbLocalDatabaseTreeViewState* aTreeViewState) :
67  mInitialized(PR_TRUE),
68  mSort(aSort),
69  mSearch(aSearch),
70  mFilter(aFilter),
71  mSelection(aSelection),
72  mFilterSet(aFilterSet),
73  mTreeViewState(aTreeViewState)
74 {
75  NS_ASSERTION(aSort, "aSort is null");
76 }
77 
78 // sbILocalDatabaseMediaListViewState
79 NS_IMETHODIMP
80 sbLocalDatabaseMediaListViewState::GetSort(sbIMutablePropertyArray** aSort)
81 {
82  NS_ENSURE_STATE(mInitialized);
83  NS_ENSURE_ARG_POINTER(aSort);
84 
85  NS_ADDREF(*aSort = mSort);
86  return NS_OK;
87 }
88 
89 NS_IMETHODIMP
91 {
92  NS_ENSURE_STATE(mInitialized);
93  NS_ENSURE_ARG_POINTER(aSearch);
94 
95  NS_IF_ADDREF(*aSearch = mSearch);
96  return NS_OK;
97 }
98 
99 NS_IMETHODIMP
101 {
102  NS_ENSURE_STATE(mInitialized);
103  NS_ENSURE_ARG_POINTER(aFilter);
104 
105  NS_IF_ADDREF(*aFilter = mFilter);
106  return NS_OK;
107 }
108 
109 NS_IMETHODIMP
111 {
112  NS_ENSURE_STATE(mInitialized);
113  NS_ENSURE_ARG_POINTER(aSelection);
114 
115  NS_IF_ADDREF(*aSelection = mSelection);
116  return NS_OK;
117 }
118 
119 NS_IMETHODIMP
121 {
122  NS_ENSURE_STATE(mInitialized);
123  NS_ENSURE_ARG_POINTER(aFilterSet);
124 
125  NS_IF_ADDREF(*aFilterSet = mFilterSet);
126  return NS_OK;
127 }
128 
129 NS_IMETHODIMP
131 {
132  NS_ENSURE_STATE(mInitialized);
133  NS_ENSURE_ARG_POINTER(aTreeViewState);
134 
135  NS_IF_ADDREF(*aTreeViewState = mTreeViewState);
136  return NS_OK;
137 }
138 
139 // sbIMediaListViewState
140 NS_IMETHODIMP
142 {
143  NS_ENSURE_STATE(mInitialized);
144 
145  nsresult rv;
146  nsString buff;
147  nsString temp;
148 
149  buff.AppendLiteral("sort: ");
150  rv = mSort->ToString(temp);
151  NS_ENSURE_SUCCESS(rv, rv);
152  buff.Append(temp);
153 
154  buff.AppendLiteral(" search: ");
155  if (mSearch) {
156  rv = mSearch->ToString(temp);
157  NS_ENSURE_SUCCESS(rv, rv);
158  buff.Append(temp);
159  }
160  else {
161  buff.AppendLiteral("null");
162  }
163 
164  buff.AppendLiteral(" filter: ");
165  if (mFilter) {
166  rv = mFilter->ToString(temp);
167  NS_ENSURE_SUCCESS(rv, rv);
168  buff.Append(temp);
169  }
170  else {
171  buff.AppendLiteral("null");
172  }
173 
174  buff.AppendLiteral(" selection: ");
175  if (mSelection) {
176  rv = mSelection->ToString(temp);
177  NS_ENSURE_SUCCESS(rv, rv);
178  buff.Append(temp);
179  }
180  else {
181  buff.AppendLiteral("null");
182  }
183 
184  buff.AppendLiteral(" filterSet: [");
185  if (mFilterSet) {
186  rv = mFilterSet->ToString(temp);
187  NS_ENSURE_SUCCESS(rv, rv);
188  buff.Append(temp);
189  }
190  buff.AppendLiteral("]");
191 
192  buff.AppendLiteral(" treeView: [");
193  if (mTreeViewState) {
194  rv = mTreeViewState->ToString(temp);
195  NS_ENSURE_SUCCESS(rv, rv);
196  buff.Append(temp);
197  }
198  buff.AppendLiteral("]");
199 
200  aString = buff;
201 
202  return NS_OK;
203 }
204 
205 // nsISerializable
206 NS_IMETHODIMP
207 sbLocalDatabaseMediaListViewState::Read(nsIObjectInputStream* aStream)
208 {
209  NS_ENSURE_ARG_POINTER(aStream);
210 
211  nsresult rv;
212 
213  nsCOMPtr<nsISupports> supports;
214 
215  rv = aStream->ReadObject(PR_TRUE, getter_AddRefs(supports));
216  NS_ENSURE_SUCCESS(rv, rv);
217  mSort = do_QueryInterface(supports, &rv);
218  NS_ENSURE_SUCCESS(rv, rv);
219 
220  PRBool hasSearch;
221  rv = aStream->ReadBoolean(&hasSearch);
222  NS_ENSURE_SUCCESS(rv, rv);
223 
224  if (hasSearch) {
225  rv = aStream->ReadObject(PR_TRUE, getter_AddRefs(supports));
226  NS_ENSURE_SUCCESS(rv, rv);
227  mSearch = do_QueryInterface(supports, &rv);
228  NS_ENSURE_SUCCESS(rv, rv);
229  }
230 
231  PRBool hasFilter;
232  rv = aStream->ReadBoolean(&hasFilter);
233  NS_ENSURE_SUCCESS(rv, rv);
234 
235  if (hasFilter) {
236  rv = aStream->ReadObject(PR_TRUE, getter_AddRefs(supports));
237  NS_ENSURE_SUCCESS(rv, rv);
238  mFilter = do_QueryInterface(supports, &rv);
239  NS_ENSURE_SUCCESS(rv, rv);
240  }
241 
243  NS_ENSURE_TRUE(mSelection, NS_ERROR_OUT_OF_MEMORY);
244 
245  rv = mSelection->Init();
246  NS_ENSURE_SUCCESS(rv, rv);
247 
248  rv = mSelection->Read(aStream);
249  NS_ENSURE_SUCCESS(rv, rv);
250 
251  PRBool hasFilterSet;
252  rv = aStream->ReadBoolean(&hasFilterSet);
253  NS_ENSURE_SUCCESS(rv, rv);
254 
255  if (hasFilterSet) {
257  NS_ENSURE_TRUE(mFilterSet, NS_ERROR_OUT_OF_MEMORY);
258 
259  rv = mFilterSet->Read(aStream);
260  NS_ENSURE_SUCCESS(rv, rv);
261  }
262 
263  PRBool hasTreeViewState;
264  rv = aStream->ReadBoolean(&hasTreeViewState);
265  NS_ENSURE_SUCCESS(rv, rv);
266 
267  if (hasTreeViewState) {
269  NS_ENSURE_TRUE(mTreeViewState, NS_ERROR_OUT_OF_MEMORY);
270 
271  rv = mTreeViewState->Init();
272  NS_ENSURE_SUCCESS(rv, rv);
273 
274  rv = mTreeViewState->Read(aStream);
275  NS_ENSURE_SUCCESS(rv, rv);
276  }
277 
278  mInitialized = PR_TRUE;
279 
280  return NS_OK;
281 }
282 
283 NS_IMETHODIMP
284 sbLocalDatabaseMediaListViewState::Write(nsIObjectOutputStream* aStream)
285 {
286  NS_ENSURE_STATE(mInitialized);
287  NS_ENSURE_ARG_POINTER(aStream);
288 
289  nsresult rv;
290 
291  rv = aStream->WriteObject(mSort, PR_TRUE);
292  NS_ENSURE_SUCCESS(rv, rv);
293 
294  if (mSearch) {
295  rv = aStream->WriteBoolean(PR_TRUE);
296  NS_ENSURE_SUCCESS(rv, rv);
297  rv = aStream->WriteObject(mSearch, PR_TRUE);
298  NS_ENSURE_SUCCESS(rv, rv);
299  }
300  else {
301  rv = aStream->WriteBoolean(PR_FALSE);
302  NS_ENSURE_SUCCESS(rv, rv);
303  }
304 
305  if (mFilter) {
306  rv = aStream->WriteBoolean(PR_TRUE);
307  NS_ENSURE_SUCCESS(rv, rv);
308  rv = aStream->WriteObject(mFilter, PR_TRUE);
309  NS_ENSURE_SUCCESS(rv, rv);
310  }
311  else {
312  rv = aStream->WriteBoolean(PR_FALSE);
313  NS_ENSURE_SUCCESS(rv, rv);
314  }
315 
316  rv = mSelection->Write(aStream);
317  NS_ENSURE_SUCCESS(rv, rv);
318 
319  if (mFilterSet) {
320  rv = aStream->WriteBoolean(PR_TRUE);
321  NS_ENSURE_SUCCESS(rv, rv);
322  rv = mFilterSet->Write(aStream);
323  NS_ENSURE_SUCCESS(rv, rv);
324  }
325  else {
326  rv = aStream->WriteBoolean(PR_FALSE);
327  NS_ENSURE_SUCCESS(rv, rv);
328  }
329 
330  if (mTreeViewState) {
331  rv = aStream->WriteBoolean(PR_TRUE);
332  NS_ENSURE_SUCCESS(rv, rv);
333  rv = mTreeViewState->Write(aStream);
334  NS_ENSURE_SUCCESS(rv, rv);
335  }
336  else {
337  rv = aStream->WriteBoolean(PR_FALSE);
338  NS_ENSURE_SUCCESS(rv, rv);
339  }
340 
341  return NS_OK;
342 }
343 
344 // nsIClassInfo
345 NS_IMETHODIMP
346 sbLocalDatabaseMediaListViewState::GetInterfaces(PRUint32* count, nsIID*** array)
347 {
348  return NS_CI_INTERFACE_GETTER_NAME(sbLocalDatabaseMediaListViewState)(count, array);
349 }
350 
351 NS_IMETHODIMP
352 sbLocalDatabaseMediaListViewState::GetHelperForLanguage(PRUint32 language,
353  nsISupports** _retval)
354 {
355  *_retval = nsnull;
356  return NS_OK;
357 }
358 
359 NS_IMETHODIMP
360 sbLocalDatabaseMediaListViewState::GetContractID(char** aContractID)
361 {
362  *aContractID = nsnull;
363  return NS_OK;
364 }
365 
366 NS_IMETHODIMP
367 sbLocalDatabaseMediaListViewState::GetClassDescription(char** aClassDescription)
368 {
369  *aClassDescription = nsnull;
370  return NS_OK;
371 }
372 
373 NS_IMETHODIMP
374 sbLocalDatabaseMediaListViewState::GetClassID(nsCID** aClassID)
375 {
376  *aClassID = nsnull;
377  return NS_OK;
378 }
379 
380 NS_IMETHODIMP
381 sbLocalDatabaseMediaListViewState::GetImplementationLanguage(PRUint32* aImplementationLanguage)
382 {
383  *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
384  return NS_OK;
385 }
386 
387 NS_IMETHODIMP
388 sbLocalDatabaseMediaListViewState::GetFlags(PRUint32 *aFlags)
389 {
390  *aFlags = 0;
391  return NS_OK;
392 }
393 
394 NS_IMETHODIMP
395 sbLocalDatabaseMediaListViewState::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc)
396 {
397  NS_ENSURE_ARG_POINTER(aClassIDNoAlloc);
398  *aClassIDNoAlloc = kMediaListViewStateCID;
399  return NS_OK;
400 }
401 
nsRefPtr< sbLocalDatabaseMediaListViewSelectionState > mSelection
NS_IMETHOD GetFilterSet(sbLocalDatabaseCascadeFilterSetState **aFilterSet)
return NS_OK
inArray array
nsCOMPtr< sbILibraryConstraint > mFilter
nsCOMPtr< sbIMutablePropertyArray > mSort
nsRefPtr< sbLocalDatabaseCascadeFilterSetState > mFilterSet
var language
Definition: Info.js:44
static nsresult ToString(const nsDiscriminatedUnion &data, nsACString &outString)
Definition: sbVariant.cpp:861
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
Saved state of a media list view.
var count
Definition: test_bug7406.js:32
NS_IMPL_ISUPPORTS4(sbLocalDatabaseMediaListViewState, sbILocalDatabaseMediaListViewState, sbIMediaListViewState, nsISerializable, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER4(sbLocalDatabaseMediaListViewState
nsRefPtr< sbLocalDatabaseTreeViewState > mTreeViewState
NS_IMETHOD GetFilter(sbILibraryConstraint **aFilter)
#define SB_LOCALDATABASE_MEDIALISTVIEWSTATE_CID
NS_IMETHOD GetSelection(sbLocalDatabaseMediaListViewSelectionState **aState)
NS_DEFINE_STATIC_IID_ACCESSOR(sbILocalDatabaseMediaListViewState,{0xd04ebdd9, 0x9c9c, 0x4acc,{0xb5, 0x4c, 0x7d, 0x30, 0x3b, 0x76, 0xee, 0xac}}) class sbLocalDatabaseMediaListViewState NS_IMETHOD GetSearch(sbILibraryConstraint **aSearch)
nsCOMPtr< sbILibraryConstraint > mSearch
NS_IMETHOD GetTreeViewState(sbLocalDatabaseTreeViewState **aTreeViewState)
static NS_DEFINE_CID(kMediaListViewStateCID,{0x9a1a9305, 0xca11, 0x4067,{0xaa, 0x24, 0xba, 0xeb, 0x64, 0x23, 0x1d, 0xfa}})