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

tdecmshell

  • tdecmshell
main.cpp
1 /*
2  Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
3  Copyright (c) 2000 Matthias Elter <elter@kde.org>
4  Copyright (c) 2004 Frans Englich <frans.englich@telia.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20 */
21 
22 #include <iostream>
23 
24 #include <tqcstring.h>
25 #include <tqfile.h>
26 
27 #include <dcopclient.h>
28 #include <qxembed.h>
29 
30 #include <tdeaboutdata.h>
31 #include <tdeapplication.h>
32 #include <tdecmdlineargs.h>
33 #include <tdecmoduleinfo.h>
34 #include <tdecmoduleloader.h>
35 #include <tdecmoduleproxy.h>
36 #include <kcmultidialog.h>
37 #include <kdebug.h>
38 #include <kdialogbase.h>
39 #include <kiconloader.h>
40 #include <tdelocale.h>
41 #include <kservice.h>
42 #include <kservicegroup.h>
43 #include <tdestartupinfo.h>
44 #include <twin.h>
45 #include <tdeglobal.h>
46 
47 #include "main.h"
48 #include "main.moc"
49 
50 using namespace std;
51 
52 KService::List m_modules;
53 
54 static TDECmdLineOptions options[] =
55 {
56  { "list", I18N_NOOP("List all possible modules"), 0},
57  { "+module", I18N_NOOP("Configuration module to open"), 0 },
58  { "lang <language>", I18N_NOOP("Specify a particular language"), 0 },
59  { "embed <id>", I18N_NOOP("Embeds the module with buttons in window with id <id>"), 0 },
60  { "embed-proxy <id>", I18N_NOOP("Embeds the module without buttons in window with id <id>"), 0 },
61  { "silent", I18N_NOOP("Do not display main window"), 0 },
62  TDECmdLineLastOption
63 };
64 
65 static void listModules(const TQString &baseGroup)
66 {
67 
68  KServiceGroup::Ptr group = KServiceGroup::group(baseGroup);
69 
70  if (!group || !group->isValid())
71  return;
72 
73  KServiceGroup::List list = group->entries(true, true);
74 
75  for( KServiceGroup::List::ConstIterator it = list.begin();
76  it != list.end(); it++)
77  {
78  KSycocaEntry *p = (*it);
79  if (p->isType(KST_KService))
80  {
81  KService *s = static_cast<KService*>(p);
82  if (!kapp->authorizeControlModule(s->menuId()))
83  continue;
84  m_modules.append(s);
85  }
86  else if (p->isType(KST_KServiceGroup))
87  listModules(p->entryPath());
88  }
89 }
90 
91 static KService::Ptr locateModule(const TQCString& module)
92 {
93  TQString path = TQFile::decodeName(module);
94 
95  if (!path.endsWith(".desktop"))
96  path += ".desktop";
97 
98  KService::Ptr service = KService::serviceByStorageId( path );
99  if (!service)
100  {
101  kdWarning(780) << "Could not find module '" << module << "'." << endl;
102  return 0;
103  }
104 
105  // avoid finding random non-TDE applications
106  if ( module.left( 4 ) != "tde-" && service->library().isEmpty() )
107  return locateModule( "tde-" + module );
108 
109  if(!TDECModuleLoader::testModule( module ))
110  {
111  kdDebug(780) << "According to \"" << module << "\"'s test function, it should Not be loaded." << endl;
112  return 0;
113  }
114 
115  return service;
116 }
117 
118 bool KCMShell::isRunning()
119 {
120  if( dcopClient()->appId() == m_dcopName )
121  return false; // We are the one and only.
122 
123  kdDebug(780) << "tdecmshell with modules '" <<
124  m_dcopName << "' is already running." << endl;
125 
126  dcopClient()->attach(); // Reregister as anonymous
127  dcopClient()->setNotifications(true);
128 
129  TQByteArray data;
130  TQDataStream str( data, IO_WriteOnly );
131  str << kapp->startupId();
132  TQCString replyType;
133  TQByteArray replyData;
134  if (!dcopClient()->call(m_dcopName, "dialog", "activate(TQCString)",
135  data, replyType, replyData))
136  {
137  kdDebug(780) << "Calling DCOP function dialog::activate() failed." << endl;
138  return false; // Error, we have to do it ourselves.
139  }
140 
141  return true;
142 }
143 
144 KCMShellMultiDialog::KCMShellMultiDialog( int dialogFace, const TQString& caption,
145  TQWidget *parent, const char *name, bool modal)
146  : KCMultiDialog( dialogFace, caption, parent, name, modal ),
147  DCOPObject("dialog")
148 {
149 }
150 
151 void KCMShellMultiDialog::activate( TQCString asn_id )
152 {
153  kdDebug(780) << k_funcinfo << endl;
154 
155  TDEStartupInfo::setNewStartupId( this, asn_id );
156 }
157 
158 void KCMShell::setDCOPName(const TQCString &dcopName, bool rootMode )
159 {
160  m_dcopName = "tdecmshell_";
161  if( rootMode )
162  m_dcopName += "rootMode_";
163 
164  m_dcopName += dcopName;
165 
166  dcopClient()->registerAs(m_dcopName, false);
167 }
168 
169 void KCMShell::waitForExit()
170 {
171  kdDebug(780) << k_funcinfo << endl;
172 
173  connect(dcopClient(), TQ_SIGNAL(applicationRemoved(const TQCString&)),
174  TQ_SLOT( appExit(const TQCString&) ));
175  exec();
176 }
177 
178 void KCMShell::appExit(const TQCString &appId)
179 {
180  kdDebug(780) << k_funcinfo << endl;
181 
182  if( appId == m_dcopName )
183  {
184  kdDebug(780) << "'" << appId << "' closed, dereferencing." << endl;
185  deref();
186  }
187 }
188 
189 static void setIcon(TQWidget *w, const TQString &iconName)
190 {
191  TQPixmap icon = DesktopIcon(iconName);
192  TQPixmap miniIcon = SmallIcon(iconName);
193  w->setIcon( icon ); //standard X11
194 #if defined TQ_WS_X11 && ! defined K_WS_QTONLY
195  KWin::setIcons(w->winId(), icon, miniIcon );
196 #endif
197 }
198 
199 extern "C" TDE_EXPORT int kdemain(int _argc, char *_argv[])
200 {
201  TDEAboutData aboutData( "tdecmshell", I18N_NOOP("TDE Control Module"),
202  0,
203  I18N_NOOP("A tool to start single TDE control modules"),
204  TDEAboutData::License_GPL,
205  I18N_NOOP("(c) 1999-2004, The KDE Developers") );
206 
207  aboutData.addAuthor("Frans Englich", I18N_NOOP("Maintainer"), "frans.englich@kde.org");
208  aboutData.addAuthor("Daniel Molkentin", 0, "molkentin@kde.org");
209  aboutData.addAuthor("Matthias Hoelzer-Kluepfel",0, "hoelzer@kde.org");
210  aboutData.addAuthor("Matthias Elter",0, "elter@kde.org");
211  aboutData.addAuthor("Matthias Ettrich",0, "ettrich@kde.org");
212  aboutData.addAuthor("Waldo Bastian",0, "bastian@kde.org");
213 
214  TDEGlobal::locale()->setMainCatalogue("tdecmshell");
215 
216  TDECmdLineArgs::init(_argc, _argv, &aboutData);
217  TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options.
218  KCMShell app;
219 
220  const TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
221 
222  const TQCString lang = args->getOption("lang");
223  if( !lang.isNull() )
224  TDEGlobal::locale()->setLanguage(lang);
225 
226  if (args->isSet("list"))
227  {
228  cout << static_cast<const char *>(i18n("The following modules are available:").local8Bit()) << endl;
229 
230  listModules( "Settings/" );
231 
232  int maxLen=0;
233 
234  for (KService::List::ConstIterator it = m_modules.begin(); it != m_modules.end(); ++it)
235  {
236  int len = (*it)->desktopEntryName().length();
237  if (len > maxLen)
238  maxLen = len;
239  }
240 
241  TQStringList module_list;
242  for (KService::List::ConstIterator it = m_modules.begin(); it != m_modules.end(); ++it)
243  {
244  module_list.append(TQString("%1 - %2")
245  .arg((*it)->desktopEntryName().leftJustify(maxLen, ' '))
246  .arg(!(*it)->comment().isEmpty() ? (*it)->comment() : i18n("No description available")));
247  }
248  module_list.sort();
249 
250  for (TQStringList::Iterator it=module_list.begin(); it!=module_list.end(); ++it)
251  {
252  cout << static_cast<const char *>((*it).local8Bit()) << endl;
253  }
254  return 0;
255  }
256 
257  if (args->count() < 1)
258  {
259  args->usage();
260  return -1;
261  }
262 
263  TQCString dcopName;
264  KService::List modules;
265  for (int i = 0; i < args->count(); i++)
266  {
267  KService::Ptr service = locateModule(args->arg(i));
268  if( service )
269  {
270  modules.append(service);
271  if( !dcopName.isEmpty() )
272  dcopName += "_";
273 
274  dcopName += args->arg(i);
275  }
276  }
277 
278  /* Check if this particular module combination is already running, but
279  * allow the same module to run when embedding(root mode) */
280  app.setDCOPName(dcopName,
281  ( args->isSet( "embed-proxy" ) || args->isSet( "embed" )));
282  if( app.isRunning() )
283  {
284  app.waitForExit();
285  return 0;
286  }
287 
288  KDialogBase::DialogType dtype = KDialogBase::Plain;
289  if ( modules.count() < 1 )
290  return 0;
291  else if( modules.count() > 1 )
292  dtype = KDialogBase::IconList;
293 
294  bool idValid;
295  int id;
296 
297  if ( args->isSet( "embed-proxy" ))
298  {
299  id = args->getOption( "embed-proxy" ).toInt(&idValid);
300  if( idValid )
301  {
302  TDECModuleProxy *module = new TDECModuleProxy( modules.first()->desktopEntryName() );
303  module->realModule();
304  QXEmbed::embedClientIntoWindow( module, id);
305  app.exec();
306  delete module;
307  }
308  else
309  kdDebug(780) << "Supplied id '" << id << "' is not valid." << endl;
310 
311  return 0;
312 
313  }
314 
315  KCMShellMultiDialog *dlg = new KCMShellMultiDialog( dtype,
316  i18n("Configure - %1").arg(kapp->caption()), 0, "", true );
317 
318  for (KService::List::ConstIterator it = modules.begin(); it != modules.end(); ++it)
319  dlg->addModule(TDECModuleInfo(*it));
320 
321  if ( args->isSet( "embed" ))
322  {
323  id = args->getOption( "embed" ).toInt(&idValid);
324  if( idValid )
325  {
326  QXEmbed::embedClientIntoWindow( dlg, id );
327  dlg->exec();
328  delete dlg;
329  }
330  else
331  kdDebug(780) << "Supplied id '" << id << "' is not valid." << endl;
332 
333  }
334  else
335  {
336 
337  if (kapp->iconName() != kapp->name())
338  setIcon(dlg, kapp->iconName());
339  else if ( modules.count() == 1 )
340  setIcon(dlg, TDECModuleInfo( modules.first()).icon());
341 
342  dlg->exec();
343  delete dlg;
344  }
345 
346  return 0;
347 }
KCMShellMultiDialog
Essentially a plain KCMultiDialog, but has the additional functionality of allowing it to be told to ...
Definition: main.h:83
KCMShell
The TDEApplication instance for tdecmshell.
Definition: main.h:34
KCMShell::setDCOPName
void setDCOPName(const TQCString &dcopName, bool rootMode)
Sets m_dcopName basically to dcopName, and then registers with DCOP.
Definition: main.cpp:158
KCMShell::isRunning
bool isRunning()
Definition: main.cpp:118
KCMShell::waitForExit
void waitForExit()
Waits until the last instance of tdecmshell with the same module as this one exits,...
Definition: main.cpp:169

tdecmshell

Skip menu "tdecmshell"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tdecmshell

Skip menu "tdecmshell"
  • 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 tdecmshell by doxygen 1.9.1
This website is maintained by Timothy Pearson.