27 #ifndef __SB_REMOTE_API_UTILS_H__
28 #define __SB_REMOTE_API_UTILS_H__
30 #include <sbILibrary.h>
31 #include <sbILibraryResource.h>
32 #include <sbIMediaItem.h>
33 #include <sbIMediaList.h>
34 #include <sbIMediaListView.h>
35 #include <sbIRemoteMediaList.h>
50 const nsAString &aLibName,
53 NS_ENSURE_ARG_POINTER(aMediaItem);
54 NS_ENSURE_ARG_POINTER(aIsFromLib);
56 nsCOMPtr<sbILibrary> library;
57 nsresult rv = aMediaItem->GetLibrary( getter_AddRefs(library) );
58 NS_ENSURE_SUCCESS( rv, rv );
61 nsCOMPtr<sbILibraryResource> res( do_QueryInterface( library, &rv ) );
62 NS_ENSURE_SUCCESS( rv, rv );
64 rv = res->GetGuid(guid);
65 NS_ENSURE_SUCCESS( rv, rv );
70 NS_ENSURE_SUCCESS( rv, rv );
72 if ( guid == libGuid )
73 *aIsFromLib = PR_TRUE;
75 *aIsFromLib = PR_FALSE;
87 NS_ENSURE_ARG_POINTER(aRemotePlayer);
88 NS_ENSURE_ARG_POINTER(aMediaList);
89 NS_ENSURE_ARG_POINTER(aRemoteMediaList);
94 nsCOMPtr<sbIMediaListView> mediaListView;
95 rv = aMediaList->CreateView( nsnull, getter_AddRefs(mediaListView) );
96 NS_ENSURE_SUCCESS(rv, rv);
100 nsCOMPtr<sbIMediaItem> item( do_QueryInterface( aMediaList, &rv ) );
101 NS_ENSURE_SUCCESS( rv, rv );
103 NS_ENSURE_SUCCESS( rv, rv );
106 NS_ENSURE_SUCCESS( rv, rv );
108 nsRefPtr<sbRemoteMediaList> remoteMediaList;
122 NS_ENSURE_TRUE( remoteMediaList, NS_ERROR_OUT_OF_MEMORY );
123 rv = remoteMediaList->Init();
124 NS_ENSURE_SUCCESS( rv, rv );
126 rv = CallQueryInterface( remoteMediaList.get(), aRemoteMediaList );
127 NS_ENSURE_SUCCESS( rv, rv );
134 static inline nsresult
139 NS_ENSURE_ARG_POINTER(aRemotePlayer);
140 NS_ENSURE_ARG_POINTER(aMediaItem);
141 NS_ENSURE_ARG_POINTER(aRemoteMediaItem);
145 nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface( aMediaItem, &rv );
146 if ( NS_SUCCEEDED(rv) ) {
148 nsCOMPtr<sbIMediaList> remoteMediaList;
151 getter_AddRefs(remoteMediaList) );
152 NS_ENSURE_SUCCESS( rv, rv );
154 rv = CallQueryInterface( remoteMediaList.get(), aRemoteMediaItem );
155 NS_ENSURE_SUCCESS( rv, rv );
161 NS_ENSURE_SUCCESS( rv, rv );
164 NS_ENSURE_SUCCESS( rv, rv );
166 nsRefPtr<sbRemoteMediaItem> remoteMediaItem;
174 NS_ENSURE_TRUE( remoteMediaItem, NS_ERROR_OUT_OF_MEMORY );
175 rv = remoteMediaItem->Init();
176 NS_ENSURE_SUCCESS( rv, rv );
178 rv = CallQueryInterface( remoteMediaItem.get(), aRemoteMediaItem );
179 NS_ENSURE_SUCCESS( rv, rv );
188 static inline nsresult
193 NS_ENSURE_ARG_POINTER(aRemotePlayer);
194 NS_ENSURE_ARG_POINTER(aMediaList);
195 NS_ENSURE_ARG_POINTER(aRemoteMediaList);
197 nsCOMPtr<sbIMediaList> mediaList;
200 getter_AddRefs(mediaList) );
201 NS_ENSURE_SUCCESS( rv, rv );
203 nsCOMPtr<sbIRemoteMediaList> remoteMediaList =
204 do_QueryInterface( mediaList, &rv );
205 NS_ENSURE_SUCCESS( rv, rv );
207 rv = CallQueryInterface( remoteMediaList.get(), aRemoteMediaList );
208 NS_ENSURE_SUCCESS( rv, rv );
215 static inline nsresult
220 NS_ENSURE_ARG_POINTER(aRemotePlayer);
221 NS_ENSURE_ARG_POINTER(aMediaListView);
222 NS_ENSURE_ARG_POINTER(aRemoteMediaList);
225 nsCOMPtr<sbIMediaList> mediaList;
226 nsresult rv = aMediaListView->GetMediaList( getter_AddRefs(mediaList) );
227 NS_ENSURE_SUCCESS(rv, rv);
230 nsCOMPtr<sbIMediaItem> item( do_QueryInterface( mediaList, &rv ) );
231 NS_ENSURE_SUCCESS( rv, rv );
236 NS_ENSURE_SUCCESS( rv, rv );
239 NS_ENSURE_SUCCESS( rv, rv );
241 nsRefPtr<sbRemoteMediaList> remoteMediaList;
255 NS_ENSURE_TRUE( remoteMediaList, NS_ERROR_OUT_OF_MEMORY );
256 rv = remoteMediaList->Init();
257 NS_ENSURE_SUCCESS( rv, rv );
259 rv = CallQueryInterface( remoteMediaList.get(), aRemoteMediaList );
260 NS_ENSURE_SUCCESS( rv, rv );
265 #endif // __SB_REMOTE_API_H__
static nsresult SB_WrapMediaList(sbRemotePlayer *aRemotePlayer, sbIMediaList *aMediaList, sbIMediaList **aRemoteMediaList)
static nsresult GetLibraryGUID(const nsAString &aLibraryID, nsAString &aLibraryGUID)
static nsresult SB_IsFromLibName(sbIMediaItem *aMediaItem, const nsAString &aLibName, PRBool *aIsFromLib)
static nsresult SB_WrapMediaItem(sbRemotePlayer *aRemotePlayer, sbIMediaItem *aMediaItem, sbIMediaItem **aRemoteMediaItem)