Skip to content

Commit

Permalink
Make avatar preferences work again
Browse files Browse the repository at this point in the history
They were waiting for commit() to be called, which never happened
because of the settings redesign getting rid of the OK/Apply/Cancel
buttons. Now there's an autoCommit option on the model, which will call
it automatically.
  • Loading branch information
askmeaboutlo0m committed Jun 13, 2023
1 parent 12fb7e8 commit 1c45972
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/desktop/dialogs/logindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct LoginDialog::Private {

// Identity & authentication page
ui->username->setValidator(new UsernameValidator(dlg));
avatars = new AvatarListModel(dlg);
avatars = new AvatarListModel(false, dlg);
avatars->loadAvatars(true);
ui->avatarList->setModel(avatars);

Expand Down
2 changes: 1 addition & 1 deletion src/desktop/dialogs/settingsdialog/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void Network::initAvatars(utils::SanerFormLayout *form)
avatars->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
avatars->setSelectionMode(QAbstractItemView::ExtendedSelection);

auto *avatarsModel = new AvatarListModel(this);
auto *avatarsModel = new AvatarListModel(true, this);
avatarsModel->loadAvatars();
avatars->setModel(avatarsModel);
avatars->setItemDelegate(new AvatarItemDelegate(this));
Expand Down
11 changes: 10 additions & 1 deletion src/libclient/utils/avatarlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include <QBuffer>
#include <QCryptographicHash>

AvatarListModel::AvatarListModel(QObject *parent)
AvatarListModel::AvatarListModel(bool autoCommit, QObject *parent)
: QAbstractListModel(parent)
, m_autoCommit(autoCommit)
{
}

Expand Down Expand Up @@ -65,6 +66,10 @@ bool AvatarListModel::removeRows(int row, int count, const QModelIndex &parent)
m_avatars.remove(row);
}
endRemoveRows();

if(m_autoCommit) {
commit();
}
return true;
}

Expand All @@ -86,6 +91,10 @@ void AvatarListModel::addAvatar(const QPixmap &icon)
QString()
};
endInsertRows();

if(m_autoCommit) {
commit();
}
}

void AvatarListModel::loadAvatars(bool includeBlank)
Expand Down
3 changes: 2 additions & 1 deletion src/libclient/utils/avatarlistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AvatarListModel final : public QAbstractListModel
FilenameRole = Qt::UserRole + 1,
};

AvatarListModel(QObject *parent=nullptr);
AvatarListModel(bool autoCommit, QObject *parent=nullptr);

int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Expand Down Expand Up @@ -45,6 +45,7 @@ public slots:
QString filename;
};

bool m_autoCommit;
QVector<Avatar> m_avatars;
QStringList m_deletions;
};
Expand Down

0 comments on commit 1c45972

Please sign in to comment.