Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[292574]: AddDlg.cpp Maximize Restore History

Download this file

AddDlg.cpp    153 lines (127 with data), 3.8 kB

  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
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/// \file AddDlg.cpp
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "PasswordSafe.h"
#include "ThisMfcApp.h"
#include "DboxMain.h"
#include "AddDlg.h"
#include "PwFont.h"
#include "OptionsPasswordPolicy.h"
#include "RandomPassword.h"
#include "corelib/PWCharPool.h"
#include "corelib/PWSprefs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//-----------------------------------------------------------------------------
CAddDlg::CAddDlg(CWnd* pParent)
: CDialog(CAddDlg::IDD, pParent), m_password(_T("")), m_notes(_T("")),
m_username(_T("")), m_title(_T("")), m_group(_T(""))
{
DBGMSG("CAddDlg()\n");
}
BOOL CAddDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetPasswordFont(GetDlgItem(IDC_PASSWORD));
return TRUE;
}
void CAddDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_PASSWORD, (CString&)m_password);
DDX_Text(pDX, IDC_NOTES, (CString&)m_notes);
DDX_Text(pDX, IDC_USERNAME, (CString&)m_username);
DDX_Text(pDX, IDC_TITLE, (CString&)m_title);
if(!pDX->m_bSaveAndValidate) {
// We are initializing the dialog. Populate the groups combo box.
CComboBox comboGroup;
comboGroup.Attach(GetDlgItem(IDC_GROUP)->GetSafeHwnd());
// For some reason, MFC calls us twice when initializing.
// Populate the combo box only once.
if(0 == comboGroup.GetCount()) {
CStringArray aryGroups;
app.m_core.GetUniqueGroups(aryGroups);
for(int igrp=0; igrp<aryGroups.GetSize(); igrp++) {
comboGroup.AddString((LPCTSTR)aryGroups[igrp]);
}
}
comboGroup.Detach();
}
DDX_CBString(pDX, IDC_GROUP, (CString&)m_group);
}
BEGIN_MESSAGE_MAP(CAddDlg, CDialog)
ON_BN_CLICKED(ID_HELP, OnHelp)
ON_BN_CLICKED(IDC_RANDOM, OnRandom)
END_MESSAGE_MAP()
void
CAddDlg::OnCancel()
{
app.m_pMainWnd = NULL;
CDialog::OnCancel();
}
void
CAddDlg::OnOK()
{
UpdateData(TRUE);
//Check that data is valid
if (m_title.IsEmpty())
{
AfxMessageBox(_T("This entry must have a title."));
((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus();
return;
}
if (m_password.IsEmpty())
{
AfxMessageBox(_T("This entry must have a password."));
((CEdit*)GetDlgItem(IDC_PASSWORD))->SetFocus();
return;
}
if (!m_group.IsEmpty() && m_group[0] == '.')
{
AfxMessageBox(_T("A dot is invalid as the first character of the Group field."));
((CEdit*)GetDlgItem(IDC_GROUP))->SetFocus();
return;
}
//End check
DboxMain* pParent = (DboxMain*) GetParent();
ASSERT(pParent != NULL);
if (pParent->Find(m_group, m_title, m_username) != NULL)
{
CMyString temp =
_T("An item with Group \"") + m_group
+ _T("\", Title \"") + m_title
+ _T("\" and User Name \"") + m_username
+ _T("\" already exists.");
AfxMessageBox(temp);
((CEdit*)GetDlgItem(IDC_TITLE))->SetSel(MAKEWORD(-1, 0));
((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus();
}
else
{
app.m_pMainWnd = NULL;
CDialog::OnOK();
}
}
void CAddDlg::OnHelp()
{
#if defined(POCKET_PC)
CreateProcess( _T("PegHelp.exe"), _T("pws_ce_help.html#adddata"), NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL );
#else
//WinHelp(0x2008E, HELP_CONTEXT);
::HtmlHelp(NULL,
"pwsafe.chm::/html/entering_pwd.html",
HH_DISPLAY_TOPIC, 0);
#endif
}
void CAddDlg::OnRandom()
{
DboxMain* pParent = (DboxMain*)GetParent();
ASSERT(pParent != NULL);
UpdateData(TRUE);
if (pParent->MakeRandomPassword(this, m_password))
UpdateData(FALSE);
}
//-----------------------------------------------------------------------------