24 #include <tqcstring.h>
27 #include <dcopclient.h>
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>
38 #include <kdialogbase.h>
39 #include <kiconloader.h>
40 #include <tdelocale.h>
42 #include <kservicegroup.h>
43 #include <tdestartupinfo.h>
45 #include <tdeglobal.h>
52 KService::List m_modules;
54 static TDECmdLineOptions options[] =
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 },
65 static void listModules(
const TQString &baseGroup)
68 KServiceGroup::Ptr group = KServiceGroup::group(baseGroup);
70 if (!group || !group->isValid())
73 KServiceGroup::List list = group->entries(
true,
true);
75 for( KServiceGroup::List::ConstIterator it = list.begin();
76 it != list.end(); it++)
78 KSycocaEntry *p = (*it);
79 if (p->isType(KST_KService))
81 KService *s =
static_cast<KService*
>(p);
82 if (!kapp->authorizeControlModule(s->menuId()))
86 else if (p->isType(KST_KServiceGroup))
87 listModules(p->entryPath());
91 static KService::Ptr locateModule(
const TQCString& module)
93 TQString path = TQFile::decodeName(module);
95 if (!path.endsWith(
".desktop"))
98 KService::Ptr service = KService::serviceByStorageId( path );
101 kdWarning(780) <<
"Could not find module '" << module <<
"'." << endl;
106 if ( module.left( 4 ) !=
"tde-" && service->library().isEmpty() )
107 return locateModule(
"tde-" + module );
109 if(!TDECModuleLoader::testModule( module ))
111 kdDebug(780) <<
"According to \"" << module <<
"\"'s test function, it should Not be loaded." << endl;
120 if( dcopClient()->appId() == m_dcopName )
123 kdDebug(780) <<
"tdecmshell with modules '" <<
124 m_dcopName <<
"' is already running." << endl;
126 dcopClient()->attach();
127 dcopClient()->setNotifications(
true);
130 TQDataStream str( data, IO_WriteOnly );
131 str << kapp->startupId();
133 TQByteArray replyData;
134 if (!dcopClient()->call(m_dcopName,
"dialog",
"activate(TQCString)",
135 data, replyType, replyData))
137 kdDebug(780) <<
"Calling DCOP function dialog::activate() failed." << endl;
144 KCMShellMultiDialog::KCMShellMultiDialog(
int dialogFace,
const TQString& caption,
145 TQWidget *parent,
const char *name,
bool modal)
146 : KCMultiDialog( dialogFace, caption, parent, name, modal ),
151 void KCMShellMultiDialog::activate( TQCString asn_id )
153 kdDebug(780) << k_funcinfo << endl;
155 TDEStartupInfo::setNewStartupId(
this, asn_id );
160 m_dcopName =
"tdecmshell_";
162 m_dcopName +=
"rootMode_";
164 m_dcopName += dcopName;
166 dcopClient()->registerAs(m_dcopName,
false);
171 kdDebug(780) << k_funcinfo << endl;
173 connect(dcopClient(), TQ_SIGNAL(applicationRemoved(
const TQCString&)),
174 TQ_SLOT( appExit(
const TQCString&) ));
178 void KCMShell::appExit(
const TQCString &appId)
180 kdDebug(780) << k_funcinfo << endl;
182 if( appId == m_dcopName )
184 kdDebug(780) <<
"'" << appId <<
"' closed, dereferencing." << endl;
189 static void setIcon(TQWidget *w,
const TQString &iconName)
191 TQPixmap icon = DesktopIcon(iconName);
192 TQPixmap miniIcon = SmallIcon(iconName);
194 #if defined TQ_WS_X11 && ! defined K_WS_QTONLY
195 KWin::setIcons(w->winId(), icon, miniIcon );
199 extern "C" TDE_EXPORT
int kdemain(
int _argc,
char *_argv[])
201 TDEAboutData aboutData(
"tdecmshell", I18N_NOOP(
"TDE Control Module"),
203 I18N_NOOP(
"A tool to start single TDE control modules"),
204 TDEAboutData::License_GPL,
205 I18N_NOOP(
"(c) 1999-2004, The KDE Developers") );
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");
214 TDEGlobal::locale()->setMainCatalogue(
"tdecmshell");
216 TDECmdLineArgs::init(_argc, _argv, &aboutData);
217 TDECmdLineArgs::addCmdLineOptions( options );
220 const TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
222 const TQCString lang = args->getOption(
"lang");
224 TDEGlobal::locale()->setLanguage(lang);
226 if (args->isSet(
"list"))
228 cout << static_cast<const char *>(i18n(
"The following modules are available:").local8Bit()) << endl;
230 listModules(
"Settings/" );
234 for (KService::List::ConstIterator it = m_modules.begin(); it != m_modules.end(); ++it)
236 int len = (*it)->desktopEntryName().length();
241 TQStringList module_list;
242 for (KService::List::ConstIterator it = m_modules.begin(); it != m_modules.end(); ++it)
244 module_list.append(TQString(
"%1 - %2")
245 .arg((*it)->desktopEntryName().leftJustify(maxLen,
' '))
246 .arg(!(*it)->comment().isEmpty() ? (*it)->comment() : i18n(
"No description available")));
250 for (TQStringList::Iterator it=module_list.begin(); it!=module_list.end(); ++it)
252 cout << static_cast<const char *>((*it).local8Bit()) << endl;
257 if (args->count() < 1)
264 KService::List modules;
265 for (
int i = 0; i < args->count(); i++)
267 KService::Ptr service = locateModule(args->arg(i));
270 modules.append(service);
271 if( !dcopName.isEmpty() )
274 dcopName += args->arg(i);
281 ( args->isSet(
"embed-proxy" ) || args->isSet(
"embed" )));
288 KDialogBase::DialogType dtype = KDialogBase::Plain;
289 if ( modules.count() < 1 )
291 else if( modules.count() > 1 )
292 dtype = KDialogBase::IconList;
297 if ( args->isSet(
"embed-proxy" ))
299 id = args->getOption(
"embed-proxy" ).toInt(&idValid);
302 TDECModuleProxy *module =
new TDECModuleProxy( modules.first()->desktopEntryName() );
303 module->realModule();
304 QXEmbed::embedClientIntoWindow( module,
id);
309 kdDebug(780) <<
"Supplied id '" <<
id <<
"' is not valid." << endl;
316 i18n(
"Configure - %1").arg(kapp->caption()), 0,
"",
true );
318 for (KService::List::ConstIterator it = modules.begin(); it != modules.end(); ++it)
319 dlg->addModule(TDECModuleInfo(*it));
321 if ( args->isSet(
"embed" ))
323 id = args->getOption(
"embed" ).toInt(&idValid);
326 QXEmbed::embedClientIntoWindow( dlg,
id );
331 kdDebug(780) <<
"Supplied id '" <<
id <<
"' is not valid." << endl;
337 if (kapp->iconName() != kapp->name())
338 setIcon(dlg, kapp->iconName());
339 else if ( modules.count() == 1 )
340 setIcon(dlg, TDECModuleInfo( modules.first()).icon());
Essentially a plain KCMultiDialog, but has the additional functionality of allowing it to be told to ...
The TDEApplication instance for tdecmshell.
void setDCOPName(const TQCString &dcopName, bool rootMode)
Sets m_dcopName basically to dcopName, and then registers with DCOP.
void waitForExit()
Waits until the last instance of tdecmshell with the same module as this one exits,...