File indexing completed on 2024-10-06 12:54:28

0001 /*
0002    SPDX-FileCopyrightText: 2017-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 "user.h"
0011 
0012 #include <QAbstractListModel>
0013 #include <QIcon>
0014 class CustomUserStatus;
0015 
0016 class LIBRUQOLACORE_EXPORT StatusModel : public QAbstractListModel
0017 {
0018     Q_OBJECT
0019 public:
0020     enum StatusRoles {
0021         StatusI18n = Qt::UserRole + 1,
0022         Status,
0023         Icon,
0024         Order,
0025     };
0026     Q_ENUM(StatusRoles)
0027 
0028     struct StatusInfo {
0029         User::PresenceStatus status;
0030         QString statusStr;
0031     };
0032 
0033     explicit StatusModel(QObject *parent = nullptr);
0034     ~StatusModel() override;
0035 
0036     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0037     [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0038 
0039     [[nodiscard]] User::PresenceStatus status(int index) const;
0040 
0041     [[nodiscard]] int currentStatus() const;
0042 
0043     void setCurrentPresenceStatus(User::PresenceStatus status);
0044     [[nodiscard]] User::PresenceStatus currentUserStatus() const;
0045 
0046     [[nodiscard]] StatusInfo currentStatusInfo() const;
0047 
0048     [[nodiscard]] QString customText() const;
0049     void setCustomText(const QString &customText);
0050 
0051     void updateCustomStatus(const QVector<CustomUserStatus> &customUserStatuses);
0052 
0053 Q_SIGNALS:
0054     void currentStatusChanged();
0055 
0056 private:
0057     struct DisplayStatusInfo {
0058         QString displayText;
0059         QString statusStr;
0060         QIcon icon;
0061         User::PresenceStatus status;
0062         int order = 0;
0063     };
0064     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT QString textFromPresenceStatus(User::PresenceStatus status) const;
0065     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT QIcon iconFromPresenceStatus(User::PresenceStatus status) const;
0066     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT StatusModel::DisplayStatusInfo createStatusInfo(User::PresenceStatus status, int order);
0067     Q_DISABLE_COPY(StatusModel)
0068     LIBRUQOLACORE_NO_EXPORT void fillModel();
0069     QVector<DisplayStatusInfo> mStatusList;
0070     QString mCustomText;
0071     int mCurrentStatus = 0;
0072 };