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