File indexing completed on 2024-05-12 05:39:48

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 TEXTMESSAGINGCONTROLLER_H
0021 #define TEXTMESSAGINGCONTROLLER_H
0022 
0023 #include <QObject>
0024 #include <QPointer>
0025 #include <memory>
0026 #include <vector>
0027 
0028 #include "controllerinterface.h"
0029 #include "data/chatroom.h"
0030 #include "data/localpersonmodel.h"
0031 #include "model/chatroomsplittermodel.h"
0032 #include "model/filterinstantmessagingmodel.h"
0033 #include "model/playermodel.h"
0034 #include "network/networkreceiver.h"
0035 #include <core_global.h>
0036 
0037 class DiceRoller;
0038 
0039 namespace InstantMessaging
0040 {
0041 class InstantMessagingModel;
0042 class InstantMessagingUpdater;
0043 } // namespace InstantMessaging
0044 
0045 class CORE_EXPORT InstantMessagingController : public AbstractControllerInterface, public NetWorkReceiver
0046 {
0047     Q_OBJECT
0048     Q_PROPERTY(InstantMessaging::ChatroomSplitterModel* mainModel READ mainModel CONSTANT)
0049     Q_PROPERTY(InstantMessaging::ChatRoom* globalChatroom READ globalChatroom CONSTANT)
0050     Q_PROPERTY(PlayerModel* playerModel READ playerModel CONSTANT)
0051     Q_PROPERTY(LocalPersonModel* localPersonModel READ localPersonModel CONSTANT)
0052     Q_PROPERTY(QString localId READ localId WRITE setLocalId NOTIFY localIdChanged)
0053     Q_PROPERTY(bool nightMode READ nightMode WRITE setNightMode NOTIFY nightModeChanged)
0054     Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
0055     Q_PROPERTY(bool unread READ unread NOTIFY unreadChanged)
0056 public:
0057     explicit InstantMessagingController(DiceRoller* diceRoller, PlayerModel* player, QObject* parent= nullptr);
0058     virtual ~InstantMessagingController();
0059     InstantMessaging::ChatroomSplitterModel* mainModel() const;
0060     InstantMessaging::ChatRoom* globalChatroom() const;
0061     PlayerModel* playerModel() const;
0062     LocalPersonModel* localPersonModel() const;
0063     QString localId() const;
0064     bool nightMode() const;
0065     bool visible() const;
0066     bool unread() const;
0067 
0068     void setGameController(GameController*) override;
0069     NetWorkReceiver::SendType processMessage(NetworkMessageReader* msg) override;
0070 
0071 public slots:
0072     void addChatroomSplitterModel();
0073     void detach(const QString& id, int index);
0074     void reattach(const QString& id, int index);
0075     void splitScreen(const QString& id, int index);
0076     void setLocalId(const QString& id);
0077     void addExtraChatroom(const QString& title, bool everyone, const QVariantList& recipiant);
0078     void setNightMode(bool mode);
0079     void openLink(const QString& link);
0080     void setDiceParser(DiceRoller* diceParser);
0081     void setVisible(bool b);
0082 
0083 signals:
0084     void createdChatWindow(InstantMessaging::FilterInstantMessagingModel* model);
0085     void localIdChanged(QString);
0086     void nightModeChanged(bool);
0087     void openWebPage(QString);
0088     void visibleChanged(bool);
0089     void unreadChanged();
0090 
0091 private:
0092     std::unique_ptr<LocalPersonModel> m_localPersonModel;
0093     std::unique_ptr<InstantMessaging::InstantMessagingUpdater> m_updater;
0094     std::vector<std::unique_ptr<InstantMessaging::ChatroomSplitterModel>> m_splitterModels;
0095     std::unique_ptr<InstantMessaging::InstantMessagingModel> m_model;
0096     QPointer<PlayerModel> m_players;
0097     bool m_nightMode= false;
0098     int m_fontSizeFactor= false;
0099     QPointer<DiceRoller> m_diceParser;
0100     bool m_visible= false;
0101 };
0102 
0103 #endif // TEXTMESSAGINGCONTROLLER_H