2020-08-03 13:27:42 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019-2020 by Savoir-faire Linux
|
|
|
|
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
|
|
|
|
* Author: Mingrui Zhang <mingrui.zhang@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
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-04-21 12:17:15 -04:00
|
|
|
#include "abstractlistmodelbase.h"
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-05-10 15:46:37 -04:00
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
#define ACC_ROLES \
|
|
|
|
X(Alias) \
|
|
|
|
X(Username) \
|
|
|
|
X(Type) \
|
|
|
|
X(Status) \
|
|
|
|
X(ID) \
|
|
|
|
X(PictureUid)
|
|
|
|
|
|
|
|
namespace AccountList {
|
|
|
|
Q_NAMESPACE
|
|
|
|
enum Role {
|
|
|
|
DummyRole = Qt::UserRole + 1,
|
|
|
|
#define X(role) role,
|
|
|
|
ACC_ROLES
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
Q_ENUM_NS(Role)
|
|
|
|
} // namespace AccountList
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The CurrentAccountFilterModel class
|
|
|
|
* is for the sole purpose of filtering out current account.
|
|
|
|
*/
|
|
|
|
class CurrentAccountFilterModel final : public QSortFilterProxyModel
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-05-10 15:46:37 -04:00
|
|
|
explicit CurrentAccountFilterModel(LRCInstance* lrcInstance,
|
|
|
|
QAbstractListModel* parent = nullptr)
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
, lrcInstance_(lrcInstance)
|
|
|
|
{
|
|
|
|
setSourceModel(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override
|
|
|
|
{
|
|
|
|
// Accept all contacts in conversation list filtered with account type, except those in a call.
|
|
|
|
auto index = sourceModel()->index(sourceRow, 0, sourceParent);
|
|
|
|
auto accountID = sourceModel()->data(index, AccountList::ID);
|
2021-05-13 17:47:23 -04:00
|
|
|
return accountID != lrcInstance_->getCurrentAccountId();
|
2021-05-10 15:46:37 -04:00
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-05-10 15:46:37 -04:00
|
|
|
protected:
|
|
|
|
LRCInstance* lrcInstance_ {nullptr};
|
|
|
|
};
|
|
|
|
|
|
|
|
class AccountListModel : public AbstractListModelBase
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AccountListModel(LRCInstance* instance, QObject* parent = nullptr);
|
2020-08-03 13:27:42 -04:00
|
|
|
~AccountListModel();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* QAbstractListModel override.
|
|
|
|
*/
|
2020-09-10 17:40:51 -04:00
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
|
|
int columnCount(const QModelIndex& parent) const override;
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
2020-09-14 13:04:57 -04:00
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
/*
|
|
|
|
* Override role name as access point in qml.
|
|
|
|
*/
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is to reset the model when there's new account added.
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE void reset();
|
2020-10-19 14:51:31 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is to update avatar uuid when there's an avatar changed.
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE void updateAvatarUid(const QString& accountId);
|
|
|
|
|
2021-05-10 15:46:37 -04:00
|
|
|
protected:
|
|
|
|
using Role = AccountList::Role;
|
|
|
|
|
2020-10-19 14:51:31 -04:00
|
|
|
private:
|
|
|
|
/*
|
|
|
|
* Give a uuid for each account avatar and it will serve PictureUid role
|
|
|
|
*/
|
|
|
|
void fillAvatarUidMap(const QStringList& accountList);
|
|
|
|
|
|
|
|
QMap<QString, QString> avatarUidMap_;
|
2020-08-03 13:27:42 -04:00
|
|
|
};
|