feat: new inertfaces for file and volume

This commit is contained in:
Gary Wang 2019-08-03 15:06:02 +08:00
parent 7bef27bc0a
commit bd6154c585
4 changed files with 46 additions and 0 deletions

View File

@ -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;

View File

@ -38,6 +38,9 @@ public:
~DGioVolume();
QString name() const;
bool canMount() const;
bool canEject() const;
bool shouldAutoMount() const;
QExplicitlySharedDataPointer<DGioMount> getMount();

View File

@ -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<File> 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
*

View File

@ -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<DGioMount> DGioVolume::getMount()
{