diff options
author | Ken Moore <ken@ixsystems.com> | 2018-01-30 09:05:21 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2018-01-30 09:05:21 -0500 |
commit | 019c1b82daa8307db4ee4341bd71246d1f8a03cc (patch) | |
tree | 546e06b536b7bcda6a0f8fcd84a05217dd149c30 /src-qt5/src-cpp | |
parent | A few couple other attempts at the layering issue. (diff) | |
download | lumina-019c1b82daa8307db4ee4341bd71246d1f8a03cc.tar.gz lumina-019c1b82daa8307db4ee4341bd71246d1f8a03cc.tar.bz2 lumina-019c1b82daa8307db4ee4341bd71246d1f8a03cc.zip |
Get the OSInterface framework up and running (template OS only at the moment)
Diffstat (limited to 'src-qt5/src-cpp')
-rw-r--r-- | src-qt5/src-cpp/framework-OSInterface-template.cpp | 87 | ||||
-rw-r--r-- | src-qt5/src-cpp/framework-OSInterface.h | 71 | ||||
-rw-r--r-- | src-qt5/src-cpp/framework-OSInterface_private.cpp | 146 |
3 files changed, 249 insertions, 55 deletions
diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp index 7921511f..6d1a7e74 100644 --- a/src-qt5/src-cpp/framework-OSInterface-template.cpp +++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp @@ -7,71 +7,70 @@ #include <framework-OSInterface.h> // = Battery = -bool OSInterface::batteryAvailable(){ return false; } -float OSInterface::batteryCharge(){ return -1; } -bool OSInterface::batteryCharging(){ return false; } -double OSInterface::batterySecondsLeft(){ return -1; } +bool OSInterface::OS_batteryAvailable(){ return false; } +float OSInterface::OS_batteryCharge(){ return -1; } +bool OSInterface::OS_batteryCharging(){ return false; } +double OSInterface::OS_batterySecondsLeft(){ return -1; } // = Volume = -bool OSInterface::volumeSupported(){ return false; } -int OSInterface::volume(){ return -1; } -void OSInterface::setVolume(int){} +bool OSInterface::OS_volumeSupported(){ return false; } +int OSInterface::OS_volume(){ return -1; } +void OSInterface::OS_setVolume(int){} // = Network Information = -QString OSInterface::networkTypeFromDeviceName(QString name){ +QString OSInterface::OS_networkTypeFromDeviceName(QString name){ //Return options: wifi, wired, cell, cell-2G, cell-3G, cell-4G return ""; } -float OSInterface::networkStrength(){ - //QString device = INFO.value("netaccess/devicename"); - return -1; //percentage. ("wired" type should always be 100%) +float OSInterface::OS_networkStrengthFromDeviceName(QString name){ + //NOTE: This will only run for non-wired devices (wifi, cell[-*]) + return -1; //percentage } // = 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 +QStringList OSInterface::OS_mediaDirectories(){ return QStringList() << "/media"; } //directory where XDG shortcuts are placed for interacting with media (local/remote) // = 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; } -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? -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 +bool OSInterface::OS_updatesSupported(){ return false; } +bool OSInterface::OS_updatesAvailable(){ return false; } +QString OSInterface::OS_updateDetails(){ return QString(); } //Information about any available updates +bool OSInterface::OS_updatesRunning(){ return false; } +QString OSInterface::OS_updateLog(){ return QString(); } //Information about any currently-running update +bool OSInterface::OS_updatesFinished(){ return false; } +QString OSInterface::OS_updateResults(){ return QString(); } //Information about any finished update +void OSInterface::OS_startUpdates(){} +bool OSInterface::OS_updateOnlyOnReboot(){ return false; } //Should the startUpdates function be called only when rebooting the system? +bool OSInterface::OS_updateCausesReboot(){ return false; } +QDateTime OSInterface::OS_lastUpdate(){ return QDateTime(); } //The date/time of the previous updates +QString OSInterface::OS_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(){} +bool OSInterface::OS_canReboot(){ return false; } +void OSInterface::OS_startReboot(){} +bool OSInterface::OS_canShutdown(){ return false; } +void OSInterface::OS_startShutdown(){} +bool OSInterface::OS_canSuspend(){ return false; } +void OSInterface::OS_startSuspend(){} // = Screen Brightness = -bool OSInterface::brightnessSupported(){ return false; } -int OSInterface::brightness(){ return -1; } //percentage: 0-100 with -1 for errors -void OSInterface::setBrightness(int){} +bool OSInterface::OS_brightnessSupported(){ return false; } +int OSInterface::OS_brightness(){ return -1; } //percentage: 0-100 with -1 for errors +void OSInterface::OS_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::OS_cpuSupported(){ return false; } +QList<int> OSInterface::OS_cpuPercentage(){ return QList<int>(); } // (one per CPU) percentage: 0-100 with empty list for errors +QStringList OSInterface::OS_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::OS_memorySupported(){ return false; } +int OSInterface::OS_memoryUsedPercentage(){ return -1; } //percentage: 0-100 with -1 for errors +QString OSInterface::OS_memoryTotal(){ return QString(); } //human-readable form - does not tend to change within a session +QStringList OSInterface::OS_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 +bool OSInterface::OS_diskSupported(){ return false; } +int OSInterface::OS_fileSystemPercentage(QString dir){ return -1; } //percentage of capacity used: 0-100 with -1 for errors +QString OSInterface::OS_fileSystemCapacity(QString dir){ return QString(); } //human-readable form - total capacity // = OS-Specific Utilities = QString OSInterface::controlPanelShortcut(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop") diff --git a/src-qt5/src-cpp/framework-OSInterface.h b/src-qt5/src-cpp/framework-OSInterface.h index 88f4d10a..95b1b441 100644 --- a/src-qt5/src-cpp/framework-OSInterface.h +++ b/src-qt5/src-cpp/framework-OSInterface.h @@ -39,9 +39,10 @@ class OSInterface : public QObject{ Q_OBJECT // == QML ACCESSIBLE PROPERTIES == //Battery - Q_PROPERTY( float batteryCharge READ batteryCharge NOTIFY batteryChargeChanged) - Q_PROPERTY( bool batteryCharging READ batteryCharging NOTIFY batteryChargingChanged) - Q_PROPERTY( double batterySecondsLeft READ batterySecondsLeft NOTIFY batterySecondsLeftChanged) + Q_PROPERTY( float batteryCharge READ batteryCharge NOTIFY batteryChanged) + Q_PROPERTY( bool batteryCharging READ batteryCharging NOTIFY batteryChanged) + Q_PROPERTY( QString batteryRemaining READ batteryRemaining NOTIFY batteryChanged) + Q_PROPERTY( QString batteryIcon READ batteryIcon NOTIFY batteryChanged) //Volume Q_PROPERTY( int volume READ volume WRITE setVolume NOTIFY volumeChanged) //Network @@ -76,7 +77,8 @@ public: Q_INVOKABLE bool batteryAvailable(); Q_INVOKABLE float batteryCharge(); Q_INVOKABLE bool batteryCharging(); - Q_INVOKABLE double batterySecondsLeft(); + Q_INVOKABLE QString batteryRemaining(); + Q_INVOKABLE QString batteryIcon(); // = Volume = Q_INVOKABLE bool volumeSupported(); @@ -86,8 +88,8 @@ public: // = Network Information = Q_INVOKABLE bool networkAvailable(); Q_INVOKABLE QString networkType(); //"wifi", "wired", "cell", "cell-2G", "cell-3G", "cell-4G" - Q_INVOKABLE QString networkTypeFromDeviceName(QString name); //wifi, wired, cell, cell-2G, cell-3G, cell-4G Q_INVOKABLE float networkStrength(); //percentage. ("wired" type should always be 100%) + Q_INVOKABLE QString networkIcon(); Q_INVOKABLE QString networkHostname(); Q_INVOKABLE QHostAddress networkAddress(); @@ -149,7 +151,56 @@ public: Q_INVOKABLE QString appStoreShortcut(); //relative *.desktop shortcut name (Example: "some_utility.desktop") - // QML-Accessible properties/functions + // = DIRECT OS INTERACTIONS = (properties above are cached/gated) + // = Battery = + bool OS_batteryAvailable(); + float OS_batteryCharge(); + bool OS_batteryCharging(); + double OS_batterySecondsLeft(); + // = Volume = + bool OS_volumeSupported(); + int OS_volume(); + void OS_setVolume(int); + // = Network Information = + QString OS_networkTypeFromDeviceName(QString name); + float OS_networkStrengthFromDeviceName(QString name); + // = Media Shortcuts = + QStringList OS_mediaDirectories(); + // = Updates = + bool OS_updatesSupported(); + bool OS_updatesAvailable(); + QString OS_updateDetails(); + bool OS_updatesRunning(); + QString OS_updateLog(); + bool OS_updatesFinished(); + QString OS_updateResults(); + void OS_startUpdates(); + bool OS_updateOnlyOnReboot(); + bool OS_updateCausesReboot(); + QDateTime OS_lastUpdate(); + QString OS_lastUpdateResults(); + // = System Power = + bool OS_canReboot(); + void OS_startReboot(); + bool OS_canShutdown(); + void OS_startShutdown(); + bool OS_canSuspend(); + void OS_startSuspend(); + // = Screen Brightness = + bool OS_brightnessSupported(); + int OS_brightness(); + void OS_setBrightness(int); + // = System Status Monitoring + bool OS_cpuSupported(); + QList<int> OS_cpuPercentage(); + QStringList OS_cpuTemperatures(); + bool OS_memorySupported(); + int OS_memoryUsedPercentage(); + QString OS_memoryTotal(); + QStringList OS_diskIO(); + bool OS_diskSupported(); + int OS_fileSystemPercentage(QString dir); + QString OS_fileSystemCapacity(QString dir); private slots: // ================ @@ -176,9 +227,7 @@ private slots: void DiskTimerUpdate(); signals: - void batteryChargeChanged(); - void batteryChargingChanged(); - void batterySecondsLeftChanged(); + void batteryChanged(); void volumeChanged(); void networkStatusChanged(); void mediaShortcutsChanged(); @@ -186,6 +235,10 @@ signals: void powerAvailableChanged(); void brightnessChanged(); + //Internal alert signals + void BatteryFullAlert(); + void BatteryEmptyAlert(); + private: //Internal persistant data storage, OS-specific usage implementation QHash< QString, QVariant> INFO; diff --git a/src-qt5/src-cpp/framework-OSInterface_private.cpp b/src-qt5/src-cpp/framework-OSInterface_private.cpp index 66ac7d8e..3e623de5 100644 --- a/src-qt5/src-cpp/framework-OSInterface_private.cpp +++ b/src-qt5/src-cpp/framework-OSInterface_private.cpp @@ -181,6 +181,16 @@ QString OSInterface::networkType(){ return ""; } +float OSInterface::networkStrength(){ + if(INFO.contains("netaccess/strength")){ return INFO.value("netaccess/strength").toFloat(); } //percentage + return -1; +} + +QString OSInterface::networkIcon(){ + if(INFO.contains("netaccess/icon")){ return INFO.value("netaccess/icon").toString(); } + return ""; +} + QString OSInterface::networkHostname(){ return QHostInfo::localHostName(); } @@ -208,9 +218,13 @@ void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility s case QNetworkConfiguration::Bearer2G: type="cell-2G"; break; case QNetworkConfiguration::Bearer3G: type="cell-3G"; break; case QNetworkConfiguration::Bearer4G: type="cell-4G"; break; - default: type=networkTypeFromDeviceName(active.name()); //could not be auto-determined - run the OS-specific routine + default: type=OS_networkTypeFromDeviceName(active.name()); //could not be auto-determined - run the OS-specific routine } INFO.insert("netaccess/type", type); + float strength = 100; + if(type!="wired"){ strength = OS_networkStrengthFromDeviceName(active.name()); } + INFO.insert("netaccess/strength", strength); + //qDebug() << "Detected Device Status:" << active.identifier() << type << stat; QNetworkInterface iface = QNetworkInterface::interfaceFromName(active.name()); //qDebug() << " - Configuration: Name:" << active.name() << active.bearerTypeName() << active.identifier(); @@ -224,6 +238,33 @@ void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility s //qDebug() << " - IP Address:" << address; //qDebug() << " - Hostname:" << networkHostname(); INFO.insert("netaccess/address", address.join(", ")); + + //Figure out the icon used for this type/strnegth + QString icon; + if(type.startsWith("cell")){ + if(address.isEmpty()){ icon = "network-cell-off"; } + else if(strength>80){ icon = "network-cell-connected-100"; } + else if(strength>60){ icon = "network-cell-connected-75"; } + else if(strength>40){ icon = "network-cell-connected-50"; } + else if(strength>10){ icon = "network-cell-connected-25"; } + else if(strength >=0){ icon = "network-cell-connected-00"; } + else{ icon = "network-cell"; } //unknown strength - just use generic icon so we at least get off/on visibility + }else if(type=="wifi"){ + if(address.isEmpty()){ icon = "network-wireless-off"; } + else if(strength>80){ icon = "network-wireless-100"; } + else if(strength>60){ icon = "network-wireless-75"; } + else if(strength>40){ icon = "network-wireless-50"; } + else if(strength>10){ icon = "network-wireless-25"; } + else if(strength >=0){ icon = "network-wireless-00"; } + else{ icon = "network-wireless"; } //unknown strength - just use generic icon so we at least get off/on visibility + }else if(type=="wired"){ + if(strength==100 && !address.isEmpty()){ icon = "network-wired-connected"; } + else if(strength==100){ icon = "network-wired-pending"; } + else{ icon = "network-wired-disconnected"; } + }else{ + icon = "network-workgroup"; //failover to a generic "network" icon + } + INFO.insert("netaccess/icon",icon); emit networkStatusChanged(); } @@ -313,7 +354,39 @@ void OSInterface::setupDiskMonitor(int update_ms, int delay_ms){ // 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){ - + float charge = OS_batteryCharge(); + bool charging = OS_batteryCharging(); + double secs = OS_batterySecondsLeft(); + //Check for any alert generations + if(charging && hash->value("battery/percent",100).toFloat() <= 99 && charge>99){ os->emit BatteryFullAlert(); } + else if(!charging && hash->value("battery/percent", 50).toFloat()>10 && charge<10){ os->emit BatteryEmptyAlert(); } + + hash->insert("battery/percent",charge); + hash->insert("battery/charging",charging); + //Convert the seconds to human-readable + QString time; + hash->insert("battery/time", time); + //Determine the icon which should be used for this status + QString icon; + if(charging){ + if(charge>=99){ icon="battery-charging"; } + else if(charge>80){ icon="battery-charging-80"; } + else if(charge >60){ icon="battery-charging-60"; } + else if(charge >30){ icon="battery-charging-40"; } + else if(charge >0){ icon="battery-charging-20"; } + else{ icon="battery-unknown"; } + }else{ + if(charge>90){ icon="battery"; } + else if(charge>80){ icon="battery-80"; } + else if(charge >60){ icon="battery-60"; } + else if(charge >30){ icon="battery-40"; } + else if(charge >10){ icon="battery-20"; } + else if(charge >0){ icon="battery-alert"; } + else{ icon="battery-unknown"; } + } + hash->insert("battery/icon",icon); + //Now emit the change signal and restart the timer + os->emit batteryChanged(); QTimer::singleShot(0, timer, SLOT(start())); } @@ -346,3 +419,72 @@ void OSInterface::syncDiskInfo(OSInterface *os, QHash<QString, QVariant> *hash, QTimer::singleShot(0, timer, SLOT(start())); } + +// = Battery = +bool OSInterface::batteryAvailable(){ return OS_batteryAvailable(); } +float OSInterface::batteryCharge(){ + if(INFO.contains("battery/percent")){ return INFO.value("battery/percent").toFloat(); } + return -1; +} +bool OSInterface::batteryCharging(){ + if(INFO.contains("battery/charging")){ return INFO.value("battery/charging").toBool(); } + return false; +} +QString OSInterface::batteryRemaining(){ + if(INFO.contains("battery/time")){ return INFO.value("battery/time").toString(); } + return ""; +} +QString OSInterface::batteryIcon(){ + if(INFO.contains("battery/icon")){ return INFO.value("battery/icon").toString(); } + return ""; +} + +// = Volume = +bool OSInterface::volumeSupported(){ return OS_volumeSupported(); } +int OSInterface::volume(){ return -1; } +void OSInterface::setVolume(int){} + +// = Media = +QStringList OSInterface::mediaDirectories(){ return OS_mediaDirectories(); } +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; } +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? +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 + +// = 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 = +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 |