Communi  3.7.0
A cross-platform IRC framework written with Qt
ircbuffer.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2020 The Communi Project
3 
4  You may use this file under the terms of BSD license as follows:
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the names of its
14  contributors may be used to endorse or promote products derived
15  from this software without specific prior written permission.
16 
17  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
21  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef IRCBUFFER_H
30 #define IRCBUFFER_H
31 
32 #include <Irc>
33 #include <IrcGlobal>
34 #include <QtCore/qobject.h>
35 #include <QtCore/qvariant.h>
36 #include <QtCore/qmetatype.h>
37 #include <QtCore/qscopedpointer.h>
38 
39 IRC_BEGIN_NAMESPACE
40 
41 class IrcChannel;
42 class IrcCommand;
43 class IrcMessage;
44 class IrcNetwork;
45 class IrcConnection;
46 class IrcBufferModel;
47 class IrcBufferPrivate;
48 
49 class IRC_MODEL_EXPORT IrcBuffer : public QObject
50 {
51  Q_OBJECT
52  Q_PROPERTY(QString title READ title NOTIFY titleChanged)
53  Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
54  Q_PROPERTY(QString prefix READ prefix WRITE setPrefix NOTIFY prefixChanged)
55  Q_PROPERTY(IrcConnection* connection READ connection CONSTANT)
56  Q_PROPERTY(IrcNetwork* network READ network CONSTANT)
57  Q_PROPERTY(IrcBufferModel* model READ model CONSTANT)
58  Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
59  Q_PROPERTY(bool channel READ isChannel CONSTANT)
60  Q_PROPERTY(bool sticky READ isSticky WRITE setSticky NOTIFY stickyChanged)
61  Q_PROPERTY(bool persistent READ isPersistent WRITE setPersistent NOTIFY persistentChanged)
62  Q_PROPERTY(QVariantMap userData READ userData WRITE setUserData NOTIFY userDataChanged)
63 
64 public:
65  enum Type
66  {
67  Basic = 0,
68  Channel,
69  Custom
70  };
71  Q_ENUM(Type)
72 
73  Q_INVOKABLE explicit IrcBuffer(QObject* parent = nullptr);
74  ~IrcBuffer() override;
75 
76  QString title() const;
77  QString name() const;
78  QString prefix() const;
79 
80  bool isChannel() const;
81  Q_INVOKABLE IrcChannel* toChannel();
82 
83  IrcConnection* connection() const;
84  IrcNetwork* network() const;
85  IrcBufferModel* model() const;
86 
87  virtual bool isActive() const;
88 
89  bool isSticky() const;
90  void setSticky(bool sticky);
91 
92  bool isPersistent() const;
93  void setPersistent(bool persistent);
94 
95  QVariantMap userData() const;
96  void setUserData(const QVariantMap& data);
97 
98  Q_INVOKABLE bool sendCommand(IrcCommand* command);
99 
100  virtual IrcBuffer *clone(QObject* parent = nullptr);
101 
102 public Q_SLOTS:
103  void setName(const QString& name);
104  void setPrefix(const QString& prefix);
105  void receiveMessage(IrcMessage* message);
106  virtual void close(const QString& reason = QString());
107 
108 Q_SIGNALS:
109  void titleChanged(const QString& title);
110  void nameChanged(const QString& name);
111  void prefixChanged(const QString& name);
112  void messageReceived(IrcMessage* message);
113  void destroyed(IrcBuffer* buffer);
114  void activeChanged(bool active);
115  void stickyChanged(bool sticky);
116  void persistentChanged(bool persistent);
117  void userDataChanged(const QVariantMap& data);
118 
119 protected:
120  IrcBuffer(IrcBufferPrivate& dd, QObject* parent);
121 
122  QScopedPointer<IrcBufferPrivate> d_ptr;
123  Q_DECLARE_PRIVATE(IrcBuffer)
124  Q_DISABLE_COPY(IrcBuffer)
125 };
126 
127 #ifndef QT_NO_DEBUG_STREAM
128 IRC_MODEL_EXPORT QDebug operator<<(QDebug debug, const IrcBuffer* buffer);
129 #endif // QT_NO_DEBUG_STREAM
130 
131 IRC_END_NAMESPACE
132 
133 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcBuffer*))
134 Q_DECLARE_METATYPE(QList<IRC_PREPEND_NAMESPACE(IrcBuffer*)>)
135 
136 #endif // IRCBUFFER_H
Keeps track of buffers.
Definition: ircbuffermodel.h:48
Keeps track of buffer status.
Definition: ircbuffer.h:50
void messageReceived(IrcMessage *message)
Keeps track of channel status.
Definition: ircchannel.h:41
Provides the most common commands.
Definition: irccommand.h:45
Provides means to establish a connection to an IRC server.
Definition: ircconnection.h:49
The base class of all messages.
Definition: ircmessage.h:48
Provides network information and capability management.
Definition: ircnetwork.h:44