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 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <stdio.h>
  22. #include <rdr/Exception.h>
  23. #include "QueryConnectDialog.h"
  24. #include "vncExt.h"
  25. QueryConnectDialog::QueryConnectDialog(Display* dpy,
  26. const char* address_,
  27. const char* user_,
  28. int timeout_,
  29. QueryResultCallback* cb)
  30. : TXDialog(dpy, 300, 100, "VNC Server : Accept Connection?"),
  31. addressLbl(dpy, "Host:",this),
  32. address(dpy, address_, this),
  33. userLbl(dpy, "User:", this),
  34. user(dpy, user_, this),
  35. timeoutLbl(dpy, "Seconds until automatic reject:", this),
  36. timeout(dpy, "0000000000", this),
  37. accept(dpy, "Accept", this, this, 60),
  38. reject(dpy, "Reject", this, this, 60),
  39. callback(cb), timeUntilReject(timeout_), timer(this)
  40. {
  41. const int pad = 4;
  42. int y=pad;
  43. int lblWidth = __rfbmax(addressLbl.width(), userLbl.width());
  44. userLbl.move(pad+lblWidth-userLbl.width(), y);
  45. user.move(pad+lblWidth, y);
  46. addressLbl.move(pad+lblWidth-addressLbl.width(), y+=userLbl.height());
  47. address.move(pad+lblWidth, y);
  48. timeoutLbl.move(pad, y+=addressLbl.height());
  49. timeout.move(pad+timeoutLbl.width(), y);
  50. accept.move(pad, y+=addressLbl.height());
  51. int maxWidth = __rfbmax(user.width(), address.width()+pad+lblWidth);
  52. maxWidth = __rfbmax(maxWidth, accept.width()*3);
  53. maxWidth = __rfbmax(maxWidth, timeoutLbl.width()+timeout.width()+pad);
  54. reject.move(maxWidth-reject.width(), y);
  55. resize(maxWidth + pad, y+reject.height()+pad);
  56. setBorderWidth(1);
  57. refreshTimeout();
  58. timer.start(1000);
  59. }
  60. void QueryConnectDialog::deleteWindow(TXWindow*) {
  61. unmap();
  62. callback->queryRejected();
  63. }
  64. void QueryConnectDialog::buttonActivate(TXButton* b) {
  65. unmap();
  66. if (b == &accept)
  67. callback->queryApproved();
  68. else if (b == &reject)
  69. callback->queryRejected();
  70. }
  71. bool QueryConnectDialog::handleTimeout(rfb::Timer* /*t*/) {
  72. if (timeUntilReject-- == 0) {
  73. unmap();
  74. callback->queryTimedOut();
  75. return false;
  76. } else {
  77. refreshTimeout();
  78. return true;
  79. }
  80. }
  81. void QueryConnectDialog::refreshTimeout() {
  82. char buf[16];
  83. sprintf(buf, "%d", timeUntilReject);
  84. timeout.setText(buf);
  85. }