Skip to content

Commit 593b3d3

Browse files
committed
improved linux sudo gui
1 parent 3650994 commit 593b3d3

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ sudo: required
88
env:
99
global:
1010
- QT_VER=5.9.1
11-
- PROJECT=QtAutoUpdater
1211

1312
matrix:
1413
include:

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ version: build-{build}
66

77
environment:
88
QT_VER: 5.9.1
9-
PROJECT: QtAutoUpdater
109

1110
matrix:
1211
- PLATFORM: msvc2017_64

src/autoupdatergui/adminauthorization_x11.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,19 @@
5454
#include <sys/ioctl.h>
5555
#include <sys/types.h>
5656
#include <sys/wait.h>
57-
#include <QProcess>
57+
#include <QtCore/QProcess>
58+
#include <QtCore/QStandardPaths>
5859
#include <errno.h>
5960

6061
using namespace QtAutoUpdater;
6162

62-
#define KDESU_COMMAND QStringLiteral("/usr/bin/kdesu")
6363
#define SU_COMMAND "/usr/bin/sudo"
6464

6565
static bool execAdminFallback(const QString &program, const QStringList &arguments);
66+
static QList<QPair<QString, QStringList>> suFontends = {
67+
{QStringLiteral("kdesu"), {QStringLiteral("-c")}},
68+
{QStringLiteral("gksu"), {}}
69+
};
6670

6771
// has no guarantee to work
6872
bool AdminAuthorization::hasAdminRights()
@@ -72,20 +76,21 @@ bool AdminAuthorization::hasAdminRights()
7276

7377
bool AdminAuthorization::executeAsAdmin(const QString &program, const QStringList &arguments)
7478
{
75-
QString command;
76-
QStringList args;
79+
foreach(auto su, suFontends) {
80+
auto command = QStandardPaths::findExecutable(su.first);
81+
if(!command.isEmpty()) {
82+
auto args = su.second;
7783

78-
if(QFile::exists(KDESU_COMMAND)) {
79-
command = KDESU_COMMAND;
80-
args.append(QStringLiteral("-c"));
81-
} else
82-
return execAdminFallback(program, arguments);
84+
QStringList tmpList(program);
85+
tmpList.append(arguments);
86+
args.append(QLatin1Char('\"') + tmpList.join(QStringLiteral("\" \"")) + QLatin1Char('\"'));
8387

84-
QStringList tmpList(program);
85-
tmpList.append(arguments);
86-
args.append(QLatin1Char('\"') + tmpList.join(QStringLiteral("\" \"")) + QLatin1Char('\"'));
88+
return QProcess::startDetached(command, args);
89+
}
90+
}
91+
92+
return execAdminFallback(program, arguments);
8793

88-
return QProcess::startDetached(command, args);
8994
}
9095

9196
static bool execAdminFallback(const QString &program, const QStringList &arguments)

0 commit comments

Comments
 (0)