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