KVIrc 5.2.6
Developer APIs
KviIrcContext.h
Go to the documentation of this file.
1#ifndef _KVI_IRCCONTEXT_H_
2#define _KVI_IRCCONTEXT_H_
3//=============================================================================
4//
5// File : KviIrcContext.h
6// Creation date : Sun 09 May 2004 20:37:46 by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2004-2010 Szymon Stefanek <pragma at kvirc dot net>
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
27#include "kvi_settings.h"
28
29#include <QObject>
30#include <vector>
31
33class KviQueryWindow;
34class KviQueryWindow;
35class KviMainWindow;
40class KviWindow;
41class QTimer;
43class KviIrcNetwork;
44class KviIrcServer;
45/*
46 KviIrcContext is the structure that groups the objects and resources
47 usable for a single irc connection: a console, a set of channels and queries,
48 and a KviIrcConnection object.
49
50 The objects grouped here are mostly permanent across connections.
51
52 Each irc context has its own unique numeric identifier. The identifiers start
53 from 1 so 0 is an invalid irc context id (this is useful in the scripting engine).
54
55 The irc context is created in the KviConsoleWindow constructor and destroyed
56 in the KviConsoleWindow destructor. No other class can allocate KviIrcContext objects.
57*/
58
59class KVIRC_API KviIrcContext : public QObject
60{
61 friend class KviConsoleWindow;
62 friend class KviChannelWindow;
63 friend class KviQueryWindow;
64 friend class KviIrcConnection;
66 Q_OBJECT
67protected:
68 KviIrcContext(KviConsoleWindow * pConsole); // only KviConsoleWindow can create this
69public:
71
72public:
73 /* If you add further states, remember to update the
74 * bUnexpectedDisconnect determination in KviIrcContext::connectionTerminated */
75 enum State
76 {
77 Idle, // connection() == 0
78 PendingReconnection, // connection() == 0
79 Connecting, // connection() != 0
80 LoggingIn, // connection() != 0
81 Connected // connection() != 0
82 };
83
84protected:
85 KviConsoleWindow * m_pConsole; // shallow, never null
87
88 unsigned int m_uId; // this irc context id
89
90 State m_eState = Idle; // this context state
91
92 // permanent links and list window
95
97 KviAsynchronousConnectionData * m_pSavedAsynchronousConnectionData = nullptr; // owned, may be null, this is used to reconnect to the last server in this context
98
99 unsigned int m_uConnectAttemptCount = 1;
100 QTimer * m_pReconnectTimer = nullptr;
101
102 std::vector<KviIrcDataStreamMonitor *> m_pMonitorList; // owned, may be empty
103
104 // dead channels and queries
105 std::vector<KviChannelWindow *> m_DeadChannels;
106 std::vector<KviQueryWindow *> m_DeadQueries;
107 // other context bound windows
108 std::vector<KviWindow *> m_ContextWindows;
109
111
112public:
113 unsigned int id() const { return m_uId; }
114 // never null and always the same!
115 KviConsoleWindow * console() const { return m_pConsole; }
116 // may be null and may change!
118 // state
119 State state() const { return m_eState; }
120 bool isConnected() const { return m_eState == Connected; }
121 bool isLoggingIn() const { return m_eState == LoggingIn; }
122 // dead channels and queries
123 bool unregisterDeadChannel(KviChannelWindow * c);
124 bool unregisterDeadQuery(KviQueryWindow * q);
125 void registerDeadChannel(KviChannelWindow * c);
126 void registerDeadQuery(KviQueryWindow * q);
127 KviChannelWindow * findDeadChannel(const QString & name);
128 KviQueryWindow * findDeadQuery(const QString & nick);
129 KviQueryWindow * firstDeadQuery();
130 KviChannelWindow * firstDeadChannel();
131 // other windows bound to the context
132 void closeAllContextWindows();
133 void registerContextWindow(KviWindow * pWnd);
134 bool unregisterContextWindow(KviWindow * pWnd);
135
136 std::vector<KviIrcDataStreamMonitor *> & monitorList() { return m_pMonitorList; }
137
138 // links window
139 void createLinksWindow();
142
143 // list window
144 void createListWindow();
147
148 void setAsynchronousConnectionData(KviAsynchronousConnectionData * d);
150 void destroyAsynchronousConnectionData();
151 // used by KviConsoleWindow (for now) and KviUserParser
152 void connectToCurrentServer();
153
154 void beginAsynchronousConnect(unsigned int uDelayInMSecs);
155
156 void registerDataStreamMonitor(KviIrcDataStreamMonitor * m);
157 void unregisterDataStreamMonitor(KviIrcDataStreamMonitor * m);
158
159 void terminateConnectionRequest(bool bForce, const QString & szQuitMessage = QString(), bool bSimulateUnexpectedDisconnect = false);
160 void abortReconnect();
161public slots:
162 void closeAllDeadChannels();
163 void closeAllDeadQueries();
164
165protected:
166 // called by KviIrcContextToolBar: this will DIE in favor of connectOrDisconnect()
167 void connectButtonClicked();
168 // used by KviConsoleWindow (for now)
169 void destroyConnection();
170 // for KviConsoleWindow (for now) . later will be used only internally
171 void setState(State eState);
172 // called by KviIrcConnection
173 void loginComplete();
174 // our heartbeat timer event
175 void timerEvent(QTimerEvent * e) override;
176
177public:
179protected:
180 //
181 // KviIrcConnection interface
182 //
183 void connectionFailed(int iError);
184 void connectionEstablished();
185 void connectionTerminated();
186signals:
188protected slots:
189 void asynchronousConnect();
190};
191
192#endif
State
Definition NotifierSettings.h:62
Definition KviAsynchronousConnectionData.h:33
The class which manages a channel.
Definition KviChannelWindow.h:108
Definition KviConsoleWindow.h:74
Definition KviIrcServerParser.h:102
An abstraction of a connection to an IRC server.
Definition KviIrcConnection.h:97
friend class KviIrcConnection
Definition KviIrcContext.h:64
std::vector< KviWindow * > m_ContextWindows
Definition KviIrcContext.h:108
unsigned int m_uId
Definition KviIrcContext.h:88
KviConsoleWindow * console() const
Definition KviIrcContext.h:115
void connectOrDisconnect()
Definition KviIrcContext.h:178
friend class KviIrcContextToolBar
Definition KviIrcContext.h:65
void setListWindowPointer(KviExternalServerDataParser *l)
Definition KviIrcContext.h:145
void stateChanged()
State
Definition KviIrcContext.h:76
@ Connecting
Definition KviIrcContext.h:79
@ PendingReconnection
Definition KviIrcContext.h:78
@ LoggingIn
Definition KviIrcContext.h:80
@ Idle
Definition KviIrcContext.h:77
@ Connected
Definition KviIrcContext.h:81
std::vector< KviIrcDataStreamMonitor * > & monitorList()
Definition KviIrcContext.h:136
bool isConnected() const
Definition KviIrcContext.h:120
State state() const
Definition KviIrcContext.h:119
KviIrcContext(KviConsoleWindow *pConsole)
Definition KviIrcContext.cpp:71
std::vector< KviChannelWindow * > m_DeadChannels
Definition KviIrcContext.h:105
std::vector< KviQueryWindow * > m_DeadQueries
Definition KviIrcContext.h:106
KviExternalServerDataParser * m_pLinksWindow
Definition KviIrcContext.h:93
std::vector< KviIrcDataStreamMonitor * > m_pMonitorList
Definition KviIrcContext.h:102
KviIrcConnection * connection() const
Definition KviIrcContext.h:117
friend class KviQueryWindow
Definition KviIrcContext.h:63
KviIrcConnection * m_pConnection
Definition KviIrcContext.h:86
void asynchronousConnect()
Definition KviIrcContext.cpp:744
QTimer * m_pReconnectTimer
Definition KviIrcContext.h:100
State m_eState
Definition KviIrcContext.h:90
friend class KviConsoleWindow
Definition KviIrcContext.h:61
KviConsoleWindow * m_pConsole
Definition KviIrcContext.h:85
unsigned int id() const
Definition KviIrcContext.h:113
void connectButtonClicked()
Definition KviIrcContext.cpp:321
KviExternalServerDataParser * linksWindow() const
Definition KviIrcContext.h:141
void setLinksWindowPointer(KviExternalServerDataParser *l)
Definition KviIrcContext.h:140
KviAsynchronousConnectionData * m_pAsynchronousConnectionData
Definition KviIrcContext.h:96
int m_iHeartbeatTimerId
Definition KviIrcContext.h:110
KviAsynchronousConnectionData * asynchronousConnectionData() const
Definition KviIrcContext.h:149
KviAsynchronousConnectionData * m_pSavedAsynchronousConnectionData
Definition KviIrcContext.h:97
KviExternalServerDataParser * listWindow() const
Definition KviIrcContext.h:146
unsigned int m_uConnectAttemptCount
Definition KviIrcContext.h:99
KviExternalServerDataParser * m_pListWindow
Definition KviIrcContext.h:94
friend class KviChannelWindow
Definition KviIrcContext.h:62
bool isLoggingIn() const
Definition KviIrcContext.h:121
Definition KviIrcDataStreamMonitor.h:33
Network handling class.
Definition KviIrcNetwork.h:48
The class which manages the irc servers.
Definition KviIrcServer.h:52
Definition KviMainWindow.h:58
The class which manages a query.
Definition KviQueryWindow.h:50
Base class for all windows in KVIrc.
Definition KviWindow.h:75
#define m
Definition detector.cpp:78
#define d
Definition detector.cpp:69
#define e
Definition detector.cpp:70
#define l
Definition detector.cpp:77
#define q
Definition detector.cpp:82
This file contains compile time settings.
#define KVIRC_API
Definition kvi_settings.h:127