File indexing completed on 2024-04-28 11:35:37

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org>
0004     SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KDED_H
0010 #define KDED_H
0011 
0012 #include <QHash>
0013 #include <QObject>
0014 #include <QSet>
0015 #include <QString>
0016 #include <QTimer>
0017 
0018 #include <QDBusAbstractAdaptor>
0019 
0020 #include <KDEDModule>
0021 #include <ksycoca.h>
0022 
0023 class QDBusMessage;
0024 class QDBusServiceWatcher;
0025 class KPluginMetaData;
0026 class KDirWatch;
0027 
0028 class Kded : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032     Kded();
0033     ~Kded() override;
0034 
0035     static Kded *self()
0036     {
0037         return _self;
0038     }
0039     static void messageFilter(const QDBusMessage &);
0040 
0041     void noDemandLoad(const QString &obj); // Don't load obj on demand
0042 
0043     QStringList loadedModules();
0044     bool unloadModule(const QString &obj);
0045     // bool isWindowRegistered(qlonglong windowId) const;
0046     /**
0047      * Applications can register/unregister their windows with kded modules.
0048      * This allows kpasswdserver and kcookiejar to delete authentication
0049      * and cookies that are local to a particular window when closing it.
0050      */
0051     //@{
0052     /**
0053      * Register a window with KDED
0054      */
0055     void registerWindowId(qlonglong windowId, const QString &sender);
0056     /**
0057      * Unregister a window previously registered with KDED
0058      */
0059     void unregisterWindowId(qlonglong windowId, const QString &sender);
0060     //@}
0061     void recreate(bool initial);
0062     // TODO KF6 remove
0063     void loadSecondPhase();
0064 
0065     //@{
0066     /**
0067      * Check if a module should be loaded on startup.
0068      *
0069      * @param module the name of the desktop file for the module, without the .desktop extension
0070      * @return @c true if the module will be loaded at startup, @c false otherwise
0071      */
0072     bool isModuleAutoloaded(const QString &module) const;
0073     //@}
0074 
0075     //@{
0076     /**
0077      * Check if a module is supported on the current QPA
0078      */
0079     bool platformSupportsModule(const KPluginMetaData &module) const;
0080     //@}
0081 
0082     //@{
0083     /**
0084      * Check if a module should be loaded on demand
0085      *
0086      * @param module the name of the desktop file for the module, without the .desktop extension
0087      * @return @c true if the module will be loaded when its D-Bus interface
0088      *         is requested, @c false otherwise
0089      */
0090     bool isModuleLoadedOnDemand(const QString &module) const;
0091     //@}
0092 
0093     /**
0094      * Configure whether a module should be loaded on startup
0095      *
0096      * If a module is set to be auto-loaded, it will be loaded at the start of a KDE
0097      * session.  Depending on the phase it is set to load in, it may also be loaded
0098      * when the first KDE application is run outside of a KDE session.
0099      *
0100      * @param module the name of the desktop file for the module, without the .desktop extension
0101      * @param autoload if @c true, the module will be loaded at startup,
0102      *                 otherwise it will not
0103      */
0104     void setModuleAutoloading(const QString &module, bool autoload);
0105 
0106 public Q_SLOTS:
0107     KDEDModule *loadModule(const QString &obj, bool onDemand);
0108 
0109     /**
0110      * Loads / unloads modules according to config
0111      */
0112     void initModules();
0113 
0114     /**
0115      * Recreate the database file
0116      */
0117     void recreate();
0118 
0119     /**
0120      * Recreating finished
0121      */
0122     void recreateDone();
0123 
0124     /**
0125      * Collect all directories to watch
0126      */
0127     void updateDirWatch();
0128 
0129     /**
0130      * Update directories to watch
0131      */
0132     void updateResourceList();
0133 
0134     /**
0135      * An application unregistered itself from DBus
0136      */
0137     void slotApplicationRemoved(const QString &);
0138 
0139     /**
0140      * A KDEDModule is about to get destroyed.
0141      */
0142     void slotKDEDModuleRemoved(KDEDModule *);
0143 
0144 protected Q_SLOTS:
0145 
0146     /**
0147      * @internal Triggers rebuilding
0148      */
0149     void dirDeleted(const QString &path);
0150 
0151     /**
0152      * @internal Triggers rebuilding
0153      */
0154     void update(const QString &dir);
0155 
0156     void runDelayedCheck();
0157 
0158 protected:
0159     /**
0160      * Scans dir for new files and new subdirectories.
0161      */
0162     void readDirectory(const QString &dir);
0163     /**
0164      * Check if a module should be loaded on demand
0165      *
0166      * @param module a service description for the module
0167      * @return @c true if the module will be loaded when its D-Bus interface
0168      *         is requested, @c false otherwise
0169      */
0170     bool isModuleLoadedOnDemand(const KPluginMetaData &module) const;
0171 
0172     /**
0173      * Check if a module should be loaded on startup.
0174      *
0175      * @param module a service description for the module
0176      * @return @c true if the module will be loaded at startup, @c false otherwise
0177      */
0178     bool isModuleAutoloaded(const KPluginMetaData &module) const;
0179 
0180     KDEDModule *loadModule(const KPluginMetaData &module, bool onDemand);
0181 
0182     QVector<KPluginMetaData> availableModules() const;
0183     /**
0184      * Pointer to the dirwatch class which tells us, when some directories
0185      * changed.
0186      * Slower polling for remote file systems is now done in KDirWatch (JW).
0187      */
0188     KDirWatch *m_pDirWatch = nullptr;
0189 
0190     /**
0191      * When a desktop file is updated, a timer is started (5 sec)
0192      * before rebuilding the binary - so that multiple updates result
0193      * in only one rebuilding.
0194      */
0195     QTimer *m_pTimer;
0196 
0197     QHash<QString, KDEDModule *> m_modules;
0198     // QHash<QString,KLibrary *> m_libs;
0199     QHash<QString, QObject *> m_dontLoad;
0200 
0201     // window id tracking, with a QDBusServiceWatcher to remove them as needed
0202     QDBusServiceWatcher *m_serviceWatcher;
0203     QHash<QString, QList<qlonglong>> m_windowIdList;
0204     QSet<long> m_globalWindowIdList;
0205 
0206     QStringList m_allResourceDirs;
0207     bool m_needDelayedCheck;
0208 
0209     static Kded *_self;
0210 };
0211 
0212 class KBuildsycocaAdaptor : public QDBusAbstractAdaptor
0213 {
0214     Q_OBJECT
0215     Q_CLASSINFO("D-Bus Interface", "org.kde.kbuildsycoca")
0216 public:
0217     KBuildsycocaAdaptor(QObject *parent);
0218 
0219 public Q_SLOTS:
0220     void recreate();
0221     bool isTestModeEnabled();
0222     void setTestModeEnabled();
0223 };
0224 
0225 class KUpdateD : public QObject
0226 {
0227     Q_OBJECT
0228 public:
0229     KUpdateD();
0230     ~KUpdateD() override;
0231 
0232 public Q_SLOTS:
0233     void runKonfUpdate();
0234     void slotNewUpdateFile(const QString &);
0235 
0236 private:
0237     /**
0238      * Pointer to the dirwatch class which tells us, when some directories
0239      * changed.
0240      * Slower polling for remote file systems is now done in KDirWatch (JW).
0241      */
0242     KDirWatch *m_pDirWatch = nullptr;
0243 
0244     /**
0245      * When a desktop file is updated, a timer is started (5 sec)
0246      * before rebuilding the binary - so that multiple updates result
0247      * in only one rebuilding.
0248      */
0249     QTimer *m_pTimer;
0250 };
0251 
0252 #endif