From af5ff9f67d05ef1ceff2e4b1b61f92ead74dcc1b Mon Sep 17 00:00:00 2001 From: Constantin Kaplinsky Date: Mon, 17 Apr 2006 14:03:42 +0000 Subject: [PATCH] Added new files from VNC 4.1.1 that were not included on merging for some reason. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/branches/merge-with-vnc-4.1.1@536 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- vncconfig_unix/QueryConnectDialog.cxx | 88 +++++++++++++++++++++++++++ vncconfig_unix/QueryConnectDialog.h | 56 +++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 vncconfig_unix/QueryConnectDialog.cxx create mode 100644 vncconfig_unix/QueryConnectDialog.h diff --git a/vncconfig_unix/QueryConnectDialog.cxx b/vncconfig_unix/QueryConnectDialog.cxx new file mode 100644 index 00000000..c1540513 --- /dev/null +++ b/vncconfig_unix/QueryConnectDialog.cxx @@ -0,0 +1,88 @@ +/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * + * This 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. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#include +#include +#include "QueryConnectDialog.h" +#include "vncExt.h" + +QueryConnectDialog::QueryConnectDialog(Display* dpy, + const char* address_, + const char* user_, + int timeout_, + QueryResultCallback* cb) + : TXDialog(dpy, 300, 100, "VNC Server : Accept Connection?"), + addressLbl(dpy, "Host:",this), + address(dpy, address_, this), + userLbl(dpy, "User:", this), + user(dpy, user_, this), + timeoutLbl(dpy, "Seconds until automatic reject:", this), + timeout(dpy, "0000000000", this), + accept(dpy, "Accept", this, this, 60), + reject(dpy, "Reject", this, this, 60), + callback(cb), timeUntilReject(timeout_), timer(this) +{ + const int pad = 4; + int y=pad; + int lblWidth = __rfbmax(addressLbl.width(), userLbl.width()); + userLbl.move(pad+lblWidth-userLbl.width(), y); + user.move(pad+lblWidth, y); + addressLbl.move(pad+lblWidth-addressLbl.width(), y+=userLbl.height()); + address.move(pad+lblWidth, y); + timeoutLbl.move(pad, y+=addressLbl.height()); + timeout.move(pad+timeoutLbl.width(), y); + accept.move(pad, y+=addressLbl.height()); + int maxWidth = __rfbmax(user.width(), address.width()+pad+lblWidth); + maxWidth = __rfbmax(maxWidth, accept.width()*3); + maxWidth = __rfbmax(maxWidth, timeoutLbl.width()+timeout.width()+pad); + reject.move(maxWidth-reject.width(), y); + resize(maxWidth + pad, y+reject.height()+pad); + setBorderWidth(1); + refreshTimeout(); + timer.start(1000); +} + +void QueryConnectDialog::deleteWindow(TXWindow*) { + unmap(); + callback->queryRejected(); +} + +void QueryConnectDialog::buttonActivate(TXButton* b) { + unmap(); + if (b == &accept) + callback->queryApproved(); + else if (b == &reject) + callback->queryRejected(); +} + +bool QueryConnectDialog::handleTimeout(rfb::Timer* t) { + if (timeUntilReject-- == 0) { + unmap(); + callback->queryTimedOut(); + return false; + } else { + refreshTimeout(); + return true; + } +} + +void QueryConnectDialog::refreshTimeout() { + char buf[16]; + sprintf(buf, "%d", timeUntilReject); + timeout.setText(buf); +} diff --git a/vncconfig_unix/QueryConnectDialog.h b/vncconfig_unix/QueryConnectDialog.h new file mode 100644 index 00000000..f685dc34 --- /dev/null +++ b/vncconfig_unix/QueryConnectDialog.h @@ -0,0 +1,56 @@ +/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * + * This 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. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#ifndef __QUERYCONNECTDIALOG_H__ +#define __QUERYCONNECTDIALOG_H__ + +#include +#include "TXLabel.h" +#include "TXButton.h" +#include "TXDialog.h" + +class QueryResultCallback { + public: + virtual ~QueryResultCallback() {} + virtual void queryApproved() = 0; + virtual void queryRejected() = 0; + virtual void queryTimedOut() { queryRejected(); }; +}; + +class QueryConnectDialog : public TXDialog, public TXEventHandler, + public TXButtonCallback, + public rfb::Timer::Callback +{ + public: + QueryConnectDialog(Display* dpy, const char* address_, + const char* user_, int timeout_, + QueryResultCallback* cb); + void handleEvent(TXWindow*, XEvent* ) { } + void deleteWindow(TXWindow*); + void buttonActivate(TXButton* b); + bool handleTimeout(rfb::Timer* t); + private: + void refreshTimeout(); + TXLabel addressLbl, address, userLbl, user, timeoutLbl, timeout; + TXButton accept, reject; + QueryResultCallback* callback; + int timeUntilReject; + rfb::Timer timer; +}; + +#endif -- 2.39.5