| 397 | } |
| 398 | |
| 399 | void Model::tryAction(Action action, const QModelIndex &index) |
| 400 | { |
| 401 | const auto visitor = [this, action](Component &component, auto v) -> void { |
| 402 | if (component.checkOnly) |
| 403 | return; |
| 404 | |
| 405 | const auto &state = component.state; |
| 406 | auto ok = (action == Action::Remove && |
| 407 | (state == State::UpdateAvailable || state == State::Actual)) || |
| 408 | (action == Action::Install && (state == State::UpdateAvailable || |
| 409 | state == State::NotInstalled)); |
| 410 | if (ok) |
| 411 | updater_.applyAction(action, component.files); |
| 412 | |
| 413 | if (!component.children.empty()) { |
| 414 | for (auto &child : component.children) v(*child, v); |
| 415 | } |
| 416 | }; |
| 417 | |
| 418 | auto component = toComponent(index); |
| 419 | SOFT_ASSERT(component, return ); |
| 420 | visitor(*component, visitor); |
| 421 | } |
| 422 | |
| 423 | Model::Component *Model::toComponent(const QModelIndex &index) const |
| 424 | { |
no test coverage detected