Communi  3.5.0
A cross-platform IRC framework written with Qt
ircbuffermodel.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2016 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 IRCBUFFERMODEL_H
30 #define IRCBUFFERMODEL_H
31 
32 #include <Irc>
33 #include <IrcGlobal>
34 #include <QtCore/qmetatype.h>
35 #include <QtCore/qstringlist.h>
36 #include <QtCore/qabstractitemmodel.h>
37 
38 IRC_BEGIN_NAMESPACE
39 
40 class IrcBuffer;
41 class IrcChannel;
42 class IrcMessage;
43 class IrcNetwork;
44 class IrcConnection;
45 class IrcBufferModelPrivate;
46 
47 class IRC_MODEL_EXPORT IrcBufferModel : public QAbstractListModel
48 {
49  Q_OBJECT
50  Q_PROPERTY(int count READ count NOTIFY countChanged)
51  Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
52  Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder)
53  Q_PROPERTY(Irc::SortMethod sortMethod READ sortMethod WRITE setSortMethod)
54  Q_PROPERTY(QStringList channels READ channels NOTIFY channelsChanged)
55  Q_PROPERTY(Irc::DataRole displayRole READ displayRole WRITE setDisplayRole)
56  Q_PROPERTY(bool persistent READ isPersistent WRITE setPersistent NOTIFY persistentChanged)
57  Q_PROPERTY(QList<IrcBuffer*> buffers READ buffers NOTIFY buffersChanged)
58  Q_PROPERTY(IrcConnection* connection READ connection WRITE setConnection NOTIFY connectionChanged)
59  Q_PROPERTY(IrcNetwork* network READ network NOTIFY networkChanged)
60  Q_PROPERTY(IrcBuffer* bufferPrototype READ bufferPrototype WRITE setBufferPrototype NOTIFY bufferPrototypeChanged)
61  Q_PROPERTY(IrcChannel* channelPrototype READ channelPrototype WRITE setChannelPrototype NOTIFY channelPrototypeChanged)
62  Q_PROPERTY(int joinDelay READ joinDelay WRITE setJoinDelay NOTIFY joinDelayChanged)
63  Q_PROPERTY(bool monitorEnabled READ isMonitorEnabled WRITE setMonitorEnabled NOTIFY monitorEnabledChanged)
64 
65 public:
66  explicit IrcBufferModel(QObject* parent = 0);
67  virtual ~IrcBufferModel();
68 
69  IrcConnection* connection() const;
70  void setConnection(IrcConnection* connection);
71 
72  IrcNetwork* network() const;
73 
74  int count() const;
75  bool isEmpty() const;
76  QStringList channels() const;
77  QList<IrcBuffer*> buffers() const;
78  Q_INVOKABLE IrcBuffer* get(int index) const;
79  Q_INVOKABLE IrcBuffer* find(const QString& title) const;
80  Q_INVOKABLE bool contains(const QString& title) const;
81  Q_INVOKABLE int indexOf(IrcBuffer* buffer) const;
82 
83  Q_INVOKABLE IrcBuffer* add(const QString& title);
84  Q_INVOKABLE void add(IrcBuffer* buffer);
85  Q_INVOKABLE void remove(const QString& title);
86  Q_INVOKABLE void remove(IrcBuffer* buffer);
87 
88  Qt::SortOrder sortOrder() const;
89  void setSortOrder(Qt::SortOrder order);
90 
91  Irc::SortMethod sortMethod() const;
92  void setSortMethod(Irc::SortMethod method);
93 
94  Irc::DataRole displayRole() const;
95  void setDisplayRole(Irc::DataRole role);
96 
97  bool isPersistent() const;
98  void setPersistent(bool persistent);
99 
100  QModelIndex index(IrcBuffer* buffer) const;
101  IrcBuffer* buffer(const QModelIndex& index) const;
102 
103  QHash<int, QByteArray> roleNames() const;
104  int rowCount(const QModelIndex& parent = QModelIndex()) const;
105  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
106  QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
107 
108  IrcBuffer* bufferPrototype() const;
109  void setBufferPrototype(IrcBuffer* prototype);
110 
111  IrcChannel* channelPrototype() const;
112  void setChannelPrototype(IrcChannel* prototype);
113 
114  int joinDelay() const;
115  void setJoinDelay(int delay);
116 
117  bool isMonitorEnabled() const;
118  void setMonitorEnabled(bool enabled);
119 
120  Q_INVOKABLE QByteArray saveState(int version = 0) const;
121  Q_INVOKABLE bool restoreState(const QByteArray& state, int version = 0);
122 
123 public Q_SLOTS:
124  void clear();
125  void receiveMessage(IrcMessage* message);
126  void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
127  void sort(Irc::SortMethod method, Qt::SortOrder order = Qt::AscendingOrder);
128 
129 Q_SIGNALS:
130  void countChanged(int count);
131  void emptyChanged(bool empty);
132  void added(IrcBuffer* buffer);
133  void removed(IrcBuffer* buffer);
134  void aboutToBeAdded(IrcBuffer* buffer);
135  void aboutToBeRemoved(IrcBuffer* buffer);
136  void persistentChanged(bool persistent);
137  void buffersChanged(const QList<IrcBuffer*>& buffers);
138  void channelsChanged(const QStringList& channels);
139  void connectionChanged(IrcConnection* connection);
140  void networkChanged(IrcNetwork* network);
141  void messageIgnored(IrcMessage* message);
142  void bufferPrototypeChanged(IrcBuffer* prototype);
143  void channelPrototypeChanged(IrcChannel* prototype);
144  void destroyed(IrcBufferModel* model);
145  void joinDelayChanged(int delay);
146  void monitorEnabledChanged(bool enabled);
147 
148 protected Q_SLOTS:
149  virtual IrcBuffer* createBuffer(const QString& title);
150  virtual IrcChannel* createChannel(const QString& title);
151 
152 protected:
153  virtual bool lessThan(IrcBuffer* one, IrcBuffer* another, Irc::SortMethod method) const;
154 
155 private:
156  friend class IrcBufferLessThan;
157  friend class IrcBufferGreaterThan;
158  QScopedPointer<IrcBufferModelPrivate> d_ptr;
159  Q_DECLARE_PRIVATE(IrcBufferModel)
160  Q_DISABLE_COPY(IrcBufferModel)
161 
162  Q_PRIVATE_SLOT(d_func(), void _irc_connected())
163  Q_PRIVATE_SLOT(d_func(), void _irc_initialized())
164  Q_PRIVATE_SLOT(d_func(), void _irc_disconnected())
165  Q_PRIVATE_SLOT(d_func(), void _irc_bufferDestroyed(IrcBuffer*))
166  Q_PRIVATE_SLOT(d_func(), void _irc_restoreBuffers())
167  Q_PRIVATE_SLOT(d_func(), void _irc_monitorStatus())
168 };
169 
170 IRC_END_NAMESPACE
171 
172 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcBufferModel*))
173 
174 #endif // IRCBUFFERMODEL_H
Provides means to establish a connection to an IRC server.
Definition: ircconnection.h:48
Provides network information and capability management.
Definition: ircnetwork.h:43
Keeps track of buffer status.
Definition: ircbuffer.h:49
Keeps track of channel status.
Definition: ircchannel.h:40
Keeps track of buffers.
Definition: ircbuffermodel.h:47
The base class of all messages.
Definition: ircmessage.h:47
Miscellaneous identifiers used throughout the library.
Definition: irc.h:39