1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2024-12-23 15:08:10 +01:00

Attempt to fix crashes in devices

This commit is contained in:
Jonas Kvinge 2019-01-05 23:17:20 +01:00
parent a06de35aa5
commit 9b7da3e071
2 changed files with 7 additions and 0 deletions

View File

@ -542,6 +542,8 @@ std::shared_ptr<ConnectedDevice> DeviceManager::Connect(int row) {
}
info->device_ = ret;
QModelIndex index = ItemToIndex(info);
if (!index.isValid()) return ret;
emit dataChanged(index, index);
connect(info->device_.get(), SIGNAL(TaskStarted(int)), SLOT(DeviceTaskStarted(int)));
connect(info->device_.get(), SIGNAL(SongCountUpdated(int)), SLOT(DeviceSongCountUpdated(int)));
@ -639,6 +641,7 @@ void DeviceManager::DeviceTaskStarted(int id) {
DeviceInfo *info = devices_[i];
if (info->device_.get() == device) {
QModelIndex index = ItemToIndex(info);
if (!index.isValid()) continue;
active_tasks_[id] = index;
info->task_percentage_ = 0;
emit dataChanged(index, index);

View File

@ -308,8 +308,11 @@ void DeviceView::DeviceConnected(int row) {
if (!device) return;
DeviceInfo *info = app_->device_manager()->ItemFromRow(row);
if (!info) return;
QModelIndex index = app_->device_manager()->ItemToIndex(info);
if (!index.isValid()) return;
QModelIndex sort_idx = sort_model_->mapFromSource(index);
if (!sort_idx.isValid()) return;
QSortFilterProxyModel *sort_model = new QSortFilterProxyModel(device->model());
sort_model->setSourceModel(device->model());
@ -326,6 +329,7 @@ void DeviceView::DeviceDisconnected(int row) {
DeviceInfo *info = app_->device_manager()->ItemFromRow(row);
if (!info) return;
QModelIndex index = app_->device_manager()->ItemToIndex(info);
if (!index.isValid()) return;
merged_model_->RemoveSubModel(sort_model_->mapFromSource(index));
}