File indexing completed on 2023-11-26 08:16:45

0001 /*
0002  * Rooms Model - A model of chatrooms.
0003  * Copyright (C) 2012  Dominik Cermak <d.cermak@arcor.de>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Lesser General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2.1 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Lesser General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Lesser General Public
0016  * License along with this library; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 #ifndef ROOMS_MODEL_H
0021 #define ROOMS_MODEL_H
0022 
0023 #include <QtCore/QAbstractListModel>
0024 #include <TelepathyQt/Types>
0025 
0026 #include <KTp/Models/ktpmodels_export.h>
0027 
0028 namespace KTp {
0029 
0030 class KTPMODELS_EXPORT RoomsModel : public QAbstractListModel
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     // TODO: find a suitable icon and add an invitation column
0036     enum Column {
0037         NameColumn=0,
0038         DescriptionColumn,
0039         MembersColumn,
0040         PasswordColumn,
0041     };
0042 
0043     enum Roles {
0044         HandleNameRole = Qt::UserRole
0045     };
0046 
0047     explicit RoomsModel(QObject *parent = nullptr);
0048     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0049     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0050     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0051     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0052 
0053     /**
0054      * \brief Add new rooms to the list.
0055      *
0056      * \param newRoomList The list with the new rooms to add.
0057      */
0058     void addRooms(const Tp::RoomInfoList newRoomList);
0059 
0060     /**
0061      * \brief Clear the room list.
0062      */
0063     void clearRoomInfoList();
0064 
0065 private:
0066     Tp::RoomInfoList m_roomInfoList;
0067 };
0068 
0069 class KTPMODELS_EXPORT FavoriteRoomsModel : public QAbstractListModel
0070 {
0071     Q_OBJECT
0072 
0073 public:
0074     enum Column {
0075         BookmarkColumn = 0,
0076         HandleNameColumn,
0077         AccountIdentifierColumn
0078     };
0079 
0080     enum Roles {
0081         HandleNameRole = Qt::UserRole,
0082         BookmarkRole,
0083         AccountRole,
0084         FavoriteRoomRole
0085     };
0086 
0087     explicit FavoriteRoomsModel(QObject *parent = nullptr);
0088     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0089     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0090     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0091     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0092     Qt::ItemFlags flags(const QModelIndex &index) const override;
0093 
0094     /**
0095      * \brief Add new rooms to the list.
0096      *
0097      * \param newRoomList The list with the new rooms to add.
0098      */
0099     void addRooms(const QList<QVariantMap> newRoomList);
0100 
0101     /**
0102      * \brief Add a new room to the list.
0103      *
0104      * \param room The room to add.
0105      */
0106     void addRoom(const QVariantMap &room);
0107 
0108     /**
0109      * \brief Remove a room from the list.
0110      *
0111      * \param room The room to remove.
0112      */
0113     void removeRoom(const QVariantMap &room);
0114 
0115     /**
0116      * \brief Remove all rooms from the list.
0117      */
0118     void clearRooms();
0119 
0120     /**
0121      * \brief Checks if it contains a room (identified by his handle-name).
0122      *
0123      * \param handle The handle to look for.
0124      *
0125      * \return True if it contains the room else false.
0126      */
0127     bool containsRoom(const QString &handle, const QString &account) const;
0128 
0129     /**
0130      * \brief Returns the count of rooms for the specified account.
0131      *
0132      * \param account The account to return the count for.
0133      *
0134      * \return The count of rooms.
0135      */
0136     int countForAccount(const QString &account) const;
0137 
0138 private:
0139     QList<QVariantMap> m_favoriteRoomsList;
0140 };
0141 
0142 } // namespace KTp
0143 
0144 #endif // ROOMS_MODEL_H