diff --git a/gio-qt/include/dgiofile.h b/gio-qt/include/dgiofile.h index 98a0c78..7d5778d 100644 --- a/gio-qt/include/dgiofile.h +++ b/gio-qt/include/dgiofile.h @@ -48,6 +48,7 @@ public: static DGioFile * createFromPath(QString path, QObject *parent = nullptr); static DGioFile * createFromUri(QString uri, QObject *parent = nullptr); + static DGioFile * createFromCmdArg(QString uri, QObject *parent = nullptr); QString basename() const; QString path() const; diff --git a/gio-qt/include/dgiovolume.h b/gio-qt/include/dgiovolume.h index f91c69e..d54b66f 100644 --- a/gio-qt/include/dgiovolume.h +++ b/gio-qt/include/dgiovolume.h @@ -38,6 +38,9 @@ public: ~DGioVolume(); QString name() const; + bool canMount() const; + bool canEject() const; + bool shouldAutoMount() const; QExplicitlySharedDataPointer getMount(); diff --git a/gio-qt/source/dgiofile.cpp b/gio-qt/source/dgiofile.cpp index 0740daf..66013df 100644 --- a/gio-qt/source/dgiofile.cpp +++ b/gio-qt/source/dgiofile.cpp @@ -139,6 +139,27 @@ DGioFile *DGioFile::createFromUri(QString uri, QObject *parent) return new DGioFile(gmmFile.release(), parent); } +/*! + * \brief Create a DGioFile instance for a given argument from the command line. + * + * The value of \a arg can be either a URI, an absolute path or a relative path resolved relative + * to the current working directory. This operation never fails, but the returned object might + * not support any I/O operation if \a arg points to a malformed path. + * + * \param arg A string containing either a URI, a relative or absolute path. + * \return the created DGioFile instance + */ +DGioFile *DGioFile::createFromCmdArg(QString arg, QObject *parent) +{ + // ensure GIO got initialized + Gio::init(); + + // File::create_for_uri never falls. + Glib::RefPtr gmmFile = File::create_for_commandline_arg(arg.toStdString()); + + return new DGioFile(gmmFile.release(), parent); +} + /*! * \brief Gets the base name (the last component of the path) of the DGioFile * diff --git a/gio-qt/source/dgiovolume.cpp b/gio-qt/source/dgiovolume.cpp index e45148e..4bba35e 100644 --- a/gio-qt/source/dgiovolume.cpp +++ b/gio-qt/source/dgiovolume.cpp @@ -84,6 +84,27 @@ QString DGioVolume::name() const return d->name(); } +bool DGioVolume::canMount() const +{ + Q_D(const DGioVolume); + + return d->getGmmVolumeInstance()->can_mount(); +} + +bool DGioVolume::canEject() const +{ + Q_D(const DGioVolume); + + return d->getGmmVolumeInstance()->can_eject(); +} + +bool DGioVolume::shouldAutoMount() const +{ + Q_D(const DGioVolume); + + return d->getGmmVolumeInstance()->should_automount(); +} + // Return value can be nullptr QExplicitlySharedDataPointer DGioVolume::getMount() {