MauiKit File Browsing

fm.h
1#pragma once
2
3#include <QObject>
4
5#include <QStringList>
6#include <QVariantList>
7#include <QDirIterator>
8#include <QVector>
9
10#include <MauiKit4/Core/fmh.h>
11
12#include "fmstatic.h"
13#include "filebrowsing_export.h"
14
15#ifdef KIO_AVAILABLE
16class KCoreDirLister;
17#else
18
20
21namespace FMH
22{
23class FileLoader;
24}
25/**
26 * @private The QDirLister class is a placeholder for the KCoreDirLister for other systems other than GNU Linux.
27 */
28class QDirLister : public QObject
29{
31 Q_DISABLE_COPY(QDirLister)
32
33public:
34 explicit QDirLister(QObject *parent = nullptr);
35
36public Q_SLOTS:
37 /**
38 * @brief openUrl
39 * @param url
40 * @return
41 */
42 bool openUrl(const QUrl &url);
43
44 /**
45 * @brief setNameFilter
46 * @param filters
47 */
48 void setNameFilter(QString filters);
49
50 /**
51 * @brief setDirOnlyMode
52 * @param value
53 */
54 void setDirOnlyMode(bool value);
55
56 /**
57 * @brief setShowingDotFiles
58 * @param value
59 */
60 void setShowingDotFiles(bool value);
61
62 /**
63 * @brief setShowHiddenFiles Placeholder method, just calls back to setShowingDotFiles
64 * @param value
65 */
66 void setShowHiddenFiles(bool value);
67
69 void itemsReady(FMH::MODEL_LIST items, QUrl url);
70 void itemReady(FMH::MODEL item, QUrl url);
71 void completed(QUrl url);
72 void itemsAdded(FMH::MODEL_LIST items, QUrl url);
73 void itemsDeleted(FMH::MODEL_LIST items, QUrl url);
74 void newItems(FMH::MODEL_LIST items, QUrl url);
75 void refreshItems(QVector<QPair<FMH::MODEL, FMH::MODEL>> items, QUrl url);
76
77private:
78 FMH::FileLoader *m_loader;
79 QFileSystemWatcher *m_watcher;
80
81 FMH::MODEL_LIST m_list;
82 QString m_nameFilters;
83 QUrl m_url;
84 bool m_dirOnly = false;
85 bool m_showDotFiles = false;
86
87 bool m_checking = false;
88
89 void reviewChanges();
90 bool includes(const QUrl &url);
91 int indexOf(const FMH::MODEL_KEY &key, const QString &value) const;
92};
93#endif
94
95class Syncing;
96
97/**
98 * @brief The FM class stands for File Management, and exposes methods for file listing, browsing and handling, with syncing and tagging integration if such components were enabled with the build flags `COMPONENT_SYNCING` and `COMPONENT_TAGGING`.
99 *
100 * @warning File syncing support with webDAV cloud providers, such as NextCloud, is still work in progress.
101 *
102 */
103class FILEBROWSING_EXPORT FM : public QObject
104{
105 Q_OBJECT
106 Q_DISABLE_COPY(FM)
107
108public:
109
110 /**
111 * @brief Creates the instance.
112 */
113 FM(QObject *parent = nullptr);
114
115 //Syncing
116
117 /**
118 * @brief Given a server URL address retrieve its contents. This only works if the syncing component has been enabled with `COMPONENT_SYNCING`
119 * @see cloudServerContentReady
120 * @param server the server URL
121 * @param filters the list of string filters to be applied
122 * @param depth how deep in the directory three to go, for example, `1` keeps the retrieval in the first level or current directory.
123 * @return whether the operation was successful.
124 */
125 bool getCloudServerContent(const QUrl &server, const QStringList &filters = QStringList(), const int &depth = 0);
126
127 /**
128 * @brief Creates a directory in the server. This only works if the syncing component has been enabled `COMPONENT_SYNCING`.
129 * @param path the server location where to create the new directory
130 * @param name directory name
131 */
132 Q_INVOKABLE void createCloudDir(const QString &path, const QString &name);
133
134 /**
135 * @brief Given a path URL retrieve the contents information packaged as a model. This method is asynchronous and once items become ready the signals will be emitted, such as, `pathContentItemsReady` or `pathContentReady`
136 * @param path the directory path
137 * @param hidden whether to pack hidden files
138 * @param onlyDirs whether to only pack directories
139 * @param filters the list of string filters to be applied
140 * @param iteratorFlags the directory iterator flags, for reference check QDirIterator documentation
141 */
142 void getPathContent(const QUrl &path, const bool &hidden = false, const bool &onlyDirs = false, const QStringList &filters = QStringList(), const QDirIterator::IteratorFlags &iteratorFlags = QDirIterator::NoIteratorFlags);
143
144 /**
145 * @brief Given a remote server address URL, resolve it to the local cache URL. This only works if the syncing component has been enabled `COMPONENT_SYNCING=ON`
146 * @param path the remote Server address
147 * @return the resolved server path as a local URL
148 */
149 QString resolveLocalCloudPath(const QString &path);
150
151 /**
152 * @brief Given the server address and the user name, resolve a local path for the cache of the files.
153 * @param server the remove server address
154 * @param user the user name of the server
155 * @return
156 */
157 static QString resolveUserCloudCachePath(const QString &server, const QString &user);
158
159#ifdef COMPONENT_SYNCING
160 Syncing *sync;
161#endif
162
163private:
164
165#ifdef KIO_AVAILABLE
166 KCoreDirLister *dirLister;
167#else
168 QDirLister *dirLister;
169#endif
170
172
173 /**
174 * @brief Emitted once the requested contents of the server are ready.
175 * @param list the contents packaged in a list, with the file information
176 */
178
179 /**
180 * @brief Emitted for every single item that becomes available, from the requested remote server location.
181 * @param item the item data
182 * @param path the URL of the remote location initially requested
183 */
184 void cloudItemReady(FMH::MODEL item, QUrl path);
185
186 /**
187 * @brief Emitted once the contents of the current location are ready and the listing has finished.
188 * @param path the requested location path
189 */
191
192 /**
193 * @brief Emitted when a set of entries for the current location are ready.
194 * @param list the contents packaged in a list, with the file information
195 */
197
198 /**
199 * @brief Emitted when the contents of the current location has changed, either by some new entries being added or removed.
200 * @param path the requested location which has changed
201 */
203
204 /**
205 * @brief Emitted when the current location entries have changed.
206 * @param items the list of pair of entries that have changed, where first is the old version and second is the new version.
207 */
208 void pathContentItemsChanged(QVector<QPair<FMH::MODEL, FMH::MODEL>> items);
209
210 /**
211 * @brief Emitted when a set of entries in the current location have been removed.
212 * @param list the removed contents packaged in a list, with the file information
213 */
215
216 /**
217 * @brief Emitted when there is an error.
218 * @param message the error message
219 */
220 void warningMessage(QString message);
221
222 /**
223 * @brief Emitted with the progress of the listing.
224 * @param percent the progress percent form 0 to 100
225 */
226 void loadProgress(int percent);
227
228 /**
229 * @brief Emitted when a directory has been created in the remote server in the current location.
230 * @param dir the information of the newly created directory
231 */
233
234 /**
235 * @brief Emitted when a new item is available in the remote server in the current location.
236 * @param item the new item information
237 * @param path the path location of the new item
238 */
239 void newItem(FMH::MODEL item, QUrl path);
240
241public Q_SLOTS:
242 /**
243 * @brief Open a given remote item in an external application. If the item does not exists in the system local cache, then it is downloaded first.
244 * @param item the item data. This is exposed this way for convenience of usage from QML, where the item entry from the model will become a QVariantMap.
245 */
246 void openCloudItem(const QVariantMap &item);
247
248 /**
249 * @brief Download a remote server entry.
250 * @param item the item data.
251 */
252 void getCloudItem(const QVariantMap &item);
253
254 //Actions
255 /**
256 * @brief Copy a set of file URLs to a new destination
257 * @param urls the list of file URLs to be copied.
258 * @param where the new location to copy the files
259 */
260 bool copy(const QList<QUrl> &urls, const QUrl &where);
261
262 /**
263 * @brief Cut a set of file URLs to a new destination
264 * @param urls the list of file URLs to be cut.
265 * @param where the new location to paste the files
266 */
267 bool cut(const QList<QUrl> &urls, const QUrl &where);
268
269 friend class FMStatic;
270};
The FileLoader class asynchronously loads batches of files from a given list of local directories or ...
Definition fileloader.h:76
The FMStatic class is a group of static file management methods, this class has a constructor only as...
Definition fmstatic.h:30
The FM class stands for File Management, and exposes methods for file listing, browsing and handling,...
Definition fm.h:104
void warningMessage(QString message)
Emitted when there is an error.
void cloudItemReady(FMH::MODEL item, QUrl path)
Emitted for every single item that becomes available, from the requested remote server location.
void cloudServerContentReady(FMStatic::PATH_CONTENT list)
Emitted once the requested contents of the server are ready.
void newItem(FMH::MODEL item, QUrl path)
Emitted when a new item is available in the remote server in the current location.
void pathContentItemsRemoved(FMStatic::PATH_CONTENT list)
Emitted when a set of entries in the current location have been removed.
void loadProgress(int percent)
Emitted with the progress of the listing.
void pathContentReady(QUrl path)
Emitted once the contents of the current location are ready and the listing has finished.
void pathContentItemsChanged(QVector< QPair< FMH::MODEL, FMH::MODEL > > items)
Emitted when the current location entries have changed.
void pathContentItemsReady(FMStatic::PATH_CONTENT list)
Emitted when a set of entries for the current location are ready.
void pathContentChanged(QUrl path)
Emitted when the contents of the current location has changed, either by some new entries being added...
void dirCreated(FMH::MODEL dir)
Emitted when a directory has been created in the remote server in the current location.
The Syncing class.
Definition syncing.h:18
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
A location contents structured for convenience.
Definition fmstatic.h:238
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.