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 * * 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"`.
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
410#if defined(Q_OS_ANDROID)
411 /** * @brief Standard home location path */
412 inline static const QString HomePath = QUrl::fromLocalFile(MAUIAndroid::homePath()).toString();
413 inline static const QString MusicPath = QUrl::fromLocalFile(MAUIAndroid::getStandardPath(QStandardPaths::MusicLocation)).toString();
414 inline static const QString PicturesPath = QUrl::fromLocalFile(MAUIAndroid::getStandardPath(QStandardPaths::PicturesLocation)).toString();
415 inline static const QString DownloadsPath = QUrl::fromLocalFile(MAUIAndroid::getStandardPath(QStandardPaths::DownloadLocation)).toString();
416 inline static const QString DocumentsPath = QUrl::fromLocalFile(MAUIAndroid::getStandardPath(QStandardPaths::DocumentsLocation)).toString();
417 inline static const QString VideosPath = QUrl::fromLocalFile(MAUIAndroid::getStandardPath(QStandardPaths::MoviesLocation)).toString();
418
419 /** * @brief The internally defined quick standard locations. */
420 inline static const QStringList defaultPaths = {
421 HomePath,
422 DocumentsPath,
423 PicturesPath,
424 MusicPath,
425 VideosPath,
426 DownloadsPath};
427#else
428
429 /** * @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 the file path exists locally
582 */
583 static bool fileExists(const QUrl &path);
584
585 /**
586 * @brief Given a file URL, return its parent directory
587 * @note If the given path is a directory then returns the same path.
588 * @param path file path URL
589 * @return the directory URL
590 */
591 static QUrl fileDir(const QUrl &path);
592
593 /**
594 * @brief Write a configuration key-value entry to the directory conf file
595 * @param path directory path
596 * @param group the entry group name
597 * @param key the key name of the entry
598 * @param value the value of the entry
599 */
600 static void setDirConf(const QUrl &path, const QString &group, const QString &key, const QVariant &value);
601
602 /**
603 * @brief Checks if a mime-type belongs to a file type, for example, whether `image/jpg` belongs to the type `FMH::FILTER_TYPE`
604 * @param type FMH::FILTER_TYPE value
605 * @param mimeTypeName the mime type name
606 * @return whether the type contains the given name
607 */
608 static bool checkFileType(const int &type, const QString &mimeTypeName);
609 static bool checkFileType(const FMStatic::FILTER_TYPE &type, const QString &mimeTypeName);
610
611 /**
612 * @brief Moves to the trashcan the provided file URLs. The associated tags are kept in case the files are restored.
613 * @param urls the file URLs
614 */
615 static void moveToTrash(const QList<QUrl> &urls);
616
617 /**
618 * @brief Empty the trashcan
619 */
620 static void emptyTrash();
621
622 /**
623 * @brief Rename a file. The associated tags will be updated.
624 * @param url the file URL to be renamed
625 * @param name the new name of the file, not the new URL, for setting a new URl use cut instead.
626 * @return whether the operation was successful.
627 */
628 static bool rename(const QUrl &url, const QString &name);
629
630 /**
631 * @brief Creates a new directory given a base path and a name
632 * @param path base path where to create the new directory
633 * @param name the new directory name
634 * @return whether the operation was successful
635 */
636 static bool createDir(const QUrl &path, const QString &name);
637
638 /**
639 * @brief Creates a file given the base directory path and a file name
640 * @param path the base location path
641 * @param name the name of the new file to be created with the extension
642 * @return whether the operation was successful
643 */
644 static bool createFile(const QUrl &path, const QString &name);
645
646 /**
647 * @brief Creates a symbolic link to a given file URL
648 * @param path file to be linked
649 * @param where destination of the symbolic link
650 * @return whether the operation was successful
651 */
652 static bool createSymlink(const QUrl &path, const QUrl &where);
653
654 /**
655 * @brief Given a URL it tries to open it using the default application associated to it
656 * @param url the file URL to be opened
657 */
658 static void openUrl(const QUrl &url);
659
660 /**
661 * @brief Open the file URLs with the default file manager
662 * @param urls file or location URLs to be opened
663 */
664 static void openLocation(const QStringList &urls);
665
666 /**
667 * @brief Add a directory URL to the places bookmarks
668 * @param url the directory URL to be bookmarked
669 */
670 static void bookmark(const QUrl &url);
671
672 /**
673 * @brief Given a filter type return a list of associated name filters, as their suffixes.
674 * @param type the filter type to be mapped to a FMH::FILTER_TYPE
675 * @see FMH::FILTER_LIST
676 */
677 static QStringList nameFilters(const int &type);
678
679#ifdef KIO_AVAILABLE
680 /**
681 * @brief Get the file information packaged in a key-value model.
682 * @param path the file path
683 * @return the file info packed into a model
684 */
685 static const FMH::MODEL getFileInfo(const KFileItem &kfile);
686#endif
687
688 /**
689 * @brief getFileInfoModel
690 * @param path
691 * @return
692 */
693 static const FMH::MODEL getFileInfoModel(const QUrl &path);
694
695 /**
696 * @brief getFileInfo
697 * @param path
698 * @return
699 */
700 static const QVariantMap getFileInfo(const QUrl &path);
701
702 /**
703 * @brief Returns the icon name for certain file.
704 * The file path must be represented as a local file URL.
705 * It also looks into the directory conf file to get the directory custom icon.
706 *
707 * @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.
708 * @param path file path
709 * @return
710 */
711 static const QString getIconName(const QUrl &path);
712
713 /**
714 * @brief Return the icon name set in the directory `.directory` conf file.
715 * The passed path must be a local file URL.
716 * @param path the directory location
717 * @return the icon name
718 */
719 static const QString dirConfIcon(const QUrl &path);
720
721 /**
722 * @brief Get the mime type of the given file path
723 * @param path the file path
724 * @return the mime-type string
725 */
726 static const QString getMime(const QUrl &path);
727
728 /**
729 * @brief Given a file URL with a well defined scheme, get the PATHTYPE_KEY.
730 * @see PATHTYPE_KEY
731 * @param url the file URL
732 * @return the file PATHTYPE_KEY
733 */
734 static FMStatic::PATHTYPE_KEY getPathType(const QUrl &url);
735};
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:185
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: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 Mon Nov 4 2024 16:32:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.