From ba9cd71816b379203b0008a76a65cd9a583330b1 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:47:10 +0100 Subject: [PATCH 1/9] set config- and data-dir to system-specific paths --- sources/dxf/dxftoelmt.cpp | 10 +--- sources/main.cpp | 5 +- .../qet_elementscaler/qet_elementscaler.cpp | 10 +--- sources/qetapp.cpp | 50 +++++++++++-------- sources/qetapp.h | 1 + sources/ui/aboutqetdialog.cpp | 2 +- 6 files changed, 39 insertions(+), 39 deletions(-) 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 #include #include -#include +#include /** * @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 #include #include -#include +#include /** * @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"; + QString configdir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); + if (configdir.endsWith('/')) { + configdir.remove(configdir.length()-1, 1); } - return(app_data_str + "/qet/"); -#else - return(QDir::homePath() + "/.qet/"); -#endif + 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//AppData/Roaming/ + on Windows and + ~/.local/share/ + 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, From 635af671002c3e4c82b5afdb2b9edd28d8e5ace8 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Thu, 23 Jan 2025 20:20:17 +0100 Subject: [PATCH 2/9] "writableLocation" is a QString --- sources/machine_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/machine_info.cpp b/sources/machine_info.cpp index 93b0f6761..0911fcc04 100644 --- a/sources/machine_info.cpp +++ b/sources/machine_info.cpp @@ -157,7 +157,7 @@ void MachineInfo::send_info_to_debug() qInfo()<< " Company Elements Dir:"<< QString(QETApp::companyElementsDir().toLatin1()); qInfo()<< " Company TitleBlock Templates Dir:"<< QString(QETApp::companyTitleBlockTemplatesDir().toLatin1()); - qInfo()<< " Standard Location :"<< QStringList(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + qInfo()<< " Standard Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); qInfo()<< " App Data Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); qInfo()<< " App Local DataLocation:"<< QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); qInfo()<< " Home Location:"<< QStandardPaths::writableLocation(QStandardPaths::HomeLocation); From b6d29fbbf01ad6a7abcbab5a2ea4723a9a0b7456 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Fri, 24 Jan 2025 06:56:04 +0100 Subject: [PATCH 3/9] update comment --- sources/qetapp.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index e7611fd88..6eea6388d 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -821,17 +821,17 @@ QString QETApp::customTitleBlockTemplatesDir() Return the QET configuration folder, i.e. the path to the folder in which QET will read configuration and customization information specific to the current user. This file is generally - C:\\Documents And Settings\\user\\Application Data\ qet + C:/Users//AppData/Local/ on Windows and - ~/.qet + ~/.config/ under UNIX-like systems. \~French Renvoie le dossier de configuration de QET, c-a-d le chemin du dossier dans lequel QET lira les informations de configuration et de personnalisation propres a l'utilisateur courant. Ce dossier est generalement - C:\\Documents And Settings\\utilisateur\\Application Data\\qet + C:/Users//AppData/Local/ sous Windows et - ~/.qet + ~/.config/ sous les systemes type UNIX. \~ @return The path of the QElectroTech configuration folder \~French Le chemin du dossier de configuration de QElectroTech From 4221bb84fb0e24e657c30b55e544d408f6fd038a Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Fri, 24 Jan 2025 07:02:57 +0100 Subject: [PATCH 4/9] create "AppDataLocation" if not present --- sources/qetapp.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 6eea6388d..ec5296b77 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -2054,6 +2054,12 @@ void QETApp::initConfiguration() QDir config_dir(QETApp::configDir()); if (!config_dir.exists()) config_dir.mkpath(QETApp::configDir()); + // we definitely need the dataDir for log files and element cache + // Nous avons absolument besoin du répertoire dataDir pour + // les fichiers journaux et le cache des éléments. + QDir data_dir(QETApp::dataDir()); + if (!data_dir.exists()) data_dir.mkpath(QETApp::dataDir()); + QDir custom_elements_dir(QETApp::customElementsDir()); if (!custom_elements_dir.exists()) custom_elements_dir.mkpath(QETApp::customElementsDir()); From 600cba6a8f2f30be074010c4655588e554921229 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Fri, 24 Jan 2025 07:10:36 +0100 Subject: [PATCH 5/9] update comment --- sources/qetapp.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index ec5296b77..53896807f 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -850,8 +850,9 @@ QString QETApp::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 + Return the QET data folder, i.e. the path to the folder in + which QET will save log-files and elements-cache and where + to find user-collections and user-titleblocks by default specific to the current user. This directory is generally C:/Users//AppData/Roaming/ on Windows and From ec7ba05ec1cf1cc1a42eef6baed8135e86f8d6e3 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Fri, 24 Jan 2025 07:19:36 +0100 Subject: [PATCH 6/9] adjust info-text --- sources/machine_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/machine_info.cpp b/sources/machine_info.cpp index 0911fcc04..596de23d7 100644 --- a/sources/machine_info.cpp +++ b/sources/machine_info.cpp @@ -157,7 +157,7 @@ void MachineInfo::send_info_to_debug() qInfo()<< " Company Elements Dir:"<< QString(QETApp::companyElementsDir().toLatin1()); qInfo()<< " Company TitleBlock Templates Dir:"<< QString(QETApp::companyTitleBlockTemplatesDir().toLatin1()); - qInfo()<< " Standard Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); + qInfo()<< " App Config Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); qInfo()<< " App Data Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); qInfo()<< " App Local DataLocation:"<< QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); qInfo()<< " Home Location:"<< QStandardPaths::writableLocation(QStandardPaths::HomeLocation); From d7ac2af4d6acda134de8cebfd50435a75926a6fa Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Fri, 24 Jan 2025 08:35:03 +0100 Subject: [PATCH 7/9] use QETApp::dataDir() instead of QStamdardPaths --- sources/dxf/dxftoelmt.cpp | 4 ++-- sources/qet_elementscaler/qet_elementscaler.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/dxf/dxftoelmt.cpp b/sources/dxf/dxftoelmt.cpp index 85ea2534f..bd21f2c54 100644 --- a/sources/dxf/dxftoelmt.cpp +++ b/sources/dxf/dxftoelmt.cpp @@ -17,11 +17,11 @@ */ #include "dxftoelmt.h" #include "../ui/thirdpartybinaryinstalldialog.h" +#include "../qetapp.h" #include #include #include -#include /** * @brief dxftoElmt @@ -71,7 +71,7 @@ QByteArray dxfToElmt(const QString &file_path) QString dxf2ElmtDirPath() { - return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/binary"; + return QETApp::dataDir() + "/binary"; } /** diff --git a/sources/qet_elementscaler/qet_elementscaler.cpp b/sources/qet_elementscaler/qet_elementscaler.cpp index b7e362d1e..b4ad83150 100644 --- a/sources/qet_elementscaler/qet_elementscaler.cpp +++ b/sources/qet_elementscaler/qet_elementscaler.cpp @@ -17,12 +17,12 @@ */ #include "qet_elementscaler.h" #include "../ui/thirdpartybinaryinstalldialog.h" +#include "../qetapp.h" #include #include #include #include -#include /** * @brief QET_ElementScaler @@ -113,7 +113,7 @@ QByteArray ElementScaler(const QString &file_path, QWidget *parent) QString ElementScalerDirPath() { - return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/binary"; + return QETApp::dataDir() + "/binary"; } /** From 620aa665f2f770df0d51384e954f25baec1edb42 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:25:57 +0100 Subject: [PATCH 8/9] Update machine_info.cpp try to resolve PR-conflict --- sources/machine_info.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sources/machine_info.cpp b/sources/machine_info.cpp index 596de23d7..40525082d 100644 --- a/sources/machine_info.cpp +++ b/sources/machine_info.cpp @@ -156,13 +156,15 @@ void MachineInfo::send_info_to_debug() qInfo()<< " Custom TitleBlock Templates Dir:"<< QString(QETApp::customTitleBlockTemplatesDir().toLatin1()); qInfo()<< " Company Elements Dir:"<< QString(QETApp::companyElementsDir().toLatin1()); qInfo()<< " Company TitleBlock Templates Dir:"<< QString(QETApp::companyTitleBlockTemplatesDir().toLatin1()); + qInfo()<< " User Location:"<< QString(QETApp::configDir().toLatin1()); - qInfo()<< " App Config Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); - qInfo()<< " App Data Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - qInfo()<< " App Local DataLocation:"<< QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); - qInfo()<< " Home Location:"<< QStandardPaths::writableLocation(QStandardPaths::HomeLocation); - qInfo()<< " Runtime Location:"<< QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); - qInfo()<< " Cache Location:"<< QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + + qInfo()<< " Config Location :"<< QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); + qInfo()<< " Project stalefiles Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + //qInfo()<< " App Local DataLocation:"<< QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); + // qInfo()<< " Home Location:"<< QStandardPaths::writableLocation(QStandardPaths::HomeLocation); + // qInfo()<< " Runtime Location:"<< QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); + // qInfo()<< " Cache Location:"<< QStandardPaths::writableLocation(QStandardPaths::CacheLocation); From 661530030a875cb91f9e860b0da2789629bfe672 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:28:52 +0100 Subject: [PATCH 9/9] Update machine_info.cpp second try to resolve PR-conflict --- sources/machine_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/machine_info.cpp b/sources/machine_info.cpp index 40525082d..fb93dfa93 100644 --- a/sources/machine_info.cpp +++ b/sources/machine_info.cpp @@ -159,7 +159,7 @@ void MachineInfo::send_info_to_debug() qInfo()<< " User Location:"<< QString(QETApp::configDir().toLatin1()); - qInfo()<< " Config Location :"<< QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); + qInfo()<< " Config Location :"<< QStringList(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); qInfo()<< " Project stalefiles Location:"<< QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); //qInfo()<< " App Local DataLocation:"<< QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); // qInfo()<< " Home Location:"<< QStandardPaths::writableLocation(QStandardPaths::HomeLocation);