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

kded

  • kded
kded.cpp
1/* This file is part of the KDE libraries
2 * Copyright (C) 1999 David Faure <faure@kde.org>
3 * Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation;
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include <tqdir.h>
21
22#include "kded.h"
23#include "kdedmodule.h"
24
25#include <kresourcelist.h>
26#include <tdecrash.h>
27
28#include <unistd.h>
29#include <stdlib.h>
30#include <signal.h>
31#include <time.h>
32
33#include <tqfile.h>
34#include <tqtimer.h>
35
36#include <dcopclient.h>
37
38#include <tdeuniqueapplication.h>
39#include <tdecmdlineargs.h>
40#include <tdeaboutdata.h>
41#include <tdelocale.h>
42#include <tdeglobal.h>
43#include <tdeprocess.h>
44#include <kdebug.h>
45#include <kdirwatch.h>
46#include <tdestandarddirs.h>
47#include <kdatastream.h>
48#include <tdeio/global.h>
49#include <kservicetype.h>
50
51#ifdef TQ_WS_X11
52#include <X11/Xlib.h>
53#include <fixx11h.h>
54#endif
55
56Kded *Kded::_self = nullptr;
57
58static bool checkStamps = true;
59static bool delayedCheck = false;
60
61static void runBuildSycoca(TQObject *callBackObj=nullptr, const char *callBackSlot=nullptr)
62{
63 TQStringList args;
64 args.append("--incremental");
65 if(checkStamps)
66 args.append("--checkstamps");
67 if(delayedCheck)
68 args.append("--nocheckfiles");
69 else
70 checkStamps = false; // useful only during kded startup
71 if (callBackObj)
72 {
73 TQByteArray data;
74 TQDataStream dataStream( data, IO_WriteOnly );
75 dataStream << TQString("tdebuildsycoca") << args;
76 TQCString _launcher = TDEApplication::launcher();
77
78 tdeApp->dcopClient()->callAsync(_launcher, _launcher, "tdeinit_exec_wait(TQString,TQStringList)", data, callBackObj, callBackSlot);
79 }
80 else
81 {
82 TDEApplication::tdeinitExecWait( "tdebuildsycoca", args );
83 }
84}
85
86static void runKonfUpdate()
87{
88 TDEApplication::tdeinitExecWait( "tdeconf_update", TQStringList(), nullptr, nullptr, "0" /*no startup notification*/ );
89}
90
91static void runDontChangeHostname(const TQCString &oldName, const TQCString &newName)
92{
93 TQStringList args;
94 args.append(TQFile::decodeName(oldName));
95 args.append(TQFile::decodeName(newName));
96 TDEApplication::tdeinitExecWait( "kdontchangethehostname", args );
97}
98
99Kded::Kded(bool checkUpdates, bool new_startup)
100 : DCOPObject("tdebuildsycoca"), DCOPObjectProxy(),
101 b_checkUpdates(checkUpdates),
102 m_needDelayedCheck(false),
103 m_newStartup( new_startup )
104{
105 _self = this;
106 TQCString cPath;
107 TQCString tdesycoca_env = getenv("TDESYCOCA");
108 if (tdesycoca_env.isEmpty())
109 cPath = TQFile::encodeName(TDEGlobal::dirs()->saveLocation("tmp")+"tdesycoca");
110 else
111 cPath = tdesycoca_env;
112 m_pTimer = new TQTimer(this);
113 connect(m_pTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(recreate()));
114
115 TQTimer::singleShot(100, this, TQ_SLOT(installCrashHandler()));
116
117 m_pDirWatch = nullptr;
118
119 m_windowIdList.setAutoDelete(true);
120
121 m_recreateCount = 0;
122 m_recreateBusy = false;
123}
124
125Kded::~Kded()
126{
127 _self = nullptr;
128 m_pTimer->stop();
129 delete m_pTimer;
130 delete m_pDirWatch;
131 // We have to delete the modules while we're still able to process incoming
132 // DCOP messages, since modules might make DCOP calls in their destructors.
133 TQAsciiDictIterator<KDEDModule> it(m_modules);
134 while (!it.isEmpty())
135 delete it.toFirst();
136}
137
138bool Kded::process(const TQCString &obj, const TQCString &fun,
139 const TQByteArray &data,
140 TQCString &replyType, TQByteArray &replyData)
141{
142 if (obj == "tdesycoca") return false; // Ignore this one.
143
144 if (m_dontLoad[obj])
145 return false;
146
147 KDEDModule *module = loadModule(obj, true);
148 if (!module)
149 return false;
150
151 module->setCallingDcopClient(tdeApp->dcopClient());
152 return module->process(fun, data, replyType, replyData);
153}
154
155void Kded::initModules()
156{
157 m_dontLoad.clear();
158 TDEConfig *config = tdeApp->config();
159 const char *fullSession = getenv( "TDE_FULL_SESSION" );
160 bool tde_running = fullSession && fullSession[ 0 ] != '\0';
161 // not the same user like the one running the session (most likely we're run via sudo or something)
162 if( getenv( "TDE_SESSION_UID" ) && uid_t( atoi( getenv( "TDE_SESSION_UID" ))) != getuid())
163 tde_running = false;
164 // Preload kded modules.
165 KService::List kdedModules = KServiceType::offers("KDEDModule");
166 TQString version = getenv( "KDE_SESSION_VERSION" );
167 TQStringList blacklist;
168 if ( !version.isNull() && version >= "4" )
169 {
170 kdDebug(7020) << "KDE4 is running:" << endl;
171 kdDebug(7020) << " KDE_SESSION_VERSION: " << version << endl;
172 kdDebug(7020) << " Blacklisting mediamanager, medianotifier, kmilod, kwrited." << endl;
173 blacklist << "mediamanager" << "medianotifier" << "kmilod" << "kwrited";
174 }
175 for(KService::List::ConstIterator it = kdedModules.begin(); it != kdedModules.end(); ++it)
176 {
177 KService::Ptr service = *it;
178 bool autoload = service->property("X-TDE-Kded-autoload", TQVariant::Bool).toBool();
179 config->setGroup(TQString("Module-%1").arg(service->desktopEntryName()));
180 autoload = config->readBoolEntry("autoload", autoload);
181 for (TQStringList::Iterator module = blacklist.begin(); module != blacklist.end(); ++module)
182 {
183 if (service->desktopEntryName() == *module)
184 {
185 autoload = false;
186 break;
187 }
188 }
189 if( m_newStartup )
190 {
191 // see ksmserver's README for description of the phases
192 TQVariant phasev = service->property("X-TDE-Kded-phase", TQVariant::Int );
193 int phase = phasev.isValid() ? phasev.toInt() : 2;
194 bool prevent_autoload = false;
195 switch( phase )
196 {
197 case 0: // always autoload
198 break;
199 case 1: // autoload only in TDE
200 if( !tde_running )
201 prevent_autoload = true;
202 break;
203 case 2: // autoload delayed, only in TDE
204 default:
205 prevent_autoload = true;
206 break;
207 }
208 if (autoload && !prevent_autoload)
209 loadModule(service, false);
210 }
211 else
212 {
213 if (autoload && tde_running)
214 loadModule(service, false);
215 }
216 bool dontLoad = false;
217 TQVariant p = service->property("X-TDE-Kded-load-on-demand", TQVariant::Bool);
218 if (p.isValid() && (p.toBool() == false))
219 dontLoad = true;
220 if (dontLoad)
221 noDemandLoad(service->desktopEntryName());
222
223 if (dontLoad && !autoload)
224 unloadModule(service->desktopEntryName().latin1());
225 }
226}
227
228void Kded::loadSecondPhase()
229{
230 kdDebug(7020) << "Loading second phase autoload" << endl;
231 TDEConfig *config = tdeApp->config();
232 KService::List kdedModules = KServiceType::offers("KDEDModule");
233 for(KService::List::ConstIterator it = kdedModules.begin(); it != kdedModules.end(); ++it)
234 {
235 KService::Ptr service = *it;
236 bool autoload = service->property("X-TDE-Kded-autoload", TQVariant::Bool).toBool();
237 config->setGroup(TQString("Module-%1").arg(service->desktopEntryName()));
238 autoload = config->readBoolEntry("autoload", autoload);
239 TQVariant phasev = service->property("X-TDE-Kded-phase", TQVariant::Int );
240 int phase = phasev.isValid() ? phasev.toInt() : 2;
241 if( phase == 2 && autoload )
242 loadModule(service, false);
243 }
244}
245
246void Kded::noDemandLoad(const TQString &obj)
247{
248 m_dontLoad.insert(obj.latin1(), this);
249}
250
251KDEDModule *Kded::loadModule(const TQCString &obj, bool onDemand)
252{
253 KDEDModule *module = m_modules.find(obj);
254 if (module)
255 return module;
256 KService::Ptr s = KService::serviceByDesktopPath("kded/"+obj+".desktop");
257 return loadModule(s, onDemand);
258}
259
260KDEDModule *Kded::loadModule(const KService *s, bool onDemand)
261{
262 KDEDModule *module = nullptr;
263 if (s && !s->library().isEmpty())
264 {
265 TQCString obj = s->desktopEntryName().latin1();
266 KDEDModule *oldModule = m_modules.find(obj);
267 if (oldModule)
268 return oldModule;
269
270 if (onDemand)
271 {
272 TQVariant p = s->property("X-TDE-Kded-load-on-demand", TQVariant::Bool);
273 if (p.isValid() && (p.toBool() == false))
274 {
275 noDemandLoad(s->desktopEntryName());
276 return nullptr;
277 }
278 }
279 // get the library loader instance
280
281 KLibLoader *loader = KLibLoader::self();
282
283 TQVariant v = s->property("X-TDE-FactoryName", TQVariant::String);
284 TQString factory = v.isValid() ? v.toString() : TQString::null;
285 if (factory.isEmpty())
286 {
287 // Stay bugward compatible
288 v = s->property("X-TDE-Factory", TQVariant::String);
289 factory = v.isValid() ? v.toString() : TQString::null;
290 }
291 if (factory.isEmpty())
292 factory = s->library();
293
294 factory = "create_" + factory;
295 TQString libname = "kded_"+s->library();
296
297 KLibrary *lib = loader->library(TQFile::encodeName(libname));
298 if (!lib)
299 {
300 kdWarning() << k_funcinfo << "Could not load library. [ "
301 << loader->lastErrorMessage() << " ]" << endl;
302 libname.prepend("lib");
303 lib = loader->library(TQFile::encodeName(libname));
304 }
305 if (lib)
306 {
307 // get the create_ function
308 void *create = lib->symbol(TQFile::encodeName(factory));
309
310 if (create)
311 {
312 // create the module
313 KDEDModule* (*func)(const TQCString &);
314 func = (KDEDModule* (*)(const TQCString &)) create;
315 module = func(obj);
316 if (module)
317 {
318 m_modules.insert(obj, module);
319 m_libs.insert(obj, lib);
320 connect(module, TQ_SIGNAL(moduleDeleted(KDEDModule *)), TQ_SLOT(slotKDEDModuleRemoved(KDEDModule *)));
321 kdDebug(7020) << "Successfully loaded module '" << obj << "'\n";
322 return module;
323 }
324 }
325 loader->unloadLibrary(TQFile::encodeName(libname));
326 }
327 else
328 {
329 kdWarning() << k_funcinfo << "Could not load library. [ "
330 << loader->lastErrorMessage() << " ]" << endl;
331 }
332 kdDebug(7020) << "Could not load module '" << obj << "'\n";
333 }
334 return nullptr;
335}
336
337bool Kded::unloadModule(const TQCString &obj)
338{
339 KDEDModule *module = m_modules.take(obj);
340 if (!module)
341 return false;
342 kdDebug(7020) << "Unloading module '" << obj << "'\n";
343 delete module;
344 return true;
345}
346
347// DCOP
348QCStringList Kded::loadedModules()
349{
350 QCStringList modules;
351 TQAsciiDictIterator<KDEDModule> it( m_modules );
352 for ( ; it.current(); ++it)
353 modules.append( it.currentKey() );
354
355 return modules;
356}
357
358QCStringList Kded::functions()
359{
360 QCStringList res = DCOPObject::functions();
361 res += "ASYNC recreate()";
362 return res;
363}
364
365void Kded::slotKDEDModuleRemoved(KDEDModule *module)
366{
367 m_modules.remove(module->objId());
368 KLibrary *lib = m_libs.take(module->objId());
369 if (lib)
370 lib->unload();
371}
372
373void Kded::slotApplicationRemoved(const TQCString &appId)
374{
375 for(TQAsciiDictIterator<KDEDModule> it(m_modules); it.current(); ++it)
376 {
377 it.current()->removeAll(appId);
378 }
379
380 TQValueList<long> *windowIds = m_windowIdList.find(appId);
381 if (windowIds)
382 {
383 for( TQValueList<long>::ConstIterator it = windowIds->begin();
384 it != windowIds->end(); ++it)
385 {
386 long windowId = *it;
387 m_globalWindowIdList.remove(windowId);
388 for(TQAsciiDictIterator<KDEDModule> it(m_modules); it.current(); ++it)
389 {
390 emit it.current()->windowUnregistered(windowId);
391 }
392 }
393 m_windowIdList.remove(appId);
394 }
395}
396
397void Kded::updateDirWatch()
398{
399 if (!b_checkUpdates) return;
400
401 delete m_pDirWatch;
402 m_pDirWatch = new KDirWatch;
403
404 TQObject::connect( m_pDirWatch, TQ_SIGNAL(dirty(const TQString&)),
405 this, TQ_SLOT(update(const TQString&)));
406 TQObject::connect( m_pDirWatch, TQ_SIGNAL(created(const TQString&)),
407 this, TQ_SLOT(update(const TQString&)));
408 TQObject::connect( m_pDirWatch, TQ_SIGNAL(deleted(const TQString&)),
409 this, TQ_SLOT(dirDeleted(const TQString&)));
410
411 // For each resource
412 for( TQStringList::ConstIterator it = m_allResourceDirs.begin();
413 it != m_allResourceDirs.end();
414 ++it )
415 {
416 readDirectory( *it );
417 }
418}
419
420void Kded::updateResourceList()
421{
422 delete KSycoca::self();
423
424 if (!b_checkUpdates) return;
425
426 if (delayedCheck) return;
427
428 TQStringList dirs = KSycoca::self()->allResourceDirs();
429 // For each resource
430 for( TQStringList::ConstIterator it = dirs.begin();
431 it != dirs.end();
432 ++it )
433 {
434 if (m_allResourceDirs.find(*it) == m_allResourceDirs.end())
435 {
436 m_allResourceDirs.append(*it);
437 readDirectory(*it);
438 }
439 }
440}
441
442void Kded::crashHandler(int)
443{
444 DCOPClient::emergencyClose();
445 if (_self) { // Don't restart if we were closing down
446 tqWarning("Last DCOP call before KDED crash was from application '%s'\n"
447 "to object '%s', function '%s'.",
448 DCOPClient::postMortemSender(),
449 DCOPClient::postMortemObject(),
450 DCOPClient::postMortemFunction());
451 tqWarning("Restarting KDED...\n");
452 if (system("kded") < 0) {
453 tqWarning("Unable to restart KDED!\n");
454 }
455 }
456}
457
458void Kded::installCrashHandler()
459{
460 TDECrash::setEmergencySaveFunction(crashHandler);
461}
462
463void Kded::recreate()
464{
465 recreate(false);
466}
467
468void Kded::runDelayedCheck()
469{
470 if( m_needDelayedCheck )
471 recreate(false);
472 m_needDelayedCheck = false;
473}
474
475void Kded::recreate(bool initial)
476{
477 m_recreateBusy = true;
478 // Using TDELauncher here is difficult since we might not have a
479 // database
480
481 if (!initial)
482 {
483 updateDirWatch(); // Update tree first, to be sure to miss nothing.
484 runBuildSycoca(this, TQ_SLOT(recreateDone()));
485 }
486 else
487 {
488 if(!delayedCheck)
489 updateDirWatch(); // this would search all the directories
490 runBuildSycoca();
491 recreateDone();
492 if(delayedCheck)
493 {
494 // do a proper tdesycoca check after a delay
495 TQTimer::singleShot( 60000, this, TQ_SLOT( runDelayedCheck()));
496 m_needDelayedCheck = true;
497 delayedCheck = false;
498 }
499 else
500 m_needDelayedCheck = false;
501 }
502}
503
504void Kded::recreateDone()
505{
506 updateResourceList();
507
508 for(; m_recreateCount; m_recreateCount--)
509 {
510 TQCString replyType = "void";
511 TQByteArray replyData;
512 DCOPClientTransaction *transaction = m_recreateRequests.first();
513 if (transaction)
514 tdeApp->dcopClient()->endTransaction(transaction, replyType, replyData);
515 m_recreateRequests.remove(m_recreateRequests.begin());
516 }
517 m_recreateBusy = false;
518
519 // Did a new request come in while building?
520 if (!m_recreateRequests.isEmpty())
521 {
522 m_pTimer->start(2000, true /* single shot */ );
523 m_recreateCount = m_recreateRequests.count();
524 }
525}
526
527void Kded::dirDeleted(const TQString& path)
528{
529 update(path);
530}
531
532void Kded::update(const TQString& )
533{
534 if (!m_recreateBusy)
535 {
536 m_pTimer->start( 2000, true /* single shot */ );
537 }
538 else
539 {
540 m_recreateRequests.append(nullptr);
541 }
542}
543
544bool Kded::process(const TQCString &fun, const TQByteArray &data,
545 TQCString &replyType, TQByteArray &replyData)
546{
547 if (fun == "recreate()") {
548 if (!m_recreateBusy)
549 {
550 if (m_recreateRequests.isEmpty())
551 {
552 m_pTimer->start(0, true /* single shot */ );
553 m_recreateCount = 0;
554 }
555 m_recreateCount++;
556 }
557 m_recreateRequests.append(tdeApp->dcopClient()->beginTransaction());
558 replyType = "void";
559 return true;
560 } else {
561 return DCOPObject::process(fun, data, replyType, replyData);
562 }
563}
564
565
566void Kded::readDirectory( const TQString& _path )
567{
568 TQString path( _path );
569 if ( path.right(1) != "/" )
570 path += "/";
571
572 if ( m_pDirWatch->contains( path ) ) // Already seen this one?
573 return;
574
575 TQDir d( _path, TQString::null, TQDir::Unsorted, TQDir::Readable | TQDir::Executable | TQDir::Dirs | TQDir::Hidden );
576 // set TQDir ...
577
578
579 //************************************************************************
580 // Setting dirs
581 //************************************************************************
582
583 m_pDirWatch->addDir(path); // add watch on this dir
584
585 if ( !d.exists() ) // exists&isdir?
586 {
587 kdDebug(7020) << TQString(TQString("Does not exist! (%1)").arg(_path)) << endl;
588 return; // return false
589 }
590
591 // Note: If some directory is gone, dirwatch will delete it from the list.
592
593 //************************************************************************
594 // Reading
595 //************************************************************************
596 TQString file;
597 unsigned int i; // counter and string length.
598 unsigned int count = d.count();
599 for( i = 0; i < count; i++ ) // check all entries
600 {
601 if (d[i] == "." || d[i] == ".." || d[i] == "magic")
602 continue; // discard those ".", "..", "magic"...
603
604 file = path; // set full path
605 file += d[i]; // and add the file name.
606
607 readDirectory( file ); // yes, dive into it.
608 }
609}
610
611bool Kded::isWindowRegistered(long windowId)
612{
613 return m_globalWindowIdList.find(windowId) != nullptr;
614
615}
616
617// DCOP
618void Kded::registerWindowId(long windowId)
619{
620 m_globalWindowIdList.replace(windowId, &windowId);
621 TQCString sender = callingDcopClient()->senderId();
622 if( sender.isEmpty()) // local call
623 sender = callingDcopClient()->appId();
624 TQValueList<long> *windowIds = m_windowIdList.find(sender);
625 if (!windowIds)
626 {
627 windowIds = new TQValueList<long>;
628 m_windowIdList.insert(sender, windowIds);
629 }
630 windowIds->append(windowId);
631
632
633 for(TQAsciiDictIterator<KDEDModule> it(m_modules); it.current(); ++it)
634 {
635 emit it.current()->windowRegistered(windowId);
636 }
637}
638
639// DCOP
640void Kded::unregisterWindowId(long windowId)
641{
642 m_globalWindowIdList.remove(windowId);
643 TQCString sender = callingDcopClient()->senderId();
644 if( sender.isEmpty()) // local call
645 sender = callingDcopClient()->appId();
646 TQValueList<long> *windowIds = m_windowIdList.find(sender);
647 if (windowIds)
648 {
649 windowIds->remove(windowId);
650 if (windowIds->isEmpty())
651 m_windowIdList.remove(sender);
652 }
653
654 for(TQAsciiDictIterator<KDEDModule> it(m_modules); it.current(); ++it)
655 {
656 emit it.current()->windowUnregistered(windowId);
657 }
658}
659
660
661static void sighandler(int /*sig*/)
662{
663 if (tdeApp)
664 tdeApp->quit();
665}
666
667KUpdateD::KUpdateD()
668{
669 m_pDirWatch = new KDirWatch;
670 m_pTimer = new TQTimer;
671 connect(m_pTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(runKonfUpdate()));
672 TQObject::connect( m_pDirWatch, TQ_SIGNAL(dirty(const TQString&)),
673 this, TQ_SLOT(slotNewUpdateFile()));
674
675 TQStringList dirs = TDEGlobal::dirs()->findDirs("data", "tdeconf_update");
676 for( TQStringList::ConstIterator it = dirs.begin();
677 it != dirs.end();
678 ++it )
679 {
680 TQString path = *it;
681 if (path[path.length()-1] != '/')
682 path += "/";
683
684 if (!m_pDirWatch->contains(path))
685 m_pDirWatch->addDir(path);
686 }
687}
688
689KUpdateD::~KUpdateD()
690{
691 delete m_pDirWatch;
692 delete m_pTimer;
693}
694
695void KUpdateD::runKonfUpdate()
696{
697 ::runKonfUpdate();
698}
699
700void KUpdateD::slotNewUpdateFile()
701{
702 m_pTimer->start( 500, true /* single shot */ );
703}
704
705KHostnameD::KHostnameD(int pollInterval)
706{
707 m_Timer.start(pollInterval, false /* repetitive */ );
708 connect(&m_Timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(checkHostname()));
709 checkHostname();
710}
711
712KHostnameD::~KHostnameD()
713{
714 // Empty
715}
716
717void KHostnameD::checkHostname()
718{
719 char buf[1024+1];
720 if (gethostname(buf, 1024) != 0)
721 return;
722 buf[sizeof(buf)-1] = '\0';
723
724 if (m_hostname.isEmpty())
725 {
726 m_hostname = buf;
727 return;
728 }
729
730 if (m_hostname == buf)
731 return;
732
733 TQCString newHostname = buf;
734
735 runDontChangeHostname(m_hostname, newHostname);
736 m_hostname = newHostname;
737}
738
739
740static TDECmdLineOptions options[] =
741{
742 { "check", I18N_NOOP("Check Sycoca database only once"), nullptr },
743 { "new-startup", "Internal", nullptr },
744 TDECmdLineLastOption
745};
746
747class KDEDQtDCOPObject : public DCOPObject
748{
749public:
750 KDEDQtDCOPObject() : DCOPObject("qt/kded") { }
751
752 virtual bool process(const TQCString &fun, const TQByteArray &data,
753 TQCString& replyType, TQByteArray &replyData)
754 {
755 if ( tdeApp && (fun == "quit()") )
756 {
757 tdeApp->quit();
758 replyType = "void";
759 return true;
760 }
761 return DCOPObject::process(fun, data, replyType, replyData);
762 }
763
764 QCStringList functions()
765 {
766 QCStringList res = DCOPObject::functions();
767 res += "void quit()";
768 return res;
769 }
770};
771
772class KDEDApplication : public TDEUniqueApplication
773{
774public:
775 KDEDApplication() : TDEUniqueApplication( )
776 {
777 startup = true;
778 dcopClient()->connectDCOPSignal( "DCOPServer", "", "terminateTDE()",
779 objId(), "quit()", false );
780 }
781
782 int newInstance()
783 {
784 if (startup) {
785 startup = false;
786 if( Kded::self()->newStartup())
787 Kded::self()->initModules();
788 else
789 TQTimer::singleShot(500, Kded::self(), TQ_SLOT(initModules()));
790 } else
791 runBuildSycoca();
792
793 return 0;
794 }
795
796 QCStringList functions()
797 {
798 QCStringList res = TDEUniqueApplication::functions();
799 res += "bool loadModule(TQCString)";
800 res += "bool unloadModule(TQCString)";
801 res += "void registerWindowId(long int)";
802 res += "void unregisterWindowId(long int)";
803 res += "QCStringList loadedModules()";
804 res += "void reconfigure()";
805 res += "void loadSecondPhase()";
806 res += "void quit()";
807 return res;
808 }
809
810 bool process(const TQCString &fun, const TQByteArray &data,
811 TQCString &replyType, TQByteArray &replyData)
812 {
813 if (fun == "loadModule(TQCString)") {
814 TQCString module;
815 TQDataStream arg( data, IO_ReadOnly );
816 arg >> module;
817 bool result = (Kded::self()->loadModule(module, false) != nullptr);
818 replyType = "bool";
819 TQDataStream _replyStream( replyData, IO_WriteOnly );
820 _replyStream << result;
821 return true;
822 }
823 else if (fun == "unloadModule(TQCString)") {
824 TQCString module;
825 TQDataStream arg( data, IO_ReadOnly );
826 arg >> module;
827 bool result = Kded::self()->unloadModule(module);
828 replyType = "bool";
829 TQDataStream _replyStream( replyData, IO_WriteOnly );
830 _replyStream << result;
831 return true;
832 }
833 else if (fun == "registerWindowId(long int)") {
834 long windowId;
835 TQDataStream arg( data, IO_ReadOnly );
836 arg >> windowId;
837 Kded::self()->setCallingDcopClient(callingDcopClient());
838 Kded::self()->registerWindowId(windowId);
839 replyType = "void";
840 return true;
841 }
842 else if (fun == "unregisterWindowId(long int)") {
843 long windowId;
844 TQDataStream arg( data, IO_ReadOnly );
845 arg >> windowId;
846 Kded::self()->setCallingDcopClient(callingDcopClient());
847 Kded::self()->unregisterWindowId(windowId);
848 replyType = "void";
849 return true;
850 }
851 else if (fun == "loadedModules()") {
852 replyType = "QCStringList";
853 TQDataStream _replyStream(replyData, IO_WriteOnly);
854 _replyStream << Kded::self()->loadedModules();
855 return true;
856 }
857 else if (fun == "reconfigure()") {
858 config()->reparseConfiguration();
859 Kded::self()->initModules();
860 replyType = "void";
861 return true;
862 }
863 else if (fun == "loadSecondPhase()") {
864 Kded::self()->loadSecondPhase();
865 replyType = "void";
866 return true;
867 }
868 else if (fun == "quit()") {
869 quit();
870 replyType = "void";
871 return true;
872 }
873 return TDEUniqueApplication::process(fun, data, replyType, replyData);
874 }
875
876 bool startup;
877 KDEDQtDCOPObject kdedQtDcopObject;
878};
879
880extern "C" TDE_EXPORT int kdemain(int argc, char *argv[])
881{
882 TDEAboutData aboutData( "kded", I18N_NOOP("TDE Daemon"),
883 "$Id$",
884 I18N_NOOP("TDE Daemon - triggers Sycoca database updates when needed"));
885
886 TDEApplication::installSigpipeHandler();
887
888 TDECmdLineArgs::init(argc, argv, &aboutData);
889
890 TDEUniqueApplication::addCmdLineOptions();
891
892 TDECmdLineArgs::addCmdLineOptions( options );
893
894 // this program is in tdelibs so it uses tdelibs as catalog
895 TDELocale::setMainCatalogue("tdelibs");
896
897 // WABA: Make sure not to enable session management.
898 putenv(strdup("SESSION_MANAGER="));
899
900 // Parse command line before checking DCOP
901 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
902
903 // Check DCOP communication.
904 {
905 DCOPClient testDCOP;
906 TQCString dcopName = testDCOP.registerAs("kded", false);
907 if (dcopName.isEmpty())
908 {
909 kdFatal() << "DCOP communication problem!" << endl;
910 return 1;
911 }
912 }
913
914 TDEInstance *instance = new TDEInstance(&aboutData);
915 TDEConfig *config = instance->config(); // Enable translations.
916
917 if (args->isSet("check"))
918 {
919 config->setGroup("General");
920 checkStamps = config->readBoolEntry("CheckFileStamps", true);
921 runBuildSycoca();
922 runKonfUpdate();
923 exit(0);
924 }
925
926 if (!TDEUniqueApplication::start())
927 {
928 fprintf(stderr, "[kded] Daemon (kded) is already running.\n");
929 exit(0);
930 }
931
932 TDEUniqueApplication::dcopClient()->setQtBridgeEnabled(false);
933
934 config->setGroup("General");
935 int HostnamePollInterval = config->readNumEntry("HostnamePollInterval", 5000);
936 bool bCheckSycoca = config->readBoolEntry("CheckSycoca", true);
937 bool bCheckUpdates = config->readBoolEntry("CheckUpdates", true);
938 bool bCheckHostname = config->readBoolEntry("CheckHostname", true);
939 checkStamps = config->readBoolEntry("CheckFileStamps", true);
940 delayedCheck = config->readBoolEntry("DelayedCheck", false);
941
942 Kded *kded = new Kded(bCheckSycoca, args->isSet("new-startup")); // Build data base
943
944 signal(SIGTERM, sighandler);
945 signal(SIGHUP, sighandler);
946 KDEDApplication k;
947
948 kded->recreate(true); // initial
949
950 if (bCheckUpdates)
951 (void) new KUpdateD; // Watch for updates
952
953 runKonfUpdate(); // Run it once.
954
955 if (bCheckHostname)
956 (void) new KHostnameD(HostnamePollInterval); // Watch for hostname changes
957
958 DCOPClient *client = tdeApp->dcopClient();
959 TQObject::connect(client, TQ_SIGNAL(applicationRemoved(const TQCString&)),
960 kded, TQ_SLOT(slotApplicationRemoved(const TQCString&)));
961 client->setNotifications(true);
962 client->setDaemonMode( true );
963
964 // During startup kdesktop waits for KDED to finish.
965 // Send a notifyDatabaseChanged signal even if the database hasn't
966 // changed.
967 // If the database changed, tdebuildsycoca's signal didn't go anywhere
968 // anyway, because it was too early, so let's send this signal
969 // unconditionnally (David)
970 TQByteArray data;
971 client->send( "*", "tdesycoca", "notifyDatabaseChanged()", data );
972 client->send( "ksplash", "", "upAndRunning(TQString)", TQString("kded"));
973#ifdef TQ_WS_X11
974 XEvent e;
975 e.xclient.type = ClientMessage;
976 e.xclient.message_type = XInternAtom( tqt_xdisplay(), "_KDE_SPLASH_PROGRESS", False );
977 e.xclient.display = tqt_xdisplay();
978 e.xclient.window = tqt_xrootwin();
979 e.xclient.format = 8;
980 strcpy( e.xclient.data.b, "kded" );
981 XSendEvent( tqt_xdisplay(), tqt_xrootwin(), False, SubstructureNotifyMask, &e );
982#endif
983 int result = k.exec(); // keep running
984
985 delete kded;
986 delete instance; // Deletes config as well
987
988 return result;
989}
990
991#include "kded.moc"
KDEDModule
The base class for KDED modules.
Definition: kdedmodule.h:56
KDEDModule::find
TDEShared * find(const TQCString &app, const TQCString &key)
Lookup object indexed with app and key.
Definition: kdedmodule.cpp:83

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.4
This website is maintained by Timothy Pearson.