From 86beeeab01ba69caa328e0e7e2533a0baedb65b0 Mon Sep 17 00:00:00 2001 From: maroy Date: Wed, 1 Dec 2004 10:17:19 +0000 Subject: [PATCH] added real time clock display --- .../gLiveSupport/src/UiTestMainWindow.cxx | 62 ++++++++++++++++++- .../gLiveSupport/src/UiTestMainWindow.h | 42 ++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx b/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx index 68936680f..7a0a233df 100644 --- a/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx +++ b/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/UiTestMainWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -38,6 +38,7 @@ #include #include +#include "LiveSupport/Core/TimeConversion.h" #include "LoginWindow.h" #include "UiTestMainWindow.h" @@ -68,6 +69,9 @@ UiTestMainWindow :: UiTestMainWindow (Ptr::Ref gLiveSupport, // set up the status label statusLabel.reset(new Gtk::Label(*getResourceUstring("welcomeMsg"))); + // set up the time label + timeLabel.reset(new Gtk::Label("")); + // set up the login button loginButton.reset(new Gtk::Button("loginWindow")); loginButton->signal_clicked().connect(sigc::mem_fun(*this, @@ -89,6 +93,7 @@ UiTestMainWindow :: UiTestMainWindow (Ptr::Ref gLiveSupport, // set up the main window, and show everything set_border_width(10); layout->add(*statusLabel); + layout->add(*timeLabel); layout->add(*loginButton); layout->add(*logoutButton); layout->add(*quitButton); @@ -96,11 +101,15 @@ UiTestMainWindow :: UiTestMainWindow (Ptr::Ref gLiveSupport, // show everything statusLabel->show(); + timeLabel->show(); loginButton->show(); logoutButton->show(); quitButton->show(); layout->show(); show(); + + // set the timer, that will update timeLabel + setTimer(); } @@ -109,6 +118,34 @@ UiTestMainWindow :: UiTestMainWindow (Ptr::Ref gLiveSupport, *----------------------------------------------------------------------------*/ UiTestMainWindow :: ~UiTestMainWindow (void) throw () { + resetTimer(); +} + + +/*------------------------------------------------------------------------------ + * Set the timer + *----------------------------------------------------------------------------*/ +void +UiTestMainWindow :: setTimer(void) throw () +{ + sigc::slot slot = sigc::bind(sigc::mem_fun(*this, + &UiTestMainWindow::onUpdateTime), + 0); + + // set the timer to active once a second + timer.reset(new sigc::connection( + Glib::signal_timeout().connect(slot, 1000))); +} + + +/*------------------------------------------------------------------------------ + * Clear the timer + *----------------------------------------------------------------------------*/ +void +UiTestMainWindow :: resetTimer(void) throw () +{ + timer->disconnect(); + timer.reset(); } @@ -166,3 +203,26 @@ UiTestMainWindow :: onLoginButtonClicked (void) throw () } } + +/*------------------------------------------------------------------------------ + * Update the timeLabel display, with the current time + *----------------------------------------------------------------------------*/ +bool +UiTestMainWindow :: onUpdateTime(int dummy) throw () +{ + // TODO: read current time from scheduler server, via the gLiveSupport + // object + Ptr::Ref now = TimeConversion::now(); + time_duration dayTime = now->time_of_day(); + // get the time of day, only up to a second precision + time_duration dayTimeSec(dayTime.hours(), + dayTime.minutes(), + dayTime.seconds(), + 0); + + timeLabel->set_text(to_simple_string(dayTimeSec)); + + return true; +} + + diff --git a/livesupport/products/gLiveSupport/src/UiTestMainWindow.h b/livesupport/products/gLiveSupport/src/UiTestMainWindow.h index 7d6854f79..e011391e2 100644 --- a/livesupport/products/gLiveSupport/src/UiTestMainWindow.h +++ b/livesupport/products/gLiveSupport/src/UiTestMainWindow.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/UiTestMainWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -66,7 +66,7 @@ using namespace LiveSupport::Core; * A window, enabling interactive testing of UI components. * * @author $Author: maroy $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class UiTestMainWindow : public Gtk::Window, public GtkLocalizedObject { @@ -81,6 +81,17 @@ class UiTestMainWindow : public Gtk::Window, public GtkLocalizedObject */ Ptr::Ref statusLabel; + /** + * A label showing the current time, with second precision. + */ + Ptr::Ref timeLabel; + + /** + * The signal connection, that is notified by the GTK timer each + * second, and will update timeLabel on each wakeup. + */ + Ptr::Ref timer; + /** * The to quit the applicaiton. */ @@ -119,6 +130,33 @@ class UiTestMainWindow : public Gtk::Window, public GtkLocalizedObject virtual void onLogoutButtonClicked(void) throw (); + /** + * Function that updates timeLabel with the current time. + * This is called by GTK at regular intervals. + * + * @param param a dummy, unused parameter + * @return true if the timer should call this function again, + * false if the timer should be canceled + */ + virtual bool + onUpdateTime(int dummy) throw (); + + /** + * Register onUpdateTime with the GTK timer. + * + * @see #resetTimer + */ + virtual void + setTimer(void) throw (); + + /** + * Stop the timer, which was set by setTimer(). + * + * @see #setTimer + */ + virtual void + resetTimer(void) throw (); + public: /**