sbMediaListEnumArrayHelper.cpp
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 
26 
27 #include <nsComponentManagerUtils.h>
28 #include <sbIMediaList.h>
29 #include <sbIMediaItem.h>
30 
31 
33 
35 {
37  nsresult rv = helper->Init(aArray);
38  NS_ENSURE_SUCCESS(rv, nsnull);
39  return helper;
40 }
41 
43 {
44 }
45 
47 {
48 }
49 
50 nsresult
52 {
53  nsresult rv;
54  if (aArray) {
55  mItemsArray = do_QueryInterface(aArray, &rv);
56  NS_ENSURE_SUCCESS(rv, rv);
57  }
58  else {
59  mItemsArray =
60  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
61  NS_ENSURE_SUCCESS(rv, rv);
62  }
63  return NS_OK;
64 }
65 
66 NS_IMETHODIMP
68 {
69  NS_ENSURE_ARG_POINTER(aOutArray);
70  NS_IF_ADDREF(*aOutArray = mItemsArray);
71  return NS_OK;
72 }
73 
74 //------------------------------------------------------------------------------
75 // sbIMediaListEnumerationListener
76 
77 NS_IMETHODIMP
78 sbMediaListEnumArrayHelper::OnEnumerationBegin(sbIMediaList *aMediaList,
79  PRUint16 *_retval)
80 {
81  NS_ENSURE_ARG_POINTER(_retval);
83  return NS_OK;
84 }
85 
86 NS_IMETHODIMP
87 sbMediaListEnumArrayHelper::OnEnumeratedItem(sbIMediaList *aMediaList,
88  sbIMediaItem *aMediaItem,
89  PRUint16 *_retval)
90 {
91  NS_ENSURE_ARG_POINTER(_retval);
93 
94  nsresult rv;
95  if (!mItemsArray) {
96  rv = Init();
97  NS_ENSURE_SUCCESS(rv, rv);
98  }
99 
100  rv = mItemsArray->AppendElement(aMediaItem, PR_FALSE);
101  NS_ENSURE_SUCCESS(rv, rv);
102  return NS_OK;
103 }
104 
105 NS_IMETHODIMP
106 sbMediaListEnumArrayHelper::OnEnumerationEnd(sbIMediaList *aMediaList,
107  nsresult aStatusCode)
108 {
109  return NS_OK;
110 }
111 
nsresult Init(nsIArray *aArray=nsnull)
Resets and clears the media items array. Be sure to call this method before using this class as a enu...
return NS_OK
Interface used to enumerate the items in a media list.
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
A brief description of the contents of this interface.
NS_IMETHOD GetMediaItemsArray(nsIArray **aOutArray)
nsCOMPtr< nsIMutableArray > mItemsArray
Interface that defines a single item of media in the system.