/*
# Copyright (c) 2009, 2010 - OpenSLX Project, Computer Center University of
# Freiburg
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
*/
#ifndef VNCCLIENTTHREAD_H_
#define VNCCLIENTTHREAD_H_
#include <QtCore>
#include <QImage>
#include <QThread>
#include <QSharedPointer>
class QPainter;
extern "C"
{
#include <rfb/rfbclient.h>
}
/**
* VncThread - communicate with VNC server, scale image if necessary.
*
* As this class is derived from QThread and overrides the run() method,
* it does not have an event-loop. Do NOT try to add any slots to it.
* It will NOT be able to receive signals. Emitting signals is fine though.
*/
class VncThread : public QThread
{
Q_OBJECT
private:
rfbClient *_client;
QString _host;
int _port;
QString _passwd;
int _quality;
QSharedPointer<QImage> _img;
volatile bool _connected;
volatile bool _run;
bool _started;
void calcScaling();
void processImageUpdate(int x, int y, int w, int h);
void emitStarted();
// Callbacks for rfb lib. make them class members so the callbacks can access private members of the class.
static void updateImage(rfbClient *client, int x, int y, int w, int h);
static char* passwdHandler(rfbClient *client);
static rfbBool frameBufferHandler(rfbClient *client);
public:
VncThread(QString host, int port, QString passwd, int quality);
~VncThread();
const QString getDesktopName() const;
bool isConnected() { return _connected; }
void stop() { _run = false; }
const QSharedPointer<QImage>& getFrameBuffer() { return _img; }
void run();
int const static HIGH = 0;
int const static MEDIUM = 1;
int const static LOW = 2;
signals:
void imageUpdated(const int x, const int y, const int w, const int h);
void projectionStarted();
void projectionStopped();
};
#endif /* VNCCLIENTTHREAD_H_ */