File indexing completed on 2024-04-28 07:42:33

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 
0063     //@{
0064     /**
0065      * Check if a module should be loaded on startup.
0066      *
0067      * @param module the name of the desktop file for the module, without the .desktop extension
0068      * @return @c true if the module will be loaded at startup, @c false otherwise
0069      */
0070     bool isModuleAutoloaded(const QString &module) const;
0071     //@}
0072 
0073     //@{
0074     /**
0075      * Check if a module is supported on the current QPA
0076      */
0077     bool platformSupportsModule(const KPluginMetaData &module) const;
0078     //@}
0079 
0080     //@{
0081     /**
0082      * Check if a module should be loaded on demand
0083      *
0084      * @param module the name of the desktop file for the module, without the .desktop extension
0085      * @return @c true if the module will be loaded when its D-Bus interface
0086      *         is requested, @c false otherwise
0087      */
0088     bool isModuleLoadedOnDemand(const QString &module) const;
0089     //@}
0090 
0091     /**
0092      * Configure whether a module should be loaded on startup
0093      *
0094      * If a module is set to be auto-loaded, it will be loaded at the start of a KDE
0095      * session.  Depending on the phase it is set to load in, it may also be loaded
0096      * when the first KDE application is run outside of a KDE session.
0097      *
0098      * @param module the name of the desktop file for the module, without the .desktop extension
0099      * @param autoload if @c true, the module will be loaded at startup,
0100      *                 otherwise it will not
0101      */
0102     void setModuleAutoloading(const QString &module, bool autoload);
0103 
0104 public Q_SLOTS:
0105     KDEDModule *loadModule(const QString &obj, bool onDemand);
0106 
0107     /**
0108      * Loads / unloads modules according to config
0109      */
0110     void initModules();
0111 
0112     /**
0113      * Recreate the database file
0114      */
0115     void recreate();
0116 
0117     /**
0118      * Recreating finished
0119      */
0120     void recreateDone();
0121 
0122     /**
0123      * Collect all directories to watch
0124      */
0125     void updateDirWatch();
0126 
0127     /**
0128      * Update directories to watch
0129      */
0130     void updateResourceList();
0131 
0132     /**
0133      * An application unregistered itself from DBus
0134      */
0135     void slotApplicationRemoved(const QString &);
0136 
0137 protected Q_SLOTS:
0138 
0139     /**
0140      * @internal Triggers rebuilding
0141      */
0142     void dirDeleted(const QString &path);
0143 
0144     /**
0145      * @internal Triggers rebuilding
0146      */
0147     void update(const QString &dir);
0148 
0149     void runDelayedCheck();
0150 
0151 protected:
0152     /**
0153      * Scans dir for new files and new subdirectories.
0154      */
0155     void readDirectory(const QString &dir);
0156     /**
0157      * Check if a module should be loaded on demand
0158      *
0159      * @param module a service description for the module
0160      * @return @c true if the module will be loaded when its D-Bus interface
0161      *         is requested, @c false otherwise
0162      */
0163     bool isModuleLoadedOnDemand(const KPluginMetaData &module) const;
0164 
0165     /**
0166      * Check if a module should be loaded on startup.
0167      *
0168      * @param module a service description for the module
0169      * @return @c true if the module will be loaded at startup, @c false otherwise
0170      */
0171     bool isModuleAutoloaded(const KPluginMetaData &module) const;
0172 
0173     KDEDModule *loadModule(const KPluginMetaData &module, bool onDemand);
0174 
0175     QList<KPluginMetaData> availableModules() const;
0176     /**
0177      * Pointer to the dirwatch class which tells us, when some directories
0178      * changed.
0179      * Slower polling for remote file systems is now done in KDirWatch (JW).
0180      */
0181     KDirWatch *m_pDirWatch = nullptr;
0182 
0183     /**
0184      * When a desktop file is updated, a timer is started (5 sec)
0185      * before rebuilding the binary - so that multiple updates result
0186      * in only one rebuilding.
0187      */
0188     QTimer *m_pTimer;
0189 
0190     QHash<QString, KDEDModule *> m_modules;
0191     // QHash<QString,KLibrary *> m_libs;
0192     QHash<QString, QObject *> m_dontLoad;
0193 
0194     // window id tracking, with a QDBusServiceWatcher to remove them as needed
0195     QDBusServiceWatcher *m_serviceWatcher;
0196     QHash<QString, QList<qlonglong>> m_windowIdList;
0197     QSet<long> m_globalWindowIdList;
0198 
0199     QStringList m_allResourceDirs;
0200     bool m_needDelayedCheck;
0201 
0202     static Kded *_self;
0203 };
0204 
0205 class KUpdateD : public QObject
0206 {
0207     Q_OBJECT
0208 public:
0209     KUpdateD();
0210     ~KUpdateD() override;
0211 
0212 public Q_SLOTS:
0213     void runKonfUpdate();
0214     void slotNewUpdateFile(const QString &);
0215 
0216 private:
0217     /**
0218      * Pointer to the dirwatch class which tells us, when some directories
0219      * changed.
0220      * Slower polling for remote file systems is now done in KDirWatch (JW).
0221      */
0222     KDirWatch *m_pDirWatch = nullptr;
0223 
0224     /**
0225      * When a desktop file is updated, a timer is started (5 sec)
0226      * before rebuilding the binary - so that multiple updates result
0227      * in only one rebuilding.
0228      */
0229     QTimer *m_pTimer;
0230 };
0231 
0232 #endif