aboutsummaryrefslogtreecommitdiff
path: root/singleapplication_p.cpp
diff options
context:
space:
mode:
authorItay Grudev <itay+github.com@grudev.com>2020-03-28 01:35:42 +0000
committerGitHub <noreply@github.com>2020-03-28 01:35:42 +0000
commit4baf2e74f64c9a6ce36d456491bb41d0f2ae999e (patch)
tree274c2e8bab52eb069317560810e8fee3eba87869 /singleapplication_p.cpp
parentMerge pull request #96 from itay-grudev/primary_user (diff)
parentAdd support for Qt < 5.10 (diff)
downloadsingleapplication-upstream.tar.xz
Merge pull request #97 from autoantwort/masterv3.1.1aupstream
SingleApplication::currentUser and codecs
Diffstat (limited to 'singleapplication_p.cpp')
-rw-r--r--singleapplication_p.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp
index 8eb49ab..ce50383 100644
--- a/singleapplication_p.cpp
+++ b/singleapplication_p.cpp
@@ -84,23 +84,33 @@ SingleApplicationPrivate::~SingleApplicationPrivate()
delete memory;
}
-QByteArray SingleApplicationPrivate::getUsername(){
+QString SingleApplicationPrivate::getUsername()
+{
#ifdef Q_OS_WIN
wchar_t username[UNLEN + 1];
// Specifies size of the buffer on input
DWORD usernameLength = UNLEN + 1;
if( GetUserNameW( username, &usernameLength ) )
- return QString::fromWCharArray( username ).toUtf8();
- return qgetenv( "USERNAME" );
+ return QString::fromWCharArray( username );
+#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
+ return QString::fromLocal8Bit( qgetenv( "USERNAME" ) );
+#else
+ return qEnvironmentVariable( "USERNAME" );
+#endif
#endif
#ifdef Q_OS_UNIX
- QByteArray username;
+ QString username;
uid_t uid = geteuid();
struct passwd *pw = getpwuid( uid );
if( pw )
- username = pw->pw_name;
- if( username.isEmpty() )
- username = qgetenv( "USER" );
+ username = QString::fromLocal8Bit( pw->pw_name );
+ if ( username.isEmpty() ) {
+#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
+ username = QString::fromLocal8Bit( qgetenv( "USER" ) );
+#else
+ username = qEnvironmentVariable( "USER" );
+#endif
+ }
return username;
#endif
}
@@ -127,7 +137,7 @@ void SingleApplicationPrivate::genBlockServerName()
// User level block requires a user specific data in the hash
if( options & SingleApplication::Mode::User ) {
- appData.addData( getUsername() );
+ appData.addData( getUsername().toUtf8() );
}
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with
@@ -175,7 +185,7 @@ void SingleApplicationPrivate::startPrimary()
inst->primary = true;
inst->primaryPid = q->applicationPid();
- strncpy( inst->primaryUser, getUsername().data(), 127 );
+ strncpy( inst->primaryUser, getUsername().toUtf8().data(), 127 );
inst->primaryUser[127] = '\0';
inst->checksum = blockChecksum();