Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Sébastien Blin | 68abac9 | 2019-01-02 17:41:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2017-2019 by Savoir-faire Linux * |
| 3 | * Author: Anthony L�onard <anthony.leonard@savoirfairelinux.com> * |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 3 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | **************************************************************************/ |
| 18 | #pragma once |
| 19 | |
| 20 | // Qt include |
| 21 | #include <QAbstractItemModel> |
| 22 | |
| 23 | // LRC |
| 24 | #include "api/account.h" |
| 25 | #include "api/conversation.h" |
| 26 | #include "api/contact.h" |
| 27 | |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 28 | namespace lrc { namespace api { class ConversationModel; } } |
| 29 | |
| 30 | class SmartListModel : public QAbstractItemModel |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | public: |
| 34 | using AccountInfo = lrc::api::account::Info; |
| 35 | using ConversationInfo = lrc::api::conversation::Info; |
| 36 | using ContactInfo = lrc::api::contact::Info; |
| 37 | |
| 38 | |
| 39 | enum Role { |
| 40 | DisplayName = Qt::UserRole + 1, |
| 41 | DisplayID, |
| 42 | Picture, |
| 43 | Presence, |
| 44 | URI, |
| 45 | UnreadMessagesCount, |
| 46 | LastInteractionDate, |
| 47 | LastInteraction, |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 48 | LastInteractionType, |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 49 | ContactType, |
| 50 | UID, |
| 51 | ContextMenuOpen |
| 52 | }; |
| 53 | |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 54 | explicit SmartListModel(const std::string& accId, QObject *parent = 0); |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 55 | |
| 56 | // QAbstractItemModel |
| 57 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 58 | int columnCount(const QModelIndex &parent) const override; |
| 59 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 60 | QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; |
| 61 | QModelIndex parent(const QModelIndex &child) const; |
| 62 | Qt::ItemFlags flags(const QModelIndex &index) const; |
| 63 | |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 64 | void setAccount(const std::string& accId); |
| 65 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 66 | // hack for context menu highlight retention |
| 67 | bool isContextMenuOpen{ false }; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 68 | |
| 69 | private: |
Andreas Traczyk | 6b5ad3e | 2019-01-02 17:04:36 -0500 | [diff] [blame] | 70 | std::string accId_; |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 71 | }; |