Communi  3.0.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-2013 The Communi Project
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
13 */
14 
15 #ifndef IRCBUFFERMODEL_H
16 #define IRCBUFFERMODEL_H
17 
18 #include <Irc>
19 #include <IrcGlobal>
20 #include <QtCore/qstringlist.h>
21 #include <QtCore/qabstractitemmodel.h>
22 
23 IRC_BEGIN_NAMESPACE
24 
25 class IrcBuffer;
26 class IrcChannel;
27 class IrcMessage;
28 class IrcNetwork;
29 class IrcConnection;
30 class IrcBufferModelPrivate;
31 
32 class IRC_MODEL_EXPORT IrcBufferModel : public QAbstractListModel
33 {
34  Q_OBJECT
35  Q_PROPERTY(int count READ count NOTIFY countChanged)
36  Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder)
37  Q_PROPERTY(Irc::SortMethod sortMethod READ sortMethod WRITE setSortMethod)
38  Q_PROPERTY(QStringList channels READ channels NOTIFY channelsChanged)
39  Q_PROPERTY(Irc::DataRole displayRole READ displayRole WRITE setDisplayRole)
40  Q_PROPERTY(QList<IrcBuffer*> buffers READ buffers NOTIFY buffersChanged)
41  Q_PROPERTY(IrcConnection* connection READ connection WRITE setConnection NOTIFY connectionChanged)
42  Q_PROPERTY(IrcNetwork* network READ network NOTIFY networkChanged)
43  Q_PROPERTY(IrcBuffer* bufferPrototype READ bufferPrototype WRITE setBufferPrototype NOTIFY bufferPrototypeChanged)
44  Q_PROPERTY(IrcChannel* channelPrototype READ channelPrototype WRITE setChannelPrototype NOTIFY channelPrototypeChanged)
45 
46 public:
47  explicit IrcBufferModel(QObject* parent = 0);
48  virtual ~IrcBufferModel();
49 
50  IrcConnection* connection() const;
51  void setConnection(IrcConnection* connection);
52 
53  IrcNetwork* network() const;
54 
55  int count() const;
56  QStringList channels() const;
57  QList<IrcBuffer*> buffers() const;
58  Q_INVOKABLE IrcBuffer* get(int index) const;
59  Q_INVOKABLE IrcBuffer* find(const QString& title) const;
60  Q_INVOKABLE bool contains(const QString& title) const;
61  Q_INVOKABLE int indexOf(IrcBuffer* buffer) const;
62 
63  Q_INVOKABLE IrcBuffer* add(const QString& title);
64  Q_INVOKABLE void add(IrcBuffer* buffer);
65  Q_INVOKABLE void remove(const QString& title);
66  Q_INVOKABLE void remove(IrcBuffer* buffer);
67 
68  Qt::SortOrder sortOrder() const;
69  void setSortOrder(Qt::SortOrder order);
70 
71  Irc::SortMethod sortMethod() const;
72  void setSortMethod(Irc::SortMethod method);
73 
74  Irc::DataRole displayRole() const;
75  void setDisplayRole(Irc::DataRole role);
76 
77  QModelIndex index(IrcBuffer* buffer) const;
78  IrcBuffer* buffer(const QModelIndex& index) const;
79 
80  QHash<int, QByteArray> roleNames() const;
81  int rowCount(const QModelIndex& parent = QModelIndex()) const;
82  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
83  QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
84 
85  IrcBuffer* bufferPrototype() const;
86  void setBufferPrototype(IrcBuffer* prototype);
87 
88  IrcChannel* channelPrototype() const;
89  void setChannelPrototype(IrcChannel* prototype);
90 
91 public Q_SLOTS:
92  void clear();
93  void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
94  void sort(Irc::SortMethod method, Qt::SortOrder order = Qt::AscendingOrder);
95 
96 Q_SIGNALS:
97  void countChanged(int count);
98  void added(IrcBuffer* buffer);
99  void removed(IrcBuffer* buffer);
100  void aboutToBeAdded(IrcBuffer* buffer);
101  void aboutToBeRemoved(IrcBuffer* buffer);
102  void buffersChanged(const QList<IrcBuffer*>& buffers);
103  void channelsChanged(const QStringList& channels);
104  void connectionChanged(IrcConnection* connection);
105  void networkChanged(IrcNetwork* network);
106  void messageIgnored(IrcMessage* message);
107  void bufferPrototypeChanged(IrcBuffer* prototype);
108  void channelPrototypeChanged(IrcChannel* prototype);
109 
110 protected Q_SLOTS:
111  virtual IrcBuffer* createBuffer(const QString& title);
112  virtual IrcChannel* createChannel(const QString& title);
113 
114 protected:
115  virtual bool lessThan(IrcBuffer* one, IrcBuffer* another, Irc::SortMethod method) const;
116 
117 private:
118  friend class IrcBufferLessThan;
119  friend class IrcBufferGreaterThan;
120  QScopedPointer<IrcBufferModelPrivate> d_ptr;
121  Q_DECLARE_PRIVATE(IrcBufferModel)
122  Q_DISABLE_COPY(IrcBufferModel)
123 
124  Q_PRIVATE_SLOT(d_func(), void _irc_connectionStatusChanged())
125  Q_PRIVATE_SLOT(d_func(), void _irc_bufferDestroyed(IrcBuffer*))
126 };
127 
128 IRC_END_NAMESPACE
129 
130 #endif // IRCBUFFERMODEL_H
Keeps track of channel status.
Definition: ircchannel.h:26
SortMethod
Definition: irc.h:78
Keeps track of buffer status.
Definition: ircbuffer.h:34
Provides means to establish a connection to an IRC server.
Definition: ircconnection.h:32
The base class of all messages.
Definition: ircmessage.h:32
DataRole
Definition: irc.h:68
Keeps track of buffers.
Definition: ircbuffermodel.h:32
Provides network information and capability management.
Definition: ircnetwork.h:29