MauiKit File Browsing

fmstatic.h
1#pragma once
2
3#include <QtGlobal>
4#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
5#include <MauiKit3/Core/fmh.h>
6#ifdef Q_OS_ANDROID
7#include <MauiKit3/Core/mauiandroid.h>
8#endif
9#else
10#include <MauiKit4/Core/fmh.h>
11#ifdef Q_OS_ANDROID
12#include <MauiKit4/Core/mauiandroid.h>
13#endif
14#endif
15
16#include <QObject>
17#include <QString>
18#include <QMimeData>
19#include <QMimeDatabase>
20#include <QMimeType>
21#include <QStandardPaths>
22#include <QUrl>
23#include <QQmlEngine>
24
25#ifdef KIO_AVAILABLE
26class KFileItem;
27#endif
28
29#include "filebrowsing_export.h"
30
31/**
32 * @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.
33 */
34class FILEBROWSING_EXPORT FMStatic : public QObject
35{
36 Q_OBJECT
37 // QML_NAMED_ELEMENT(FM)
38 // QML_SINGLETON
39
40 Q_DISABLE_COPY_MOVE(FMStatic)
41
42public:
43 /**
44 * @private
45 */
46 explicit FMStatic(QObject *parent = nullptr);
47
48 /**
49 * @brief The common file types for filtering
50 */
51 enum FILTER_TYPE : int { AUDIO, VIDEO, TEXT, IMAGE, DOCUMENT, COMPRESSED, FONT, NONE };
52
53 /**
54 * @brief The list supported audio formats, associated to the FILTER_TYPE::AUDIO.
55 */
56 inline static const QStringList AUDIO_MIMETYPES = {
57 QStringLiteral("audio/mpeg"),
58 QStringLiteral("audio/mp4"),
59 QStringLiteral("audio/flac"),
60 QStringLiteral("audio/ogg"),
61 QStringLiteral("audio/wav")};
62
63 /**
64 * @brief The list supported video formats, associated to the FILTER_TYPE::VIDEO.
65 */
66 inline static const QStringList VIDEO_MIMETYPES = {
67 QStringLiteral("video/mp4"),
68 QStringLiteral("video/x-matroska"),
69 QStringLiteral("video/webm"),
70 QStringLiteral("video/avi"),
71 QStringLiteral("video/flv"),
72 QStringLiteral("video/mpg"),
73 QStringLiteral("video/wmv"),
74 QStringLiteral("video/mov"),
75 QStringLiteral("video/quicktime"),
76 QStringLiteral("video/ogg"),
77 QStringLiteral("video/x-flv"),
78 QStringLiteral("video/mpeg"),
79 QStringLiteral("video/jpeg")};
80
81 /**
82 * @brief The list supported text formats, associated to the FILTER_TYPE::TEXT.
83 */
84 inline static const QStringList TEXT_MIMETYPES = {
85 QStringLiteral("text/markdown"),
86 QStringLiteral("text/x-chdr"),
87 QStringLiteral("text/x-c++src"),
88 QStringLiteral("text/x-c++hdr"),
89 QStringLiteral("text/css"),
90 QStringLiteral("text/html"),
91 QStringLiteral("text/plain"),
92 QStringLiteral("text/richtext"),
93 QStringLiteral("text/scriptlet"),
94 QStringLiteral("text/x-vcard"),
95 QStringLiteral("text/x-go"),
96 QStringLiteral("text/x-cmake"),
97 QStringLiteral("text/x-makefile"),
98 QStringLiteral("text/x-qml"),
99 QStringLiteral("text/x-java"),
100 QStringLiteral("text/x-log"),
101 QStringLiteral("text/x-python"),
102 QStringLiteral("text/*"),
103 QStringLiteral("text/x-copying"),
104 QStringLiteral("text/x-dbus-service"),
105 QStringLiteral("text/x-gettext-translation"),
106 QStringLiteral("application/xml"),
107 QStringLiteral("application/yaml"),
108 QStringLiteral("application/vnd.kde.knotificationrc"),
109 QStringLiteral("application/x-gitignore"),
110 QStringLiteral("application/javascript"),
111 QStringLiteral("application/json"),
112 QStringLiteral("application/pgp-keys"),
113 QStringLiteral("application/x-shellscript"),
114 QStringLiteral("application/x-cmakecache"),
115 QStringLiteral("application/x-yaml"),
116 QStringLiteral("application/x-perl"),
117 QStringLiteral("application/x-kdevelop"),
118 QStringLiteral("application/x-kicad-project")};
119
120 /**
121 * @brief The list supported image formats, associated to the FILTER_TYPE::IMAGE.
122 */
123 inline static const QStringList IMAGE_MIMETYPES = {
124 QStringLiteral("image/bmp"),
125 QStringLiteral("image/webp"),
126 QStringLiteral("image/png"),
127 QStringLiteral("image/gif"),
128 QStringLiteral("image/jpeg"),
129 QStringLiteral("image/web"),
130 QStringLiteral("image/svg"),
131 QStringLiteral("image/svg+xml"),
132 QStringLiteral("application/x-krita"),
133 QStringLiteral("image/x-xcf"),
134 QStringLiteral("image/vnd.adobe.photoshop"),
135 QStringLiteral("image/x-eps"),
136 QStringLiteral("image/jxl"),
137 QStringLiteral("image/avif")};
138
139 /**
140 * @brief The list supported document formats, associated to the FILTER_TYPE::DOCUMENT.
141 */
142 inline static const QStringList DOCUMENT_MIMETYPES = {
143 QStringLiteral("application/pdf"),
144 QStringLiteral("application/rtf"),
145 QStringLiteral("application/doc"),
146 QStringLiteral("application/odf"),
147 QStringLiteral("application/vnd.comicbook+zip"),
148 QStringLiteral("application/vnd.comicbook+rar")};
149
150 /**
151 * @brief The list supported archive formats, associated to the FILTER_TYPE::COMPRESSED.
152 */
153 inline static const QStringList COMPRESSED_MIMETYPES = {
154 QStringLiteral("application/x-compress"),
155 QStringLiteral("application/x-compressed"),
156 QStringLiteral("application/x-xz-compressed-tar"),
157 QStringLiteral("application/x-compressed-tar"),
158 // "application/vnd.android.package-archive",
159 QStringLiteral("application/x-xz"),
160 QStringLiteral("application/x-bzip"),
161 QStringLiteral("application/x-gtar"),
162 QStringLiteral("application/x-gzip"),
163 QStringLiteral("application/zip")};
164
165 /**
166 * @brief The list supported font formats, associated to the FILTER_TYPE::FONT.
167 */
168 inline static const QStringList FONT_MIMETYPES = {
169 QStringLiteral("font/ttf"),
170 QStringLiteral("font/otf")};
171
172 /**
173 * @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.
174 *
175 * 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"`.
176 */
177 inline static const QMap<FILTER_TYPE, QStringList> SUPPORTED_MIMETYPES {{FILTER_TYPE::AUDIO, AUDIO_MIMETYPES},
178 {FILTER_TYPE::VIDEO, VIDEO_MIMETYPES},
179 {FILTER_TYPE::TEXT, TEXT_MIMETYPES},
180 {FILTER_TYPE::IMAGE, IMAGE_MIMETYPES},
181 {FILTER_TYPE::DOCUMENT, DOCUMENT_MIMETYPES},
182 {FILTER_TYPE::FONT, FONT_MIMETYPES},
183 {FILTER_TYPE::COMPRESSED, COMPRESSED_MIMETYPES}};
184
185 /**
186 * @brief Given a FILTER_TYPE and its associated mime-types, return a list of all the supported file extension suffixes.
187 * @param type the FILTER_TYPE
188 * @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.
189 * @return the list of associated file extensions
190 */
191 inline static QStringList getMimeTypeSuffixes(const FILTER_TYPE &type, QString (*cb)(QString) = nullptr)
192 {
193 QStringList res;
194 QMimeDatabase mimedb;
195 for (const auto &mime : SUPPORTED_MIMETYPES[type]) {
196 if (cb) {
197 const auto suffixes = mimedb.mimeTypeForName(mime).suffixes();
198 for (const QString &_suffix : suffixes) {
199 res << cb(_suffix);
200 }
201 } else {
202 res << mimedb.mimeTypeForName(mime).suffixes();
203 }
204 }
205 return res;
206 }
207
208 /**
209 * @private
210 */
211 inline static auto func = [](QString suffix) -> QString {
212 return QStringLiteral("*.") + suffix;
213 };
214
215 /**
216 * @brief Convenient map set of file type extensions.
217 * The values make use of the regex wildcard operator [*] meant for filtering a directory contents, for example.
218 * `FILTER_LIST[FILTER_TYPE::AUDIO]` could possible return something alike `["*.mp3", "*.mp4", "*.mpeg", "*.wav"]` etc.
219 */
220 inline static QHash<FILTER_TYPE, QStringList> FILTER_LIST = {{FILTER_TYPE::AUDIO,
221 getMimeTypeSuffixes(FILTER_TYPE::AUDIO,
222 func)},
223 {FILTER_TYPE::VIDEO,
224 getMimeTypeSuffixes(FILTER_TYPE::VIDEO,
225 func)},
226 {FILTER_TYPE::TEXT,
227 getMimeTypeSuffixes(FILTER_TYPE::TEXT,
228 func)},
229 {FILTER_TYPE::DOCUMENT,
230 getMimeTypeSuffixes(FILTER_TYPE::DOCUMENT,
231 func)},
232 {FILTER_TYPE::COMPRESSED,
233 getMimeTypeSuffixes(FILTER_TYPE::COMPRESSED,
234 func)},
235 {FILTER_TYPE::FONT,
236 getMimeTypeSuffixes(FILTER_TYPE::FONT,
237 func)},
238 {FILTER_TYPE::IMAGE,
239 getMimeTypeSuffixes(FILTER_TYPE::IMAGE,
240 func)},
241 {FILTER_TYPE::NONE, QStringList()}};
242
243 /** * @brief A location contents structured for convenience. */
245
246 /**
247 * @brief The location URL holding all of the contents.
248 */
250
251 /**
252 * @brief The contents of the location.
253 */
255 };
256
257 /** * @brief The different location types supported. Most of them need of KDE KIO framework to be fully operational. */
258 enum PATHTYPE_KEY : int {
259 /**
260 * Local paths, such as the Downloads, Pictures, etc. `file:/`
261 */
263
264 /**
265 * Remote locations, such as servers accessed via SSH or FTP
266 */
268
269 /**
270 * Hard drives locations
271 */
273
274 /**
275 * Removable places, such as optic CDs, USB pen drives, etc.
276 */
278
279 /**
280 * A tag location.
281 */
283
284 /**
285 * Unknown location type.
286 */
288
289 /**
290 * The applications location. Accessed with KIO via the `applications://` scheme.
291 */
293
294 /**
295 * The trash location. `trash:/`
296 */
298
299 /**
300 * A search results.
301 */
303
304 /**
305 * A remote cloud server path.
306 */
308
309 /**
310 * A remote SHH or FTP. `fish:/` `ftp:/`
311 */
313
314 /**
315 * MTP path
316 */
318
319 /**
320 * The common standard paths
321 */
323
324 /**
325 * A bookmarked location. `file:/`
326 */
328
329 /**
330 * Any other path
331 */
333 };
334
335 /**
336 * @brief The map of the PATH_TYPE to its associated protocol scheme.
337 * For example `PATHTYPE_SCHEME[PATHTYPE_KEY::TRASH_PATH] = "trash"`, `PATHTYPE_SCHEME[PATHTYPE_KEY::PLACES_PATH] = "file"`
338 */
339 inline static const QHash<PATHTYPE_KEY, QString> PATHTYPE_SCHEME = {{PATHTYPE_KEY::PLACES_PATH, QStringLiteral("file")},
340 {PATHTYPE_KEY::BOOKMARKS_PATH, QStringLiteral("file")},
341 {PATHTYPE_KEY::DRIVES_PATH, QStringLiteral("drives")},
342 {PATHTYPE_KEY::APPS_PATH, QStringLiteral("applications")},
343 {PATHTYPE_KEY::REMOTE_PATH, QStringLiteral("remote")},
344 {PATHTYPE_KEY::REMOVABLE_PATH, QStringLiteral("removable")},
345 {PATHTYPE_KEY::UNKNOWN_TYPE, QStringLiteral("unknown")},
346 {PATHTYPE_KEY::TRASH_PATH, QStringLiteral("trash")},
347 {PATHTYPE_KEY::TAGS_PATH, QStringLiteral("tags")},
348 {PATHTYPE_KEY::SEARCH_PATH, QStringLiteral("search")},
349 {PATHTYPE_KEY::CLOUD_PATH, QStringLiteral("cloud")},
350 {PATHTYPE_KEY::FISH_PATH, QStringLiteral("fish")},
351 {PATHTYPE_KEY::MTP_PATH, QStringLiteral("mtp")}};
352
353 /**
354 * @brief The protocol scheme mapped to its PATHTYPE_KEY.
355 * Where `PATHTYPE_SCHEME_NAME["file"] = FMH::PATHTYPE_KEY::PLACES_PATH`
356 */
357 inline static const QHash<QString, PATHTYPE_KEY> PATHTYPE_SCHEME_NAME = {{PATHTYPE_SCHEME[PATHTYPE_KEY::PLACES_PATH], PATHTYPE_KEY::PLACES_PATH},
358 {PATHTYPE_SCHEME[PATHTYPE_KEY::BOOKMARKS_PATH], PATHTYPE_KEY::BOOKMARKS_PATH},
359 {PATHTYPE_SCHEME[PATHTYPE_KEY::DRIVES_PATH], PATHTYPE_KEY::DRIVES_PATH},
360 {PATHTYPE_SCHEME[PATHTYPE_KEY::APPS_PATH], PATHTYPE_KEY::APPS_PATH},
361 {PATHTYPE_SCHEME[PATHTYPE_KEY::REMOTE_PATH], PATHTYPE_KEY::REMOTE_PATH},
362 {PATHTYPE_SCHEME[PATHTYPE_KEY::REMOVABLE_PATH], PATHTYPE_KEY::REMOVABLE_PATH},
363 {PATHTYPE_SCHEME[PATHTYPE_KEY::UNKNOWN_TYPE], PATHTYPE_KEY::UNKNOWN_TYPE},
364 {PATHTYPE_SCHEME[PATHTYPE_KEY::TRASH_PATH], PATHTYPE_KEY::TRASH_PATH},
365 {PATHTYPE_SCHEME[PATHTYPE_KEY::TAGS_PATH], PATHTYPE_KEY::TAGS_PATH},
366 {PATHTYPE_SCHEME[PATHTYPE_KEY::SEARCH_PATH], PATHTYPE_KEY::SEARCH_PATH},
367 {PATHTYPE_SCHEME[PATHTYPE_KEY::CLOUD_PATH], PATHTYPE_KEY::CLOUD_PATH},
368 {PATHTYPE_SCHEME[PATHTYPE_KEY::FISH_PATH], PATHTYPE_KEY::FISH_PATH},
369 {PATHTYPE_SCHEME[PATHTYPE_KEY::MTP_PATH], PATHTYPE_KEY::MTP_PATH}};
370
371 /**
372 * @brief Similar to PATHTYPE_SCHEME, but mapped with the complete scheme.
373 * For example `PATHTYPE_URIE[PATHTYPE_KEY::TRASH_PATH] = "trash://"`, `PATHTYPE_URI[PLACES_PATH] = "file://"`
374 */
375 inline static const QHash<PATHTYPE_KEY, QString> PATHTYPE_URI = {{PATHTYPE_KEY::PLACES_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::PLACES_PATH] + QStringLiteral("://")},
376 {PATHTYPE_KEY::BOOKMARKS_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::BOOKMARKS_PATH] + QStringLiteral("://")},
377 {PATHTYPE_KEY::DRIVES_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::DRIVES_PATH] + QStringLiteral("://")},
378 {PATHTYPE_KEY::APPS_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::APPS_PATH] + QStringLiteral(":///")},
379 {PATHTYPE_KEY::REMOTE_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::REMOTE_PATH] + QStringLiteral("://")},
380 {PATHTYPE_KEY::REMOVABLE_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::REMOVABLE_PATH] + QStringLiteral("://")},
381 {PATHTYPE_KEY::UNKNOWN_TYPE, PATHTYPE_SCHEME[PATHTYPE_KEY::UNKNOWN_TYPE] + QStringLiteral("://")},
382 {PATHTYPE_KEY::TRASH_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::TRASH_PATH] + QStringLiteral("://")},
383 {PATHTYPE_KEY::TAGS_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::TAGS_PATH] + QStringLiteral(":///")},
384 {PATHTYPE_KEY::SEARCH_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::SEARCH_PATH] + QStringLiteral("://")},
385 {PATHTYPE_KEY::CLOUD_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::CLOUD_PATH] + QStringLiteral(":///")},
386 {PATHTYPE_KEY::FISH_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::FISH_PATH] + QStringLiteral("://")},
387 {PATHTYPE_KEY::MTP_PATH, PATHTYPE_SCHEME[PATHTYPE_KEY::MTP_PATH] + QStringLiteral("://")}};
388
389
390 /**
391 * @brief Given a PATHTYPE_KEY return a user friendly string.
392 * @warning This is a user visible and translatable string, so it should not be used as a key anywhere
393 * @param key the PATHTYPE_KEY key
394 **/
395 static QString PathTypeLabel(const FMStatic::PATHTYPE_KEY &key);
396
397 /** * @brief Standard Data location path */
399
400 /** * @brief Standard Configuration location path */
402
403 /** * @brief Standard Cloud Cache location path */
404 inline static const QString CloudCachePath = DataPath + QStringLiteral("/Cloud/");
405
406 /** * @brief Standard desktop location path */
408
409 /** * @brief Standard applications location path */
411
412 /** * @brief Standard root location path */
413 inline static const QString RootPath = QUrl::fromLocalFile(QStringLiteral("/")).toString();
414
415 /** * @brief Standard pictures location path */
417
418 /** * @brief Standard downloads location path */
420
421 /** * @brief Standard documents location path */
423
424 /** * @brief Standard music location path */
426
427 /** * @brief Standard videos location path */
429
430
431#if defined(Q_OS_ANDROID)
432 /** * @brief Standard home location path */
433 inline static const QString HomePath = QUrl::fromLocalFile( MAUIAndroid::homePath()).toString();
434
435 /** * @brief The internally defined quick standard locations. */
436 inline static const QStringList defaultPaths = {HomePath, DocumentsPath, PicturesPath, MusicPath, VideosPath, DownloadsPath};
437#else
438
439 /** * @brief Standard home location path */
441
442 /** * @brief Standard trash location path */
443 inline static const QString TrashPath = QStringLiteral("trash:/");
444
445 /** * @brief The internally defined quick standard locations. */
446 inline static const QStringList defaultPaths = {
447 HomePath,
448 DesktopPath,
449 DocumentsPath,
450 DownloadsPath,
451 MusicPath,
452 PicturesPath,
453 VideosPath,
454 RootPath
455 };
456
457#endif
458
459 /**
460 * @brief A mapping of the standard location to a icon name.
461 */
462 inline static const QMap<QString, QString> folderIcon {{PicturesPath, QStringLiteral("folder-pictures")},
463 {DownloadsPath, QStringLiteral("folder-download")},
464 {DocumentsPath, QStringLiteral("folder-documents")},
465 {HomePath, QStringLiteral("user-home")},
466 {MusicPath, QStringLiteral("folder-music")},
467 {VideosPath, QStringLiteral("folder-videos")},
468 {DesktopPath, QStringLiteral("user-desktop")},
469 {AppsPath, QStringLiteral("system-run")},
470 {RootPath, QStringLiteral("folder-root")}};
471
472public Q_SLOTS:
473 /**
474 * @brief Search for files in a path using name filters
475 * @param query the term query to be searched, such as `".qml"` or `"music"`
476 * @param path the path where to perform or start the search
477 * @param hidden whether to search for hidden files
478 * @param onlyDirs whether to only search for directories and not files
479 * @param filters list of filter patterns such as `{"*.qml"}`, it can use regular expressions.
480 * @return the search results are returned as a FMH::MODEL_LIST
481 */
482 static FMH::MODEL_LIST search(const QString &query, const QUrl &path, const bool &hidden = false, const bool &onlyDirs = false, const QStringList &filters = QStringList());
483
484 /**
485 * @brief Devices mounted in the file system
486 * @return list of devices represented as a FMH::MODEL_LIST with information
487 */
488 static FMH::MODEL_LIST getDevices();
489
490 /**
491 * @brief A model list of the default paths in most systems, such as Home, Pictures, Video, Downloads, Music and Documents folders
492 * @return the packaged model with information for each directory
493 */
494 static FMH::MODEL_LIST getDefaultPaths();
495
496 /**
497 * @brief Given a list of path URLs pack all the info of such files as a FMH::MODEL_LIST
498 * @param items list of local URLs
499 * @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`
500 * @return
501 */
502 static FMH::MODEL_LIST packItems(const QStringList &items, const QString &type);
503
504 /**
505 * @brief Perform a move operation of the given files to a new destination
506 * @param urls list of URLs to be copied
507 * @param destinationDir destination
508 * @param name the name of the new directory where all the entries will be grouped/moved into
509 * @return whether the operation has been successful
510 */
511 static bool group(const QList<QUrl> &urls, const QUrl &destinationDir, const QString &name);
512
513 /**
514 * @brief Perform a copy of the files to the given destination
515 * @param urls list of URLs to be copy
516 * @param destinationDir destination
517 * @return whether the operation has been successful
518 */
519 static bool copy(const QList<QUrl> &urls, const QUrl &destinationDir);
520
521 /**
522 * @brief Perform a move/cut of a list of files to a destination. This function also moves the associated tags.
523 * @param urls list of URLs to be moved
524 * @param where destination path
525 * @return whether the operation has been successful
526 */
527 static bool cut(const QList<QUrl> &urls, const QUrl &where);
528
529 /**
530 * @see cut
531 * @param name new name of the directory where the files will be pasted
532 */
533 static bool cut(const QList<QUrl> &urls, const QUrl &where, const QString &name);
534
535 /**
536 * @brief List of files to be removed completely. This function also removes the associated tags to the files.
537 * @param urls file URLs to be removed
538 * @return Whether the operation has been sucessfull
539 */
540 static bool removeFiles(const QList<QUrl> &urls);
541
542 /**
543 * @brief Remove a directory recursively.
544 * @param path directory URL to be removed
545 * @return whether the operation has been sucessfull
546 */
547 static bool removeDir(const QUrl &path);
548
549 /**
550 * @brief The default home path.
551 * @return URL of the home location
552 */
553 static QString homePath();
554
555 /**
556 * @brief Given a file URL return its parent directory
557 * @param path the file URL
558 * @return the parent directory URL if it exists otherwise returns the passed URL
559 */
560 static QUrl parentDir(const QUrl &path);
561
562 /**
563 * @brief Checks if a given path URL is a default path as found in the `defaultPaths` method
564 * @param path the directory location path
565 * @return whether is a default path
566 */
567 static bool isDefaultPath(const QString &path);
568
569 /**
570 * @brief Whether a local file URL is a directory
571 * @param path file URL
572 * @return is a directory
573 */
574 static bool isDir(const QUrl &path);
575
576 /**
577 * @brief Whether a path is a URL server instead of a local file
578 * @param path
579 * @return
580 */
581 static bool isCloud(const QUrl &path);
582
583 /**
584 * @brief Checks if a local file exists in the file system
585 * @param path file URL
586 * @return whether it exists locally
587 */
588 static bool fileExists(const QUrl &path);
589
590 /**
591 * @brief Given a file URL return its parent directory, and if the path is a directory then returns the same path.
592 * @param path file path URL
593 * @return the directory URL
594 */
595 static QUrl fileDir(const QUrl &path);
596
597 /**
598 * @brief Write a configuration key-value entry to the directory conf file
599 * @param path directory path
600 * @param group the entry group name
601 * @param key the key name of the entry
602 * @param value the value of the entry
603 */
604 static void setDirConf(const QUrl &path, const QString &group, const QString &key, const QVariant &value);
605
606 /**
607 * @brief Checks if a mime-type belongs to a file type, for example, whether `image/jpg` belongs to the type `FMH::FILTER_TYPE`
608 * @param type FMH::FILTER_TYPE value
609 * @param mimeTypeName the mime type name
610 * @return whether the type contains the given name
611 */
612 static bool checkFileType(const int &type, const QString &mimeTypeName);
613 static bool checkFileType(const FMStatic::FILTER_TYPE &type, const QString &mimeTypeName);
614
615 /**
616 * @brief Moves to the trashcan the provided file URLs. The associated tags are kept in case the files are restored.
617 * @param urls the file URLs
618 */
619 static void moveToTrash(const QList<QUrl> &urls);
620
621 /**
622 * @brief Empty the trashcan
623 */
624 static void emptyTrash();
625
626 /**
627 * @brief Rename a file. The associated tags will be updated.
628 * @param url the file URL to be renamed
629 * @param name the new name of the file, not the new URL, for setting a new URl use cut instead.
630 * @return whether the operation was successful.
631 */
632 static bool rename(const QUrl &url, const QString &name);
633
634 /**
635 * @brief Creates a new directory given a base path and a name
636 * @param path base path where to create the new directory
637 * @param name the new directory name
638 * @return whether the operation was successful
639 */
640 static bool createDir(const QUrl &path, const QString &name);
641
642 /**
643 * @brief Creates a file given the base directory path and a file name
644 * @param path the base location path
645 * @param name the name of the new file to be created with the extension
646 * @return whether the operation was successful
647 */
648 static bool createFile(const QUrl &path, const QString &name);
649
650 /**
651 * @brief Creates a symbolic link to a given file URL
652 * @param path file to be linked
653 * @param where destination of the symbolic link
654 * @return whether the operation was successful
655 */
656 static bool createSymlink(const QUrl &path, const QUrl &where);
657
658 /**
659 * @brief Given a URL it tries to open it using the default application associated to it
660 * @param url the file URL to be opened
661 */
662 static void openUrl(const QUrl &url);
663
664 /**
665 * @brief Open the file URLs with the default file manager
666 * @param urls file or location URLs to be opened
667 */
668 static void openLocation(const QStringList &urls);
669
670 /**
671 * @brief Add a directory URL to the places bookmarks
672 * @param url the directory URL to be bookmarked
673 */
674 static void bookmark(const QUrl &url);
675
676 /**
677 * @brief Given a filter type return a list of associated name filters, as their suffixes.
678 * @param type the filter type to be mapped to a FMH::FILTER_TYPE
679 * @see FMH::FILTER_LIST
680 */
681 static QStringList nameFilters(const int &type);
682
683#ifdef KIO_AVAILABLE
684 /**
685 * @brief Get the file information packaged in a key-value model.
686 * @param path the file path
687 * @return the file info packed into a model
688 */
689 static const FMH::MODEL getFileInfo(const KFileItem &kfile);
690#endif
691
692 /**
693 * @brief getFileInfoModel
694 * @param path
695 * @return
696 */
697 static const FMH::MODEL getFileInfoModel(const QUrl &path);
698
699 /**
700 * @brief getFileInfo
701 * @param path
702 * @return
703 */
704 static const QVariantMap getFileInfo(const QUrl &path);
705
706 /**
707 * @brief Returns the icon name for certain file.
708 * The file path must be represented as a local file URL.
709 * It also looks into the directory conf file to get the directory custom icon.
710 *
711 * @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.
712 * @param path file path
713 * @return
714 */
715 static const QString getIconName(const QUrl &path);
716
717 /**
718 * @brief Return the icon name set in the directory `.directory` conf file.
719 * The passed path must be a local file URL.
720 * @param path the directory location
721 * @return the icon name
722 */
723 static const QString dirConfIcon(const QUrl &path);
724
725 /**
726 * @brief Get the mime type of the given file path
727 * @param path the file path
728 * @return the mime-type string
729 */
730 static const QString getMime(const QUrl &path);
731
732 /**
733 * @brief Given a file URL with a well defined scheme, get the PATHTYPE_KEY.
734 * @see PATHTYPE_KEY
735 * @param url the file URL
736 * @return the file PATHTYPE_KEY
737 */
738 static FMStatic::PATHTYPE_KEY getPathType(const QUrl &url);
739};
The FMStatic class is a group of static file management methods, this class has a constructor only as...
Definition fmstatic.h:35
static QStringList getMimeTypeSuffixes(const FILTER_TYPE &type, QString(*cb)(QString)=nullptr)
Given a FILTER_TYPE and its associated mime-types, return a list of all the supported file extension ...
Definition fmstatic.h:191
FILTER_TYPE
The common file types for filtering.
Definition fmstatic.h:51
PATHTYPE_KEY
The different location types supported. Most of them need of KDE KIO framework to be fully operationa...
Definition fmstatic.h:258
@ REMOTE_PATH
Remote locations, such as servers accessed via SSH or FTP.
Definition fmstatic.h:267
@ OTHER_PATH
Any other path.
Definition fmstatic.h:332
@ UNKNOWN_TYPE
Unknown location type.
Definition fmstatic.h:287
@ FISH_PATH
A remote SHH or FTP.
Definition fmstatic.h:312
@ APPS_PATH
The applications location.
Definition fmstatic.h:292
@ TAGS_PATH
A tag location.
Definition fmstatic.h:282
@ SEARCH_PATH
A search results.
Definition fmstatic.h:302
@ DRIVES_PATH
Hard drives locations.
Definition fmstatic.h:272
@ MTP_PATH
MTP path.
Definition fmstatic.h:317
@ CLOUD_PATH
A remote cloud server path.
Definition fmstatic.h:307
@ TRASH_PATH
The trash location.
Definition fmstatic.h:297
@ BOOKMARKS_PATH
A bookmarked location.
Definition fmstatic.h:327
@ REMOVABLE_PATH
Removable places, such as optic CDs, USB pen drives, etc.
Definition fmstatic.h:277
@ QUICK_PATH
The common standard paths.
Definition fmstatic.h:322
@ PLACES_PATH
Local paths, such as the Downloads, Pictures, etc.
Definition fmstatic.h:262
static QString homePath()
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
Q_SLOTSQ_SLOTS
QString writableLocation(StandardLocation type)
QUrl fromLocalFile(const QString &localFile)
QString toString(FormattingOptions options) const const
A location contents structured for convenience.
Definition fmstatic.h:244
FMH::MODEL_LIST content
The contents of the location.
Definition fmstatic.h:254
QUrl path
The location URL holding all of the contents.
Definition fmstatic.h:249
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:51:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.