diff --git a/src/gui/UserStatusSelectorDialog.qml b/src/gui/UserStatusSelectorDialog.qml index 3f86f8cf9..28d09254a 100644 --- a/src/gui/UserStatusSelectorDialog.qml +++ b/src/gui/UserStatusSelectorDialog.qml @@ -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 diff --git a/src/gui/tray/UserLine.qml b/src/gui/tray/UserLine.qml index 740cd1a91..d401457cc 100644 --- a/src/gui/tray/UserLine.qml +++ b/src/gui/tray/UserLine.qml @@ -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 diff --git a/src/gui/tray/Window.qml b/src/gui/tray/Window.qml index cfb6aaacd..50b099ec6 100644 --- a/src/gui/tray/Window.qml +++ b/src/gui/tray/Window.qml @@ -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) diff --git a/src/gui/userstatusselectormodel.cpp b/src/gui/userstatusselectormodel.cpp index da0b44c15..973f184dc 100644 --- a/src/gui/userstatusselectormodel.cpp +++ b/src/gui/userstatusselectormodel.cpp @@ -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 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; }