MauiKit File Browsing

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