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