Communi  3.3.0
A cross-platform IRC framework written with Qt
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Macros Groups Pages
ircbuffermodel.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2014 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 
63 public:
64  explicit IrcBufferModel(QObject* parent = 0);
65  virtual ~IrcBufferModel();
66 
67  IrcConnection* connection() const;
68  void setConnection(IrcConnection* connection);
69 
70  IrcNetwork* network() const;
71 
72  int count() const;
73  bool isEmpty() const;
74  QStringList channels() const;
75  QList<IrcBuffer*> buffers() const;
76  Q_INVOKABLE IrcBuffer* get(int index) const;
77  Q_INVOKABLE IrcBuffer* find(const QString& title) const;
78  Q_INVOKABLE bool contains(const QString& title) const;
79  Q_INVOKABLE int indexOf(IrcBuffer* buffer) const;
80 
81  Q_INVOKABLE IrcBuffer* add(const QString& title);
82  Q_INVOKABLE void add(IrcBuffer* buffer);
83  Q_INVOKABLE void remove(const QString& title);
84  Q_INVOKABLE void remove(IrcBuffer* buffer);
85 
86  Qt::SortOrder sortOrder() const;
87  void setSortOrder(Qt::SortOrder order);
88 
89  Irc::SortMethod sortMethod() const;
90  void setSortMethod(Irc::SortMethod method);
91 
92  Irc::DataRole displayRole() const;
93  void setDisplayRole(Irc::DataRole role);
94 
95  bool isPersistent() const;
96  void setPersistent(bool persistent);
97 
98  QModelIndex index(IrcBuffer* buffer) const;
99  IrcBuffer* buffer(const QModelIndex& index) const;
100 
101  QHash<int, QByteArray> roleNames() const;
102  int rowCount(const QModelIndex& parent = QModelIndex()) const;
103  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
104  QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
105 
106  IrcBuffer* bufferPrototype() const;
107  void setBufferPrototype(IrcBuffer* prototype);
108 
109  IrcChannel* channelPrototype() const;
110  void setChannelPrototype(IrcChannel* prototype);
111 
112  int joinDelay() const;
113  void setJoinDelay(int delay);
114 
115  Q_INVOKABLE QByteArray saveState(int version = 0) const;
116  Q_INVOKABLE bool restoreState(const QByteArray& state, int version = 0);
117 
118 public Q_SLOTS:
119  void clear();
120  void receiveMessage(IrcMessage* message);
121  void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
122  void sort(Irc::SortMethod method, Qt::SortOrder order = Qt::AscendingOrder);
123 
124 Q_SIGNALS:
125  void countChanged(int count);
126  void emptyChanged(bool empty);
127  void added(IrcBuffer* buffer);
128  void removed(IrcBuffer* buffer);
129  void aboutToBeAdded(IrcBuffer* buffer);
130  void aboutToBeRemoved(IrcBuffer* buffer);
131  void persistentChanged(bool persistent);
132  void buffersChanged(const QList<IrcBuffer*>& buffers);
133  void channelsChanged(const QStringList& channels);
134  void connectionChanged(IrcConnection* connection);
135  void networkChanged(IrcNetwork* network);
136  void messageIgnored(IrcMessage* message);
137  void bufferPrototypeChanged(IrcBuffer* prototype);
138  void channelPrototypeChanged(IrcChannel* prototype);
139  void destroyed(IrcBufferModel* model);
140  void joinDelayChanged(int delay);
141 
142 protected Q_SLOTS:
143  virtual IrcBuffer* createBuffer(const QString& title);
144  virtual IrcChannel* createChannel(const QString& title);
145 
146 protected:
147  virtual bool lessThan(IrcBuffer* one, IrcBuffer* another, Irc::SortMethod method) const;
148 
149 private:
150  friend class IrcBufferLessThan;
151  friend class IrcBufferGreaterThan;
152  QScopedPointer<IrcBufferModelPrivate> d_ptr;
153  Q_DECLARE_PRIVATE(IrcBufferModel)
154  Q_DISABLE_COPY(IrcBufferModel)
155 
156  Q_PRIVATE_SLOT(d_func(), void _irc_connected())
157  Q_PRIVATE_SLOT(d_func(), void _irc_disconnected())
158  Q_PRIVATE_SLOT(d_func(), void _irc_bufferDestroyed(IrcBuffer*))
159  Q_PRIVATE_SLOT(d_func(), void _irc_restoreBuffers())
160 };
161 
162 IRC_END_NAMESPACE
163 
164 #endif // IRCBUFFERMODEL_H
DataRole
Definition: irc.h:82
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