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:
Adrien Destugues
2014-12-15 09:52:36 +01:00
parent aa47adf6e0
commit b245bc8dbd
2 changed files with 27 additions and 51 deletions
+21 -46
View File
@@ -319,13 +319,8 @@ MediaWindow::MessageReceived(BMessage* message)
if (message->FindString("be:signature", &mimeSig) == B_OK if (message->FindString("be:signature", &mimeSig) == B_OK
&& (mimeSig == "application/x-vnd.Be.addon-host" && (mimeSig == "application/x-vnd.Be.addon-host"
|| mimeSig == "application/x-vnd.Be.media-server")) { || mimeSig == "application/x-vnd.Be.media-server")) {
BNotification notificationPopup(B_PROGRESS_NOTIFICATION); _Notify(0.75, B_TRANSLATE("Starting media server"
notificationPopup.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID); B_UTF8_ELLIPSIS));
notificationPopup.SetTitle(B_TRANSLATE("Media Service"));
notificationPopup.SetProgress(0.5);
notificationPopup.SetContent(
B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
notificationPopup.Send();
} }
break; break;
} }
@@ -419,13 +414,7 @@ MediaWindow::_InitMedia(bool first)
if (alert->Go() == 0) if (alert->Go() == 0)
return B_ERROR; return B_ERROR;
BNotification notificationPopup(B_PROGRESS_NOTIFICATION); _Notify(0, B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
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(); Show();
@@ -439,15 +428,8 @@ MediaWindow::_InitMedia(bool first)
&& fListView->ItemAt(0)->IsSelected()) && fListView->ItemAt(0)->IsSelected())
isVideoSelected = false; isVideoSelected = false;
if (!first || (first && err) ) { if (!first || (first && err) )
BNotification notificationPopup(B_PROGRESS_NOTIFICATION); _Notify(1, B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS));
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) while (fListView->CountItems() > 0)
delete fListView->RemoveItem((int32)0); delete fListView->RemoveItem((int32)0);
@@ -650,24 +632,11 @@ MediaWindow::_RestartMediaServices(void* data)
{ {
MediaWindow* window = (MediaWindow*)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, shutdown_media_server(B_INFINITE_TIMEOUT, MediaWindow::_UpdateProgress,
NULL); data);
notificationPopup.SetContent(
B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS));
notificationPopup.SetProgress(0.5);
notificationPopup.Send();
launch_media_server(); launch_media_server();
notificationPopup.SetProgress(1);
notificationPopup.Send();
return window->PostMessage(ML_INIT_MEDIA); return window->PostMessage(ML_INIT_MEDIA);
} }
@@ -675,9 +644,8 @@ MediaWindow::_RestartMediaServices(void* data)
bool bool
MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie) MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)
{ {
// parameters "message" and "cookie" are no longer used. // parameter "message" is no longer used. It is kept for compatibility with
// They remain here because they're declared within BeOS API and // BeOS as this is used as a shutdown_media_server callback.
// thus could not be removed.
PRINT(("stage : %i\n", stage)); PRINT(("stage : %i\n", stage));
const char* string = "Unknown stage"; const char* string = "Unknown stage";
@@ -699,17 +667,24 @@ MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)
break; break;
} }
BNotification info(B_PROGRESS_NOTIFICATION); ((MediaWindow*)cookie)->_Notify(stage / 150.0, string);
info.SetMessageID(MEDIA_SERVICE_NOTIFICATION_ID);
info.SetProgress(stage/100.0);
info.SetTitle(B_TRANSLATE("Media Service"));
info.SetContent(string);
info.Send();
return true; 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 void
MediaWindow::_ClearParamView() MediaWindow::_ClearParamView()
{ {
+5 -4
View File
@@ -34,9 +34,9 @@ class MidiSettingsView;
class MediaWindow : public BWindow { class MediaWindow : public BWindow {
public: public:
MediaWindow(BRect frame); MediaWindow(BRect frame);
~MediaWindow(); ~MediaWindow();
status_t InitCheck(); status_t InitCheck();
// methods to be called by MediaListItems... // methods to be called by MediaListItems...
void SelectNode(const dormant_node_info* node); void SelectNode(const dormant_node_info* node);
@@ -53,8 +53,8 @@ public:
MediaListItem::media_type type, MediaListItem::media_type type,
const dormant_node_info* node); const dormant_node_info* node);
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
private: private:
typedef BObjectList<dormant_node_info> NodeList; typedef BObjectList<dormant_node_info> NodeList;
@@ -75,6 +75,7 @@ private:
static status_t _RestartMediaServices(void* data); 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* cookie);
void _Notify(float progress, const char* message);
void _ClearParamView(); void _ClearParamView();
void _MakeParamView(); void _MakeParamView();