From 1912f6f4e03b86ad0963d80b2f89cef1025aaea1 Mon Sep 17 00:00:00 2001 From: chenke Date: Tue, 6 Aug 2019 09:44:19 +0800 Subject: [PATCH] feat:add Wrapper of Gio::File::mount_enclosing_volume use DGioFile::mountEnclosingVolume to mount "smb://..." --- gio-qt/include/dgiofile.h | 4 ++++ gio-qt/include/dgiomountoperation.h | 11 +++++++++++ gio-qt/source/dgiofile.cpp | 25 +++++++++++++++++++++++++ gio-qt/source/dgiomountoperation.cpp | 6 ++++++ 4 files changed, 46 insertions(+) diff --git a/gio-qt/include/dgiofile.h b/gio-qt/include/dgiofile.h index 7d5778d..1b68aba 100644 --- a/gio-qt/include/dgiofile.h +++ b/gio-qt/include/dgiofile.h @@ -38,6 +38,7 @@ Q_DECLARE_FLAGS(DGioFileQueryInfoFlags, DGioFileQueryInfoFlag) class DGioFileInfo; class DGioFileIterator; +class DGioMountOperation; class DGioFilePrivate; class DGioFile : public QObject, public QSharedData { @@ -58,8 +59,11 @@ public: QExplicitlySharedDataPointer createFileIterator(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE); void createFileIteratorAsync(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE); + void mountEnclosingVolume(DGioMountOperation *dgioMountOperation); + Q_SIGNALS: void createFileIteratorReady(QExplicitlySharedDataPointer iter); + void mountEnclosingVolumeReady(bool result, QString msg); private: QScopedPointer d_ptr; diff --git a/gio-qt/include/dgiomountoperation.h b/gio-qt/include/dgiomountoperation.h index f8536cf..4d609ac 100644 --- a/gio-qt/include/dgiomountoperation.h +++ b/gio-qt/include/dgiomountoperation.h @@ -23,6 +23,14 @@ #include +namespace Glib{ +template +class RefPtr; +} +namespace Gio{ +class MountOperation; +} + enum DGioAskPasswordFlag { ASK_PASSWORD_NEED_PASSWORD = (1 << 0), @@ -77,6 +85,9 @@ public: void reply(DGioMountOperationResult result); + // do not release the ptr returned + Glib::RefPtr getGIOMountOperationObj(); + Q_SIGNALS: void askPassword(QString message, QString defaultUser, QString defaultDomain, DGioAskPasswordFlags flags); void askQuestion(QString message, QStringList choices); diff --git a/gio-qt/source/dgiofile.cpp b/gio-qt/source/dgiofile.cpp index 66013df..f2ffa81 100644 --- a/gio-qt/source/dgiofile.cpp +++ b/gio-qt/source/dgiofile.cpp @@ -29,6 +29,7 @@ #include #include +#include using namespace Gio; @@ -48,6 +49,8 @@ private: void slot_enumerateChildrenAsyncResult(const Glib::RefPtr& result); + void slot_mountEnclosingVolumeResult(const Glib::RefPtr& result); + Q_DECLARE_PUBLIC(DGioFile) }; @@ -82,6 +85,20 @@ void DGioFilePrivate::slot_enumerateChildrenAsyncResult(const Glib::RefPtr &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) @@ -293,3 +310,11 @@ void DGioFile::createFileIteratorAsync(QString attr, DGioFileQueryInfoFlags quer d->getGmmFileInstance()->enumerate_children_async(sigc::mem_fun(d, &DGioFilePrivate::slot_enumerateChildrenAsyncResult), 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)); +} diff --git a/gio-qt/source/dgiomountoperation.cpp b/gio-qt/source/dgiomountoperation.cpp index 07e43ec..d1d9bce 100644 --- a/gio-qt/source/dgiomountoperation.cpp +++ b/gio-qt/source/dgiomountoperation.cpp @@ -200,3 +200,9 @@ void DGioMountOperation::reply(DGioMountOperationResult result) d->getGmmMountOperationInstance()->reply(static_cast(result)); } + +Glib::RefPtr DGioMountOperation::getGIOMountOperationObj() +{ + Q_D(const DGioMountOperation); + return d->getGmmMountOperationInstance(); +}