Code cleanup.
This commit is contained in:
@@ -76,7 +76,7 @@ QVariantMap CddaLister::DeviceHardwareInfo(const QString &) {
|
||||
|
||||
QString CddaLister::MakeFriendlyName(const QString &id) {
|
||||
|
||||
CdIo_t* cdio = cdio_open(id.toLocal8Bit().constData(), DRIVER_DEVICE);
|
||||
CdIo_t *cdio = cdio_open(id.toLocal8Bit().constData(), DRIVER_DEVICE);
|
||||
cdio_hwinfo_t cd_info;
|
||||
if (cdio_get_hwinfo(cdio, &cd_info)) {
|
||||
cdio_destroy(cdio);
|
||||
|
||||
@@ -45,7 +45,7 @@ ConnectedDevice::ConnectedDevice(const QUrl &url, DeviceLister *lister, const QS
|
||||
model_(nullptr),
|
||||
song_count_(0) {
|
||||
|
||||
qLog(Info) << "connected" << url << unique_id << first_time;
|
||||
qLog(Info) << "Connected" << url << unique_id << first_time;
|
||||
|
||||
// Create the backend in the database thread.
|
||||
backend_ = new CollectionBackend();
|
||||
@@ -61,6 +61,7 @@ ConnectedDevice::ConnectedDevice(const QUrl &url, DeviceLister *lister, const QS
|
||||
|
||||
// Create the model
|
||||
model_ = new CollectionModel(backend_, app_, this);
|
||||
|
||||
}
|
||||
|
||||
ConnectedDevice::~ConnectedDevice() { backend_->deleteLater(); }
|
||||
@@ -77,8 +78,7 @@ void ConnectedDevice::InitBackendDirectory(const QString &mount_point, bool firs
|
||||
// the database to fix it. This can be done entirely in sqlite so it's
|
||||
// relatively fast...
|
||||
|
||||
// Get the directory it was mounted at last time. Devices only have one
|
||||
// directory (the root).
|
||||
// Get the directory it was mounted at last time. Devices only have one directory (the root).
|
||||
Directory dir = backend_->GetAllDirectories()[0];
|
||||
if (dir.path != mount_point) {
|
||||
// The directory is different, commence the munging.
|
||||
@@ -90,6 +90,7 @@ void ConnectedDevice::InitBackendDirectory(const QString &mount_point, bool firs
|
||||
// Load the directory properly now
|
||||
backend_->LoadDirectoriesAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ConnectedDevice::Eject() {
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
|
||||
DeviceKitLister::DeviceKitLister() {}
|
||||
DeviceKitLister::~DeviceKitLister() {}
|
||||
//qLog(Debug) << __PRETTY_FUNCTION__;
|
||||
|
||||
QString DeviceKitLister::DeviceData::unique_id() const {
|
||||
return QString("DeviceKit/%1/%2/%3/%4").arg(drive_serial, drive_vendor, drive_model).arg(device_size);
|
||||
|
||||
@@ -394,6 +394,7 @@ int DeviceManager::FindDeviceById(const QString &id) const {
|
||||
if (backend.unique_id_ == id) return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
@@ -406,13 +407,13 @@ int DeviceManager::FindDeviceByUrl(const QList<QUrl> &urls) const {
|
||||
for (const DeviceInfo::Backend &backend : devices_[i].backends_) {
|
||||
if (!backend.lister_) continue;
|
||||
|
||||
QList<QUrl> device_urls =
|
||||
backend.lister_->MakeDeviceUrls(backend.unique_id_);
|
||||
QList<QUrl> device_urls = backend.lister_->MakeDeviceUrls(backend.unique_id_);
|
||||
for (const QUrl &url : device_urls) {
|
||||
if (urls.contains(url)) return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
@@ -435,7 +436,8 @@ void DeviceManager::PhysicalDeviceAdded(const QString &id) {
|
||||
}
|
||||
|
||||
emit dataChanged(index(i, 0), index(i, 0));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Check if we have another device with the same URL
|
||||
i = FindDeviceByUrl(lister->MakeDeviceUrls(id));
|
||||
if (i != -1) {
|
||||
@@ -452,7 +454,8 @@ void DeviceManager::PhysicalDeviceAdded(const QString &id) {
|
||||
}
|
||||
|
||||
emit dataChanged(index(i, 0), index(i, 0));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// It's a completely new device
|
||||
DeviceInfo info;
|
||||
info.backends_ << DeviceInfo::Backend(lister, id);
|
||||
|
||||
@@ -144,6 +144,7 @@ void DeviceItemDelegate::paint(QPainter *p, const QStyleOptionViewItem &opt, con
|
||||
p->drawText(line2, Qt::AlignLeft | Qt::AlignTop, status_text);
|
||||
|
||||
p->restore();
|
||||
|
||||
}
|
||||
|
||||
DeviceView::DeviceView(QWidget *parent)
|
||||
@@ -232,13 +233,14 @@ void DeviceView::contextMenuEvent(QContextMenuEvent *e) {
|
||||
eject_action_->setEnabled(is_plugged_in);
|
||||
|
||||
device_menu_->popup(e->globalPos());
|
||||
} else if (collection_index.isValid()) {
|
||||
}
|
||||
else if (collection_index.isValid()) {
|
||||
const QModelIndex parent_device_index = FindParentDevice(menu_index_);
|
||||
|
||||
bool is_filesystem_device = false;
|
||||
if (parent_device_index.isValid()) {
|
||||
std::shared_ptr<ConnectedDevice> device =
|
||||
app_->device_manager()->GetConnectedDevice(parent_device_index.row());
|
||||
std::shared_ptr<ConnectedDevice> device = app_->device_manager()->GetConnectedDevice(parent_device_index.row());
|
||||
qLog(Debug) << device->LocalPath();
|
||||
if (device && !device->LocalPath().isEmpty()) is_filesystem_device = true;
|
||||
}
|
||||
|
||||
@@ -286,8 +288,7 @@ void DeviceView::Connect() {
|
||||
|
||||
void DeviceView::DeviceConnected(int row) {
|
||||
|
||||
std::shared_ptr<ConnectedDevice> device =
|
||||
app_->device_manager()->GetConnectedDevice(row);
|
||||
std::shared_ptr<ConnectedDevice> device = app_->device_manager()->GetConnectedDevice(row);
|
||||
if (!device) return;
|
||||
|
||||
QModelIndex sort_idx = sort_model_->mapFromSource(app_->device_manager()->index(row));
|
||||
@@ -300,6 +301,7 @@ void DeviceView::DeviceConnected(int row) {
|
||||
merged_model_->AddSubModel(sort_idx, sort_model);
|
||||
|
||||
expand(menu_index_);
|
||||
|
||||
}
|
||||
|
||||
void DeviceView::DeviceDisconnected(int row) {
|
||||
|
||||
@@ -61,10 +61,10 @@ bool GioLister::DeviceInfo::is_suitable() const {
|
||||
}
|
||||
|
||||
template <typename T, typename F>
|
||||
void OperationFinished(F f, GObject* object, GAsyncResult* result) {
|
||||
void OperationFinished(F f, GObject *object, GAsyncResult *result) {
|
||||
|
||||
T* obj = reinterpret_cast<T*>(object);
|
||||
GError* error = nullptr;
|
||||
T *obj = reinterpret_cast<T*>(object);
|
||||
GError *error = nullptr;
|
||||
|
||||
f(obj, result, &error);
|
||||
|
||||
@@ -75,7 +75,7 @@ void OperationFinished(F f, GObject* object, GAsyncResult* result) {
|
||||
|
||||
}
|
||||
|
||||
void GioLister::VolumeMountFinished(GObject* object, GAsyncResult* result, gpointer) {
|
||||
void GioLister::VolumeMountFinished(GObject *object, GAsyncResult *result, gpointer) {
|
||||
OperationFinished<GVolume>(std::bind(g_volume_mount_finish, _1, _2, _3), object, result);
|
||||
}
|
||||
|
||||
@@ -84,9 +84,9 @@ void GioLister::Init() {
|
||||
monitor_.reset_without_add(g_volume_monitor_get());
|
||||
|
||||
// Get existing volumes
|
||||
GList* const volumes = g_volume_monitor_get_volumes(monitor_);
|
||||
for (GList* p = volumes; p; p = p->next) {
|
||||
GVolume* volume = static_cast<GVolume*>(p->data);
|
||||
GList *const volumes = g_volume_monitor_get_volumes(monitor_);
|
||||
for (GList *p = volumes; p; p = p->next) {
|
||||
GVolume *volume = static_cast<GVolume*>(p->data);
|
||||
|
||||
VolumeAdded(volume);
|
||||
g_object_unref(volume);
|
||||
@@ -94,9 +94,9 @@ void GioLister::Init() {
|
||||
g_list_free(volumes);
|
||||
|
||||
// Get existing mounts
|
||||
GList* const mounts = g_volume_monitor_get_mounts(monitor_);
|
||||
for (GList* p = mounts; p; p = p->next) {
|
||||
GMount* mount = static_cast<GMount*>(p->data);
|
||||
GList *const mounts = g_volume_monitor_get_mounts(monitor_);
|
||||
for (GList *p = mounts; p; p = p->next) {
|
||||
GMount *mount = static_cast<GMount*>(p->data);
|
||||
|
||||
MountAdded(mount);
|
||||
g_object_unref(mount);
|
||||
@@ -123,13 +123,13 @@ QStringList GioLister::DeviceUniqueIDs() {
|
||||
return devices_.keys();
|
||||
}
|
||||
|
||||
QVariantList GioLister::DeviceIcons(const QString& id) {
|
||||
QVariantList GioLister::DeviceIcons(const QString &id) {
|
||||
|
||||
QVariantList ret;
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return ret;
|
||||
|
||||
const DeviceInfo& info = devices_[id];
|
||||
const DeviceInfo &info = devices_[id];
|
||||
|
||||
if (info.mount) {
|
||||
ret << DeviceLister::GuessIconForPath(info.mount_path);
|
||||
@@ -142,37 +142,37 @@ QVariantList GioLister::DeviceIcons(const QString& id) {
|
||||
|
||||
}
|
||||
|
||||
QString GioLister::DeviceManufacturer(const QString& id) { return QString(); }
|
||||
QString GioLister::DeviceManufacturer(const QString &id) { return QString(); }
|
||||
|
||||
QString GioLister::DeviceModel(const QString& id) {
|
||||
QString GioLister::DeviceModel(const QString &id) {
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return QString();
|
||||
const DeviceInfo& info = devices_[id];
|
||||
const DeviceInfo &info = devices_[id];
|
||||
|
||||
return info.drive_name.isEmpty() ? info.volume_name : info.drive_name;
|
||||
|
||||
}
|
||||
|
||||
quint64 GioLister::DeviceCapacity(const QString& id) {
|
||||
quint64 GioLister::DeviceCapacity(const QString &id) {
|
||||
return LockAndGetDeviceInfo(id, &DeviceInfo::filesystem_size);
|
||||
}
|
||||
|
||||
quint64 GioLister::DeviceFreeSpace(const QString& id) {
|
||||
quint64 GioLister::DeviceFreeSpace(const QString &id) {
|
||||
return LockAndGetDeviceInfo(id, &DeviceInfo::filesystem_free);
|
||||
}
|
||||
|
||||
QString GioLister::MakeFriendlyName(const QString& id) {
|
||||
QString GioLister::MakeFriendlyName(const QString &id) {
|
||||
return DeviceModel(id);
|
||||
}
|
||||
|
||||
QVariantMap GioLister::DeviceHardwareInfo(const QString& id) {
|
||||
QVariantMap GioLister::DeviceHardwareInfo(const QString &id) {
|
||||
|
||||
QVariantMap ret;
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return ret;
|
||||
const DeviceInfo& info = devices_[id];
|
||||
const DeviceInfo &info = devices_[id];
|
||||
|
||||
ret[QT_TR_NOOP("Mount point")] = info.mount_path;
|
||||
ret[QT_TR_NOOP("Device")] = info.volume_unix_device;
|
||||
@@ -181,7 +181,7 @@ QVariantMap GioLister::DeviceHardwareInfo(const QString& id) {
|
||||
|
||||
}
|
||||
|
||||
QList<QUrl> GioLister::MakeDeviceUrls(const QString& id) {
|
||||
QList<QUrl> GioLister::MakeDeviceUrls(const QString &id) {
|
||||
|
||||
QString mount_point;
|
||||
QString uri;
|
||||
@@ -198,40 +198,41 @@ QList<QUrl> GioLister::MakeDeviceUrls(const QString& id) {
|
||||
|
||||
QList<QUrl> ret;
|
||||
|
||||
// Special case for file:// GIO URIs - we have to check whether they point
|
||||
// to an ipod.
|
||||
// Special case for file:// GIO URIs - we have to check whether they point to an ipod.
|
||||
if (url.isValid() && url.scheme() == "file") {
|
||||
ret << MakeUrlFromLocalPath(url.path());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ret << url;
|
||||
}
|
||||
|
||||
ret << MakeUrlFromLocalPath(mount_point);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
void GioLister::VolumeAddedCallback(GVolumeMonitor*, GVolume* v, gpointer d) {
|
||||
void GioLister::VolumeAddedCallback(GVolumeMonitor*, GVolume *v, gpointer d) {
|
||||
static_cast<GioLister*>(d)->VolumeAdded(v);
|
||||
}
|
||||
|
||||
void GioLister::VolumeRemovedCallback(GVolumeMonitor*, GVolume* v, gpointer d) {
|
||||
void GioLister::VolumeRemovedCallback(GVolumeMonitor*, GVolume *v, gpointer d) {
|
||||
static_cast<GioLister*>(d)->VolumeRemoved(v);
|
||||
}
|
||||
|
||||
void GioLister::MountAddedCallback(GVolumeMonitor*, GMount* m, gpointer d) {
|
||||
void GioLister::MountAddedCallback(GVolumeMonitor*, GMount *m, gpointer d) {
|
||||
static_cast<GioLister*>(d)->MountAdded(m);
|
||||
}
|
||||
|
||||
void GioLister::MountChangedCallback(GVolumeMonitor*, GMount* m, gpointer d) {
|
||||
void GioLister::MountChangedCallback(GVolumeMonitor*, GMount *m, gpointer d) {
|
||||
static_cast<GioLister*>(d)->MountChanged(m);
|
||||
}
|
||||
|
||||
void GioLister::MountRemovedCallback(GVolumeMonitor*, GMount* m, gpointer d) {
|
||||
void GioLister::MountRemovedCallback(GVolumeMonitor*, GMount *m, gpointer d) {
|
||||
static_cast<GioLister*>(d)->MountRemoved(m);
|
||||
}
|
||||
|
||||
void GioLister::VolumeAdded(GVolume* volume) {
|
||||
void GioLister::VolumeAdded(GVolume *volume) {
|
||||
|
||||
g_object_ref(volume);
|
||||
|
||||
@@ -255,7 +256,7 @@ void GioLister::VolumeAdded(GVolume* volume) {
|
||||
|
||||
}
|
||||
|
||||
void GioLister::VolumeRemoved(GVolume* volume) {
|
||||
void GioLister::VolumeRemoved(GVolume *volume) {
|
||||
|
||||
QString id;
|
||||
|
||||
@@ -270,7 +271,7 @@ void GioLister::VolumeRemoved(GVolume* volume) {
|
||||
emit DeviceRemoved(id);
|
||||
}
|
||||
|
||||
void GioLister::MountAdded(GMount* mount) {
|
||||
void GioLister::MountAdded(GMount *mount) {
|
||||
|
||||
g_object_ref(mount);
|
||||
|
||||
@@ -316,7 +317,7 @@ void GioLister::MountAdded(GMount* mount) {
|
||||
|
||||
}
|
||||
|
||||
void GioLister::MountChanged(GMount* mount) {
|
||||
void GioLister::MountChanged(GMount *mount) {
|
||||
|
||||
QString id;
|
||||
{
|
||||
@@ -344,7 +345,7 @@ void GioLister::MountChanged(GMount* mount) {
|
||||
|
||||
}
|
||||
|
||||
void GioLister::MountRemoved(GMount* mount) {
|
||||
void GioLister::MountRemoved(GMount *mount) {
|
||||
|
||||
QString id;
|
||||
{
|
||||
@@ -359,13 +360,13 @@ void GioLister::MountRemoved(GMount* mount) {
|
||||
|
||||
}
|
||||
|
||||
QString GioLister::DeviceInfo::ConvertAndFree(char* str) {
|
||||
QString GioLister::DeviceInfo::ConvertAndFree(char *str) {
|
||||
QString ret = QString::fromUtf8(str);
|
||||
g_free(str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) {
|
||||
void GioLister::DeviceInfo::ReadMountInfo(GMount *mount) {
|
||||
|
||||
// Get basic information
|
||||
this->mount.reset_without_add(mount);
|
||||
@@ -375,16 +376,16 @@ void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) {
|
||||
|
||||
// Get the icon name(s)
|
||||
mount_icon_names.clear();
|
||||
GIcon* icon = g_mount_get_icon(mount);
|
||||
GIcon *icon = g_mount_get_icon(mount);
|
||||
if (G_IS_THEMED_ICON(icon)) {
|
||||
const char* const* icons = g_themed_icon_get_names(G_THEMED_ICON(icon));
|
||||
for (const char* const* p = icons; *p; ++p) {
|
||||
const char *const *icons = g_themed_icon_get_names(G_THEMED_ICON(icon));
|
||||
for (const char *const *p = icons; *p; ++p) {
|
||||
mount_icon_names << QString::fromUtf8(*p);
|
||||
}
|
||||
}
|
||||
g_object_unref(icon);
|
||||
|
||||
GFile* root = g_mount_get_root(mount);
|
||||
GFile *root = g_mount_get_root(mount);
|
||||
|
||||
// Get the mount path
|
||||
mount_path = ConvertAndFree(g_file_get_path(root));
|
||||
@@ -393,8 +394,8 @@ void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) {
|
||||
// Do a sanity check to make sure the root is actually this mount - when a
|
||||
// device is unmounted GIO sends a changed signal before the removed signal,
|
||||
// and we end up reading information about the / filesystem by mistake.
|
||||
GError* error = nullptr;
|
||||
GMount* actual_mount = g_file_find_enclosing_mount(root, nullptr, &error);
|
||||
GError *error = nullptr;
|
||||
GMount *actual_mount = g_file_find_enclosing_mount(root, nullptr, &error);
|
||||
if (error || !actual_mount) {
|
||||
g_error_free(error);
|
||||
invalid_enclosing_mount = true;
|
||||
@@ -405,21 +406,15 @@ void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) {
|
||||
|
||||
// Query the filesystem info for size, free space, and type
|
||||
error = nullptr;
|
||||
GFileInfo* info = g_file_query_filesystem_info(
|
||||
root, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE
|
||||
"," G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
|
||||
nullptr, &error);
|
||||
GFileInfo *info = g_file_query_filesystem_info(root, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE "," G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, nullptr, &error);
|
||||
if (error) {
|
||||
qLog(Warning) << error->message;
|
||||
g_error_free(error);
|
||||
}
|
||||
else {
|
||||
filesystem_size = g_file_info_get_attribute_uint64(
|
||||
info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
|
||||
filesystem_free = g_file_info_get_attribute_uint64(
|
||||
info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
|
||||
filesystem_type = QString::fromUtf8(g_file_info_get_attribute_string(
|
||||
info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE));
|
||||
filesystem_size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
|
||||
filesystem_free = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
|
||||
filesystem_type = QString::fromUtf8(g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE));
|
||||
g_object_unref(info);
|
||||
}
|
||||
|
||||
@@ -442,7 +437,7 @@ void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) {
|
||||
|
||||
}
|
||||
|
||||
void GioLister::DeviceInfo::ReadVolumeInfo(GVolume* volume) {
|
||||
void GioLister::DeviceInfo::ReadVolumeInfo(GVolume *volume) {
|
||||
|
||||
this->volume.reset_without_add(volume);
|
||||
if (!volume) return;
|
||||
@@ -451,7 +446,7 @@ void GioLister::DeviceInfo::ReadVolumeInfo(GVolume* volume) {
|
||||
volume_uuid = ConvertAndFree(g_volume_get_uuid(volume));
|
||||
volume_unix_device = ConvertAndFree(g_volume_get_identifier(volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE));
|
||||
|
||||
GFile* root = g_volume_get_activation_root(volume);
|
||||
GFile *root = g_volume_get_activation_root(volume);
|
||||
if (root) {
|
||||
volume_root_uri = g_file_get_uri(root);
|
||||
g_object_unref(root);
|
||||
@@ -459,7 +454,7 @@ void GioLister::DeviceInfo::ReadVolumeInfo(GVolume* volume) {
|
||||
|
||||
}
|
||||
|
||||
void GioLister::DeviceInfo::ReadDriveInfo(GDrive* drive) {
|
||||
void GioLister::DeviceInfo::ReadDriveInfo(GDrive *drive) {
|
||||
this->drive.reset_without_add(drive);
|
||||
if (!drive) return;
|
||||
|
||||
@@ -467,38 +462,38 @@ void GioLister::DeviceInfo::ReadDriveInfo(GDrive* drive) {
|
||||
drive_removable = g_drive_is_media_removable(drive);
|
||||
}
|
||||
|
||||
QString GioLister::FindUniqueIdByMount(GMount* mount) const {
|
||||
for (const DeviceInfo& info : devices_) {
|
||||
QString GioLister::FindUniqueIdByMount(GMount *mount) const {
|
||||
for (const DeviceInfo &info : devices_) {
|
||||
if (info.mount == mount) return info.unique_id();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString GioLister::FindUniqueIdByVolume(GVolume* volume) const {
|
||||
for (const DeviceInfo& info : devices_) {
|
||||
QString GioLister::FindUniqueIdByVolume(GVolume *volume) const {
|
||||
for (const DeviceInfo &info : devices_) {
|
||||
if (info.volume == volume) return info.unique_id();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void GioLister::VolumeEjectFinished(GObject* object, GAsyncResult* result, gpointer) {
|
||||
void GioLister::VolumeEjectFinished(GObject *object, GAsyncResult *result, gpointer) {
|
||||
OperationFinished<GVolume>(std::bind(g_volume_eject_with_operation_finish, _1, _2, _3), object, result);
|
||||
}
|
||||
|
||||
void GioLister::MountEjectFinished(GObject* object, GAsyncResult* result, gpointer) {
|
||||
void GioLister::MountEjectFinished(GObject *object, GAsyncResult *result, gpointer) {
|
||||
OperationFinished<GMount>(std::bind(g_mount_eject_with_operation_finish, _1, _2, _3), object, result);
|
||||
}
|
||||
|
||||
void GioLister::MountUnmountFinished(GObject* object, GAsyncResult* result, gpointer) {
|
||||
void GioLister::MountUnmountFinished(GObject *object, GAsyncResult *result, gpointer) {
|
||||
OperationFinished<GMount>(std::bind(g_mount_unmount_with_operation_finish, _1, _2, _3), object, result);
|
||||
}
|
||||
|
||||
void GioLister::UnmountDevice(const QString& id) {
|
||||
void GioLister::UnmountDevice(const QString &id) {
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return;
|
||||
|
||||
const DeviceInfo& info = devices_[id];
|
||||
const DeviceInfo &info = devices_[id];
|
||||
|
||||
if (!info.mount) return;
|
||||
|
||||
@@ -519,18 +514,18 @@ void GioLister::UnmountDevice(const QString& id) {
|
||||
|
||||
}
|
||||
|
||||
void GioLister::UpdateDeviceFreeSpace(const QString& id) {
|
||||
void GioLister::UpdateDeviceFreeSpace(const QString &id) {
|
||||
|
||||
{
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) return;
|
||||
|
||||
DeviceInfo& device_info = devices_[id];
|
||||
DeviceInfo &device_info = devices_[id];
|
||||
|
||||
GFile* root = g_mount_get_root(device_info.mount);
|
||||
GFile *root = g_mount_get_root(device_info.mount);
|
||||
|
||||
GError* error = nullptr;
|
||||
GFileInfo* info = g_file_query_filesystem_info(root, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, nullptr, &error);
|
||||
GError *error = nullptr;
|
||||
GFileInfo *info = g_file_query_filesystem_info(root, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, nullptr, &error);
|
||||
if (error) {
|
||||
qLog(Warning) << error->message;
|
||||
g_error_free(error);
|
||||
@@ -547,18 +542,18 @@ void GioLister::UpdateDeviceFreeSpace(const QString& id) {
|
||||
|
||||
}
|
||||
|
||||
bool GioLister::DeviceNeedsMount(const QString& id) {
|
||||
bool GioLister::DeviceNeedsMount(const QString &id) {
|
||||
QMutexLocker l(&mutex_);
|
||||
return devices_.contains(id) && !devices_[id].mount;
|
||||
}
|
||||
|
||||
int GioLister::MountDevice(const QString& id) {
|
||||
int GioLister::MountDevice(const QString &id) {
|
||||
const int request_id = next_mount_request_id_++;
|
||||
metaObject()->invokeMethod(this, "DoMountDevice", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(int, request_id));
|
||||
return request_id;
|
||||
}
|
||||
|
||||
void GioLister::DoMountDevice(const QString& id, int request_id) {
|
||||
void GioLister::DoMountDevice(const QString &id, int request_id) {
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
if (!devices_.contains(id)) {
|
||||
@@ -566,7 +561,7 @@ void GioLister::DoMountDevice(const QString& id, int request_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const DeviceInfo& info = devices_[id];
|
||||
const DeviceInfo &info = devices_[id];
|
||||
if (info.mount) {
|
||||
// Already mounted
|
||||
emit DeviceMounted(id, request_id, true);
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "mtpconnection.h"
|
||||
#include "core/song.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "core/logging.h"
|
||||
|
||||
#include "collection/collectionbackend.h"
|
||||
|
||||
MtpLoader::MtpLoader(const QUrl &url, TaskManager *task_manager, CollectionBackend *backend, std::shared_ptr<ConnectedDevice> device)
|
||||
|
||||
@@ -112,9 +112,7 @@ void Udisks2Lister::UnmountDevice(const QString &id) {
|
||||
QReadLocker locker(&device_data_lock_);
|
||||
if (!device_data_.contains(id)) return;
|
||||
|
||||
OrgFreedesktopUDisks2FilesystemInterface filesystem(
|
||||
udisks2_service_, device_data_[id].dbus_path,
|
||||
QDBusConnection::systemBus());
|
||||
OrgFreedesktopUDisks2FilesystemInterface filesystem(udisks2_service_, device_data_[id].dbus_path, QDBusConnection::systemBus());
|
||||
|
||||
if (filesystem.isValid()) {
|
||||
auto unmount_result = filesystem.Unmount(QVariantMap());
|
||||
@@ -177,6 +175,7 @@ void Udisks2Lister::Init() {
|
||||
|
||||
connect(udisks2_interface_.get(), SIGNAL(InterfacesAdded(QDBusObjectPath, InterfacesAndProperties)), SLOT(DBusInterfaceAdded(QDBusObjectPath, InterfacesAndProperties)));
|
||||
connect(udisks2_interface_.get(), SIGNAL(InterfacesRemoved(QDBusObjectPath, QStringList)), SLOT(DBusInterfaceRemoved(QDBusObjectPath, QStringList)));
|
||||
|
||||
}
|
||||
|
||||
void Udisks2Lister::DBusInterfaceAdded(const QDBusObjectPath &path, const InterfacesAndProperties &interfaces) {
|
||||
@@ -223,12 +222,14 @@ void Udisks2Lister::DBusInterfaceRemoved(const QDBusObjectPath &path, const QStr
|
||||
}
|
||||
|
||||
bool Udisks2Lister::isPendingJob(const QDBusObjectPath &job_path) {
|
||||
|
||||
QMutexLocker locker(&jobs_lock_);
|
||||
|
||||
if (!mounting_jobs_.contains(job_path)) return false;
|
||||
|
||||
mounting_jobs_.remove(job_path);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void Udisks2Lister::RemoveDevice(const QDBusObjectPath &device_path) {
|
||||
@@ -281,6 +282,7 @@ void Udisks2Lister::JobCompleted(bool success, const QString &message) {
|
||||
|
||||
mounting_jobs_[jobPath].is_mount ? HandleFinishedMountJob(partition_data) : HandleFinishedUnmountJob(partition_data, mounted_object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Udisks2Lister::HandleFinishedMountJob(const Udisks2Lister::PartitionData &partition_data) {
|
||||
@@ -306,8 +308,7 @@ void Udisks2Lister::HandleFinishedUnmountJob(const Udisks2Lister::PartitionData
|
||||
}
|
||||
|
||||
if (!id.isEmpty()) {
|
||||
qLog(Debug) << "Partition " << partition_data.dbus_path
|
||||
<< " has no more mount points, removing it from device list";
|
||||
qLog(Debug) << "Partition " << partition_data.dbus_path << " has no more mount points, removing it from device list";
|
||||
device_data_.remove(id);
|
||||
DeviceRemoved(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user