VolumeControl: Add support for media services notifications

This commit is contained in:
Dario Casalinuovo 2015-07-23 18:10:56 +02:00
parent 32afe10ab2
commit 92ab0a8c3a

View File

@ -19,8 +19,8 @@
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h> #include <ControlLook.h>
#include <Dragger.h> #include <Dragger.h>
#include <MediaRoster.h>
#include <MessageRunner.h> #include <MessageRunner.h>
#include <Roster.h>
#include <AppMisc.h> #include <AppMisc.h>
@ -29,15 +29,10 @@
#include "VolumeWindow.h" #include "VolumeWindow.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "VolumeControl" #define B_TRANSLATION_CONTEXT "VolumeControl"
static const char* kMediaServerSignature = "application/x-vnd.Be.media-server";
static const char* kAddOnServerSignature = "application/x-vnd.Be.addon-host";
static const uint32 kMsgReconnectVolume = 'rcms'; static const uint32 kMsgReconnectVolume = 'rcms';
@ -131,7 +126,9 @@ VolumeControl::AttachedToWindow()
else else
SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY); SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
be_roster->StartWatching(this, B_REQUEST_LAUNCHED | B_REQUEST_QUIT); BMediaRoster* roster = BMediaRoster::Roster();
roster->StartWatching(BMessenger(this), B_MEDIA_SERVER_STARTED);
roster->StartWatching(BMessenger(this), B_MEDIA_SERVER_QUIT);
_ConnectVolume(); _ConnectVolume();
@ -150,7 +147,9 @@ VolumeControl::DetachedFromWindow()
{ {
_DisconnectVolume(); _DisconnectVolume();
be_roster->StopWatching(this); BMediaRoster* roster = BMediaRoster::CurrentRoster();
roster->StopWatching(BMessenger(this), B_MEDIA_SERVER_STARTED);
roster->StopWatching(BMessenger(this), B_MEDIA_SERVER_QUIT);
} }
@ -294,42 +293,19 @@ VolumeControl::MessageReceived(BMessage* msg)
SetValue((int32)fMixerControl->Volume()); SetValue((int32)fMixerControl->Volume());
break; break;
case B_SOME_APP_LAUNCHED: case B_MEDIA_SERVER_STARTED:
case B_SOME_APP_QUIT:
{ {
const char* signature; BMessage reconnect(kMsgReconnectVolume);
if (msg->FindString("be:signature", &signature) != B_OK) BMessageRunner::StartSending(this, &reconnect, 1000000LL, 1);
break; fConnectRetries = 3;
break;
}
bool isMediaServer = !strcmp(signature, kMediaServerSignature); case B_MEDIA_SERVER_QUIT:
bool isAddOnServer = !strcmp(signature, kAddOnServerSignature); {
if (!isMediaServer && !isAddOnServer) // No media server around
break; SetLabel(B_TRANSLATE("No media server running"));
SetEnabled(false);
if (isMediaServer)
fMediaServerRunning = msg->what == B_SOME_APP_LAUNCHED;
if (isAddOnServer)
fAddOnServerRunning = msg->what == B_SOME_APP_LAUNCHED;
if (!fMediaServerRunning && !fAddOnServerRunning) {
// No media server around
SetLabel(B_TRANSLATE("No media server running"));
SetEnabled(false);
} else if (fMediaServerRunning && fAddOnServerRunning) {
// HACK!
// quit our now invalid instance of the media roster
// so that before new nodes are created,
// we get a new roster
BMediaRoster* roster = BMediaRoster::CurrentRoster();
if (roster != NULL) {
roster->Lock();
roster->Quit();
}
BMessage reconnect(kMsgReconnectVolume);
BMessageRunner::StartSending(this, &reconnect, 1000000LL, 1);
fConnectRetries = 3;
}
break; break;
} }