File indexing completed on 2024-05-12 05:40:23

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 MESSAGEINTERFACE_H
0021 #define MESSAGEINTERFACE_H
0022 
0023 #include "im_global.h"
0024 
0025 #include <QDateTime>
0026 #include <QObject>
0027 #include <QUrl>
0028 
0029 namespace InstantMessaging
0030 {
0031 class IM_EXPORT MessageInterface : public QObject
0032 {
0033     Q_OBJECT
0034     Q_PROPERTY(MessageType type READ type CONSTANT)
0035     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
0036     Q_PROPERTY(QString owner READ owner CONSTANT)   // Player only
0037     Q_PROPERTY(QString writer READ writer CONSTANT) // player or one of its character.
0038     Q_PROPERTY(QDateTime dateTime READ dateTime CONSTANT)
0039     Q_PROPERTY(QUrl imageLink READ imageLink WRITE setImageLink NOTIFY imageLinkChanged)
0040 public:
0041     enum MessageType
0042     {
0043         Text,
0044         Dice,
0045         Command,
0046         Error,
0047     };
0048     Q_ENUM(MessageType)
0049     explicit MessageInterface(QObject* parent= nullptr);
0050 
0051     virtual MessageType type() const= 0;
0052     virtual QString text() const= 0;
0053     virtual QString owner() const= 0;
0054     virtual QDateTime dateTime() const= 0;
0055     virtual QString writer() const= 0;
0056     virtual QUrl imageLink() const= 0;
0057 
0058 public slots:
0059     virtual void setText(const QString& text)= 0;
0060     virtual void setImageLink(const QUrl& path)= 0;
0061 
0062 signals:
0063     void textChanged();
0064     void imageLinkChanged();
0065 };
0066 
0067 class IM_EXPORT MessageBase : public MessageInterface
0068 {
0069     Q_OBJECT
0070 public:
0071     explicit MessageBase(const QString& owner, const QString& writer, const QDateTime& time, MessageType type,
0072                          QObject* parent= nullptr);
0073     QString owner() const override;
0074     QDateTime dateTime() const override;
0075     MessageType type() const override;
0076     QString writer() const override;
0077     QUrl imageLink() const override;
0078 
0079 public slots:
0080     void setImageLink(const QUrl& path) override;
0081 
0082 private:
0083     QString m_ownerId;
0084     QDateTime m_time;
0085     MessageType m_type;
0086     QString m_writer;
0087     QUrl m_imageLink;
0088 };
0089 } // namespace InstantMessaging
0090 #endif // MESSAGEINTERFACE_H