26 #include <QtDBus/QtDBus>
29 #include <KApplication>
30 #include <KAuthorized>
31 #include <KCmdLineArgs>
32 #include <KCModuleInfo>
33 #include <KCMultiDialog>
36 #include <KServiceTypeTrader>
37 #include <KStartupInfo>
40 #include <kdeversion.h>
49 static int s_area = KDebug::registerArea(
"kcmshell");
55 const int compare = QString::compare(s1->desktopEntryName(),
56 s2->desktopEntryName(),
63 const KService::List services = KServiceTypeTrader::self()->query(
"KCModule",
"[X-KDE-ParentApp] == 'kcontrol' or [X-KDE-ParentApp] == 'kinfocenter'" );
64 for( KService::List::const_iterator it = services.begin();
65 it != services.end(); ++it)
67 const KService::Ptr s = (*it);
68 if (!KAuthorized::authorizeControlModule(s->menuId()))
78 QString path = module;
80 if (!path.endsWith(QLatin1String(
".desktop")))
83 KService::Ptr service = KService::serviceByStorageId( path );
85 return KService::Ptr();
88 if (!service->hasServiceType(
"KCModule")) {
90 return KService::Ptr();
93 if ( service->noDisplay() ) {
94 kDebug(
debugArea()) << module <<
" should not be loaded.";
95 return KService::Ptr();
103 QString owner = QDBusConnection::sessionBus().interface()->serviceOwner(m_serviceName);
104 if( owner == QDBusConnection::sessionBus().baseService() )
107 kDebug(
debugArea()) <<
"kcmshell4 with modules '" <<
108 m_serviceName <<
"' is already running." << endl;
110 QDBusInterface iface(m_serviceName,
"/KCModule/dialog",
"org.kde.KCMShellMultiDialog");
111 QDBusReply<void> reply = iface.call(
"activate", kapp->startupId());
112 if (!reply.isValid())
114 kDebug(
debugArea()) <<
"Calling D-Bus function dialog::activate() failed.";
124 setFaceType(dialogFace);
127 QDBusConnection::sessionBus().registerObject(
"/KCModule/dialog",
this, QDBusConnection::ExportScriptableSlots);
135 KStartupInfo::setNewStartupId(
this, asn_id );
141 m_serviceName = QLatin1String(
"org.kde.kcmshell_" ) + dbusName;
142 QDBusConnection::sessionBus().registerService(m_serviceName);
149 QDBusServiceWatcher *watcher =
new QDBusServiceWatcher(
this);
150 watcher->setConnection(QDBusConnection::sessionBus());
151 watcher->setWatchMode(QDBusServiceWatcher::WatchForOwnerChange);
152 watcher->addWatchedService(m_serviceName);
153 connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
154 SLOT(appExit(QString,QString,QString)));
158 void KCMShell::appExit(
const QString &appId,
const QString &oldName,
const QString &newName)
164 if (!oldName.isEmpty())
166 kDebug(
debugArea()) <<
"'" << appId <<
"' closed, dereferencing.";
171 extern "C" KDE_EXPORT
int kdemain(
int _argc,
char *_argv[])
173 KAboutData aboutData(
"kcmshell", 0, ki18n(
"KDE Control Module"),
175 ki18n(
"A tool to start single KDE control modules"),
176 KAboutData::License_GPL,
177 ki18n(
"(c) 1999-2004, The KDE Developers") );
179 aboutData.addAuthor(ki18n(
"Frans Englich"), ki18n(
"Maintainer"),
"frans.englich@kde.org");
180 aboutData.addAuthor(ki18n(
"Daniel Molkentin"), KLocalizedString(),
"molkentin@kde.org");
181 aboutData.addAuthor(ki18n(
"Matthias Hoelzer-Kluepfel"),KLocalizedString(),
"hoelzer@kde.org");
182 aboutData.addAuthor(ki18n(
"Matthias Elter"),KLocalizedString(),
"elter@kde.org");
183 aboutData.addAuthor(ki18n(
"Matthias Ettrich"),KLocalizedString(),
"ettrich@kde.org");
184 aboutData.addAuthor(ki18n(
"Waldo Bastian"),KLocalizedString(),
"bastian@kde.org");
186 KCmdLineArgs::init(_argc, _argv, &aboutData);
188 KCmdLineOptions options;
189 options.add(
"list", ki18n(
"List all possible modules"));
190 options.add(
"+module", ki18n(
"Configuration module to open"));
191 options.add(
"lang <language>", ki18n(
"Specify a particular language"));
192 options.add(
"silent", ki18n(
"Do not display main window"));
193 options.add(
"args <arguments>", ki18n(
"Arguments for the module"));
194 KCmdLineArgs::addCmdLineOptions( options );
197 const KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
199 const QString lang = args->getOption(
"lang");
200 if( !lang.isEmpty() ) {
201 KGlobal::setLocale(
new KLocale(aboutData.catalogName(), lang));
204 if (args->isSet(
"list"))
206 cout << i18n(
"The following modules are available:").toLocal8Bit().data() << endl;
212 for( KService::List::ConstIterator it =
m_modules.constBegin(); it !=
m_modules.constEnd(); ++it)
214 int len = (*it)->desktopEntryName().length();
219 for( KService::List::ConstIterator it =
m_modules.constBegin(); it !=
m_modules.constEnd(); ++it)
221 QString entry(
"%1 - %2");
223 entry = entry.arg((*it)->desktopEntryName().leftJustified(maxLen,
' '))
224 .arg(!(*it)->comment().isEmpty() ? (*it)->comment()
225 : i18n(
"No description available"));
227 cout << entry.toLocal8Bit().data() << endl;
232 if (args->count() < 1)
239 KService::List modules;
240 for (
int i = 0; i < args->count(); i++)
242 const QString arg = args->arg(i);
252 modules.append(service);
253 if( !serviceName.isEmpty() )
255 serviceName += args->arg(i);
257 fprintf(stderr,
"%s\n", i18n(
"Could not find module '%1'. See kcmshell4 --list for the full list of modules.", arg).toLocal8Bit().constData());
268 KPageDialog::FaceType ftype = KPageDialog::Plain;
270 if (modules.count() < 1) {
272 }
else if (modules.count() > 1) {
273 ftype = KPageDialog::List;
276 QStringList moduleArgs;
277 QString x = args->getOption(
"args");
278 moduleArgs << x.split(QRegExp(
" +"));
281 KCmdLineArgs *kdeargs = KCmdLineArgs::parsedArgs(
"kde");
282 if (kdeargs && kdeargs->isSet(
"caption")) {
283 dlg->setCaption(QString());
285 }
else if (modules.count() == 1) {
286 dlg->setCaption(modules.first()->name());
289 for (KService::List::ConstIterator it = modules.constBegin(); it != modules.constEnd(); ++it)
290 dlg->addModule(*it, 0, moduleArgs);
292 if ( !args->isSet(
"icon" ) && modules.count() == 1)
294 QString iconName = KCModuleInfo(modules.first()).icon();
295 dlg->setWindowIcon( KIcon(iconName) );
The KApplication instance for kcmshell.
virtual Q_SCRIPTABLE void activate(const QByteArray &asn_id)
Activate a module with id asn_id .
KDE_EXPORT int kdemain(int _argc, char *_argv[])
void setServiceName(const QString &serviceName)
Sets m_serviceName basically to serviceName, and then registers with D-BUS.
static bool caseInsensitiveLessThan(const KService::Ptr s1, const KService::Ptr s2)
KCMShellMultiDialog(KPageDialog::FaceType dialogFace, QWidget *parent=0)
Constructor.
static KService::Ptr locateModule(const QString &module)
static void listModules()
void waitForExit()
Waits until the last instance of kcmshell with the same module as this one exits, and then exits...
Essentially a plain KCMultiDialog, but has the additional functionality of allowing it to be told to ...