Skip to content

Commit

Permalink
Fix incorrect behavior when removing a user in between zero and the c…
Browse files Browse the repository at this point in the history
…urrent one.

Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Oct 29, 2022
1 parent 675fe7b commit 2f16e4e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,11 @@ void UserModel::removeAccount(const int id)
}

QMessageBox messageBox(QMessageBox::Question,
tr("Confirm Account Removal"),
tr("<p>Do you really want to remove the connection to the account <i>%1</i>?</p>"
"<p><b>Note:</b> This will <b>not</b> delete any files.</p>")
.arg(_users[id]->name()), QMessageBox::NoButton);
tr("Confirm Account Removal"),
tr("<p>Do you really want to remove the connection to the account <i>%1</i>?</p>"
"<p><b>Note:</b> This will <b>not</b> delete any files.</p>")
.arg(_users[id]->name()),
QMessageBox::NoButton);
QPushButton *yesButton = messageBox.addButton(tr("Remove connection"), QMessageBox::YesRole);
messageBox.addButton(tr("Cancel"), QMessageBox::NoRole);

Expand All @@ -1089,11 +1090,14 @@ void UserModel::removeAccount(const int id)
_users.removeAt(id);
endRemoveRows();

if (_users.size() <= 1) {
setCurrentUserId(_users.size() - 1);
} else if (currentUserId() == id || currentUserId() >= id) {
setCurrentUserId(id < _users.size() ? id : id - 1);
}
if (_users.size() <= 1) {
setCurrentUserId(_users.size() - 1);
} else if (currentUserId() > id) {
// an account was removed from the in-between 0 and the current one, the index of the current one needs a decrement
setCurrentUserId(currentUserId() - 1);
} else if (currentUserId() == id) {
setCurrentUserId(id < _users.size() ? id : id - 1);
}
}

std::shared_ptr<OCC::UserStatusConnector> UserModel::userStatusConnector(int id)
Expand Down

0 comments on commit 2f16e4e

Please sign in to comment.