26 #include <kdeversion.h>
33 #include <QtCore/QDir>
34 #include <QtCore/QFile>
35 #include <QtCore/QTimer>
37 #include <QtDBus/QtDBus>
43 #ifndef KDE_NO_DEPRECATED
61 #include <qx11info_x11.h>
66 #define KDED_EXENAME "kded4"
68 #define MODULES_PATH "/modules/"
80 extern Q_DBUS_EXPORT
void qDBusAddSpyHook(
void (*)(
const QDBusMessage&));
82 extern QDBUS_EXPORT
void qDBusAddSpyHook(
void (*)(
const QDBusMessage&));
88 Q_ASSERT(!exe.isEmpty());
90 args.append(
"--incremental");
92 args.append(
"--checkstamps");
94 args.append(
"--nocheckfiles");
118 args.append(QFile::decodeName(oldName));
119 args.append(QFile::decodeName(newName));
124 : m_needDelayedCheck(false)
130 m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
137 QDBusConnection session = QDBusConnection::sessionBus();
138 session.registerObject(
"/kbuildsycoca",
this);
139 session.registerObject(
"/kded",
this);
160 for (QHash<QByteArray,KDEDModule*>::iterator
168 disconnect(module, SIGNAL(moduleDeleted(
KDEDModule*)),
184 if (message.type() != QDBusMessage::MethodCallMessage)
193 if (obj ==
"ksycoca")
197 int index = obj.indexOf(
'/');
199 obj = obj.left(index);
207 kDebug(7020) <<
"Failed to load module for " << obj;
214 const QVariant phasev = service->property(
"X-KDE-Kded-phase", QVariant::Int );
215 return phasev.isValid() ? phasev.toInt() : 2;
221 bool kde_running = !qgetenv(
"KDE_FULL_SESSION" ).isEmpty();
224 const QByteArray sessionUID = qgetenv(
"KDE_SESSION_UID" );
225 if( !sessionUID.isEmpty() && uid_t( sessionUID.toInt() ) != getuid())
229 const QByteArray kdeSession = qgetenv(
"KDE_SESSION_VERSION");
238 const bool loadPhase2Now = (kde_running && qgetenv(
"KDED_STARTED_BY_KDEINIT").toInt() == 0);
242 for(KService::List::ConstIterator it = kdedModules.begin(); it != kdedModules.end(); ++it)
249 bool prevent_autoload =
false;
256 prevent_autoload =
true;
261 if (!loadPhase2Now) {
262 prevent_autoload =
true;
268 if (autoload && !prevent_autoload) {
281 if (!loadOnDemand && !autoload)
288 kDebug(7020) <<
"Loading second phase autoload";
291 for(KService::List::ConstIterator it = kdedModules.constBegin(); it != kdedModules.constEnd(); ++it) {
329 bool autoload = module->
property(
"X-KDE-Kded-autoload", QVariant::Bool).toBool();
331 autoload = cg.
readEntry(
"autoload", autoload);
346 bool loadOnDemand =
true;
348 if (p.isValid() && (p.toBool() ==
false))
349 loadOnDemand =
false;
356 Q_ASSERT(obj.indexOf(
'/')==-1);
367 if (s && !s->
library().isEmpty())
377 if (p.isValid() && (p.toBool() ==
false))
391 QString factoryName = s->
property(
"X-KDE-FactoryName", QVariant::String).toString();
392 if (factoryName.isEmpty())
394 factoryName =
"create_" + factoryName;
395 #ifndef KDE_NO_DEPRECATED
405 kWarning() <<
"Could not load library" << libname <<
". ["
417 kDebug(7020) <<
"Successfully loaded module" << obj;
420 kDebug(7020) <<
"Could not load module" << obj;
432 kDebug(7020) <<
"Unloading module" << obj;
453 #if 0 // see kdedmodule.cpp (KDED_OBJECTS)
456 module->removeAll(appId);
461 for( QList<qlonglong>::ConstIterator it = windowIds.begin();
462 it != windowIds.end(); ++it)
464 qlonglong windowId = *it;
476 if (!bCheckUpdates)
return;
499 KSycoca::clearCaches();
501 if (!bCheckUpdates)
return;
503 if (delayedCheck)
return;
507 for( QStringList::ConstIterator it = dirs.begin();
554 delayedCheck =
false;
568 QDBusConnection::sessionBus().send(msg.createReply());
604 msg.setDelayedReply(
true);
613 if ( !path.endsWith(
'/' ) )
622 QDir d( _path,
QString(), QDir::Unsorted, QDir::Readable | QDir::Executable | QDir::Dirs | QDir::Hidden );
632 kDebug(7020) <<
"Does not exist:" << _path;
643 unsigned int count = d.count();
644 for( i = 0; i < count; i++ )
646 if (d[i] ==
"." || d[i] ==
".." || d[i] ==
"magic")
673 windowIds.append(windowId);
687 if (!windowIds.isEmpty())
689 windowIds.removeAll(windowId);
690 if (windowIds.isEmpty()) {
715 m_pTimer =
new QTimer;
716 m_pTimer->setSingleShot(
true );
718 QObject::connect( m_pDirWatch, SIGNAL(dirty(
QString)),
722 for( QStringList::ConstIterator it = dirs.begin();
727 if (path[path.length()-1] !=
'/')
748 m_pTimer->start( 500 );
753 m_Timer.start(pollInterval);
766 if (gethostname(buf, 1024) != 0)
768 buf[
sizeof(buf)-1] =
'\0';
770 if (m_hostname.isEmpty())
776 if (m_hostname == buf)
779 QByteArray newHostname = buf;
782 m_hostname = newHostname;
823 e.xclient.type = ClientMessage;
824 e.xclient.message_type = XInternAtom( QX11Info::display(),
"_KDE_SPLASH_PROGRESS", False );
825 e.xclient.display = QX11Info::display();
826 e.xclient.window = QX11Info::appRootWindow();
827 e.xclient.format = 8;
828 strcpy( e.xclient.data.b,
"kded" );
829 XSendEvent( QX11Info::display(), QX11Info::appRootWindow(), False, SubstructureNotifyMask, &e );
835 e.xclient.type = ClientMessage;
836 e.xclient.message_type = XInternAtom( QX11Info::display(),
"_KDE_SPLASH_PROGRESS", False );
837 e.xclient.display = QX11Info::display();
838 e.xclient.window = QX11Info::appRootWindow();
839 e.xclient.format = 8;
840 strcpy( e.xclient.data.b,
"confupdate" );
841 XSendEvent( QX11Info::display(), QX11Info::appRootWindow(), False, SubstructureNotifyMask, &e );
860 "kdelibs4",
ki18n(
"KDE Daemon"),
862 ki18n(
"KDE Daemon - triggers Sycoca database updates when needed"));
865 options.
add(
"check",
ki18n(
"Check Sycoca database only once"));
874 putenv(qstrdup(
"SESSION_MANAGER="));
883 if (args->
isSet(
"check"))
887 checkStamps = cg.
readEntry(
"CheckFileStamps",
true);
895 fprintf(stderr,
"KDE Daemon (kded) already running.\n");
903 bCheckSycoca = cg.
readEntry(
"CheckSycoca",
true);
904 bCheckUpdates = cg.
readEntry(
"CheckUpdates",
true);
905 bCheckHostname = cg.
readEntry(
"CheckHostname",
true);
906 checkStamps = cg.
readEntry(
"CheckFileStamps",
true);
907 delayedCheck = cg.
readEntry(
"DelayedCheck",
false);
916 k.setQuitOnLastWindowClosed(
false);
923 kded->moveToThread( k.thread() );
925 int result = k.exec();