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

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