Replacing getenv function in Windows, thanks Francisco

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2661 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
scorpio810 2013-12-19 16:11:52 +00:00
parent 5c3e0d6dc4
commit 1ec9d9705f

View File

@ -35,6 +35,7 @@
#include <iostream> #include <iostream>
#define QUOTE(x) STRINGIFY(x) #define QUOTE(x) STRINGIFY(x)
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#include <QProcessEnvironment>
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
QString QETApp::common_elements_dir = QString(); QString QETApp::common_elements_dir = QString();
@ -389,11 +390,15 @@ TitleBlockTemplatesCollection *QETApp::titleBlockTemplatesCollection(const QStri
@return le nom de l'utilisateur courant @return le nom de l'utilisateur courant
*/ */
QString QETApp::userName() { QString QETApp::userName() {
QProcess * process = new QProcess();
#ifndef Q_OS_WIN32 #ifndef Q_OS_WIN32
return(QString(getenv("USER"))); // return(QString(getenv("USER")));
return((process->processEnvironment()).value("USER", "UNKNOWN"));
#else #else
return(QString(getenv("USERNAME"))); // return(QString(getenv("USERNAME")));
return((process->processEnvironment()).value("USERNAME", "UNKNOWN"));
#endif #endif
delete process;
} }
/** /**
@ -473,9 +478,12 @@ QString QETApp::configDir() {
#endif #endif
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
// recupere l'emplacement du dossier Application Data // recupere l'emplacement du dossier Application Data
char *app_data_env = getenv("APPDATA"); // char *app_data_env = getenv("APPDATA");
QString app_data_str(app_data_env); // QString app_data_str(app_data_env);
delete 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()) { if (app_data_str.isEmpty()) {
app_data_str = QDir::homePath() + "/Application Data"; app_data_str = QDir::homePath() + "/Application Data";
} }