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)
return m_values.contains(key);
}
QString Environment::userName() const
{
return value(QLatin1String(HostOsInfo::isWindowsHost() ? "USERNAME" : "USER"));
}
bool Environment::operator!=(const Environment &other) const
{
return !(*this == other);
......
......@@ -79,6 +79,8 @@ public:
QList<EnvironmentItem> diff(const Environment &other) const;
bool hasKey(const QString &key);
QString userName() const;
void appendOrSet(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 @@
#include "settings.h"
#include "pastebindotcomprotocol.h"
#include <utils/hostosinfo.h>
#include <utils/environment.h>
#include <QVariant>
#include <QSettings>
......@@ -67,8 +67,7 @@ void Settings::toSettings(QSettings *settings) const
void Settings::fromSettings(const QSettings *settings)
{
const QString rootKey = QLatin1String(groupC) + QLatin1Char('/');
const char * const envKey = Utils::HostOsInfo::isWindowsHost() ? "USERNAME" : "USER";
const QString defaultUser = QString::fromLocal8Bit(qgetenv(envKey));
const QString defaultUser = Utils::Environment::systemEnvironment().userName();
username = settings->value(rootKey + QLatin1String(userNameKeyC), defaultUser).toString();
protocol = settings->value(rootKey + QLatin1String(defaultProtocolKeyC), PasteBinDotComProtocol::protocolName()).toString();
copyToClipboard = settings->value(rootKey + QLatin1String(copyToClipboardKeyC), true).toBool();
......
......@@ -39,7 +39,7 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/hostosinfo.h>
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <QSettings>
......@@ -151,8 +151,7 @@ static bool keyWordReplacement(const QString &keyWord,
return true;
}
if (keyWord == QLatin1String("%USER%")) {
const char * const envKey = Utils::HostOsInfo::isWindowsHost() ? "USERNAME" : "USER";
*value = QString::fromLocal8Bit(qgetenv(envKey));
*value = Utils::Environment::systemEnvironment().userName();
return true;
}
// 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