diff --git a/krfb/Makefile.am b/krfb/Makefile.am index 8bff36b5..afd57510 100644 --- a/krfb/Makefile.am +++ b/krfb/Makefile.am @@ -1,10 +1,12 @@ +METASOURCES = AUTO + bin_PROGRAMS = krfb -krfb_SOURCES = trayicon.cpp XUpdateScanner.cc rfbserver.cpp main.cpp configurationdialog.ui newconnectiondialog.ui configuration.cpp +krfb_SOURCES = configuration.cc trayicon.cpp XUpdateScanner.cc rfbconnection.cpp main.cpp configurationdialog.ui newconnectiondialog.ui krfb_LDADD = ./lib/liblib.a $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIBSOCKET) SUBDIRS = lib -EXTRA_DIST = main.cpp krfb.desktop lo32-app-krfb.png lo16-app-krfb.png rfbserver.cpp rfbserver.h eyes-closed24.png eyes-open24.png XUpdateScanner.cc XUpdateScanner.h trayicon.cpp trayicon.h +EXTRA_DIST = main.cpp krfb.desktop lo32-app-krfb.png lo16-app-krfb.png rfbserver.cpp rfbserver.h eyes-closed24.png eyes-open24.png XUpdateScanner.cc XUpdateScanner.h trayicon.cpp trayicon.h configuration.h configuration.cpp install-data-local: $(mkinstalldirs) $(kde_appsdir)/Applications/ @@ -41,8 +43,6 @@ uninstall-local: # set the include path for X, qt and KDE INCLUDES= $(all_includes) -I../include -METASOURCES = AUTO - # the library search path. krfb_LDFLAGS = $(all_libraries) $(KDE_RPATH) -lXtst @@ -51,15 +51,7 @@ krfb_LDFLAGS = $(all_libraries) $(KDE_RPATH) -lXtst #rcdir = $(kde_datadir)/krfb #rc_DATA = krfbui.rc -#WARNING: if you use a ui.rc file above, use: - -# messages: rc.cpp - -# instead of - -# messages: - -messages: +messages: rc.cpp LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \ if test -n "$$LIST"; then \ $(XGETTEXT) $$LIST -o $(podir)/krfb.pot; \ diff --git a/krfb/XUpdateScanner.h b/krfb/XUpdateScanner.h index 29b91e79..2f87ad3c 100644 --- a/krfb/XUpdateScanner.h +++ b/krfb/XUpdateScanner.h @@ -22,7 +22,10 @@ #define _hexonet_rfb_XUpdateScanner_h_ -#include "rfbServer.h" +#include "../include/rfbServer.h" + +#include +#include namespace rfb { diff --git a/krfb/configuration.cc b/krfb/configuration.cc new file mode 100644 index 00000000..d733b658 --- /dev/null +++ b/krfb/configuration.cc @@ -0,0 +1,128 @@ +/*************************************************************************** + configuration.cpp + ------------------- + begin : Tue Dec 11 2001 + copyright : (C) 2001 by Tim Jansen + email : tim@tjansen.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "configuration.h" + +#include +#include + +#include +#include +#include + +Configuration::Configuration() +{ + loadFromKConfig(); + saveToDialog(); + + + portValidator = new QIntValidator(0, 65535, + confDlg.displayNumberInput); + confDlg.displayNumberInput->setValidator(portValidator); + + connect(confDlg.okButton, SIGNAL(clicked()), + SLOT(okPressed())); + connect(confDlg.cancelButton, SIGNAL(clicked()), + SLOT(cancelPressed())); + connect(confDlg.applyButton, SIGNAL(clicked()), + SLOT(applyPressed())); +} + +Configuration::~Configuration() { +} + +void Configuration::loadFromKConfig() { + KConfig *config = KGlobal::config(); + askOnConnectFlag = config->readBoolEntry("askOnConnect", true); + allowDesktopControlFlag = config->readBoolEntry("allowDesktopControl", + false); + showMousePointerFlag = config->readBoolEntry("showMousePointer", + true); + passwordString = config->readEntry("password", ""); + portNumber = config->readNumEntry("port", 0); +} + +void Configuration::loadFromDialog() { + askOnConnectFlag = confDlg.askOnConnectCB->isChecked(); + allowDesktopControlFlag = confDlg.allowDesktopControlCB->isChecked(); + showMousePointerFlag = confDlg.showMousePointerCB->isChecked(); + passwordString = confDlg.passwordInput->text(); + int p = confDlg.displayNumberInput->text().toInt(); + if (p != portNumber) { + portNumber = p; + emit portChanged(); + } +} + +void Configuration::saveToKConfig() { + KConfig *config = KGlobal::config(); + config->writeEntry("askOnConnect", askOnConnectFlag); + config->writeEntry("allowDesktopControl", allowDesktopControlFlag); + config->writeEntry("showMousePointer", showMousePointerFlag); + config->writeEntry("password", passwordString); + config->writeEntry("port", portNumber); +} + +void Configuration::saveToDialog() { + confDlg.askOnConnectCB->setChecked(askOnConnectFlag); + confDlg.allowDesktopControlCB->setChecked(allowDesktopControlFlag); + confDlg.showMousePointerCB->setChecked(showMousePointerFlag); + confDlg.passwordInput->setText(passwordString); + confDlg.displayNumberInput->setText(QString().setNum(portNumber)); +} + +bool Configuration::askOnConnect() const { + return askOnConnectFlag; +} + +bool Configuration::allowDesktopControl() const { + return allowDesktopControlFlag; +} + +bool Configuration::showMousePointer() const { + return showMousePointerFlag; +} + +QString Configuration::password() const { + return passwordString; +} + +int Configuration::port() const { + return portNumber; +} + +void Configuration::showDialog() { + confDlg.show(); +} + +void Configuration::okPressed() { + loadFromDialog(); + saveToKConfig(); + confDlg.hide(); +} + +void Configuration::cancelPressed() { + saveToDialog(); + confDlg.hide(); +} + +void Configuration::applyPressed() { + loadFromDialog(); + saveToKConfig(); +} + +#include "configuration.moc" diff --git a/krfb/configuration.h b/krfb/configuration.h new file mode 100644 index 00000000..963445e9 --- /dev/null +++ b/krfb/configuration.h @@ -0,0 +1,72 @@ +/*************************************************************************** + configuration.h + ------------------- + begin : Tue Dec 11 2001 + copyright : (C) 2001 by Tim Jansen + email : tim@tjansen.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef CONFIGURATION_H +#define CONFIGURATION_H + +#include "configurationdialog.h" + +#include +#include +#include + +/** + * This class stores the app's configuration and also 'drives' + * the configuration dialog. + * @author Tim Jansen + */ +class Configuration : public QObject { + Q_OBJECT +public: + Configuration(); + ~Configuration(); + + bool askOnConnect() const; + bool allowDesktopControl() const; + bool showMousePointer() const; + + QString password() const; + int port() const; + +signals: + void portChanged(); + +public slots: + void showDialog(); + +private: + void loadFromKConfig(); + void loadFromDialog(); + void saveToKConfig(); + void saveToDialog(); + + ConfigurationDialog confDlg; + QIntValidator *portValidator; + + bool askOnConnectFlag; + bool allowDesktopControlFlag; + bool showMousePointerFlag; + QString passwordString; + int portNumber; + +private slots: + void okPressed(); + void cancelPressed(); + void applyPressed(); +}; + +#endif diff --git a/krfb/configurationdialog.ui b/krfb/configurationdialog.ui index 4442b908..99c36547 100644 --- a/krfb/configurationdialog.ui +++ b/krfb/configurationdialog.ui @@ -11,7 +11,7 @@ 0 0 - 390 + 386 278 @@ -352,6 +352,10 @@ text &Ok + + default + true + whatsThis Apply changes and close window. diff --git a/krfb/main.cpp b/krfb/main.cpp index 11bea913..d2b6996e 100644 --- a/krfb/main.cpp +++ b/krfb/main.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "trayicon.h" +#include "configuration.h" #include #include @@ -24,6 +25,7 @@ #include #include #include +#include #define VERSION "0.1" @@ -46,7 +48,14 @@ int main(int argc, char *argv[]) KCmdLineArgs::addCmdLineOptions( options ); KApplication app; - TrayIcon tray; - + TrayIcon trayicon; + Configuration config; + + QObject::connect(&trayicon, SIGNAL(showConfigure()), + &config, SLOT(showDialog())); + + QObject::connect(&app, SIGNAL(lastWindowClosed()), + &app, SLOT(quit())); + return app.exec(); } diff --git a/krfb/myview.ui b/krfb/myview.ui deleted file mode 100644 index 6677740c..00000000 --- a/krfb/myview.ui +++ /dev/null @@ -1,82 +0,0 @@ - -myview - - QWidget - - name - myview - - - geometry - - 0 - 11 - 178 - 48 - - - - maximumSize - - 32767 - 48 - - - - minimumSize - - 16 - 0 - - - - sizePolicy - - 5 - 5 - - - - caption - Form1 - - - QPushButton - - name - PushButton1 - - - geometry - - 0 - 0 - 48 - 48 - - - - text - Test - - - sizePolicy - - 4 - 4 - - - - cursor - 13 - - - maximumSize - - 48 - 32767 - - - - - diff --git a/krfb/rfbconnection.cpp b/krfb/rfbconnection.cpp new file mode 100644 index 00000000..6cb9d22d --- /dev/null +++ b/krfb/rfbconnection.cpp @@ -0,0 +1,136 @@ +/*************************************************************************** + rfbconnection.cpp + ------------------- + begin : Sun Dec 9 2001 + copyright : (C) 2001 by Tim Jansen + email : tim@tjansen.de + ***************************************************************************/ + +/*************************************************************************** + * Contains portions & concept from rfb's x0rfbserver.cc + * Copyright (C) 2000 heXoNet Support GmbH, D-66424 Homburg. + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "rfbconnection.h" + +#include +#include +#include + + +RFBConnection::RFBConnection(Display *dpy, int fd) : + Server(), + dpy(dpy), + fd(fd), + buttonMask(0) +{ + bufferedConnection = new BufferedConnection(32768, 32768); + connection = bufferedConnection; + + InitBlocks(32, 32); + + XTestGrabControl(dpy, true); + createFramebuffer(); + + connection->send((unsigned char*) RFB_PROTOCOL_VERSION, 12); +} + +RFBConnection::~RFBConnection() { + DeleteBlocks(); + + destroyFramebuffer(); + XTestDiscard( dpy ); + + delete bufferedConnection; + close(fd); +} + +void RFBConnection::handleKeyEvent(KeyEvent &keyEvent) { + KeyCode kc = XKeysymToKeycode(dpy, keyEvent.key); + if (kc != NoSymbol) + XTestFakeKeyEvent(dpy, + XKeysymToKeycode( dpy, keyEvent.key ), + keyEvent.down_flag, + CurrentTime); +} + +void RFBConnection::handlePointerEvent(PointerEvent &pointerEvent) { + XTestFakeMotionEvent(dpy, + 0, + pointerEvent.x_position, + pointerEvent.y_position, + CurrentTime); + int i = 1; + while (i <= 5) { + if ( (buttonMask & (1 << (i-1))) != (pointerEvent.button_mask & (1 << (i-1))) ) + XTestFakeButtonEvent( dpy, i, + (pointerEvent.button_mask & (1 << (i-1)))? True : False, + CurrentTime ); + i++; + } + buttonMask = pointerEvent.button_mask; +} + +void RFBConnection::createFramebuffer() +{ + framebufferImage = XGetImage(dpy, + QApplication::desktop()->winId(), + 0, + 0, + QApplication::desktop()->width(), + QApplication::desktop()->height(), + AllPlanes, + ZPixmap); + framebuffer.width = framebufferImage->width; + framebuffer.height = framebufferImage->height; + framebuffer.bytesPerLine = framebufferImage->bytes_per_line; + framebuffer.data = (unsigned char*) framebufferImage->data; + + framebuffer.pixelFormat.bits_per_pixel = + framebufferImage->bits_per_pixel; + framebuffer.pixelFormat.depth = framebufferImage->depth; + framebuffer.pixelFormat.big_endian_flag = + (framebufferImage->bitmap_bit_order == MSBFirst); + framebuffer.pixelFormat.true_colour_flag = true; + + if (framebuffer.pixelFormat.bits_per_pixel == 8) { + framebuffer.pixelFormat.red_shift = 0; + framebuffer.pixelFormat.green_shift = 2; + framebuffer.pixelFormat.blue_shift = 5; + framebuffer.pixelFormat.red_max = 3; + framebuffer.pixelFormat.green_max = 7; + framebuffer.pixelFormat.blue_max = 3; + } else { + framebuffer.pixelFormat.red_shift = 0; + if ( framebufferImage->red_mask ) + while (!(framebufferImage->red_mask & (1 << framebuffer.pixelFormat.red_shift))) + framebuffer.pixelFormat.red_shift++; + framebuffer.pixelFormat.green_shift = 0; + if (framebufferImage->green_mask) + while (!(framebufferImage->green_mask & (1 << framebuffer.pixelFormat.green_shift))) + framebuffer.pixelFormat.green_shift++; + framebuffer.pixelFormat.blue_shift = 0; + if (framebufferImage->blue_mask) + while (!(framebufferImage->blue_mask & (1 << framebuffer.pixelFormat.blue_shift))) + framebuffer.pixelFormat.blue_shift++; + framebuffer.pixelFormat.red_max = framebufferImage->red_mask >> framebuffer.pixelFormat.red_shift; + framebuffer.pixelFormat.green_max = framebufferImage->green_mask >> framebuffer.pixelFormat.green_shift; + framebuffer.pixelFormat.blue_max = framebufferImage->blue_mask >> framebuffer.pixelFormat.blue_shift; + } + scanner = new XUpdateScanner( dpy, QApplication::desktop()->winId(), &framebuffer ); +} + +void RFBConnection::destroyFramebuffer() +{ + delete scanner; + XDestroyImage(framebufferImage); +} diff --git a/krfb/rfbserver.h b/krfb/rfbconnection.h similarity index 61% rename from krfb/rfbserver.h rename to krfb/rfbconnection.h index 70c177c3..290e8808 100644 --- a/krfb/rfbserver.h +++ b/krfb/rfbconnection.h @@ -1,5 +1,5 @@ /*************************************************************************** - rfbserver.h - description + rfbconnection.h ------------------- begin : Sun Dec 9 2001 copyright : (C) 2001 by Tim Jansen @@ -20,31 +20,53 @@ * * ***************************************************************************/ -#ifndef RFBSERVER_H -#define RFBSERVER_H +#ifndef RFBCONNECTION_H +#define RFBCONNECTION_H + +// QT must be first because of conflicts with X11 +#include + +#include "XUpdateScanner.h" #include "../include/rfbServer.h" + +#include #include using namespace rfb; /** - * KDE-specific implementation of the Server base class - * @author Tim Jansen - */ -class RFBServer : public Server { + * This is a port from x0rfbserver's BaseServer to KDE. It is called + * RFBConnection because the original Server, despite its name, handles only + * a single connection after it has been established. This class and its + * connections are created and destroyed by RFBController. RFBController is the real + * serverk, but I did not want to call it Server and create more confusion. + * Unlike the original this one allows only one client, making stuff a little bit + * simpler. + * @author Tim Jansen + */ +class RFBConnection : public QObject, public Server { + Q_OBJECT public: - RFBServer(Display *dpy, int fd); - ~RFBServer(); + RFBConnection(Display *dpy, int fd); + ~RFBConnection(); virtual void handleKeyEvent(KeyEvent &keyEvent); virtual void handlePointerEvent(PointerEvent &pointerEvent); private: + void createFramebuffer(); + void destroyFramebuffer(); + int fd; int buttonMask; BufferedConnection *bufferedConnection; + + Framebuffer framebuffer; + XUpdateScanner *scanner; + Display *dpy; + XImage *framebufferImage; }; #endif diff --git a/krfb/rfbserver.cpp b/krfb/rfbserver.cpp deleted file mode 100644 index 32a33950..00000000 --- a/krfb/rfbserver.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** - rfbserver.cpp - description - ------------------- - begin : Sun Dec 9 2001 - copyright : (C) 2001 by Tim Jansen - email : tim@tjansen.de - ***************************************************************************/ - -/*************************************************************************** - * Contains portions & concept from rfb's x0rfbserver.cc - * Copyright (C) 2000 heXoNet Support GmbH, D-66424 Homburg. - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#include "rfbserver.h" - -#include - - -RFBServer::RFBServer(Display *dpy, int fd) : - Server(), - dpy(dpy), - fd(fd), - buttonMask(0) -{ - connection = bufferedConnection = new BufferedConnection(32768, - 32768); - InitBlocks(32, 32); - connection->send((unsigned char*) RFB_PROTOCOL_VERSION, 12); -} - -RFBServer::~RFBServer() { - DeleteBlocks(); - delete bufferedConnection; - close(fd); -} - -void RFBServer::handleKeyEvent(KeyEvent &keyEvent) { - KeyCode kc = XKeysymToKeycode(dpy, keyEvent.key); - if (kc != NoSymbol) - XTestFakeKeyEvent(dpy, - XKeysymToKeycode( dpy, keyEvent.key ), - keyEvent.down_flag, - CurrentTime); -} - -void RFBServer::handlePointerEvent(PointerEvent &pointerEvent) { - XTestFakeMotionEvent(dpy, - 0, - pointerEvent.x_position, - pointerEvent.y_position, - CurrentTime); - int i = 1; - while (i <= 5) { - if ( (buttonMask & (1 << (i-1))) != (pointerEvent.button_mask & (1 << (i-1))) ) - XTestFakeButtonEvent( dpy, i, - (pointerEvent.button_mask & (1 << (i-1)))? True : False, - CurrentTime ); - i++; - } - buttonMask = pointerEvent.button_mask; -} diff --git a/krfb/trayicon.cpp b/krfb/trayicon.cpp index 0cfd430a..4d73f745 100644 --- a/krfb/trayicon.cpp +++ b/krfb/trayicon.cpp @@ -30,6 +30,7 @@ TrayIcon::TrayIcon() : KSystemTray() { configureAction = new KAction(i18n("&Configure KRfb")); configureAction->plug(contextMenu()); closeConnectionAction = new KAction(i18n("Close connection")); + connect(configureAction, SIGNAL(activated()), SIGNAL(showConfigure())); show(); }