Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Network
KDE Connect
Commits
f1b3c0e0
Commit
f1b3c0e0
authored
Aug 02, 2020
by
Richard Liebscher
Committed by
Nicolas Fella
Aug 02, 2020
Browse files
Better device name in Sailfish OS
parent
f3656d96
Pipeline
#29411
passed with stage
in 10 minutes and 19 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/kdeconnectconfig.cpp
View file @
f1b3c0e0
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment