aboutsummaryrefslogtreecommitdiff
path: root/src-qt5
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5')
-rw-r--r--src-qt5/src-cpp/framework-OSInterface-template.cpp29
-rw-r--r--src-qt5/src-cpp/framework-OSInterface.h56
-rw-r--r--src-qt5/src-cpp/framework-OSInterface_private.cpp153
3 files changed, 204 insertions, 34 deletions
diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp
index 7655acb3..7921511f 100644
--- a/src-qt5/src-cpp/framework-OSInterface-template.cpp
+++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp
@@ -5,24 +5,6 @@
// See the LICENSE file for full details
//===========================================
#include <framework-OSInterface.h>
-#include <QNetworkConfiguration>
-#include <QNetworkInterface>
-
-//Start/stop interface watchers/notifications
-void OSInterface::start(){
- setupMediaWatcher(); //will create/connect the filesystem watcher automatically
- setupNetworkManager(); //will create/connect the network monitor automatically
-
-}
-
-void OSInterface::stop(){
- if(isRunning()){
- watcher->deleteLater();
- watcher = 0;
- }
-}
-
-bool OSInterface::isRunning(){ return (watcher!=0); } //status of the object - whether it has been started yet
// = Battery =
bool OSInterface::batteryAvailable(){ return false; }
@@ -31,7 +13,7 @@ bool OSInterface::batteryCharging(){ return false; }
double OSInterface::batterySecondsLeft(){ return -1; }
// = Volume =
-bool OSInterface::volumeAvailable(){ return false; }
+bool OSInterface::volumeSupported(){ return false; }
int OSInterface::volume(){ return -1; }
void OSInterface::setVolume(int){}
@@ -51,6 +33,7 @@ QStringList OSInterface::mediaDirectories(){ return QStringList() << "/media"; }
QStringList OSInterface::mediaShortcuts(){ return autoHandledMediaFiles(); } //List of currently-available XDG shortcut file paths
// = Updates =
+bool OSInterface::updatesSupported(){ return false; }
bool OSInterface::updatesAvailable(){ return false; }
QString OSInterface::updateDetails(){ return QString(); } //Information about any available updates
bool OSInterface::updatesRunning(){ return false; }
@@ -59,6 +42,7 @@ bool OSInterface::updatesFinished(){ return false; }
QString OSInterface::updateResults(){ return QString(); } //Information about any finished update
void OSInterface::startUpdates(){}
bool OSInterface::updateOnlyOnReboot(){ return false; } //Should the startUpdates function be called only when rebooting the system?
+bool OSInterface::updateCausesReboot(){ return false; }
QDateTime OSInterface::lastUpdate(){ return QDateTime(); } //The date/time of the previous updates
QString OSInterface::lastUpdateResults(){ return QString(); } //Information about the previously-finished update
@@ -71,15 +55,21 @@ bool OSInterface::canSuspend(){ return false; }
void OSInterface::startSuspend(){}
// = Screen Brightness =
+bool OSInterface::brightnessSupported(){ return false; }
int OSInterface::brightness(){ return -1; } //percentage: 0-100 with -1 for errors
void OSInterface::setBrightness(int){}
// = System Status Monitoring
+bool OSInterface::cpuSupported(){ return false; }
QList<int> OSInterface::cpuPercentage(){ return QList<int>(); } // (one per CPU) percentage: 0-100 with empty list for errors
QStringList OSInterface::cpuTemperatures(){ return QStringList(); } // (one per CPU) Temperature of CPU ("50C" for example)
+
+bool OSInterface::memorySupported(){ return false; }
int OSInterface::memoryUsedPercentage(){ return -1; } //percentage: 0-100 with -1 for errors
QString OSInterface::memoryTotal(){ return QString(); } //human-readable form - does not tend to change within a session
QStringList OSInterface::diskIO(){ return QStringList(); } //Returns list of current read/write stats for each device
+
+bool OSInterface::diskSupported(){ return false; }
int OSInterface::fileSystemPercentage(QString dir){ return -1; } //percentage of capacity used: 0-100 with -1 for errors
QString OSInterface::fileSystemCapacity(QString dir){ return QString(); } //human-readable form - total capacity
@@ -101,4 +91,3 @@ void OSInterface::iodeviceAboutToClose(){}
void OSInterface::netRequestFinished(QNetworkReply*){}
void OSInterface::netSslErrors(QNetworkReply*, const QList<QSslError>&){}
-void OSInterface::timerUpdate(){}
diff --git a/src-qt5/src-cpp/framework-OSInterface.h b/src-qt5/src-cpp/framework-OSInterface.h
index 3d64483d..f8345bac 100644
--- a/src-qt5/src-cpp/framework-OSInterface.h
+++ b/src-qt5/src-cpp/framework-OSInterface.h
@@ -77,10 +77,12 @@ public:
Q_INVOKABLE float batteryCharge();
Q_INVOKABLE bool batteryCharging();
Q_INVOKABLE double batterySecondsLeft();
+
// = Volume =
- Q_INVOKABLE bool volumeAvailable();
+ Q_INVOKABLE bool volumeSupported();
Q_INVOKABLE int volume();
Q_INVOKABLE void setVolume(int);
+
// = Network Information =
Q_INVOKABLE bool networkAvailable();
Q_INVOKABLE QString networkType(); //"wifi", "wired", "cell", "cell-2G", "cell-3G", "cell-4G"
@@ -88,6 +90,7 @@ public:
Q_INVOKABLE float networkStrength(); //percentage. ("wired" type should always be 100%)
Q_INVOKABLE QString networkHostname();
Q_INVOKABLE QHostAddress networkAddress();
+
// = Network Modification =
Q_INVOKABLE bool hasNetworkManager();
Q_INVOKABLE QString networkManagerUtility(); //binary name or *.desktop filename (if registered on the system)
@@ -95,7 +98,9 @@ public:
// = Media Shortcuts =
Q_INVOKABLE QStringList mediaDirectories(); //directory where XDG shortcuts are placed for interacting with media (local/remote)
Q_INVOKABLE QStringList mediaShortcuts(); //List of currently-available XDG shortcut file paths
+
// = Updates =
+ Q_INVOKABLE bool updatesSupported(); //is thie subsystem supported for the OS?
Q_INVOKABLE bool updatesAvailable();
Q_INVOKABLE QString updateDetails(); //Information about any available updates
Q_INVOKABLE bool updatesRunning();
@@ -104,8 +109,10 @@ public:
Q_INVOKABLE QString updateResults(); //Information about any finished update
Q_INVOKABLE void startUpdates();
Q_INVOKABLE bool updateOnlyOnReboot(); //Should the startUpdates function be called only when rebooting the system?
+ Q_INVOKABLE bool updateCausesReboot(); //Does the update power-cycle the system?
Q_INVOKABLE QDateTime lastUpdate(); //The date/time of the previous updates
Q_INVOKABLE QString lastUpdateResults(); //Information about the previously-finished update
+
// = System Power =
Q_INVOKABLE bool canReboot();
Q_INVOKABLE void startReboot();
@@ -113,17 +120,26 @@ public:
Q_INVOKABLE void startShutdown();
Q_INVOKABLE bool canSuspend();
Q_INVOKABLE void startSuspend();
+
// = Screen Brightness =
+ Q_INVOKABLE bool brightnessSupported(); //is this subsystem available for the OS?
Q_INVOKABLE int brightness(); //percentage: 0-100 with -1 for errors
Q_INVOKABLE void setBrightness(int);
+
// = System Status Monitoring
+ Q_INVOKABLE bool cpuSupported(); //is this subsystem available for the OS?
Q_INVOKABLE QList<int> cpuPercentage(); // (one per CPU) percentage: 0-100 with -1 for errors
Q_INVOKABLE QStringList cpuTemperatures(); // (one per CPU) Temperature of CPU ("50C" for example)
+
+ Q_INVOKABLE bool memorySupported(); //is this subsystem available for the OS?
Q_INVOKABLE int memoryUsedPercentage(); //percentage: 0-100 with -1 for errors
Q_INVOKABLE QString memoryTotal(); //human-readable form - does not tend to change within a session
Q_INVOKABLE QStringList diskIO(); //Returns list of current read/write stats for each device
+
+ Q_INVOKABLE bool diskSupported(); //is this subsystem available for the OS?
Q_INVOKABLE int fileSystemPercentage(QString dir); //percentage of capacity used: 0-100 with -1 for errors
Q_INVOKABLE QString fileSystemCapacity(QString dir); //human-readable form - total capacity
+
// = OS-Specific Utilities =
Q_INVOKABLE bool hasControlPanel();
Q_INVOKABLE QString controlPanelShortcut(); //relative *.desktop shortcut name (Example: "some_utility.desktop")
@@ -132,6 +148,9 @@ public:
Q_INVOKABLE bool hasAppStore();
Q_INVOKABLE QString appStoreShortcut(); //relative *.desktop shortcut name (Example: "some_utility.desktop")
+
+ // QML-Accessible properties/functions
+
private slots:
// ================
// SEMI-VIRTUAL FUNCTIONS - NEED TO BE DEFINED IN THE OS-SPECIFIC FILES
@@ -148,7 +167,13 @@ private slots:
void netRequestFinished(QNetworkReply*);
void netSslErrors(QNetworkReply*, const QList<QSslError>&);
//Timer slots
- void timerUpdate();
+ void BatteryTimerUpdate();
+ void UpdateTimerUpdate();
+ void BrightnessTimerUpdate();
+ void VolumeTimerUpdate();
+ void CpuTimerUpdate();
+ void MemTimerUpdate();
+ void DiskTimerUpdate();
signals:
void batteryChargeChanged();
@@ -164,6 +189,7 @@ signals:
private:
//Internal persistant data storage, OS-specific usage implementation
QHash< QString, QVariant> INFO;
+ bool _started;
// ============
// Internal possibilities for watching the system (OS-Specific usage/implementation)
@@ -175,14 +201,13 @@ private:
//Network Access Manager (check network connectivity, etc)
QNetworkAccessManager *netman;
//Timer for regular probes/updates
- QTimer *timer;
+ QTimer *batteryTimer, *updateTimer, *brightnessTimer, *volumeTimer, *cpuTimer, *memTimer, *diskTimer;
// Internal implifications for connecting the various watcher objects to their respective slots
// (OS-agnostic - defined in the "OSInterface_private.cpp" file)
void connectWatcher(); //setup the internal connections *only*
void connectIodevice(); //setup the internal connections *only*
void connectNetman(); //setup the internal connections *only*
- void connectTimer(); //setup the internal connections *only*
//Internal simplification routines
bool verifyAppOrBin(QString chk);
@@ -194,11 +219,24 @@ private:
// Qt-based NetworkAccessManager usage
void setupNetworkManager();
- //void setupBatteryMonitor(int update_ms);
- //void setupUpdateMonitor(int update_ms);
- //void setupBrightnessMonitor(int update_ms);
- //void setupVolumeMonitor(int update_ms);
- //void
+
+ // Timer-based monitors
+ void setupBatteryMonitor(int update_ms, int delay_ms);
+ void setupUpdateMonitor(int update_ms, int delay_ms);
+ void setupBrightnessMonitor(int update_ms, int delay_ms);
+ void setupVolumeMonitor(int update_ms, int delay_ms);
+ void setupCpuMonitor(int update_ms, int delay_ms);
+ void setupMemoryMonitor(int update_ms, int delay_ms);
+ void setupDiskMonitor(int update_ms, int delay_ms);
+
+ // Timer-based monitor update routines (NOTE: these are all run in a separate thread!!)
+ void syncBatteryInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer);
+ void syncUpdateInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer);
+ void syncBrightnessInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer);
+ void syncVolumeInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer);
+ void syncCpuInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer);
+ void syncMemoryInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer);
+ void syncDiskInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer);
public:
OSInterface(QObject *parent = 0);
diff --git a/src-qt5/src-cpp/framework-OSInterface_private.cpp b/src-qt5/src-cpp/framework-OSInterface_private.cpp
index 709c54d4..d633fe9a 100644
--- a/src-qt5/src-cpp/framework-OSInterface_private.cpp
+++ b/src-qt5/src-cpp/framework-OSInterface_private.cpp
@@ -7,6 +7,7 @@
// Internal, OS-agnostic functionality for managing the object itself
//===========================================
#include <framework-OSInterface.h>
+#include <QtConcurrent>
OSInterface::OSInterface(QObject *parent) : QObject(parent){
watcher = 0;
@@ -37,6 +38,33 @@ OSInterface* OSInterface::instance(){
return m_os_object;
}
+//Start/stop interface systems
+void OSInterface::start(){
+ if(!mediaDirectories().isEmpty()){ setupMediaWatcher(); }//will create/connect the filesystem watcher automatically
+ setupNetworkManager(); //will create/connect the network monitor automatically
+ if(batteryAvailable()){ setupBatteryMonitor(30000, 1); } //30 second updates, 1 ms init delay
+ if(brightnessSupported()){ setupBrightnessMonitor(60000, 1); } //1 minute updates, 1 ms init delay
+ if(volumeSupported()){ setupVolumeMonitor(60000, 2); } //1 minute updates, 2 ms init delay
+ if(updatesSupported()){ setupUpdateMonitor(12*60*60*1000, 5*60*1000); } //12-hour updates, 5 minute delay
+ if(cpuSupported()){ setupCpuMonitor(2000, 20); } //2 second updates, 20 ms init delay
+ if(memorySupported()){ setupMemoryMonitor(2000, 21); } //2 second updates, 21 ms init delay
+ if(diskSupported()){ setupDiskMonitor(60000, 25); } //1 minute updates, 25 ms init delay
+}
+
+void OSInterface::stop(){
+ if(watcher!=0){ watcher->deleteLater(); watcher=0; }
+ if(batteryTimer!=0){ batteryTimer->stop(); disconnect(batteryTimer); }
+ if(brightnessTimer!=0){ brightnessTimer->stop(); disconnect(brightnessTimer); }
+ if(volumeTimer!=0){ volumeTimer->stop(); disconnect(volumeTimer); }
+ if(updateTimer!=0){ updateTimer->stop(); disconnect(updateTimer); }
+ if(cpuTimer!=0){ cpuTimer->stop(); disconnect(cpuTimer); }
+ if(memTimer!=0){ memTimer->stop(); disconnect(memTimer); }
+ if(diskTimer!=0){ diskTimer->stop(); disconnect(diskTimer); }
+ if(netman!=0){ disconnect(netman); netman->deleteLater(); netman = 0; }
+}
+
+bool OSInterface::isRunning(){ return _started; } //status of the object - whether it has been started yet
+
void OSInterface::connectWatcher(){
if(watcher==0){ return; }
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherFileChanged(QString)) );
@@ -55,11 +83,6 @@ void OSInterface::connectNetman(){
connect(netman, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(netSslErrors(QNetworkReply*, const QList<QSslError>&)) );
}
-void OSInterface::connectTimer(){
- if(timer==0){ return; }
- connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()) );
-}
-
bool OSInterface::verifyAppOrBin(QString chk){
bool valid = !chk.isEmpty();
if(valid && chk.endsWith(".desktop")){
@@ -194,3 +217,123 @@ void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility s
INFO.insert("netaccess/address", address.join(", "));
emit networkStatusChanged();
}
+
+
+// ========================
+// TIMER-BASED MONITORS
+// ========================
+//Timer slots
+void OSInterface::BatteryTimerUpdate(){
+ QtConcurrent::run(this, &OSInterface::syncBatteryInfo, this, &INFO, batteryTimer);
+}
+
+void OSInterface::UpdateTimerUpdate(){
+ QtConcurrent::run(this, &OSInterface::syncUpdateInfo, this, &INFO, updateTimer);
+}
+
+void OSInterface::BrightnessTimerUpdate(){
+ QtConcurrent::run(this, &OSInterface::syncBrightnessInfo, this, &INFO, brightnessTimer);
+}
+
+void OSInterface::VolumeTimerUpdate(){
+ QtConcurrent::run(this, &OSInterface::syncVolumeInfo, this, &INFO, volumeTimer);
+}
+
+void OSInterface::CpuTimerUpdate(){
+ QtConcurrent::run(this, &OSInterface::syncCpuInfo, this, &INFO, cpuTimer);
+}
+
+void OSInterface::MemTimerUpdate(){
+ QtConcurrent::run(this, &OSInterface::syncMemoryInfo, this, &INFO, memTimer);
+}
+
+void OSInterface::DiskTimerUpdate(){
+ QtConcurrent::run(this, &OSInterface::syncDiskInfo, this, &INFO, diskTimer);
+}
+
+// Timer Setup functions
+void OSInterface::setupBatteryMonitor(int update_ms, int delay_ms){
+ batteryTimer = new QTimer(this);
+ batteryTimer->setSingleShot(true);
+ batteryTimer->setInterval(update_ms);
+ connect(batteryTimer, SIGNAL(timeout()), this, SLOT(BatteryTimerUpdate()) );
+ QTimer::singleShot(delay_ms, this, SLOT(BatteryTimerUpdate()) );
+}
+void OSInterface::setupUpdateMonitor(int update_ms, int delay_ms){
+ updateTimer = new QTimer(this);
+ updateTimer->setSingleShot(true);
+ updateTimer->setInterval(update_ms);
+ connect(updateTimer, SIGNAL(timeout()), this, SLOT(UpdateTimerUpdate()) );
+ QTimer::singleShot(delay_ms, this, SLOT(UpdateTimerUpdate()) );
+}
+void OSInterface::setupBrightnessMonitor(int update_ms, int delay_ms){
+ brightnessTimer = new QTimer(this);
+ brightnessTimer->setSingleShot(true);
+ brightnessTimer->setInterval(update_ms);
+ connect(brightnessTimer, SIGNAL(timeout()), this, SLOT(BrightnessTimerUpdate()) );
+ QTimer::singleShot(delay_ms, this, SLOT(BrightnessTimerUpdate()) );
+}
+void OSInterface::setupVolumeMonitor(int update_ms, int delay_ms){
+ volumeTimer = new QTimer(this);
+ volumeTimer->setSingleShot(true);
+ volumeTimer->setInterval(update_ms);
+ connect(volumeTimer, SIGNAL(timeout()), this, SLOT(VolumeTimerUpdate()) );
+ QTimer::singleShot(delay_ms, this, SLOT(VolumeTimerUpdate()) );
+}
+void OSInterface::setupCpuMonitor(int update_ms, int delay_ms){
+ cpuTimer = new QTimer(this);
+ cpuTimer->setSingleShot(true);
+ cpuTimer->setInterval(update_ms);
+ connect(cpuTimer, SIGNAL(timeout()), this, SLOT(CpuTimerUpdate()) );
+ QTimer::singleShot(delay_ms, this, SLOT(CpuTimerUpdate()) );
+}
+void OSInterface::setupMemoryMonitor(int update_ms, int delay_ms){
+ memTimer = new QTimer(this);
+ memTimer->setSingleShot(true);
+ memTimer->setInterval(update_ms);
+ connect(memTimer, SIGNAL(timeout()), this, SLOT(MemTimerUpdate()) );
+ QTimer::singleShot(delay_ms, this, SLOT(MemTimerUpdate()) );
+}
+void OSInterface::setupDiskMonitor(int update_ms, int delay_ms){
+ diskTimer = new QTimer(this);
+ diskTimer->setSingleShot(true);
+ diskTimer->setInterval(update_ms);
+ connect(diskTimer, SIGNAL(timeout()), this, SLOT(DiskTimerUpdate()) );
+ QTimer::singleShot(delay_ms, this, SLOT(DiskTimerUpdate()) );
+}
+
+// Timer-based monitor update routines (NOTE: these are all run in a separate thread!!)
+void OSInterface::syncBatteryInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer){
+
+ QTimer::singleShot(0, timer, SLOT(start()));
+}
+
+void OSInterface::syncUpdateInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer){
+
+ QTimer::singleShot(0, timer, SLOT(start()));
+}
+
+void OSInterface::syncBrightnessInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer){
+
+ QTimer::singleShot(0, timer, SLOT(start()));
+}
+
+void OSInterface::syncVolumeInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer){
+
+ QTimer::singleShot(0, timer, SLOT(start()));
+}
+
+void OSInterface::syncCpuInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer){
+
+ QTimer::singleShot(0, timer, SLOT(start()));
+}
+
+void OSInterface::syncMemoryInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer){
+
+ QTimer::singleShot(0, timer, SLOT(start()));
+}
+
+void OSInterface::syncDiskInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer *timer){
+
+ QTimer::singleShot(0, timer, SLOT(start()));
+}
bgstack15