diff options
author | Ken Moore <ken@pcbsd.org> | 2015-02-05 15:01:18 -0500 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2015-02-05 15:01:18 -0500 |
commit | 9debac5e1074f1a1db41d9bc5ac3bf65652d7af5 (patch) | |
tree | ba197fb6e2677509973b62e66c6877c6a7a2a814 /lumina-desktop/panel-plugins/clock | |
parent | Another bit of cleanup/rearranging in lumina-config. (diff) | |
download | lumina-9debac5e1074f1a1db41d9bc5ac3bf65652d7af5.tar.gz lumina-9debac5e1074f1a1db41d9bc5ac3bf65652d7af5.tar.bz2 lumina-9debac5e1074f1a1db41d9bc5ac3bf65652d7af5.zip |
Add the ability to set different date/time formats on a session-wide scale, and have the clock plugin instantly update to the new format (backwards compatible with no formats set)
Diffstat (limited to 'lumina-desktop/panel-plugins/clock')
-rw-r--r-- | lumina-desktop/panel-plugins/clock/LClock.cpp | 23 | ||||
-rw-r--r-- | lumina-desktop/panel-plugins/clock/LClock.h | 5 |
2 files changed, 22 insertions, 6 deletions
diff --git a/lumina-desktop/panel-plugins/clock/LClock.cpp b/lumina-desktop/panel-plugins/clock/LClock.cpp index a61eb75d..e66d83c2 100644 --- a/lumina-desktop/panel-plugins/clock/LClock.cpp +++ b/lumina-desktop/panel-plugins/clock/LClock.cpp @@ -6,6 +6,8 @@ //=========================================== #include "LClock.h" +#include "LSession.h" + LClock::LClock(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ //Setup the widget label = new QLabel(this); @@ -15,9 +17,11 @@ LClock::LClock(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, //Setup the timer timer = new QTimer(); - timer->setInterval(1000); //update once a second - connect(timer,SIGNAL(timeout()), this, SLOT(updateTime()) ); + timer->setInterval(1000); //update once a second + updateFormats(); updateTime(); + connect(timer,SIGNAL(timeout()), this, SLOT(updateTime()) ); + connect(QApplication::instance(), SIGNAL(SessionConfigChanged()), this, SLOT(updateFormats()) ); timer->start(); } @@ -26,10 +30,19 @@ LClock::~LClock(){ delete timer; } + void LClock::updateTime(){ QDateTime CT = QDateTime::currentDateTime(); //Now update the display - QLocale sys = QLocale::system(); - label->setText( "<b>"+CT.toString(sys.timeFormat(QLocale::ShortFormat))+"</b>" ); - label->setToolTip(CT.toString(sys.dateFormat())); + if(deftime){ label->setText( "<b>"+CT.time().toString(Qt::SystemLocaleShortDate)+"</b>" ); } + else{ label->setText( "<b>"+CT.toString(timefmt)+"</b>" ); } + if(defdate){ label->setToolTip(CT.date().toString(Qt::SystemLocaleLongDate)); } + else{ label->setToolTip(CT.toString(datefmt)); } } + +void LClock::updateFormats(){ + timefmt = LSession::handle()->sessionSettings()->value("TimeFormat","").toString(); + datefmt = LSession::handle()->sessionSettings()->value("DateFormat","").toString(); + deftime = timefmt.simplified().isEmpty(); + defdate = datefmt.simplified().isEmpty(); +}
\ No newline at end of file diff --git a/lumina-desktop/panel-plugins/clock/LClock.h b/lumina-desktop/panel-plugins/clock/LClock.h index d4de917c..8f7e38eb 100644 --- a/lumina-desktop/panel-plugins/clock/LClock.h +++ b/lumina-desktop/panel-plugins/clock/LClock.h @@ -25,9 +25,12 @@ public: private: QTimer *timer; QLabel *label; - + QString timefmt, datefmt; + bool deftime, defdate; + private slots: void updateTime(); + void updateFormats(); }; |