sbLocalMediaListBaseEnumerationListener.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 <sbIMediaItem.h>
30 #include <sbIMediaList.h>
31 
32 #include <nsComponentManagerUtils.h>
33 
36 
38 : mHasItems(PR_FALSE)
39 {
40 }
41 
42 sbLocalMediaListBaseEnumerationListener ::~sbLocalMediaListBaseEnumerationListener ()
43 {
44 }
45 
46 nsresult
48 {
49  nsresult rv = NS_ERROR_UNEXPECTED;
50  nsCOMPtr<nsIMutableArray> array =
51  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
52  NS_ENSURE_SUCCESS(rv, rv);
53 
54  array.swap(mArray);
55 
56  return NS_OK;
57 }
58 
59 nsresult
61 {
62  NS_ENSURE_ARG_POINTER(aArray);
63  NS_IF_ADDREF(*aArray = mArray);
64  return mHasItems ? NS_OK : NS_ERROR_NOT_AVAILABLE;
65 }
66 
67 nsresult
69 {
70  NS_ENSURE_ARG_POINTER(aLength);
71  nsresult rv = mArray->GetLength(aLength);
72  NS_ENSURE_SUCCESS(rv, rv);
73  return NS_OK;
74 }
75 
76 nsresult
78 {
79  mHasItems = aHasItems;
80  return NS_OK;
81 }
82 
83 NS_IMETHODIMP
84 sbLocalMediaListBaseEnumerationListener::OnEnumerationBegin(sbIMediaList *aMediaList,
85  PRUint16 *_retval)
86 {
87  NS_ENSURE_ARG_POINTER(_retval);
89  return NS_OK;
90 }
91 
92 NS_IMETHODIMP
93 sbLocalMediaListBaseEnumerationListener::OnEnumeratedItem(sbIMediaList *aMediaList,
94  sbIMediaItem *aMediaItem,
95  PRUint16 *_retval)
96 {
97  NS_ENSURE_STATE(mArray);
98  NS_ENSURE_ARG_POINTER(aMediaItem);
99 
100  nsresult rv = mArray->AppendElement(aMediaItem, PR_FALSE);
101  NS_ENSURE_SUCCESS(rv, rv);
102 
103  if(!mHasItems) {
104  mHasItems = PR_TRUE;
105  }
106 
108 
109  return NS_OK;
110 }
111 
112 NS_IMETHODIMP
113 sbLocalMediaListBaseEnumerationListener::OnEnumerationEnd(sbIMediaList *aMediaList,
114  nsresult aStatusCode)
115 {
116  return NS_OK;
117 }
return NS_OK
Interface used to enumerate the items in a media list.
inArray array
A brief description of the contents of this interface.
Interface that defines a single item of media in the system.
NS_IMPL_ISUPPORTS1(sbLocalMediaListBaseEnumerationListener, sbIMediaListEnumerationListener) sbLocalMediaListBaseEnumerationListener