29 #include <nsIStringBundle.h>
30 #include <nsAutoPtr.h>
31 #include <nsServiceManagerUtils.h>
32 #include <nsComponentManagerUtils.h>
34 #include <sbIDataRemote.h>
35 #include <sbILibrary.h>
36 #include <sbILibraryManager.h>
38 #define SB_DATAREMOTE_FACEPLATE_STATUS \
39 NS_LITERAL_STRING("faceplate.status.override.text")
40 #define TIMER_RESOLUTION 500
41 #define MAX_NOTIFICATION_TIME 1 * PR_USEC_PER_SEC
43 #define BUNDLE_URL "chrome://songbird/locale/songbird.properties"
50 static PRLogModuleInfo* gRemoteNotificationManagerLog = nsnull;
53 #define TRACE(args) PR_LOG(gRemoteNotificationManagerLog, PR_LOG_DEBUG, args)
54 #define LOG(args) PR_LOG(gRemoteNotificationManagerLog, PR_LOG_WARN, args)
59 mCurrentActionType(
eNone),
60 mCancelPending(PR_FALSE)
63 if (!gRemoteNotificationManagerLog) {
64 gRemoteNotificationManagerLog = PR_NewLogModule(
"sbRemoteNotificationManager");
67 TRACE((
"sbRemoteNotificationManager[0x%.8x] - Constructed",
this));
72 TRACE((
"sbRemoteNotificationManager[0x%.8x] - Destructed",
this));
78 TRACE((
"sbRemoteNotificationManager[0x%.8x] - Init",
this));
82 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
85 do_CreateInstance(
"@songbirdnest.com/Songbird/DataRemote;1", &rv);
86 NS_ENSURE_SUCCESS(rv, rv);
89 NS_ENSURE_SUCCESS(rv, rv);
91 nsCOMPtr<nsIStringBundleService> stringBundleService =
92 do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
93 NS_ENSURE_SUCCESS(rv, rv);
95 rv = stringBundleService->CreateBundle(
BUNDLE_URL, getter_AddRefs(mBundle));
96 NS_ENSURE_SUCCESS(rv, rv);
98 nsCOMPtr<sbILibraryManager> libManager =
99 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
100 NS_ENSURE_SUCCESS(rv, rv);
102 rv = libManager->GetMainLibrary(getter_AddRefs(mMainLibrary));
103 NS_ENSURE_SUCCESS(rv, rv);
115 mCancelPending = PR_TRUE;
123 TRACE((
"sbRemoteNotificationManager[0x%.8x] - Action (%d, 0x%.8x)",
124 this, aType, aLibrary));
129 return NS_ERROR_INVALID_ARG;
132 nsString libraryName;
135 PRBool isMainLibrary;
136 rv = mMainLibrary->Equals(aLibrary, &isMainLibrary);
137 NS_ENSURE_SUCCESS(rv, rv);
139 if (!isMainLibrary) {
143 rv = aLibrary->GetName(libraryName);
144 NS_ENSURE_SUCCESS(rv, rv);
148 mPriorityList[aType].mLibraryName = libraryName;
153 if (aType < mCurrentActionType) {
154 mCurrentActionType = aType;
156 NS_ENSURE_SUCCESS(rv, rv);
161 mTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
162 NS_ENSURE_SUCCESS(rv, rv);
167 rv = mTimer->InitWithCallback(
this,
169 nsITimer::TYPE_REPEATING_SLACK);
170 NS_ENSURE_SUCCESS(rv, rv);
177 sbRemoteNotificationManager::Notify(nsITimer* aTimer)
179 TRACE((
"sbRemoteNotificationManager[0x%.8x] - Notify",
this));
181 NS_ENSURE_ARG_POINTER(aTimer);
185 if (mCancelPending) {
186 nsRefPtr<sbRemoteNotificationManager> kungFuDeathGrip(
this);
189 mCurrentActionType =
eNone;
194 rv2 = mTimer->Cancel();
201 NS_ENSURE_SUCCESS(rv, rv);
205 PRTime
now = PR_Now();
209 if (mCurrentActionType >
eNone) {
210 if (now > mPriorityList[mCurrentActionType].mDisplayUntilTime) {
211 mPriorityList[mCurrentActionType].mDisplayUntilTime = 0;
222 if (mPriorityList[
i].mDisplayUntilTime > 0) {
223 mCurrentActionType =
i;
226 NS_ENSURE_SUCCESS(rv, rv);
237 sbRemoteNotificationManager::UpdateStatus()
239 TRACE((
"sbRemoteNotificationManager[0x%.8x] - UpdateStatus",
this));
245 switch(mCurrentActionType) {
247 key.AssignLiteral(
"rapi.notification.download");
250 key.AssignLiteral(
"rapi.notification.updateditems");
253 key.AssignLiteral(
"rapi.notification.updatedplaylists");
256 key.AssignLiteral(
"rapi.notification.editeditems");
259 key.AssignLiteral(
"rapi.notification.editedplaylists");
266 if (!key.IsEmpty()) {
267 nsString libraryName = mPriorityList[mCurrentActionType].mLibraryName;
268 const PRUnichar*
strings[1] = { libraryName.get() };
269 rv = mBundle->FormatStringFromName(key.BeginReading(),
272 getter_Copies(message));
278 rv = mDataRemote->SetStringValue(message);
279 NS_ENSURE_SUCCESS(rv, rv);
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
#define SB_DATAREMOTE_FACEPLATE_STATUS
nsresult Action(ActionType aType, sbILibrary *aLibrary)
Media library abstraction.
#define MAX_NOTIFICATION_TIME
~sbRemoteNotificationManager()
_getSelectedPageStyle s i