Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[040794]: ExpPWListDlg.cpp Maximize Restore History

Download this file

ExpPWListDlg.cpp    202 lines (169 with data), 5.6 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// ExpPWListDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ThisMfcApp.h"
#include "ExpPWListDlg.h"
#include "corelib/MyString.h"
#include "corelib/Util.h"
// CExpPWListDlg dialog
CExpPWListDlg::CExpPWListDlg(CWnd* pParent, const CString& a_filespec)
: CDialog(CExpPWListDlg::IDD, pParent)
{
const int FILE_DISP_LEN = 75;
if (a_filespec.GetLength() > FILE_DISP_LEN) {
// m_message = a_filespec.Right(FILE_DISP_LEN - 3); // truncate for display
// m_message.Insert(0, _T("..."));
m_message = a_filespec.Left(FILE_DISP_LEN/2-5) +
_T(" ... ") + a_filespec.Right(FILE_DISP_LEN/2);
} else {
m_message = a_filespec;
}
m_iSortedColumn = -1;
m_bSortAscending = TRUE;
}
CExpPWListDlg::~CExpPWListDlg()
{
}
void CExpPWListDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EXPIRED_PASSWORD_LIST, m_expPWListCtrl);
DDX_Text(pDX, IDC_MESSAGE, m_message);
}
BEGIN_MESSAGE_MAP(CExpPWListDlg, CDialog)
ON_BN_CLICKED(IDC_COPY_EXP_TO_CLIPBOARD, OnBnClickedCopyExpToClipboard)
ON_BN_CLICKED(IDOK, OnOK)
ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHeaderClicked)
ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHeaderClicked)
END_MESSAGE_MAP()
// CExpPWListDlg message handlers
BOOL
CExpPWListDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_expPWListCtrl.InsertColumn(0, _T("Group"));
m_expPWListCtrl.InsertColumn(1, _T("Title"));
m_expPWListCtrl.InsertColumn(2, _T("User Name"));
m_expPWListCtrl.InsertColumn(3, _T("Expiry Date/Time"));
int nPos = 0;
POSITION itempos;
POSITION listpos = m_pexpPWList->GetHeadPosition();
while (listpos != NULL) {
itempos = listpos;
const ExpPWEntry exppwentry = m_pexpPWList->GetAt(listpos);
nPos = m_expPWListCtrl.InsertItem(nPos, exppwentry.group);
m_expPWListCtrl.SetItemText(nPos, 1, exppwentry.title);
m_expPWListCtrl.SetItemText(nPos, 2, exppwentry.user);
m_expPWListCtrl.SetItemText(nPos, 3, exppwentry.expiryascdate);
m_expPWListCtrl.SetItemData(nPos, (DWORD)itempos);
m_pexpPWList->GetNext(listpos);
}
m_expPWListCtrl.SetRedraw(FALSE);
for (int i = 0; i < 4; i++) {
m_expPWListCtrl.SetColumnWidth(i, LVSCW_AUTOSIZE);
int nColumnWidth = m_expPWListCtrl.GetColumnWidth(i);
m_expPWListCtrl.SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER);
int nHeaderWidth = m_expPWListCtrl.GetColumnWidth(i);
m_expPWListCtrl.SetColumnWidth(i, max(nColumnWidth, nHeaderWidth));
}
m_expPWListCtrl.SetRedraw(TRUE);
return TRUE;
}
void
CExpPWListDlg::OnOK()
{
CDialog::OnOK();
}
void
CExpPWListDlg::OnBnClickedCopyExpToClipboard()
{
CString data= _T("Group\tTitle\tUsername\tPassword Expiry Date\r\n");
const CString CRLF = _T("\r\n");
const CString TAB = _T('\t');
POSITION listpos = m_pexpPWList->GetHeadPosition();
while (listpos != NULL) {
const ExpPWEntry exppwentry = m_pexpPWList->GetAt(listpos);
data = data +
(CString)exppwentry.group + TAB +
(CString)exppwentry.title + TAB +
(CString)exppwentry.user + TAB +
(CString)exppwentry.expiryexpdate + CRLF;
m_pexpPWList->GetNext(listpos);
}
app.SetClipboardData(data);
}
void
CExpPWListDlg::OnHeaderClicked(NMHDR* pNMHDR, LRESULT* pResult)
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
if(phdn->iButton == 0) {
// User clicked on header using left mouse button
if(phdn->iItem == m_iSortedColumn)
m_bSortAscending = !m_bSortAscending;
else
m_bSortAscending = TRUE;
m_iSortedColumn = phdn->iItem;
m_expPWListCtrl.SortItems(CompareFunc, (LPARAM)this);
// Note: WINVER defines the minimum system level for which this is program compiled and
// NOT the level of system it is running on!
// In this case, these values are defined in Windows XP and later and supported
// by V6 of comctl32.dll (supplied with Windows XP) and later.
// They should be ignored by earlier levels of this dll or .....
// we can check the dll version (code available on request)!
#if (WINVER < 0x0501) // These are already defined for WinXP and later
#define HDF_SORTUP 0x0400
#define HDF_SORTDOWN 0x0200
#endif
HDITEM HeaderItem;
HeaderItem.mask = HDI_FORMAT;
m_expPWListCtrl.GetHeaderCtrl()->GetItem(m_iSortedColumn, &HeaderItem);
// Turn off all arrows
HeaderItem.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
// Turn on the correct arrow
HeaderItem.fmt |= ((m_bSortAscending == TRUE) ? HDF_SORTUP : HDF_SORTDOWN);
m_expPWListCtrl.GetHeaderCtrl()->SetItem(m_iSortedColumn, &HeaderItem);
}
*pResult = 0;
}
int CALLBACK CExpPWListDlg::CompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM closure)
{
CExpPWListDlg *self = (CExpPWListDlg*)closure;
int nSortColumn = self->m_iSortedColumn;
POSITION Lpos = (POSITION)lParam1;
POSITION Rpos = (POSITION)lParam2;
const ExpPWEntry pLHS = self->m_pexpPWList->GetAt(Lpos);
const ExpPWEntry pRHS = self->m_pexpPWList->GetAt(Rpos);
CMyString group1, title1, username1;
CMyString group2, title2, username2;
time_t t1, t2;
int iResult;
switch(nSortColumn) {
case 0:
group1 = pLHS.group;
group2 = pRHS.group;
iResult = ((CString)group1).CompareNoCase(group2);
break;
case 1:
title1 = pLHS.title;
title2 = pRHS.title;
iResult = ((CString)title1).CompareNoCase(title2);
break;
case 2:
username1 = pLHS.user;
username2 = pRHS.user;
iResult = ((CString)username1).CompareNoCase(username2);
break;
case 3:
t1 = pLHS.expirytttdate;
t2 = pRHS.expirytttdate;
iResult = ((long) t1 < (long) t2) ? -1 : 1;
break;
default:
iResult = 0; // should never happen - just keep compiler happy
ASSERT(FALSE);
}
if (!self->m_bSortAscending)
iResult *= -1;
return iResult;
}