1 /*
2  * Copyright (C) 2008-2020 The Communi Project
3  *
4  * This example is free, and not covered by the BSD license. There is no
5  * restriction applied to their modification, redistribution, using and so on.
6  * You can study them, modify them, use them in your own program - either
7  * completely or partially.
8  */
9 
10 #ifndef IRCCLIENT_H
11 #define IRCCLIENT_H
12 
13 #include <QSplitter>
14 #include <QHash>
15 
16 class IrcBuffer;
17 class IrcMessage;
18 class IrcUserModel;
19 class IrcCompleter;
20 class IrcConnection;
21 class IrcBufferModel;
22 class IrcCommandParser;
23 
24 QT_FORWARD_DECLARE_CLASS(QLineEdit)
QT_FORWARD_DECLARE_CLASS(QListView)25 QT_FORWARD_DECLARE_CLASS(QListView)
26 QT_FORWARD_DECLARE_CLASS(QTextEdit)
27 QT_FORWARD_DECLARE_CLASS(QModelIndex)
28 QT_FORWARD_DECLARE_CLASS(QTextDocument)
29 
30 class IrcClient : public QSplitter
31 {
32     Q_OBJECT
33 
34 public:
35     IrcClient(QWidget* parent = nullptr);
36     ~IrcClient() override;
37 
38 private slots:
39     void onConnected();
40     void onConnecting();
41     void onDisconnected();
42 
43     void onTextEdited();
44     void onTextEntered();
45 
46     void onCompletion();
47     void onCompleted(const QString& text, int cursor);
48 
49     void onBufferAdded(IrcBuffer* buffer);
50     void onBufferRemoved(IrcBuffer* buffer);
51 
52     void onBufferActivated(const QModelIndex& index);
53     void onUserActivated(const QModelIndex& index);
54 
55     void receiveMessage(IrcMessage* message);
56 
57 private:
58     void createLayout();
59     void createCompleter();
60     void createParser();
61     void createUserList();
62     void createBufferList();
63     void createConnection();
64 
65     QLineEdit* lineEdit;
66     QTextEdit* textEdit;
67     QListView* userList;
68     QListView* bufferList;
69 
70     IrcCompleter* completer;
71     IrcCommandParser* parser;
72     IrcConnection* connection;
73     IrcBufferModel* bufferModel;
74     QHash<IrcBuffer*, IrcUserModel*> userModels;
75     QHash<IrcBuffer*, QTextDocument*> documents;
76 };
77 
78 #endif // IRCCLIENT_H
79