Warning, file /maui/mauikit-filebrowsing/src/code/fm.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #pragma once 0002 0003 #include <QObject> 0004 0005 #include <QStringList> 0006 #include <QVariantList> 0007 #include <QDirIterator> 0008 #include <QVector> 0009 0010 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0011 #include <MauiKit3/Core/fmh.h> 0012 #else 0013 #include <MauiKit4/Core/fmh.h> 0014 #endif 0015 0016 #include "fmstatic.h" 0017 #include "filebrowsing_export.h" 0018 0019 #ifdef KIO_AVAILABLE 0020 class KCoreDirLister; 0021 #else 0022 0023 class QFileSystemWatcher; 0024 0025 namespace FMH 0026 { 0027 class FileLoader; 0028 } 0029 /** 0030 * @private The QDirLister class is a placeholder for the KCoreDirLister for other systems other than GNU Linux. 0031 */ 0032 class QDirLister : public QObject 0033 { 0034 Q_OBJECT 0035 Q_DISABLE_COPY(QDirLister) 0036 0037 public: 0038 explicit QDirLister(QObject *parent = nullptr); 0039 0040 public Q_SLOTS: 0041 /** 0042 * @brief openUrl 0043 * @param url 0044 * @return 0045 */ 0046 bool openUrl(const QUrl &url); 0047 0048 /** 0049 * @brief setNameFilter 0050 * @param filters 0051 */ 0052 void setNameFilter(QString filters); 0053 0054 /** 0055 * @brief setDirOnlyMode 0056 * @param value 0057 */ 0058 void setDirOnlyMode(bool value); 0059 0060 /** 0061 * @brief setShowingDotFiles 0062 * @param value 0063 */ 0064 void setShowingDotFiles(bool value); 0065 0066 Q_SIGNALS: 0067 void itemsReady(FMH::MODEL_LIST items, QUrl url); 0068 void itemReady(FMH::MODEL item, QUrl url); 0069 void completed(QUrl url); 0070 void itemsAdded(FMH::MODEL_LIST items, QUrl url); 0071 void itemsDeleted(FMH::MODEL_LIST items, QUrl url); 0072 void newItems(FMH::MODEL_LIST items, QUrl url); 0073 void refreshItems(QVector<QPair<FMH::MODEL, FMH::MODEL>> items, QUrl url); 0074 0075 private: 0076 FMH::FileLoader *m_loader; 0077 QFileSystemWatcher *m_watcher; 0078 0079 FMH::MODEL_LIST m_list; 0080 QString m_nameFilters; 0081 QUrl m_url; 0082 bool m_dirOnly = false; 0083 bool m_showDotFiles = false; 0084 0085 bool m_checking = false; 0086 0087 void reviewChanges(); 0088 bool includes(const QUrl &url); 0089 int indexOf(const FMH::MODEL_KEY &key, const QString &value) const; 0090 }; 0091 #endif 0092 0093 class Syncing; 0094 0095 /** 0096 * @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`. 0097 * 0098 * @warning File syncing support with webDAV cloud providers, such as NextCloud, is still work in progress. 0099 * 0100 */ 0101 class FILEBROWSING_EXPORT FM : public QObject 0102 { 0103 Q_OBJECT 0104 Q_DISABLE_COPY(FM) 0105 0106 public: 0107 0108 /** 0109 * @brief Creates the instance. 0110 */ 0111 FM(QObject *parent = nullptr); 0112 0113 //Syncing 0114 0115 /** 0116 * @brief Given a server URL address retrieve its contents. This only works if the syncing component has been enabled with `COMPONENT_SYNCING` 0117 * @see cloudServerContentReady 0118 * @param server the server URL 0119 * @param filters the list of string filters to be applied 0120 * @param depth how deep in the directory three to go, for example, `1` keeps the retrieval in the first level or current directory. 0121 * @return whether the operation was successful. 0122 */ 0123 bool getCloudServerContent(const QUrl &server, const QStringList &filters = QStringList(), const int &depth = 0); 0124 0125 /** 0126 * @brief Creates a directory in the server. This only works if the syncing component has been enabled `COMPONENT_SYNCING`. 0127 * @param path the server location where to create the new directory 0128 * @param name directory name 0129 */ 0130 Q_INVOKABLE void createCloudDir(const QString &path, const QString &name); 0131 0132 /** 0133 * @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` 0134 * @param path the directory path 0135 * @param hidden whether to pack hidden files 0136 * @param onlyDirs whether to only pack directories 0137 * @param filters the list of string filters to be applied 0138 * @param iteratorFlags the directory iterator flags, for reference check QDirIterator documentation 0139 */ 0140 void getPathContent(const QUrl &path, const bool &hidden = false, const bool &onlyDirs = false, const QStringList &filters = QStringList(), const QDirIterator::IteratorFlags &iteratorFlags = QDirIterator::NoIteratorFlags); 0141 0142 /** 0143 * @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` 0144 * @param path the remote Server address 0145 * @return the resolved server path as a local URL 0146 */ 0147 QString resolveLocalCloudPath(const QString &path); 0148 0149 /** 0150 * @brief Given the server address and the user name, resolve a local path for the cache of the files. 0151 * @param server the remove server address 0152 * @param user the user name of the server 0153 * @return 0154 */ 0155 static QString resolveUserCloudCachePath(const QString &server, const QString &user); 0156 0157 #ifdef COMPONENT_SYNCING 0158 Syncing *sync; 0159 #endif 0160 0161 private: 0162 0163 #ifdef KIO_AVAILABLE 0164 KCoreDirLister *dirLister; 0165 #else 0166 QDirLister *dirLister; 0167 #endif 0168 0169 Q_SIGNALS: 0170 0171 /** 0172 * @brief Emitted once the requested contents of the server are ready. 0173 * @param list the contents packaged in a list, with the file information 0174 */ 0175 void cloudServerContentReady(FMStatic::PATH_CONTENT list); 0176 0177 /** 0178 * @brief Emitted for every single item that becomes available, from the requested remote server location. 0179 * @param item the item data 0180 * @param path the URL of the remote location initially requested 0181 */ 0182 void cloudItemReady(FMH::MODEL item, QUrl path); 0183 0184 /** 0185 * @brief Emitted once the contents of the current location are ready and the listing has finished. 0186 * @param path the requested location path 0187 */ 0188 void pathContentReady(QUrl path); 0189 0190 /** 0191 * @brief Emitted when a set of entries for the current location are ready. 0192 * @param list the contents packaged in a list, with the file information 0193 */ 0194 void pathContentItemsReady(FMStatic::PATH_CONTENT list); 0195 0196 /** 0197 * @brief Emitted when the contents of the current location has changed, either by some new entries being added or removed. 0198 * @param path the requested location which has changed 0199 */ 0200 void pathContentChanged(QUrl path); 0201 0202 /** 0203 * @brief Emitted when the current location entries have changed. 0204 * @param items the list of pair of entries that have changed, where first is the old version and second is the new version. 0205 */ 0206 void pathContentItemsChanged(QVector<QPair<FMH::MODEL, FMH::MODEL>> items); 0207 0208 /** 0209 * @brief Emitted when a set of entries in the current location have been removed. 0210 * @param list the removed contents packaged in a list, with the file information 0211 */ 0212 void pathContentItemsRemoved(FMStatic::PATH_CONTENT list); 0213 0214 /** 0215 * @brief Emitted when there is an error. 0216 * @param message the error message 0217 */ 0218 void warningMessage(QString message); 0219 0220 /** 0221 * @brief Emitted with the progress of the listing. 0222 * @param percent the progress percent form 0 to 100 0223 */ 0224 void loadProgress(int percent); 0225 0226 /** 0227 * @brief Emitted when a directory has been created in the remote server in the current location. 0228 * @param dir the information of the newly created directory 0229 */ 0230 void dirCreated(FMH::MODEL dir); 0231 0232 /** 0233 * @brief Emitted when a new item is available in the remote server in the current location. 0234 * @param item the new item information 0235 * @param path the path location of the new item 0236 */ 0237 void newItem(FMH::MODEL item, QUrl path); 0238 0239 public Q_SLOTS: 0240 /** 0241 * @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. 0242 * @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. 0243 */ 0244 void openCloudItem(const QVariantMap &item); 0245 0246 /** 0247 * @brief Download a remote server entry. 0248 * @param item the item data. 0249 */ 0250 void getCloudItem(const QVariantMap &item); 0251 0252 //Actions 0253 /** 0254 * @brief Copy a set of file URLs to a new destination 0255 * @param urls the list of file URLs to be copied. 0256 * @param where the new location to copy the files 0257 */ 0258 bool copy(const QList<QUrl> &urls, const QUrl &where); 0259 0260 /** 0261 * @brief Cut a set of file URLs to a new destination 0262 * @param urls the list of file URLs to be cut. 0263 * @param where the new location to paste the files 0264 */ 0265 bool cut(const QList<QUrl> &urls, const QUrl &where); 0266 0267 friend class FMStatic; 0268 };