diff --git a/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx b/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx index bcb3a71b0..c9dae9453 100644 --- a/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx +++ b/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.43 $ + Version : $Revision: 1.44 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -338,6 +338,8 @@ MasterPanelWindow :: onUpdateTime(int dummy) throw () timeWidget->set_text(to_simple_string(dayTimeSec)); } + nowPlayingWidget->onUpdateTime(); + return true; } diff --git a/livesupport/products/gLiveSupport/src/NowPlaying.cxx b/livesupport/products/gLiveSupport/src/NowPlaying.cxx index 014e1a820..a372100a7 100644 --- a/livesupport/products/gLiveSupport/src/NowPlaying.cxx +++ b/livesupport/products/gLiveSupport/src/NowPlaying.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.9 $ + Version : $Revision: 1.10 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/NowPlaying.cxx,v $ ------------------------------------------------------------------------------*/ @@ -35,6 +35,7 @@ #include +#include "LiveSupport/Core/TimeConversion.h" #include "LiveSupport/Widgets/WidgetFactory.h" #include "NowPlaying.h" @@ -87,7 +88,37 @@ NowPlaying :: NowPlaying(Ptr::Ref gLiveSupport, label->set_use_markup(true); label->set_ellipsize(Pango::ELLIPSIZE_END); label->set_markup(""); - pack_end(*label, Gtk::PACK_EXPAND_WIDGET, 5); + + Gtk::Label * elapsedLabel = createFormattedLabel(8); + Gtk::Label * remainsLabel = createFormattedLabel(8); + elapsedTime = createFormattedLabel(12); + remainsTime = createFormattedLabel(12); + + try { + elapsedLabel->set_text(*getResourceUstring("elapsedTimeLabel")); + remainsLabel->set_text(*getResourceUstring("remainingTimeLabel")); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + std::exit(1); + } + + Gtk::Box * elapsedBox = Gtk::manage(new Gtk::VBox); + elapsedBox->pack_start(*elapsedLabel, Gtk::PACK_EXPAND_WIDGET, 2); + elapsedBox->pack_start(*elapsedTime, Gtk::PACK_EXPAND_WIDGET, 2); + + Gtk::Box * remainsBox = Gtk::manage(new Gtk::VBox); + remainsBox->pack_start(*remainsLabel, Gtk::PACK_EXPAND_WIDGET, 2); + remainsBox->pack_start(*remainsTime, Gtk::PACK_EXPAND_WIDGET, 2); + + Gtk::Box * timeBox = Gtk::manage(new Gtk::HBox); + timeBox->pack_start(*elapsedBox, Gtk::PACK_EXPAND_WIDGET, 2); + timeBox->pack_start(*remainsBox, Gtk::PACK_EXPAND_WIDGET, 2); + + Gtk::Box * textBox = Gtk::manage(new Gtk::VBox); + textBox->pack_start(*label, Gtk::PACK_EXPAND_PADDING, 2); + textBox->pack_start(*timeBox, Gtk::PACK_EXPAND_PADDING, 2); + + pack_end(*textBox, Gtk::PACK_EXPAND_WIDGET, 5); } @@ -125,8 +156,11 @@ NowPlaying :: setPlayable(Ptr::Ref playable) throw () infoString->append(""); } label->set_markup(*infoString); + + audioLength = playable->getPlaylength(); + audioStart = TimeConversion::now(); + } else { - label->set_markup(""); if (isActive) { remove(*stopButton); if (isPaused) { @@ -136,6 +170,11 @@ NowPlaying :: setPlayable(Ptr::Ref playable) throw () } isActive = false; } + label->set_markup(""); + elapsedTime->set_text(""); + remainsTime->set_text(""); + audioLength.reset(); + audioStart.reset(); } } @@ -181,3 +220,50 @@ NowPlaying :: onStopButtonClicked(void) throw () gLiveSupport->stopOutputAudio(); } + +/*------------------------------------------------------------------------------ + * Construct a label with the font attribute already set. + *----------------------------------------------------------------------------*/ +Gtk::Label * +NowPlaying :: createFormattedLabel(int fontSize) throw () +{ + Gtk::Label * label = Gtk::manage(new Gtk::Label); + + Pango::FontDescription fontDescription; + fontDescription.set_family("Bitstream Vera Sans"); + fontDescription.set_weight(Pango::WEIGHT_BOLD); + fontDescription.set_size(fontSize * Pango::SCALE); + + Pango::Attribute fontDescriptionAttribute = + Pango::Attribute::create_attr_font_desc( + fontDescription); + fontDescriptionAttribute.set_start_index(0); + fontDescriptionAttribute.set_end_index(100); + + Pango::AttrList attributeList; + attributeList.insert(fontDescriptionAttribute); + label->set_attributes(attributeList); + + return label; +} + + +/*------------------------------------------------------------------------------ + * Update the timer displays. This is called every second by the master panel. + *----------------------------------------------------------------------------*/ +void +NowPlaying :: onUpdateTime(void) throw () +{ + if (isActive) { + Ptr::Ref now = TimeConversion::now(); + Ptr::Ref elapsed(new time_duration( + *now - *audioStart )); + Ptr::Ref remains(new time_duration( + *audioLength - *elapsed )); + elapsedTime->set_text(*TimeConversion::timeDurationToHhMmSsString( + elapsed )); + remainsTime->set_text(*TimeConversion::timeDurationToHhMmSsString( + remains )); + } +} + diff --git a/livesupport/products/gLiveSupport/src/NowPlaying.h b/livesupport/products/gLiveSupport/src/NowPlaying.h index e285c8b25..0e4a247d7 100644 --- a/livesupport/products/gLiveSupport/src/NowPlaying.h +++ b/livesupport/products/gLiveSupport/src/NowPlaying.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/NowPlaying.h,v $ ------------------------------------------------------------------------------*/ @@ -66,7 +66,7 @@ using namespace LiveSupport::Widgets; * The box displaying "now playing" in the master panel. * * @author $Author: fgerlits $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class NowPlaying : public Gtk::HBox, public LocalizedObject @@ -83,11 +83,31 @@ class NowPlaying : public Gtk::HBox, */ bool isPaused; + /** + * The length of the item currently playing. + */ + Ptr::Ref audioLength; + + /** + * The time the item started playing. + */ + Ptr::Ref audioStart; + /** * The label holding the title etc. of the now playing item. */ Gtk::Label * label; + /** + * The label holding the elapsed time. + */ + Gtk::Label * elapsedTime; + + /** + * The label holding the remaining time. + */ + Gtk::Label * remainsTime; + /** * The play button. */ @@ -131,6 +151,16 @@ class NowPlaying : public Gtk::HBox, void onStopButtonClicked(void) throw (); + /** + * Return a Gtk::manage'd Gtk::Label*, with the Bitstream Vera + * font attributes set. + * + * @param fontSize the size of the text in the label, in points + * @return the new label + */ + Gtk::Label * + createFormattedLabel(int fontSize) throw (); + public: @@ -160,6 +190,14 @@ class NowPlaying : public Gtk::HBox, */ void setPlayable(Ptr::Ref playable) throw (); + + /** + * Function that updates the elapsed and remaining time displays. + * This is called by the MasterPanelWindow every second. + */ + void + onUpdateTime(void) throw (); + }; diff --git a/livesupport/products/gLiveSupport/var/root.txt b/livesupport/products/gLiveSupport/var/root.txt index 427c0549f..f81f79261 100644 --- a/livesupport/products/gLiveSupport/var/root.txt +++ b/livesupport/products/gLiveSupport/var/root.txt @@ -18,6 +18,9 @@ root:table yesButtonLabel:string { "Yes" } okButtonLabel:string { "OK" } + elapsedTimeLabel:string { "elapsed" } + remainingTimeLabel:string { "remaining" } + localeNotAvailableMsg:string { "Locale {0} not available" } schedulerNotReachableMsg:string { "Scheduler server not available" } storageNotReachableMsg:string { "Storage server not available" }