From 7a5f5d3ded70e0250636eb8d4c0ce0093abdaf2a Mon Sep 17 00:00:00 2001 From: fgerlits Date: Tue, 8 Aug 2006 16:09:00 +0000 Subject: [PATCH] created a "stop currently playing" button in the Scheduler window; fixing #1434, or most of it --- .../SchedulerClientInterface.h | 10 +++++ .../src/SchedulerDaemonXmlRpcClient.cxx | 38 ++++++++++++++++ .../src/SchedulerDaemonXmlRpcClient.h | 10 +++++ .../gLiveSupport/src/SchedulerWindow.cxx | 45 ++++++++++++++++++- .../gLiveSupport/src/SchedulerWindow.h | 7 +++ .../src/products/gLiveSupport/var/root.txt | 5 +++ .../products/scheduler/src/PlaylistEvent.cxx | 2 + .../src/StopCurrentlyPlayingMethod.h | 3 +- 8 files changed, 118 insertions(+), 2 deletions(-) diff --git a/livesupport/src/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h b/livesupport/src/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h index 90912b5f2..1676b988a 100644 --- a/livesupport/src/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h +++ b/livesupport/src/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h @@ -252,6 +252,16 @@ class SchedulerClientInterface throw (XmlRpcException) = 0; + /** + * Stop the scheduler's audio player. + * + * @param sessionId a valid session ID to identify the user. + * @exception XmlRpcException if there is an error. + */ + virtual void + stopCurrentlyPlaying(Ptr::Ref sessionId) + throw (XmlRpcException) = 0; + /** * A virtual destructor, as this class has virtual functions. */ diff --git a/livesupport/src/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx b/livesupport/src/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx index fb13d18ed..b1e94c011 100644 --- a/livesupport/src/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx +++ b/livesupport/src/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx @@ -554,3 +554,41 @@ SchedulerDaemonXmlRpcClient :: restoreBackup( xmlRpcClient.close(); } + +/*------------------------------------------------------------------------------ + * Stop the scheduler's audio player. + *----------------------------------------------------------------------------*/ +void +SchedulerDaemonXmlRpcClient :: stopCurrentlyPlaying( + Ptr::Ref sessionId) + throw (Core::XmlRpcException) +{ + XmlRpcValue xmlRpcParams; + XmlRpcValue xmlRpcResult; + + XmlRpcClient xmlRpcClient(xmlRpcHost->c_str(), + xmlRpcPort, + xmlRpcUri->c_str(), + false); + + XmlRpcTools::sessionIdToXmlRpcValue(sessionId, xmlRpcParams); + + xmlRpcResult.clear(); + if (!xmlRpcClient.execute("stopCurrentlyPlaying", + xmlRpcParams, + xmlRpcResult)) { + throw Core::XmlRpcCommunicationException( + "cannot execute XML-RPC method 'stopCurrentlyPlaying'"); + } + + if (xmlRpcClient.isFault()) { + std::stringstream eMsg; + eMsg << "XML-RPC method 'stopCurrentlyPlaying'" + << " returned error message:\n" + << xmlRpcResult; + throw Core::XmlRpcMethodFaultException(eMsg.str()); + } + + xmlRpcClient.close(); +} + diff --git a/livesupport/src/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h b/livesupport/src/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h index 1f4a76dc8..dc33ae880 100644 --- a/livesupport/src/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h +++ b/livesupport/src/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h @@ -330,6 +330,16 @@ class SchedulerDaemonXmlRpcClient : restoreBackup(Ptr::Ref sessionId, Ptr::Ref path) throw (XmlRpcException); + + /** + * Stop the scheduler's audio player. + * + * @param sessionId a valid session ID to identify the user. + * @exception XmlRpcException if there is an error. + */ + virtual void + stopCurrentlyPlaying(Ptr::Ref sessionId) + throw (XmlRpcException); }; diff --git a/livesupport/src/products/gLiveSupport/src/SchedulerWindow.cxx b/livesupport/src/products/gLiveSupport/src/SchedulerWindow.cxx index 906d97653..cf752d3a2 100644 --- a/livesupport/src/products/gLiveSupport/src/SchedulerWindow.cxx +++ b/livesupport/src/products/gLiveSupport/src/SchedulerWindow.cxx @@ -201,7 +201,31 @@ SchedulerWindow :: constructScheduleView(void) throw () Gtk::VBox * SchedulerWindow :: constructStatusView(void) throw () { - Gtk::VBox * view = Gtk::manage(new Gtk::VBox); + Ptr::Ref wf = WidgetFactory::getInstance(); + + Gtk::Label * stopCurrentlyPlayingLabel; + Button * stopCurrentlyPlayingButton; + try { + stopCurrentlyPlayingLabel = Gtk::manage(new Gtk::Label( + *getResourceUstring("stopCurrentlyPlayingText"))); + stopCurrentlyPlayingButton = Gtk::manage(wf->createButton( + *getResourceUstring("stopCurrentlyPlayingButtonLabel"))); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + std::exit(1); + } + stopCurrentlyPlayingButton->signal_clicked().connect(sigc::mem_fun( + *this, + &SchedulerWindow::onStopCurrentlyPlayingButtonClicked)); + + Gtk::HBox * stopCurrentlyPlayingBox = Gtk::manage(new Gtk::HBox); + stopCurrentlyPlayingBox->pack_start(*stopCurrentlyPlayingLabel, + Gtk::PACK_SHRINK, 5); + stopCurrentlyPlayingBox->pack_start(*stopCurrentlyPlayingButton, + Gtk::PACK_SHRINK, 5); + + Gtk::VBox * view = Gtk::manage(new Gtk::VBox); + view->pack_start(*stopCurrentlyPlayingBox, Gtk::PACK_SHRINK, 20); return view; } @@ -351,3 +375,22 @@ SchedulerWindow :: onDeleteItem(void) throw () } } + +/*------------------------------------------------------------------------------ + * Signal handler for the "stop currently playing" button getting clicked. + *----------------------------------------------------------------------------*/ +void +SchedulerWindow :: onStopCurrentlyPlayingButtonClicked(void) throw () +{ + Ptr::Ref sessionId = gLiveSupport->getSessionId(); + Ptr::Ref + scheduler = gLiveSupport->getScheduler(); + + try { + scheduler->stopCurrentlyPlaying(sessionId); + + } catch (XmlRpcException &e) { + // TODO: signal error here + } +} + diff --git a/livesupport/src/products/gLiveSupport/src/SchedulerWindow.h b/livesupport/src/products/gLiveSupport/src/SchedulerWindow.h index a2e2fa668..ae37b2aa6 100644 --- a/livesupport/src/products/gLiveSupport/src/SchedulerWindow.h +++ b/livesupport/src/products/gLiveSupport/src/SchedulerWindow.h @@ -228,6 +228,13 @@ class SchedulerWindow : public GuiWindow virtual void onDeleteItem(void) throw (); + /** + * Signal handler for the "stop currently playing" button + * getting clicked. + */ + virtual void + onStopCurrentlyPlayingButtonClicked(void) throw (); + public: /** diff --git a/livesupport/src/products/gLiveSupport/var/root.txt b/livesupport/src/products/gLiveSupport/var/root.txt index 04e14614a..260ab0c96 100644 --- a/livesupport/src/products/gLiveSupport/var/root.txt +++ b/livesupport/src/products/gLiveSupport/var/root.txt @@ -168,6 +168,11 @@ root:table endColumnLabel:string { "end" } deleteMenuItem:string { "_Delete" } + stopCurrentlyPlayingText:string + { "Currently playing in scheduler:" } + stopCurrentlyPlayingButtonLabel:string + { "Stop" } + closeButtonLabel:string { "Close" } } diff --git a/livesupport/src/products/scheduler/src/PlaylistEvent.cxx b/livesupport/src/products/scheduler/src/PlaylistEvent.cxx index 81afa1c96..b163a593e 100644 --- a/livesupport/src/products/scheduler/src/PlaylistEvent.cxx +++ b/livesupport/src/products/scheduler/src/PlaylistEvent.cxx @@ -170,6 +170,8 @@ PlaylistEvent :: stop(void) throw () audioPlayer->close(); } catch (std::logic_error &e) { // TODO: handle error + // NOTE: this may not be an error, because the user may have stopped + // the playback manually (see Scheduler::StopCurrentlyPlayingMethod) std::cerr << "PlaylistEvent::stop error: " << std::endl; std::cerr << e.what() << std::endl; } diff --git a/livesupport/src/products/scheduler/src/StopCurrentlyPlayingMethod.h b/livesupport/src/products/scheduler/src/StopCurrentlyPlayingMethod.h index d59912fe4..cef6d8498 100644 --- a/livesupport/src/products/scheduler/src/StopCurrentlyPlayingMethod.h +++ b/livesupport/src/products/scheduler/src/StopCurrentlyPlayingMethod.h @@ -66,7 +66,8 @@ using namespace LiveSupport::Core; /** * An XML-RPC method object to stop the scheduler's audio player. * - * The name of the method when called through XML-RPC is "stopCurrenlyPlaying". + * The name of the method when called through XML-RPC is + * "stopCurrentlyPlaying". * * The expected parameter is an XML-RPC structure, with the following * member: