nsresult nsMessengerUnixIntegration::ShowAlertMessage(const nsAString& aAlertTitle, const nsAString& aAlertText, const nsACString& aFolderURI) { nsresult rv; // if we are already in the process of showing an alert, don't try to show another.... if (mAlertInProgress) return NS_OK; nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); bool showAlert = true; prefBranch->GetBoolPref(SHOW_ALERT_PREF, &showAlert); if (showAlert) { #ifdef MOZ_THUNDERBIRD nsCOMPtr<nsIAlertsService> alertsService(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { mAlertInProgress = PR_TRUE; rv = alertsService->ShowAlertNotification(NS_LITERAL_STRING(NEW_MAIL_ALERT_ICON), aAlertTitle, aAlertText, PR_FALSE, NS_ConvertASCIItoUTF16(aFolderURI), this, EmptyString()); if (NS_SUCCEEDED(rv)) return rv; } AlertFinished(); ShowNewAlertNotification(PR_FALSE); #else nsCOMPtr<nsIAlertsService> alertsService (do_GetService(NS_ALERTSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { rv = alertsService->ShowAlertNotification(NS_LITERAL_STRING(NEW_MAIL_ALERT_ICON), aAlertTitle, aAlertText, PR_TRUE, NS_ConvertASCIItoUTF16(aFolderURI), this, EmptyString()); mAlertInProgress = PR_TRUE; } #endif } if (!showAlert || NS_FAILED(rv)) // go straight to showing the system tray icon. AlertFinished(); return rv; }
void nsDownload::DisplayDownloadFinishedAlert() { nsresult rv; nsCOMPtr<nsIAlertsService> alertsService(do_GetService(NS_ALERTSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return; nsCOMPtr<nsIStringBundle> bundle; nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); if (NS_FAILED(rv)) return; rv = bundleService->CreateBundle(DOWNLOAD_MANAGER_BUNDLE, getter_AddRefs(bundle)); if (NS_FAILED(rv)) return; nsXPIDLString finishedTitle, finishedText; rv = bundle->GetStringFromName(NS_LITERAL_STRING("finishedTitle").get(), getter_Copies(finishedTitle)); if (NS_FAILED(rv)) return; const PRUnichar *strings[] = { mDisplayName.get() }; rv = bundle->FormatStringFromName(NS_LITERAL_STRING("finishedText").get(), strings, 1, getter_Copies(finishedText)); if (NS_FAILED(rv)) return; nsCAutoString url; mTarget->GetSpec(url); alertsService->ShowAlertNotification(NS_LITERAL_STRING("moz-icon://") + NS_ConvertUTF8toUTF16(url), finishedTitle, finishedText, PR_TRUE, NS_LITERAL_STRING("download"), this, EmptyString()); }