diff options
author | sr | 2013-02-04 19:50:31 +0100 |
---|---|---|
committer | sr | 2013-02-04 19:50:31 +0100 |
commit | 1a5709501f94014d41987b956338bb6424b9f90c (patch) | |
tree | d3b93fe8dc406bca56aff147ef5cc4cbf9ed6be0 /src/client/vnc/vncthread.h | |
parent | Test (diff) | |
download | pvs2-1a5709501f94014d41987b956338bb6424b9f90c.tar.gz pvs2-1a5709501f94014d41987b956338bb6424b9f90c.tar.xz pvs2-1a5709501f94014d41987b956338bb6424b9f90c.zip |
Initial commit
Diffstat (limited to 'src/client/vnc/vncthread.h')
-rw-r--r-- | src/client/vnc/vncthread.h | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/src/client/vnc/vncthread.h b/src/client/vnc/vncthread.h new file mode 100644 index 0000000..b6679b3 --- /dev/null +++ b/src/client/vnc/vncthread.h @@ -0,0 +1,141 @@ +/* + # 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> + +class QPainter; + +extern "C" +{ +#include <rfb/rfbclient.h> +} + +/** + * - START - + * Event classes. Not my code. Might be useful to implement remote assistance via VNC later. + * Code might come from the KDE VNC client. + */ +class SomeEvent +{ +public: + virtual ~SomeEvent(){} + virtual void fire(rfbClient*) = 0; +}; + +class KeyEvent : public SomeEvent +{ +public: + KeyEvent(int key, int pressed) : + _key(key), _pressed(pressed) + { + } + + void fire(rfbClient*); + +private: + int _key; + int _pressed; +}; + +class PointerEvent : public SomeEvent +{ +public: + PointerEvent(int x, int y, int buttonMask) : + _x(x), _y(y), _buttonMask(buttonMask) + { + } + + void fire(rfbClient*); + +private: + int _x; + int _y; + int _buttonMask; +}; +/** - END - **/ + +/** + * 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; + quint8 *_frameBuffer; + + QString _host; + int _port; + QString _passwd; + int _quality; + QQueue<SomeEvent*> _eventQueue; + + QPainter *_painter; + QImage _img; + QImage _imgScaled; + QSize _clientSize; + QSize _localSize; + QMutex _mutex; + + QSize _newLocalSize; + volatile bool _hasNewLocalSize; + + int _srcStepX, _srcStepY, _dstStepX, _dstStepY; + + bool _connected; + volatile bool _run; + + void calcScaling(); + + // 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); + // Do NOT delete this class directly. use VncThread::destroy() instead! + ~VncThread(); + + const QImage& getImage() const { if (_srcStepX > 1 || _srcStepY > 1) return _imgScaled; return _img; } + const QSize& getSourceSize() const { return _clientSize; } + const QString getDesktopName() const; + void processImageUpdate(const int x, const int y, const int w, const int h); + void mouseEvent(int x, int y, int buttonMask); + void keyEvent(int key, bool pressed); + const bool isConnected() const { return _connected; } + void stop() { _run = false; } + void setTargetSize(const QSize size); + 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(); + +}; + +#endif /* VNCCLIENTTHREAD_H_ */ |