//=========================================== // Lumina-DE source code // Copyright (c) 2014-2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "LuminaThemes.h" #include "LuminaUtils.h" #include "LuminaOS.h" #include #include #include #include #include //Stuff necesary for Qt Cursor Reloads //#include "qxcbcursor.h" //needed to prod Qt to refresh the mouse cursor theme //#include QStringList LTHEME::availableSystemThemes(){ //returns: [name::::path] for each item QDir dir(LOS::LuminaShare()+"themes"); QStringList list = dir.entryList(QStringList() <<"*.qss.template", QDir::Files, QDir::Name); for(int i=0; i::::] 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(QDir::homePath()+"/.lumina/themes"); QStringList list = dir.entryList(QStringList() <<"*.qss.template", QDir::Files, QDir::Name); for(int i=0; i::::] 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()+"colors"); QStringList list = dir.entryList(QStringList() <<"*.qss.colors", QDir::Files, QDir::Name); for(int i=0; i::::] list[i] = list[i].section(".qss.",0,0)+"::::"+dir.absoluteFilePath(list[i]); } return list; } QStringList LTHEME::availableLocalColors(){ //returns: [name::::path] for each item QDir dir(QDir::homePath()+"/.lumina/colors"); QStringList list = dir.entryList(QStringList() <<"*.qss.colors", QDir::Files, QDir::Name); for(int i=0; i::::] list[i] = list[i].section(".qss.",0,0)+"::::"+dir.absoluteFilePath(list[i]); } return list; } QStringList LTHEME::availableSystemIcons(){ //returns: [name] for each item QStringList paths; paths << QDir::homePath()+"/.icons"; QStringList xdd = QString(getenv("XDG_DATA_HOME")).split(":"); xdd << QString(getenv("XDG_DATA_DIRS")).split(":"); for(int i=0; ifont(); tmp.setStyleStrategy(QFont::PreferAntialias); application->setFont(tmp); // Now load the theme stylesheet QStringList current = LTHEME::currentSettings(); theme = current[0]; colors=current[1]; icons=current[2]; font=current[3]; fontsize=current[4]; cursors = LTHEME::currentCursor(); application->setStyleSheet( LTHEME::assembleStyleSheet(theme, colors, font, fontsize) ); QIcon::setThemeName(icons); //make sure this sets set within this environment syncTimer = new QTimer(this); syncTimer->setSingleShot(true); syncTimer->setInterval(500); //wait 1/2 second before re-loading the files if(cursors.isEmpty()){ 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()) ); connect(syncTimer, SIGNAL(timeout()), this, SLOT(reloadFiles()) ); } LuminaThemeEngine::~LuminaThemeEngine(){ } void LuminaThemeEngine::watcherChange(){ if(syncTimer->isActive()){ syncTimer->stop(); } syncTimer->start(); } void LuminaThemeEngine::reloadFiles(){ //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]; } //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; } //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"); }