KVIrc  4.9.2
DeveloperAPIs
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 #include "KviPointerList.h"
29 #include <QObject>
30 
31 class KviChannelWindow;
32 class KviQueryWindow;
33 class KviQueryWindow;
34 class KviMainWindow;
35 class KviIrcConnection;
39 class KviWindow;
40 class QTimer;
41 class KviConsoleWindow;
42 class KviIrcNetwork;
43 class KviIrcServer;
44 /*
45  KviIrcContext is the structure that groups the objects and resources
46  usable for a single irc connection: a console, a set of channels and queries,
47  and a KviIrcConnection object.
48 
49  The objects grouped here are mostly permanent across connections.
50 
51  Each irc context has its own unique numeric identifier. The identifiers start
52  from 1 so 0 is an invalid irc context id (this is useful in the scripting engine).
53 
54  The irc context is created in the KviConsoleWindow constructor and destroyed
55  in the KviConsoleWindow destructor. No other class can allocate KviIrcContext objects.
56 */
57 
58 class KVIRC_API KviIrcContext : public QObject
59 {
60  friend class KviConsoleWindow;
61  friend class KviChannelWindow;
62  friend class KviQueryWindow;
63  friend class KviIrcConnection;
64  friend class KviIrcContextToolBar;
65  Q_OBJECT
66 protected:
67  KviIrcContext(KviConsoleWindow * pConsole); // only KviConsoleWindow can create this
68 public:
69  ~KviIrcContext();
70 
71 public:
72  /* If you add further states, remember to update the
73  * bUnexpectedDisconnect determination in KviIrcContext::connectionTerminated */
74  enum State
75  {
76  Idle, // connection() == 0
77  PendingReconnection, // connection() == 0
78  Connecting, // connection() != 0
79  LoggingIn, // connection() != 0
80  Connected // connection() != 0
81  };
82 
83 protected:
84  KviConsoleWindow * m_pConsole; // shallow, never null
86 
87  unsigned int m_uId; // this irc context id
88 
89  State m_eState; // this context state
90 
91  // permanent links and list window
94 
96  KviAsynchronousConnectionData * m_pSavedAsynchronousConnectionData; // owned, may be null, this is used to reconnect to the last server in this context
97 
98  unsigned int m_uConnectAttemptCount;
100 
102 
103  // dead channels and queries
106  // other context bound windows
108 
110 
111 public:
112  inline unsigned int id() { return m_uId; };
113  // never null and always the same!
114  inline KviConsoleWindow * console() { return m_pConsole; };
115  // may be null and may change!
116  inline KviIrcConnection * connection() { return m_pConnection; };
117  // state
118  inline State state() { return m_eState; };
119  inline bool isConnected() { return m_eState == Connected; };
120  inline bool isLoggingIn() { return m_eState == LoggingIn; };
121  // dead channels and queries
122  bool unregisterDeadChannel(KviChannelWindow * c);
123  bool unregisterDeadQuery(KviQueryWindow * q);
124  void registerDeadChannel(KviChannelWindow * c);
125  void registerDeadQuery(KviQueryWindow * q);
126  KviChannelWindow * findDeadChannel(const QString & name);
127  KviQueryWindow * findDeadQuery(const QString & nick);
128  KviQueryWindow * firstDeadQuery();
129  KviChannelWindow * firstDeadChannel();
130  // other windows bound to the context
131  void closeAllContextWindows();
132  void registerContextWindow(KviWindow * pWnd);
133  bool unregisterContextWindow(KviWindow * pWnd);
134 
135  inline KviPointerList<KviIrcDataStreamMonitor> * monitorList() { return m_pMonitorList; };
136 
137  // links window
138  void createLinksWindow();
139  inline void setLinksWindowPointer(KviExternalServerDataParser * l) { m_pLinksWindow = l; };
140  inline KviExternalServerDataParser * linksWindow() { return m_pLinksWindow; };
141 
142  // list window
143  void createListWindow();
144  inline void setListWindowPointer(KviExternalServerDataParser * l) { m_pListWindow = l; };
145  inline KviExternalServerDataParser * listWindow() { return m_pListWindow; };
146 
147  void setAsynchronousConnectionData(KviAsynchronousConnectionData * d);
148  inline KviAsynchronousConnectionData * asynchronousConnectionData() { return m_pAsynchronousConnectionData; };
149  void destroyAsynchronousConnectionData();
150  // used by KviConsoleWindow (for now) and KviUserParser
151  void connectToCurrentServer();
152 
153  void beginAsynchronousConnect(unsigned int uDelayInMSecs);
154 
155  void registerDataStreamMonitor(KviIrcDataStreamMonitor * m);
156  void unregisterDataStreamMonitor(KviIrcDataStreamMonitor * m);
157 
158  void terminateConnectionRequest(bool bForce, const QString & szQuitMessage = QString(), bool bSimulateUnexpectedDisconnect = false);
159 public slots:
160  void closeAllDeadChannels();
161  void closeAllDeadQueries();
162 
163 protected:
164  // called by KviIrcContextToolBar: this will DIE in favor of connectOrDisconnect()
165  void connectButtonClicked();
166  // used by KviConsoleWindow (for now)
167  void destroyConnection();
168  // for KviConsoleWindow (for now) . later will be used only internally
169  void setState(State eState);
170  // called by KviIrcConnection
171  void loginComplete();
172  // our heartbeat timer event
173  virtual void timerEvent(QTimerEvent * e);
174 
175 public:
176  void connectOrDisconnect() { connectButtonClicked(); };
177 protected:
178  //
179  // KviIrcConnection interface
180  //
181  void connectionFailed(int iError);
182  void connectionEstablished();
183  void connectionTerminated();
184 signals:
185  void stateChanged();
186 protected slots:
187  void asynchronousConnect();
188 };
189 
190 #endif
KviAsynchronousConnectionData * asynchronousConnectionData()
Definition: KviIrcContext.h:148
void connectOrDisconnect()
Definition: KviIrcContext.h:176
Definition: KviIrcContext.h:77
Definition: KviIrcContext.h:78
Definition: KviMainWindow.h:60
Definition: KviConsoleWindow.h:75
Definition: KviAsynchronousConnectionData.h:32
The class which manages the irc servers.
Definition: KviIrcServer.h:51
#define KVIRC_API
Definition: kvi_settings.h:128
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
KviPointerList< KviIrcDataStreamMonitor > * monitorList()
Definition: KviIrcContext.h:135
KviExternalServerDataParser * m_pListWindow
Definition: KviIrcContext.h:93
int m_iHeartbeatTimerId
Definition: KviIrcContext.h:109
#define m
Definition: detector.cpp:77
State
Definition: NotifierSettings.h:61
#define l
Definition: detector.cpp:76
An abstraction of a connection to an IRC server.
Definition: KviIrcConnection.h:95
bool isConnected()
Definition: KviIrcContext.h:119
KviConsoleWindow * m_pConsole
Definition: KviIrcContext.h:84
State m_eState
Definition: KviIrcContext.h:89
void setLinksWindowPointer(KviExternalServerDataParser *l)
Definition: KviIrcContext.h:139
KviPointerList< KviIrcDataStreamMonitor > * m_pMonitorList
Definition: KviIrcContext.h:101
KviPointerList< KviChannelWindow > * m_pDeadChannels
Definition: KviIrcContext.h:104
unsigned int id()
Definition: KviIrcContext.h:112
#define e
Definition: detector.cpp:69
void setListWindowPointer(KviExternalServerDataParser *l)
Definition: KviIrcContext.h:144
KviExternalServerDataParser * m_pLinksWindow
Definition: KviIrcContext.h:92
KviAsynchronousConnectionData * m_pSavedAsynchronousConnectionData
Definition: KviIrcContext.h:96
The class which manages a query.
Definition: KviQueryWindow.h:49
KviExternalServerDataParser * linksWindow()
Definition: KviIrcContext.h:140
Network handling class.
Definition: KviIrcNetwork.h:47
#define q
Definition: detector.cpp:81
KviIrcConnection * m_pConnection
Definition: KviIrcContext.h:85
KviExternalServerDataParser * listWindow()
Definition: KviIrcContext.h:145
char s d
Definition: KviIrcNumericCodes.h:391
KviIrcConnection * connection()
Definition: KviIrcContext.h:116
State
Definition: KviIrcContext.h:74
KviConsoleWindow * console()
Definition: KviIrcContext.h:114
QTimer * m_pReconnectTimer
Definition: KviIrcContext.h:99
Definition: KviIrcContext.h:79
bool isLoggingIn()
Definition: KviIrcContext.h:120
KviAsynchronousConnectionData * m_pAsynchronousConnectionData
Definition: KviIrcContext.h:95
Definition: KviIrcServerParser.h:103
C++ Template based double linked pointer list class.
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
QString name()
Definition: KviRuntimeInfo.cpp:655
unsigned int m_uConnectAttemptCount
Definition: KviIrcContext.h:98
Definition: KviIrcContext.h:76
Definition: KviIrcDataStreamMonitor.h:32
This file contains compile time settings.
KviPointerList< KviWindow > * m_pContextWindows
Definition: KviIrcContext.h:107
Definition: KviIrcContext.h:58
KviPointerList< KviQueryWindow > * m_pDeadQueries
Definition: KviIrcContext.h:105
State state()
Definition: KviIrcContext.h:118
The class which manages a channel.
Definition: KviChannelWindow.h:113
unsigned int m_uId
Definition: KviIrcContext.h:87