summaryrefslogtreecommitdiffstats
path: root/vncviewer/UserPasswdDialog.cxx
blob: 8ab4ba4c9b32e1d74cfbb63f52b385d149b4878c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Copyright (C) 2002-2004 RealVNC Ltd.  All Rights Reserved.
 *    
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

#include <vncviewer/UserPasswdDialog.h>
#include <vncviewer/resource.h>

using namespace rfb;
using namespace rfb::win32;


UserPasswdDialog::UserPasswdDialog() : Dialog(GetModuleHandle(0)), showUsername(false) {
}


void UserPasswdDialog::setCSecurity(const CSecurity* cs) {
  description.replaceBuf(tstrDup(cs->description()));
}

bool UserPasswdDialog::showDialog() {
  return Dialog::showDialog(MAKEINTRESOURCE(IDD_VNC_AUTH_DLG));
}

void UserPasswdDialog::initDialog() {
  if (username.buf) {
    setItemString(IDC_USERNAME, username.buf);
    tstrFree(username.takeBuf());
  }
  if (password.buf) {
    setItemString(IDC_PASSWORD, password.buf);
    tstrFree(password.takeBuf());
  }
  if (!showUsername) {
    setItemString(IDC_USERNAME, _T(""));
    enableItem(IDC_USERNAME, false);
  }
  if (description.buf) {
    TCharArray title(128);
    GetWindowText(handle, title.buf, 128);
    _tcsncat(title.buf, _T(" ["), 128);
    _tcsncat(title.buf, description.buf, 128);
    _tcsncat(title.buf, _T("]"), 128);
    SetWindowText(handle, title.buf);
  }
}

bool UserPasswdDialog::onOk() {
	username.buf = getItemString(IDC_USERNAME);
	password.buf = getItemString(IDC_PASSWORD);
  return true;
}


bool UserPasswdDialog::getUserPasswd(char** user, char** passwd) {
  bool result = false;
  showUsername = user != 0;
  if (user && *user)
    username.buf = tstrDup(*user);
  if (passwd && *passwd)
    password.buf = tstrDup(*passwd);
  if (showDialog()) {
    if (user)
      *user = strDup(username.buf);
    *passwd = strDup(password.buf);
    result = true;
  }
  tstrFree(username.takeBuf());
  tstrFree(password.takeBuf());
  return result;
}