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.

UserPasswdDialog.cxx 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright (C) 2002-2004 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 <vncviewer/UserPasswdDialog.h>
  19. #include <vncviewer/resource.h>
  20. using namespace rfb;
  21. using namespace rfb::win32;
  22. UserPasswdDialog::UserPasswdDialog() : Dialog(GetModuleHandle(0)), showUsername(false) {
  23. }
  24. void UserPasswdDialog::setCSecurity(const CSecurity* cs) {
  25. description.replaceBuf(tstrDup(cs->description()));
  26. }
  27. bool UserPasswdDialog::showDialog() {
  28. return Dialog::showDialog(MAKEINTRESOURCE(IDD_VNC_AUTH_DLG));
  29. }
  30. void UserPasswdDialog::initDialog() {
  31. if (username.buf) {
  32. setItemString(IDC_USERNAME, username.buf);
  33. tstrFree(username.takeBuf());
  34. }
  35. if (password.buf) {
  36. setItemString(IDC_PASSWORD, password.buf);
  37. tstrFree(password.takeBuf());
  38. }
  39. if (!showUsername) {
  40. setItemString(IDC_USERNAME, _T(""));
  41. enableItem(IDC_USERNAME, false);
  42. }
  43. if (description.buf) {
  44. TCharArray title(128);
  45. GetWindowText(handle, title.buf, 128);
  46. _tcsncat(title.buf, _T(" ["), 128);
  47. _tcsncat(title.buf, description.buf, 128);
  48. _tcsncat(title.buf, _T("]"), 128);
  49. SetWindowText(handle, title.buf);
  50. }
  51. }
  52. bool UserPasswdDialog::onOk() {
  53. username.buf = getItemString(IDC_USERNAME);
  54. password.buf = getItemString(IDC_PASSWORD);
  55. return true;
  56. }
  57. bool UserPasswdDialog::getUserPasswd(char** user, char** passwd) {
  58. bool result = false;
  59. showUsername = user != 0;
  60. if (user && *user)
  61. username.buf = tstrDup(*user);
  62. if (passwd && *passwd)
  63. password.buf = tstrDup(*passwd);
  64. if (showDialog()) {
  65. if (user)
  66. *user = strDup(username.buf);
  67. *passwd = strDup(password.buf);
  68. result = true;
  69. }
  70. tstrFree(username.takeBuf());
  71. tstrFree(password.takeBuf());
  72. return result;
  73. }