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

kded

tde-menu.cpp

00001 /*  This file is part of the KDE libraries
00002  *  Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
00003  *
00004  *  This library is free software; you can redistribute it and/or
00005  *  modify it under the terms of the GNU Library General Public
00006  *  License version 2 as published by the Free Software Foundation;
00007  *
00008  *  This library is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  *  Library General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU Library General Public License
00014  *  along with this library; see the file COPYING.LIB.  If not, write to
00015  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  *  Boston, MA 02110-1301, USA.
00017  **/
00018 
00019 #include <stdlib.h>
00020 
00021 #include <tqfile.h>
00022 
00023 #include <dcopclient.h>
00024 #include <dcopref.h>
00025 
00026 #include "tdeaboutdata.h"
00027 #include "tdeapplication.h"
00028 #include "tdecmdlineargs.h"
00029 #include "tdeglobal.h"
00030 #include "tdelocale.h"
00031 #include "kservice.h"
00032 #include "kservicegroup.h"
00033 #include "kstandarddirs.h"
00034 
00035 static TDECmdLineOptions options[] = {
00036    { "utf8", I18N_NOOP("Output data in UTF-8 instead of local encoding"), 0 },
00037    { "print-menu-id", I18N_NOOP("Print menu-id of the menu that contains\nthe application"), 0 },
00038    { "print-menu-name", I18N_NOOP("Print menu name (caption) of the menu that\ncontains the application"), 0 },
00039    { "highlight", I18N_NOOP("Highlight the entry in the menu"), 0 },
00040    { "nocache-update", I18N_NOOP("Do not check if sycoca database is up to date"), 0 },
00041    { "+<application-id>", I18N_NOOP("The id of the menu entry to locate"), 0 },
00042    TDECmdLineLastOption
00043 };
00044 
00045 static const char appName[] = "tde-menu";
00046 static const char appVersion[] = "1.0";
00047 static bool utf8;
00048 
00049 static bool bPrintMenuId;
00050 static bool bPrintMenuName;
00051 static bool bHighlight;
00052 
00053 static void result(const TQString &txt)
00054 {
00055    if (utf8)
00056       puts( txt.utf8() );
00057    else
00058       puts( txt.local8Bit() );
00059 }
00060 
00061 static void error(int exitCode, const TQString &txt)
00062 {
00063    tqWarning("tde-menu: %s", txt.local8Bit().data());
00064    exit(exitCode);
00065 }
00066 
00067 static void findMenuEntry(KServiceGroup::Ptr parent, const TQString &name, const TQString &menuId)
00068 {
00069    KServiceGroup::List list = parent->entries(true, true, false);
00070    KServiceGroup::List::ConstIterator it = list.begin();
00071    for (; it != list.end(); ++it)
00072    {
00073       KSycocaEntry * e = *it;
00074 
00075       if (e->isType(KST_KServiceGroup))
00076       {
00077          KServiceGroup::Ptr g(static_cast<KServiceGroup *>(e));
00078          
00079          findMenuEntry(g, name.isEmpty() ? g->caption() : name+"/"+g->caption(), menuId);
00080       }
00081       else if (e->isType(KST_KService))
00082       {
00083          KService::Ptr s(static_cast<KService *>(e));
00084          if (s->menuId() == menuId)
00085          {
00086             if (bPrintMenuId)
00087             {
00088                result(parent->relPath());
00089             }
00090             if (bPrintMenuName)
00091             {
00092                result(name);
00093             }
00094             if (bHighlight)
00095             {
00096                DCOPRef kicker( "kicker", "kicker" );
00097                bool result = kicker.call( "highlightMenuItem", menuId );
00098                if (!result)
00099                   error(3, TQString(i18n("Menu item '%1' could not be highlighted.").arg(menuId)).local8Bit());
00100             }
00101             exit(0);
00102          }
00103       }
00104    }
00105 }
00106 
00107 
00108 int main(int argc, char **argv)
00109 {
00110    TDELocale::setMainCatalogue("tdelibs");
00111    const char *description = I18N_NOOP("TDE Menu query tool.\n"
00112    "This tool can be used to find in which menu a specific application is shown.\n"
00113    "The --highlight option can be used to visually indicate to the user where\n"
00114    "in the TDE menu a specific application is located.");
00115    
00116    TDEAboutData d(appName, I18N_NOOP("tde-menu"), appVersion,
00117                 description,
00118                 TDEAboutData::License_GPL, "(c) 2003 Waldo Bastian");
00119    d.addAuthor("Waldo Bastian", I18N_NOOP("Author"), "bastian@kde.org");
00120 
00121    TDECmdLineArgs::init(argc, argv, &d);
00122    TDECmdLineArgs::addCmdLineOptions(options);
00123 
00124 //   TDEApplication k(false, false);
00125    TDEApplication k(false);
00126    k.disableSessionManagement();
00127 
00128    // this program is in tdelibs so it uses tdelibs as catalog
00129    TDELocale::setMainCatalogue("tdelibs");
00130 
00131    TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
00132    if (args->count() != 1)
00133       TDECmdLineArgs::usage(i18n("You must specify an application-id such as 'tde-konsole.desktop'"));
00134 
00135    utf8 = args->isSet("utf8");
00136 
00137    bPrintMenuId = args->isSet("print-menu-id");
00138    bPrintMenuName = args->isSet("print-menu-name");
00139    bHighlight = args->isSet("highlight");
00140 
00141    if (!bPrintMenuId && !bPrintMenuName && !bHighlight)
00142       TDECmdLineArgs::usage(i18n("You must specify at least one of --print-menu-id, --print-menu-name or --highlight"));
00143 
00144    if (args->isSet("cache-update"))
00145    {
00146       TQStringList args;
00147       args.append("--incremental");
00148       args.append("--checkstamps");
00149       TQString command = "tdebuildsycoca";
00150       TQCString _launcher = TDEApplication::launcher();
00151       if (!DCOPRef(_launcher, _launcher).call("tdeinit_exec_wait", command, args).isValid())
00152       {
00153          tqWarning("Can't talk to tdelauncher!");
00154          command = TDEGlobal::dirs()->findExe(command);
00155          command += " " + args.join(" ");
00156          system(command.local8Bit());
00157       }
00158    }
00159 
00160    TQString menuId = TQFile::decodeName(args->arg(0));
00161    KService::Ptr s = KService::serviceByMenuId(menuId);
00162    
00163    if (!s)
00164       error(1, i18n("No menu item '%1'.").arg(menuId));
00165 
00166    findMenuEntry(KServiceGroup::root(), "", menuId);
00167 
00168    error(2, i18n("Menu item '%1' not found in menu.").arg(menuId));
00169    return 2;
00170 }
00171 

kded

Skip menu "kded"
  • Main Page
  • Class Hierarchy
  • 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.6.3
This website is maintained by Timothy Pearson.