From 8a4df319800c71dafdf612fd6a275117dc9f6f14 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 17 May 2024 02:24:54 +0300 Subject: [PATCH] kde-menu: do not run kbuildsycoca by default that is why it is separate program - run it before if update may be required Signed-off-by: Ivailo Monev --- kde-menu/kde-menu.cpp | 153 ++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 87 deletions(-) diff --git a/kde-menu/kde-menu.cpp b/kde-menu/kde-menu.cpp index d25875e1..040fdfe9 100644 --- a/kde-menu/kde-menu.cpp +++ b/kde-menu/kde-menu.cpp @@ -19,10 +19,7 @@ #include -#include -#include -#include -#include +#include #include #include @@ -33,122 +30,104 @@ #include #include #include +#include static const char appName[] = "kde-menu"; static const char appVersion[] = "1.0"; -static bool utf8; -static bool bPrintMenuId; -static bool bPrintMenuName; +static bool utf8 = false; +static bool bPrintMenuId = false; +static bool bPrintMenuName = false; static void result(const QString &txt) { - if (utf8) - puts( txt.toUtf8() ); - else - puts( txt.toLocal8Bit() ); + if (utf8) { + puts(txt.toUtf8()); + } else { + puts(txt.toLocal8Bit()); + } } static void error(int exitCode, const QString &txt) { - qWarning("kde-menu: %s", txt.toLocal8Bit().data()); - exit(exitCode); + qWarning("kde-menu: %s", txt.toLocal8Bit().data()); + exit(exitCode); } static void findMenuEntry(KServiceGroup::Ptr parent, const QString &name, const QString &menuId) { - const KServiceGroup::List list = parent->entries(true, true, false); - KServiceGroup::List::ConstIterator it = list.constBegin(); - for (; it != list.constEnd(); ++it) - { - KSycocaEntry::Ptr e = (*it); + const KServiceGroup::List list = parent->entries(true, true, false); + KServiceGroup::List::ConstIterator it = list.constBegin(); + for (; it != list.constEnd(); ++it) { + KSycocaEntry::Ptr e = (*it); - if (e->isType(KST_KServiceGroup)) - { - KServiceGroup::Ptr g = KServiceGroup::Ptr::staticCast( e ); + if (e->isType(KST_KServiceGroup)) { + KServiceGroup::Ptr g = KServiceGroup::Ptr::staticCast( e ); - findMenuEntry(g, name.isEmpty() ? g->caption() : name+'/'+g->caption(), menuId); - } - else if (e->isType(KST_KService)) - { - KService::Ptr s = KService::Ptr::staticCast( e ); - if (s->menuId() == menuId) - { - if (bPrintMenuId) - { - result(parent->relPath()); + findMenuEntry(g, name.isEmpty() ? g->caption() : name + '/' + g->caption(), menuId); + } else if (e->isType(KST_KService)) { + KService::Ptr s = KService::Ptr::staticCast(e); + if (s->menuId() == menuId) { + if (bPrintMenuId) { + result(parent->relPath()); + } + if (bPrintMenuName) { + result(name); + } + exit(0); } - if (bPrintMenuName) - { - result(name); - } - exit(0); - } - } - } + } + } } int main(int argc, char **argv) { - const char *description = I18N_NOOP("KDE Menu query tool.\n" - "This tool can be used to find in which menu a specific application is shown.\n" - "The --highlight option can be used to visually indicate to the user where\n" - "in the KDE menu a specific application is located."); + const char *description = I18N_NOOP( + "KDE Menu query tool.\n" + "This tool can be used to find in which menu a specific application is shown.\n" + ); - KAboutData d(appName, "kde-menu", ki18n("kde-menu"), appVersion, - ki18n(description), - KAboutData::License_GPL, ki18n("(c) 2003 Waldo Bastian")); - d.addAuthor(ki18n("Waldo Bastian"), ki18n("Author"), "bastian@kde.org"); + KAboutData d( + appName, "kde-menu", ki18n("kde-menu"), appVersion, + ki18n(description), + KAboutData::License_GPL, ki18n("(c) 2003 Waldo Bastian")); + d.addAuthor(ki18n("Waldo Bastian"), ki18n("Author"), "bastian@kde.org"); - KCmdLineArgs::init(argc, argv, &d); + KCmdLineArgs::init(argc, argv, &d); - KCmdLineOptions options; - options.add("utf8", ki18n("Output data in UTF-8 instead of local encoding")); - options.add("print-menu-id", ki18n("Print menu-id of the menu that contains\nthe application")); - options.add("print-menu-name", ki18n("Print menu name (caption) of the menu that\ncontains the application")); - options.add("nocache-update", ki18n("Do not check if sycoca database is up to date")); - options.add("+", ki18n("The id of the menu entry to locate")); - KCmdLineArgs::addCmdLineOptions(options); + KCmdLineOptions options; + options.add("utf8", ki18n("Output data in UTF-8 instead of local encoding")); + options.add("print-menu-id", ki18n("Print menu-id of the menu that contains\nthe application")); + options.add("print-menu-name", ki18n("Print menu name (caption) of the menu that\ncontains the application")); + options.add("+", ki18n("The id of the menu entry to locate")); + KCmdLineArgs::addCmdLineOptions(options); - QCoreApplication app(argc, argv); + QCoreApplication app(argc, argv); - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - if (args->count() != 1) - KCmdLineArgs::usageError(i18n("You must specify an application-id such as 'konsole.desktop'")); + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if (args->count() != 1) { + KCmdLineArgs::usageError(i18n("You must specify an application-id such as 'konsole.desktop'")); + } - utf8 = args->isSet("utf8"); + utf8 = args->isSet("utf8"); + bPrintMenuId = args->isSet("print-menu-id"); + bPrintMenuName = args->isSet("print-menu-name"); - bPrintMenuId = args->isSet("print-menu-id"); - bPrintMenuName = args->isSet("print-menu-name"); + if (!bPrintMenuId && !bPrintMenuName) { + KCmdLineArgs::usageError(i18n("You must specify at least one of --print-menu-id or --print-menu-name")); + } - if (!bPrintMenuId && !bPrintMenuName) - KCmdLineArgs::usageError(i18n("You must specify at least one of --print-menu-id or --print-menu-name")); + QString menuId = args->arg(0); + KService::Ptr s = KService::serviceByMenuId(menuId); - if (args->isSet("cache-update")) - { - QStringList args; - args.append("--incremental"); - args.append("--checkstamps"); - QString command = KStandardDirs::findExe(KBUILDSYCOCA_EXENAME); - if (command.isEmpty()) - { - error(4, i18n("Could not find '%1' executable.", QLatin1String(KBUILDSYCOCA_EXENAME))); - } - if (QProcess::execute(command, args) != 0) { - error(5, i18n("Could not execute '%1'.", QLatin1String(KBUILDSYCOCA_EXENAME))); - } - } + if (!s) { + error(1, i18n("No menu item '%1'.", menuId)); + } - QString menuId = args->arg(0); - KService::Ptr s = KService::serviceByMenuId(menuId); + findMenuEntry(KServiceGroup::root(), "", menuId); - if (!s) - error(1, i18n("No menu item '%1'.", menuId)); - - findMenuEntry(KServiceGroup::root(), "", menuId); - - error(2, i18n("Menu item '%1' not found in menu.", menuId)); - return 2; + error(2, i18n("Menu item '%1' not found in menu.", menuId)); + return 2; }