mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-04-21 21:52:03 +02:00
moderatorlistmodel: fix refresh on account change
Change-Id: Ib689e97d903a42fc241f505e3fb5f37c155c65f9 GitLab: #1122
This commit is contained in:
parent
03b3530d3d
commit
207872244b
6 changed files with 36 additions and 16 deletions
|
@ -34,10 +34,12 @@ AccountAdapter::AccountAdapter(AppSettingsManager* settingsManager,
|
|||
, settingsManager_(settingsManager)
|
||||
, systemTray_(systemTray)
|
||||
, accountListModel_(new AccountListModel(instance))
|
||||
, deviceItemListModel_(new DeviceItemListModel(instance))
|
||||
, deviceItemListModel_(new DeviceItemListModel(instance, parent))
|
||||
, moderatorListModel_(new ModeratorListModel(instance, parent))
|
||||
{
|
||||
QML_REGISTERSINGLETONTYPE_POBJECT(NS_MODELS, accountListModel_.get(), "AccountListModel");
|
||||
QML_REGISTERSINGLETONTYPE_POBJECT(NS_MODELS, deviceItemListModel_.get(), "DeviceItemListModel");
|
||||
QML_REGISTERSINGLETONTYPE_POBJECT(NS_MODELS, moderatorListModel_.get(), "ModeratorListModel");
|
||||
|
||||
connect(&lrcInstance_->accountModel(),
|
||||
&AccountModel::accountStatusChanged,
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "accountlistmodel.h"
|
||||
#include "deviceitemlistmodel.h"
|
||||
#include "moderatorlistmodel.h"
|
||||
#include "systemtray.h"
|
||||
#include "lrcinstance.h"
|
||||
#include "utils.h"
|
||||
|
@ -102,5 +103,6 @@ private:
|
|||
|
||||
QScopedPointer<AccountListModel> accountListModel_;
|
||||
QScopedPointer<DeviceItemListModel> deviceItemListModel_;
|
||||
QScopedPointer<ModeratorListModel> moderatorListModel_;
|
||||
};
|
||||
Q_DECLARE_METATYPE(AccountAdapter*)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2023 Savoir-faire Linux Inc.
|
||||
* Author: Albert Babí Oller <albert.babi@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,9 +19,17 @@
|
|||
|
||||
#include "lrcinstance.h"
|
||||
|
||||
ModeratorListModel::ModeratorListModel(QObject* parent)
|
||||
ModeratorListModel::ModeratorListModel(LRCInstance* instance, QObject* parent)
|
||||
: AbstractListModelBase(parent)
|
||||
{}
|
||||
{
|
||||
lrcInstance_ = instance;
|
||||
connect(lrcInstance_,
|
||||
&LRCInstance::currentAccountIdChanged,
|
||||
this,
|
||||
&ModeratorListModel::connectAccount,
|
||||
Qt::UniqueConnection);
|
||||
connectAccount();
|
||||
}
|
||||
|
||||
ModeratorListModel::~ModeratorListModel() {}
|
||||
|
||||
|
@ -52,7 +59,7 @@ ModeratorListModel::data(const QModelIndex& index, int role) const
|
|||
{
|
||||
try {
|
||||
QStringList list = lrcInstance_->accountModel().getDefaultModerators(
|
||||
lrcInstance_->get_currentAccountId());
|
||||
lrcInstance_->get_currentAccountId());
|
||||
if (!index.isValid() || list.size() <= index.row()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -61,8 +68,8 @@ ModeratorListModel::data(const QModelIndex& index, int role) const
|
|||
|
||||
switch (role) {
|
||||
case Role::ContactName: {
|
||||
QString str = lrcInstance_->getCurrentAccountInfo().contactModel->
|
||||
bestNameForContact(list.at(index.row()));
|
||||
QString str = lrcInstance_->getCurrentAccountInfo().contactModel->bestNameForContact(
|
||||
list.at(index.row()));
|
||||
return QVariant(str);
|
||||
}
|
||||
case Role::ContactID:
|
||||
|
@ -120,3 +127,10 @@ ModeratorListModel::reset()
|
|||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void
|
||||
ModeratorListModel::connectAccount()
|
||||
{
|
||||
if (!lrcInstance_->get_currentAccountId().isEmpty())
|
||||
reset();
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2023 Savoir-faire Linux Inc.
|
||||
* Author: Albert Babí Oller <albert.babi@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,14 +19,14 @@
|
|||
|
||||
#include "abstractlistmodelbase.h"
|
||||
|
||||
class ModeratorListModel : public AbstractListModelBase
|
||||
class ModeratorListModel final : public AbstractListModelBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Role { ContactName = Qt::UserRole + 1, ContactID };
|
||||
Q_ENUM(Role)
|
||||
|
||||
explicit ModeratorListModel(QObject* parent = nullptr);
|
||||
explicit ModeratorListModel(LRCInstance* lrcInstance, QObject* parent = nullptr);
|
||||
~ModeratorListModel();
|
||||
|
||||
/*
|
||||
|
@ -48,4 +47,10 @@ public:
|
|||
* This function is to reset the model when there's new account added.
|
||||
*/
|
||||
Q_INVOKABLE void reset();
|
||||
|
||||
public Q_SLOTS:
|
||||
void connectAccount();
|
||||
|
||||
private:
|
||||
LRCInstance* lrcInstance_;
|
||||
};
|
||||
|
|
|
@ -165,7 +165,6 @@ registerTypes(QQmlEngine* engine,
|
|||
|
||||
// QAbstractListModels
|
||||
QML_REGISTERTYPE(NS_MODELS, BannedListModel);
|
||||
QML_REGISTERTYPE(NS_MODELS, ModeratorListModel);
|
||||
QML_REGISTERTYPE(NS_MODELS, MediaCodecListModel);
|
||||
QML_REGISTERTYPE(NS_MODELS, AudioDeviceModel);
|
||||
QML_REGISTERTYPE(NS_MODELS, AudioManagerListModel);
|
||||
|
@ -229,6 +228,7 @@ registerTypes(QQmlEngine* engine,
|
|||
QML_REGISTERUNCREATABLE(NS_ENUMS, NetworkManager)
|
||||
QML_REGISTERUNCREATABLE(NS_ENUMS, WizardViewStepModel)
|
||||
QML_REGISTERUNCREATABLE(NS_ENUMS, DeviceItemListModel)
|
||||
QML_REGISTERUNCREATABLE(NS_ENUMS, ModeratorListModel)
|
||||
QML_REGISTERUNCREATABLE(NS_ENUMS, VideoInputDeviceModel)
|
||||
QML_REGISTERUNCREATABLE(NS_ENUMS, VideoFormatResolutionModel)
|
||||
QML_REGISTERUNCREATABLE(NS_ENUMS, VideoFormatFpsModel)
|
||||
|
|
|
@ -276,11 +276,8 @@ SettingsPageBase {
|
|||
Layout.preferredHeight: 160
|
||||
spacing: JamiTheme.settingsListViewsSpacing
|
||||
|
||||
visible: model.rowCount() > 0
|
||||
|
||||
model: ModeratorListModel {
|
||||
lrcInstance: LRCInstance
|
||||
}
|
||||
visible: count > 0
|
||||
model: ModeratorListModel
|
||||
|
||||
delegate: ContactItemDelegate {
|
||||
id: moderatorListDelegate
|
||||
|
|
Loading…
Add table
Reference in a new issue