File indexing completed on 2024-02-25 16:44:39

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "libruqolacore_export.h"
0010 #include <QAbstractListModel>
0011 class RocketChatAccount;
0012 class LIBRUQOLACORE_EXPORT RocketChatAccountModel : public QAbstractListModel
0013 {
0014     Q_OBJECT
0015 public:
0016     enum AccountRoles {
0017         Name = Qt::UserRole + 1,
0018         SiteUrl,
0019         UserName,
0020         Account,
0021         AccountName,
0022     };
0023     Q_ENUM(AccountRoles)
0024 
0025     explicit RocketChatAccountModel(QObject *parent = nullptr);
0026     ~RocketChatAccountModel() override;
0027 
0028     [[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override;
0029     [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
0030 
0031     void insertAccount(RocketChatAccount *account);
0032     RocketChatAccount *removeAccount(const QString &name);
0033 
0034     void clear();
0035 
0036     void setAccounts(const QVector<RocketChatAccount *> &accounts);
0037 
0038     [[nodiscard]] RocketChatAccount *account(int index) const;
0039 
0040     [[nodiscard]] RocketChatAccount *account(const QString &accountName) const;
0041 
0042     [[nodiscard]] int accountNumber() const;
0043     [[nodiscard]] QStringList accountsName() const;
0044 
0045     [[nodiscard]] RocketChatAccount *accountFromServerUrl(const QString &serverUrl) const;
0046 Q_SIGNALS:
0047     void accountNumberChanged();
0048 
0049 private:
0050     QVector<RocketChatAccount *> mRocketChatAccount;
0051 };