Merge pull request #4616 from nextcloud/bugfix/user-status-selector-crash

Fix crashing when selecting user status and predefined statuses not appearing
This commit is contained in:
Claudio Cambra 2022-06-24 13:44:31 +02:00 committed by GitHub
commit d23305f1fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 15 deletions

View file

@ -4,10 +4,14 @@ import com.nextcloud.desktopclient 1.0 as NC
Window {
id: dialog
title: qsTr("Set user status")
property NC.UserStatusSelectorModel model: NC.UserStatusSelectorModel {
onFinished: dialog.close()
}
property int userIndex
onUserIndexChanged: model.load(userIndex)
minimumWidth: view.implicitWidth
minimumHeight: view.implicitHeight

View file

@ -184,10 +184,7 @@ MenuItem {
font.pixelSize: Style.topLinePixelSize
palette.windowText: Style.ncTextColor
hoverEnabled: true
onClicked: {
showUserStatusSelectorDialog(index)
accountMenu.close()
}
onClicked: showUserStatusSelectorDialog(index)
background: Item {
height: parent.height

View file

@ -175,10 +175,6 @@ Window {
}
}
Loader {
id: userStatusSelectorDialogLoader
}
Menu {
id: accountMenu
@ -221,15 +217,36 @@ Window {
userLineInstantiator.active = true;
}
Loader {
id: userStatusSelectorDialogLoader
property int userIndex
function openDialog(newUserIndex) {
console.log(`About to show dialog for user with index ${newUserIndex}`);
userIndex = newUserIndex;
active = true;
item.show();
}
active: false
sourceComponent: UserStatusSelectorDialog {
userIndex: userStatusSelectorDialogLoader.userIndex
}
onLoaded: {
item.model.load(userIndex);
item.show();
}
}
Instantiator {
id: userLineInstantiator
model: UserModel
delegate: UserLine {
onShowUserStatusSelectorDialog: {
userStatusSelectorDialogLoader.source = "qrc:/qml/src/gui/UserStatusSelectorDialog.qml"
userStatusSelectorDialogLoader.item.title = qsTr("Set user status")
userStatusSelectorDialogLoader.item.model.load(index)
userStatusSelectorDialogLoader.item.show()
userStatusSelectorDialogLoader.openDialog(model.index);
accountMenu.close();
}
}
onObjectAdded: accountMenu.insertItem(index, object)

View file

@ -79,6 +79,7 @@ UserStatusSelectorModel::UserStatusSelectorModel(const UserStatus &userStatus,
void UserStatusSelectorModel::load(int id)
{
reset();
qCDebug(lcUserStatusDialogModel) << "Loading user status connector for user with index: " << id;
_userStatusConnector = UserModel::instance()->userStatusConnector(id);
init();
}
@ -177,7 +178,7 @@ void UserStatusSelectorModel::clearError()
void UserStatusSelectorModel::setOnlineStatus(UserStatus::OnlineStatus status)
{
if (status == _userStatus.state()) {
if (!_userStatusConnector || status == _userStatus.state()) {
return;
}
@ -300,7 +301,6 @@ Optional<ClearAt> UserStatusSelectorModel::clearStageTypeToDateTime(ClearStageTy
void UserStatusSelectorModel::setUserStatus()
{
Q_ASSERT(_userStatusConnector);
if (!_userStatusConnector) {
return;
}
@ -311,7 +311,6 @@ void UserStatusSelectorModel::setUserStatus()
void UserStatusSelectorModel::clearUserStatus()
{
Q_ASSERT(_userStatusConnector);
if (!_userStatusConnector) {
return;
}