aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/libLumina
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/core/libLumina')
-rw-r--r--src-qt5/core/libLumina/LUtils.cpp26
-rw-r--r--src-qt5/core/libLumina/LUtils.h4
2 files changed, 30 insertions, 0 deletions
diff --git a/src-qt5/core/libLumina/LUtils.cpp b/src-qt5/core/libLumina/LUtils.cpp
index 78831231..fa0173dc 100644
--- a/src-qt5/core/libLumina/LUtils.cpp
+++ b/src-qt5/core/libLumina/LUtils.cpp
@@ -12,6 +12,8 @@
#include <QApplication>
#include <QtConcurrent>
+#include <unistd.h>
+
inline QStringList ProcessRun(QString cmd, QStringList args){
//Assemble outputs
QStringList out; out << "1" << ""; //error code, string output
@@ -127,6 +129,30 @@ bool LUtils::isValidBinary(QString& bin){
return good;
}
+QSettings* LUtils::openSettings(QString org, QString name, QObject *parent){
+ //Start with the base configuration directory
+ QString path = QString(getenv("XDG_CONFIG_HOME")).simplified();
+ if(path.isEmpty()){ path = QDir::homePath()+"/.config"; }
+ //Now add the organization directory
+ path = path+"/"+org;
+ QDir dir(path);
+ if(!dir.exists()){ dir.mkpath(path); }
+ //Now generate/check the name of the file
+ unsigned int user = getuid();
+ QString filepath = dir.absoluteFilePath(name+".conf");
+ if(user==0){
+ //special case - make sure we don't clobber the user-permissioned file
+ QString rootfilepath = dir.absoluteFilePath(name+"_root.conf");
+ if(!QFileInfo::exists(rootfilepath) && QFileInfo::exists(filepath)){
+ QFile::copy(filepath, rootfilepath); //make a copy of the user settings before they start to diverge
+ }
+ return (new QSettings(rootfilepath, QSettings::IniFormat, parent));
+ }else{
+ return (new QSettings(filepath, QSettings::IniFormat, parent));
+ }
+
+}
+
QStringList LUtils::systemApplicationDirs(){
//Returns a list of all the directories where *.desktop files can be found
QStringList appDirs = QString(getenv("XDG_DATA_HOME")).split(":");
diff --git a/src-qt5/core/libLumina/LUtils.h b/src-qt5/core/libLumina/LUtils.h
index 459fca60..4ad05ca1 100644
--- a/src-qt5/core/libLumina/LUtils.h
+++ b/src-qt5/core/libLumina/LUtils.h
@@ -25,6 +25,7 @@
#include <QRegExp>
#include <QFuture>
#include <QScreen>
+#include <QSettings>
class LUtils{
public:
@@ -46,6 +47,9 @@ public:
return isValidBinary(bins); //overload for a "junk" binary variable input
}
+ //Open the right settings file (user/permissions aware)
+ static QSettings* openSettings(QString org, QString name, QObject *parent = 0);
+
//Return all the dirs on the system which contain .desktop files
static QStringList systemApplicationDirs();
bgstack15