Topic: Set Config- and Data-Directory to system-specific paths
This thread is a continuation of the topic that started here:
https://qelectrotech.org/forum/viewtopi … 844#p20844
----------------------------
Salut Laurent !
I created a patch to set the config- and data-directories to system-specific values.
diff --git a/sources/dxf/dxftoelmt.cpp b/sources/dxf/dxftoelmt.cpp
index f2dd572d8..85ea2534f 100644
--- a/sources/dxf/dxftoelmt.cpp
+++ b/sources/dxf/dxftoelmt.cpp
@@ -21,7 +21,7 @@
#include <QFile>
#include <QProcess>
#include <QMessageBox>
-#include <QDir>
+#include <QStandardPaths>
/**
* @brief dxftoElmt
@@ -71,13 +71,7 @@ QByteArray dxfToElmt(const QString &file_path)
QString dxf2ElmtDirPath()
{
-#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
- return (QDir::homePath() + QStringLiteral("/Application Data/qet/binary"));
-#elif defined(Q_OS_MACOS)
- return (QDir::homePath() + QStringLiteral("/.qet/binary"));
-#else
- return (QDir::homePath() + QStringLiteral("/.qet/binary"));
-#endif
+ return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/binary";
}
/**
diff --git a/sources/main.cpp b/sources/main.cpp
index ed460609f..5eb7efca3 100644
--- a/sources/main.cpp
+++ b/sources/main.cpp
@@ -112,7 +112,8 @@ void myMessageOutput(QtMsgType type,
txt+= context.function ? context.function : "";
txt+=")\n";
}
- QFile outFile(QETApp::configDir()
+ QFile outFile(QETApp::dataDir()
+ +"/"
+QDate::currentDate().toString("yyyyMMdd")
+".log");
if(outFile.open(QIODevice::WriteOnly | QIODevice::Append))
@@ -131,7 +132,7 @@ void myMessageOutput(QtMsgType type,
void delete_old_log_files(int days)
{
const QDate today = QDate::currentDate();
- const QString path = QETApp::configDir() + "/";
+ const QString path = QETApp::dataDir() + "/";
QString filter("%1%1%1%1%1%1%1%1.log"); // pattern
filter = filter.arg("[0123456789]"); // valid characters
diff --git a/sources/qet_elementscaler/qet_elementscaler.cpp b/sources/qet_elementscaler/qet_elementscaler.cpp
index 930bae333..b7e362d1e 100644
--- a/sources/qet_elementscaler/qet_elementscaler.cpp
+++ b/sources/qet_elementscaler/qet_elementscaler.cpp
@@ -22,7 +22,7 @@
#include <QProcess>
#include <QInputDialog>
#include <QMessageBox>
-#include <QDir>
+#include <QStandardPaths>
/**
* @brief QET_ElementScaler
@@ -113,13 +113,7 @@ QByteArray ElementScaler(const QString &file_path, QWidget *parent)
QString ElementScalerDirPath()
{
-#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
- return (QDir::homePath() + QStringLiteral("/Application Data/qet/binary"));
-#elif defined(Q_OS_MACOS)
- return (QDir::homePath() + QStringLiteral("/.qet/binary"));
-#else
- return (QDir::homePath() + QStringLiteral("/.qet/binary"));
-#endif
+ return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/binary";
}
/**
diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp
index f1211bb47..e7611fd88 100644
--- a/sources/qetapp.cpp
+++ b/sources/qetapp.cpp
@@ -121,7 +121,7 @@ QETApp::QETApp() :
tr("Chargement... Initialisation du cache des collections d'éléments",
"splash screen caption"));
if (!collections_cache_) {
- QString cache_path = QETApp::configDir() + "/elements_cache.sqlite";
+ QString cache_path = QETApp::dataDir() + "/elements_cache.sqlite";
collections_cache_ = new ElementsCollectionCache(cache_path, this);
collections_cache_->setLocale(langFromSetting());
@@ -620,7 +620,7 @@ QString QETApp::customElementsDir()
}
}
- m_custom_element_dir = configDir() + "elements/";
+ m_custom_element_dir = dataDir() + "/elements/";
return m_custom_element_dir;
}
}
@@ -657,7 +657,7 @@ QString QETApp::companyElementsDir()
}
}
- m_company_element_dir = configDir() + "elements-company/";
+ m_company_element_dir = dataDir() + "/elements-company/";
return m_company_element_dir;
}
}
@@ -780,7 +780,7 @@ QString QETApp::companyTitleBlockTemplatesDir()
return m_user_company_tbt_dir;
}
- return(configDir() + "titleblocks-company/");
+ return(dataDir() + "/titleblocks-company/");
}
/**
@@ -813,7 +813,7 @@ QString QETApp::customTitleBlockTemplatesDir()
return m_user_custom_tbt_dir;
}
- return(configDir() + "titleblocks/");
+ return(dataDir() + "/titleblocks/");
}
/**
@@ -841,21 +841,31 @@ QString QETApp::configDir()
#ifdef QET_ALLOW_OVERRIDE_CD_OPTION
if (config_dir != QString()) return(config_dir);
#endif
-#ifdef Q_OS_WIN32
- // recupere l'emplacement du dossier Application Data
- // char *app_data_env = getenv("APPDATA");
- // QString app_data_str(app_data_env);
- QProcess * process = new QProcess();
- QString app_data_str = (process->processEnvironment()).value("APPDATA");
- // delete app_data_env;
- delete process;
- if (app_data_str.isEmpty()) {
- app_data_str = QDir::homePath() + "/Application Data";
- }
- return(app_data_str + "/qet/");
-#else
- return(QDir::homePath() + "/.qet/");
-#endif
+ QString configdir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
+ if (configdir.endsWith('/')) {
+ configdir.remove(configdir.length()-1, 1);
+ }
+ return configdir;
+}
+
+/**
+ @brief QETApp::dataDir
+ Return the QET data folder, i.e. the path to the folder in which
+ QET will find user-collections and user-titleblocks by default
+ specific to the current user. This directory is generally
+ C:/Users/<USER>/AppData/Roaming/<APPNAME>
+ on Windows and
+ ~/.local/share/<APPNAME>
+ under UNIX-like systems.
+ \~ @return The path of the QElectroTech data-folder
+*/
+QString QETApp::dataDir()
+{
+ QString datadir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
+ if (datadir.endsWith('/')) {
+ datadir.remove(datadir.length()-1, 1);
+ }
+ return datadir;
}
/**
@@ -1536,7 +1546,7 @@ void QETApp::useSystemPalette(bool use) {
"}"
);
} else {
- QFile file(configDir() + "style.css");
+ QFile file(configDir() + "/style.css");
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());
qApp->setStyleSheet(styleSheet);
diff --git a/sources/qetapp.h b/sources/qetapp.h
index 2f4cdc402..572e2c837 100644
--- a/sources/qetapp.h
+++ b/sources/qetapp.h
@@ -97,6 +97,7 @@ class QETApp : public QObject
static QETProject *project(const uint &);
static int projectId(const QETProject *);
static QString configDir();
+ static QString dataDir();
static QString languagesPath();
static QString realPath(const QString &);
static QString symbolicPath(const QString &);
diff --git a/sources/ui/aboutqetdialog.cpp b/sources/ui/aboutqetdialog.cpp
index b1dc0abc0..f94b62449 100644
--- a/sources/ui/aboutqetdialog.cpp
+++ b/sources/ui/aboutqetdialog.cpp
@@ -208,7 +208,7 @@ void AboutQETDialog::setLicence()
*/
void AboutQETDialog::setLoginfo()
{
- const QString path = QETApp::configDir() + "/";
+ const QString path = QETApp::dataDir() + "/";
QString filter("%1%1%1%1%1%1%1%1.log"); // pattern
filter = filter.arg("[0123456789]"); // valid characters
Q_FOREACH (auto fileInfo,
As already said in previous post the general configuration-file of QET and the stalefiles are completely managed by Qt-Library-functions. So they are already at system-specific locations. There is no need to touch them with these modifications!
I uploaded that patch to my fork of QET at https://github.com/plc-user/qelectrotech-source-mirror and can create a pull-request, if you wish, Laurent.
@all:
Everyone who can compile QET from sources is invited to download, compile and test the software!
But be aware:
The location of configurations, the elements-collections and the titleblocks may (will) have changed!
Please give feedback here or at github about your experience!
Thanks in advance!
plc-user