added elapsed/remaining time indicator

This commit is contained in:
fgerlits 2005-08-24 14:37:45 +00:00
parent dc0d2f38b8
commit ec462c8092
4 changed files with 135 additions and 6 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ 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)); timeWidget->set_text(to_simple_string(dayTimeSec));
} }
nowPlayingWidget->onUpdateTime();
return true; return true;
} }

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/NowPlaying.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -35,6 +35,7 @@
#include <iostream> #include <iostream>
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Widgets/WidgetFactory.h" #include "LiveSupport/Widgets/WidgetFactory.h"
#include "NowPlaying.h" #include "NowPlaying.h"
@ -87,7 +88,37 @@ NowPlaying :: NowPlaying(Ptr<GLiveSupport>::Ref gLiveSupport,
label->set_use_markup(true); label->set_use_markup(true);
label->set_ellipsize(Pango::ELLIPSIZE_END); label->set_ellipsize(Pango::ELLIPSIZE_END);
label->set_markup(""); 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<Playable>::Ref playable) throw ()
infoString->append("</span>"); infoString->append("</span>");
} }
label->set_markup(*infoString); label->set_markup(*infoString);
audioLength = playable->getPlaylength();
audioStart = TimeConversion::now();
} else { } else {
label->set_markup("");
if (isActive) { if (isActive) {
remove(*stopButton); remove(*stopButton);
if (isPaused) { if (isPaused) {
@ -136,6 +170,11 @@ NowPlaying :: setPlayable(Ptr<Playable>::Ref playable) throw ()
} }
isActive = false; 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(); 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<ptime>::Ref now = TimeConversion::now();
Ptr<time_duration>::Ref elapsed(new time_duration(
*now - *audioStart ));
Ptr<time_duration>::Ref remains(new time_duration(
*audioLength - *elapsed ));
elapsedTime->set_text(*TimeConversion::timeDurationToHhMmSsString(
elapsed ));
remainsTime->set_text(*TimeConversion::timeDurationToHhMmSsString(
remains ));
}
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ 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. * The box displaying "now playing" in the master panel.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.3 $ * @version $Revision: 1.4 $
*/ */
class NowPlaying : public Gtk::HBox, class NowPlaying : public Gtk::HBox,
public LocalizedObject public LocalizedObject
@ -83,11 +83,31 @@ class NowPlaying : public Gtk::HBox,
*/ */
bool isPaused; bool isPaused;
/**
* The length of the item currently playing.
*/
Ptr<time_duration>::Ref audioLength;
/**
* The time the item started playing.
*/
Ptr<ptime>::Ref audioStart;
/** /**
* The label holding the title etc. of the now playing item. * The label holding the title etc. of the now playing item.
*/ */
Gtk::Label * label; Gtk::Label * label;
/**
* The label holding the elapsed time.
*/
Gtk::Label * elapsedTime;
/**
* The label holding the remaining time.
*/
Gtk::Label * remainsTime;
/** /**
* The play button. * The play button.
*/ */
@ -131,6 +151,16 @@ class NowPlaying : public Gtk::HBox,
void void
onStopButtonClicked(void) throw (); 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: public:
@ -160,6 +190,14 @@ class NowPlaying : public Gtk::HBox,
*/ */
void void
setPlayable(Ptr<Playable>::Ref playable) throw (); setPlayable(Ptr<Playable>::Ref playable) throw ();
/**
* Function that updates the elapsed and remaining time displays.
* This is called by the MasterPanelWindow every second.
*/
void
onUpdateTime(void) throw ();
}; };

View file

@ -18,6 +18,9 @@ root:table
yesButtonLabel:string { "Yes" } yesButtonLabel:string { "Yes" }
okButtonLabel:string { "OK" } okButtonLabel:string { "OK" }
elapsedTimeLabel:string { "elapsed" }
remainingTimeLabel:string { "remaining" }
localeNotAvailableMsg:string { "Locale {0} not available" } localeNotAvailableMsg:string { "Locale {0} not available" }
schedulerNotReachableMsg:string { "Scheduler server not available" } schedulerNotReachableMsg:string { "Scheduler server not available" }
storageNotReachableMsg:string { "Storage server not available" } storageNotReachableMsg:string { "Storage server not available" }