mirror of
https://github.com/linuxdeepin/gio-qt.git
synced 2024-11-10 12:03:46 +01:00
feat: add interfaces for DGioDrive
This commit is contained in:
parent
1912f6f4e0
commit
8ddb30527b
@ -24,6 +24,8 @@
|
||||
#include <QObject>
|
||||
#include <QSharedData>
|
||||
|
||||
#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<DGioDrivePrivate> d_ptr;
|
||||
|
@ -47,6 +47,9 @@ Q_SIGNALS:
|
||||
void volumeAdded(QExplicitlySharedDataPointer<DGioVolume> volume);
|
||||
void volumeRemoved(QExplicitlySharedDataPointer<DGioVolume> volume);
|
||||
void volumeChanged(QExplicitlySharedDataPointer<DGioVolume> volume);
|
||||
void driveConnected(QExplicitlySharedDataPointer<DGioDrive> drive);
|
||||
void driveDisconnected(QExplicitlySharedDataPointer<DGioDrive> drive);
|
||||
void driveChanged(QExplicitlySharedDataPointer<DGioDrive> drive);
|
||||
|
||||
private:
|
||||
QScopedPointer<DGioVolumeManagerPrivate> d_ptr;
|
||||
|
@ -9,7 +9,7 @@ class DGioDrivePrivate{
|
||||
public:
|
||||
DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr);
|
||||
|
||||
Glib::RefPtr<Drive> getGmmDriveInstence();
|
||||
Glib::RefPtr<Drive> getGmmDriveInstence() const;
|
||||
|
||||
QString name() const;
|
||||
|
||||
@ -27,7 +27,7 @@ DGioDrivePrivate::DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr)
|
||||
|
||||
}
|
||||
|
||||
Glib::RefPtr<Drive> DGioDrivePrivate::getGmmDriveInstence()
|
||||
Glib::RefPtr<Drive> DGioDrivePrivate::getGmmDriveInstence() const
|
||||
{
|
||||
return m_gmmDrivePtr;
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
@ -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<Mount> &gmmMount)
|
||||
@ -74,7 +81,6 @@ void DGioVolumeManagerPrivate::slot_mountAdded(const Glib::RefPtr<Mount> &gmmMou
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Mount> copy(gmmMount);
|
||||
|
||||
QExplicitlySharedDataPointer<DGioMount> mount(new DGioMount(copy.release()));
|
||||
|
||||
Q_EMIT q->mountAdded(mount);
|
||||
@ -85,7 +91,6 @@ void DGioVolumeManagerPrivate::slot_mountRemoved(const Glib::RefPtr<Mount> &gmmM
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Mount> copy(gmmMount);
|
||||
|
||||
QExplicitlySharedDataPointer<DGioMount> mount(new DGioMount(copy.release()));
|
||||
|
||||
Q_EMIT q->mountRemoved(mount);
|
||||
@ -96,7 +101,6 @@ void DGioVolumeManagerPrivate::slot_mountPreRemoved(const Glib::RefPtr<Mount> &g
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Mount> copy(gmmMount);
|
||||
|
||||
QExplicitlySharedDataPointer<DGioMount> mount(new DGioMount(copy.release()));
|
||||
|
||||
Q_EMIT q->mountPreRemoved(mount);
|
||||
@ -107,7 +111,6 @@ void DGioVolumeManagerPrivate::slot_mountChanged(const Glib::RefPtr<Mount> &gmmM
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Mount> copy(gmmMount);
|
||||
|
||||
QExplicitlySharedDataPointer<DGioMount> mount(new DGioMount(copy.release()));
|
||||
|
||||
Q_EMIT q->mountChanged(mount);
|
||||
@ -118,7 +121,6 @@ void DGioVolumeManagerPrivate::slot_volumeAdded(const Glib::RefPtr<Volume> &gmmV
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Volume> copy(gmmVolume);
|
||||
|
||||
QExplicitlySharedDataPointer<DGioVolume> volume(new DGioVolume(copy.release()));
|
||||
|
||||
Q_EMIT q->volumeAdded(volume);
|
||||
@ -129,7 +131,6 @@ void DGioVolumeManagerPrivate::slot_volumeRemoved(const Glib::RefPtr<Volume> &gm
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Volume> copy(gmmVolume);
|
||||
|
||||
QExplicitlySharedDataPointer<DGioVolume> volume(new DGioVolume(copy.release()));
|
||||
|
||||
Q_EMIT q->volumeRemoved(volume);
|
||||
@ -140,12 +141,41 @@ void DGioVolumeManagerPrivate::slot_volumeChanged(const Glib::RefPtr<Volume> &gm
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Volume> copy(gmmVolume);
|
||||
|
||||
QExplicitlySharedDataPointer<DGioVolume> volume(new DGioVolume(copy.release()));
|
||||
|
||||
Q_EMIT q->volumeChanged(volume);
|
||||
}
|
||||
|
||||
void DGioVolumeManagerPrivate::slot_driveConnected(const Glib::RefPtr<Drive> &gmmDrive)
|
||||
{
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Drive> copy(gmmDrive);
|
||||
QExplicitlySharedDataPointer<DGioDrive> drive(new DGioDrive(copy.release()));
|
||||
|
||||
Q_EMIT q->driveConnected(drive);
|
||||
}
|
||||
|
||||
void DGioVolumeManagerPrivate::slot_driveDisconnected(const Glib::RefPtr<Drive> &gmmDrive)
|
||||
{
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Drive> copy(gmmDrive);
|
||||
QExplicitlySharedDataPointer<DGioDrive> drive(new DGioDrive(copy.release()));
|
||||
|
||||
Q_EMIT q->driveDisconnected(drive);
|
||||
}
|
||||
|
||||
void DGioVolumeManagerPrivate::slot_driveChanged(const Glib::RefPtr<Drive> &gmmDrive)
|
||||
{
|
||||
Q_Q(DGioVolumeManager);
|
||||
|
||||
Glib::RefPtr<Drive> copy(gmmDrive);
|
||||
QExplicitlySharedDataPointer<DGioDrive> drive(new DGioDrive(copy.release()));
|
||||
|
||||
Q_EMIT q->driveChanged(drive);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
DGioVolumeManager::DGioVolumeManager(QObject *parent)
|
||||
|
Loading…
Reference in New Issue
Block a user