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

KDE's Doxygen guidelines are available online.