aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorq5sys <jt@xsystems.com>2017-12-12 23:04:25 -0500
committerq5sys <jt@xsystems.com>2017-12-12 23:04:25 -0500
commitf586583f69a6b54f7d9e40459c3df22405011e78 (patch)
treef413f2955dae26c1e9b0cc6505a80dad2f1b63d6
parentmake portlint happy (diff)
parentMerge branch 'master' of github.com:trueos/lumina (diff)
downloadlumina-f586583f69a6b54f7d9e40459c3df22405011e78.tar.gz
lumina-f586583f69a6b54f7d9e40459c3df22405011e78.tar.bz2
lumina-f586583f69a6b54f7d9e40459c3df22405011e78.zip
Merge branch 'master' of http://github.com/trueos/lumina
-rw-r--r--src-qt5/src-cpp/framework-OSInterface-template.cpp158
-rw-r--r--src-qt5/src-cpp/framework-OSInterface.h34
-rw-r--r--src-qt5/src-cpp/framework-OSInterface_private.cpp36
3 files changed, 144 insertions, 84 deletions
diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp
index 96b01e60..bc995601 100644
--- a/src-qt5/src-cpp/framework-OSInterface-template.cpp
+++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp
@@ -6,95 +6,95 @@
//===========================================
#include <OSInterface.h>
-//===========
-// PUBLIC
-//===========
-
-//Simple functions used to determine if the current OS supports using this class, and what levels of support
-QList<OSInterface::Interface> OSInterface::supportedNotifications(){
- //Which interfaces provide change notifications
- return QList< OSInterface::Interface >();
-}
-
-QList<OSInterface::Interface> OSInterface::supportedStatus(){
- //Which interfaces are available for "status" requests
- return QList< OSInterface::Interface >();
-}
-
-QList<OSInterface::Interface> OSInterface::supportedModify(){
- //Which interfaces are available for "modify" requests
- return QList< OSInterface::Interface >();
-}
-
-//Start/stop interface watchers/notifications (each only called once per session)
+//Start/stop interface watchers/notifications
void OSInterface::start(){
- //nothing to do
+ setupMediaWatcher(); //will create/connect the filesystem watcher automatically
}
void OSInterface::stop(){
- //nothing to do
-}
-
-//Generic status update
-QList<QVariant> OSInterface::status(OSInterface::Interface){
- // ==== Interface status output lists ====
- // Battery: [ float (percent charge), bool (is Charging), double (seconds remaining) ];
- // Volume: [int (percent volume) ]
- // Devices: [ QStringList[ name, mountpoint, type (optional)] ] (List length depends on number of devices)
- // Network: [bool (network access available)]
- // PowerOff: [bool (can power off system)]
- // Reboot: [bool (can reboot system)]
- // Suspend: [bool (can suspend system)]
- // Updates: [bool (is updating), bool (reboot required)]
- // ==========
- return QList<QVariant>();
+ if(isRunning()){
+ watcher->deleteLater();
+ watcher = 0;
+ }
}
-//Individual Interface interactions
-bool OSInterface::modify(OSInterface::Interface, QList<QVariant>){ //returns: success/failure
- // ==== Interface modification argument lists ====
- // Battery: <NO MODIFICATION>
- // Volume: [int (set percent volume) ]
- // Devices: <NO MODIFICATION>
- // Network: <NO MODIFICATION>
- // PowerOff: [bool (skip updates - optional)]
- // Reboot: [bool (skip updates - optional)]
- // Suspend: [] (No input arguments)
- // Updates: <NO MODIFICATION>
- // ==========
- return false;
-}
+bool OSInterface::isRunning(){ return (watcher!=0); } //status of the object - whether it has been started yet
+
+// = Battery =
+bool OSInterface::batteryAvailable(){ return false; }
+float OSInterface::batteryCharge(){ return -1; }
+bool OSInterface::batteryCharging(){ return false; }
+double OSInterface::batterySecondsLeft(){ return -1; }
+
+// = Volume =
+bool OSInterface::volumeAvailable(){ return false; }
+int OSInterface::volume(){ return -1; }
+void OSInterface::setVolume(int){}
+
+// = Network Information =
+bool OSInterface::networkAvailable(){ return false; }
+QString OSInterface::networkType(){ return QString(); } //"wifi", "wired", or "cell"
+float OSInterface::networkStrength(){ return -1; } //percentage. ("wired" type should always be 100%)
+QString OSInterface::networkHostname(){ return QString(); }
+QHostAddress OSInterface::networkAddress(){ return QHostAddress(); }
+// = Network Modification =
+
+// = Media Shortcuts =
+QStringList OSInterface::mediaDirectories(){ return QStringList() << "/media"; } //directory where XDG shortcuts are placed for interacting with media (local/remote)
+QStringList OSInterface::mediaShortcuts(){ return autoHandledMediaFiles(); } //List of currently-available XDG shortcut file paths
+
+// = Updates =
+bool OSInterface::updatesAvailable(){ return false; }
+QString OSInterface::updateDetails(){ return QString(); } //Information about any available updates
+bool OSInterface::updatesRunning(){ return false; }
+QString OSInterface::updateLog(){ return QString(); } //Information about any currently-running update
+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?
+QDateTime OSInterface::lastUpdate(){ return QDateTime(); } //The date/time of the previous updates
+QString OSInterface::lastUpdateResults(){ return QString(); } //Information about the previously-finished update
+
+// = System Power =
+bool OSInterface::canReboot(){ return false; }
+void OSInterface::startReboot(){}
+bool OSInterface::canShutdown(){ return false; }
+void OSInterface::startShutdown(){}
+bool OSInterface::canSuspend(){ return false; }
+void OSInterface::startSuspend(){}
+
+// = Screen Brightness =
+int OSInterface::brightness(){ return -1; } //percentage: 0-100 with -1 for errors
+void OSInterface::setBrightness(int){}
+
+// = System Status Monitoring
+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)
+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
+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
+
+// = OS-Specific Utilities =
+bool OSInterface::hasControlPanel(){ return false; }
+QString OSInterface::controlPanelShortcut(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop")
+bool OSInterface::hasAudioMixer(){ return false; }
+QString OSInterface::audioMixerShortcut(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop")
+bool OSInterface::hasAppStore(){ return false; }
+QString OSInterface::appStoreShortcut(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop")
-//=================
-// PRIVATE SLOTS
-//=================
//FileSystemWatcher slots
-void OSInterface::watcherFileChanged(QString){
-
-}
-
-void OSInterface::watcherDirChanged(QString){
-
+void OSInterface::watcherFileChanged(QString){}
+void OSInterface::watcherDirChanged(QString dir){
+ if(handleMediaDirChange(dir)){ return; }
}
//IO Device slots
-void OSInterface::iodeviceReadyRead(){
-
-}
-
-void OSInterface::iodeviceAboutToClose(){
-
-}
+void OSInterface::iodeviceReadyRead(){}
+void OSInterface::iodeviceAboutToClose(){}
//NetworkAccessManager slots
-void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility){
-
-}
-
-void OSInterface::netRequestFinished(QNetworkReply*){
-
-}
-
-void OSInterface::netSslErrors(QNetworkReply*, const QList<QSslError>&){
-
-}
+void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility){}
+void OSInterface::netRequestFinished(QNetworkReply*){}
+void OSInterface::netSslErrors(QNetworkReply*, const QList<QSslError>&){}
diff --git a/src-qt5/src-cpp/framework-OSInterface.h b/src-qt5/src-cpp/framework-OSInterface.h
index bbf9e2c2..cccaddb4 100644
--- a/src-qt5/src-cpp/framework-OSInterface.h
+++ b/src-qt5/src-cpp/framework-OSInterface.h
@@ -49,6 +49,8 @@ class OSInterface : public QObject{
Q_PROPERTY( bool canReboot READ canReboot NOTIFY powerAvailableChanged)
Q_PROPERTY( bool canShutdown READ canShutdown NOTIFY powerAvailableChanged)
Q_PROPERTY( bool canSuspend READ canSuspend NOTIFY powerAvailableChanged)
+ //Brightness
+ Q_PROPERTY( int brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
public:
// ================
// SEMI-VIRTUAL FUNCTIONS - NEED TO BE DEFINED IN THE OS-SPECIFIC FILES
@@ -96,6 +98,24 @@ public:
Q_INVOKABLE void startShutdown();
Q_INVOKABLE bool canSuspend();
Q_INVOKABLE void startSuspend();
+ // = Screen Brightness =
+ Q_INVOKABLE int brightness(); //percentage: 0-100 with -1 for errors
+ Q_INVOKABLE void setBrightness(int);
+ // = System Status Monitoring
+ 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 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 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")
+ Q_INVOKABLE bool hasAudioMixer();
+ Q_INVOKABLE QString audioMixerShortcut(); //relative *.desktop shortcut name (Example: "some_utility.desktop")
+ Q_INVOKABLE bool hasAppStore();
+ Q_INVOKABLE QString appStoreShortcut(); //relative *.desktop shortcut name (Example: "some_utility.desktop")
private slots:
// ================
@@ -122,11 +142,11 @@ signals:
void mediaShortcutsChanged();
void updateStatusChanged();
void powerAvailableChanged();
+ void brightnessChanged();
private:
//Internal persistant data storage, OS-specific usage implementation
- enum Interface{ Battery, Volume, Media, Network, PowerOff, Reboot, Suspend, Updates };
- QHash< OSInterface::Interface, QList<QVariant> > INFO;
+ QHash< QString, QList<QVariant> > INFO;
// ============
// Internal possibilities for watching the system (OS-Specific usage/implementation)
@@ -140,9 +160,13 @@ private:
// Internal implifications for connecting the various watcher objects to their respective slots
// (OS-agnostic - defined in the "OSInterface_private.cpp" file)
- void connectWatcher();
- void connectIodevice();
- void connectNetman();
+ void connectWatcher(); //setup the internal connections *only*
+ void connectIodevice(); //setup the internal connections *only*
+ void connectNetman(); //setup the internal connections *only*
+ // External Media Management (if system uses *.desktop shortcuts only)
+ void setupMediaWatcher();
+ bool handleMediaDirChange(QString dir); //returns true if directory was handled
+ QStringList autoHandledMediaFiles();
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 bd2d17b5..23db9a6c 100644
--- a/src-qt5/src-cpp/framework-OSInterface_private.cpp
+++ b/src-qt5/src-cpp/framework-OSInterface_private.cpp
@@ -54,3 +54,39 @@ void OSInterface::connectNetman(){
connect(netman, SIGNAL(requestFinished(QNetworkReply*)), this, SLOT(netRequestFinished(QNetworkReply*)) );
connect(netman, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(netSslErrors(QNetworkReply*, const QList<QSslError>&)) );
}
+
+// External Media Management (if system uses *.desktop shortcuts)
+void OSInterface::setupMediaWatcher(){
+ //Create/connect the watcher if needed
+ if(watcher == 0){ watcher = new QFileSystemWatcher(); connectWatcher(); }
+ QStringList dirs = this->mediaDirectories();
+ if(dirs.isEmpty()){ return; } //nothing to do
+ //Make sure each directory is scanned **right now** (if it exists)
+ for(int i=0; i<dirs.length(); i++){
+ if(QFile::exists(dirs[i])){
+ handleMediaDirChange(dirs[i]);
+ }
+ }
+}
+
+bool OSInterface::handleMediaDirChange(QString dir){ //returns true if directory was handled
+ if( !this->mediaDirectories().contains(dir) ){ return false; } //not a media directory
+ QDir qdir(dir);
+ QStringList files = qdir.entryList(QStringList() << "*.desktop", QDir::Files, QDir::Name);
+ for(int i=0; i<files.length(); i++){ files[i] = qdir.absoluteFilePath(files[i]); }
+ QString key = "media_files/"+dir;
+ if(files.isEmpty() && INFO.contains(key)){ INFO.remove(key); emit mediaShortcutsChanged(); } //no files for this directory at the moment
+ else{ INFO.setValue("media_files/"+dir, files); emit mediaShortcutsChanged(); } //save these file paths for later
+ //Make sure the directory is still watched (sometimes the dir is removed/recreated on modification)
+ if(!watcher->directories().contains(dir)){ watcher->addPath(dir); }
+ return true;
+}
+
+QStringList OSInterface::autoHandledMediaFiles(){
+ QStringList files;
+ QStringList keys = INFO.keys().filter("media_files/");
+ for(int i=0; i<keys.length(); i++){
+ if(keys[i].startsWith("media_files/")){ files.append( INFO[keys[i]] ); }
+ }
+ return files;
+}
bgstack15