-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDlgEmailList.cpp
More file actions
273 lines (210 loc) · 7.06 KB
/
DlgEmailList.cpp
File metadata and controls
273 lines (210 loc) · 7.06 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*******************************************************************
// Copyright (c) 2002, 2003, 2004, 2005,
// Robert Umbehant
// mailto:rumbehant@wheresjames.com
//
// This program 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 program 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 program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA
//
*******************************************************************/
// DlgEmailList.cpp : implementation file
//
#include "stdafx.h"
#include "vp.h"
#include "DlgEmailList.h"
#include "WzFrame.h"
#include "WzEmailPg1.h"
#include "WzEmailPg2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgEmailList dialog
CDlgEmailList::CDlgEmailList(CWnd* pParent /*=NULL*/)
: CDialog(CDlgEmailList::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgEmailList)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_images.Create( 16, 16, ILC_MASK | ILC_COLOR24, 0, 32 );
m_images.Add( AfxGetApp()->LoadIcon( IDI_SERVER ) );
}
void CDlgEmailList::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgEmailList)
DDX_Control(pDX, IDC_LIST, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgEmailList, CDialog)
//{{AFX_MSG_MAP(CDlgEmailList)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_REMOVE, OnRemove)
ON_BN_CLICKED(IDC_EDIT, OnEdit)
ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
//}}AFX_MSG_MAP
ON_MESSAGE( CWZ_PAGECHG, OnPageChange )
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgEmailList message handlers
BOOL CDlgEmailList::OnInitDialog()
{
CDialog::OnInitDialog();
RECT rect;
m_list.GetClientRect( &rect );
long w = ( rect.right - rect.left ) - GetSystemMetrics( SM_CXVSCROLL ) - 4;
m_list.InsertColumn( 0, "Name", LVCFMT_LEFT, w >> 1 );
m_list.InsertColumn( 1, "Address", LVCFMT_LEFT, w >> 1 );
ListCtrl_SetExtendedListViewStyle( m_list.GetSafeHwnd(), LVS_EX_FULLROWSELECT );
m_list.SetImageList( &m_images, LVSIL_NORMAL );
m_list.SetImageList( &m_images, LVSIL_SMALL );
OnRefresh( 0, 0L );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
LRESULT CDlgEmailList::OnRefresh(WPARAM wParam, LPARAM lParam)
{
FillList();
return 1;
}
void CDlgEmailList::FillList()
{
m_list.DeleteAllItems();
char str[ 256 ];
HGROUP hGroup = NULL;
while ( ( hGroup = EMAILSERVERS().GetNext( hGroup ) ) != NULL )
{
// Insert the item
int item = m_list.InsertItem( m_list.GetItemCount(), hGroup->name,0 );
// Set address text
if ( item != LB_ERR )
if ( EMAILSERVERS().GetValue( hGroup, "Address", str, sizeof( str ) ) )
m_list.SetItemText( item, 1, str );
} // end while
}
void CDlgEmailList::OnAdd()
{
CWzFrame dlg( IDD_WZFTP_FRAME );
// Set reg pointer
CRKey rk;
dlg.SetData( &rk );
char helppath[ CWF_STRSIZE ];
GetModuleFileName( NULL, helppath, sizeof( helppath ) );
CWinFile::GetPathFromFileName( helppath, helppath );
CWinFile::BuildPath( helppath, helppath, "Help" );
dlg.SetHelpRoot( helppath );
// Add Pages to wizard
dlg.SetPage( 0, new CWzEmailPg1(), CWzEmailPg1::IDD, "E-Mail Server Information", "wizard_email.htm" );
dlg.SetPage( 1, new CWzEmailPg2(), CWzEmailPg2::IDD, "E-Mail Server Settings", "wizard_email.htm" );
HGROUP hGroup = NULL;
char server[ CWF_STRSIZE ] = { 0 };
do
{
// Run the wizard
if ( dlg.DoModal() != IDOK ) return;
// Get server name
if ( !rk.Get( "ServerName", server, sizeof( server ) ) || *server == 0 )
return;
// Check for existing server
hGroup = EMAILSERVERS().FindGroup( server );
// Does it exist?
} while ( hGroup != NULL &&
::MessageBox( GetSafeHwnd(),
"Server Name exists!\r\n\r\nOverwrite?",
"Overwrite Settings?",
MB_YESNO | MB_ICONQUESTION ) != IDYES );
// Copy new server settings
EMAILSERVERS().Copy( server, &rk );
FillList();
}
void CDlgEmailList::OnRemove()
{
UpdateData( TRUE );
// Get the selected item
int sel = CComCtrl::ListGetFirstSelectedItem( m_list.GetSafeHwnd() );
if ( sel == LB_ERR ) return;
// Remove the server
CString str = m_list.GetItemText( sel, 0 );
// Ask user to verify
char msg[ CWF_STRSIZE + 256 ];
wsprintf( msg, "Delete E-Mail Server %s?", str );
if ( ::MessageBox( GetSafeHwnd(), msg, "Remove E-Mail Server", MB_YESNO ) != IDYES )
return;
// Remove the server
EMAILSERVERS().RemoveGroup( str );
// Refresh list
FillList();
}
void CDlgEmailList::OnEdit()
{
CWzFrame dlg( IDD_WZFTP_FRAME );
UpdateData( TRUE );
// Get the selected item
int sel = CComCtrl::ListGetFirstSelectedItem( m_list.GetSafeHwnd() );
if ( sel == LB_ERR ) return;
// Remove the server
CString srv = m_list.GetItemText( sel, 0 );
// Ensure group exists
if ( EMAILSERVERS().FindGroup( srv ) == NULL )
return;
// Set reg pointer
CRKey rk;
dlg.SetData( &rk );
// Copy current server settings
rk.Copy( &EMAILSERVERS(), srv );
rk.Set( "ServerName", srv );
char helppath[ CWF_STRSIZE ];
GetModuleFileName( NULL, helppath, sizeof( helppath ) );
CWinFile::GetPathFromFileName( helppath, helppath );
CWinFile::BuildPath( helppath, helppath, "Help" );
dlg.SetHelpRoot( helppath );
// Add Pages to wizard
dlg.SetPage( 0, new CWzEmailPg1(), CWzEmailPg1::IDD, "E-Mail Server Information", "wizard_email.htm" );
dlg.SetPage( 1, new CWzEmailPg2(), CWzEmailPg2::IDD, "E-Mail Server Settings", "wizard_email.htm" );
// Run the wizard
if ( dlg.DoModal() != IDOK ) return;
// Get server name
char server[ CWF_STRSIZE ];
if ( !rk.Get( "ServerName", server, sizeof( server ) ) || *server == 0 )
return;
// Delete old server entry
EMAILSERVERS().RemoveGroup( srv );
// Copy new server settings
EMAILSERVERS().Copy( server, &rk );
FillList();
}
void CDlgEmailList::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
OnEdit();
*pResult = 0;
}
LRESULT CDlgEmailList::OnPageChange(WPARAM wParam, LPARAM lParam)
{
if ( wParam != 1 ) return 0;
CReg *pReg = (CReg*)CDlgTabFrame::GetData( GetSafeHwnd() );
if ( pReg == NULL ) return 0;
// Get the selected item
CString srv;
int sel = CComCtrl::ListGetFirstSelectedItem( m_list.GetSafeHwnd() );
if ( sel != LB_ERR ) srv = m_list.GetItemText( sel, 0 );
if ( sel == LB_ERR || srv.IsEmpty() )
{ ::MessageBox( GetSafeHwnd(), "You must select an E-Mail Server",
"No Server", MB_OK | MB_ICONSTOP );
return 1;
} // end if
// Save server value
pReg->Set( "CDlgEmailList", "Server", srv );
return 0;
}