From be7d2cf633e09edd2d26f0c32f106a4f5ab5378e Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 15 Jun 2021 05:17:45 +0300 Subject: [PATCH] generic: avoid global static KStandardDirs instance access Signed-off-by: Ivailo Monev --- kcontrol/keyboard/xkb_helper.cpp | 4 ++-- kde-menu/kde-menu.cpp | 11 ++++++++--- kdontchangethehostname/khostname.cpp | 2 +- ksmserver/server.cpp | 4 ++-- kwalletd/autotests/kwalletexecuter.cpp | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/kcontrol/keyboard/xkb_helper.cpp b/kcontrol/keyboard/xkb_helper.cpp index d7ebc696..10b9e07d 100644 --- a/kcontrol/keyboard/xkb_helper.cpp +++ b/kcontrol/keyboard/xkb_helper.cpp @@ -51,7 +51,7 @@ QString getSetxkbmapExe() return ""; if( setxkbmapExe.isEmpty() ) { - setxkbmapExe = KGlobal::dirs()->findExe(SETXKBMAP_EXEC); + setxkbmapExe = KStandardDirs::findExe(SETXKBMAP_EXEC); if( setxkbmapExe.isEmpty() ) { setxkbmapNotFound = true; kError() << "Can't find" << SETXKBMAP_EXEC << "- keyboard layouts won't be configured"; @@ -70,7 +70,7 @@ void executeXmodmap(const QString& configFileName) if( QFile(configFileName).exists() ) { if( xmodmapExe.isEmpty() ) { - xmodmapExe = KGlobal::dirs()->findExe(XMODMAP_EXEC); + xmodmapExe = KStandardDirs::findExe(XMODMAP_EXEC); if( xmodmapExe.isEmpty() ) { xmodmapNotFound = true; kError() << "Can't find" << XMODMAP_EXEC << "- xmodmap files won't be run"; diff --git a/kde-menu/kde-menu.cpp b/kde-menu/kde-menu.cpp index 6d6b4d90..c901a1e9 100644 --- a/kde-menu/kde-menu.cpp +++ b/kde-menu/kde-menu.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -146,13 +147,17 @@ int main(int argc, char **argv) args.append("--incremental"); args.append("--checkstamps"); QString command = KStandardDirs::findExe(KBUILDSYCOCA_EXENAME); + if (command.isEmpty()) + { + error(4, i18n("Could not find '%1' executable.", KBUILDSYCOCA_EXENAME)); + } QDBusMessage reply = KToolInvocation::klauncher()->call("kdeinit_exec_wait", command, args, QStringList(), QString()); if (reply.type() != QDBusMessage::ReplyMessage) { qWarning("Can not talk to klauncher!"); - command = KGlobal::dirs()->findExe(command); - command += ' ' + args.join(" "); - system(command.toLocal8Bit()); + if (QProcess::execute(command, args) != 0) { + error(5, i18n("Could not execute '%1'.", KBUILDSYCOCA_EXENAME)); + } } } diff --git a/kdontchangethehostname/khostname.cpp b/kdontchangethehostname/khostname.cpp index 17b01ab0..94492643 100644 --- a/kdontchangethehostname/khostname.cpp +++ b/kdontchangethehostname/khostname.cpp @@ -193,7 +193,7 @@ void KHostName::changeStdDirs(const QByteArray &type) } if (result != 0) { - const QString lnusertemp = KGlobal::dirs()->findExe( "lnusertemp" ); + const QString lnusertemp = KStandardDirs::findExe( "lnusertemp" ); QProcess::execute( lnusertemp, QStringList() << type ); } } diff --git a/ksmserver/server.cpp b/ksmserver/server.cpp index 99d0a92a..72edcbe4 100644 --- a/ksmserver/server.cpp +++ b/ksmserver/server.cpp @@ -456,7 +456,7 @@ Status SetAuthentication (int count, IceListenObj *listenObjs, fclose(addAuthFile); fclose(remAuthFile); - QString iceAuth = KGlobal::dirs()->findExe("iceauth"); + QString iceAuth = KStandardDirs::findExe("iceauth"); if (iceAuth.isEmpty()) { qWarning("KSMServer: could not find iceauth"); @@ -484,7 +484,7 @@ void FreeAuthenticationData(int count, IceAuthDataEntry *authDataEntries) free (authDataEntries); - QString iceAuth = KGlobal::dirs()->findExe("iceauth"); + QString iceAuth = KStandardDirs::findExe("iceauth"); if (iceAuth.isEmpty()) { qWarning("KSMServer: could not find iceauth"); diff --git a/kwalletd/autotests/kwalletexecuter.cpp b/kwalletd/autotests/kwalletexecuter.cpp index 6bdf8a05..22e3b6ce 100644 --- a/kwalletd/autotests/kwalletexecuter.cpp +++ b/kwalletd/autotests/kwalletexecuter.cpp @@ -117,7 +117,7 @@ void KWalletExecuter::execute_kwallet(int toWalletPipe[2], int envSocket) sprintf(sockIn, "%d", envSocket); qDebug() << "Executing kwalletd"; - QByteArray wallet = KStandardDirs::locate("exe", "kwalletd").toLocal8Bit(); + QByteArray wallet = KStandardDirs::findExec("kwalletd").toLocal8Bit(); char *args[] = {wallet.data(), (char*)"--pam-login", pipeInt, sockIn, NULL}; execve(args[0], args, environ); qFatal("Couldn't execute kwalletd");