summaryrefslogtreecommitdiff
path: root/noncore/comm/keypebble/krfbconnection.h
blob: fe477c1cdaf509a019351514f640c277f17ec50f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// -*- c++ -*-

#ifndef KRFBCONNECTION_H
#define KRFBCONNECTION_H

#include <qobject.h>
#include <qstring.h>
#include <qcstring.h>
#include <qurl.h>

class KRFBLogin;
class KRBUpdateHandler;
class KRFBOptions;
class QSocket;
class KRFBDecoder;
class KRFBBuffer;
class QTimer;

/**
 * Encapsulates the RFB socket.
 *
 */
class KRFBConnection : public QObject
{
  Q_OBJECT

public:
  friend class KRFBLogin;
  friend class KRFBDecoder;

  //* The state of the connection.
  enum State {
    Connecting,
    LoggingIn,
    Connected,
    Disconnecting,
    Disconnected,
    Error
  };

  KRFBConnection( QObject *parent = 0 );
  ~KRFBConnection();

  //* Get the state of a connection.
  State state() const;

  //* Get the options for this connection
  KRFBOptions *options() const { return options_; };

  KRFBBuffer *buffer() const { return buffer_; };

  KRFBDecoder *decoder() const { return decoder_; };

  //* Set the base from which the port for a given display will be calculated.
  void setPortBase( int base );

  //* Get the base from which the port for a given display is calculated.
  int portBase() const;

  //* Set the password which will be used to login
  void setPassword( const QCString &pass );

  //* Open a connection
  void connectTo( const QCString &host, int display );

  //* Close the connection
  void disconnect();

  //* Get the host
  const QCString host() const { return host_; };

  //* Get the display
  int display() const { return display_; };

  //* Get the current host/display as a URL
  const QUrl &url();

  //* Reload the display
  void refresh();

  //* Send text to the remote clipboard
  void sendCutText( const QString & );

protected slots:
  //* When the shit hits the fan
  void gotSocketError( int );

  //* When we have an open socket
  void gotSocketConnection();

  //* When we have logged in
  void gotRFBConnection();

  //* When some more data arrived
  void gotMoreData();

  void updateTimer();

  void disconnectDone();

signals:
  //* Emitted when the status of the connection changes.
  void statusChanged( const QString & );

  /**
   * Emitted when we *really* need a password. If the password
   * was specified before you tried to connect then you won't
   * see this.
   */
  void passwordRequired( KRFBConnection * );

  //* When we have a working RFB connection
  void connected();

  void loggedIn();

  void disconnected();

  //* What happened?
  void error( const QString &msg );

  //* Emitted in response to a waitForData() call.
  void gotEnoughData();

private:
  //
  // The following are called by our friends.
  //

  void waitForData( unsigned int );

  int read( void *buf, int sz );
  int write( void *buf, int sz );

private:
  QCString host_;
  int portBase_;
  int display_;
  QCString pass_;
  QSocket *sock;
  State currentState_;
  unsigned int minData_;
  QTimer *updater;
  KRFBLogin *login;
  KRFBDecoder *decoder_;
  KRFBOptions *options_;
  KRFBBuffer *buffer_;
  QUrl url_;
};

#endif // KRFBCONNECTION_H