feat: add interface for g_volume_get_identifier.

This commit is contained in:
Chris Xiong 2019-09-05 14:00:46 +08:00
parent 8cc7cde492
commit 3f21a4a1b7
4 changed files with 31 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
# User # User
*.user *.user
# Build directory
build/

View File

@ -28,6 +28,14 @@ namespace Gio {
class Volume; class Volume;
} }
enum DGioVolumeIdentifierType {
VOLUME_IDENTIFIER_TYPE_LABEL,
VOLUME_IDENTIFIER_TYPE_NFS_MOUNT,
VOLUME_IDENTIFIER_TYPE_UUID,
VOLUME_IDENTIFIER_TYPE_CLASS
};
Q_ENUMS(DGioVolumeIdentifierType);
class DGioMount; class DGioMount;
class DGioVolumePrivate; class DGioVolumePrivate;
class DGioVolume : public QObject, public QSharedData class DGioVolume : public QObject, public QSharedData
@ -44,6 +52,8 @@ public:
QExplicitlySharedDataPointer<DGioMount> getMount(); QExplicitlySharedDataPointer<DGioMount> getMount();
QString identifier(DGioVolumeIdentifierType id) const;
private: private:
QScopedPointer<DGioVolumePrivate> d_ptr; QScopedPointer<DGioVolumePrivate> d_ptr;

View File

@ -115,3 +115,17 @@ QExplicitlySharedDataPointer<DGioMount> DGioVolume::getMount()
return mntPtr; return mntPtr;
} }
QString DGioVolume::identifier(DGioVolumeIdentifierType id) const
{
Q_D(const DGioVolume);
const static QHash<DGioVolumeIdentifierType, std::string> idtmap = {
{DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_LABEL, G_VOLUME_IDENTIFIER_KIND_LABEL},
{DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_NFS_MOUNT, G_VOLUME_IDENTIFIER_KIND_NFS_MOUNT},
{DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_UUID, G_VOLUME_IDENTIFIER_KIND_UUID},
{DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_CLASS, G_VOLUME_IDENTIFIER_KIND_CLASS}
};
return QString::fromStdString(d->getGmmVolumeInstance()->get_identifier(idtmap[id]));
}

View File

@ -123,7 +123,10 @@ int main(int argc, char * argv[])
const QList<QExplicitlySharedDataPointer<DGioVolume> > vols = DGioVolumeManager::getVolumes(); const QList<QExplicitlySharedDataPointer<DGioVolume> > vols = DGioVolumeManager::getVolumes();
for (const QExplicitlySharedDataPointer<DGioVolume> &p : vols) { for (const QExplicitlySharedDataPointer<DGioVolume> &p : vols) {
qDebug() << p->name(); qDebug() << p->name()
<< p->identifier(DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_UUID)
<< p->identifier(DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_CLASS)
<< p->identifier(DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_LABEL);
} }
qDebug() << "----------drives------------"; qDebug() << "----------drives------------";