feat: volume signals, file create from uri

(#1)
This commit is contained in:
Gary Wang 2019-07-25 14:09:22 +08:00 committed by GitHub
parent fa0bf3da6b
commit 238173e860
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 0 deletions

View File

@ -65,6 +65,8 @@ DGioFile::~DGioFile()
* This operation never fails since Gio::File::create_for_path never fails, but the returned
* object might not support any I/O operation if path is malformed.
*
* Caller take the ownership of the created object, you can also provide a \a parent object.
*
* \return the created DGioFile instance
*/
DGioFile *DGioFile::createFromPath(QString path, QObject *parent)
@ -78,6 +80,27 @@ DGioFile *DGioFile::createFromPath(QString path, QObject *parent)
return new DGioFile(gmmFile.release(), parent);
}
/*!
* \brief Create a DGioFile instance by given \a uri
*
* This operation never fails since Gio::File::create_for_uri never fails, but the returned
* object might not support any I/O operation if uri is malformed.
*
* Caller take the ownership of the created object, you can also provide a \a parent object.
*
* \return the created DGioFile instance
*/
DGioFile *DGioFile::createFromUri(QString uri, QObject *parent)
{
// ensure GIO got initialized
Gio::init();
// File::create_for_path never falls.
Glib::RefPtr<File> gmmFile = File::create_for_uri(uri.toStdString());
return new DGioFile(gmmFile.release(), parent);
}
QString DGioFile::basename() const
{
Q_D(const DGioFile);

View File

@ -18,6 +18,7 @@ public:
~DGioFile();
static DGioFile * createFromPath(QString path, QObject *parent = nullptr);
static DGioFile * createFromUri(QString uri, QObject *parent = nullptr);
QString basename() const;
QString path() const;

View File

@ -22,6 +22,9 @@ private:
void slot_mountRemoved(const Glib::RefPtr< Mount >& gmmMount);
void slot_mountPreRemoved(const Glib::RefPtr< Mount >& gmmMount);
void slot_mountChanged(const Glib::RefPtr< Mount >& gmmMount);
void slot_volumeAdded(const Glib::RefPtr< Volume >& gmmVolume);
void slot_volumeRemoved(const Glib::RefPtr< Volume >& gmmVolume);
void slot_volumeChanged(const Glib::RefPtr< Volume >& gmmVolume);
Q_DECLARE_PUBLIC(DGioVolumeManager)
};
@ -39,6 +42,10 @@ DGioVolumeManagerPrivate::DGioVolumeManagerPrivate(DGioVolumeManager *qq)
m_gmmVolumeMonitorPtr->signal_mount_removed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_mountRemoved));
m_gmmVolumeMonitorPtr->signal_mount_pre_unmount().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_mountPreRemoved));
m_gmmVolumeMonitorPtr->signal_mount_changed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_mountChanged));
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));
}
void DGioVolumeManagerPrivate::slot_mountAdded(const Glib::RefPtr<Mount> &gmmMount)
@ -85,6 +92,39 @@ void DGioVolumeManagerPrivate::slot_mountChanged(const Glib::RefPtr<Mount> &gmmM
Q_EMIT q->mountChanged(mount);
}
void DGioVolumeManagerPrivate::slot_volumeAdded(const Glib::RefPtr<Volume> &gmmVolume)
{
Q_Q(DGioVolumeManager);
Glib::RefPtr<Volume> copy(gmmVolume);
QExplicitlySharedDataPointer<DGioVolume> volume(new DGioVolume(copy.release()));
Q_EMIT q->volumeAdded(volume);
}
void DGioVolumeManagerPrivate::slot_volumeRemoved(const Glib::RefPtr<Volume> &gmmVolume)
{
Q_Q(DGioVolumeManager);
Glib::RefPtr<Volume> copy(gmmVolume);
QExplicitlySharedDataPointer<DGioVolume> volume(new DGioVolume(copy.release()));
Q_EMIT q->volumeRemoved(volume);
}
void DGioVolumeManagerPrivate::slot_volumeChanged(const Glib::RefPtr<Volume> &gmmVolume)
{
Q_Q(DGioVolumeManager);
Glib::RefPtr<Volume> copy(gmmVolume);
QExplicitlySharedDataPointer<DGioVolume> volume(new DGioVolume(copy.release()));
Q_EMIT q->volumeChanged(volume);
}
// -------------------------------------------------------------
DGioVolumeManager::DGioVolumeManager(QObject *parent)

View File

@ -22,6 +22,9 @@ Q_SIGNALS:
void mountRemoved(QExplicitlySharedDataPointer<DGioMount> mount);
void mountPreRemoved(QExplicitlySharedDataPointer<DGioMount> mount);
void mountChanged(QExplicitlySharedDataPointer<DGioMount> mount);
void volumeAdded(QExplicitlySharedDataPointer<DGioVolume> volume);
void volumeRemoved(QExplicitlySharedDataPointer<DGioVolume> volume);
void volumeChanged(QExplicitlySharedDataPointer<DGioVolume> volume);
private:
QScopedPointer<DGioVolumeManagerPrivate> d_ptr;