Media Prefs: rework the BNotification code
* Factor out the notification sending in a single method * Tweak the "progress" values so the progress bar goes from 0 to 100% in order, and only once, during the restart * Remove one notification that was needlessly sent twice * Some other small cleanups Final fix for #8171.
This commit is contained in:
@@ -319,13 +319,8 @@ MediaWindow::MessageReceived(BMessage* message)
|
||||
if (message->FindString("be:signature", &mimeSig) == B_OK
|
||||
&& (mimeSig == "application/x-vnd.Be.addon-host"
|
||||
|| mimeSig == "application/x-vnd.Be.media-server")) {
|
||||
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();
|
||||
_Notify(0.75, B_TRANSLATE("Starting media server"
|
||||
B_UTF8_ELLIPSIS));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -419,13 +414,7 @@ MediaWindow::_InitMedia(bool first)
|
||||
if (alert->Go() == 0)
|
||||
return B_ERROR;
|
||||
|
||||
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();
|
||||
_Notify(0, B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
|
||||
|
||||
Show();
|
||||
|
||||
@@ -439,15 +428,8 @@ MediaWindow::_InitMedia(bool first)
|
||||
&& fListView->ItemAt(0)->IsSelected())
|
||||
isVideoSelected = false;
|
||||
|
||||
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();
|
||||
}
|
||||
if (!first || (first && err) )
|
||||
_Notify(1, B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS));
|
||||
|
||||
while (fListView->CountItems() > 0)
|
||||
delete fListView->RemoveItem((int32)0);
|
||||
@@ -650,24 +632,11 @@ MediaWindow::_RestartMediaServices(void* data)
|
||||
{
|
||||
MediaWindow* window = (MediaWindow*)data;
|
||||
|
||||
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,
|
||||
NULL);
|
||||
|
||||
notificationPopup.SetContent(
|
||||
B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
|
||||
notificationPopup.SetProgress(0.5);
|
||||
notificationPopup.Send();
|
||||
data);
|
||||
|
||||
launch_media_server();
|
||||
|
||||
notificationPopup.SetProgress(1);
|
||||
notificationPopup.Send();
|
||||
|
||||
return window->PostMessage(ML_INIT_MEDIA);
|
||||
}
|
||||
|
||||
@@ -675,9 +644,8 @@ MediaWindow::_RestartMediaServices(void* data)
|
||||
bool
|
||||
MediaWindow::_UpdateProgress(int stage, const char* message, void* 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.
|
||||
// parameter "message" is no longer used. It is kept for compatibility with
|
||||
// BeOS as this is used as a shutdown_media_server callback.
|
||||
|
||||
PRINT(("stage : %i\n", stage));
|
||||
const char* string = "Unknown stage";
|
||||
@@ -699,17 +667,24 @@ MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)
|
||||
break;
|
||||
}
|
||||
|
||||
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();
|
||||
((MediaWindow*)cookie)->_Notify(stage / 150.0, string);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MediaWindow::_Notify(float progress, const char* message)
|
||||
{
|
||||
BNotification info(B_PROGRESS_NOTIFICATION);
|
||||
info.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID);
|
||||
info.SetProgress(progress);
|
||||
info.SetTitle(B_TRANSLATE("Media Service"));
|
||||
info.SetContent(message);
|
||||
info.Send();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MediaWindow::_ClearParamView()
|
||||
{
|
||||
|
||||
@@ -34,9 +34,9 @@ class MidiSettingsView;
|
||||
class MediaWindow : public BWindow {
|
||||
public:
|
||||
MediaWindow(BRect frame);
|
||||
~MediaWindow();
|
||||
~MediaWindow();
|
||||
|
||||
status_t InitCheck();
|
||||
status_t InitCheck();
|
||||
|
||||
// methods to be called by MediaListItems...
|
||||
void SelectNode(const dormant_node_info* node);
|
||||
@@ -53,8 +53,8 @@ public:
|
||||
MediaListItem::media_type type,
|
||||
const dormant_node_info* node);
|
||||
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
typedef BObjectList<dormant_node_info> NodeList;
|
||||
@@ -73,8 +73,9 @@ private:
|
||||
NodeListItem* _FindNodeListItem(dormant_node_info* info);
|
||||
|
||||
static status_t _RestartMediaServices(void* data);
|
||||
static bool _UpdateProgress(int stage, const char* message,
|
||||
static bool _UpdateProgress(int stage, const char* message,
|
||||
void* cookie);
|
||||
void _Notify(float progress, const char* message);
|
||||
|
||||
void _ClearParamView();
|
||||
void _MakeParamView();
|
||||
|
||||
Reference in New Issue
Block a user