File indexing completed on 2024-05-12 05:39:49
0001 /*************************************************************************** 0002 * Copyright (C) 2020 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program 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 * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #ifndef CHATROOM_H 0021 #define CHATROOM_H 0022 0023 #include <QObject> 0024 #include <QPointer> 0025 #include <QUuid> 0026 0027 #include <core_global.h> 0028 #include <memory> 0029 0030 #include "model/filteredplayermodel.h" 0031 #include "model/messagemodel.h" 0032 0033 class DiceRoller; 0034 class PlayerModel; 0035 namespace InstantMessaging 0036 { 0037 class MessageInterface; 0038 class CORE_EXPORT ChatRoom : public QObject 0039 { 0040 Q_OBJECT 0041 Q_PROPERTY(FilteredPlayerModel* recipiants READ recipiants CONSTANT) 0042 Q_PROPERTY(MessageModel* messageModel READ messageModel CONSTANT) 0043 Q_PROPERTY(bool unreadMessage READ unreadMessage WRITE setUnreadMessage NOTIFY unreadMessageChanged) 0044 Q_PROPERTY(ChatRoomType type READ type CONSTANT) 0045 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 0046 Q_PROPERTY(int recipiantCount READ recipiantCount NOTIFY recipiantCountChanged) 0047 Q_PROPERTY(QString uuid READ uuid WRITE setUuid NOTIFY uuidChanged) 0048 Q_PROPERTY(QString localId READ localId WRITE setLocalId NOTIFY localIdChanged) 0049 public: 0050 enum ChatRoomType 0051 { 0052 GLOBAL, 0053 SINGLEPLAYER, 0054 EXTRA 0055 }; 0056 explicit ChatRoom(PlayerModel* model, ChatRoomType type, const QStringList& recipiants= QStringList(), 0057 const QString& id= QUuid::createUuid().toString(QUuid::WithoutBraces), QObject* parent= nullptr); 0058 virtual ~ChatRoom(); 0059 0060 MessageModel* messageModel() const; 0061 FilteredPlayerModel* recipiants() const; 0062 0063 QString title() const; 0064 ChatRoomType type() const; 0065 int recipiantCount() const; 0066 bool unreadMessage() const; 0067 QString uuid() const; 0068 QString localId() const; 0069 0070 bool hasRecipiant(const QString& id); 0071 void setDiceParser(DiceRoller* diceParser); 0072 0073 public slots: 0074 void setUuid(const QString& id); 0075 void setTitle(const QString& title); 0076 void setUnreadMessage(bool b); 0077 void addMessage(const QString& text, const QUrl& url, const QString& personId, const QString& personName); 0078 void addMessageInterface(MessageInterface* message); 0079 void setLocalId(const QString& id); 0080 0081 signals: 0082 void unreadMessageChanged(bool); 0083 void titleChanged(QString title); 0084 void recipiantCountChanged(int); 0085 void uuidChanged(QString); 0086 void localIdChanged(QString); 0087 0088 private: 0089 bool runCommand(const QString& command, const QString& personId, const QString& personName); 0090 bool rollDice(const QString& command, const QString& personId); 0091 0092 private: 0093 std::unique_ptr<FilteredPlayerModel> m_recipiants; 0094 std::unique_ptr<MessageModel> m_messageModel; 0095 QString m_title; 0096 ChatRoomType m_type; 0097 QString m_uuid; 0098 bool m_unreadMessage= false; 0099 QPointer<DiceRoller> m_diceParser; 0100 }; 0101 } // namespace InstantMessaging 0102 #endif // CHATROOM_H