Commit f1b3c0e0 authored by Richard Liebscher's avatar Richard Liebscher Committed by Nicolas Fella
Browse files

Better device name in Sailfish OS

parent f3656d96
Pipeline #29411 passed with stage
in 10 minutes and 19 seconds
......@@ -58,6 +58,29 @@ struct KdeConnectConfigPrivate {
static QString getDefaultDeviceName() {
const QString hwReleaseFile = QStringLiteral("/etc/hw-release");
// QSettings will crash if the file does not exist or can be created, like in this case by us in /etc.
// E.g. in the SFOS SDK Emulator there is no such file, so check before to protect against the crash.
if (QFile::exists(hwReleaseFile)) {
QSettings hwRelease(hwReleaseFile, QSettings::IniFormat);
auto hwName = hwRelease.value(QStringLiteral("NAME")).toString();
if (!hwName.isEmpty()) {
return hwName;
#ifdef Q_OS_WIN
QString username = QString::fromLatin1(qgetenv("USERNAME"));
QString username = QString::fromLatin1(qgetenv("USER"));
return username + QStringLiteral("@") + QHostInfo::localHostName();
KdeConnectConfig& KdeConnectConfig::instance()
static KdeConnectConfig kcc;
......@@ -86,19 +109,15 @@ KdeConnectConfig::KdeConnectConfig()
if (name().isEmpty()) {
QString KdeConnectConfig::name()
QString username;
#ifdef Q_OS_WIN
username = QString::fromLatin1(qgetenv("USERNAME"));
username = QString::fromLatin1(qgetenv("USER"));
QString defaultName = username + QStringLiteral("@") + QHostInfo::localHostName();
QString name = d->m_config->value(QStringLiteral("name"), defaultName).toString();
return name;
return d->m_config->value(QStringLiteral("name")).toString();
void KdeConnectConfig::setName(const QString& name)
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