From be7850a7e808e48cf7ddcdf6f6bc9f80c0d5c331 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 18 Aug 2015 10:34:24 -0400 Subject: Update the lumina theme engine/class so that custom environment variables may be set/loaded for all apps using the theme engine (including the session - which propagates to new non-lumina applications as well) --- libLumina/LuminaThemes.cpp | 120 +++++++++++++++++++++++++++++++++++++-------- libLumina/LuminaThemes.h | 17 +++++-- 2 files changed, 113 insertions(+), 24 deletions(-) (limited to 'libLumina') diff --git a/libLumina/LuminaThemes.cpp b/libLumina/LuminaThemes.cpp index cf31e5fd..17ddc60d 100644 --- a/libLumina/LuminaThemes.cpp +++ b/libLumina/LuminaThemes.cpp @@ -13,6 +13,8 @@ #include #include +#include + //Stuff necesary for Qt Cursor Reloads //#include "qxcbcursor.h" //needed to prod Qt to refresh the mouse cursor theme //#include @@ -250,11 +252,70 @@ QStringList LTHEME::cursorInformation(QString name){ return out; } +QStringList LTHEME::CustomEnvSettings(){ //view all the key=value settings + static QStringList info = QStringList(); + static QDateTime lastcheck = QDateTime(); + if(lastcheck.isNull() || lastcheck < QFileInfo(QDir::homePath()+"/.lumina/envsettings.conf").lastModified()){ + lastcheck = QDateTime::currentDateTime(); + info = LUtils::readFile(QDir::homePath()+"/.lumina/envsettings.conf"); + } + return info; +} + +void LTHEME::LoadCustomEnvSettings(){ + //will push the custom settings into the environment (recommended before loading the initial QApplication) + QStringList info = LTHEME::CustomEnvSettings(); + if(info.isEmpty()){ + //Ensure the file exists, and create it otherwise; + if(!QFile::exists(QDir::homePath()+"/.lumina/envsettings.conf")){ + LUtils::writeFile(QDir::homePath()+"/.lumina/envsettings.conf", QStringList() << "", true); + } + } + for(int i=0; ifont(); tmp.setStyleStrategy(QFont::PreferAntialias); @@ -272,7 +333,9 @@ LuminaThemeEngine::LuminaThemeEngine(QApplication *app){ LTHEME::setCursorTheme("default"); //X11 fallback (always installed?) cursors = "default"; } + //setenv("XCURSOR_THEME", cursors.toLocal8Bit(),1); watcher = new QFileSystemWatcher(this); + watcher->addPath( QDir::homePath()+"/.lumina/envsettings.conf" ); watcher->addPath( QDir::homePath()+"/.lumina/themesettings.cfg" ); watcher->addPaths( QStringList() << theme << colors << QDir::homePath()+"/.icons/default/index.theme" ); //also watch these files for changes connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherChange()) ); @@ -289,28 +352,45 @@ void LuminaThemeEngine::watcherChange(){ } void LuminaThemeEngine::reloadFiles(){ - QStringList current = LTHEME::currentSettings(); - application->setStyleSheet( LTHEME::assembleStyleSheet(current[0], current[1], current[3], current[4]) ); - - if(icons!=current[2]){ - QIcon::setThemeName(current[2]); //make sure this sets set within this environment - emit updateIcons(); + //Check the Theme file/settings + if(lastcheck < QFileInfo(QDir::homePath()+"/.lumina/themesettings.cfg").lastModified() ){ + QStringList current = LTHEME::currentSettings(); + application->setStyleSheet( LTHEME::assembleStyleSheet(current[0], current[1], current[3], current[4]) ); + if(icons!=current[2]){ + QIcon::setThemeName(current[2]); //make sure this sets set within this environment + emit updateIcons(); + } + //save the settings for comparison later + theme = current[0]; colors=current[1]; icons=current[2]; font=current[3]; fontsize=current[4]; } - QString ccurs = LTHEME::currentCursor(); - if(cursors != ccurs){ - emit updateCursors(); - //Might be something we can do automatically here as well - since we have the QApplication handy - // - Note: setting/unsetting an override cursor does not update the current cursor bitmap - // Qt created a background database/hash/mapping of the theme pixmaps on startup - // So Qt itself needs to be prodded to update that mapping - /*QXcbCursor::cursorThemePropertyChanged( \ + //Check the Cursor file/settings + if(lastcheck < QFileInfo(QDir::homePath()+"/.icons/default/index.theme").lastModified()){ + QString ccurs = LTHEME::currentCursor(); + if(cursors != ccurs){ + emit updateCursors(); + //Might be something we can do automatically here as well - since we have the QApplication handy + // - Note: setting/unsetting an override cursor does not update the current cursor bitmap + // Qt created a background database/hash/mapping of the theme pixmaps on startup + // So Qt itself needs to be prodded to update that mapping + /*QXcbCursor::cursorThemePropertyChanged( \ new QXcbVirtualDesktop(QX11Info::connection(), application->screen()->handle(), QX11Info::appScreen()), ccurs.toData(), QVariant("Inherits"), NULL);*/ - + //QCursorData::cleanup(); + //QCursorData::initialize(); + //setenv("XCURSOR_THEME", ccurs.toLocal8Bit(),1); + } + cursors = ccurs; } - //Now save this for later checking - watcher->removePaths( QStringList() << theme << colors << QDir::homePath()+"/.icons/default/index.theme"); - theme = current[0]; colors=current[1]; icons=current[2]; font=current[3]; fontsize=current[4]; - cursors = ccurs; - watcher->addPaths( QStringList() << theme << colors << QDir::homePath()+"/.icons/default/index.theme"); + + + //Environment Changes + if( lastcheck < QFileInfo(QDir::homePath()+"/.lumina/envsettings.conf").lastModified()){ + LTHEME::LoadCustomEnvSettings(); + emit EnvChanged(); + } + lastcheck = QDateTime::currentDateTime(); + + //Now update the watched files to ensure nothing is missed + watcher->removePaths( QStringList() << theme << colors << QDir::homePath()+"/.icons/default/index.theme" << QDir::homePath()+"/.lumina/envsettings.conf"); + watcher->addPaths( QStringList() << theme << colors << QDir::homePath()+"/.icons/default/index.theme" << QDir::homePath()+"/.lumina/envsettings.conf"); } diff --git a/libLumina/LuminaThemes.h b/libLumina/LuminaThemes.h index 3767eb7a..6dcff89d 100644 --- a/libLumina/LuminaThemes.h +++ b/libLumina/LuminaThemes.h @@ -17,6 +17,7 @@ #include #include #include +#include class LTHEME{ public: @@ -46,11 +47,18 @@ public: //Additional info for a cursor theme static QStringList cursorInformation(QString name); //returns: [Name, Comment, Sample Image File] + //Environment settings + static QStringList CustomEnvSettings(); //view all the key=value settings + static void LoadCustomEnvSettings(); //will push the custom settings into the environment (recommended before loading the initial QApplication) + static bool setCustomEnvSetting(QString var, QString val); //variable/value pair (use an empty val to clear it) + static QString readCustomEnvSetting(QString var); + }; //Simple class to setup a utility to use the Lumina theme //-----Example usage in "main.cpp" ------------------------------- +// LTHEME::LoadCustomEnvSettings(); // QApplication a(argc,argv); // LuminaThemeEngine themes(&a) //------------------------------------------------------------------------------------ @@ -71,15 +79,16 @@ private: QFileSystemWatcher *watcher; QString theme,colors,icons, font, fontsize, cursors; //current settings QTimer *syncTimer; + QDateTime lastcheck; private slots: void watcherChange(); void reloadFiles(); signals: - void updateIcons(); - void updateCursors(); -}; - + void updateIcons(); //Icon theme changed + void updateCursors(); //Cursor theme changed + void EnvChanged(); //Some environment variable(s) changed +}; #endif -- cgit