feat:add Wrapper of Gio::File::mount_enclosing_volume

use DGioFile::mountEnclosingVolume to mount "smb://..."
This commit is contained in:
chenke 2019-08-06 09:44:19 +08:00 committed by 王子冲
parent 4c412bb5bf
commit 1912f6f4e0
4 changed files with 46 additions and 0 deletions

View file

@ -38,6 +38,7 @@ Q_DECLARE_FLAGS(DGioFileQueryInfoFlags, DGioFileQueryInfoFlag)
class DGioFileInfo; class DGioFileInfo;
class DGioFileIterator; class DGioFileIterator;
class DGioMountOperation;
class DGioFilePrivate; class DGioFilePrivate;
class DGioFile : public QObject, public QSharedData class DGioFile : public QObject, public QSharedData
{ {
@ -58,8 +59,11 @@ public:
QExplicitlySharedDataPointer<DGioFileIterator> createFileIterator(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE); QExplicitlySharedDataPointer<DGioFileIterator> createFileIterator(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);
void createFileIteratorAsync(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE); void createFileIteratorAsync(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);
void mountEnclosingVolume(DGioMountOperation *dgioMountOperation);
Q_SIGNALS: Q_SIGNALS:
void createFileIteratorReady(QExplicitlySharedDataPointer<DGioFileIterator> iter); void createFileIteratorReady(QExplicitlySharedDataPointer<DGioFileIterator> iter);
void mountEnclosingVolumeReady(bool result, QString msg);
private: private:
QScopedPointer<DGioFilePrivate> d_ptr; QScopedPointer<DGioFilePrivate> d_ptr;

View file

@ -23,6 +23,14 @@
#include <QObject> #include <QObject>
namespace Glib{
template <class T_CppObject>
class RefPtr;
}
namespace Gio{
class MountOperation;
}
enum DGioAskPasswordFlag enum DGioAskPasswordFlag
{ {
ASK_PASSWORD_NEED_PASSWORD = (1 << 0), ASK_PASSWORD_NEED_PASSWORD = (1 << 0),
@ -77,6 +85,9 @@ public:
void reply(DGioMountOperationResult result); void reply(DGioMountOperationResult result);
// do not release the ptr returned
Glib::RefPtr<Gio::MountOperation> getGIOMountOperationObj();
Q_SIGNALS: Q_SIGNALS:
void askPassword(QString message, QString defaultUser, QString defaultDomain, DGioAskPasswordFlags flags); void askPassword(QString message, QString defaultUser, QString defaultDomain, DGioAskPasswordFlags flags);
void askQuestion(QString message, QStringList choices); void askQuestion(QString message, QStringList choices);

View file

@ -29,6 +29,7 @@
#include <giomm/fileenumerator.h> #include <giomm/fileenumerator.h>
#include <QDebug> #include <QDebug>
#include <dgiomountoperation.h>
using namespace Gio; using namespace Gio;
@ -48,6 +49,8 @@ private:
void slot_enumerateChildrenAsyncResult(const Glib::RefPtr<Gio::AsyncResult>& result); void slot_enumerateChildrenAsyncResult(const Glib::RefPtr<Gio::AsyncResult>& result);
void slot_mountEnclosingVolumeResult(const Glib::RefPtr<Gio::AsyncResult>& result);
Q_DECLARE_PUBLIC(DGioFile) Q_DECLARE_PUBLIC(DGioFile)
}; };
@ -82,6 +85,20 @@ void DGioFilePrivate::slot_enumerateChildrenAsyncResult(const Glib::RefPtr<Async
} }
} }
void DGioFilePrivate::slot_mountEnclosingVolumeResult(const Glib::RefPtr<AsyncResult> &result)
{
Q_Q(DGioFile);
try {
bool res = m_gmmFilePtr->mount_enclosing_volume_finish(result);
Q_EMIT q->mountEnclosingVolumeReady(res, "");
} catch (const Glib::Error & error) {
qDebug() << QString::fromStdString(error.what().raw());
Q_EMIT q->mountEnclosingVolumeReady(false, QString::fromStdString(error.what().raw()));
}
}
// ------------------------------------------------------------- // -------------------------------------------------------------
DGioFile::DGioFile(File* gmmFilePtr, QObject *parent) DGioFile::DGioFile(File* gmmFilePtr, QObject *parent)
@ -293,3 +310,11 @@ void DGioFile::createFileIteratorAsync(QString attr, DGioFileQueryInfoFlags quer
d->getGmmFileInstance()->enumerate_children_async(sigc::mem_fun(d, &DGioFilePrivate::slot_enumerateChildrenAsyncResult), d->getGmmFileInstance()->enumerate_children_async(sigc::mem_fun(d, &DGioFilePrivate::slot_enumerateChildrenAsyncResult),
attr.toStdString(), flags); attr.toStdString(), flags);
} }
void DGioFile::mountEnclosingVolume(DGioMountOperation *dgioMountOperation)
{
Q_D(DGioFile);
d->getGmmFileInstance()->mount_enclosing_volume(dgioMountOperation->getGIOMountOperationObj(),
sigc::mem_fun(d, &DGioFilePrivate::slot_mountEnclosingVolumeResult));
}

View file

@ -200,3 +200,9 @@ void DGioMountOperation::reply(DGioMountOperationResult result)
d->getGmmMountOperationInstance()->reply(static_cast<MountOperationResult>(result)); d->getGmmMountOperationInstance()->reply(static_cast<MountOperationResult>(result));
} }
Glib::RefPtr<MountOperation> DGioMountOperation::getGIOMountOperationObj()
{
Q_D(const DGioMountOperation);
return d->getGmmMountOperationInstance();
}