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