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
6061using namespace QtAutoUpdater ;
6162
62- #define KDESU_COMMAND QStringLiteral (" /usr/bin/kdesu" )
6363#define SU_COMMAND " /usr/bin/sudo"
6464
6565static 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
6872bool AdminAuthorization::hasAdminRights ()
@@ -72,20 +76,21 @@ bool AdminAuthorization::hasAdminRights()
7276
7377bool 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
9196static bool execAdminFallback (const QString &program, const QStringList &arguments)
0 commit comments