33 #include <sbILibraryManager.h>
35 #include <nsIAppStartupNotifier.h>
36 #include <nsICategoryManager.h>
37 #include <nsIGenericFactory.h>
38 #include <nsIObserver.h>
39 #include <nsIObserverService.h>
40 #include <nsISimpleEnumerator.h>
41 #include <nsISupportsPrimitives.h>
43 #include <nsArrayEnumerator.h>
44 #include <nsAutoLock.h>
45 #include <nsCOMArray.h>
46 #include <nsComponentManagerUtils.h>
47 #include <nsEnumeratorUtils.h>
48 #include <nsServiceManagerUtils.h>
49 #include <nsThreadUtils.h>
58 static PRLogModuleInfo* gMediaListViewMapLog = nsnull;
59 #define TRACE(args) PR_LOG(gMediaListViewMapLog, PR_LOG_DEBUG, args)
60 #define LOG(args) PR_LOG(gMediaListViewMapLog, PR_LOG_WARN, args)
72 MOZ_COUNT_CTOR(sbMediaListViewMap);
74 if (!gMediaListViewMapLog)
75 gMediaListViewMapLog = PR_NewLogModule(
"sbMediaListViewMap");
78 TRACE((
"sbMediaListViewMap[0x%x] - Created",
this));
80 NS_ASSERTION(NS_IsMainThread(),
"Wrong thread!");
83 sbMediaListViewMap::~sbMediaListViewMap()
85 TRACE((
"MediaListViewMap[0x%x] - Destroyed",
this));
92 const char* aLoaderStr,
94 const nsModuleComponentInfo *aInfo)
97 nsCOMPtr<nsICategoryManager> categoryManager =
98 do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
99 NS_ENSURE_SUCCESS(rv, rv);
101 rv = categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY,
104 PR_TRUE, PR_TRUE, nsnull);
105 NS_ENSURE_SUCCESS(rv, rv);
116 TRACE((
"sbMediaListViewMap[0x%x] - Init",
this));
117 NS_ASSERTION(NS_IsMainThread(),
"Wrong thread!");
121 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
122 NS_ENSURE_SUCCESS(rv, rv);
126 NS_ENSURE_SUCCESS(rv, rv);
130 NS_ENSURE_SUCCESS(rv, rv);
137 sbMediaListViewMap::GetView(
nsISupports *aParentKey,
141 TRACE((
"sbMediaListViewMap[0x%x] - GetView",
this));
143 NS_ASSERTION(NS_IsMainThread(),
"Wrong thread!");
144 NS_ENSURE_ARG_POINTER( aParentKey );
145 NS_ENSURE_ARG_POINTER( aPageKey );
146 NS_ENSURE_ARG_POINTER( _retval );
147 sbViewMapInner *innerMap = nsnull;
148 sbViewStateInfo *innerValue = nsnull;
150 if ( mViewMap.Get( aParentKey, &innerMap ) && innerMap && innerMap->Get( aPageKey, &innerValue ) )
155 innerValue->state->ToString(buff);
156 TRACE((
"sbMediaListViewMap[0x%x] - Restoring view %s %s %s",
this,
157 NS_LossyConvertUTF16toASCII(innerValue->libraryGuid).get(),
158 NS_LossyConvertUTF16toASCII(innerValue->libraryGuid).get(),
159 NS_LossyConvertUTF16toASCII(buff).get()));
164 nsCOMPtr<sbILibraryManager> lm =
165 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv );
166 NS_ENSURE_SUCCESS( rv, rv );
168 nsCOMPtr<sbILibrary> library;
169 rv = lm->GetLibrary( innerValue->libraryGuid, getter_AddRefs(library) );
170 if ( rv == NS_ERROR_NOT_AVAILABLE ) {
173 NS_ENSURE_SUCCESS( rv, rv );
175 nsCOMPtr<sbIMediaItem> item;
176 rv = library->GetItemByGuid( innerValue->listGuid, getter_AddRefs(item) );
177 if ( rv == NS_ERROR_NOT_AVAILABLE ) {
180 NS_ENSURE_SUCCESS( rv, rv );
182 nsCOMPtr<sbIMediaList> list = do_QueryInterface(item, &rv);
183 NS_ENSURE_SUCCESS( rv, rv );
185 rv = list->CreateView(innerValue->state, _retval);
186 NS_ENSURE_SUCCESS( rv, rv );
195 sbMediaListViewMap::SetView(
nsISupports *aParentKey,
199 TRACE((
"sbMediaListViewMap[0x%x] - SetView",
this));
201 NS_ASSERTION(NS_IsMainThread(),
"Wrong thread!");
202 NS_ENSURE_ARG_POINTER( aParentKey );
203 NS_ENSURE_ARG_POINTER( aPageKey );
204 NS_ENSURE_ARG_POINTER( aView );
208 sbViewMapInner *innerMap = nsnull;
211 if ( ! mViewMap.Get( aParentKey, &innerMap ) )
213 innerMap =
new sbViewMapInner;
214 NS_ENSURE_TRUE(innerMap, NS_ERROR_OUT_OF_MEMORY);
215 success = innerMap->Init();
216 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
217 success = mViewMap.Put( aParentKey, innerMap );
218 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
221 nsCOMPtr<sbIMediaList> list;
223 rv = aView->GetMediaList(getter_AddRefs(list));
224 NS_ENSURE_SUCCESS(rv, rv);
225 rv = list->GetGuid(listGuid);
226 NS_ENSURE_SUCCESS(rv, rv);
228 nsCOMPtr<sbILibrary> library;
229 nsString libraryGuid;
230 rv = list->GetLibrary(getter_AddRefs(library));
231 NS_ENSURE_SUCCESS(rv, rv);
232 rv = library->GetGuid(libraryGuid);
233 NS_ENSURE_SUCCESS(rv, rv);
235 nsCOMPtr<sbIMediaListViewState> state;
236 rv = aView->GetState(getter_AddRefs(state));
237 NS_ENSURE_SUCCESS(rv, rv);
242 state->ToString(buff);
243 TRACE((
"sbMediaListViewMap[0x%x] - Saving view %s %s %s",
this,
244 NS_LossyConvertUTF16toASCII(libraryGuid).
get(),
245 NS_LossyConvertUTF16toASCII(libraryGuid).
get(),
246 NS_LossyConvertUTF16toASCII(buff).
get()));
250 nsAutoPtr<sbViewStateInfo> si(
251 new sbViewStateInfo(libraryGuid, listGuid, state));
252 NS_ENSURE_TRUE(si, NS_ERROR_OUT_OF_MEMORY);
255 success = innerMap->Put( aPageKey, si );
256 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
264 NS_IMETHODIMP sbMediaListViewMap::ReleaseViews(
nsISupports *aParentKey)
266 NS_ASSERTION(NS_IsMainThread(),
"Wrong thread!");
274 sbViewMapInner *innerMap = nsnull;
275 if ( mViewMap.Get( aParentKey, &innerMap ) )
278 mViewMap.Remove( aParentKey );
290 const PRUnichar*
aData)
292 TRACE((
"sbMediaListViewMap[0x%x] - Observe: %s",
this, aTopic));
296 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
298 if (strcmp(aTopic, APPSTARTUP_TOPIC) == 0) {
304 if (NS_SUCCEEDED(rv)) {
316 if (NS_SUCCEEDED(rv)) {
321 ReleaseViews( nsnull );
326 NS_NOTREACHED(
"Observing a topic that wasn't handled!");
const SB_LIBRARY_MANAGER_READY_TOPIC
static nsCOMPtr< nsIObserverService > observerService
const SB_LIBRARY_MANAGER_BEFORE_SHUTDOWN_TOPIC
_updateTextAndScrollDataForFrame aData