32 #include <QtCore/QDir>
33 #include <QtCore/QFile>
34 #include <QtCore/QTimer>
36 #include <QtDBus/QtDBus>
42 #ifndef KDE_NO_DEPRECATED
60 #include <qx11info_x11.h>
65 #define KDED_EXENAME "kded4"
67 #define MODULES_PATH "/modules/"
79 extern Q_DBUS_EXPORT
void qDBusAddSpyHook(
void (*)(
const QDBusMessage&));
81 extern QDBUS_EXPORT
void qDBusAddSpyHook(
void (*)(
const QDBusMessage&));
87 Q_ASSERT(!exe.isEmpty());
89 args.append(
"--incremental");
91 args.append(
"--checkstamps");
93 args.append(
"--nocheckfiles");
117 args.append(QFile::decodeName(oldName));
118 args.append(QFile::decodeName(newName));
123 : m_needDelayedCheck(false)
129 m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
136 QDBusConnection session = QDBusConnection::sessionBus();
137 session.registerObject(
"/kbuildsycoca",
this);
138 session.registerObject(
"/kded",
this);
159 for (QHash<QByteArray,KDEDModule*>::iterator
167 disconnect(module, SIGNAL(moduleDeleted(
KDEDModule*)),
183 if (message.type() != QDBusMessage::MethodCallMessage)
192 if (obj ==
"ksycoca")
196 int index = obj.indexOf(
'/');
198 obj = obj.left(index);
206 kDebug(7020) <<
"Failed to load module for " << obj;
213 const QVariant phasev = service->property(
"X-KDE-Kded-phase", QVariant::Int );
214 return phasev.isValid() ? phasev.toInt() : 2;
220 bool kde_running = !qgetenv(
"KDE_FULL_SESSION" ).isEmpty();
223 const QByteArray sessionUID = qgetenv(
"KDE_SESSION_UID" );
224 if( !sessionUID.isEmpty() && uid_t( sessionUID.toInt() ) != getuid())
228 const QByteArray kdeSession = qgetenv(
"KDE_SESSION_VERSION");
237 const bool loadPhase2Now = (kde_running && qgetenv(
"KDED_STARTED_BY_KDEINIT").toInt() == 0);
241 for(KService::List::ConstIterator it = kdedModules.begin(); it != kdedModules.end(); ++it)
248 bool prevent_autoload =
false;
255 prevent_autoload =
true;
260 if (!loadPhase2Now) {
261 prevent_autoload =
true;
267 if (autoload && !prevent_autoload) {
280 if (!loadOnDemand && !autoload)
287 kDebug(7020) <<
"Loading second phase autoload";
290 for(KService::List::ConstIterator it = kdedModules.constBegin(); it != kdedModules.constEnd(); ++it) {
328 bool autoload = module->
property(
"X-KDE-Kded-autoload", QVariant::Bool).toBool();
330 autoload = cg.
readEntry(
"autoload", autoload);
345 bool loadOnDemand =
true;
347 if (p.isValid() && (p.toBool() ==
false))
348 loadOnDemand =
false;
355 Q_ASSERT(obj.indexOf(
'/')==-1);
366 if (s && !s->
library().isEmpty())
376 if (p.isValid() && (p.toBool() ==
false))
390 QString factoryName = s->
property(
"X-KDE-FactoryName", QVariant::String).toString();
391 if (factoryName.isEmpty())
393 factoryName =
"create_" + factoryName;
394 #ifndef KDE_NO_DEPRECATED
404 kWarning() <<
"Could not load library" << libname <<
". ["
416 kDebug(7020) <<
"Successfully loaded module" << obj;
419 kDebug(7020) <<
"Could not load module" << obj;
431 kDebug(7020) <<
"Unloading module" << obj;
452 #if 0 // see kdedmodule.cpp (KDED_OBJECTS)
455 module->removeAll(appId);
460 for( QList<qlonglong>::ConstIterator it = windowIds.begin();
461 it != windowIds.end(); ++it)
463 qlonglong windowId = *it;
475 if (!bCheckUpdates)
return;
498 KSycoca::clearCaches();
500 if (!bCheckUpdates)
return;
502 if (delayedCheck)
return;
506 for( QStringList::ConstIterator it = dirs.begin();
553 delayedCheck =
false;
567 QDBusConnection::sessionBus().send(msg.createReply());
603 msg.setDelayedReply(
true);
612 if ( !path.endsWith(
'/' ) )
621 QDir d( _path,
QString(), QDir::Unsorted, QDir::Readable | QDir::Executable | QDir::Dirs | QDir::Hidden );
631 kDebug(7020) <<
"Does not exist:" << _path;
642 unsigned int count = d.count();
643 for( i = 0; i < count; i++ )
645 if (d[i] ==
"." || d[i] ==
".." || d[i] ==
"magic")
672 windowIds.append(windowId);
686 if (!windowIds.isEmpty())
688 windowIds.removeAll(windowId);
689 if (windowIds.isEmpty()) {
714 m_pTimer =
new QTimer;
715 m_pTimer->setSingleShot(
true );
717 QObject::connect( m_pDirWatch, SIGNAL(dirty(
QString)),
721 for( QStringList::ConstIterator it = dirs.begin();
726 if (path[path.length()-1] !=
'/')
747 m_pTimer->start( 500 );
752 m_Timer.start(pollInterval);
765 if (gethostname(buf, 1024) != 0)
767 buf[
sizeof(buf)-1] =
'\0';
769 if (m_hostname.isEmpty())
775 if (m_hostname == buf)
778 QByteArray newHostname = buf;
781 m_hostname = newHostname;
822 e.xclient.type = ClientMessage;
823 e.xclient.message_type = XInternAtom( QX11Info::display(),
"_KDE_SPLASH_PROGRESS", False );
824 e.xclient.display = QX11Info::display();
825 e.xclient.window = QX11Info::appRootWindow();
826 e.xclient.format = 8;
827 strcpy( e.xclient.data.b,
"kded" );
828 XSendEvent( QX11Info::display(), QX11Info::appRootWindow(), False, SubstructureNotifyMask, &e );
834 e.xclient.type = ClientMessage;
835 e.xclient.message_type = XInternAtom( QX11Info::display(),
"_KDE_SPLASH_PROGRESS", False );
836 e.xclient.display = QX11Info::display();
837 e.xclient.window = QX11Info::appRootWindow();
838 e.xclient.format = 8;
839 strcpy( e.xclient.data.b,
"confupdate" );
840 XSendEvent( QX11Info::display(), QX11Info::appRootWindow(), False, SubstructureNotifyMask, &e );
859 "kdelibs4",
ki18n(
"KDE Daemon"),
861 ki18n(
"KDE Daemon - triggers Sycoca database updates when needed"));
864 options.
add(
"check",
ki18n(
"Check Sycoca database only once"));
873 putenv(qstrdup(
"SESSION_MANAGER="));
882 if (args->
isSet(
"check"))
886 checkStamps = cg.
readEntry(
"CheckFileStamps",
true);
894 fprintf(stderr,
"KDE Daemon (kded) already running.\n");
902 bCheckSycoca = cg.
readEntry(
"CheckSycoca",
true);
903 bCheckUpdates = cg.
readEntry(
"CheckUpdates",
true);
904 bCheckHostname = cg.
readEntry(
"CheckHostname",
true);
905 checkStamps = cg.
readEntry(
"CheckFileStamps",
true);
906 delayedCheck = cg.
readEntry(
"DelayedCheck",
false);
915 k.setQuitOnLastWindowClosed(
false);
922 kded->moveToThread( k.thread() );
924 int result = k.exec();