DeviceManager: Rename variables
This commit is contained in:
@@ -167,12 +167,12 @@ void DeviceManager::Exit() {
|
|||||||
|
|
||||||
void DeviceManager::CloseDevices() {
|
void DeviceManager::CloseDevices() {
|
||||||
|
|
||||||
for (DeviceInfo *info : std::as_const(devices_)) {
|
for (DeviceInfo *device_info : std::as_const(devices_)) {
|
||||||
if (!info->device_) continue;
|
if (!device_info->device_) continue;
|
||||||
if (wait_for_exit_.contains(&*info->device_)) continue;
|
if (wait_for_exit_.contains(&*device_info->device_)) continue;
|
||||||
wait_for_exit_ << &*info->device_;
|
wait_for_exit_ << &*device_info->device_;
|
||||||
QObject::connect(&*info->device_, &ConnectedDevice::destroyed, this, &DeviceManager::DeviceDestroyed);
|
QObject::connect(&*device_info->device_, &ConnectedDevice::destroyed, this, &DeviceManager::DeviceDestroyed);
|
||||||
info->device_->Close();
|
device_info->device_->Close();
|
||||||
}
|
}
|
||||||
if (wait_for_exit_.isEmpty()) CloseListers();
|
if (wait_for_exit_.isEmpty()) CloseListers();
|
||||||
|
|
||||||
@@ -224,10 +224,10 @@ void DeviceManager::ListerClosed() {
|
|||||||
|
|
||||||
void DeviceManager::DeviceDestroyed() {
|
void DeviceManager::DeviceDestroyed() {
|
||||||
|
|
||||||
ConnectedDevice *device = static_cast<ConnectedDevice*>(sender());
|
ConnectedDevice *connected_device = static_cast<ConnectedDevice*>(sender());
|
||||||
if (!wait_for_exit_.contains(device) || !backend_) return;
|
if (!wait_for_exit_.contains(connected_device) || !backend_) return;
|
||||||
|
|
||||||
wait_for_exit_.removeAll(device);
|
wait_for_exit_.removeAll(connected_device);
|
||||||
if (wait_for_exit_.isEmpty()) CloseListers();
|
if (wait_for_exit_.isEmpty()) CloseListers();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -238,9 +238,9 @@ void DeviceManager::LoadAllDevices() {
|
|||||||
|
|
||||||
const DeviceDatabaseBackend::DeviceList devices = backend_->GetAllDevices();
|
const DeviceDatabaseBackend::DeviceList devices = backend_->GetAllDevices();
|
||||||
for (const DeviceDatabaseBackend::Device &device : devices) {
|
for (const DeviceDatabaseBackend::Device &device : devices) {
|
||||||
DeviceInfo *info = new DeviceInfo(DeviceInfo::Type::Device, root_);
|
DeviceInfo *device_info = new DeviceInfo(DeviceInfo::Type::Device, root_);
|
||||||
info->InitFromDb(device);
|
device_info->InitFromDb(device);
|
||||||
Q_EMIT DeviceCreatedFromDB(info);
|
Q_EMIT DeviceCreatedFromDB(device_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is done in a concurrent thread so close the unique DB connection.
|
// This is done in a concurrent thread so close the unique DB connection.
|
||||||
@@ -248,29 +248,29 @@ void DeviceManager::LoadAllDevices() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::AddDeviceFromDB(DeviceInfo *info) {
|
void DeviceManager::AddDeviceFromDB(DeviceInfo *device_info) {
|
||||||
|
|
||||||
const QStringList icon_names = info->icon_name_.split(u',');
|
const QStringList icon_names = device_info->icon_name_.split(u',');
|
||||||
QVariantList icons;
|
QVariantList icons;
|
||||||
icons.reserve(icon_names.count());
|
icons.reserve(icon_names.count());
|
||||||
for (const QString &icon_name : icon_names) {
|
for (const QString &icon_name : icon_names) {
|
||||||
icons << icon_name;
|
icons << icon_name;
|
||||||
}
|
}
|
||||||
info->SetIcon(icons, info->friendly_name_);
|
device_info->SetIcon(icons, device_info->friendly_name_);
|
||||||
|
|
||||||
DeviceInfo *existing = FindEquivalentDevice(info);
|
DeviceInfo *existing = FindEquivalentDevice(device_info);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
qLog(Info) << "Found existing device: " << info->friendly_name_;
|
qLog(Info) << "Found existing device: " << device_info->friendly_name_;
|
||||||
existing->icon_name_ = info->icon_name_;
|
existing->icon_name_ = device_info->icon_name_;
|
||||||
existing->icon_ = info->icon_;
|
existing->icon_ = device_info->icon_;
|
||||||
QModelIndex idx = ItemToIndex(existing);
|
QModelIndex idx = ItemToIndex(existing);
|
||||||
if (idx.isValid()) Q_EMIT dataChanged(idx, idx);
|
if (idx.isValid()) Q_EMIT dataChanged(idx, idx);
|
||||||
root_->Delete(info->row);
|
root_->Delete(device_info->row);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Info) << "Device added from database: " << info->friendly_name_;
|
qLog(Info) << "Device added from database: " << device_info->friendly_name_;
|
||||||
beginInsertRows(ItemToIndex(root_), static_cast<int>(devices_.count()), static_cast<int>(devices_.count()));
|
beginInsertRows(ItemToIndex(root_), static_cast<int>(devices_.count()), static_cast<int>(devices_.count()));
|
||||||
devices_ << info;
|
devices_ << device_info;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,29 +280,29 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
|
|||||||
|
|
||||||
if (!idx.isValid() || idx.column() != 0) return QVariant();
|
if (!idx.isValid() || idx.column() != 0) return QVariant();
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info) return QVariant();
|
if (!device_info) return QVariant();
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:{
|
case Qt::DisplayRole:{
|
||||||
QString text;
|
QString text;
|
||||||
if (!info->friendly_name_.isEmpty()) {
|
if (!device_info->friendly_name_.isEmpty()) {
|
||||||
text = info->friendly_name_;
|
text = device_info->friendly_name_;
|
||||||
}
|
}
|
||||||
else if (info->BestBackend()) {
|
else if (device_info->BestBackend()) {
|
||||||
text = info->BestBackend()->unique_id_;
|
text = device_info->BestBackend()->unique_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->size_ > 0) {
|
if (device_info->size_ > 0) {
|
||||||
text = text + QStringLiteral(" (%1)").arg(Utilities::PrettySize(info->size_));
|
text = text + QStringLiteral(" (%1)").arg(Utilities::PrettySize(device_info->size_));
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Qt::DecorationRole:{
|
case Qt::DecorationRole:{
|
||||||
QPixmap pixmap = info->icon_.pixmap(kDeviceIconSize);
|
QPixmap pixmap = device_info->icon_.pixmap(kDeviceIconSize);
|
||||||
|
|
||||||
if (info->backends_.isEmpty() || !info->BestBackend() || !info->BestBackend()->lister_) {
|
if (device_info->backends_.isEmpty() || !device_info->BestBackend() || !device_info->BestBackend()->lister_) {
|
||||||
// Disconnected but remembered
|
// Disconnected but remembered
|
||||||
QPainter p(&pixmap);
|
QPainter p(&pixmap);
|
||||||
p.drawPixmap(kDeviceIconSize - kDeviceIconOverlaySize, kDeviceIconSize - kDeviceIconOverlaySize, not_connected_overlay_.pixmap(kDeviceIconOverlaySize));
|
p.drawPixmap(kDeviceIconSize - kDeviceIconOverlaySize, kDeviceIconSize - kDeviceIconOverlaySize, not_connected_overlay_.pixmap(kDeviceIconOverlaySize));
|
||||||
@@ -312,62 +312,62 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Role_FriendlyName:
|
case Role_FriendlyName:
|
||||||
return info->friendly_name_;
|
return device_info->friendly_name_;
|
||||||
|
|
||||||
case Role_UniqueId:
|
case Role_UniqueId:
|
||||||
if (!info->BestBackend()) return QString();
|
if (!device_info->BestBackend()) return QString();
|
||||||
return info->BestBackend()->unique_id_;
|
return device_info->BestBackend()->unique_id_;
|
||||||
|
|
||||||
case Role_IconName:
|
case Role_IconName:
|
||||||
return info->icon_name_;
|
return device_info->icon_name_;
|
||||||
|
|
||||||
case Role_Capacity:
|
case Role_Capacity:
|
||||||
case MusicStorage::Role_Capacity:
|
case MusicStorage::Role_Capacity:
|
||||||
return info->size_;
|
return device_info->size_;
|
||||||
|
|
||||||
case Role_FreeSpace:
|
case Role_FreeSpace:
|
||||||
case MusicStorage::Role_FreeSpace:
|
case MusicStorage::Role_FreeSpace:
|
||||||
return ((info->BestBackend() && info->BestBackend()->lister_) ? info->BestBackend()->lister_->DeviceFreeSpace(info->BestBackend()->unique_id_) : QVariant());
|
return ((device_info->BestBackend() && device_info->BestBackend()->lister_) ? device_info->BestBackend()->lister_->DeviceFreeSpace(device_info->BestBackend()->unique_id_) : QVariant());
|
||||||
|
|
||||||
case Role_State:
|
case Role_State:
|
||||||
if (info->device_) return State_Connected;
|
if (device_info->device_) return State_Connected;
|
||||||
if (info->BestBackend() && info->BestBackend()->lister_) {
|
if (device_info->BestBackend() && device_info->BestBackend()->lister_) {
|
||||||
if (info->BestBackend()->lister_->DeviceNeedsMount(info->BestBackend()->unique_id_)) return State_NotMounted;
|
if (device_info->BestBackend()->lister_->DeviceNeedsMount(device_info->BestBackend()->unique_id_)) return State_NotMounted;
|
||||||
return State_NotConnected;
|
return State_NotConnected;
|
||||||
}
|
}
|
||||||
return State_Remembered;
|
return State_Remembered;
|
||||||
|
|
||||||
case Role_UpdatingPercentage:
|
case Role_UpdatingPercentage:
|
||||||
if (info->task_percentage_ == -1) return QVariant();
|
if (device_info->task_percentage_ == -1) return QVariant();
|
||||||
return info->task_percentage_;
|
return device_info->task_percentage_;
|
||||||
|
|
||||||
case MusicStorage::Role_Storage:
|
case MusicStorage::Role_Storage:
|
||||||
if (!info->device_ && info->database_id_ != -1) {
|
if (!device_info->device_ && device_info->database_id_ != -1) {
|
||||||
const_cast<DeviceManager*>(this)->Connect(info);
|
const_cast<DeviceManager*>(this)->Connect(device_info);
|
||||||
}
|
}
|
||||||
if (!info->device_) return QVariant();
|
if (!device_info->device_) return QVariant();
|
||||||
return QVariant::fromValue<SharedPtr<MusicStorage>>(info->device_);
|
return QVariant::fromValue<SharedPtr<MusicStorage>>(device_info->device_);
|
||||||
|
|
||||||
case MusicStorage::Role_StorageForceConnect:
|
case MusicStorage::Role_StorageForceConnect:
|
||||||
if (!info->BestBackend()) return QVariant();
|
if (!device_info->BestBackend()) return QVariant();
|
||||||
if (!info->device_) {
|
if (!device_info->device_) {
|
||||||
if (info->database_id_ == -1 && !info->BestBackend()->lister_->DeviceNeedsMount(info->BestBackend()->unique_id_)) {
|
if (device_info->database_id_ == -1 && !device_info->BestBackend()->lister_->DeviceNeedsMount(device_info->BestBackend()->unique_id_)) {
|
||||||
if (info->BestBackend()->lister_->AskForScan(info->BestBackend()->unique_id_)) {
|
if (device_info->BestBackend()->lister_->AskForScan(device_info->BestBackend()->unique_id_)) {
|
||||||
ScopedPtr<QMessageBox> dialog(new QMessageBox(QMessageBox::Information, tr("Connect device"), tr("This is the first time you have connected this device. Strawberry will now scan the device to find music files - this may take some time."), QMessageBox::Cancel));
|
ScopedPtr<QMessageBox> dialog(new QMessageBox(QMessageBox::Information, tr("Connect device"), tr("This is the first time you have connected this device. Strawberry will now scan the device to find music files - this may take some time."), QMessageBox::Cancel));
|
||||||
QPushButton *pushbutton = dialog->addButton(tr("Connect device"), QMessageBox::AcceptRole);
|
QPushButton *pushbutton = dialog->addButton(tr("Connect device"), QMessageBox::AcceptRole);
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
if (dialog->clickedButton() != pushbutton) return QVariant();
|
if (dialog->clickedButton() != pushbutton) return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const_cast<DeviceManager*>(this)->Connect(info);
|
const_cast<DeviceManager*>(this)->Connect(device_info);
|
||||||
}
|
}
|
||||||
if (!info->device_) return QVariant();
|
if (!device_info->device_) return QVariant();
|
||||||
return QVariant::fromValue<SharedPtr<MusicStorage>>(info->device_);
|
return QVariant::fromValue<SharedPtr<MusicStorage>>(device_info->device_);
|
||||||
|
|
||||||
case Role_MountPath:{
|
case Role_MountPath:{
|
||||||
if (!info->device_) return QVariant();
|
if (!device_info->device_) return QVariant();
|
||||||
|
|
||||||
QString ret = info->device_->url().path();
|
QString ret = device_info->device_->url().path();
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
if (ret.startsWith(u'/')) ret.remove(0, 1);
|
if (ret.startsWith(u'/')) ret.remove(0, 1);
|
||||||
#endif
|
#endif
|
||||||
@@ -375,17 +375,17 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Role_TranscodeMode:
|
case Role_TranscodeMode:
|
||||||
return static_cast<int>(info->transcode_mode_);
|
return static_cast<int>(device_info->transcode_mode_);
|
||||||
|
|
||||||
case Role_TranscodeFormat:
|
case Role_TranscodeFormat:
|
||||||
return static_cast<int>(info->transcode_format_);
|
return static_cast<int>(device_info->transcode_format_);
|
||||||
|
|
||||||
case Role_SongCount:
|
case Role_SongCount:
|
||||||
if (!info->device_) return QVariant();
|
if (!device_info->device_) return QVariant();
|
||||||
return info->device_->song_count();
|
return device_info->device_->song_count();
|
||||||
|
|
||||||
case Role_CopyMusic:
|
case Role_CopyMusic:
|
||||||
if (info->BestBackend() && info->BestBackend()->lister_) return info->BestBackend()->lister_->CopyMusic();
|
if (device_info->BestBackend() && device_info->BestBackend()->lister_) return device_info->BestBackend()->lister_->CopyMusic();
|
||||||
else return false;
|
else return false;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -436,9 +436,9 @@ DeviceInfo *DeviceManager::FindDeviceByUrl(const QList<QUrl> &urls) const {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceInfo *DeviceManager::FindEquivalentDevice(DeviceInfo *info) const {
|
DeviceInfo *DeviceManager::FindEquivalentDevice(DeviceInfo *device_info) const {
|
||||||
|
|
||||||
for (const DeviceInfo::Backend &backend : std::as_const(info->backends_)) {
|
for (const DeviceInfo::Backend &backend : std::as_const(device_info->backends_)) {
|
||||||
DeviceInfo *match = FindDeviceById(backend.unique_id_);
|
DeviceInfo *match = FindDeviceById(backend.unique_id_);
|
||||||
if (match) return match;
|
if (match) return match;
|
||||||
}
|
}
|
||||||
@@ -454,42 +454,42 @@ void DeviceManager::PhysicalDeviceAdded(const QString &id) {
|
|||||||
qLog(Info) << "Device added:" << id << lister->DeviceUniqueIDs();
|
qLog(Info) << "Device added:" << id << lister->DeviceUniqueIDs();
|
||||||
|
|
||||||
// Do we have this device already?
|
// Do we have this device already?
|
||||||
DeviceInfo *info = FindDeviceById(id);
|
DeviceInfo *device_info = FindDeviceById(id);
|
||||||
if (info) {
|
if (device_info) {
|
||||||
for (int backend_index = 0; backend_index < info->backends_.count(); ++backend_index) {
|
for (int backend_index = 0; backend_index < device_info->backends_.count(); ++backend_index) {
|
||||||
if (info->backends_[backend_index].unique_id_ == id) {
|
if (device_info->backends_[backend_index].unique_id_ == id) {
|
||||||
info->backends_[backend_index].lister_ = lister;
|
device_info->backends_[backend_index].lister_ = lister;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QModelIndex idx = ItemToIndex(info);
|
QModelIndex idx = ItemToIndex(device_info);
|
||||||
if (idx.isValid()) Q_EMIT dataChanged(idx, idx);
|
if (idx.isValid()) Q_EMIT dataChanged(idx, idx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Check if we have another device with the same URL
|
// Check if we have another device with the same URL
|
||||||
info = FindDeviceByUrl(lister->MakeDeviceUrls(id));
|
device_info = FindDeviceByUrl(lister->MakeDeviceUrls(id));
|
||||||
if (info) {
|
if (device_info) {
|
||||||
// Add this device's lister to the existing device
|
// Add this device's lister to the existing device
|
||||||
info->backends_ << DeviceInfo::Backend(lister, id);
|
device_info->backends_ << DeviceInfo::Backend(lister, id);
|
||||||
|
|
||||||
// If the user hasn't saved the device in the DB yet then overwrite the device's name and icon etc.
|
// If the user hasn't saved the device in the DB yet then overwrite the device's name and icon etc.
|
||||||
if (info->database_id_ == -1 && info->BestBackend() && info->BestBackend()->lister_ == lister) {
|
if (device_info->database_id_ == -1 && device_info->BestBackend() && device_info->BestBackend()->lister_ == lister) {
|
||||||
info->friendly_name_ = lister->MakeFriendlyName(id);
|
device_info->friendly_name_ = lister->MakeFriendlyName(id);
|
||||||
info->size_ = lister->DeviceCapacity(id);
|
device_info->size_ = lister->DeviceCapacity(id);
|
||||||
info->SetIcon(lister->DeviceIcons(id), info->friendly_name_);
|
device_info->SetIcon(lister->DeviceIcons(id), device_info->friendly_name_);
|
||||||
}
|
}
|
||||||
QModelIndex idx = ItemToIndex(info);
|
QModelIndex idx = ItemToIndex(device_info);
|
||||||
if (idx.isValid()) Q_EMIT dataChanged(idx, idx);
|
if (idx.isValid()) Q_EMIT dataChanged(idx, idx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// It's a completely new device
|
// It's a completely new device
|
||||||
info = new DeviceInfo(DeviceInfo::Type::Device, root_);
|
device_info = new DeviceInfo(DeviceInfo::Type::Device, root_);
|
||||||
info->backends_ << DeviceInfo::Backend(lister, id);
|
device_info->backends_ << DeviceInfo::Backend(lister, id);
|
||||||
info->friendly_name_ = lister->MakeFriendlyName(id);
|
device_info->friendly_name_ = lister->MakeFriendlyName(id);
|
||||||
info->size_ = lister->DeviceCapacity(id);
|
device_info->size_ = lister->DeviceCapacity(id);
|
||||||
info->SetIcon(lister->DeviceIcons(id), info->friendly_name_);
|
device_info->SetIcon(lister->DeviceIcons(id), device_info->friendly_name_);
|
||||||
beginInsertRows(ItemToIndex(root_), static_cast<int>(devices_.count()), static_cast<int>(devices_.count()));
|
beginInsertRows(ItemToIndex(root_), static_cast<int>(devices_.count()), static_cast<int>(devices_.count()));
|
||||||
devices_ << info;
|
devices_ << device_info;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,42 +502,42 @@ void DeviceManager::PhysicalDeviceRemoved(const QString &id) {
|
|||||||
|
|
||||||
qLog(Info) << "Device removed:" << id;
|
qLog(Info) << "Device removed:" << id;
|
||||||
|
|
||||||
DeviceInfo *info = FindDeviceById(id);
|
DeviceInfo *device_info = FindDeviceById(id);
|
||||||
if (!info) return;
|
if (!device_info) return;
|
||||||
|
|
||||||
QModelIndex idx = ItemToIndex(info);
|
QModelIndex idx = ItemToIndex(device_info);
|
||||||
if (!idx.isValid()) return;
|
if (!idx.isValid()) return;
|
||||||
|
|
||||||
if (info->database_id_ != -1) {
|
if (device_info->database_id_ != -1) {
|
||||||
// Keep the structure around, but just "disconnect" it
|
// Keep the structure around, but just "disconnect" it
|
||||||
for (int backend_index = 0; backend_index < info->backends_.count(); ++backend_index) {
|
for (int backend_index = 0; backend_index < device_info->backends_.count(); ++backend_index) {
|
||||||
if (info->backends_[backend_index].unique_id_ == id) {
|
if (device_info->backends_[backend_index].unique_id_ == id) {
|
||||||
info->backends_[backend_index].lister_ = nullptr;
|
device_info->backends_[backend_index].lister_ = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->device_ && info->device_->lister() == lister) {
|
if (device_info->device_ && device_info->device_->lister() == lister) {
|
||||||
info->device_->Close();
|
device_info->device_->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!info->device_) Q_EMIT DeviceDisconnected(idx);
|
if (!device_info->device_) Q_EMIT DeviceDisconnected(idx);
|
||||||
|
|
||||||
Q_EMIT dataChanged(idx, idx);
|
Q_EMIT dataChanged(idx, idx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If this was the last lister for the device then remove it from the model
|
// If this was the last lister for the device then remove it from the model
|
||||||
for (int backend_index = 0; backend_index < info->backends_.count(); ++backend_index) {
|
for (int backend_index = 0; backend_index < device_info->backends_.count(); ++backend_index) {
|
||||||
if (info->backends_[backend_index].unique_id_ == id) {
|
if (device_info->backends_[backend_index].unique_id_ == id) {
|
||||||
info->backends_.removeAt(backend_index);
|
device_info->backends_.removeAt(backend_index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->backends_.isEmpty()) {
|
if (device_info->backends_.isEmpty()) {
|
||||||
beginRemoveRows(ItemToIndex(root_), idx.row(), idx.row());
|
beginRemoveRows(ItemToIndex(root_), idx.row(), idx.row());
|
||||||
devices_.removeAll(info);
|
devices_.removeAll(device_info);
|
||||||
root_->Delete(info->row);
|
root_->Delete(device_info->row);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -549,8 +549,8 @@ void DeviceManager::PhysicalDeviceChanged(const QString &id) {
|
|||||||
DeviceLister *lister = qobject_cast<DeviceLister*>(sender());
|
DeviceLister *lister = qobject_cast<DeviceLister*>(sender());
|
||||||
Q_UNUSED(lister);
|
Q_UNUSED(lister);
|
||||||
|
|
||||||
DeviceInfo *info = FindDeviceById(id);
|
DeviceInfo *device_info = FindDeviceById(id);
|
||||||
if (!info) return;
|
if (!device_info) return;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
@@ -560,40 +560,40 @@ SharedPtr<ConnectedDevice> DeviceManager::Connect(const QModelIndex &idx) {
|
|||||||
|
|
||||||
SharedPtr<ConnectedDevice> ret;
|
SharedPtr<ConnectedDevice> ret;
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info) return ret;
|
if (!device_info) return ret;
|
||||||
|
|
||||||
return Connect(info);
|
return Connect(device_info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
|
SharedPtr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *device_info) {
|
||||||
|
|
||||||
SharedPtr<ConnectedDevice> ret;
|
SharedPtr<ConnectedDevice> connected_device;
|
||||||
|
|
||||||
if (!info) return ret;
|
if (!device_info) return connected_device;
|
||||||
if (info->device_) { // Already connected
|
if (device_info->device_) { // Already connected
|
||||||
return info->device_;
|
return device_info->device_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!info->BestBackend() || !info->BestBackend()->lister_) { // Not physically connected
|
if (!device_info->BestBackend() || !device_info->BestBackend()->lister_) { // Not physically connected
|
||||||
return ret;
|
return connected_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->BestBackend()->lister_->DeviceNeedsMount(info->BestBackend()->unique_id_)) { // Mount the device
|
if (device_info->BestBackend()->lister_->DeviceNeedsMount(device_info->BestBackend()->unique_id_)) { // Mount the device
|
||||||
info->BestBackend()->lister_->MountDeviceAsync(info->BestBackend()->unique_id_);
|
device_info->BestBackend()->lister_->MountDeviceAsync(device_info->BestBackend()->unique_id_);
|
||||||
return ret;
|
return connected_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool first_time = (info->database_id_ == -1);
|
bool first_time = (device_info->database_id_ == -1);
|
||||||
if (first_time) {
|
if (first_time) {
|
||||||
// We haven't stored this device in the database before
|
// We haven't stored this device in the database before
|
||||||
info->database_id_ = backend_->AddDevice(info->SaveToDb());
|
device_info->database_id_ = backend_->AddDevice(device_info->SaveToDb());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the device URLs
|
// Get the device URLs
|
||||||
const QList<QUrl> urls = info->BestBackend()->lister_->MakeDeviceUrls(info->BestBackend()->unique_id_);
|
const QList<QUrl> urls = device_info->BestBackend()->lister_->MakeDeviceUrls(device_info->BestBackend()->unique_id_);
|
||||||
if (urls.isEmpty()) return ret;
|
if (urls.isEmpty()) return connected_device;
|
||||||
|
|
||||||
// Take the first URL that we have a handler for
|
// Take the first URL that we have a handler for
|
||||||
QUrl device_url;
|
QUrl device_url;
|
||||||
@@ -613,7 +613,7 @@ SharedPtr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
|
|||||||
tr("This is an MTP device, but you compiled Strawberry without libmtp support.") + u" "_s +
|
tr("This is an MTP device, but you compiled Strawberry without libmtp support.") + u" "_s +
|
||||||
tr("If you continue, this device will work slowly and songs copied to it may not work."),
|
tr("If you continue, this device will work slowly and songs copied to it may not work."),
|
||||||
QMessageBox::Abort, QMessageBox::Ignore) == QMessageBox::Abort)
|
QMessageBox::Abort, QMessageBox::Ignore) == QMessageBox::Abort)
|
||||||
return ret;
|
return connected_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.scheme() == "ipod"_L1) {
|
if (url.scheme() == "ipod"_L1) {
|
||||||
@@ -621,7 +621,7 @@ SharedPtr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
|
|||||||
tr("This is an iPod, but you compiled Strawberry without libgpod support.") + " "_L1 +
|
tr("This is an iPod, but you compiled Strawberry without libgpod support.") + " "_L1 +
|
||||||
tr("If you continue, this device will work slowly and songs copied to it may not work."),
|
tr("If you continue, this device will work slowly and songs copied to it may not work."),
|
||||||
QMessageBox::Abort, QMessageBox::Ignore) == QMessageBox::Abort)
|
QMessageBox::Abort, QMessageBox::Ignore) == QMessageBox::Abort)
|
||||||
return ret;
|
return connected_device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,114 +634,114 @@ SharedPtr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT DeviceError(tr("This type of device is not supported: %1").arg(url_strings.join(", "_L1)));
|
Q_EMIT DeviceError(tr("This type of device is not supported: %1").arg(url_strings.join(", "_L1)));
|
||||||
return ret;
|
return connected_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMetaObject meta_object = device_classes_.value(device_url.scheme());
|
QMetaObject meta_object = device_classes_.value(device_url.scheme());
|
||||||
QObject *instance = meta_object.newInstance(
|
QObject *instance = meta_object.newInstance(
|
||||||
Q_ARG(QUrl, device_url),
|
Q_ARG(QUrl, device_url),
|
||||||
Q_ARG(DeviceLister*, info->BestBackend()->lister_),
|
Q_ARG(DeviceLister*, device_info->BestBackend()->lister_),
|
||||||
Q_ARG(QString, info->BestBackend()->unique_id_),
|
Q_ARG(QString, device_info->BestBackend()->unique_id_),
|
||||||
Q_ARG(DeviceManager*, this),
|
Q_ARG(DeviceManager*, this),
|
||||||
Q_ARG(SharedPtr<TaskManager>, task_manager_),
|
Q_ARG(SharedPtr<TaskManager>, task_manager_),
|
||||||
Q_ARG(SharedPtr<Database>, database_),
|
Q_ARG(SharedPtr<Database>, database_),
|
||||||
Q_ARG(SharedPtr<TagReaderClient>, tagreader_client_),
|
Q_ARG(SharedPtr<TagReaderClient>, tagreader_client_),
|
||||||
Q_ARG(SharedPtr<AlbumCoverLoader>, albumcover_loader_),
|
Q_ARG(SharedPtr<AlbumCoverLoader>, albumcover_loader_),
|
||||||
Q_ARG(int, info->database_id_),
|
Q_ARG(int, device_info->database_id_),
|
||||||
Q_ARG(bool, first_time));
|
Q_ARG(bool, first_time));
|
||||||
|
|
||||||
ret.reset(qobject_cast<ConnectedDevice*>(instance));
|
connected_device.reset(qobject_cast<ConnectedDevice*>(instance));
|
||||||
|
|
||||||
if (!ret) {
|
if (!connected_device) {
|
||||||
qLog(Warning) << "Could not create device for" << device_url.toString();
|
qLog(Warning) << "Could not create device for" << device_url.toString();
|
||||||
return ret;
|
return connected_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = ret->Init();
|
bool result = connected_device->Init();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
qLog(Warning) << "Could not connect to device" << device_url.toString();
|
qLog(Warning) << "Could not connect to device" << device_url.toString();
|
||||||
return ret;
|
return connected_device;
|
||||||
}
|
}
|
||||||
info->device_ = ret;
|
device_info->device_ = connected_device;
|
||||||
|
|
||||||
QModelIndex idx = ItemToIndex(info);
|
QModelIndex idx = ItemToIndex(device_info);
|
||||||
if (!idx.isValid()) return ret;
|
if (!idx.isValid()) return connected_device;
|
||||||
|
|
||||||
Q_EMIT dataChanged(idx, idx);
|
Q_EMIT dataChanged(idx, idx);
|
||||||
|
|
||||||
QObject::connect(&*info->device_, &ConnectedDevice::TaskStarted, this, &DeviceManager::DeviceTaskStarted);
|
QObject::connect(&*device_info->device_, &ConnectedDevice::TaskStarted, this, &DeviceManager::DeviceTaskStarted);
|
||||||
QObject::connect(&*info->device_, &ConnectedDevice::SongCountUpdated, this, &DeviceManager::DeviceSongCountUpdated);
|
QObject::connect(&*device_info->device_, &ConnectedDevice::SongCountUpdated, this, &DeviceManager::DeviceSongCountUpdated);
|
||||||
QObject::connect(&*info->device_, &ConnectedDevice::DeviceConnectFinished, this, &DeviceManager::DeviceConnectFinished);
|
QObject::connect(&*device_info->device_, &ConnectedDevice::DeviceConnectFinished, this, &DeviceManager::DeviceConnectFinished);
|
||||||
QObject::connect(&*info->device_, &ConnectedDevice::DeviceCloseFinished, this, &DeviceManager::DeviceCloseFinished);
|
QObject::connect(&*device_info->device_, &ConnectedDevice::DeviceCloseFinished, this, &DeviceManager::DeviceCloseFinished);
|
||||||
QObject::connect(&*info->device_, &ConnectedDevice::Error, this, &DeviceManager::DeviceError);
|
QObject::connect(&*device_info->device_, &ConnectedDevice::Error, this, &DeviceManager::DeviceError);
|
||||||
|
|
||||||
ret->ConnectAsync();
|
connected_device->ConnectAsync();
|
||||||
|
|
||||||
return ret;
|
return connected_device;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::DeviceConnectFinished(const QString &id, const bool success) {
|
void DeviceManager::DeviceConnectFinished(const QString &id, const bool success) {
|
||||||
|
|
||||||
DeviceInfo *info = FindDeviceById(id);
|
DeviceInfo *device_info = FindDeviceById(id);
|
||||||
if (!info) return;
|
if (!device_info) return;
|
||||||
|
|
||||||
QModelIndex idx = ItemToIndex(info);
|
QModelIndex idx = ItemToIndex(device_info);
|
||||||
if (!idx.isValid()) return;
|
if (!idx.isValid()) return;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
Q_EMIT DeviceConnected(idx);
|
Q_EMIT DeviceConnected(idx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info->device_->Close();
|
device_info->device_->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::DeviceCloseFinished(const QString &id) {
|
void DeviceManager::DeviceCloseFinished(const QString &id) {
|
||||||
|
|
||||||
DeviceInfo *info = FindDeviceById(id);
|
DeviceInfo *device_info = FindDeviceById(id);
|
||||||
if (!info) return;
|
if (!device_info) return;
|
||||||
|
|
||||||
info->device_.reset();
|
device_info->device_.reset();
|
||||||
|
|
||||||
QModelIndex idx = ItemToIndex(info);
|
QModelIndex idx = ItemToIndex(device_info);
|
||||||
if (!idx.isValid()) return;
|
if (!idx.isValid()) return;
|
||||||
|
|
||||||
Q_EMIT DeviceDisconnected(idx);
|
Q_EMIT DeviceDisconnected(idx);
|
||||||
Q_EMIT dataChanged(idx, idx);
|
Q_EMIT dataChanged(idx, idx);
|
||||||
|
|
||||||
if (info->unmount_ && info->BestBackend() && info->BestBackend()->lister_) {
|
if (device_info->unmount_ && device_info->BestBackend() && device_info->BestBackend()->lister_) {
|
||||||
info->BestBackend()->lister_->UnmountDeviceAsync(info->BestBackend()->unique_id_);
|
device_info->BestBackend()->lister_->UnmountDeviceAsync(device_info->BestBackend()->unique_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->forget_) {
|
if (device_info->forget_) {
|
||||||
RemoveFromDB(info, idx);
|
RemoveFromDB(device_info, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceInfo *DeviceManager::GetDevice(const QModelIndex &idx) const {
|
DeviceInfo *DeviceManager::GetDevice(const QModelIndex &idx) const {
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
return info;
|
return device_info;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<ConnectedDevice> DeviceManager::GetConnectedDevice(const QModelIndex &idx) const {
|
SharedPtr<ConnectedDevice> DeviceManager::GetConnectedDevice(const QModelIndex &idx) const {
|
||||||
|
|
||||||
SharedPtr<ConnectedDevice> ret;
|
SharedPtr<ConnectedDevice> connected_device;
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info) return ret;
|
if (!device_info) return connected_device;
|
||||||
return info->device_;
|
return device_info->device_;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<ConnectedDevice> DeviceManager::GetConnectedDevice(DeviceInfo *info) const {
|
SharedPtr<ConnectedDevice> DeviceManager::GetConnectedDevice(DeviceInfo *device_info) const {
|
||||||
|
|
||||||
SharedPtr<ConnectedDevice> ret;
|
SharedPtr<ConnectedDevice> connected_device;
|
||||||
if (!info) return ret;
|
if (!device_info) return connected_device;
|
||||||
return info->device_;
|
return device_info->device_;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,9 +749,9 @@ int DeviceManager::GetDatabaseId(const QModelIndex &idx) const {
|
|||||||
|
|
||||||
if (!idx.isValid()) return -1;
|
if (!idx.isValid()) return -1;
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info) return -1;
|
if (!device_info) return -1;
|
||||||
return info->database_id_;
|
return device_info->database_id_;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,17 +759,17 @@ DeviceLister *DeviceManager::GetLister(const QModelIndex &idx) const {
|
|||||||
|
|
||||||
if (!idx.isValid()) return nullptr;
|
if (!idx.isValid()) return nullptr;
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info || !info->BestBackend()) return nullptr;
|
if (!device_info || !device_info->BestBackend()) return nullptr;
|
||||||
return info->BestBackend()->lister_;
|
return device_info->BestBackend()->lister_;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::Disconnect(DeviceInfo *info, const QModelIndex &idx) {
|
void DeviceManager::Disconnect(DeviceInfo *device_info, const QModelIndex &idx) {
|
||||||
|
|
||||||
Q_UNUSED(idx);
|
Q_UNUSED(idx);
|
||||||
|
|
||||||
info->device_->Close();
|
device_info->device_->Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,37 +777,37 @@ void DeviceManager::Forget(const QModelIndex &idx) {
|
|||||||
|
|
||||||
if (!idx.isValid()) return;
|
if (!idx.isValid()) return;
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info) return;
|
if (!device_info) return;
|
||||||
|
|
||||||
if (info->database_id_ == -1) return;
|
if (device_info->database_id_ == -1) return;
|
||||||
|
|
||||||
if (info->device_) {
|
if (device_info->device_) {
|
||||||
info->forget_ = true;
|
device_info->forget_ = true;
|
||||||
Disconnect(info, idx);
|
Disconnect(device_info, idx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
RemoveFromDB(info, idx);
|
RemoveFromDB(device_info, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::RemoveFromDB(DeviceInfo *info, const QModelIndex &idx) {
|
void DeviceManager::RemoveFromDB(DeviceInfo *device_info, const QModelIndex &idx) {
|
||||||
|
|
||||||
backend_->RemoveDevice(info->database_id_);
|
backend_->RemoveDevice(device_info->database_id_);
|
||||||
info->database_id_ = -1;
|
device_info->database_id_ = -1;
|
||||||
|
|
||||||
if (!info->BestBackend() || !info->BestBackend()->lister_) { // It's not attached any more so remove it from the list
|
if (!device_info->BestBackend() || !device_info->BestBackend()->lister_) { // It's not attached any more so remove it from the list
|
||||||
beginRemoveRows(ItemToIndex(root_), idx.row(), idx.row());
|
beginRemoveRows(ItemToIndex(root_), idx.row(), idx.row());
|
||||||
devices_.removeAll(info);
|
devices_.removeAll(device_info);
|
||||||
root_->Delete(info->row);
|
root_->Delete(device_info->row);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
else { // It's still attached, set the name and icon back to what they were originally
|
else { // It's still attached, set the name and icon back to what they were originally
|
||||||
const QString id = info->BestBackend()->unique_id_;
|
const QString id = device_info->BestBackend()->unique_id_;
|
||||||
|
|
||||||
info->friendly_name_ = info->BestBackend()->lister_->MakeFriendlyName(id);
|
device_info->friendly_name_ = device_info->BestBackend()->lister_->MakeFriendlyName(id);
|
||||||
info->SetIcon(info->BestBackend()->lister_->DeviceIcons(id), info->friendly_name_);
|
device_info->SetIcon(device_info->BestBackend()->lister_->DeviceIcons(id), device_info->friendly_name_);
|
||||||
Q_EMIT dataChanged(idx, idx);
|
Q_EMIT dataChanged(idx, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -817,18 +817,18 @@ void DeviceManager::SetDeviceOptions(const QModelIndex &idx, const QString &frie
|
|||||||
|
|
||||||
if (!idx.isValid()) return;
|
if (!idx.isValid()) return;
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info) return;
|
if (!device_info) return;
|
||||||
|
|
||||||
info->friendly_name_ = friendly_name;
|
device_info->friendly_name_ = friendly_name;
|
||||||
info->SetIcon(QVariantList() << icon_name, friendly_name);
|
device_info->SetIcon(QVariantList() << icon_name, friendly_name);
|
||||||
info->transcode_mode_ = mode;
|
device_info->transcode_mode_ = mode;
|
||||||
info->transcode_format_ = format;
|
device_info->transcode_format_ = format;
|
||||||
|
|
||||||
Q_EMIT dataChanged(idx, idx);
|
Q_EMIT dataChanged(idx, idx);
|
||||||
|
|
||||||
if (info->database_id_ != -1) {
|
if (device_info->database_id_ != -1) {
|
||||||
backend_->SetDeviceOptions(info->database_id_, friendly_name, icon_name, mode, format);
|
backend_->SetDeviceOptions(device_info->database_id_, friendly_name, icon_name, mode, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -839,12 +839,12 @@ void DeviceManager::DeviceTaskStarted(const int id) {
|
|||||||
if (!device) return;
|
if (!device) return;
|
||||||
|
|
||||||
for (int i = 0; i < devices_.count(); ++i) {
|
for (int i = 0; i < devices_.count(); ++i) {
|
||||||
DeviceInfo *info = devices_.value(i);
|
DeviceInfo *device_info = devices_.value(i);
|
||||||
if (info->device_ && &*info->device_ == device) {
|
if (device_info->device_ && &*device_info->device_ == device) {
|
||||||
QModelIndex index = ItemToIndex(info);
|
QModelIndex index = ItemToIndex(device_info);
|
||||||
if (!index.isValid()) continue;
|
if (!index.isValid()) continue;
|
||||||
active_tasks_[id] = index;
|
active_tasks_[id] = index;
|
||||||
info->task_percentage_ = 0;
|
device_info->task_percentage_ = 0;
|
||||||
Q_EMIT dataChanged(index, index);
|
Q_EMIT dataChanged(index, index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -863,12 +863,12 @@ void DeviceManager::TasksChanged() {
|
|||||||
const QPersistentModelIndex idx = active_tasks_.value(task.id);
|
const QPersistentModelIndex idx = active_tasks_.value(task.id);
|
||||||
if (!idx.isValid()) continue;
|
if (!idx.isValid()) continue;
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (task.progress_max) {
|
if (task.progress_max) {
|
||||||
info->task_percentage_ = static_cast<int>(static_cast<float>(task.progress) / static_cast<float>(task.progress_max) * 100);
|
device_info->task_percentage_ = static_cast<int>(static_cast<float>(task.progress) / static_cast<float>(task.progress_max) * 100);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info->task_percentage_ = 0;
|
device_info->task_percentage_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT dataChanged(idx, idx);
|
Q_EMIT dataChanged(idx, idx);
|
||||||
@@ -880,10 +880,10 @@ void DeviceManager::TasksChanged() {
|
|||||||
|
|
||||||
if (!idx.isValid()) continue;
|
if (!idx.isValid()) continue;
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info) continue;
|
if (!device_info) continue;
|
||||||
|
|
||||||
info->task_percentage_ = -1;
|
device_info->task_percentage_ = -1;
|
||||||
Q_EMIT dataChanged(idx, idx);
|
Q_EMIT dataChanged(idx, idx);
|
||||||
|
|
||||||
active_tasks_.remove(active_tasks_.key(idx));
|
active_tasks_.remove(active_tasks_.key(idx));
|
||||||
@@ -899,17 +899,17 @@ void DeviceManager::Unmount(const QModelIndex &idx) {
|
|||||||
|
|
||||||
if (!idx.isValid()) return;
|
if (!idx.isValid()) return;
|
||||||
|
|
||||||
DeviceInfo *info = IndexToItem(idx);
|
DeviceInfo *device_info = IndexToItem(idx);
|
||||||
if (!info) return;
|
if (!device_info) return;
|
||||||
|
|
||||||
if (info->database_id_ != -1 && !info->device_) return;
|
if (device_info->database_id_ != -1 && !device_info->device_) return;
|
||||||
|
|
||||||
if (info->device_) {
|
if (device_info->device_) {
|
||||||
info->unmount_ = true;
|
device_info->unmount_ = true;
|
||||||
Disconnect(info, idx);
|
Disconnect(device_info, idx);
|
||||||
}
|
}
|
||||||
else if (info->BestBackend() && info->BestBackend()->lister_) {
|
else if (device_info->BestBackend() && device_info->BestBackend()->lister_) {
|
||||||
info->BestBackend()->lister_->UnmountDeviceAsync(info->BestBackend()->unique_id_);
|
device_info->BestBackend()->lister_->UnmountDeviceAsync(device_info->BestBackend()->unique_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -918,13 +918,13 @@ void DeviceManager::DeviceSongCountUpdated(const int count) {
|
|||||||
|
|
||||||
Q_UNUSED(count);
|
Q_UNUSED(count);
|
||||||
|
|
||||||
ConnectedDevice *device = qobject_cast<ConnectedDevice*>(sender());
|
ConnectedDevice *connected_device = qobject_cast<ConnectedDevice*>(sender());
|
||||||
if (!device) return;
|
if (!connected_device) return;
|
||||||
|
|
||||||
DeviceInfo *info = FindDeviceById(device->unique_id());
|
DeviceInfo *device_info = FindDeviceById(connected_device->unique_id());
|
||||||
if (!info) return;
|
if (!device_info) return;
|
||||||
|
|
||||||
QModelIndex idx = ItemToIndex(info);
|
QModelIndex idx = ItemToIndex(device_info);
|
||||||
if (!idx.isValid()) return;
|
if (!idx.isValid()) return;
|
||||||
|
|
||||||
Q_EMIT dataChanged(idx, idx);
|
Q_EMIT dataChanged(idx, idx);
|
||||||
@@ -933,10 +933,10 @@ void DeviceManager::DeviceSongCountUpdated(const int count) {
|
|||||||
|
|
||||||
QString DeviceManager::DeviceNameByID(const QString &unique_id) {
|
QString DeviceManager::DeviceNameByID(const QString &unique_id) {
|
||||||
|
|
||||||
DeviceInfo *info = FindDeviceById(unique_id);
|
DeviceInfo *device_info = FindDeviceById(unique_id);
|
||||||
if (!info) return QString();
|
if (!device_info) return QString();
|
||||||
|
|
||||||
QModelIndex idx = ItemToIndex(info);
|
QModelIndex idx = ItemToIndex(device_info);
|
||||||
if (!idx.isValid()) return QString();
|
if (!idx.isValid()) return QString();
|
||||||
|
|
||||||
return data(idx, DeviceManager::Role_FriendlyName).toString();
|
return data(idx, DeviceManager::Role_FriendlyName).toString();
|
||||||
|
|||||||
@@ -104,17 +104,17 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
|
|||||||
DeviceLister *GetLister(const QModelIndex &idx) const;
|
DeviceLister *GetLister(const QModelIndex &idx) const;
|
||||||
DeviceInfo *GetDevice(const QModelIndex &idx) const;
|
DeviceInfo *GetDevice(const QModelIndex &idx) const;
|
||||||
SharedPtr<ConnectedDevice> GetConnectedDevice(const QModelIndex &idx) const;
|
SharedPtr<ConnectedDevice> GetConnectedDevice(const QModelIndex &idx) const;
|
||||||
SharedPtr<ConnectedDevice> GetConnectedDevice(DeviceInfo *info) const;
|
SharedPtr<ConnectedDevice> GetConnectedDevice(DeviceInfo *device_info) const;
|
||||||
|
|
||||||
DeviceInfo *FindDeviceById(const QString &id) const;
|
DeviceInfo *FindDeviceById(const QString &id) const;
|
||||||
DeviceInfo *FindDeviceByUrl(const QList<QUrl> &url) const;
|
DeviceInfo *FindDeviceByUrl(const QList<QUrl> &url) const;
|
||||||
QString DeviceNameByID(const QString &unique_id);
|
QString DeviceNameByID(const QString &unique_id);
|
||||||
DeviceInfo *FindEquivalentDevice(DeviceInfo *info) const;
|
DeviceInfo *FindEquivalentDevice(DeviceInfo *device_info) const;
|
||||||
|
|
||||||
// Actions on devices
|
// Actions on devices
|
||||||
SharedPtr<ConnectedDevice> Connect(DeviceInfo *info);
|
SharedPtr<ConnectedDevice> Connect(DeviceInfo *device_info);
|
||||||
SharedPtr<ConnectedDevice> Connect(const QModelIndex &idx);
|
SharedPtr<ConnectedDevice> Connect(const QModelIndex &idx);
|
||||||
void Disconnect(DeviceInfo *info, const QModelIndex &idx);
|
void Disconnect(DeviceInfo *device_info, const QModelIndex &idx);
|
||||||
void Forget(const QModelIndex &idx);
|
void Forget(const QModelIndex &idx);
|
||||||
void UnmountAsync(const QModelIndex &idx);
|
void UnmountAsync(const QModelIndex &idx);
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
|
|||||||
void ExitFinished();
|
void ExitFinished();
|
||||||
void DeviceConnected(const QModelIndex idx);
|
void DeviceConnected(const QModelIndex idx);
|
||||||
void DeviceDisconnected(const QModelIndex idx);
|
void DeviceDisconnected(const QModelIndex idx);
|
||||||
void DeviceCreatedFromDB(DeviceInfo *info);
|
void DeviceCreatedFromDB(DeviceInfo *device_info);
|
||||||
void DeviceError(const QString &error);
|
void DeviceError(const QString &error);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
@@ -143,7 +143,7 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
|
|||||||
void LoadAllDevices();
|
void LoadAllDevices();
|
||||||
void DeviceConnectFinished(const QString &id, bool success);
|
void DeviceConnectFinished(const QString &id, bool success);
|
||||||
void DeviceCloseFinished(const QString &id);
|
void DeviceCloseFinished(const QString &id);
|
||||||
void AddDeviceFromDB(DeviceInfo *info);
|
void AddDeviceFromDB(DeviceInfo *device_info);
|
||||||
void BackendClosed();
|
void BackendClosed();
|
||||||
void ListerClosed();
|
void ListerClosed();
|
||||||
void DeviceDestroyed();
|
void DeviceDestroyed();
|
||||||
@@ -154,7 +154,7 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
|
|||||||
|
|
||||||
DeviceDatabaseBackend::Device InfoToDatabaseDevice(const DeviceInfo &info) const;
|
DeviceDatabaseBackend::Device InfoToDatabaseDevice(const DeviceInfo &info) const;
|
||||||
|
|
||||||
void RemoveFromDB(DeviceInfo *info, const QModelIndex &idx);
|
void RemoveFromDB(DeviceInfo *device_info, const QModelIndex &idx);
|
||||||
|
|
||||||
void CloseDevices();
|
void CloseDevices();
|
||||||
void CloseListers();
|
void CloseListers();
|
||||||
|
|||||||
Reference in New Issue
Block a user