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
|
|
25 | 25 | #include <Locale.h> |
26 | 26 | #include <MediaRoster.h> |
27 | 27 | #include <MediaTheme.h> |
| 28 | #include <Notification.h> |
28 | 29 | #include <Resources.h> |
29 | 30 | #include <Roster.h> |
30 | 31 | #include <Screen.h> |
… |
… |
MediaWindow::MediaWindow(BRect frame)
|
161 | 162 | fAudioOutputs(5, true), |
162 | 163 | fVideoInputs(5, true), |
163 | 164 | fVideoOutputs(5, true), |
164 | | fAlert(NULL), |
165 | 165 | fInitCheck(B_OK) |
166 | 166 | { |
167 | 167 | _InitWindow(); |
… |
… |
MediaWindow::MessageReceived(BMessage* message)
|
314 | 314 | case B_SOME_APP_LAUNCHED: |
315 | 315 | { |
316 | 316 | PRINT_OBJECT(*message); |
317 | | if (fAlert == NULL) |
318 | | break; |
319 | 317 | |
320 | 318 | BString mimeSig; |
321 | 319 | if (message->FindString("be:signature", &mimeSig) == B_OK |
322 | 320 | && (mimeSig == "application/x-vnd.Be.addon-host" |
323 | 321 | || 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( |
326 | 327 | B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); |
327 | | fAlert->Unlock(); |
| 328 | notificationPopup.Send(); |
328 | 329 | } |
329 | 330 | break; |
330 | 331 | } |
… |
… |
MediaWindow::_InitMedia(bool first)
|
418 | 419 | if (alert->Go() == 0) |
419 | 420 | return B_ERROR; |
420 | 421 | |
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(); |
425 | 429 | |
426 | 430 | Show(); |
427 | 431 | |
… |
… |
MediaWindow::_InitMedia(bool first)
|
435 | 439 | && fListView->ItemAt(0)->IsSelected()) |
436 | 440 | isVideoSelected = false; |
437 | 441 | |
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(); |
443 | 450 | } |
444 | 451 | |
445 | 452 | while (fListView->CountItems() > 0) |
… |
… |
MediaWindow::_InitMedia(bool first)
|
517 | 524 | else |
518 | 525 | fListView->Select(fListView->IndexOf(audio)); |
519 | 526 | |
520 | | if (fAlert != NULL) { |
521 | | snooze(800000); |
522 | | fAlert->PostMessage(B_QUIT_REQUESTED); |
523 | | } |
524 | | fAlert = NULL; |
525 | | |
526 | 527 | Unlock(); |
527 | 528 | |
528 | 529 | return B_OK; |
… |
… |
status_t
|
648 | 649 | MediaWindow::_RestartMediaServices(void* data) |
649 | 650 | { |
650 | 651 | 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")); |
656 | 657 | |
657 | 658 | 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(); |
659 | 665 | |
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 | | } |
666 | 666 | launch_media_server(); |
667 | 667 | |
| 668 | notificationPopup.SetProgress(1); |
| 669 | notificationPopup.Send(); |
| 670 | |
668 | 671 | return window->PostMessage(ML_INIT_MEDIA); |
669 | 672 | } |
670 | 673 | |
… |
… |
MediaWindow::_RestartMediaServices(void* data)
|
672 | 675 | bool |
673 | 676 | MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie) |
674 | 677 | { |
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 | |
676 | 682 | PRINT(("stage : %i\n", stage)); |
677 | 683 | const char* string = "Unknown stage"; |
678 | 684 | switch (stage) { |
… |
… |
MediaWindow::_UpdateProgress(int stage, const char* message, void* cookie)
|
693 | 699 | break; |
694 | 700 | } |
695 | 701 | |
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 | |
699 | 709 | return true; |
700 | 710 | } |
701 | 711 | |
diff --git a/src/preferences/media/MediaWindow.h b/src/preferences/media/MediaWindow.h
index be0af2f..8d200ed 100644
a
|
b
|
|
23 | 23 | #include "MediaListItem.h" |
24 | 24 | #include "MediaViews.h" |
25 | 25 | |
26 | | |
| 26 | #define MEDIA_SERVICE_NOTIFICATION_ID "MediaServiceNotificationID" |
27 | 27 | #define SETTINGS_FILE "MediaPrefs Settings" |
28 | 28 | |
29 | 29 | |
… |
… |
private:
|
73 | 73 | NodeListItem* _FindNodeListItem(dormant_node_info* info); |
74 | 74 | |
75 | 75 | 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); |
78 | 78 | |
79 | 79 | void _ClearParamView(); |
80 | 80 | void _MakeParamView(); |
… |
… |
private:
|
111 | 111 | NodeList fVideoInputs; |
112 | 112 | NodeList fVideoOutputs; |
113 | 113 | |
114 | | MediaAlert* fAlert; |
115 | 114 | status_t fInitCheck; |
116 | 115 | }; |
117 | 116 | |