aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp29
-rw-r--r--src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h8
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();
bgstack15