mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
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 <xakepa10@gmail.com>
This commit is contained in:
parent
032fbe8217
commit
8a4df31980
1 changed files with 66 additions and 87 deletions
|
@ -19,10 +19,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <QtCore/QFile>
|
#include <QCoreApplication>
|
||||||
#include <QtCore/QCoreApplication>
|
|
||||||
#include <QtCore/QProcess>
|
|
||||||
#include <QtDBus/QtDBus>
|
|
||||||
|
|
||||||
#include <kaboutdata.h>
|
#include <kaboutdata.h>
|
||||||
#include <kapplication.h>
|
#include <kapplication.h>
|
||||||
|
@ -33,122 +30,104 @@
|
||||||
#include <kservicegroup.h>
|
#include <kservicegroup.h>
|
||||||
#include <kstandarddirs.h>
|
#include <kstandarddirs.h>
|
||||||
#include <ksycoca.h>
|
#include <ksycoca.h>
|
||||||
|
#include <kdebug.h>
|
||||||
|
|
||||||
static const char appName[] = "kde-menu";
|
static const char appName[] = "kde-menu";
|
||||||
static const char appVersion[] = "1.0";
|
static const char appVersion[] = "1.0";
|
||||||
static bool utf8;
|
|
||||||
|
|
||||||
static bool bPrintMenuId;
|
static bool utf8 = false;
|
||||||
static bool bPrintMenuName;
|
static bool bPrintMenuId = false;
|
||||||
|
static bool bPrintMenuName = false;
|
||||||
|
|
||||||
static void result(const QString &txt)
|
static void result(const QString &txt)
|
||||||
{
|
{
|
||||||
if (utf8)
|
if (utf8) {
|
||||||
puts( txt.toUtf8() );
|
puts(txt.toUtf8());
|
||||||
else
|
} else {
|
||||||
puts( txt.toLocal8Bit() );
|
puts(txt.toLocal8Bit());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void error(int exitCode, const QString &txt)
|
static void error(int exitCode, const QString &txt)
|
||||||
{
|
{
|
||||||
qWarning("kde-menu: %s", txt.toLocal8Bit().data());
|
qWarning("kde-menu: %s", txt.toLocal8Bit().data());
|
||||||
exit(exitCode);
|
exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void findMenuEntry(KServiceGroup::Ptr parent, const QString &name, const QString &menuId)
|
static void findMenuEntry(KServiceGroup::Ptr parent, const QString &name, const QString &menuId)
|
||||||
{
|
{
|
||||||
const KServiceGroup::List list = parent->entries(true, true, false);
|
const KServiceGroup::List list = parent->entries(true, true, false);
|
||||||
KServiceGroup::List::ConstIterator it = list.constBegin();
|
KServiceGroup::List::ConstIterator it = list.constBegin();
|
||||||
for (; it != list.constEnd(); ++it)
|
for (; it != list.constEnd(); ++it) {
|
||||||
{
|
KSycocaEntry::Ptr e = (*it);
|
||||||
KSycocaEntry::Ptr e = (*it);
|
|
||||||
|
|
||||||
if (e->isType(KST_KServiceGroup))
|
if (e->isType(KST_KServiceGroup)) {
|
||||||
{
|
KServiceGroup::Ptr g = KServiceGroup::Ptr::staticCast( e );
|
||||||
KServiceGroup::Ptr g = KServiceGroup::Ptr::staticCast( e );
|
|
||||||
|
|
||||||
findMenuEntry(g, name.isEmpty() ? g->caption() : name+'/'+g->caption(), menuId);
|
findMenuEntry(g, name.isEmpty() ? g->caption() : name + '/' + g->caption(), menuId);
|
||||||
}
|
} else if (e->isType(KST_KService)) {
|
||||||
else if (e->isType(KST_KService))
|
KService::Ptr s = KService::Ptr::staticCast(e);
|
||||||
{
|
if (s->menuId() == menuId) {
|
||||||
KService::Ptr s = KService::Ptr::staticCast( e );
|
if (bPrintMenuId) {
|
||||||
if (s->menuId() == menuId)
|
result(parent->relPath());
|
||||||
{
|
}
|
||||||
if (bPrintMenuId)
|
if (bPrintMenuName) {
|
||||||
{
|
result(name);
|
||||||
result(parent->relPath());
|
}
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
if (bPrintMenuName)
|
}
|
||||||
{
|
}
|
||||||
result(name);
|
|
||||||
}
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *description = I18N_NOOP("KDE Menu query tool.\n"
|
const char *description = I18N_NOOP(
|
||||||
"This tool can be used to find in which menu a specific application is shown.\n"
|
"KDE Menu query tool.\n"
|
||||||
"The --highlight option can be used to visually indicate to the user where\n"
|
"This tool can be used to find in which menu a specific application is shown.\n"
|
||||||
"in the KDE menu a specific application is located.");
|
);
|
||||||
|
|
||||||
KAboutData d(appName, "kde-menu", ki18n("kde-menu"), appVersion,
|
KAboutData d(
|
||||||
ki18n(description),
|
appName, "kde-menu", ki18n("kde-menu"), appVersion,
|
||||||
KAboutData::License_GPL, ki18n("(c) 2003 Waldo Bastian"));
|
ki18n(description),
|
||||||
d.addAuthor(ki18n("Waldo Bastian"), ki18n("Author"), "bastian@kde.org");
|
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;
|
KCmdLineOptions options;
|
||||||
options.add("utf8", ki18n("Output data in UTF-8 instead of local encoding"));
|
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-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("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("+<application-id>", ki18n("The id of the menu entry to locate"));
|
||||||
options.add("+<application-id>", ki18n("The id of the menu entry to locate"));
|
KCmdLineArgs::addCmdLineOptions(options);
|
||||||
KCmdLineArgs::addCmdLineOptions(options);
|
|
||||||
|
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
|
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
|
||||||
if (args->count() != 1)
|
if (args->count() != 1) {
|
||||||
KCmdLineArgs::usageError(i18n("You must specify an application-id such as 'konsole.desktop'"));
|
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");
|
if (!bPrintMenuId && !bPrintMenuName) {
|
||||||
bPrintMenuName = args->isSet("print-menu-name");
|
KCmdLineArgs::usageError(i18n("You must specify at least one of --print-menu-id or --print-menu-name"));
|
||||||
|
}
|
||||||
|
|
||||||
if (!bPrintMenuId && !bPrintMenuName)
|
QString menuId = args->arg(0);
|
||||||
KCmdLineArgs::usageError(i18n("You must specify at least one of --print-menu-id or --print-menu-name"));
|
KService::Ptr s = KService::serviceByMenuId(menuId);
|
||||||
|
|
||||||
if (args->isSet("cache-update"))
|
if (!s) {
|
||||||
{
|
error(1, i18n("No menu item '%1'.", menuId));
|
||||||
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)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString menuId = args->arg(0);
|
findMenuEntry(KServiceGroup::root(), "", menuId);
|
||||||
KService::Ptr s = KService::serviceByMenuId(menuId);
|
|
||||||
|
|
||||||
if (!s)
|
error(2, i18n("Menu item '%1' not found in menu.", menuId));
|
||||||
error(1, i18n("No menu item '%1'.", menuId));
|
return 2;
|
||||||
|
|
||||||
findMenuEntry(KServiceGroup::root(), "", menuId);
|
|
||||||
|
|
||||||
error(2, i18n("Menu item '%1' not found in menu.", menuId));
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue