30 #include <nsComponentManagerUtils.h>
31 #include <nsIClassInfoImpl.h>
32 #include <nsIProgrammingLanguage.h>
34 #include <nsStringAPI.h>
35 #include <nsThreadUtils.h>
43 #include <sbILibrary.h>
44 #include <sbIMediaItem.h>
45 #include <sbIMediaList.h>
58 sbMediaListEnumeratorWrapper::sbMediaListEnumeratorWrapper()
63 sbMediaListEnumeratorWrapper::~sbMediaListEnumeratorWrapper()
66 nsAutoMonitor::DestroyMonitor(mMonitor);
71 sbMediaListEnumeratorWrapper::Initialize(
75 NS_ENSURE_ARG_POINTER(aEnumerator);
78 nsAutoMonitor::NewMonitor(
"sbMediaListEnumeratorWrapper::mMonitor");
79 NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
81 mEnumerator = aEnumerator;
84 nsCOMPtr<nsIThread>
target;
85 nsresult rv = NS_GetMainThread(getter_AddRefs(target));
86 NS_ENSURE_SUCCESS(rv, rv);
91 NS_PROXY_SYNC | NS_PROXY_ALWAYS,
92 getter_AddRefs(mListener));
93 NS_ENSURE_SUCCESS(rv, rv);
101 sbMediaListEnumeratorWrapper::HasMoreElements(PRBool *aMore)
103 NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
104 NS_ENSURE_TRUE(mEnumerator, NS_ERROR_NOT_INITIALIZED);
106 nsAutoMonitor mon(mMonitor);
107 nsresult rv = mEnumerator->HasMoreElements(aMore);
108 NS_ENSURE_SUCCESS(rv, rv);
111 nsCOMPtr<nsISimpleEnumerator> grip(mEnumerator);
112 nsCOMPtr<sbIMediaListEnumeratorWrapperListener>
listener(mListener);
115 rv =
listener->OnHasMoreElements(grip, *aMore);
116 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"onHasMoreElements returned an error");
123 sbMediaListEnumeratorWrapper::GetNext(
nsISupports ** aItem)
125 NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
126 NS_ENSURE_ARG_POINTER(aItem);
128 nsAutoMonitor mon(mMonitor);
130 nsCOMPtr<nsISupports> supports;
131 nsresult rv = mEnumerator->GetNext(getter_AddRefs(supports));
132 NS_ENSURE_SUCCESS(rv, rv);
134 nsCOMPtr<sbIMediaItem> mediaItem;
135 nsCOMPtr<sbIIndexedMediaItem> indexedMediaItem = do_QueryInterface(supports, &rv);
137 if(NS_SUCCEEDED(rv)) {
138 rv = indexedMediaItem->GetMediaItem(getter_AddRefs(mediaItem));
139 NS_ENSURE_SUCCESS(rv, rv);
141 else if(rv == NS_ERROR_NO_INTERFACE) {
142 mediaItem = do_QueryInterface(supports, &rv);
143 NS_ENSURE_SUCCESS(rv, rv);
150 rv = mediaItem->GetGuid(itemGuid);
151 NS_ENSURE_SUCCESS(rv, rv);
153 nsCOMPtr<sbILibrary> library;
154 rv = mediaItem->GetLibrary(getter_AddRefs(library));
155 NS_ENSURE_SUCCESS(rv, rv);
157 nsString libraryGuid;
158 rv = library->GetGuid(libraryGuid);
159 NS_ENSURE_SUCCESS(rv, rv);
161 nsString propertyValue(libraryGuid);
162 propertyValue += NS_LITERAL_STRING(
",");
163 propertyValue += itemGuid;
166 nsCOMPtr<sbILocalDatabaseMediaItem> item =
167 do_QueryInterface(mediaItem, &rv);
168 NS_ENSURE_SUCCESS(rv, rv);
170 item->SetSuppressNotifications(PR_TRUE);
174 NS_ENSURE_SUCCESS(rv, rv);
175 item->SetSuppressNotifications(PR_FALSE);
177 NS_ADDREF(*aItem = mediaItem);
180 nsCOMPtr<nsISimpleEnumerator> grip(mEnumerator);
181 nsCOMPtr<sbIMediaListEnumeratorWrapperListener>
listener(mListener);
184 rv =
listener->OnGetNext(grip, mediaItem);
185 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"onGetNext returned an error");
nsresult do_GetProxyForObject(nsIEventTarget *aTarget, REFNSIID aIID, nsISupports *aObj, PRInt32 aProxyType, void **aProxyObject)
#define SB_PROPERTY_DOWNLOAD_STATUS_TARGET