Ticket #11922: 0013-MediaPlayer-add-support-for-new-media-services-notif.patch

File 0013-MediaPlayer-add-support-for-new-media-services-notif.patch, 6.7 KB (added by Barrett, 5 years ago)
  • src/apps/mediaplayer/MainApp.cpp

    From 3624d05e28df468417a4342f57b6a7c3b2e51b11 Mon Sep 17 00:00:00 2001
    From: Dario Casalinuovo <b.vitruvio@gmail.com>
    Date: Thu, 9 Apr 2015 16:04:06 +0200
    Subject: [PATCH 13/13] MediaPlayer: add support for new media services
     notification service and remove custom code.
    
    ---
     src/apps/mediaplayer/MainApp.cpp | 71 ++--------------------------------------
     src/apps/mediaplayer/MainApp.h   |  6 ----
     src/apps/mediaplayer/MainWin.cpp | 17 +++++++---
     3 files changed, 15 insertions(+), 79 deletions(-)
    
    diff --git a/src/apps/mediaplayer/MainApp.cpp b/src/apps/mediaplayer/MainApp.cpp
    index 4b435d7..d61e8e9 100644
    a b  
    3333#include <MimeType.h>
    3434#include <Path.h>
    3535#include <Resources.h>
    36 #include <Roster.h>
    3736
    3837#include <stdio.h>
    3938#include <stdlib.h>
    const char* kAppSig = "application/x-vnd.Haiku-MediaPlayer";  
    5554
    5655MainApp* gMainApp;
    5756
    58 static const char* kMediaServerSig = B_MEDIA_SERVER_SIGNATURE;
    59 static const char* kMediaServerAddOnSig = "application/x-vnd.Be.addon-host";
    60 
    6157
    6258MainApp::MainApp()
    6359    :
    MainApp::MainApp()  
    6965    fSaveFilePanel(NULL),
    7066    fLastFilePanelFolder(),
    7167
    72     fMediaServerRunning(false),
    73     fMediaAddOnServerRunning(false),
    74 
    7568    fAudioWindowFrameSaved(false),
    7669    fLastSavedAudioWindowCreationTime(0)
    7770{
    7871    fLastFilePanelFolder = Settings::Default()->FilePanelFolder();
    7972
    80     // Now tell the application roster, that we're interested
    81     // in getting notifications of apps being launched or quit.
    82     // In this way we are going to detect a media_server restart.
    83     be_roster->StartWatching(BMessenger(this, this),
    84         B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
    85     // we will keep track of the status of media_server
    86     // and media_addon_server
    87     fMediaServerRunning = be_roster->IsRunning(kMediaServerSig);
    88     fMediaAddOnServerRunning = be_roster->IsRunning(kMediaServerAddOnSig);
    89 
    90     if (!fMediaServerRunning || !fMediaAddOnServerRunning) {
     73    if (!BMediaRoster::IsRunning()) {
    9174        BAlert* alert = new BAlert("start_media_server",
    9275            B_TRANSLATE("It appears the media server is not running.\n"
    9376            "Would you like to start it ?"), B_TRANSLATE("Quit"),
    9477            B_TRANSLATE("Start media server"), NULL,
    9578            B_WIDTH_AS_USUAL, B_WARNING_ALERT);
    9679        alert->SetShortcut(0, B_ESCAPE);
    97        
     80
    9881        if (alert->Go() == 0) {
    9982            PostMessage(B_QUIT_REQUESTED);
    10083            return;
    10184        }
    10285
    10386        launch_media_server();
    104 
    105         fMediaServerRunning = be_roster->IsRunning(kMediaServerSig);
    106         fMediaAddOnServerRunning = be_roster->IsRunning(kMediaServerAddOnSig);
    10787    }
    10888}
    10989
    MainApp::MessageReceived(BMessage* message)  
    317297            break;
    318298        }
    319299
    320         case B_SOME_APP_LAUNCHED:
    321         case B_SOME_APP_QUIT:
    322         {
    323             const char* mimeSig;
    324             if (message->FindString("be:signature", &mimeSig) < B_OK)
    325                 break;
    326 
    327             bool isMediaServer = strcmp(mimeSig, kMediaServerSig) == 0;
    328             bool isAddonServer = strcmp(mimeSig, kMediaServerAddOnSig) == 0;
    329             if (!isMediaServer && !isAddonServer)
    330                 break;
    331 
    332             bool running = (message->what == B_SOME_APP_LAUNCHED);
    333             if (isMediaServer)
    334                 fMediaServerRunning = running;
    335             if (isAddonServer)
    336                 fMediaAddOnServerRunning = running;
    337 
    338             if (!fMediaServerRunning && !fMediaAddOnServerRunning) {
    339                 fprintf(stderr, "media server has quit.\n");
    340                 // trigger closing of media nodes
    341                 BMessage broadcast(M_MEDIA_SERVER_QUIT);
    342                 _BroadcastMessage(broadcast);
    343             } else if (fMediaServerRunning && fMediaAddOnServerRunning) {
    344                 fprintf(stderr, "media server has launched.\n");
    345                 // HACK!
    346                 // quit our now invalid instance of the media roster
    347                 // so that before new nodes are created,
    348                 // we get a new roster (it is a normal looper)
    349                 // TODO: This functionality could become part of
    350                 // BMediaRoster. It could detect the start/quit of
    351                 // the servers like it is done here, and either quit
    352                 // itself, or re-establish the connection, and send some
    353                 // notification to the app... something along those lines.
    354                 BMediaRoster* roster = BMediaRoster::CurrentRoster();
    355                 if (roster) {
    356                     roster->Lock();
    357                     roster->Quit();
    358                 }
    359                 // give the servers some time to init...
    360                 snooze(3000000);
    361                 // trigger re-init of media nodes
    362                 BMessage broadcast(M_MEDIA_SERVER_STARTED);
    363                 _BroadcastMessage(broadcast);
    364             }
    365             break;
    366         }
    367300        case M_SETTINGS:
    368301            _ShowSettingsWindow();
    369302            break;
  • src/apps/mediaplayer/MainApp.h

    diff --git a/src/apps/mediaplayer/MainApp.h b/src/apps/mediaplayer/MainApp.h
    index d629d6d..5111df8 100644
    a b enum {  
    4646    M_OPEN_PANEL_RESULT         = 'oprs',
    4747    M_SAVE_PANEL_RESULT         = 'sprs',
    4848
    49     M_MEDIA_SERVER_STARTED      = 'msst',
    50     M_MEDIA_SERVER_QUIT         = 'msqt',
    51 
    5249    M_OPEN_PREVIOUS_PLAYLIST    = 'oppp'
    5350};
    5451
    private:  
    108105            BFilePanel*         fSaveFilePanel;
    109106            entry_ref           fLastFilePanelFolder;
    110107
    111             bool                fMediaServerRunning;
    112             bool                fMediaAddOnServerRunning;
    113 
    114108            bool                fAudioWindowFrameSaved;
    115109            bigtime_t           fLastSavedAudioWindowCreationTime;
    116110};
  • src/apps/mediaplayer/MainWin.cpp

    diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp
    index d16d050..524fad0 100644
    a b  
    3535#include <fs_attr.h>
    3636#include <Language.h>
    3737#include <Locale.h>
     38#include <MediaRoster.h>
    3839#include <Menu.h>
    3940#include <MenuBar.h>
    4041#include <MenuItem.h>
    MainWin::MainWin(bool isFirstWindow, BMessage* message)  
    315316
    316317    if (message != NULL)
    317318        PostMessage(message);
     319
     320    BMediaRoster* roster = BMediaRoster::Roster();
     321    roster->StartWatching(BMessenger(this, this), B_MEDIA_SERVER_STARTED);
     322    roster->StartWatching(BMessenger(this, this),  B_MEDIA_SERVER_QUIT);
    318323}
    319324
    320325
    MainWin::~MainWin()  
    322327{
    323328//  printf("MainWin::~MainWin\n");
    324329
     330    BMediaRoster* roster = BMediaRoster::CurrentRoster();
     331    roster->StopWatching(BMessenger(this, this), B_MEDIA_SERVER_STARTED);
     332    roster->StopWatching(BMessenger(this, this), B_MEDIA_SERVER_QUIT);
     333
    325334    Settings::Default()->RemoveListener(&fGlobalSettingsListener);
    326335    fPlaylist->RemoveListener(fPlaylistObserver);
    327336    fController->Lock();
    MainWin::MessageReceived(BMessage* msg)  
    623632            fPlaylistWindow->PostMessage(msg);
    624633            break;
    625634
    626         case M_MEDIA_SERVER_STARTED:
     635        case B_MEDIA_SERVER_STARTED:
    627636        {
    628             printf("TODO: implement M_MEDIA_SERVER_STARTED\n");
     637            printf("TODO: implement B_MEDIA_SERVER_STARTED\n");
    629638//
    630639//          BAutolock _(fPlaylist);
    631640//          BMessage fakePlaylistMessage(MSG_PLAYLIST_CURRENT_ITEM_CHANGED);
    MainWin::MessageReceived(BMessage* msg)  
    635644            break;
    636645        }
    637646
    638         case M_MEDIA_SERVER_QUIT:
    639             printf("TODO: implement M_MEDIA_SERVER_QUIT\n");
     647        case B_MEDIA_SERVER_QUIT:
     648            printf("TODO: implement B_MEDIA_SERVER_QUIT\n");
    640649//          if (fController->Lock()) {
    641650//              fController->CleanupNodes();
    642651//              fController->Unlock();