ircclient.h
1 //------------------------------------------------------------------------------
2 // ircclient.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __IRCCLIENT_H__
24 #define __IRCCLIENT_H__
25 
26 #include "socketsignalsadapter.h"
27 #include <QHostInfo>
28 #include <QTcpSocket>
29 #include <QTimer>
30 
31 class IRCClient : public QObject
32 {
33  Q_OBJECT
34 
35  public:
36  static const int MAX_MESSAGE_LENGTH = 510;
37  static const int SAFE_MESSAGE_LENGTH = 400;
38 
39  IRCClient();
40  ~IRCClient();
41 
42  void connect(const QString& address, unsigned short port);
43  void connectSocketSignals(SocketSignalsAdapter* pAdapter);
44  void disconnect();
45 
46  bool isConnected() const;
47 
48  bool sendMessage(const QString& message);
49  void setFakeRecvLag(int lagMs);
50 
51  signals:
52  void hostLookupError(QHostInfo::HostInfoError errorValue);
53 
60  void infoMessage(const QString& message);
61  void ircServerResponse(const QString& message);
62 
63  private:
64  bool bIsInHostLookupMode;
65  QString hostName;
66  unsigned short port;
67  QTimer recvTimer;
68  QTcpSocket socket;
69 
75  const QHostAddress* pickAddress(const QList<QHostAddress>& addressesList);
76 
77  private slots:
78  void hostLookupFinished(const QHostInfo& hostInfo);
79  void receiveSocketData();
80  void receiveSocketDataDelayed();
81 
82 };
83 
84 #endif
void infoMessage(const QString &message)
These are the messages that IRCClient class sends to inform the upper layers of progress.