diff options
author | Ken Moore <ken@ixsystems.com> | 2018-02-01 09:26:58 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2018-02-01 09:26:58 -0500 |
commit | 18330354e918d7fd369a6b6273da023b86a6242c (patch) | |
tree | 8c6f4a00cedc456acc8d62428facb25e875a41fd | |
parent | Another large batch of work on Lumina 2. (diff) | |
download | lumina-18330354e918d7fd369a6b6273da023b86a6242c.tar.gz lumina-18330354e918d7fd369a6b6273da023b86a6242c.tar.bz2 lumina-18330354e918d7fd369a6b6273da023b86a6242c.zip |
Get a unified system clock setup within the RootDesktopObject.
This can be used for any number of display clocks as needed without extra overhead
-rw-r--r-- | src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp | 29 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h | 8 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp index 77dd2d79..0585ae2c 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp @@ -16,6 +16,8 @@ RootDesktopObject::RootDesktopObject(QObject *parent) : QObject(parent){ last_window_up = 0; updateScreens(); //make sure the internal list is updated right away connect(this, SIGNAL(changePanels(QStringList)), this, SLOT(setPanels(QStringList)) ); + currentTimeTimer = new QTimer(this); + connect(currentTimeTimer, SIGNAL(timeout()), this, SLOT(updateCurrentTime()) ); } RootDesktopObject::~RootDesktopObject(){ @@ -105,6 +107,10 @@ bool RootDesktopObject::hasTrayWindows(){ return !tray_window_objects.isEmpty(); } +QString RootDesktopObject::currentTime(){ + return currentTimeString; +} + OSInterface* RootDesktopObject::os_interface(){ return OSInterface::instance(); } @@ -175,6 +181,18 @@ void RootDesktopObject::setTrayWindows(QList<NativeWindowObject*> list){ mousePositionChanged(true); } +void RootDesktopObject::updateCurrentTimeFormat(QString fmt){ + currentTimeFormat = fmt.simplified(); + if(currentTimeTimer->isActive()){ currentTimeTimer->stop(); } + //sanitize the time format as needed + if(fmt.contains("z")){ currentTimeFormat.replace("z",""); } //do not allow millisecond updates - too fast for the desktop + //Adjust the refresh time for the clock based on the smallest unit requested + if(fmt.contains("s")){ currentTimeTimer->setInterval(500); } //1/2 second pings for 1-second displays + else if(fmt.contains("m") || currentTimeFormat.isEmpty()){ currentTimeTimer->setInterval(5000); } //5 second pings for 1-minute displays + else{ currentTimeTimer->setInterval(60000); } //1 minute pings for 1-hour displays + updateCurrentTime(); //refresh the currently-available time + currentTimeTimer->start();//start the update timer +} void RootDesktopObject::logout(){ //Emit the logout signal in a few ms (let the display close/sync first) @@ -246,3 +264,14 @@ QString RootDesktopObject::CurrentWallpaper(QString screen){ // === PRIVATE === + +// === PRIVATE SLOTS === +void RootDesktopObject::updateCurrentTime(){ + QString tmp; + if(currentTimeFormat.isEmpty()){ tmp = QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate); } + else{ tmp = QDateTime::currentDateTime().toString(currentTimeFormat); } + if(tmp!=currentTimeString){ //prevent sending signals to update the interface if nothing changed + currentTimeString = tmp; + emit currentTimeChanged(); + } +} diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h index 7914f3f6..e7ce50e0 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h @@ -20,6 +20,7 @@ class RootDesktopObject : public QObject{ Q_PROPERTY( QStringList windows READ windows NOTIFY windowsChanged) Q_PROPERTY( QStringList trayWindows READ trayWindows NOTIFY trayWindowsChanged) Q_PROPERTY( bool hasTrayWindows READ hasTrayWindows NOTIFY trayWindowsChanged) + Q_PROPERTY( QString currentTime READ currentTime NOTIFY currentTimeChanged); public: //main contructor/destructor @@ -41,6 +42,7 @@ public: Q_INVOKABLE QStringList trayWindows(); Q_INVOKABLE NativeWindowObject* trayWindow(QString id); Q_INVOKABLE bool hasTrayWindows(); + Q_INVOKABLE QString currentTime(); //QML Globals Access Q_INVOKABLE OSInterface* os_interface(); @@ -57,6 +59,8 @@ private: QList<NativeWindowObject*> window_objects; QList<NativeWindowObject*> tray_window_objects; QPointer<NativeWindowObject> last_window_up; + QTimer *currentTimeTimer; + QString currentTimeFormat, currentTimeString; public slots: void updateScreens(); //rescan/update screen objects @@ -70,13 +74,17 @@ public slots: void setWindows(QList<NativeWindowObject*> list); void setTrayWindows(QList<NativeWindowObject*> list); + void updateCurrentTimeFormat(QString); + private slots: + void updateCurrentTime(); signals: void screensChanged(); void panelsChanged(); void windowsChanged(); void trayWindowsChanged(); + void currentTimeChanged(); void startLogout(); void mouseMoved(); |