Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashing when selecting user status and predefined statuses not appearing #4616

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/gui/UserStatusSelectorDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/gui/tray/UserLine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 25 additions & 8 deletions src/gui/tray/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ Window {
}
}

Loader {
id: userStatusSelectorDialogLoader
}

Menu {
id: accountMenu

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions src/gui/userstatusselectormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -177,7 +178,7 @@ void UserStatusSelectorModel::clearError()

void UserStatusSelectorModel::setOnlineStatus(UserStatus::OnlineStatus status)
{
if (status == _userStatus.state()) {
if (!_userStatusConnector || status == _userStatus.state()) {
claucambra marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down Expand Up @@ -300,7 +301,6 @@ Optional<ClearAt> UserStatusSelectorModel::clearStageTypeToDateTime(ClearStageTy

void UserStatusSelectorModel::setUserStatus()
{
Q_ASSERT(_userStatusConnector);
if (!_userStatusConnector) {
return;
}
Expand All @@ -311,7 +311,6 @@ void UserStatusSelectorModel::setUserStatus()

void UserStatusSelectorModel::clearUserStatus()
{
Q_ASSERT(_userStatusConnector);
if (!_userStatusConnector) {
return;
}
Expand Down