blob: 2eea0ea071bc617b9193010044e2cb07837406af [file] [log] [blame]
Constantin Kaplinskyac306682006-05-16 08:48:31 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00003 * 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>
Constantin Kaplinskyac306682006-05-16 08:48:31 +000021#include <rfb/Exception.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000022
23using namespace rfb;
24using namespace rfb::win32;
25
26
Constantin Kaplinskyac306682006-05-16 08:48:31 +000027UserPasswdDialog::UserPasswdDialog() : Dialog(GetModuleHandle(0)),
28 showUsername(false), showPassword(false) {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000029}
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() {
Constantin Kaplinskyac306682006-05-16 08:48:31 +000041 if (username.buf)
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000042 setItemString(IDC_USERNAME, username.buf);
Constantin Kaplinskyac306682006-05-16 08:48:31 +000043 if (password.buf)
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000044 setItemString(IDC_PASSWORD, password.buf);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000045 if (!showUsername) {
46 setItemString(IDC_USERNAME, _T(""));
47 enableItem(IDC_USERNAME, false);
48 }
Constantin Kaplinskyac306682006-05-16 08:48:31 +000049 if (!showPassword) {
50 setItemString(IDC_PASSWORD, _T(""));
51 enableItem(IDC_PASSWORD, false);
52 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000053 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() {
Constantin Kaplinskyac306682006-05-16 08:48:31 +000064 username.replaceBuf(getItemString(IDC_USERNAME));
65 password.replaceBuf(getItemString(IDC_PASSWORD));
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000066 return true;
67}
68
69
Constantin Kaplinskyac306682006-05-16 08:48:31 +000070void UserPasswdDialog::getUserPasswd(char** user, char** passwd) {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000071 showUsername = user != 0;
Constantin Kaplinskyac306682006-05-16 08:48:31 +000072 showPassword = passwd != 0;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000073 if (user && *user)
Constantin Kaplinskyac306682006-05-16 08:48:31 +000074 username.replaceBuf(tstrDup(*user));
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000075 if (passwd && *passwd)
Constantin Kaplinskyac306682006-05-16 08:48:31 +000076 password.replaceBuf(tstrDup(*passwd));
77
78 if (!showDialog())
79 throw rfb::AuthCancelledException();
80
81 if (user)
82 *user = strDup(username.buf);
83 if (passwd)
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000084 *passwd = strDup(password.buf);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000085}