From 71a8a7de68f6f82515d473fcfdbb815f15a505e6 Mon Sep 17 00:00:00 2001 From: kegechen Date: Thu, 1 Aug 2019 09:19:28 +0800 Subject: [PATCH] feat:add dgiodrive (#10) --- gio-qt/CMakeLists.txt | 2 + gio-qt/include/dgiodrive.h | 26 ++++++++++++ gio-qt/include/dgiovolumemanager.h | 2 + gio-qt/source/dgiodrive.cpp | 61 +++++++++++++++++++++++++++++ gio-qt/source/dgiovolumemanager.cpp | 17 ++++++++ qgio-tools/main.cpp | 13 +++++- 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 gio-qt/include/dgiodrive.h create mode 100644 gio-qt/source/dgiodrive.cpp diff --git a/gio-qt/CMakeLists.txt b/gio-qt/CMakeLists.txt index 87be596..43f56f3 100644 --- a/gio-qt/CMakeLists.txt +++ b/gio-qt/CMakeLists.txt @@ -12,6 +12,7 @@ set (QGIO_PUBLIC_HEADER_FILES include/dgiofileinfo.h include/dgioutils.h include/dgiofileiterator.h + include/dgiodrive.h ) set (QGIO_PRIVATE_HEADER_FILES @@ -27,6 +28,7 @@ set (QGIO_PRIVATE_CPP_FILES source/dgiofileinfo.cpp source/dgioutils.cpp source/dgiofileiterator.cpp + source/dgiodrive.cpp private/dgiohelper.cpp ) diff --git a/gio-qt/include/dgiodrive.h b/gio-qt/include/dgiodrive.h new file mode 100644 index 0000000..f24014c --- /dev/null +++ b/gio-qt/include/dgiodrive.h @@ -0,0 +1,26 @@ +#ifndef DGIODRIVE_H +#define DGIODRIVE_H + +#include +#include + +namespace Gio { +class Drive; +} + +class DGioDrivePrivate; +class DGioDrive : public QObject, public QSharedData{ + Q_OBJECT +public: + explicit DGioDrive(Gio::Drive *gmmDrivePtr, QObject *parent = nullptr); + ~DGioDrive(); + + QString name() const; + +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(DGioDrive) +}; + + +#endif // DGIODRIVE_H diff --git a/gio-qt/include/dgiovolumemanager.h b/gio-qt/include/dgiovolumemanager.h index 8d2a2e5..91e0194 100644 --- a/gio-qt/include/dgiovolumemanager.h +++ b/gio-qt/include/dgiovolumemanager.h @@ -6,6 +6,7 @@ class DGioMount; class DGioVolume; +class DGioDrive; class DGioVolumeManagerPrivate; class DGioVolumeManager : public QObject { @@ -16,6 +17,7 @@ public: static const QList > getMounts(); static const QList > getVolumes(); + static const QList > getDrives(); Q_SIGNALS: void mountAdded(QExplicitlySharedDataPointer mount); diff --git a/gio-qt/source/dgiodrive.cpp b/gio-qt/source/dgiodrive.cpp new file mode 100644 index 0000000..cb73fff --- /dev/null +++ b/gio-qt/source/dgiodrive.cpp @@ -0,0 +1,61 @@ +#include "dgiodrive.h" + +#include +#include + +#include + +using namespace Gio; + +class DGioDrivePrivate{ +public: + DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr); + + Glib::RefPtr getGmmDriveInstence(); + + QString name() const; + +private: + Glib::RefPtr m_gmmDrivePtr; + + DGioDrive *q_ptr; + Q_DECLARE_PUBLIC(DGioDrive) +}; + +DGioDrivePrivate::DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr) + : m_gmmDrivePtr(gmmDrivePtr) + , q_ptr(qq) +{ + +} + +Glib::RefPtr DGioDrivePrivate::getGmmDriveInstence() +{ + return m_gmmDrivePtr; +} + +QString DGioDrivePrivate::name() const +{ + return QString::fromStdString(m_gmmDrivePtr->get_name()); +} + +/////////////////////////////////////////////////////////////// +//// class DGioDrive +/// /////////////////////////////////////////////////////////// +DGioDrive::DGioDrive(Gio::Drive *gmmDrivePtr, QObject *parent) + : QObject(parent) + , d_ptr(new DGioDrivePrivate(this, gmmDrivePtr)) +{ + Q_CHECK_PTR(gmmDrivePtr); +} + +DGioDrive::~DGioDrive() +{ + +} + +QString DGioDrive::name() const +{ + Q_D(const DGioDrive); + return d->name(); +} diff --git a/gio-qt/source/dgiovolumemanager.cpp b/gio-qt/source/dgiovolumemanager.cpp index a9f4332..64538ad 100644 --- a/gio-qt/source/dgiovolumemanager.cpp +++ b/gio-qt/source/dgiovolumemanager.cpp @@ -1,5 +1,6 @@ #include "dgiomount.h" #include "dgiovolume.h" +#include "dgiodrive.h" #include "dgiovolumemanager.h" #include @@ -176,3 +177,19 @@ const QList > DGioVolumeManager::getVol return volumes; } + +const QList > DGioVolumeManager::getDrives() +{ + Gio::init(); + + QList > drives; + + Glib::RefPtr vm = Gio::VolumeMonitor::get(); + + auto drvs = vm->get_connected_drives(); + for(auto oneDrive : drvs){ + QExplicitlySharedDataPointer drvPtr(new DGioDrive(oneDrive.release())); + drives.push_back(drvPtr); + } + return drives; +} diff --git a/qgio-tools/main.cpp b/qgio-tools/main.cpp index 8f43f1c..912e76c 100644 --- a/qgio-tools/main.cpp +++ b/qgio-tools/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -85,7 +86,7 @@ int main(int argc, char * argv[]) delete m; } - qDebug() << "----------------------"; + qDebug() << "---------mounts-------------"; const QList > mnts = DGioVolumeManager::getMounts(); @@ -97,7 +98,7 @@ int main(int argc, char * argv[]) qDebug() << p->name() << p->uuid() << p->canUnmount() << p->themedIconNames() << p->themedIconNames(); } - qDebug() << "----------------------"; + qDebug() << "--------volumes--------------"; const QList > vols = DGioVolumeManager::getVolumes(); @@ -105,6 +106,14 @@ int main(int argc, char * argv[]) qDebug() << p->name(); } + qDebug() << "----------drives------------"; + + const QList > drvs = DGioVolumeManager::getDrives(); + + for (const QExplicitlySharedDataPointer &p : drvs) { + qDebug() << p->name(); + } + qDebug() << "----------------------"; QCoreApplication app(argc, argv);