23 #include <dcopclient.h>
26 #include "tdeaboutdata.h"
27 #include "tdeapplication.h"
28 #include "tdecmdlineargs.h"
29 #include "tdeglobal.h"
30 #include "tdelocale.h"
32 #include "kservicegroup.h"
33 #include "kstandarddirs.h"
35 static TDECmdLineOptions options[] = {
36 {
"utf8", I18N_NOOP(
"Output data in UTF-8 instead of local encoding"), 0 },
37 {
"print-menu-id", I18N_NOOP(
"Print menu-id of the menu that contains\nthe application"), 0 },
38 {
"print-menu-name", I18N_NOOP(
"Print menu name (caption) of the menu that\ncontains the application"), 0 },
39 {
"highlight", I18N_NOOP(
"Highlight the entry in the menu"), 0 },
40 {
"nocache-update", I18N_NOOP(
"Do not check if sycoca database is up to date"), 0 },
41 {
"+<application-id>", I18N_NOOP(
"The id of the menu entry to locate"), 0 },
45 static const char appName[] =
"tde-menu";
46 static const char appVersion[] =
"1.0";
49 static bool bPrintMenuId;
50 static bool bPrintMenuName;
51 static bool bHighlight;
53 static void result(
const TQString &txt)
58 puts( txt.local8Bit() );
61 static void error(
int exitCode,
const TQString &txt)
63 tqWarning(
"tde-menu: %s", txt.local8Bit().data());
67 static void findMenuEntry(KServiceGroup::Ptr parent,
const TQString &name,
const TQString &menuId)
69 KServiceGroup::List list = parent->entries(
true,
true,
false);
70 KServiceGroup::List::ConstIterator it = list.begin();
71 for (; it != list.end(); ++it)
73 KSycocaEntry * e = *it;
75 if (e->isType(KST_KServiceGroup))
77 KServiceGroup::Ptr g(
static_cast<KServiceGroup *
>(e));
79 findMenuEntry(g, name.isEmpty() ? g->caption() : name+
"/"+g->caption(), menuId);
81 else if (e->isType(KST_KService))
83 KService::Ptr s(
static_cast<KService *
>(e));
84 if (s->menuId() == menuId)
88 result(parent->relPath());
96 DCOPRef kicker(
"kicker",
"kicker" );
97 bool result = kicker.call(
"highlightMenuItem", menuId );
99 error(3, TQString(i18n(
"Menu item '%1' could not be highlighted.").arg(menuId)).local8Bit());
108 int main(
int argc,
char **argv)
110 TDELocale::setMainCatalogue(
"tdelibs");
111 const char *description = I18N_NOOP(
"TDE Menu query tool.\n"
112 "This tool can be used to find in which menu a specific application is shown.\n"
113 "The --highlight option can be used to visually indicate to the user where\n"
114 "in the TDE menu a specific application is located.");
116 TDEAboutData d(appName, I18N_NOOP(
"tde-menu"), appVersion,
118 TDEAboutData::License_GPL,
"(c) 2003 Waldo Bastian");
119 d.addAuthor(
"Waldo Bastian", I18N_NOOP(
"Author"),
"bastian@kde.org");
121 TDECmdLineArgs::init(argc, argv, &d);
122 TDECmdLineArgs::addCmdLineOptions(options);
125 TDEApplication k(
false);
126 k.disableSessionManagement();
129 TDELocale::setMainCatalogue(
"tdelibs");
131 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
132 if (args->count() != 1)
133 TDECmdLineArgs::usage(i18n(
"You must specify an application-id such as 'tde-konsole.desktop'"));
135 utf8 = args->isSet(
"utf8");
137 bPrintMenuId = args->isSet(
"print-menu-id");
138 bPrintMenuName = args->isSet(
"print-menu-name");
139 bHighlight = args->isSet(
"highlight");
141 if (!bPrintMenuId && !bPrintMenuName && !bHighlight)
142 TDECmdLineArgs::usage(i18n(
"You must specify at least one of --print-menu-id, --print-menu-name or --highlight"));
144 if (args->isSet(
"cache-update"))
147 args.append(
"--incremental");
148 args.append(
"--checkstamps");
149 TQString command =
"tdebuildsycoca";
150 TQCString _launcher = TDEApplication::launcher();
151 if (!DCOPRef(_launcher, _launcher).call(
"tdeinit_exec_wait", command, args).isValid())
153 tqWarning(
"Can't talk to tdelauncher!");
154 command = TDEGlobal::dirs()->findExe(command);
155 command +=
" " + args.join(
" ");
156 system(command.local8Bit());
160 TQString menuId = TQFile::decodeName(args->arg(0));
161 KService::Ptr s = KService::serviceByMenuId(menuId);
164 error(1, i18n(
"No menu item '%1'.").arg(menuId));
166 findMenuEntry(KServiceGroup::root(),
"", menuId);
168 error(2, i18n(
"Menu item '%1' not found in menu.").arg(menuId));