From 8ddb30527b9dc25f1983f84d2a0732a1ca7c1a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AD=90=E5=86=B2?= Date: Tue, 6 Aug 2019 09:54:11 +0800 Subject: [PATCH] feat: add interfaces for DGioDrive --- gio-qt/include/dgiodrive.h | 7 ++++ gio-qt/include/dgiovolumemanager.h | 3 ++ gio-qt/source/dgiodrive.cpp | 53 +++++++++++++++++++++++++++-- gio-qt/source/dgiovolumemanager.cpp | 44 ++++++++++++++++++++---- 4 files changed, 97 insertions(+), 10 deletions(-) diff --git a/gio-qt/include/dgiodrive.h b/gio-qt/include/dgiodrive.h index a577787..d01ab8d 100644 --- a/gio-qt/include/dgiodrive.h +++ b/gio-qt/include/dgiodrive.h @@ -24,6 +24,8 @@ #include #include +#define DGIODRIVE_IDENTIFIER_KIND_UNIX_DEVICE "unix-device" + namespace Gio { class Drive; } @@ -36,6 +38,11 @@ public: ~DGioDrive(); QString name() const; + QString identifier(const QString & kind = DGIODRIVE_IDENTIFIER_KIND_UNIX_DEVICE) const; + bool hasVolumes() const; + bool canStart() const; + bool canStop() const; + bool canEject() const; private: QScopedPointer d_ptr; diff --git a/gio-qt/include/dgiovolumemanager.h b/gio-qt/include/dgiovolumemanager.h index d2f139e..13f8794 100644 --- a/gio-qt/include/dgiovolumemanager.h +++ b/gio-qt/include/dgiovolumemanager.h @@ -47,6 +47,9 @@ Q_SIGNALS: void volumeAdded(QExplicitlySharedDataPointer volume); void volumeRemoved(QExplicitlySharedDataPointer volume); void volumeChanged(QExplicitlySharedDataPointer volume); + void driveConnected(QExplicitlySharedDataPointer drive); + void driveDisconnected(QExplicitlySharedDataPointer drive); + void driveChanged(QExplicitlySharedDataPointer drive); private: QScopedPointer d_ptr; diff --git a/gio-qt/source/dgiodrive.cpp b/gio-qt/source/dgiodrive.cpp index d29250f..8004c55 100644 --- a/gio-qt/source/dgiodrive.cpp +++ b/gio-qt/source/dgiodrive.cpp @@ -9,7 +9,7 @@ class DGioDrivePrivate{ public: DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr); - Glib::RefPtr getGmmDriveInstence(); + Glib::RefPtr getGmmDriveInstence() const; QString name() const; @@ -27,9 +27,9 @@ DGioDrivePrivate::DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr) } -Glib::RefPtr DGioDrivePrivate::getGmmDriveInstence() +Glib::RefPtr DGioDrivePrivate::getGmmDriveInstence() const { - return m_gmmDrivePtr; + return m_gmmDrivePtr; } QString DGioDrivePrivate::name() const @@ -59,5 +59,52 @@ DGioDrive::~DGioDrive() QString DGioDrive::name() const { Q_D(const DGioDrive); + return d->name(); } + +/*! + * \brief Gets the identifier of the given kind for drive. + * + * Wrapper of Gio::Drive::get_identifier() + * + * The only identifier currently available is DGIODRIVE_IDENTIFIER_KIND_UNIX_DEVICE. + * + * \param kind the kind of identifier to return + * + * \return A string containing the requested identfier, or empty string if the drive doesn't have this kind of identifier. + */ +QString DGioDrive::identifier(const QString &kind) const +{ + Q_D(const DGioDrive); + + return QString::fromStdString(d->getGmmDriveInstence()->get_identifier(kind.toStdString())); +} + +bool DGioDrive::hasVolumes() const +{ + Q_D(const DGioDrive); + + return d->getGmmDriveInstence()->has_volumes(); +} + +bool DGioDrive::canStart() const +{ + Q_D(const DGioDrive); + + return d->getGmmDriveInstence()->can_start(); +} + +bool DGioDrive::canStop() const +{ + Q_D(const DGioDrive); + + return d->getGmmDriveInstence()->can_stop(); +} + +bool DGioDrive::canEject() const +{ + Q_D(const DGioDrive); + + return d->getGmmDriveInstence()->can_eject(); +} diff --git a/gio-qt/source/dgiovolumemanager.cpp b/gio-qt/source/dgiovolumemanager.cpp index 054f5e9..439c71c 100644 --- a/gio-qt/source/dgiovolumemanager.cpp +++ b/gio-qt/source/dgiovolumemanager.cpp @@ -46,6 +46,9 @@ private: void slot_volumeAdded(const Glib::RefPtr< Volume >& gmmVolume); void slot_volumeRemoved(const Glib::RefPtr< Volume >& gmmVolume); void slot_volumeChanged(const Glib::RefPtr< Volume >& gmmVolume); + void slot_driveConnected(const Glib::RefPtr< Drive >& gmmDrive); + void slot_driveDisconnected(const Glib::RefPtr< Drive >& gmmDrive); + void slot_driveChanged(const Glib::RefPtr< Drive >& gmmDrive); Q_DECLARE_PUBLIC(DGioVolumeManager) }; @@ -67,6 +70,10 @@ DGioVolumeManagerPrivate::DGioVolumeManagerPrivate(DGioVolumeManager *qq) m_gmmVolumeMonitorPtr->signal_volume_added().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_volumeAdded)); m_gmmVolumeMonitorPtr->signal_volume_removed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_volumeRemoved)); m_gmmVolumeMonitorPtr->signal_volume_changed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_volumeChanged)); + + m_gmmVolumeMonitorPtr->signal_drive_connected().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_driveConnected)); + m_gmmVolumeMonitorPtr->signal_drive_disconnected().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_driveDisconnected)); + m_gmmVolumeMonitorPtr->signal_drive_changed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_driveChanged)); } void DGioVolumeManagerPrivate::slot_mountAdded(const Glib::RefPtr &gmmMount) @@ -74,7 +81,6 @@ void DGioVolumeManagerPrivate::slot_mountAdded(const Glib::RefPtr &gmmMou Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmMount); - QExplicitlySharedDataPointer mount(new DGioMount(copy.release())); Q_EMIT q->mountAdded(mount); @@ -85,7 +91,6 @@ void DGioVolumeManagerPrivate::slot_mountRemoved(const Glib::RefPtr &gmmM Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmMount); - QExplicitlySharedDataPointer mount(new DGioMount(copy.release())); Q_EMIT q->mountRemoved(mount); @@ -96,7 +101,6 @@ void DGioVolumeManagerPrivate::slot_mountPreRemoved(const Glib::RefPtr &g Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmMount); - QExplicitlySharedDataPointer mount(new DGioMount(copy.release())); Q_EMIT q->mountPreRemoved(mount); @@ -107,7 +111,6 @@ void DGioVolumeManagerPrivate::slot_mountChanged(const Glib::RefPtr &gmmM Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmMount); - QExplicitlySharedDataPointer mount(new DGioMount(copy.release())); Q_EMIT q->mountChanged(mount); @@ -118,7 +121,6 @@ void DGioVolumeManagerPrivate::slot_volumeAdded(const Glib::RefPtr &gmmV Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmVolume); - QExplicitlySharedDataPointer volume(new DGioVolume(copy.release())); Q_EMIT q->volumeAdded(volume); @@ -129,7 +131,6 @@ void DGioVolumeManagerPrivate::slot_volumeRemoved(const Glib::RefPtr &gm Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmVolume); - QExplicitlySharedDataPointer volume(new DGioVolume(copy.release())); Q_EMIT q->volumeRemoved(volume); @@ -140,12 +141,41 @@ void DGioVolumeManagerPrivate::slot_volumeChanged(const Glib::RefPtr &gm Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmVolume); - QExplicitlySharedDataPointer volume(new DGioVolume(copy.release())); Q_EMIT q->volumeChanged(volume); } +void DGioVolumeManagerPrivate::slot_driveConnected(const Glib::RefPtr &gmmDrive) +{ + Q_Q(DGioVolumeManager); + + Glib::RefPtr copy(gmmDrive); + QExplicitlySharedDataPointer drive(new DGioDrive(copy.release())); + + Q_EMIT q->driveConnected(drive); +} + +void DGioVolumeManagerPrivate::slot_driveDisconnected(const Glib::RefPtr &gmmDrive) +{ + Q_Q(DGioVolumeManager); + + Glib::RefPtr copy(gmmDrive); + QExplicitlySharedDataPointer drive(new DGioDrive(copy.release())); + + Q_EMIT q->driveDisconnected(drive); +} + +void DGioVolumeManagerPrivate::slot_driveChanged(const Glib::RefPtr &gmmDrive) +{ + Q_Q(DGioVolumeManager); + + Glib::RefPtr copy(gmmDrive); + QExplicitlySharedDataPointer drive(new DGioDrive(copy.release())); + + Q_EMIT q->driveChanged(drive); +} + // ------------------------------------------------------------- DGioVolumeManager::DGioVolumeManager(QObject *parent)