Warning, file /maui/mauikit-filebrowsing/src/code/fmstatic.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 <QtGlobal> 0004 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0005 #include <MauiKit3/Core/fmh.h> 0006 #else 0007 #include <MauiKit4/Core/fmh.h> 0008 #endif 0009 0010 #include <QObject> 0011 #include <QString> 0012 #include <QMimeData> 0013 #include <QMimeDatabase> 0014 #include <QMimeType> 0015 #include <QStandardPaths> 0016 #include <QUrl> 0017 0018 #ifdef Q_OS_ANDROID 0019 #include <MauiKit3/Core/mauiandroid.h> 0020 #endif 0021 0022 #ifdef KIO_AVAILABLE 0023 class KFileItem; 0024 #endif 0025 0026 #include "filebrowsing_export.h" 0027 0028 /** 0029 * @brief The FMStatic class is a group of static file management methods, this class has a constructor only as a way to register it to QML, however all methods in here are static. 0030 */ 0031 class FILEBROWSING_EXPORT FMStatic : public QObject 0032 { 0033 Q_OBJECT 0034 Q_DISABLE_COPY(FMStatic) 0035 0036 public: 0037 /** 0038 * @private 0039 */ 0040 explicit FMStatic(QObject *parent = nullptr); 0041 0042 /** 0043 * @brief The common file types for filtering 0044 */ 0045 enum FILTER_TYPE : int { AUDIO, VIDEO, TEXT, IMAGE, DOCUMENT, COMPRESSED, FONT, NONE }; 0046 0047 /** 0048 * @brief The list supported audio formats, associated to the FILTER_TYPE::AUDIO. 0049 */ 0050 inline static const QStringList AUDIO_MIMETYPES = { 0051 QStringLiteral("audio/mpeg"), 0052 QStringLiteral("audio/mp4"), 0053 QStringLiteral("audio/flac"), 0054 QStringLiteral("audio/ogg"), 0055 QStringLiteral("audio/wav")}; 0056 0057 /** 0058 * @brief The list supported video formats, associated to the FILTER_TYPE::VIDEO. 0059 */ 0060 inline static const QStringList VIDEO_MIMETYPES = { 0061 QStringLiteral("video/mp4"), 0062 QStringLiteral("video/x-matroska"), 0063 QStringLiteral("video/webm"), 0064 QStringLiteral("video/avi"), 0065 QStringLiteral("video/flv"), 0066 QStringLiteral("video/mpg"), 0067 QStringLiteral("video/wmv"), 0068 QStringLiteral("video/mov"), 0069 QStringLiteral("video/quicktime"), 0070 QStringLiteral("video/ogg"), 0071 QStringLiteral("video/x-flv"), 0072 QStringLiteral("video/mpeg"), 0073 QStringLiteral("video/jpeg")}; 0074 0075 /** 0076 * @brief The list supported text formats, associated to the FILTER_TYPE::TEXT. 0077 */ 0078 inline static const QStringList TEXT_MIMETYPES = { 0079 QStringLiteral("text/markdown"), 0080 QStringLiteral("text/x-chdr"), 0081 QStringLiteral("text/x-c++src"), 0082 QStringLiteral("text/x-c++hdr"), 0083 QStringLiteral("text/css"), 0084 QStringLiteral("text/html"), 0085 QStringLiteral("text/plain"), 0086 QStringLiteral("text/richtext"), 0087 QStringLiteral("text/scriptlet"), 0088 QStringLiteral("text/x-vcard"), 0089 QStringLiteral("text/x-go"), 0090 QStringLiteral("text/x-cmake"), 0091 QStringLiteral("text/x-makefile"), 0092 QStringLiteral("text/x-qml"), 0093 QStringLiteral("text/x-java"), 0094 QStringLiteral("text/x-log"), 0095 QStringLiteral("text/x-python"), 0096 QStringLiteral("text/*"), 0097 QStringLiteral("text/x-copying"), 0098 QStringLiteral("text/x-dbus-service"), 0099 QStringLiteral("text/x-gettext-translation"), 0100 QStringLiteral("application/xml"), 0101 QStringLiteral("application/vnd.kde.knotificationrc"), 0102 QStringLiteral("application/x-gitignore"), 0103 QStringLiteral("application/javascript"), 0104 QStringLiteral("application/json"), 0105 QStringLiteral("application/pgp-keys"), 0106 QStringLiteral("application/x-shellscript"), 0107 QStringLiteral("application/x-cmakecache"), 0108 QStringLiteral("application/x-yaml"), 0109 QStringLiteral("application/x-perl"), 0110 QStringLiteral("application/x-kdevelop"), 0111 QStringLiteral("application/x-kicad-project")}; 0112 0113 /** 0114 * @brief The list supported image formats, associated to the FILTER_TYPE::IMAGE. 0115 */ 0116 inline static const QStringList IMAGE_MIMETYPES = { 0117 QStringLiteral("image/bmp"), 0118 QStringLiteral("image/webp"), 0119 QStringLiteral("image/png"), 0120 QStringLiteral("image/gif"), 0121 QStringLiteral("image/jpeg"), 0122 QStringLiteral("image/web"), 0123 QStringLiteral("image/svg"), 0124 QStringLiteral("image/svg+xml"), 0125 QStringLiteral("application/x-krita"), 0126 QStringLiteral("image/x-xcf"), 0127 QStringLiteral("image/vnd.adobe.photoshop"), 0128 QStringLiteral("image/x-eps"), 0129 QStringLiteral("image/jxl"), 0130 QStringLiteral("image/avif")}; 0131 0132 /** 0133 * @brief The list supported document formats, associated to the FILTER_TYPE::DOCUMENT. 0134 */ 0135 inline static const QStringList DOCUMENT_MIMETYPES = { 0136 QStringLiteral("application/pdf"), 0137 QStringLiteral("application/rtf"), 0138 QStringLiteral("application/doc"), 0139 QStringLiteral("application/odf"), 0140 QStringLiteral("application/vnd.comicbook+zip"), 0141 QStringLiteral("application/vnd.comicbook+rar")}; 0142 0143 /** 0144 * @brief The list supported archive formats, associated to the FILTER_TYPE::COMPRESSED. 0145 */ 0146 inline static const QStringList COMPRESSED_MIMETYPES = { 0147 QStringLiteral("application/x-compress"), 0148 QStringLiteral("application/x-compressed"), 0149 QStringLiteral("application/x-xz-compressed-tar"), 0150 QStringLiteral("application/x-compressed-tar"), 0151 // "application/vnd.android.package-archive", 0152 QStringLiteral("application/x-xz"), 0153 QStringLiteral("application/x-bzip"), 0154 QStringLiteral("application/x-gtar"), 0155 QStringLiteral("application/x-gzip"), 0156 QStringLiteral("application/zip")}; 0157 0158 /** 0159 * @brief The list supported font formats, associated to the FILTER_TYPE::FONT. 0160 */ 0161 inline static const QStringList FONT_MIMETYPES = { 0162 QStringLiteral("font/ttf"), 0163 QStringLiteral("font/otf")}; 0164 0165 /** 0166 * @brief The map set of the supported mime types for the FM classes. This structure maps the FILTER_TYPE to the associated list of mime types. 0167 * 0168 * For example `SUPPORTED_MIMETYPES[FILTER_TYPE::AUDIO]` would return a list of mimetypes associated to the FILTER_TYPE::AUDIO as `"audio/mpeg", "audio/mp4", "audio/flac", "audio/ogg", "audio/wav"`. 0169 */ 0170 inline static const QMap<FILTER_TYPE, QStringList> SUPPORTED_MIMETYPES {{FILTER_TYPE::AUDIO, AUDIO_MIMETYPES}, 0171 {FILTER_TYPE::VIDEO, VIDEO_MIMETYPES}, 0172 {FILTER_TYPE::TEXT, TEXT_MIMETYPES}, 0173 {FILTER_TYPE::IMAGE, IMAGE_MIMETYPES}, 0174 {FILTER_TYPE::DOCUMENT, DOCUMENT_MIMETYPES}, 0175 {FILTER_TYPE::FONT, FONT_MIMETYPES}, 0176 {FILTER_TYPE::COMPRESSED, COMPRESSED_MIMETYPES}}; 0177 0178 /** 0179 * @brief Given a FILTER_TYPE and its associated mime-types, return a list of all the supported file extension suffixes. 0180 * @param type the FILTER_TYPE 0181 * @param cb a callback function to modify the gathered suffix extension. This function will receive the supported suffix and it can return a new string of a modified suffix or the same one. This is optional. 0182 * @return the list of associated file extensions 0183 */ 0184 inline static QStringList getMimeTypeSuffixes(const FILTER_TYPE &type, QString (*cb)(QString) = nullptr) 0185 { 0186 QStringList res; 0187 QMimeDatabase mimedb; 0188 for (const auto &mime : SUPPORTED_MIMETYPES[type]) { 0189 if (cb) { 0190 const auto suffixes = mimedb.mimeTypeForName(mime).suffixes(); 0191 for (const QString &_suffix : suffixes) { 0192 res << cb(_suffix); 0193 } 0194 } else { 0195 res << mimedb.mimeTypeForName(mime).suffixes(); 0196 } 0197 } 0198 return res; 0199 } 0200 0201 /** 0202 * @private 0203 */ 0204 inline static auto func = [](QString suffix) -> QString { 0205 return QStringLiteral("*.") + suffix; 0206 }; 0207 0208 /** 0209 * @brief Convenient map set of file type extensions. 0210 * The values make use of the regex wildcard operator [*] meant for filtering a directory contents, for example. 0211 * `FILTER_LIST[FILTER_TYPE::AUDIO]` could possible return something alike `["*.mp3", "*.mp4", "*.mpeg", "*.wav"]` etc. 0212 */ 0213 inline static QHash<FILTER_TYPE, QStringList> FILTER_LIST = {{FILTER_TYPE::AUDIO, 0214 getMimeTypeSuffixes(FILTER_TYPE::AUDIO, 0215 func)}, 0216 {FILTER_TYPE::VIDEO, 0217 getMimeTypeSuffixes(FILTER_TYPE::VIDEO, 0218 func)}, 0219 {FILTER_TYPE::TEXT, 0220 getMimeTypeSuffixes(FILTER_TYPE::TEXT, 0221 func)}, 0222 {FILTER_TYPE::DOCUMENT, 0223 getMimeTypeSuffixes(FILTER_TYPE::DOCUMENT, 0224 func)}, 0225 {FILTER_TYPE::COMPRESSED, 0226 getMimeTypeSuffixes(FILTER_TYPE::COMPRESSED, 0227 func)}, 0228 {FILTER_TYPE::FONT, 0229 getMimeTypeSuffixes(FILTER_TYPE::FONT, 0230 func)}, 0231 {FILTER_TYPE::IMAGE, 0232 getMimeTypeSuffixes(FILTER_TYPE::IMAGE, 0233 func)}, 0234 {FILTER_TYPE::NONE, QStringList()}}; 0235 0236 /** * @brief A location contents structured for convenience. */ 0237 struct PATH_CONTENT { 0238 0239 /** 0240 * @brief The location URL holding all of the contents. 0241 */ 0242 QUrl path; 0243 0244 /** 0245 * @brief The contents of the location. 0246 */ 0247 FMH::MODEL_LIST content; 0248 }; 0249 0250 /** * @brief The different location types supported. Most of them need of KDE KIO framework to be fully operational. */ 0251 enum PATHTYPE_KEY : int { 0252 /** 0253 * Local paths, such as the Downloads, Pictures, etc. `file:/` 0254 */ 0255 PLACES_PATH, 0256 0257 /** 0258 * Remote locations, such as servers accessed via SSH or FTP 0259 */ 0260 REMOTE_PATH, 0261 0262 /** 0263 * Hard drives locations 0264 */ 0265 DRIVES_PATH, 0266 0267 /** 0268 * Removable places, such as optic CDs, USB pen drives, etc. 0269 */ 0270 REMOVABLE_PATH, 0271 0272 /** 0273 * A tag location. 0274 */ 0275 TAGS_PATH, 0276 0277 /** 0278 * Unknown location type. 0279 */ 0280 UNKNOWN_TYPE, 0281 0282 /** 0283 * The applications location. Accessed with KIO via the `applications://` scheme. 0284 */ 0285 APPS_PATH, 0286 0287 /** 0288 * The trash location. `trash:/` 0289 */ 0290 TRASH_PATH, 0291 0292 /** 0293 * A search results. 0294 */ 0295 SEARCH_PATH, 0296 0297 /** 0298 * A remote cloud server path. 0299 */ 0300 CLOUD_PATH, 0301 0302 /** 0303 * A remote SHH or FTP. `fish:/` `ftp:/` 0304 */ 0305 FISH_PATH, 0306 0307 /** 0308 * MTP path 0309 */ 0310 MTP_PATH, 0311 0312 /** 0313 * The common standard paths 0314 */ 0315 QUICK_PATH, 0316 0317 /** 0318 * A bookmarked location. `file:/` 0319 */ 0320 BOOKMARKS_PATH, 0321 0322 /** 0323 * Any other path 0324 */ 0325 OTHER_PATH, 0326 }; 0327 0328 /** 0329 * @brief The map of the PATH_TYPE to its associated protocol scheme. 0330 * For example `PATHTYPE_SCHEME[PATHTYPE_KEY::TRASH_PATH] = "trash"`, `PATHTYPE_SCHEME[PATHTYPE_KEY::PLACES_PATH] = "file"` 0331 */ 0332 inline static const QHash<PATHTYPE_KEY, QString> PATHTYPE_SCHEME = {{PATHTYPE_KEY::PLACES_PATH, QStringLiteral("file")}, 0333 {PATHTYPE_KEY::BOOKMARKS_PATH, QStringLiteral("file")}, 0334 {PATHTYPE_KEY::DRIVES_PATH, QStringLiteral("drives")}, 0335 {PATHTYPE_KEY::APPS_PATH, QStringLiteral("applications")}, 0336 {PATHTYPE_KEY::REMOTE_PATH, QStringLiteral("remote")}, 0337 {PATHTYPE_KEY::REMOVABLE_PATH, QStringLiteral("removable")}, 0338 {PATHTYPE_KEY::UNKNOWN_TYPE, QStringLiteral("unknown")}, 0339 {PATHTYPE_KEY::TRASH_PATH, QStringLiteral("trash")}, 0340 {PATHTYPE_KEY::TAGS_PATH, QStringLiteral("tags")}, 0341 {PATHTYPE_KEY::SEARCH_PATH, QStringLiteral("search")}, 0342 {PATHTYPE_KEY::CLOUD_PATH, QStringLiteral("cloud")}, 0343 {PATHTYPE_KEY::FISH_PATH, QStringLiteral("fish")}, 0344 {PATHTYPE_KEY::MTP_PATH, QStringLiteral("mtp")}}; 0345 0346 /** 0347 * @brief The protocol scheme mapped to its PATHTYPE_KEY. 0348 * Where `PATHTYPE_SCHEME_NAME["file"] = FMH::PATHTYPE_KEY::PLACES_PATH` 0349 */ 0350 inline static const QHash<QString, PATHTYPE_KEY> PATHTYPE_SCHEME_NAME = {{PATHTYPE_SCHEME[PATHTYPE_KEY::PLACES_PATH], PATHTYPE_KEY::PLACES_PATH}, 0351 {PATHTYPE_SCHEME[PATHTYPE_KEY::BOOKMARKS_PATH], PATHTYPE_KEY::BOOKMARKS_PATH}, 0352 {PATHTYPE_SCHEME[PATHTYPE_KEY::DRIVES_PATH], PATHTYPE_KEY::DRIVES_PATH}, 0353 {PATHTYPE_SCHEME[PATHTYPE_KEY::APPS_PATH], PATHTYPE_KEY::APPS_PATH}, 0354 {PATHTYPE_SCHEME[PATHTYPE_KEY::REMOTE_PATH], PATHTYPE_KEY::REMOTE_PATH}, 0355 {PATHTYPE_SCHEME[PATHTYPE_KEY::REMOVABLE_PATH], PATHTYPE_KEY::REMOVABLE_PATH}, 0356 {PATHTYPE_SCHEME[PATHTYPE_KEY::UNKNOWN_TYPE], PATHTYPE_KEY::UNKNOWN_TYPE}, 0357 {PATHTYPE_SCHEME[PATHTYPE_KEY::TRASH_PATH], PATHTYPE_KEY::TRASH_PATH}, 0358 {PATHTYPE_SCHEME[PATHTYPE_KEY::TAGS_PATH], PATHTYPE_KEY::TAGS_PATH}, 0359 {PATHTYPE_SCHEME[PATHTYPE_KEY::SEARCH_PATH], PATHTYPE_KEY::SEARCH_PATH}, 0360 {PATHTYPE_SCHEME[PATHTYPE_KEY::CLOUD_PATH], PATHTYPE_KEY::CLOUD_PATH}, 0361 {PATHTYPE_SCHEME[PATHTYPE_KEY::FISH_PATH], PATHTYPE_KEY::FISH_PATH}, 0362 {PATHTYPE_SCHEME[PATHTYPE_KEY::MTP_PATH], PATHTYPE_KEY::MTP_PATH}}; 0363 0364 /** 0365 * @brief Similar to PATHTYPE_SCHEME, but mapped with the complete scheme. 0366 * For example `PATHTYPE_URIE[PATHTYPE_KEY::TRASH_PATH] = "trash://"`, `PATHTYPE_URI[PLACES_PATH] = "file://"` 0367 */ 0368 inline static const QHash<PATHTYPE_KEY, QString> PATHTYPE_URI = {{PATHTYPE_KEY::PLACES_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::PLACES_PATH] + QStringLiteral("://")}, 0369 {PATHTYPE_KEY::BOOKMARKS_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::BOOKMARKS_PATH] + QStringLiteral("://")}, 0370 {PATHTYPE_KEY::DRIVES_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::DRIVES_PATH] + QStringLiteral("://")}, 0371 {PATHTYPE_KEY::APPS_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::APPS_PATH] + QStringLiteral(":///")}, 0372 {PATHTYPE_KEY::REMOTE_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::REMOTE_PATH] + QStringLiteral("://")}, 0373 {PATHTYPE_KEY::REMOVABLE_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::REMOVABLE_PATH] + QStringLiteral("://")}, 0374 {PATHTYPE_KEY::UNKNOWN_TYPE, PATHTYPE_SCHEME[PATHTYPE_KEY::UNKNOWN_TYPE] + QStringLiteral("://")}, 0375 {PATHTYPE_KEY::TRASH_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::TRASH_PATH] + QStringLiteral("://")}, 0376 {PATHTYPE_KEY::TAGS_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::TAGS_PATH] + QStringLiteral(":///")}, 0377 {PATHTYPE_KEY::SEARCH_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::SEARCH_PATH] + QStringLiteral("://")}, 0378 {PATHTYPE_KEY::CLOUD_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::CLOUD_PATH] + QStringLiteral(":///")}, 0379 {PATHTYPE_KEY::FISH_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::FISH_PATH] + QStringLiteral("://")}, 0380 {PATHTYPE_KEY::MTP_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::MTP_PATH] + QStringLiteral("://")}}; 0381 0382 0383 /** 0384 * @brief Given a PATHTYPE_KEY return a user friendly string. 0385 * @warning This is a user visible and translatable string, so it should not be used as a key anywhere 0386 * @param key the PATHTYPE_KEY key 0387 **/ 0388 static QString PathTypeLabel(const FMStatic::PATHTYPE_KEY &key); 0389 0390 /** * @brief Standard Data location path */ 0391 inline static const QString DataPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); 0392 0393 /** * @brief Standard Configuration location path */ 0394 inline static const QString ConfigPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).toString(); 0395 0396 /** * @brief Standard Cloud Cache location path */ 0397 inline static const QString CloudCachePath = DataPath + QStringLiteral("/Cloud/"); 0398 0399 /** * @brief Standard desktop location path */ 0400 inline static const QString DesktopPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)).toString(); 0401 0402 /** * @brief Standard applications location path */ 0403 inline static const QString AppsPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)).toString(); 0404 0405 /** * @brief Standard root location path */ 0406 inline static const QString RootPath = QUrl::fromLocalFile(QStringLiteral("/")).toString(); 0407 0408 /** * @brief Standard pictures location path */ 0409 inline static const QString PicturesPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)).toString(); 0410 0411 /** * @brief Standard downloads location path */ 0412 inline static const QString DownloadsPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)).toString(); 0413 0414 /** * @brief Standard documents location path */ 0415 inline static const QString DocumentsPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).toString(); 0416 0417 /** * @brief Standard music location path */ 0418 inline static const QString MusicPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation)).toString(); 0419 0420 /** * @brief Standard videos location path */ 0421 inline static const QString VideosPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)).toString(); 0422 0423 0424 #if defined(Q_OS_ANDROID) 0425 /** * @brief Standard home location path */ 0426 inline static const QString HomePath = QUrl::fromLocalFile( MAUIAndroid::homePath()).toString(); 0427 0428 /** * @brief The internally defined quick standard locations. */ 0429 inline static const QStringList defaultPaths = {HomePath, DocumentsPath, PicturesPath, MusicPath, VideosPath, DownloadsPath}; 0430 #else 0431 0432 /** * @brief Standard home location path */ 0433 inline static const QString HomePath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).toString(); 0434 0435 /** * @brief Standard trash location path */ 0436 inline static const QString TrashPath = QStringLiteral("trash:/"); 0437 0438 /** * @brief The internally defined quick standard locations. */ 0439 inline static const QStringList defaultPaths = { 0440 HomePath, 0441 DesktopPath, 0442 DocumentsPath, 0443 DownloadsPath, 0444 MusicPath, 0445 PicturesPath, 0446 VideosPath, 0447 RootPath 0448 }; 0449 0450 #endif 0451 0452 /** 0453 * @brief A mapping of the standard location to a icon name. 0454 */ 0455 inline static const QMap<QString, QString> folderIcon {{PicturesPath, QStringLiteral("folder-pictures")}, 0456 {DownloadsPath, QStringLiteral("folder-download")}, 0457 {DocumentsPath, QStringLiteral("folder-documents")}, 0458 {HomePath, QStringLiteral("user-home")}, 0459 {MusicPath, QStringLiteral("folder-music")}, 0460 {VideosPath, QStringLiteral("folder-videos")}, 0461 {DesktopPath, QStringLiteral("user-desktop")}, 0462 {AppsPath, QStringLiteral("system-run")}, 0463 {RootPath, QStringLiteral("folder-root")}}; 0464 0465 public Q_SLOTS: 0466 /** 0467 * @brief Search for files in a path using name filters 0468 * @param query the term query to be searched, such as `".qml"` or `"music"` 0469 * @param path the path where to perform or start the search 0470 * @param hidden whether to search for hidden files 0471 * @param onlyDirs whether to only search for directories and not files 0472 * @param filters list of filter patterns such as `{"*.qml"}`, it can use regular expressions. 0473 * @return the search results are returned as a FMH::MODEL_LIST 0474 */ 0475 static FMH::MODEL_LIST search(const QString &query, const QUrl &path, const bool &hidden = false, const bool &onlyDirs = false, const QStringList &filters = QStringList()); 0476 0477 /** 0478 * @brief Devices mounted in the file system 0479 * @return list of devices represented as a FMH::MODEL_LIST with information 0480 */ 0481 static FMH::MODEL_LIST getDevices(); 0482 0483 /** 0484 * @brief A model list of the default paths in most systems, such as Home, Pictures, Video, Downloads, Music and Documents folders 0485 * @return the packaged model with information for each directory 0486 */ 0487 static FMH::MODEL_LIST getDefaultPaths(); 0488 0489 /** 0490 * @brief Given a list of path URLs pack all the info of such files as a FMH::MODEL_LIST 0491 * @param items list of local URLs 0492 * @param type the type of the list of URLs, such as local, remote etc. This value is inserted with the key `FMH::MODEL_KEY::TYPE` 0493 * @return 0494 */ 0495 static FMH::MODEL_LIST packItems(const QStringList &items, const QString &type); 0496 0497 /** 0498 * @brief Perform a move operation of the given files to a new destination 0499 * @param urls list of URLs to be copied 0500 * @param destinationDir destination 0501 * @param name the name of the new directory where all the entries will be grouped/moved into 0502 * @return whether the operation has been successful 0503 */ 0504 static bool group(const QList<QUrl> &urls, const QUrl &destinationDir, const QString &name); 0505 0506 /** 0507 * @brief Perform a copy of the files to the given destination 0508 * @param urls list of URLs to be copy 0509 * @param destinationDir destination 0510 * @return whether the operation has been successful 0511 */ 0512 static bool copy(const QList<QUrl> &urls, const QUrl &destinationDir); 0513 0514 /** 0515 * @brief Perform a move/cut of a list of files to a destination. This function also moves the associated tags. 0516 * @param urls list of URLs to be moved 0517 * @param where destination path 0518 * @return whether the operation has been successful 0519 */ 0520 static bool cut(const QList<QUrl> &urls, const QUrl &where); 0521 0522 /** 0523 * @see cut 0524 * @param name new name of the directory where the files will be pasted 0525 */ 0526 static bool cut(const QList<QUrl> &urls, const QUrl &where, const QString &name); 0527 0528 /** 0529 * @brief List of files to be removed completely. This function also removes the associated tags to the files. 0530 * @param urls file URLs to be removed 0531 * @return Whether the operation has been sucessfull 0532 */ 0533 static bool removeFiles(const QList<QUrl> &urls); 0534 0535 /** 0536 * @brief Remove a directory recursively. 0537 * @param path directory URL to be removed 0538 * @return whether the operation has been sucessfull 0539 */ 0540 static bool removeDir(const QUrl &path); 0541 0542 /** 0543 * @brief The default home path. 0544 * @return URL of the home location 0545 */ 0546 static QString homePath(); 0547 0548 /** 0549 * @brief Given a file URL return its parent directory 0550 * @param path the file URL 0551 * @return the parent directory URL if it exists otherwise returns the passed URL 0552 */ 0553 static QUrl parentDir(const QUrl &path); 0554 0555 /** 0556 * @brief Checks if a given path URL is a default path as found in the `defaultPaths` method 0557 * @param path the directory location path 0558 * @return whether is a default path 0559 */ 0560 static bool isDefaultPath(const QString &path); 0561 0562 /** 0563 * @brief Whether a local file URL is a directory 0564 * @param path file URL 0565 * @return is a directory 0566 */ 0567 static bool isDir(const QUrl &path); 0568 0569 /** 0570 * @brief Whether a path is a URL server instead of a local file 0571 * @param path 0572 * @return 0573 */ 0574 static bool isCloud(const QUrl &path); 0575 0576 /** 0577 * @brief Checks if a local file exists in the file system 0578 * @param path file URL 0579 * @return whether it exists locally 0580 */ 0581 static bool fileExists(const QUrl &path); 0582 0583 /** 0584 * @brief Given a file URL return its parent directory, and if the path is a directory then returns the same path. 0585 * @param path file path URL 0586 * @return the directory URL 0587 */ 0588 static QUrl fileDir(const QUrl &path); 0589 0590 /** 0591 * @brief Write a configuration key-value entry to the directory conf file 0592 * @param path directory path 0593 * @param group the entry group name 0594 * @param key the key name of the entry 0595 * @param value the value of the entry 0596 */ 0597 static void setDirConf(const QUrl &path, const QString &group, const QString &key, const QVariant &value); 0598 0599 /** 0600 * @brief Checks if a mime-type belongs to a file type, for example, whether `image/jpg` belongs to the type `FMH::FILTER_TYPE` 0601 * @param type FMH::FILTER_TYPE value 0602 * @param mimeTypeName the mime type name 0603 * @return whether the type contains the given name 0604 */ 0605 static bool checkFileType(const int &type, const QString &mimeTypeName); 0606 static bool checkFileType(const FMStatic::FILTER_TYPE &type, const QString &mimeTypeName); 0607 0608 /** 0609 * @brief Moves to the trashcan the provided file URLs. The associated tags are kept in case the files are restored. 0610 * @param urls the file URLs 0611 */ 0612 static void moveToTrash(const QList<QUrl> &urls); 0613 0614 /** 0615 * @brief Empty the trashcan 0616 */ 0617 static void emptyTrash(); 0618 0619 /** 0620 * @brief Rename a file. The associated tags will be updated. 0621 * @param url the file URL to be renamed 0622 * @param name the new name of the file, not the new URL, for setting a new URl use cut instead. 0623 * @return whether the operation was successful. 0624 */ 0625 static bool rename(const QUrl &url, const QString &name); 0626 0627 /** 0628 * @brief Creates a new directory given a base path and a name 0629 * @param path base path where to create the new directory 0630 * @param name the new directory name 0631 * @return whether the operation was successful 0632 */ 0633 static bool createDir(const QUrl &path, const QString &name); 0634 0635 /** 0636 * @brief Creates a file given the base directory path and a file name 0637 * @param path the base location path 0638 * @param name the name of the new file to be created with the extension 0639 * @return whether the operation was successful 0640 */ 0641 static bool createFile(const QUrl &path, const QString &name); 0642 0643 /** 0644 * @brief Creates a symbolic link to a given file URL 0645 * @param path file to be linked 0646 * @param where destination of the symbolic link 0647 * @return whether the operation was successful 0648 */ 0649 static bool createSymlink(const QUrl &path, const QUrl &where); 0650 0651 /** 0652 * @brief Given a URL it tries to open it using the default application associated to it 0653 * @param url the file URL to be opened 0654 */ 0655 static void openUrl(const QUrl &url); 0656 0657 /** 0658 * @brief Open the file URLs with the default file manager 0659 * @param urls file or location URLs to be opened 0660 */ 0661 static void openLocation(const QStringList &urls); 0662 0663 /** 0664 * @brief Add a directory URL to the places bookmarks 0665 * @param url the directory URL to be bookmarked 0666 */ 0667 static void bookmark(const QUrl &url); 0668 0669 /** 0670 * @brief Given a filter type return a list of associated name filters, as their suffixes. 0671 * @param type the filter type to be mapped to a FMH::FILTER_TYPE 0672 * @see FMH::FILTER_LIST 0673 */ 0674 static QStringList nameFilters(const int &type); 0675 0676 #ifdef KIO_AVAILABLE 0677 /** 0678 * @brief Get the file information packaged in a key-value model. 0679 * @param path the file path 0680 * @return the file info packed into a model 0681 */ 0682 static const FMH::MODEL getFileInfo(const KFileItem &kfile); 0683 #endif 0684 0685 /** 0686 * @brief getFileInfoModel 0687 * @param path 0688 * @return 0689 */ 0690 static const FMH::MODEL getFileInfoModel(const QUrl &path); 0691 0692 /** 0693 * @brief getFileInfo 0694 * @param path 0695 * @return 0696 */ 0697 static const QVariantMap getFileInfo(const QUrl &path); 0698 0699 /** 0700 * @brief Returns the icon name for certain file. 0701 * The file path must be represented as a local file URL. 0702 * It also looks into the directory conf file to get the directory custom icon. 0703 * 0704 * @note To get an abstract icon, use a template name, such as `test.jpg`, to get an icon for the JPG image type. The file does not need to exists. 0705 * @param path file path 0706 * @return 0707 */ 0708 static const QString getIconName(const QUrl &path); 0709 0710 /** 0711 * @brief Return the icon name set in the directory `.directory` conf file. 0712 * The passed path must be a local file URL. 0713 * @param path the directory location 0714 * @return the icon name 0715 */ 0716 static const QString dirConfIcon(const QUrl &path); 0717 0718 /** 0719 * @brief Get the mime type of the given file path 0720 * @param path the file path 0721 * @return the mime-type string 0722 */ 0723 static const QString getMime(const QUrl &path); 0724 0725 /** 0726 * @brief Given a file URL with a well defined scheme, get the PATHTYPE_KEY. 0727 * @see PATHTYPE_KEY 0728 * @param url the file URL 0729 * @return the file PATHTYPE_KEY 0730 */ 0731 static FMStatic::PATHTYPE_KEY getPathType(const QUrl &url); 0732 };