diff options
Diffstat (limited to 'src-qt5/core/libLumina')
-rw-r--r-- | src-qt5/core/libLumina/ExternalProcess.h | 11 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LDesktopUtils.cpp | 53 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LUtils.pri | 10 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaOS-FreeBSD.cpp | 2 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaSingleApplication.cpp | 4 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaThemes.cpp | 42 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaThemes.h | 3 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaXDG.cpp | 1 | ||||
-rw-r--r-- | src-qt5/core/libLumina/OSInterface-template.cpp | 100 | ||||
-rw-r--r-- | src-qt5/core/libLumina/OSInterface.h | 136 |
10 files changed, 90 insertions, 272 deletions
diff --git a/src-qt5/core/libLumina/ExternalProcess.h b/src-qt5/core/libLumina/ExternalProcess.h index 2a6f4949..e75d6108 100644 --- a/src-qt5/core/libLumina/ExternalProcess.h +++ b/src-qt5/core/libLumina/ExternalProcess.h @@ -21,6 +21,7 @@ class ExternalProcess : public QProcess{ Q_OBJECT private: bool cursorRestored; + QString logoutput; private slots: void resetCursor(){ @@ -46,6 +47,9 @@ private slots: //Clean up this object this->deleteLater(); } + void updateLog(){ + logoutput.append( QString(this->readAllStandardOutput()) ); + } public: ExternalProcess(QString logfile = "", bool manageCursors = false) : QProcess(){ @@ -53,6 +57,8 @@ public: cursorRestored = !manageCursors; if(logfile.isEmpty()){ this->setStandardOutputFile(QProcess::nullDevice()); + }else if(logfile=="stdout"){ + connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(updateLog()) ); }else{ this->setStandardOutputFile(logfile); } @@ -67,6 +73,11 @@ public: }*/ } + QString log(){ + //NOTE: This will only contain output if the "stdout" argument is used as the logfile + return logoutput; + } + static void launch(QString program, QStringList args = QStringList(), bool manageCursors = true){ //Quick launch of a process with logging disabled and automatic cleanup ExternalProcess *tmp = new ExternalProcess("", manageCursors); diff --git a/src-qt5/core/libLumina/LDesktopUtils.cpp b/src-qt5/core/libLumina/LDesktopUtils.cpp index 69d4ba52..5595532a 100644 --- a/src-qt5/core/libLumina/LDesktopUtils.cpp +++ b/src-qt5/core/libLumina/LDesktopUtils.cpp @@ -13,10 +13,8 @@ #include "LuminaThemes.h" -static QStringList fav; - QString LDesktopUtils::LuminaDesktopVersion(){ - QString ver = "1.4.0"; + QString ver = "1.4.1"; #ifdef GIT_VERSION ver.append( QString(" (Git Revision: %1)").arg(GIT_VERSION) ); #endif @@ -80,22 +78,23 @@ QStringList LDesktopUtils::infoQuickPlugin(QString ID){ //Returns: [Name, Descri } QStringList LDesktopUtils::listFavorites(){ - static QDateTime lastRead; - QDateTime cur = QDateTime::currentDateTime(); - if(lastRead.isNull() || lastRead<QFileInfo( QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/favorites.list").lastModified()){ + //static QDateTime lastRead; + QStringList fav; + //QDateTime cur = QDateTime::currentDateTime(); + //if(lastRead.isNull() || fav.isEmpty() || lastRead<QFileInfo( QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/favorites.list").lastModified()){ fav = LUtils::readFile(QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/favorites.list"); fav.removeAll(""); //remove any empty lines fav.removeDuplicates(); - lastRead = cur; - } - + //lastRead = cur; + //} return fav; } bool LDesktopUtils::saveFavorites(QStringList list){ list.removeDuplicates(); + //qDebug() << "Save Favorites:" << list; bool ok = LUtils::writeFile(QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/favorites.list", list, true); - if(ok){ fav = list; } //also save internally in case of rapid write/read of the file + //if(ok){ fav = list; } //also save internally in case of rapid write/read of the file return ok; } @@ -116,11 +115,13 @@ bool LDesktopUtils::addFavorite(QString path, QString name){ else{ type = LXDG::findAppMimeForFile(path); } //Assign a name if none given if(name.isEmpty()){ name = info.fileName(); } + //qDebug() << "Add Favorite:" << path << type << name; //Now add it to the list QStringList favs = LDesktopUtils::listFavorites(); + //qDebug() << "Current Favorites:" << favs; bool found = false; for(int i=0; i<favs.length(); i++){ - if(favs[i].endsWith("::::"+path)){ favs[i] = name+"::::"+type+"::::"+path; } + if(favs[i].endsWith("::::"+path)){ favs[i] = name+"::::"+type+"::::"+path; found = true; } } if(!found){ favs << name+"::::"+type+"::::"+path; } return LDesktopUtils::saveFavorites(favs); @@ -143,8 +144,15 @@ void LDesktopUtils::upgradeFavorites(int){ //fromoldversionnumber void LDesktopUtils::LoadSystemDefaults(bool skipOS){ //Will create the Lumina configuration files based on the current system template (if any) qDebug() << "Loading System Defaults"; + //Ensure that the settings directory exists + QString setdir = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop"; + if(!QFile::exists(setdir)){ + QDir dir; + dir.mkpath(setdir); + } + bool skipmime = QFile::exists( QString(getenv("XDG_CONFIG_HOME"))+"/lumina-mimapps.list" ); - qDebug() << " - Skipping mimetype default apps" << skipmime; + //qDebug() << " - Skipping mimetype default apps" << skipmime; QStringList sysDefaults; if(!skipOS){ sysDefaults = LUtils::readFile(LOS::AppPrefix()+"etc/luminaDesktop.conf"); } if(sysDefaults.isEmpty() && !skipOS){ sysDefaults = LUtils::readFile(LOS::AppPrefix()+"etc/luminaDesktop.conf.dist"); } @@ -187,6 +195,8 @@ void LDesktopUtils::LoadSystemDefaults(bool skipOS){ if(var.endsWith("_ifexists") ){ var = var.remove("_ifexists"); //remove this flag from the variable //Check if the value exists (absolute path only) + val = LUtils::AppToAbsolute(val); + //qDebug() << "Checking if favorite app exists:" << val; if(!QFile::exists(val)){ continue; } //skip this line - value/file does not exist } @@ -231,20 +241,23 @@ void LDesktopUtils::LoadSystemDefaults(bool skipOS){ if(tmp[i].startsWith("#") || !tmp[i].contains("=") ){ continue; } QString var = tmp[i].section("=",0,0).toLower().simplified(); QString val = tmp[i].section("=",1,1).section("#",0,0).simplified(); + qDebug() << "Mime entry:" << var << val; if(val.isEmpty()){ continue; } QString istrue = (val.toLower()=="true") ? "true": "false"; //Change in 0.8.5 - use "_" instead of "." within variables names - need backwards compat for a little while if(var.contains(".")){ var.replace(".","_"); } //Now parse the variable and put the value in the proper file - val = LUtils::AppToAbsolute(val); //Special handling for values which need to exist first if(var.endsWith("_ifexists") ){ var = var.remove("_ifexists"); //remove this flag from the variable + val = LUtils::AppToAbsolute(val); + //qDebug() << "Checking if Mime app exists:" << val; //Check if the value exists (absolute path only) if(!QFile::exists(val)){ continue; } //skip this line - value/file does not exist } //Now turn this variable into the mimetype only var = var.section("_default_",1,-1); + //qDebug() << " - Set Default Mime:" << var << val; LXDG::setDefaultAppForMime(var, val); } @@ -326,6 +339,7 @@ void LDesktopUtils::LoadSystemDefaults(bool skipOS){ tmp = sysDefaults.filter("favorites_"); if(tmp.isEmpty()){ tmp = sysDefaults.filter("favorites."); } for(int i=0; i<tmp.length(); i++){ + //qDebug() << "Found Favorite Entry:" << tmp[i]; if(tmp[i].startsWith("#") || !tmp[i].contains("=") ){ continue; } QString var = tmp[i].section("=",0,0).toLower().simplified(); QString val = tmp[i].section("=",1,1).section("#",0,0).simplified(); @@ -334,7 +348,7 @@ void LDesktopUtils::LoadSystemDefaults(bool skipOS){ //Now parse the variable and put the value in the proper file qDebug() << "Favorite entry:" << var << val; val = LUtils::AppToAbsolute(val); //turn any relative files into absolute - if(var=="favorites_add_ifexists" && QFile::exists(val)){ qDebug() << " - Exists/Adding:"; LDesktopUtils::addFavorite(val); } + if(var=="favorites_add_ifexists" && QFile::exists(val)){ qDebug() << " - Exists/Adding:" << val; LDesktopUtils::addFavorite(val); } else if(var=="favorites_add"){ qDebug() << " - Adding:"; LDesktopUtils::addFavorite(val); } else if(var=="favorites_remove"){ qDebug() << " - Removing:"; LDesktopUtils::removeFavorite(val); } } @@ -385,6 +399,7 @@ void LDesktopUtils::LoadSystemDefaults(bool skipOS){ if(var.contains(".")){ var.replace(".","_"); } //Now parse the variable and put the value in the proper file if(var=="theme_themefile"){ themesettings[0] = val; } + else if(var=="theme_styles"){ LTHEME::setCurrentStyles( val.split(",",QString::SkipEmptyParts) ); } else if(var=="theme_colorfile"){ themesettings[1] = val; } else if(var=="theme_iconset"){ themesettings[2] = val; } else if(var=="theme_font"){ themesettings[3] = val; } @@ -425,12 +440,6 @@ void LDesktopUtils::LoadSystemDefaults(bool skipOS){ } //qDebug() << " - Final Theme Color:" << themesettings[1]; - //Ensure that the settings directory exists - QString setdir = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop"; - if(!QFile::exists(setdir)){ - QDir dir; - dir.mkpath(setdir); - } //Now save the settings files if(setTheme){ LTHEME::setCurrentSettings( themesettings[0], themesettings[1], themesettings[2], themesettings[3], themesettings[4]); @@ -538,7 +547,7 @@ bool LDesktopUtils::checkUserFiles(QString lastversion, QString currentversion){ newtheme.setValue("Interface/desktop_stylesheets", QStringList() << enginedir+"desktop_qss/Glass.qss"); } newtheme.setValue("Appearance/style", "Fusion"); - newtheme.setValue("Interface/stylesheets", QStringList() << enginedir+"qss/tooltip-simple.qss" << enginedir+"qss/scrollbar-simple.qss" << enginedir+"qss/sliders-simple.qss"); + newtheme.setValue("Interface/stylesheets", QStringList() << enginedir+"qss/tooltip-simple.qss" << enginedir+"qss/scrollbar-simple.qss" << enginedir+"qss/sliders-simple.qss" << enginedir+"qss/traynotification-simple.qss"); newtheme.sync(); //flush this to file right now } //end check for theme file existance } @@ -569,7 +578,7 @@ bool LDesktopUtils::checkUserFiles(QString lastversion, QString currentversion){ } int LDesktopUtils::VersionStringToNumber(QString version){ - version = version.section("-",0,0); //trim any extra labels off the end + version = version.section("_",0,0).section("-",0,0); //trim any extra labels off the end int maj, mid, min; //major/middle/minor version numbers (<Major>.<Middle>.<Minor>) maj = mid = min = 0; bool ok = true; diff --git a/src-qt5/core/libLumina/LUtils.pri b/src-qt5/core/libLumina/LUtils.pri index 6ce0839c..da5a78d5 100644 --- a/src-qt5/core/libLumina/LUtils.pri +++ b/src-qt5/core/libLumina/LUtils.pri @@ -15,8 +15,7 @@ GIT_VERSION=$$system(git describe --always) #DEFINES += BUILD_DATE='"\\\"$$system(date)\\\""' #LuminaOS files -HEADERS *= $${PWD}/LuminaOS.h \ - $${PWD}/OSInterface.h +HEADERS *= $${PWD}/LuminaOS.h # LuminaOS support functions (or fall back to generic one) exists($${PWD}/LuminaOS-$${LINUX_DISTRO}.cpp){ @@ -26,13 +25,6 @@ exists($${PWD}/LuminaOS-$${LINUX_DISTRO}.cpp){ }else{ SOURCES *= $${PWD}/LuminaOS-template.cpp } -exists($${PWD}/OSInterface-$${LINUX_DISTRO}.cpp){ - SOURCES *= $${PWD}/OSInterface-$${LINUX_DISTRO}.cpp -}else:exists($${PWD}/OSInterface-$${OS}.cpp){ - SOURCES *= $${PWD}/OSInterface-$${OS}.cpp -}else{ - SOURCES *= $${PWD}/OSInterface-template.cpp -} #LUtils Files SOURCES *= $${PWD}/LUtils.cpp diff --git a/src-qt5/core/libLumina/LuminaOS-FreeBSD.cpp b/src-qt5/core/libLumina/LuminaOS-FreeBSD.cpp index dc7de37f..1ee8fb8a 100644 --- a/src-qt5/core/libLumina/LuminaOS-FreeBSD.cpp +++ b/src-qt5/core/libLumina/LuminaOS-FreeBSD.cpp @@ -30,7 +30,7 @@ QString LOS::AppStoreShortcut(){ return "/usr/local/share/applications/appcafe.d QStringList LOS::RSSFeeds(){ QStringList feeds; feeds << "FreeBSD News Feed::::https://www.freebsd.org/news/rss.xml"; - feeds << "TrueOS News Feed::::http://www.trueos.org/?feed=rss2"; + feeds << "TrueOS News Feed::::http://www.trueos.org/feed/"; return feeds; } diff --git a/src-qt5/core/libLumina/LuminaSingleApplication.cpp b/src-qt5/core/libLumina/LuminaSingleApplication.cpp index 5d276805..6107aff8 100644 --- a/src-qt5/core/libLumina/LuminaSingleApplication.cpp +++ b/src-qt5/core/libLumina/LuminaSingleApplication.cpp @@ -11,7 +11,7 @@ #include <QDebug> #include <QX11Info> -#include <unistd.h> //for getlogin() +#include <unistd.h> //for getuid() LSingleApplication::LSingleApplication(int &argc, char **argv, QString appname) : QApplication(argc, argv){ //Load the proper translation systems @@ -19,7 +19,7 @@ LSingleApplication::LSingleApplication(int &argc, char **argv, QString appname) if(appname!="lumina-desktop"){ cTrans = LUtils::LoadTranslation(this, appname); }//save the translator for later //Initialize a couple convenience internal variables cfile = QDir::tempPath()+"/.LSingleApp-%1-%2-%3"; - QString username = QString(getuid()); + QString username = QString::number(getuid()); //For locking the process use the official process name - not the user input (no masking) appname = this->applicationName(); cfile = cfile.arg( username, appname, QString::number(QX11Info::appScreen()) ); diff --git a/src-qt5/core/libLumina/LuminaThemes.cpp b/src-qt5/core/libLumina/LuminaThemes.cpp index 857e604b..03524941 100644 --- a/src-qt5/core/libLumina/LuminaThemes.cpp +++ b/src-qt5/core/libLumina/LuminaThemes.cpp @@ -34,6 +34,17 @@ QStringList LTHEME::availableSystemThemes(){ return list; } +QStringList LTHEME::availableSystemStyles(){ + //returns: [name::::path] for each item + QDir dir(LOS::LuminaShare()+"../lthemeengine/qss"); + QStringList list = dir.entryList(QStringList() <<"*.qss", QDir::Files, QDir::Name); + for(int i=0; i<list.length(); i++){ + //Format the output entry [<name>::::<fullpath>] + list[i] = list[i].section(".qss",0,0)+"::::"+dir.absoluteFilePath(list[i]); + } + return list; +} + QStringList LTHEME::availableLocalThemes(){ //returns: [name::::path] for each item QDir dir( QString(getenv("XDG_CONFIG_HOME"))+"/lthemeengine/desktop_qss"); QStringList list = dir.entryList(QStringList() <<"*.qss", QDir::Files, QDir::Name); @@ -44,6 +55,16 @@ QStringList LTHEME::availableLocalThemes(){ //returns: [name::::path] for each i return list; } +QStringList LTHEME::availableLocalStyles(){ //returns: [name::::path] for each item + QDir dir( QString(getenv("XDG_CONFIG_HOME"))+"/lthemeengine/qss"); + QStringList list = dir.entryList(QStringList() <<"*.qss", QDir::Files, QDir::Name); + for(int i=0; i<list.length(); i++){ + //Format the output entry [<name>::::<fullpath>] + list[i] = list[i].section(".qss",0,0)+"::::"+dir.absoluteFilePath(list[i]); + } + return list; +} + QStringList LTHEME::availableSystemColors(){ //returns: [name::::path] for each item //returns: [name::::path] for each item QDir dir(LOS::LuminaShare()+"../lthemeengine/colors"); @@ -244,6 +265,23 @@ bool LTHEME::setCursorTheme(QString cursorname){ return LUtils::writeFile(QDir::homePath()+"/.icons/default/index.theme", info, true); } +bool LTHEME::setCurrentStyles(QStringList paths){ + //Verify that the paths are all absolute paths, otherwise scan/replace with absolute paths + QStringList avail = LTHEME::availableSystemStyles(); + for(int i=0; i<paths.length(); i++){ + paths[i] = paths[i].simplified(); + if(paths[i].startsWith("/")){ continue; } //already an absolute path + for(int j=0; j<avail.length(); j++){ + if(avail[j].startsWith(paths[i].section("/",-1).section(".qss",0,0)+"::::") ){ paths[i] = avail[j].section("::::",1,-1); break; } + } + } + //ordered by priority: lowest -> highest + QSettings engineset("lthemeengine","lthemeengine"); + engineset.setValue("Interface/stylesheets",paths); + engineset.sync(); + return true; +} + //Return the complete stylesheet for a given theme/colors QString LTHEME::assembleStyleSheet(QString themepath, QString colorpath, QString font, QString fontsize){ QString stylesheet = LUtils::readFile(themepath).join("\n"); @@ -340,10 +378,10 @@ void LTHEME::LoadCustomEnvSettings(){ setenv(info[i].section("=",0,0).toLocal8Bit(), info[i].section("=",1,100).simplified().toLocal8Bit(), 1); } } - + } -bool LTHEME::setCustomEnvSetting(QString var, QString val){ +bool LTHEME::setCustomEnvSetting(QString var, QString val){ //variable/value pair (use an empty val to clear it) QStringList info = LTHEME::CustomEnvSettings(true); //user only bool changed = false; diff --git a/src-qt5/core/libLumina/LuminaThemes.h b/src-qt5/core/libLumina/LuminaThemes.h index ca79e0bd..133bd04d 100644 --- a/src-qt5/core/libLumina/LuminaThemes.h +++ b/src-qt5/core/libLumina/LuminaThemes.h @@ -25,7 +25,9 @@ class LTHEME{ public: //Read the Themes/Colors/Icons that are available on the system static QStringList availableSystemThemes();//returns: [name::::path] for each item + static QStringList availableSystemStyles();//returns: [name::::path] for each item static QStringList availableLocalThemes(); //returns: [name::::path] for each item + static QStringList availableLocalStyles(); //returns: [name::::path] for each item static QStringList availableSystemColors(); //returns: [name::::path] for each item static QStringList availableLocalColors(); //returns: [name::::path] for each item static QStringList availableSystemIcons(); //returns: [name] for each item @@ -42,6 +44,7 @@ public: //Change the current Theme/Colors/Icons static bool setCurrentSettings(QString themepath, QString colorpath, QString iconname, QString font, QString fontsize); static bool setCursorTheme(QString cursorname); + static bool setCurrentStyles(QStringList paths); //ordered by priority: lowest -> highest //Return the complete stylesheet for a given theme/colors static QString assembleStyleSheet(QString themepath, QString colorpath, QString font, QString fontsize); diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index 1933ba93..e1c582d9 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -1294,6 +1294,7 @@ QStringList LXDG::findAvailableAppsForMime(QString mime){ } void LXDG::setDefaultAppForMime(QString mime, QString app){ + //qDebug() << "Set Default App For Mime:" << mime << app; QString filepath = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-mimeapps.list"; QStringList cinfo = LUtils::readFile(filepath); //If this is a new file, make sure to add the header appropriately diff --git a/src-qt5/core/libLumina/OSInterface-template.cpp b/src-qt5/core/libLumina/OSInterface-template.cpp deleted file mode 100644 index 96b01e60..00000000 --- a/src-qt5/core/libLumina/OSInterface-template.cpp +++ /dev/null @@ -1,100 +0,0 @@ -//=========================================== -// Lumina desktop source code -// Copyright (c) 2017, Ken Moore -// Available under the 3-clause BSD license -// See the LICENSE file for full details -//=========================================== -#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) -void OSInterface::start(){ - //nothing to do -} - -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>(); -} - -//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; -} - -//================= -// PRIVATE SLOTS -//================= -//FileSystemWatcher slots -void OSInterface::watcherFileChanged(QString){ - -} - -void OSInterface::watcherDirChanged(QString){ - -} - -//IO Device slots -void OSInterface::iodeviceReadyRead(){ - -} - -void OSInterface::iodeviceAboutToClose(){ - -} - -//NetworkAccessManager slots -void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility){ - -} - -void OSInterface::netRequestFinished(QNetworkReply*){ - -} - -void OSInterface::netSslErrors(QNetworkReply*, const QList<QSslError>&){ - -} diff --git a/src-qt5/core/libLumina/OSInterface.h b/src-qt5/core/libLumina/OSInterface.h deleted file mode 100644 index acbd5c38..00000000 --- a/src-qt5/core/libLumina/OSInterface.h +++ /dev/null @@ -1,136 +0,0 @@ -//=========================================== -// Lumina desktop source code -// Copyright (c) 2017, Ken Moore -// Available under the 3-clause BSD license -// See the LICENSE file for full details -//=========================================== -// This is the main interface for any OS-specific system calls -// To port Lumina to a different operating system, just create a file -// called "OSInterface-<Operating System>.cpp" -//=========================================== -#ifndef _LUMINA_LIBRARY_OS_INTERFACE_H -#define _LUMINA_LIBRARY_OS_INTERFACE_H - -#include <QString> -#include <QStringList> -#include <QList> -#include <QObject> -#include <QVariant> -#include <QHash> - -#include <QIODevice> -#include <QFileSystemWatcher> -#include <QNetworkAccessManager> -#include <QNetworkReply> -#include <QSslError> - -class OSInterface : public QObject{ - Q_OBJECT - -public: - enum Interface{ Battery, Volume, Devices, Network, PowerOff, Reboot, Suspend, Updates }; - -private slots: - //FileSystemWatcher slots - void watcherFileChanged(QString); - void watcherDirChanged(QString); - //IO Device slots - void iodeviceReadyRead(); - void iodeviceAboutToClose(); - //NetworkAccessManager slots - void netAccessChanged(QNetworkAccessManager::NetworkAccessibility); - void netRequestFinished(QNetworkReply*); - void netSslErrors(QNetworkReply*, const QList<QSslError>&); - -private: - //Internal persistant data storage, OS-specific usage implementation - QHash< OSInterface::Interface, QList<QVariant> > INFO; - - // ============ - // Internal possibilities for watching the system (OS-Specific usage/implementation) - // ============ - //File System Watcher - QFileSystemWatcher *watcher; - //IO Device (QLocalSocket, QTcpConnection, QFile, etc) - QIODevice *iodevice; - //Network Access Manager (check network connectivity, etc) - QNetworkAccessManager *netman; - - //Simplifications for connecting the various watcher objects to their respective slots - void connectWatcher(){ - if(watcher==0){ return; } - connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherFileChanged(QString)) ); - connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(watcherDirChanged(QString)) ); - } - void connectIodevice(){ - if(iodevice==0){ return; } - connect(iodevice, SIGNAL(readyRead()), this, SLOT(iodeviceReadyRead()) ); - } - void connectNetman(){ - if(netman==0){ return; } - connect(netman, SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SLOT(netAccessChanged(QNetworkAccessManager::NetworkAccessibility)) ); - connect(netman, SIGNAL(requestFinished(QNetworkReply*)), this, SLOT(netRequestFinished(QNetworkReply*)) ); - connect(netman, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(netSslErrors(QNetworkReply*, const QList<QSslError>&)) ); - } - -public: - OSInterface(QObject *parent = 0) : QObject(parent){ - watcher = 0; - iodevice = 0; - netman = 0; - } - ~OSInterface(){ - if(watcher!=0){ - QStringList paths; paths << watcher->files() << watcher->directories(); - if(!paths.isEmpty()){ watcher->removePaths(paths); } - watcher->deleteLater(); - } - if(iodevice!=0){ - if(iodevice->isOpen()){ iodevice->close(); } - iodevice->deleteLater(); - } - if(netman!=0){ - netman->deleteLater(); - } - } - - //Simple functions used to determine if the current OS supports using this class, and what levels of support - QList<OSInterface::Interface> supportedNotifications(); //Which interfaces provide change notifications - QList<OSInterface::Interface> supportedStatus(); //Which interfaces are available for "status" requests - QList<OSInterface::Interface> supportedModify(); //Which interfaces are available for "modify" requests - - //Start/stop interface watchers/notifications (each only called once per session) - void start(); - void stop(); - - //Generic status update - QList<QVariant> 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)] - // ========== - - //Individual Interface interactions - bool modify(OSInterface::Interface, QList<QVariant> args); //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> - // ========== - -signals: - void interfaceChanged(OSInterface::Interface); - -}; -#endif |