forked from mirrors/gio-qt
parent
10392da3e3
commit
71a8a7de68
6 changed files with 119 additions and 2 deletions
|
@ -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
|
||||
)
|
||||
|
||||
|
|
26
gio-qt/include/dgiodrive.h
Normal file
26
gio-qt/include/dgiodrive.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef DGIODRIVE_H
|
||||
#define DGIODRIVE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSharedData>
|
||||
|
||||
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<DGioDrivePrivate> d_ptr;
|
||||
Q_DECLARE_PRIVATE(DGioDrive)
|
||||
};
|
||||
|
||||
|
||||
#endif // DGIODRIVE_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<QExplicitlySharedDataPointer<DGioMount> > getMounts();
|
||||
static const QList<QExplicitlySharedDataPointer<DGioVolume> > getVolumes();
|
||||
static const QList<QExplicitlySharedDataPointer<DGioDrive> > getDrives();
|
||||
|
||||
Q_SIGNALS:
|
||||
void mountAdded(QExplicitlySharedDataPointer<DGioMount> mount);
|
||||
|
|
61
gio-qt/source/dgiodrive.cpp
Normal file
61
gio-qt/source/dgiodrive.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "dgiodrive.h"
|
||||
|
||||
#include <glibmm/refptr.h>
|
||||
#include <giomm/drive.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Gio;
|
||||
|
||||
class DGioDrivePrivate{
|
||||
public:
|
||||
DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr);
|
||||
|
||||
Glib::RefPtr<Drive> getGmmDriveInstence();
|
||||
|
||||
QString name() const;
|
||||
|
||||
private:
|
||||
Glib::RefPtr<Drive> m_gmmDrivePtr;
|
||||
|
||||
DGioDrive *q_ptr;
|
||||
Q_DECLARE_PUBLIC(DGioDrive)
|
||||
};
|
||||
|
||||
DGioDrivePrivate::DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr)
|
||||
: m_gmmDrivePtr(gmmDrivePtr)
|
||||
, q_ptr(qq)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Glib::RefPtr<Drive> 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();
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include "dgiomount.h"
|
||||
#include "dgiovolume.h"
|
||||
#include "dgiodrive.h"
|
||||
#include "dgiovolumemanager.h"
|
||||
|
||||
#include <glibmm/refptr.h>
|
||||
|
@ -176,3 +177,19 @@ const QList<QExplicitlySharedDataPointer<DGioVolume> > DGioVolumeManager::getVol
|
|||
|
||||
return volumes;
|
||||
}
|
||||
|
||||
const QList<QExplicitlySharedDataPointer<DGioDrive> > DGioVolumeManager::getDrives()
|
||||
{
|
||||
Gio::init();
|
||||
|
||||
QList<QExplicitlySharedDataPointer<DGioDrive> > drives;
|
||||
|
||||
Glib::RefPtr<VolumeMonitor> vm = Gio::VolumeMonitor::get();
|
||||
|
||||
auto drvs = vm->get_connected_drives();
|
||||
for(auto oneDrive : drvs){
|
||||
QExplicitlySharedDataPointer<DGioDrive> drvPtr(new DGioDrive(oneDrive.release()));
|
||||
drives.push_back(drvPtr);
|
||||
}
|
||||
return drives;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <dgioutils.h>
|
||||
#include <dgiomount.h>
|
||||
#include <dgiovolume.h>
|
||||
#include <dgiodrive.h>
|
||||
#include <dgiovolumemanager.h>
|
||||
#include <dgiofileinfo.h>
|
||||
#include <dgiofileiterator.h>
|
||||
|
@ -85,7 +86,7 @@ int main(int argc, char * argv[])
|
|||
delete m;
|
||||
}
|
||||
|
||||
qDebug() << "----------------------";
|
||||
qDebug() << "---------mounts-------------";
|
||||
|
||||
const QList<QExplicitlySharedDataPointer<DGioMount> > 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<QExplicitlySharedDataPointer<DGioVolume> > vols = DGioVolumeManager::getVolumes();
|
||||
|
||||
|
@ -105,6 +106,14 @@ int main(int argc, char * argv[])
|
|||
qDebug() << p->name();
|
||||
}
|
||||
|
||||
qDebug() << "----------drives------------";
|
||||
|
||||
const QList<QExplicitlySharedDataPointer<DGioDrive> > drvs = DGioVolumeManager::getDrives();
|
||||
|
||||
for (const QExplicitlySharedDataPointer<DGioDrive> &p : drvs) {
|
||||
qDebug() << p->name();
|
||||
}
|
||||
|
||||
qDebug() << "----------------------";
|
||||
|
||||
QCoreApplication app(argc, argv);
|
||||
|
|
Loading…
Reference in a new issue