• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kded
 

kded

  • kded
tde-menu.cpp
1 /* This file is part of the KDE libraries
2  * Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License version 2 as published by the Free Software Foundation;
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public License
14  * along with this library; see the file COPYING.LIB. If not, write to
15  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301, USA.
17  **/
18 
19 #include <stdlib.h>
20 
21 #include <tqfile.h>
22 
23 #include <dcopclient.h>
24 #include <dcopref.h>
25 
26 #include "tdeaboutdata.h"
27 #include "tdeapplication.h"
28 #include "tdecmdlineargs.h"
29 #include "tdeglobal.h"
30 #include "tdelocale.h"
31 #include "kservice.h"
32 #include "kservicegroup.h"
33 #include "kstandarddirs.h"
34 
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 },
42  TDECmdLineLastOption
43 };
44 
45 static const char appName[] = "tde-menu";
46 static const char appVersion[] = "1.0";
47 static bool utf8;
48 
49 static bool bPrintMenuId;
50 static bool bPrintMenuName;
51 static bool bHighlight;
52 
53 static void result(const TQString &txt)
54 {
55  if (utf8)
56  puts( txt.utf8() );
57  else
58  puts( txt.local8Bit() );
59 }
60 
61 static void error(int exitCode, const TQString &txt)
62 {
63  tqWarning("tde-menu: %s", txt.local8Bit().data());
64  exit(exitCode);
65 }
66 
67 static void findMenuEntry(KServiceGroup::Ptr parent, const TQString &name, const TQString &menuId)
68 {
69  KServiceGroup::List list = parent->entries(true, true, false);
70  KServiceGroup::List::ConstIterator it = list.begin();
71  for (; it != list.end(); ++it)
72  {
73  KSycocaEntry * e = *it;
74 
75  if (e->isType(KST_KServiceGroup))
76  {
77  KServiceGroup::Ptr g(static_cast<KServiceGroup *>(e));
78 
79  findMenuEntry(g, name.isEmpty() ? g->caption() : name+"/"+g->caption(), menuId);
80  }
81  else if (e->isType(KST_KService))
82  {
83  KService::Ptr s(static_cast<KService *>(e));
84  if (s->menuId() == menuId)
85  {
86  if (bPrintMenuId)
87  {
88  result(parent->relPath());
89  }
90  if (bPrintMenuName)
91  {
92  result(name);
93  }
94  if (bHighlight)
95  {
96  DCOPRef kicker( "kicker", "kicker" );
97  bool result = kicker.call( "highlightMenuItem", menuId );
98  if (!result)
99  error(3, TQString(i18n("Menu item '%1' could not be highlighted.").arg(menuId)).local8Bit());
100  }
101  exit(0);
102  }
103  }
104  }
105 }
106 
107 
108 int main(int argc, char **argv)
109 {
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.");
115 
116  TDEAboutData d(appName, I18N_NOOP("tde-menu"), appVersion,
117  description,
118  TDEAboutData::License_GPL, "(c) 2003 Waldo Bastian");
119  d.addAuthor("Waldo Bastian", I18N_NOOP("Author"), "bastian@kde.org");
120 
121  TDECmdLineArgs::init(argc, argv, &d);
122  TDECmdLineArgs::addCmdLineOptions(options);
123 
124 // TDEApplication k(false, false);
125  TDEApplication k(false);
126  k.disableSessionManagement();
127 
128  // this program is in tdelibs so it uses tdelibs as catalog
129  TDELocale::setMainCatalogue("tdelibs");
130 
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'"));
134 
135  utf8 = args->isSet("utf8");
136 
137  bPrintMenuId = args->isSet("print-menu-id");
138  bPrintMenuName = args->isSet("print-menu-name");
139  bHighlight = args->isSet("highlight");
140 
141  if (!bPrintMenuId && !bPrintMenuName && !bHighlight)
142  TDECmdLineArgs::usage(i18n("You must specify at least one of --print-menu-id, --print-menu-name or --highlight"));
143 
144  if (args->isSet("cache-update"))
145  {
146  TQStringList args;
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())
152  {
153  tqWarning("Can't talk to tdelauncher!");
154  command = TDEGlobal::dirs()->findExe(command);
155  command += " " + args.join(" ");
156  system(command.local8Bit());
157  }
158  }
159 
160  TQString menuId = TQFile::decodeName(args->arg(0));
161  KService::Ptr s = KService::serviceByMenuId(menuId);
162 
163  if (!s)
164  error(1, i18n("No menu item '%1'.").arg(menuId));
165 
166  findMenuEntry(KServiceGroup::root(), "", menuId);
167 
168  error(2, i18n("Menu item '%1' not found in menu.").arg(menuId));
169  return 2;
170 }
171 

kded

Skip menu "kded"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kded

Skip menu "kded"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kded by doxygen 1.9.1
This website is maintained by Timothy Pearson.