set config- and data-dir to system-specific paths

This commit is contained in:
plc-user
2025-01-23 18:47:10 +01:00
parent b19fbd2522
commit ba9cd71816
6 changed files with 39 additions and 39 deletions

View File

@@ -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/<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);