You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QueryConnectDialog.cxx 2.9KB

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