FOSSredder 0.5.0
Loading...
Searching...
No Matches
FileSystemBrowser.cpp
Go to the documentation of this file.
1
5
7
8#include <QCoreApplication>
9#include <QDesktopServices>
10#include <QDir>
11#include <QFileInfo>
12#include <QUrl>
13
15
16namespace ui {
17
18FileSystemBrowser::FileSystemBrowser(QObject* parent) : QObject(parent) {}
19
20QVariantList FileSystemBrowser::listDir(const QString& path) const {
21 QVariantList out;
22 QDir d(path);
23 if (!d.exists())
24 return out;
25 QFileInfoList entries = d.entryInfoList(
26 QDir::NoDotAndDotDot | QDir::AllEntries, QDir::DirsFirst | QDir::Name);
27 for (const QFileInfo& fi : entries) {
28 QVariantMap m;
29 m[payload::keys::common::kName] = fi.fileName();
30 m[payload::keys::fileSystem::kPath] = fi.absoluteFilePath();
32 out.append(m);
33 }
34 return out;
35}
36
38 return QCoreApplication::applicationDirPath();
39}
40
41bool FileSystemBrowser::openLocation(const QString& path) const {
42 const QString trimmed = path.trimmed();
43 if (trimmed.isEmpty()) {
44 return false;
45 }
46
47 const QFileInfo info(trimmed);
48 QString folderPath;
49 if (info.exists()) {
50 folderPath = info.isDir() ? info.absoluteFilePath() : info.absolutePath();
51 } else {
52 const QDir dir(trimmed);
53 if (dir.exists()) {
54 folderPath = dir.absolutePath();
55 }
56 }
57 return !folderPath.isEmpty() &&
58 QDesktopServices::openUrl(QUrl::fromLocalFile(folderPath));
59}
60
61} // namespace ui
Declares the UI helper that exposes a minimal filesystem view to QML.
Declarations for the UI PayloadKeys component.
Q_INVOKABLE QVariantList listDir(const QString &path) const
List the contents of a directory in a QML-friendly payload shape.
Q_INVOKABLE bool openLocation(const QString &path) const
Opens the containing folder for a file or directory path.
Q_INVOKABLE QString appDir() const
Return the current application directory path.
FileSystemBrowser(QObject *parent=nullptr)
Create the filesystem helper exposed to QML.