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
63 void itemsReady(FMH::MODEL_LIST items, QUrl url);
64 void itemReady(FMH::MODEL item, QUrl url);
65 void completed(QUrl url);
66 void itemsAdded(FMH::MODEL_LIST items, QUrl url);
67 void itemsDeleted(FMH::MODEL_LIST items, QUrl url);
68 void newItems(FMH::MODEL_LIST items, QUrl url);
69 void refreshItems(QVector<QPair<FMH::MODEL, FMH::MODEL>> items, QUrl url);
70
71private:
72 FMH::FileLoader *m_loader;
73 QFileSystemWatcher *m_watcher;
74
75 FMH::MODEL_LIST m_list;
76 QString m_nameFilters;
77 QUrl m_url;
78 bool m_dirOnly = false;
79 bool m_showDotFiles = false;
80
81 bool m_checking = false;
82
83 void reviewChanges();
84 bool includes(const QUrl &url);
85 int indexOf(const FMH::MODEL_KEY &key, const QString &value) const;
86};
87#endif
88
89class Syncing;
90
91/**
92 * @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`.
93 *
94 * @warning File syncing support with webDAV cloud providers, such as NextCloud, is still work in progress.
95 *
96 */
97class FILEBROWSING_EXPORT FM : public QObject
98{
99 Q_OBJECT
100 Q_DISABLE_COPY(FM)
101
102public:
103
104 /**
105 * @brief Creates the instance.
106 */
107 FM(QObject *parent = nullptr);
108
109 //Syncing
110
111 /**
112 * @brief Given a server URL address retrieve its contents. This only works if the syncing component has been enabled with `COMPONENT_SYNCING`
113 * @see cloudServerContentReady
114 * @param server the server URL
115 * @param filters the list of string filters to be applied
116 * @param depth how deep in the directory three to go, for example, `1` keeps the retrieval in the first level or current directory.
117 * @return whether the operation was successful.
118 */
119 bool getCloudServerContent(const QUrl &server, const QStringList &filters = QStringList(), const int &depth = 0);
120
121 /**
122 * @brief Creates a directory in the server. This only works if the syncing component has been enabled `COMPONENT_SYNCING`.
123 * @param path the server location where to create the new directory
124 * @param name directory name
125 */
126 Q_INVOKABLE void createCloudDir(const QString &path, const QString &name);
127
128 /**
129 * @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`
130 * @param path the directory path
131 * @param hidden whether to pack hidden files
132 * @param onlyDirs whether to only pack directories
133 * @param filters the list of string filters to be applied
134 * @param iteratorFlags the directory iterator flags, for reference check QDirIterator documentation
135 */
136 void getPathContent(const QUrl &path, const bool &hidden = false, const bool &onlyDirs = false, const QStringList &filters = QStringList(), const QDirIterator::IteratorFlags &iteratorFlags = QDirIterator::NoIteratorFlags);
137
138 /**
139 * @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`
140 * @param path the remote Server address
141 * @return the resolved server path as a local URL
142 */
143 QString resolveLocalCloudPath(const QString &path);
144
145 /**
146 * @brief Given the server address and the user name, resolve a local path for the cache of the files.
147 * @param server the remove server address
148 * @param user the user name of the server
149 * @return
150 */
151 static QString resolveUserCloudCachePath(const QString &server, const QString &user);
152
153#ifdef COMPONENT_SYNCING
154 Syncing *sync;
155#endif
156
157private:
158
159#ifdef KIO_AVAILABLE
160 KCoreDirLister *dirLister;
161#else
162 QDirLister *dirLister;
163#endif
164
166
167 /**
168 * @brief Emitted once the requested contents of the server are ready.
169 * @param list the contents packaged in a list, with the file information
170 */
172
173 /**
174 * @brief Emitted for every single item that becomes available, from the requested remote server location.
175 * @param item the item data
176 * @param path the URL of the remote location initially requested
177 */
178 void cloudItemReady(FMH::MODEL item, QUrl path);
179
180 /**
181 * @brief Emitted once the contents of the current location are ready and the listing has finished.
182 * @param path the requested location path
183 */
185
186 /**
187 * @brief Emitted when a set of entries for the current location are ready.
188 * @param list the contents packaged in a list, with the file information
189 */
191
192 /**
193 * @brief Emitted when the contents of the current location has changed, either by some new entries being added or removed.
194 * @param path the requested location which has changed
195 */
197
198 /**
199 * @brief Emitted when the current location entries have changed.
200 * @param items the list of pair of entries that have changed, where first is the old version and second is the new version.
201 */
202 void pathContentItemsChanged(QVector<QPair<FMH::MODEL, FMH::MODEL>> items);
203
204 /**
205 * @brief Emitted when a set of entries in the current location have been removed.
206 * @param list the removed contents packaged in a list, with the file information
207 */
209
210 /**
211 * @brief Emitted when there is an error.
212 * @param message the error message
213 */
214 void warningMessage(QString message);
215
216 /**
217 * @brief Emitted with the progress of the listing.
218 * @param percent the progress percent form 0 to 100
219 */
220 void loadProgress(int percent);
221
222 /**
223 * @brief Emitted when a directory has been created in the remote server in the current location.
224 * @param dir the information of the newly created directory
225 */
227
228 /**
229 * @brief Emitted when a new item is available in the remote server in the current location.
230 * @param item the new item information
231 * @param path the path location of the new item
232 */
233 void newItem(FMH::MODEL item, QUrl path);
234
235public Q_SLOTS:
236 /**
237 * @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.
238 * @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.
239 */
240 void openCloudItem(const QVariantMap &item);
241
242 /**
243 * @brief Download a remote server entry.
244 * @param item the item data.
245 */
246 void getCloudItem(const QVariantMap &item);
247
248 //Actions
249 /**
250 * @brief Copy a set of file URLs to a new destination
251 * @param urls the list of file URLs to be copied.
252 * @param where the new location to copy the files
253 */
254 bool copy(const QList<QUrl> &urls, const QUrl &where);
255
256 /**
257 * @brief Cut a set of file URLs to a new destination
258 * @param urls the list of file URLs to be cut.
259 * @param where the new location to paste the files
260 */
261 bool cut(const QList<QUrl> &urls, const QUrl &where);
262
263 friend class FMStatic;
264};
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:98
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
typedef IteratorFlags
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
A location contents structured for convenience.
Definition fmstatic.h:239
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:53:26 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.