Ticket #8171: 0001-Media-service-restart-is-now-using-BNotification.Ticket-8171.patch

File 0001-Media-service-restart-is-now-using-BNotification.Ticket-8171.patch, 6.3 KB (added by MrPingouin, 9 years ago)
  • src/preferences/media/MediaWindow.cpp

    From 2342a671931a9be313a698f9160320161c100b65 Mon Sep 17 00:00:00 2001
    From: Laurent Chea <contact@laurentchea.com>
    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 247259b..d641712 100644
    a b  
    2525#include <Locale.h>
    2626#include <MediaRoster.h>
    2727#include <MediaTheme.h>
     28#include <Notification.h>
    2829#include <Resources.h>
    2930#include <Roster.h>
    3031#include <Screen.h>
    MediaWindow::MediaWindow(BRect frame)  
    161162    fAudioOutputs(5, true),
    162163    fVideoInputs(5, true),
    163164    fVideoOutputs(5, true),
    164     fAlert(NULL),
    165165    fInitCheck(B_OK)
    166166{
    167167    _InitWindow();
    MediaWindow::MessageReceived(BMessage* message)  
    314314        case B_SOME_APP_LAUNCHED:
    315315        {
    316316            PRINT_OBJECT(*message);
    317             if (fAlert == NULL)
    318                 break;
    319317
    320318            BString mimeSig;
    321319            if (message->FindString("be:signature", &mimeSig) == B_OK
    322320                && (mimeSig == "application/x-vnd.Be.addon-host"
    323321                    || mimeSig == "application/x-vnd.Be.media-server")) {
    324                 fAlert->Lock();
    325                 fAlert->TextView()->SetText(
     322                BNotification notificationPopup(B_PROGRESS_NOTIFICATION);
     323                notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID);
     324                notificationPopup.SetTitle(B_TRANSLATE("Media Service"));
     325                notificationPopup.SetProgress(0.5);
     326                notificationPopup.SetContent(
    326327                    B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
    327                 fAlert->Unlock();
     328                notificationPopup.Send();
    328329            }
    329330            break;
    330331        }
    MediaWindow::_InitMedia(bool first)  
    418419        if (alert->Go() == 0)
    419420            return B_ERROR;
    420421
    421         fAlert = new MediaAlert(BRect(0, 0, 300, 60), "restart_alert",
    422             B_TRANSLATE("Restarting media services\nStarting media server"
    423                 B_UTF8_ELLIPSIS "\n"));
    424         fAlert->Show();
     422        BNotification notificationPopup(B_PROGRESS_NOTIFICATION);
     423        notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID);
     424        notificationPopup.SetTitle(B_TRANSLATE("Media Service"));
     425        notificationPopup.SetProgress(0.5);
     426        notificationPopup.SetContent(
     427            B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
     428        notificationPopup.Send();
    425429
    426430        Show();
    427431
    MediaWindow::_InitMedia(bool first)  
    435439        && fListView->ItemAt(0)->IsSelected())
    436440        isVideoSelected = false;
    437441
    438     if ((!first || (first && err) ) && fAlert) {
    439         BAutolock locker(fAlert);
    440         if (locker.IsLocked())
    441             fAlert->TextView()->SetText(
    442                 B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS));
     442    if (!first || (first && err) ) {
     443        BNotification notificationPopup(B_PROGRESS_NOTIFICATION);
     444        notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID);
     445        notificationPopup.SetTitle(B_TRANSLATE("Media Service"));
     446        notificationPopup.SetProgress(1.0);
     447        notificationPopup.SetContent(
     448            B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS));
     449        notificationPopup.Send();
    443450    }
    444451
    445452    while (fListView->CountItems() > 0)
    MediaWindow::_InitMedia(bool first)  
    517524    else
    518525        fListView->Select(fListView->IndexOf(audio));
    519526
    520     if (fAlert != NULL) {
    521         snooze(800000);
    522         fAlert->PostMessage(B_QUIT_REQUESTED);
    523     }
    524     fAlert = NULL;
    525 
    526527    Unlock();
    527528
    528529    return B_OK;
    status_t  
    648649MediaWindow::_RestartMediaServices(void* data)
    649650{
    650651    MediaWindow* window = (MediaWindow*)data;
    651     window->fAlert = new MediaAlert(BRect(0, 0, 300, 60),
    652         "restart_alert", B_TRANSLATE(
    653         "Restarting media services\nShutting down media server\n"));
    654 
    655     window->fAlert->Show();
     652   
     653    BNotification notificationPopup(B_PROGRESS_NOTIFICATION);
     654    notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID);
     655    notificationPopup.SetTitle(B_TRANSLATE("Media Service"));
     656    notificationPopup.SetContent( B_TRANSLATE("Shutting down media server"));
    656657
    657658    shutdown_media_server(B_INFINITE_TIMEOUT, MediaWindow::_UpdateProgress,
    658         window->fAlert);
     659        NULL);
     660
     661    notificationPopup.SetContent(
     662        B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
     663    notificationPopup.SetProgress(0.5);
     664    notificationPopup.Send();
    659665
    660     {
    661         BAutolock locker(window->fAlert);
    662         if (locker.IsLocked())
    663             window->fAlert->TextView()->SetText(
    664                 B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
    665     }
    666666    launch_media_server();
    667667
     668    notificationPopup.SetProgress(1);
     669    notificationPopup.Send();
     670
    668671    return window->PostMessage(ML_INIT_MEDIA);
    669672}
    670673
    MediaWindow::_RestartMediaServices(void* data)  
    672675bool
    673676MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)
    674677{
    675     MediaAlert* alert = static_cast<MediaAlert*>(cookie);
     678    // parameters "message" and "cookie" are no longer used.
     679    // They remain here because they're declared within BeOS API and
     680    // thus could not be removed.
     681
    676682    PRINT(("stage : %i\n", stage));
    677683    const char* string = "Unknown stage";
    678684    switch (stage) {
    MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)  
    693699            break;
    694700    }
    695701
    696     BAutolock locker(alert);
    697     if (locker.IsLocked())
    698         alert->TextView()->SetText(string);
     702    BNotification info(B_PROGRESS_NOTIFICATION);
     703    info.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID);
     704    info.SetProgress(stage/100.0);
     705    info.SetTitle(B_TRANSLATE("Media Service"));
     706    info.SetContent(string);
     707    info.Send();
     708
    699709    return true;
    700710}
    701711
  • src/preferences/media/MediaWindow.h

    diff --git a/src/preferences/media/MediaWindow.h b/src/preferences/media/MediaWindow.h
    index be0af2f..8d200ed 100644
    a b  
    2323#include "MediaListItem.h"
    2424#include "MediaViews.h"
    2525
    26 
     26#define MEDIA_SERVICE_NOTIFICATION_ID "MediaServiceNotificationID"
    2727#define SETTINGS_FILE "MediaPrefs Settings"
    2828
    2929
    private:  
    7373            NodeListItem*       _FindNodeListItem(dormant_node_info* info);
    7474
    7575    static  status_t            _RestartMediaServices(void* data);
    76     static  bool                _UpdateProgress(int stage, const char * message,
    77                                     void * cookie);
     76    static  bool                _UpdateProgress(int stage, const char* message,
     77                                    void* cookie);
    7878
    7979            void                _ClearParamView();
    8080            void                _MakeParamView();
    private:  
    111111            NodeList            fVideoInputs;
    112112            NodeList            fVideoOutputs;
    113113
    114             MediaAlert*         fAlert;
    115114            status_t            fInitCheck;
    116115};
    117116