author | dwmw2 <dwmw2> | 2002-05-09 17:30:42 (UTC) |
---|---|---|
committer | dwmw2 <dwmw2> | 2002-05-09 17:30:42 (UTC) |
commit | 37b512ee81aacdc53c4cf5de18a2eb7c0819086d (patch) (unidiff) | |
tree | 4125c12092cf9036c07e1d06710ef08a7bafdc5d | |
parent | b9d7463dde0158b06ccbdc014ef20aa8569454a5 (diff) | |
download | opie-37b512ee81aacdc53c4cf5de18a2eb7c0819086d.zip opie-37b512ee81aacdc53c4cf5de18a2eb7c0819086d.tar.gz opie-37b512ee81aacdc53c4cf5de18a2eb7c0819086d.tar.bz2 |
don't use errno for variable names
-rw-r--r-- | noncore/comm/keypebble/krfbconnection.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/noncore/comm/keypebble/krfbconnection.cpp b/noncore/comm/keypebble/krfbconnection.cpp index c413186..c51f18a 100644 --- a/noncore/comm/keypebble/krfbconnection.cpp +++ b/noncore/comm/keypebble/krfbconnection.cpp | |||
@@ -1,242 +1,242 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include <qsocket.h> | 2 | #include <qsocket.h> |
3 | #include <qtimer.h> | 3 | #include <qtimer.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | 5 | ||
6 | #include "krfbconnection.h" | 6 | #include "krfbconnection.h" |
7 | #include "krfblogin.h" | 7 | #include "krfblogin.h" |
8 | #include "krfboptions.h" | 8 | #include "krfboptions.h" |
9 | #include "krfbdecoder.h" | 9 | #include "krfbdecoder.h" |
10 | #include "krfbbuffer.h" | 10 | #include "krfbbuffer.h" |
11 | 11 | ||
12 | KRFBConnection::KRFBConnection( QObject *parent ) | 12 | KRFBConnection::KRFBConnection( QObject *parent ) |
13 | : QObject( parent, "KRFBConnection" ) | 13 | : QObject( parent, "KRFBConnection" ) |
14 | { | 14 | { |
15 | portBase_ = 5900; | 15 | portBase_ = 5900; |
16 | currentState_ = Disconnected; | 16 | currentState_ = Disconnected; |
17 | sock = 0; | 17 | sock = 0; |
18 | minData_ = 0; | 18 | minData_ = 0; |
19 | options_ = new KRFBOptions(); | 19 | options_ = new KRFBOptions(); |
20 | updater = 0; | 20 | updater = 0; |
21 | decoder_ = 0; | 21 | decoder_ = 0; |
22 | buffer_ = 0; | 22 | buffer_ = 0; |
23 | } | 23 | } |
24 | 24 | ||
25 | KRFBConnection::~KRFBConnection() | 25 | KRFBConnection::~KRFBConnection() |
26 | { | 26 | { |
27 | if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) { | 27 | if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) { |
28 | disconnectDone(); | 28 | disconnectDone(); |
29 | } | 29 | } |
30 | delete options_; | 30 | delete options_; |
31 | } | 31 | } |
32 | 32 | ||
33 | void KRFBConnection::connectTo( const QCString &host, int display ) | 33 | void KRFBConnection::connectTo( const QCString &host, int display ) |
34 | { | 34 | { |
35 | if ( currentState_ != Disconnected ); | 35 | if ( currentState_ != Disconnected ); |
36 | disconnect(); | 36 | disconnect(); |
37 | 37 | ||
38 | this->host_= host; | 38 | this->host_= host; |
39 | this->display_ = display; | 39 | this->display_ = display; |
40 | 40 | ||
41 | sock = new QSocket( this, "rfbSocket" ); | 41 | sock = new QSocket( this, "rfbSocket" ); |
42 | CHECK_PTR( sock ); | 42 | CHECK_PTR( sock ); |
43 | 43 | ||
44 | // Connect to something to notice connection or error | 44 | // Connect to something to notice connection or error |
45 | connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) ); | 45 | connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) ); |
46 | connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) ); | 46 | connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) ); |
47 | 47 | ||
48 | qWarning( "Connecting..." ); | 48 | qWarning( "Connecting..." ); |
49 | 49 | ||
50 | currentState_ = Connecting; | 50 | currentState_ = Connecting; |
51 | sock->connectToHost( host_, portBase_ + display_ ); | 51 | sock->connectToHost( host_, portBase_ + display_ ); |
52 | } | 52 | } |
53 | 53 | ||
54 | void KRFBConnection::disconnect() | 54 | void KRFBConnection::disconnect() |
55 | { | 55 | { |
56 | qWarning( "Disconnecting from server" ); | 56 | qWarning( "Disconnecting from server" ); |
57 | 57 | ||
58 | if ( ( currentState_ != Disconnected ) | 58 | if ( ( currentState_ != Disconnected ) |
59 | && ( currentState_ != Disconnecting ) | 59 | && ( currentState_ != Disconnecting ) |
60 | && sock ) { | 60 | && sock ) { |
61 | currentState_ = Disconnecting; | 61 | currentState_ = Disconnecting; |
62 | 62 | ||
63 | connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); | 63 | connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); |
64 | sock->close(); | 64 | sock->close(); |
65 | 65 | ||
66 | if ( sock->state() != QSocket::Closing ) | 66 | if ( sock->state() != QSocket::Closing ) |
67 | disconnectDone(); | 67 | disconnectDone(); |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | void KRFBConnection::disconnectDone() | 71 | void KRFBConnection::disconnectDone() |
72 | { | 72 | { |
73 | qWarning( "KRFBConnection disconnected" ); | 73 | qWarning( "KRFBConnection disconnected" ); |
74 | currentState_ = Disconnected; | 74 | currentState_ = Disconnected; |
75 | delete sock; | 75 | delete sock; |
76 | sock = 0; | 76 | sock = 0; |
77 | minData_ = 0; | 77 | minData_ = 0; |
78 | delete updater; | 78 | delete updater; |
79 | delete decoder_; | 79 | delete decoder_; |
80 | delete buffer_; | 80 | delete buffer_; |
81 | emit disconnected(); | 81 | emit disconnected(); |
82 | } | 82 | } |
83 | 83 | ||
84 | void KRFBConnection::gotSocketConnection() | 84 | void KRFBConnection::gotSocketConnection() |
85 | { | 85 | { |
86 | currentState_ = LoggingIn; | 86 | currentState_ = LoggingIn; |
87 | 87 | ||
88 | qWarning( "Connected, logging in..." ); | 88 | qWarning( "Connected, logging in..." ); |
89 | 89 | ||
90 | static QString statusMsg = tr( "Connected" ); | 90 | static QString statusMsg = tr( "Connected" ); |
91 | emit statusChanged( statusMsg ); | 91 | emit statusChanged( statusMsg ); |
92 | 92 | ||
93 | // Do some login stuff | 93 | // Do some login stuff |
94 | login = new KRFBLogin( this ); | 94 | login = new KRFBLogin( this ); |
95 | } | 95 | } |
96 | 96 | ||
97 | void KRFBConnection::gotRFBConnection() | 97 | void KRFBConnection::gotRFBConnection() |
98 | { | 98 | { |
99 | qWarning( "Logged into server" ); | 99 | qWarning( "Logged into server" ); |
100 | 100 | ||
101 | currentState_ = Connected; | 101 | currentState_ = Connected; |
102 | emit connected(); | 102 | emit connected(); |
103 | 103 | ||
104 | // Create the decoder and start doing stuff | 104 | // Create the decoder and start doing stuff |
105 | decoder_ = new KRFBDecoder( this ); | 105 | decoder_ = new KRFBDecoder( this ); |
106 | CHECK_PTR( decoder_ ); | 106 | CHECK_PTR( decoder_ ); |
107 | 107 | ||
108 | buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" ); | 108 | buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" ); |
109 | CHECK_PTR( buffer_ ); | 109 | CHECK_PTR( buffer_ ); |
110 | decoder_->setBuffer( buffer_ ); | 110 | decoder_->setBuffer( buffer_ ); |
111 | 111 | ||
112 | connect( decoder_, SIGNAL( status( const QString & ) ), | 112 | connect( decoder_, SIGNAL( status( const QString & ) ), |
113 | this, SIGNAL( statusChanged( const QString & ) ) ); | 113 | this, SIGNAL( statusChanged( const QString & ) ) ); |
114 | emit loggedIn(); | 114 | emit loggedIn(); |
115 | 115 | ||
116 | decoder_->start(); | 116 | decoder_->start(); |
117 | 117 | ||
118 | updater = new QTimer; | 118 | updater = new QTimer; |
119 | connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) ); | 119 | connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) ); |
120 | updater->start( options_->updateRate ); | 120 | updater->start( options_->updateRate ); |
121 | } | 121 | } |
122 | 122 | ||
123 | void KRFBConnection::gotSocketError( int errno ) | 123 | void KRFBConnection::gotSocketError( int err ) |
124 | { | 124 | { |
125 | currentState_ = Error; | 125 | currentState_ = Error; |
126 | 126 | ||
127 | // Do some error handling stuff | 127 | // Do some error handling stuff |
128 | qWarning( "KRFBConnection: Socket error %d", errno ); | 128 | qWarning( "KRFBConnection: Socket error %d", err ); |
129 | 129 | ||
130 | static QString refused = tr( "Connection Refused" ); | 130 | static QString refused = tr( "Connection Refused" ); |
131 | static QString host = tr( "Host not found" ); | 131 | static QString host = tr( "Host not found" ); |
132 | static QString read = tr( "Read Error: QSocket reported an error reading\n" | 132 | static QString read = tr( "Read Error: QSocket reported an error reading\n" |
133 | "data, the remote host has probably dropped the\n" | 133 | "data, the remote host has probably dropped the\n" |
134 | "connection." ); | 134 | "connection." ); |
135 | static QString confused = tr( "QSocket reported an invalid error code" ); | 135 | static QString confused = tr( "QSocket reported an invalid error code" ); |
136 | 136 | ||
137 | QString msg; | 137 | QString msg; |
138 | switch ( errno ) { | 138 | switch ( err ) { |
139 | case QSocket::ErrConnectionRefused: | 139 | case QSocket::ErrConnectionRefused: |
140 | msg = refused; | 140 | msg = refused; |
141 | break; | 141 | break; |
142 | case QSocket::ErrHostNotFound: | 142 | case QSocket::ErrHostNotFound: |
143 | msg = host; | 143 | msg = host; |
144 | break; | 144 | break; |
145 | case QSocket::ErrSocketRead: | 145 | case QSocket::ErrSocketRead: |
146 | msg = read; | 146 | msg = read; |
147 | break; | 147 | break; |
148 | default: | 148 | default: |
149 | msg = confused; | 149 | msg = confused; |
150 | }; | 150 | }; |
151 | 151 | ||
152 | QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); | 152 | QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); |
153 | delete sock; | 153 | delete sock; |
154 | sock = 0; | 154 | sock = 0; |
155 | currentState_ = Disconnected; | 155 | currentState_ = Disconnected; |
156 | 156 | ||
157 | emit error( msg ); | 157 | emit error( msg ); |
158 | } | 158 | } |
159 | 159 | ||
160 | void KRFBConnection::gotMoreData() | 160 | void KRFBConnection::gotMoreData() |
161 | { | 161 | { |
162 | assert( minData_ > 0 ); | 162 | assert( minData_ > 0 ); |
163 | 163 | ||
164 | if ( sock->size() >= minData_ ) { | 164 | if ( sock->size() >= minData_ ) { |
165 | minData_ = 0; | 165 | minData_ = 0; |
166 | QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); | 166 | QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); |
167 | emit gotEnoughData(); | 167 | emit gotEnoughData(); |
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
171 | void KRFBConnection::waitForData( unsigned int sz ) | 171 | void KRFBConnection::waitForData( unsigned int sz ) |
172 | { | 172 | { |
173 | assert( minData_ == 0 ); | 173 | assert( minData_ == 0 ); |
174 | assert( sz > 0 ); | 174 | assert( sz > 0 ); |
175 | assert( currentState_ != Error ); | 175 | assert( currentState_ != Error ); |
176 | 176 | ||
177 | if ( sock->size() >= sz ) { | 177 | if ( sock->size() >= sz ) { |
178 | // qWarning( "No need to wait for data" ); | 178 | // qWarning( "No need to wait for data" ); |
179 | emit gotEnoughData(); | 179 | emit gotEnoughData(); |
180 | } | 180 | } |
181 | else { | 181 | else { |
182 | // qWarning( "Waiting for %u bytes", sz ); | 182 | // qWarning( "Waiting for %u bytes", sz ); |
183 | 183 | ||
184 | minData_ = sz; | 184 | minData_ = sz; |
185 | connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); | 185 | connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | int KRFBConnection::read( void *buf, int sz ) | 189 | int KRFBConnection::read( void *buf, int sz ) |
190 | { | 190 | { |
191 | return sock->readBlock( (char *) buf, sz ); | 191 | return sock->readBlock( (char *) buf, sz ); |
192 | } | 192 | } |
193 | 193 | ||
194 | int KRFBConnection::write( void *buf, int sz ) | 194 | int KRFBConnection::write( void *buf, int sz ) |
195 | { | 195 | { |
196 | return sock->writeBlock( (const char *) buf, sz ); | 196 | return sock->writeBlock( (const char *) buf, sz ); |
197 | } | 197 | } |
198 | 198 | ||
199 | KRFBConnection::State KRFBConnection::state() const | 199 | KRFBConnection::State KRFBConnection::state() const |
200 | { | 200 | { |
201 | return currentState_; | 201 | return currentState_; |
202 | } | 202 | } |
203 | 203 | ||
204 | void KRFBConnection::setPortBase( int base ) | 204 | void KRFBConnection::setPortBase( int base ) |
205 | { | 205 | { |
206 | portBase_ = base; | 206 | portBase_ = base; |
207 | } | 207 | } |
208 | 208 | ||
209 | int KRFBConnection::portBase() const | 209 | int KRFBConnection::portBase() const |
210 | { | 210 | { |
211 | return portBase_; | 211 | return portBase_; |
212 | } | 212 | } |
213 | 213 | ||
214 | void KRFBConnection::setPassword( const QCString &pass ) | 214 | void KRFBConnection::setPassword( const QCString &pass ) |
215 | { | 215 | { |
216 | this->pass_ = pass; | 216 | this->pass_ = pass; |
217 | } | 217 | } |
218 | 218 | ||
219 | void KRFBConnection::updateTimer() | 219 | void KRFBConnection::updateTimer() |
220 | { | 220 | { |
221 | decoder_->sendUpdateRequest( true ); | 221 | decoder_->sendUpdateRequest( true ); |
222 | } | 222 | } |
223 | 223 | ||
224 | void KRFBConnection::refresh() | 224 | void KRFBConnection::refresh() |
225 | { | 225 | { |
226 | decoder_->sendUpdateRequest( false ); | 226 | decoder_->sendUpdateRequest( false ); |
227 | } | 227 | } |
228 | 228 | ||
229 | void KRFBConnection::sendCutText( const QString &text ) | 229 | void KRFBConnection::sendCutText( const QString &text ) |
230 | { | 230 | { |
231 | decoder_->sendCutEvent( text ); | 231 | decoder_->sendCutEvent( text ); |
232 | } | 232 | } |
233 | 233 | ||
234 | const QUrl &KRFBConnection::url() | 234 | const QUrl &KRFBConnection::url() |
235 | { | 235 | { |
236 | url_.setProtocol( "vnc" ); | 236 | url_.setProtocol( "vnc" ); |
237 | url_.setPort( display() ); | 237 | url_.setPort( display() ); |
238 | url_.setHost( host() ); | 238 | url_.setHost( host() ); |
239 | url_.setPath( "/" ); | 239 | url_.setPath( "/" ); |
240 | 240 | ||
241 | return url_; | 241 | return url_; |
242 | } | 242 | } |