File indexing completed on 2024-05-12 03:54:26

0001 /*
0002     SPDX-FileCopyrightText: 2018 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KCONFIGWATCHER_H
0008 #define KCONFIGWATCHER_H
0009 
0010 #include <QObject>
0011 #include <QSharedPointer>
0012 
0013 #include <KConfigGroup>
0014 #include <KSharedConfig>
0015 
0016 #include <kconfigcore_export.h>
0017 
0018 class KConfigWatcherPrivate;
0019 
0020 /**
0021  * \class KConfigWatcher kconfigwatcher.h <KConfigWatcher>
0022  *
0023  * Notifies when another client has updated this config file with the Notify flag set.
0024  * @since 5.51
0025  */
0026 class KCONFIGCORE_EXPORT KConfigWatcher : public QObject
0027 {
0028     Q_OBJECT
0029 public:
0030     typedef QSharedPointer<KConfigWatcher> Ptr;
0031 
0032     /**
0033      * Instantiate a ConfigWatcher for a given config
0034      *
0035      * @note any additional config sources should be set before this point.
0036      */
0037     static Ptr create(const KSharedConfig::Ptr &config);
0038 
0039     ~KConfigWatcher() override;
0040 
0041     /**
0042      * Returns the config being watched
0043      * @since 5.66
0044      */
0045     KSharedConfig::Ptr config() const;
0046 
0047 Q_SIGNALS:
0048     /**
0049      * Emitted when a config group has changed
0050      * The config will be reloaded before this signal is emitted
0051      *
0052      * @arg group the config group that has changed
0053      * @arg names a list of entries that have changed within that group (UTF-8 encoded)
0054      */
0055     void configChanged(const KConfigGroup &group, const QByteArrayList &names);
0056 
0057 private Q_SLOTS:
0058     KCONFIGCORE_NO_EXPORT void onConfigChangeNotification(const QHash<QString, QByteArrayList> &changes);
0059 
0060 private:
0061     KCONFIGCORE_NO_EXPORT explicit KConfigWatcher(const KSharedConfig::Ptr &config);
0062     Q_DISABLE_COPY(KConfigWatcher)
0063     const QScopedPointer<KConfigWatcherPrivate> d;
0064 };
0065 
0066 #endif