2010-07-17 16:22:07 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GIOLISTER_H
|
|
|
|
#define GIOLISTER_H
|
|
|
|
|
|
|
|
#include "devicelister.h"
|
|
|
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
2010-07-17 19:18:02 +02:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QStringList>
|
|
|
|
|
2010-07-17 16:22:07 +02:00
|
|
|
class GioLister : public DeviceLister {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
GioLister();
|
|
|
|
~GioLister();
|
|
|
|
|
2010-07-17 19:18:02 +02:00
|
|
|
int priority() const { return 50; }
|
|
|
|
|
2010-07-17 16:22:07 +02:00
|
|
|
QStringList DeviceUniqueIDs();
|
2010-07-17 19:18:02 +02:00
|
|
|
QStringList DeviceIcons(const QString& id);
|
2010-07-17 16:22:07 +02:00
|
|
|
QString DeviceManufacturer(const QString& id);
|
|
|
|
QString DeviceModel(const QString& id);
|
|
|
|
quint64 DeviceCapacity(const QString& id);
|
|
|
|
quint64 DeviceFreeSpace(const QString& id);
|
|
|
|
QVariantMap DeviceHardwareInfo(const QString& id);
|
|
|
|
|
|
|
|
QString MakeFriendlyName(const QString &id);
|
|
|
|
QUrl MakeDeviceUrl(const QString &id);
|
|
|
|
|
2010-07-25 03:07:51 +02:00
|
|
|
void UnmountDevice(const QString &id);
|
|
|
|
|
2010-07-17 16:22:07 +02:00
|
|
|
protected:
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
private:
|
2010-07-17 19:18:02 +02:00
|
|
|
struct MountInfo {
|
|
|
|
MountInfo() : filesystem_size(0), filesystem_free(0) {}
|
|
|
|
|
|
|
|
QString unique_id() const;
|
|
|
|
|
|
|
|
GMount* mount;
|
2010-07-18 00:06:19 +02:00
|
|
|
QString unix_device;
|
2010-07-17 19:18:02 +02:00
|
|
|
QString mount_path;
|
2010-07-18 00:06:19 +02:00
|
|
|
QString uri;
|
2010-07-17 19:18:02 +02:00
|
|
|
QString name;
|
|
|
|
QStringList icon_names;
|
|
|
|
QString uuid;
|
|
|
|
quint64 filesystem_size;
|
|
|
|
quint64 filesystem_free;
|
|
|
|
QString filesystem_type;
|
|
|
|
};
|
|
|
|
|
2010-07-17 16:22:07 +02:00
|
|
|
void MountAdded(GMount* mount);
|
|
|
|
void MountChanged(GMount* mount);
|
|
|
|
void MountRemoved(GMount* mount);
|
|
|
|
|
|
|
|
static void MountAddedCallback(GVolumeMonitor*, GMount*, gpointer);
|
|
|
|
static void MountChangedCallback(GVolumeMonitor*, GMount*, gpointer);
|
|
|
|
static void MountRemovedCallback(GVolumeMonitor*, GMount*, gpointer);
|
|
|
|
|
2010-07-25 03:07:51 +02:00
|
|
|
static void VolumeEjectFinished(GObject *object, GAsyncResult *result, gpointer);
|
|
|
|
static void MountEjectFinished(GObject *object, GAsyncResult *result, gpointer);
|
|
|
|
static void MountUnmountFinished(GObject *object, GAsyncResult *result, gpointer);
|
|
|
|
|
2010-07-17 19:18:02 +02:00
|
|
|
static QString ConvertAndFree(char* str);
|
|
|
|
static MountInfo ReadMountInfo(GMount* mount);
|
|
|
|
|
|
|
|
// You MUST hold the mutex while calling this function
|
|
|
|
QString FindUniqueIdByMount(GMount* mount) const;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T LockAndGetMountInfo(const QString& id, T MountInfo::*field);
|
|
|
|
|
2010-07-17 16:22:07 +02:00
|
|
|
private:
|
|
|
|
GVolumeMonitor* monitor_;
|
2010-07-17 19:18:02 +02:00
|
|
|
|
|
|
|
QMutex mutex_;
|
|
|
|
QMap<QString, MountInfo> mounts_;
|
2010-07-17 16:22:07 +02:00
|
|
|
};
|
|
|
|
|
2010-07-17 19:18:02 +02:00
|
|
|
template <typename T>
|
|
|
|
T GioLister::LockAndGetMountInfo(const QString& id, T MountInfo::*field) {
|
|
|
|
QMutexLocker l(&mutex_);
|
|
|
|
if (!mounts_.contains(id))
|
|
|
|
return T();
|
|
|
|
|
|
|
|
return mounts_[id].*field;
|
|
|
|
}
|
|
|
|
|
2010-07-17 16:22:07 +02:00
|
|
|
#endif // GIOLISTER_H
|