1 //=========================================== 2 // Lumina-desktop source code 3 // Copyright (c) 2017, Ken Moore 4 // Available under the 3-clause BSD license 5 // See the LICENSE file for full details 6 //=========================================== 7 // This is a simple class for managing all the various desktop 8 // setting files, and sending out notifications about changes 9 //=========================================== 10 // NOTE: 11 // This class has a heirarchy-based lookup/write system 12 // USER Settings > SYSTEM Settings > DEFAULT Settings 13 // XDG_CONFIG_HOME/lumina-desktop > XDG_CONFIG_DIRS/lumina-desktop > XDG_DATA_DIRS/lumina-desktop 14 //=========================================== 15 #ifndef _LUMINA_DESKTOP_SETTINGS_CLASS_H 16 #define _LUMINA_DESKTOP_SETTINGS_CLASS_H 17 18 #include <QSettings> 19 #include <QFileSystemWatcher> 20 #include <QString> 21 #include <QStringList> 22 #include <QHash> 23 #include <QVariant> 24 25 class DesktopSettings : public QObject{ 26 Q_OBJECT 27 public: 28 enum File{ System, Favorites, Environment, Session, Desktop, Panels, Plugins, ContextMenu, Keys, Animation, ScreenSaver, WM}; 29 //Changes to this enum need to be added to the "filesForRunMode()" and "rel_path()" functions as well 30 31 DesktopSettings(QObject *parent = 0); 32 ~DesktopSettings(); 33 34 static DesktopSettings* instance(); 35 36 //Start/stop routines 37 void start(); 38 void stop(); 39 40 //Main Read/Write functions 41 QList< DesktopSettings::File > writableFiles(); //return the list of all writable files 42 QVariant value(DesktopSettings::File, QString variable, QVariant defaultvalue); 43 bool setValue(DesktopSettings::File, QString variable, QVariant value); 44 QStringList keys(DesktopSettings::File); //return a list of all variables which are available in this file 45 46 //Information functions 47 QStringList filePaths(DesktopSettings::File); //just in case we need to access any of these files outside this class 48 49 private: 50 enum RunMode{UserFull, SystemFull, SystemInterface }; 51 DesktopSettings::RunMode runmode; //simple flag for which mode the current session is running in 52 QFileSystemWatcher *watcher; 53 QHash< DesktopSettings::File, QStringList > files; //location hash for where files are actually located on disk 54 QHash< QString, QSettings*> settings; //location hash for the settings files themselves 55 56 //Functions 57 void parseSystemSettings(); //run at start - determine the RunMode for this user/session 58 void locateFiles(); //run at start - finds the locations of the various files (based on RunMode) 59 void touchFile(QString path); //used to create an empty file so it can be watched for changes later 60 61 //The two functions which define the public "File" enumeration (both need updates when the enum changes) 62 QList< DesktopSettings::File > filesForRunMode(RunMode mode); 63 QString rel_path(DesktopSettings::File); //return the relative file path (starting with "/") 64 65 private slots: 66 void fileChanged(QString); //QFileSystemWatcher change detected 67 void dirChanged(QString); //QFileSystemWatcher change detected 68 69 signals: 70 void FileModified(DesktopSettings::File); 71 72 }; 73 #endif 74