Commit b7a1e87c authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Utils: Add user name accessor to the Environnment class.



Change-Id: Ic67381ab185525552eef948af602d00d3800b653
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@nokia.com>
parent b18b458d
...@@ -383,6 +383,11 @@ bool Environment::hasKey(const QString &key) ...@@ -383,6 +383,11 @@ bool Environment::hasKey(const QString &key)
return m_values.contains(key); return m_values.contains(key);
} }
QString Environment::userName() const
{
return value(QLatin1String(HostOsInfo::isWindowsHost() ? "USERNAME" : "USER"));
}
bool Environment::operator!=(const Environment &other) const bool Environment::operator!=(const Environment &other) const
{ {
return !(*this == other); return !(*this == other);
......
...@@ -79,6 +79,8 @@ public: ...@@ -79,6 +79,8 @@ public:
QList<EnvironmentItem> diff(const Environment &other) const; QList<EnvironmentItem> diff(const Environment &other) const;
bool hasKey(const QString &key); bool hasKey(const QString &key);
QString userName() const;
void appendOrSet(const QString &key, const QString &value, const QString &sep = QString()); void appendOrSet(const QString &key, const QString &value, const QString &sep = QString());
void prependOrSet(const QString &key, const QString &value, const QString &sep = QString()); void prependOrSet(const QString &key, const QString &value, const QString &sep = QString());
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "settings.h" #include "settings.h"
#include "pastebindotcomprotocol.h" #include "pastebindotcomprotocol.h"
#include <utils/hostosinfo.h> #include <utils/environment.h>
#include <QVariant> #include <QVariant>
#include <QSettings> #include <QSettings>
...@@ -67,8 +67,7 @@ void Settings::toSettings(QSettings *settings) const ...@@ -67,8 +67,7 @@ void Settings::toSettings(QSettings *settings) const
void Settings::fromSettings(const QSettings *settings) void Settings::fromSettings(const QSettings *settings)
{ {
const QString rootKey = QLatin1String(groupC) + QLatin1Char('/'); const QString rootKey = QLatin1String(groupC) + QLatin1Char('/');
const char * const envKey = Utils::HostOsInfo::isWindowsHost() ? "USERNAME" : "USER"; const QString defaultUser = Utils::Environment::systemEnvironment().userName();
const QString defaultUser = QString::fromLocal8Bit(qgetenv(envKey));
username = settings->value(rootKey + QLatin1String(userNameKeyC), defaultUser).toString(); username = settings->value(rootKey + QLatin1String(userNameKeyC), defaultUser).toString();
protocol = settings->value(rootKey + QLatin1String(defaultProtocolKeyC), PasteBinDotComProtocol::protocolName()).toString(); protocol = settings->value(rootKey + QLatin1String(defaultProtocolKeyC), PasteBinDotComProtocol::protocolName()).toString();
copyToClipboard = settings->value(rootKey + QLatin1String(copyToClipboardKeyC), true).toBool(); copyToClipboard = settings->value(rootKey + QLatin1String(copyToClipboardKeyC), true).toBool();
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/hostosinfo.h> #include <utils/environment.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <QSettings> #include <QSettings>
...@@ -151,8 +151,7 @@ static bool keyWordReplacement(const QString &keyWord, ...@@ -151,8 +151,7 @@ static bool keyWordReplacement(const QString &keyWord,
return true; return true;
} }
if (keyWord == QLatin1String("%USER%")) { if (keyWord == QLatin1String("%USER%")) {
const char * const envKey = Utils::HostOsInfo::isWindowsHost() ? "USERNAME" : "USER"; *value = Utils::Environment::systemEnvironment().userName();
*value = QString::fromLocal8Bit(qgetenv(envKey));
return true; return true;
} }
// Environment variables (for example '%$EMAIL%'). // Environment variables (for example '%$EMAIL%').
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment