Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame^] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <rdr/Exception.h> |
| 21 | #include "QueryConnectDialog.h" |
| 22 | #include "vncExt.h" |
| 23 | |
| 24 | QueryConnectDialog::QueryConnectDialog(Display* dpy, |
| 25 | const char* address_, |
| 26 | const char* user_, |
| 27 | int timeout_, |
| 28 | QueryResultCallback* cb) |
| 29 | : TXDialog(dpy, 300, 100, "VNC Server : Accept Connection?"), |
| 30 | addressLbl(dpy, "Host:",this), |
| 31 | address(dpy, address_, this), |
| 32 | userLbl(dpy, "User:", this), |
| 33 | user(dpy, user_, this), |
| 34 | timeoutLbl(dpy, "Seconds until automatic reject:", this), |
| 35 | timeout(dpy, "0000000000", this), |
| 36 | accept(dpy, "Accept", this, this, 60), |
| 37 | reject(dpy, "Reject", this, this, 60), |
| 38 | callback(cb), timeUntilReject(timeout_), timer(this) |
| 39 | { |
| 40 | const int pad = 4; |
| 41 | int y=pad; |
| 42 | int lblWidth = __rfbmax(addressLbl.width(), userLbl.width()); |
| 43 | userLbl.move(pad+lblWidth-userLbl.width(), y); |
| 44 | user.move(pad+lblWidth, y); |
| 45 | addressLbl.move(pad+lblWidth-addressLbl.width(), y+=userLbl.height()); |
| 46 | address.move(pad+lblWidth, y); |
| 47 | timeoutLbl.move(pad, y+=addressLbl.height()); |
| 48 | timeout.move(pad+timeoutLbl.width(), y); |
| 49 | accept.move(pad, y+=addressLbl.height()); |
| 50 | int maxWidth = __rfbmax(user.width(), address.width()+pad+lblWidth); |
| 51 | maxWidth = __rfbmax(maxWidth, accept.width()*3); |
| 52 | maxWidth = __rfbmax(maxWidth, timeoutLbl.width()+timeout.width()+pad); |
| 53 | reject.move(maxWidth-reject.width(), y); |
| 54 | resize(maxWidth + pad, y+reject.height()+pad); |
| 55 | setBorderWidth(1); |
| 56 | refreshTimeout(); |
| 57 | timer.start(1000); |
| 58 | } |
| 59 | |
| 60 | void QueryConnectDialog::deleteWindow(TXWindow*) { |
| 61 | unmap(); |
| 62 | callback->queryRejected(); |
| 63 | } |
| 64 | |
| 65 | void QueryConnectDialog::buttonActivate(TXButton* b) { |
| 66 | unmap(); |
| 67 | if (b == &accept) |
| 68 | callback->queryApproved(); |
| 69 | else if (b == &reject) |
| 70 | callback->queryRejected(); |
| 71 | } |
| 72 | |
| 73 | bool QueryConnectDialog::handleTimeout(rfb::Timer* t) { |
| 74 | if (timeUntilReject-- == 0) { |
| 75 | unmap(); |
| 76 | callback->queryTimedOut(); |
| 77 | return false; |
| 78 | } else { |
| 79 | refreshTimeout(); |
| 80 | return true; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void QueryConnectDialog::refreshTimeout() { |
| 85 | char buf[16]; |
| 86 | sprintf(buf, "%d", timeUntilReject); |
| 87 | timeout.setText(buf); |
| 88 | } |