blob: bdf35924166019121ccb79413e34733a2145b725 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
2 * Copyright (C) 2017-2020 by Savoir-faire Linux
3 * Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
4 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
5 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include "api/account.h"
24#include "api/contact.h"
25#include "api/conversation.h"
26#include "api/conversationmodel.h"
27
28#include <QAbstractItemModel>
29
30using namespace lrc::api;
31
32class SmartListModel : public QAbstractListModel
33{
34 Q_OBJECT
35public:
36 using AccountInfo = lrc::api::account::Info;
37 using ConversationInfo = lrc::api::conversation::Info;
38 using ContactInfo = lrc::api::contact::Info;
39
40 enum class Type { CONVERSATION, CONFERENCE, TRANSFER, COUNT__ };
41
42 enum Role {
43 DisplayName = Qt::UserRole + 1,
44 DisplayID,
45 Picture,
46 Presence,
47 URI,
48 UnreadMessagesCount,
49 LastInteractionDate,
50 LastInteraction,
51 LastInteractionType,
52 ContactType,
53 UID,
54 ContextMenuOpen,
55 InCall,
56 IsAudioOnly,
57 CallStackViewShouldShow,
58 CallStateStr,
59 SectionName,
60 AccountId,
61 Draft
62 };
63
64 explicit SmartListModel(const QString &accId,
65 QObject *parent = 0,
66 SmartListModel::Type listModelType = Type::CONVERSATION,
67 const QString &convUid = {});
68 ~SmartListModel();
69
70 /*
71 * QAbstractListModel.
72 */
73 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
74 int columnCount(const QModelIndex &parent) const override;
75 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
76 QHash<int, QByteArray> roleNames() const override;
77 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
78 QModelIndex parent(const QModelIndex &child) const;
79 Qt::ItemFlags flags(const QModelIndex &index) const;
80
81 Q_INVOKABLE void setAccount(const QString &accId);
82 Q_INVOKABLE void setConferenceableFilter(const QString &filter = {});
83 Q_INVOKABLE void toggleSection(const QString &section);
84 Q_INVOKABLE int currentUidSmartListModelIndex();
ababi0b686642020-08-18 17:21:28 +020085 Q_INVOKABLE void fillConversationsList();
86 Q_INVOKABLE void updateConversation(const QString &conv);
Sébastien Blin1f915762020-08-03 13:27:42 -040087
88private:
89 QString accountId_;
90
91 QVariant getConversationItemData(const ConversationInfo &item,
92 const AccountInfo &accountInfo,
93 int role) const;
94 /*
95 * List sectioning.
96 */
97 QString convUid_;
98 Type listModelType_;
99 QMap<QString, bool> sectionState_;
100 QMap<ConferenceableItem, ConferenceableValue> conferenceables_;
ababi0b686642020-08-18 17:21:28 +0200101 ConversationModel::ConversationQueue conversations_;
102};