From aa47adf6e0410809de37a3d57776a6bb2dffc520 Mon Sep 17 00:00:00 2001 From: Laurent Chea Date: Sat, 13 Dec 2014 15:16:16 +0100 Subject: [PATCH] Media service restart is now using BNotification. Fixes 8171. --- src/preferences/media/MediaWindow.cpp | 84 +++++++++++++++------------ src/preferences/media/MediaWindow.h | 7 +-- 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/preferences/media/MediaWindow.cpp b/src/preferences/media/MediaWindow.cpp index 247259b4f8..d641712deb 100644 --- a/src/preferences/media/MediaWindow.cpp +++ b/src/preferences/media/MediaWindow.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -161,7 +162,6 @@ MediaWindow::MediaWindow(BRect frame) fAudioOutputs(5, true), fVideoInputs(5, true), fVideoOutputs(5, true), - fAlert(NULL), fInitCheck(B_OK) { _InitWindow(); @@ -314,17 +314,18 @@ MediaWindow::MessageReceived(BMessage* message) case B_SOME_APP_LAUNCHED: { PRINT_OBJECT(*message); - if (fAlert == NULL) - break; BString mimeSig; if (message->FindString("be:signature", &mimeSig) == B_OK && (mimeSig == "application/x-vnd.Be.addon-host" || mimeSig == "application/x-vnd.Be.media-server")) { - fAlert->Lock(); - fAlert->TextView()->SetText( + BNotification notificationPopup(B_PROGRESS_NOTIFICATION); + notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); + notificationPopup.SetTitle(B_TRANSLATE("Media Service")); + notificationPopup.SetProgress(0.5); + notificationPopup.SetContent( B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); - fAlert->Unlock(); + notificationPopup.Send(); } break; } @@ -418,10 +419,13 @@ MediaWindow::_InitMedia(bool first) if (alert->Go() == 0) return B_ERROR; - fAlert = new MediaAlert(BRect(0, 0, 300, 60), "restart_alert", - B_TRANSLATE("Restarting media services\nStarting media server" - B_UTF8_ELLIPSIS "\n")); - fAlert->Show(); + BNotification notificationPopup(B_PROGRESS_NOTIFICATION); + notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); + notificationPopup.SetTitle(B_TRANSLATE("Media Service")); + notificationPopup.SetProgress(0.5); + notificationPopup.SetContent( + B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); + notificationPopup.Send(); Show(); @@ -435,11 +439,14 @@ MediaWindow::_InitMedia(bool first) && fListView->ItemAt(0)->IsSelected()) isVideoSelected = false; - if ((!first || (first && err) ) && fAlert) { - BAutolock locker(fAlert); - if (locker.IsLocked()) - fAlert->TextView()->SetText( - B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS)); + if (!first || (first && err) ) { + BNotification notificationPopup(B_PROGRESS_NOTIFICATION); + notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); + notificationPopup.SetTitle(B_TRANSLATE("Media Service")); + notificationPopup.SetProgress(1.0); + notificationPopup.SetContent( + B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS)); + notificationPopup.Send(); } while (fListView->CountItems() > 0) @@ -517,12 +524,6 @@ MediaWindow::_InitMedia(bool first) else fListView->Select(fListView->IndexOf(audio)); - if (fAlert != NULL) { - snooze(800000); - fAlert->PostMessage(B_QUIT_REQUESTED); - } - fAlert = NULL; - Unlock(); return B_OK; @@ -648,23 +649,25 @@ status_t MediaWindow::_RestartMediaServices(void* data) { MediaWindow* window = (MediaWindow*)data; - window->fAlert = new MediaAlert(BRect(0, 0, 300, 60), - "restart_alert", B_TRANSLATE( - "Restarting media services\nShutting down media server\n")); - - window->fAlert->Show(); + + BNotification notificationPopup(B_PROGRESS_NOTIFICATION); + notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); + notificationPopup.SetTitle(B_TRANSLATE("Media Service")); + notificationPopup.SetContent( B_TRANSLATE("Shutting down media server")); shutdown_media_server(B_INFINITE_TIMEOUT, MediaWindow::_UpdateProgress, - window->fAlert); + NULL); + + notificationPopup.SetContent( + B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); + notificationPopup.SetProgress(0.5); + notificationPopup.Send(); - { - BAutolock locker(window->fAlert); - if (locker.IsLocked()) - window->fAlert->TextView()->SetText( - B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); - } launch_media_server(); + notificationPopup.SetProgress(1); + notificationPopup.Send(); + return window->PostMessage(ML_INIT_MEDIA); } @@ -672,7 +675,10 @@ MediaWindow::_RestartMediaServices(void* data) bool MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie) { - MediaAlert* alert = static_cast(cookie); + // parameters "message" and "cookie" are no longer used. + // They remain here because they're declared within BeOS API and + // thus could not be removed. + PRINT(("stage : %i\n", stage)); const char* string = "Unknown stage"; switch (stage) { @@ -693,9 +699,13 @@ MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie) break; } - BAutolock locker(alert); - if (locker.IsLocked()) - alert->TextView()->SetText(string); + BNotification info(B_PROGRESS_NOTIFICATION); + info.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); + info.SetProgress(stage/100.0); + info.SetTitle(B_TRANSLATE("Media Service")); + info.SetContent(string); + info.Send(); + return true; } diff --git a/src/preferences/media/MediaWindow.h b/src/preferences/media/MediaWindow.h index be0af2f24d..8d200ede61 100644 --- a/src/preferences/media/MediaWindow.h +++ b/src/preferences/media/MediaWindow.h @@ -23,7 +23,7 @@ #include "MediaListItem.h" #include "MediaViews.h" - +#define MEDIA_SERVICE_NOTIFICATION_ID "MediaServiceNotificationID" #define SETTINGS_FILE "MediaPrefs Settings" @@ -73,8 +73,8 @@ private: NodeListItem* _FindNodeListItem(dormant_node_info* info); static status_t _RestartMediaServices(void* data); - static bool _UpdateProgress(int stage, const char * message, - void * cookie); + static bool _UpdateProgress(int stage, const char* message, + void* cookie); void _ClearParamView(); void _MakeParamView(); @@ -111,7 +111,6 @@ private: NodeList fVideoInputs; NodeList fVideoOutputs; - MediaAlert* fAlert; status_t fInitCheck; };