Skip to content

Commit

Permalink
Update the materialised items model post-file eviction
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Nov 1, 2023
1 parent ce92854 commit b58a721
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/gui/macOS/fileprovidermaterialiseditemsmodel_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,40 @@
return;
}

__block BOOL successfullyDeleted = YES;

[manager evictItemWithIdentifier:identifier.toNSString() completionHandler:^(NSError *error) {
if (error != nil) {
const auto errorDesc = QString::fromNSString(error.localizedDescription);
qCWarning(lcMacImplFileProviderMaterialisedItemsModelMac) << "Error evicting item:" << errorDesc;
Systray::instance()->showMessage(tr("Error"),
tr("An error occurred while trying to delete the local copy of this item: %1").arg(errorDesc),
QSystemTrayIcon::Warning);
successfullyDeleted = NO;
}
}];

// TODO: Update the model
if (successfullyDeleted == NO) {
return;
}

const auto deletedItemIt = std::find_if(_items.cbegin(),
_items.cend(),
[identifier, domainIdentifier](const FileProviderItemMetadata &item) {
return item.identifier() == identifier && item.domainIdentifier() == domainIdentifier;
});

if (deletedItemIt == _items.cend()) {
qCWarning(lcMacImplFileProviderMaterialisedItemsModelMac) << "Could not find item"
<< identifier
<< "in model items.";
return;
}

const auto deletedItemRow = std::distance(_items.cbegin(), deletedItemIt);
beginRemoveRows({}, deletedItemRow, deletedItemRow);
_items.remove(deletedItemRow);
endRemoveRows();
}


Expand Down

0 comments on commit b58a721

Please sign in to comment.