blob: 8e506966313c8d276345591fc4650f188e84def3 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* 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
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000019#include <winvnc/VNCServerWin32.h>
Adam Tkace450dc42010-06-25 10:04:27 +000020#include <winvnc/QueryConnectDialog.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000021#include <winvnc/resource.h>
22#include <rfb_win32/Win32Util.h>
23#include <rfb_win32/TCharArray.h>
24#include <rfb_win32/Service.h>
25#include <rfb/LogWriter.h>
26
27using namespace rfb;
28using namespace win32;
29using namespace winvnc;
30
31static LogWriter vlog("QueryConnectDialog");
32
33static IntParameter timeout("QueryConnectTimeout",
34 "Number of seconds to show the Accept Connection dialog before "
35 "rejecting the connection",
36 10);
37
38
39// - Visible methods
40
41QueryConnectDialog::QueryConnectDialog(network::Socket* sock_,
42 const char* userName_,
43 VNCServerWin32* s)
44: Thread("QueryConnectDialog"), Dialog(GetModuleHandle(0)),
45 sock(sock_), approve(false), server(s) {
46 peerIp.buf = sock->getPeerAddress();
47 userName.buf = strDup(userName_);
48}
49
50void QueryConnectDialog::startDialog() {
51 start();
52}
53
54
55// - Thread overrides
56
57void QueryConnectDialog::run() {
58 countdown = timeout;
59 try {
60 if (desktopChangeRequired() && !changeDesktop())
61 throw rdr::Exception("changeDesktop failed");
62 approve = Dialog::showDialog(MAKEINTRESOURCE(IDD_QUERY_CONNECT));
63 server->queryConnectionComplete();
64 } catch (...) {
65 server->queryConnectionComplete();
66 throw;
67 }
68}
69
70
71// - Dialog overrides
72
73void QueryConnectDialog::initDialog() {
74 if (!SetTimer(handle, 1, 1000, 0))
75 throw rdr::SystemException("SetTimer", GetLastError());
76 setItemString(IDC_QUERY_HOST, TStr(peerIp.buf));
77 if (!userName.buf)
78 userName.buf = strDup("(anonymous)");
79 setItemString(IDC_QUERY_USER, TStr(userName.buf));
80 setCountdownLabel();
81}
82
83void QueryConnectDialog::setCountdownLabel() {
84 TCHAR buf[16];
85 _stprintf(buf, _T("%d"), countdown);
86 setItemString(IDC_QUERY_COUNTDOWN, buf);
87}
88
89BOOL QueryConnectDialog::dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
90 if (msg == WM_TIMER) {
91 if (--countdown == 0 || desktopChangeRequired()) {
92 DestroyWindow(hwnd);
93 } else {
94 setCountdownLabel();
95 }
96 return TRUE;
97 } else {
98 return Dialog::dialogProc(hwnd, msg, wParam, lParam);
99 }
100}