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

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 {
#endif
};
static QString getDefaultDeviceName() {
#ifdef SAILFISHOS
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;
}
}
#endif
#ifdef Q_OS_WIN
QString username = QString::fromLatin1(qgetenv("USERNAME"));
#else
QString username = QString::fromLatin1(qgetenv("USER"));
#endif
return username + QStringLiteral("@") + QHostInfo::localHostName();
}
KdeConnectConfig& KdeConnectConfig::instance()
{
static KdeConnectConfig kcc;
......@@ -86,19 +109,15 @@ KdeConnectConfig::KdeConnectConfig()
loadPrivateKey();
loadCertificate();
if (name().isEmpty()) {
setName(getDefaultDeviceName());
}
}
QString KdeConnectConfig::name()
{
QString username;
#ifdef Q_OS_WIN
username = QString::fromLatin1(qgetenv("USERNAME"));
#else
username = QString::fromLatin1(qgetenv("USER"));
#endif
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