1 /* 2 This file is part of the KDE libraries 3 SPDX-FileCopyrightText: 2000-2012 David Faure <faure@kde.org> 4 SPDX-FileCopyrightText: 2006 Thiago Macieira <thiago@kde.org> 5 6 SPDX-License-Identifier: LGPL-2.0-or-later 7 */ 8 9 #ifndef KDIRNOTIFY_H 10 #define KDIRNOTIFY_H 11 12 #include "kiocore_export.h" 13 #include <QByteArray> 14 #ifdef QT_DBUS_LIB 15 #include <QDBusAbstractInterface> 16 #include <QList> 17 #include <QMap> 18 #include <QObject> 19 #include <QString> 20 #include <QStringList> 21 #include <QVariant> 22 23 class QDBusConnection; 24 25 /** 26 * \class OrgKdeKDirNotifyInterface kdirnotify.h KDirNotify 27 * 28 * \brief Proxy class for interface org.kde.KDirNotify. 29 * 30 * KDirNotify can be used to inform KIO about changes in real or virtual file systems. 31 * Classes like KDirModel connect to the signals as in the following example to 32 * be able to keep caches up-to-date. 33 * 34 * \code 35 * kdirnotify = new org::kde::KDirNotify(QString(), QString(), QDBusConnection::sessionBus(), this); 36 * connect(kdirnotify, &KDirNotify::FileRenamedWithLocalPath, 37 * this, [this](const QString &src, const QString &dst, const QString &dstPath) { 38 * slotFileRenamed(src, dst, dstPath); 39 * }); 40 * 41 * connect(kdirnotify, &KDirNotify::FilesAdded, 42 * this, [this](const QString &directory) { slotFilesAdded(directory); }); 43 * 44 * connect(kdirnotify, &KDirNotify::FilesChanged, 45 * this, [this](const QStringList &fileList) { slotFilesChanged(fileList); }); 46 * 47 * connect(kdirnotify, &KDirNotify::FilesRemoved, 48 * this, [this](const QStringList &fileList) { slotFilesRemoved(fileList); }); 49 * \endcode 50 * 51 * Especially noteworthy are the empty strings for both \p service and \p path. That 52 * way the client will connect to signals emitted by any application. 53 * 54 * The second usage is to actually emit the signals. For that emitFileRenamed() and friends are 55 * to be used. 56 */ 57 class KIOCORE_EXPORT OrgKdeKDirNotifyInterface : public QDBusAbstractInterface 58 { 59 Q_OBJECT 60 public: staticInterfaceName()61 static inline const char *staticInterfaceName() 62 { 63 return "org.kde.KDirNotify"; 64 } 65 66 public: 67 /** 68 * Create a new KDirNotify interface. 69 * 70 * \param service The service whose signals one wants to listed to. Use an empty 71 * string to connect to all services/applications. 72 * \param path The path to the D-Bus object whose signals one wants to listed to. 73 * Use an empty string to connect to signals from all objects. 74 * \param connection Typically QDBusConnection::sessionBus(). 75 * \param parent The parent QObject. 76 */ 77 OrgKdeKDirNotifyInterface(const QString &service, 78 const QString &path, 79 const QDBusConnection &connection = QDBusConnection::sessionBus(), 80 QObject *parent = nullptr); 81 82 /** 83 * Destructor. 84 */ 85 ~OrgKdeKDirNotifyInterface() override; 86 87 public Q_SLOTS: // METHODS 88 Q_SIGNALS: // SIGNALS 89 void FileRenamed(const QString &src, const QString &dst); 90 void FileRenamedWithLocalPath(const QString &src, const QString &dst, const QString &dstPath); 91 void FileMoved(const QString &src, const QString &dst); 92 void FilesAdded(const QString &directory); 93 void FilesChanged(const QStringList &fileList); 94 void FilesRemoved(const QStringList &fileList); 95 void enteredDirectory(const QString &url); 96 void leftDirectory(const QString &url); 97 98 public: 99 static void emitFileRenamed(const QUrl &src, const QUrl &dst); 100 /** 101 * \param src The old URL of the file that has been renamed. 102 * \param dst The new URL of the file after it was renamed. 103 * \param dstPath The local path of the file after it was renamed. This may be empty 104 * and should otherwise be used to update UDS_LOCAL_PATH. 105 * @since 5.20 106 */ 107 static void emitFileRenamedWithLocalPath(const QUrl &src, const QUrl &dst, const QString &dstPath); 108 static void emitFileMoved(const QUrl &src, const QUrl &dst); 109 static void emitFilesAdded(const QUrl &directory); 110 static void emitFilesChanged(const QList<QUrl> &fileList); 111 static void emitFilesRemoved(const QList<QUrl> &fileList); 112 static void emitEnteredDirectory(const QUrl &url); 113 static void emitLeftDirectory(const QUrl &url); 114 }; 115 116 namespace org 117 { 118 namespace kde 119 { 120 typedef ::OrgKdeKDirNotifyInterface KDirNotify; 121 } 122 } 123 #endif 124 #endif 125