29 #include <nsIProxyObjectManager.h>
30 #include <nsIObserverService.h>
39 mJobProgress(aJobProgress),
56 PRBool canceled = PR_TRUE;
58 canceled = mJobProgress->CancelRequested();
70 NS_ENSURE_SUCCESS(rv, rv);
72 rv = mStatusDataRemote->Init(NS_LITERAL_STRING(
"faceplate.status.text"), nsString());
73 NS_ENSURE_SUCCESS(rv, rv);
78 nsTArray<nsString> params;
80 nsString * newElement = params.AppendElement(NS_LITERAL_STRING(
"iTunes"));
81 NS_ENSURE_TRUE(newElement, NS_ERROR_OUT_OF_MEMORY);
83 nsString titleText = bundle.
Format(NS_LITERAL_STRING(
"import_library.job.title_text"),
85 rv = mJobProgress->SetTitleText(titleText);
86 NS_ENSURE_SUCCESS(rv, rv);
88 rv = mJobProgress->SetStatusText(
SBLocalizedString(
"import_library.job.status_text"));
89 NS_ENSURE_SUCCESS(rv, rv);
92 NS_ENSURE_SUCCESS(rv, rv);
98 mStatusDataRemote = nsnull;
99 mJobProgress = nsnull;
103 mStatusText.Truncate();
109 mProgress = (PRUint32)((aProgress * 100L) / mProgressMax);
114 mProgressMax = aProgressMax;
125 if (!mStatusDataRemote || !mJobProgress) {
126 return NS_ERROR_FAILURE;
128 nsString status(mStatusText);
130 if (!mLastStatusText.Equals(mStatusText) || mLastProgress != mProgress) {
132 status.AppendLiteral(
" ");
133 status.AppendInt(mProgress, 10);
134 status.AppendLiteral(
"%");
136 rv = mStatusDataRemote->SetStringValue(status);
137 NS_ENSURE_SUCCESS(rv, rv);
139 if (mLastProgress != mProgress) {
140 rv = mJobProgress->SetProgress(mProgress);
141 NS_ENSURE_SUCCESS(rv, rv);
143 rv = mJobProgress->SetTotal(100);
144 NS_ENSURE_SUCCESS(rv, rv);
152 nsCOMPtr<nsIObserverService> obsSvc = do_GetService(
153 NS_OBSERVERSERVICE_CONTRACTID, &rv);
154 NS_ENSURE_SUCCESS(rv, rv);
156 nsCOMPtr<nsISupports> job = NS_ISUPPORTS_CAST(
sbIJobProgress*, mJobProgress);
157 rv = obsSvc->NotifyObservers(job,
160 NS_ENSURE_SUCCESS(rv, rv);
163 mLastProgress = mProgress;
164 mLastStatusText = mStatusText;
Generic interface for exposing long running jobs to the UI.
nsString Format(const nsAString &aKey, nsTArray< nsString > &aParams, const nsAString &aDefault=SBVoidString())
const unsigned short STATUS_SUCCEEDED
Constant indicating that the job has completed.
~sbiTunesImporterStatus()
const unsigned short STATUS_RUNNING
Constant indicating that the job is active.
static sbiTunesImporterStatus * New(sbiTunesImporterJob *aJobProgress)
#define SB_DATAREMOTE_CONTRACTID
Songbird String Bundle Definitions.
void SetProgress(PRInt64 aProgress)
void SetStatusText(nsAString const &aMsg)
#define SB_LIBRARY_IMPORT_ITUNES_COMPLETE
void SetProgressMax(PRInt64 aMaxProgress)