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