diff options
Diffstat (limited to 'src-qt5/src-cpp/framework-OSInterface-template.cpp')
-rw-r--r-- | src-qt5/src-cpp/framework-OSInterface-template.cpp | 168 |
1 files changed, 58 insertions, 110 deletions
diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp index 972e02e0..c9c7775a 100644 --- a/src-qt5/src-cpp/framework-OSInterface-template.cpp +++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp @@ -4,147 +4,95 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== +// USEFUL INTERNAL FUNCTIONS: (See framework-OSInterface.h for all possibilities); +//---------------------------------------------- +// bool verifyAppOrBin(QString chk) : Returns true is the check is a valid binary or application (*.desktop) +// int runCmd(QString command, QStringList arguments) : return code of command is returned +// QStringList getCmdOutput(QString command, QStringList arguments) : returns standard output of command +//=========================================== #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(); -} - -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; } -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::volumeAvailable(){ return false; } -int OSInterface::volume(){ return -1; } -void OSInterface::setVolume(int){} +bool OSInterface::OS_volumeSupported(){ return false; } +int OSInterface::OS_volume(){ return -1; } +bool OSInterface::OS_setVolume(int){ return false;} // = Network Information = -bool OSInterface::networkAvailable(){ - if(INFO.contains("netaccess/available")){ return INFO.value("netaccess/available").toBool(); } - return false; -} - -QString OSInterface::networkType(){ - if(INFO.contains("netaccess/type")){ return INFO.value("netaccess/type").toString(); } //"wifi", "wired", or "cell" +QString OSInterface::OS_networkTypeFromDeviceName(QString name){ + //Return options: wifi, wired, cell, cell-2G, cell-3G, cell-4G return ""; } -float OSInterface::networkStrength(){ return -1; } //percentage. ("wired" type should always be 100%) - -QString OSInterface::networkHostname(){ - return QHostInfo::localHostName(); -} - -QHostAddress OSInterface::networkAddress(){ - QString addr; - if(INFO.contains("netaccess/address")){ addr = INFO.value("netaccess/address").toString(); } - return QHostAddress(addr); +float OSInterface::OS_networkStrengthFromDeviceName(QString name){ + //NOTE: This will only run for non-wired devices (wifi, cell[-*]) + return -1; //percentage } -// = 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 +QStringList OSInterface::OS_mediaDirectories(){ return QStringList() << "/media"; } //directory where XDG shortcuts are placed for interacting with media (local/remote) // = 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 +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 = -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 +bool OSInterface::OS_setBrightness(int){ return false; } // = 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 +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::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::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 = -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") +QString OSInterface::networkManagerUtility(){ return QString(); } //relative *.desktop shortcut name (Example: "some_utility.desktop") -//FileSystemWatcher slots -void OSInterface::watcherFileChanged(QString){} -void OSInterface::watcherDirChanged(QString dir){ - if(handleMediaDirChange(dir)){ return; } +//FileSystemWatcher slots (optional - re-implement only if needed/used by this OS) +void OSInterface::watcherFileChanged(QString){} //any additional parsing for files that are watched +void OSInterface::watcherDirChanged(QString dir){ //any additional parsing for watched directories + if(handleMediaDirChange(dir)){ return; } //auto-handled media directories } -//IO Device slots +//IO Device slots (optional - implement only if needed/used by this OS) void OSInterface::iodeviceReadyRead(){} void OSInterface::iodeviceAboutToClose(){} -//NetworkAccessManager slots -void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility stat){ - INFO.insert("netaccess/available", stat== QNetworkAccessManager::Accessible); - //Update all the other network status info at the same time - QNetworkConfiguration active = netman->activeConfiguration(); - //Type of connection - QString type; - switch(active.bearerTypeFamily()){ - case QNetworkConfiguration::BearerEthernet: type="wired"; break; - case QNetworkConfiguration::BearerWLAN: type="wifi"; break; - case QNetworkConfiguration::Bearer2G: type="cell-2G"; break; - case QNetworkConfiguration::Bearer3G: type="cell-3G"; break; - case QNetworkConfiguration::Bearer4G: type="cell-4G"; break; - default: type=""; - } - INFO.insert("netaccess/type", type); - qDebug() << "Detected Device Status:" << active.identifier() << type << stat; - QNetworkInterface iface = QNetworkInterface::interfaceFromName(active.name()); - qDebug() << " - Configuration: Name:" << active.name() << active.bearerTypeName() << active.identifier(); - qDebug() << " - Interface: MAC Address:" << iface.hardwareAddress() << "Name:" << iface.name() << iface.humanReadableName() << iface.isValid(); - QList<QNetworkAddressEntry> addressList = iface.addressEntries(); - QStringList address; - //NOTE: There are often 2 addresses, IPv4 and IPv6 - for(int i=0; i<addressList.length(); i++){ - address << addressList[i].ip().toString(); - } - qDebug() << " - IP Address:" << address; - qDebug() << " - Hostname:" << networkHostname(); - INFO.insert("netaccess/address", address.join(", ")); - emit networkStatusChanged(); -} - void OSInterface::netRequestFinished(QNetworkReply*){} void OSInterface::netSslErrors(QNetworkReply*, const QList<QSslError>&){} -void OSInterface::timerUpdate(){} |