diff options
Diffstat (limited to 'src-qt5/src-cpp')
-rw-r--r-- | src-qt5/src-cpp/framework-OSInterface-template.cpp | 73 | ||||
-rw-r--r-- | src-qt5/src-cpp/framework-OSInterface.h | 21 | ||||
-rw-r--r-- | src-qt5/src-cpp/framework-OSInterface_private.cpp | 92 |
3 files changed, 120 insertions, 66 deletions
diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp index a1553857..7655acb3 100644 --- a/src-qt5/src-cpp/framework-OSInterface-template.cpp +++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp @@ -11,7 +11,8 @@ //Start/stop interface watchers/notifications void OSInterface::start(){ setupMediaWatcher(); //will create/connect the filesystem watcher automatically - setupNetworkManager(); + setupNetworkManager(); //will create/connect the network monitor automatically + } void OSInterface::stop(){ @@ -35,34 +36,16 @@ int OSInterface::volume(){ return -1; } void OSInterface::setVolume(int){} // = 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" - return ""; -} - QString OSInterface::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(); +float OSInterface::networkStrength(){ + //QString device = INFO.value("netaccess/devicename"); + return -1; //percentage. ("wired" type should always be 100%) } -QHostAddress OSInterface::networkAddress(){ - QString addr; - if(INFO.contains("netaccess/address")){ addr = INFO.value("netaccess/address").toString(); } - return QHostAddress(addr); -} -// = 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 @@ -101,55 +84,21 @@ int OSInterface::fileSystemPercentage(QString dir){ return -1; } //percentage of 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") +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=networkTypeFromDeviceName(active.name()); //could not be auto-determined - run the OS-specific routine - } - 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(){} diff --git a/src-qt5/src-cpp/framework-OSInterface.h b/src-qt5/src-cpp/framework-OSInterface.h index f367039e..3d64483d 100644 --- a/src-qt5/src-cpp/framework-OSInterface.h +++ b/src-qt5/src-cpp/framework-OSInterface.h @@ -18,6 +18,9 @@ #include <QVariant> #include <QHash> #include <QTimer> +#include <QFile> +#include <QDir> +#include <QVariant> #include <QIODevice> #include <QFileSystemWatcher> @@ -26,6 +29,11 @@ #include <QSslError> #include <QHostInfo> #include <QHostAddress> +#include <QNetworkConfiguration> +#include <QNetworkInterface> + +//Lumina Utils class +#include <LUtils.h> class OSInterface : public QObject{ Q_OBJECT @@ -81,7 +89,9 @@ public: 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) + // = 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 @@ -126,6 +136,7 @@ private slots: // ================ // SEMI-VIRTUAL FUNCTIONS - NEED TO BE DEFINED IN THE OS-SPECIFIC FILES // ================ + //FileSystemWatcher slots void watcherFileChanged(QString); void watcherDirChanged(QString); @@ -173,6 +184,9 @@ private: void connectNetman(); //setup the internal connections *only* void connectTimer(); //setup the internal connections *only* + //Internal simplification routines + bool verifyAppOrBin(QString chk); + // External Media Management (if system uses *.desktop shortcuts only) void setupMediaWatcher(); bool handleMediaDirChange(QString dir); //returns true if directory was handled @@ -180,6 +194,11 @@ 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 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 d15d9be8..709c54d4 100644 --- a/src-qt5/src-cpp/framework-OSInterface_private.cpp +++ b/src-qt5/src-cpp/framework-OSInterface_private.cpp @@ -7,9 +7,6 @@ // Internal, OS-agnostic functionality for managing the object itself //=========================================== #include <framework-OSInterface.h> -#include <QFile> -#include <QDir> -#include <QVariant> OSInterface::OSInterface(QObject *parent) : QObject(parent){ watcher = 0; @@ -63,6 +60,36 @@ void OSInterface::connectTimer(){ connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()) ); } +bool OSInterface::verifyAppOrBin(QString chk){ + bool valid = !chk.isEmpty(); + if(valid && chk.endsWith(".desktop")){ + chk = LUtils::AppToAbsolute(chk); + valid = QFile::exists(chk); + }else if(valid){ + valid = LUtils::isValidBinary(chk); + } + return valid; +} + +// =========================== +// OS SPECIFIC EXISTANCE CHECKS +// =========================== +bool OSInterface::hasControlPanel(){ + return verifyAppOrBin(controlPanelShortcut()); +} + +bool OSInterface::hasAudioMixer(){ + return verifyAppOrBin(audioMixerShortcut()); +} + +bool OSInterface::hasAppStore(){ + return verifyAppOrBin(appStoreShortcut()); +} + +// ======================== +// MEDIA DIRECTORIES +// ======================== + // External Media Management (if system uses *.desktop shortcuts) void OSInterface::setupMediaWatcher(){ //Create/connect the watcher if needed @@ -99,6 +126,9 @@ QStringList OSInterface::autoHandledMediaFiles(){ return files; } +// ============================= +// NETWORK INTERFACE FUNCTIONS +// ============================= // Qt-based NetworkAccessManager usage void OSInterface::setupNetworkManager(){ if(netman==0){ @@ -108,3 +138,59 @@ void OSInterface::setupNetworkManager(){ //Load the initial state of the network accessibility netAccessChanged(netman->networkAccessible()); } + +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" + return ""; +} + +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); +} + +bool OSInterface::hasNetworkManager(){ + return verifyAppOrBin(networkManagerUtility()); +} + +//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=networkTypeFromDeviceName(active.name()); //could not be auto-determined - run the OS-specific routine + } + 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(); +} |