-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxMsAccountDetails.cpp
373 lines (357 loc) · 13.4 KB
/
wxMsAccountDetails.cpp
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*-----------------------------------------------------------------
* Name: wxMsAccountsDetails.cpp
* Purpose:
* Author: A. Wiegert
*
* Copyright:
* Licence: wxWidgets license
*---------------------------------------------------------------- */
/*----------------------------------------------------------------
* Standard wxWidgets headers
*---------------------------------------------------------------- */
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
# if defined ( _DEBUG )
// this statement NEEDS to go BEFORE all headers
# define _CRTDBG_MAP_ALLOC
# endif
#endif
#include "wxMsPreProcDefsh.h" // needs to be first
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
/* For all others, include the necessary headers
* (this file is usually all you need because it
* includes almost all "standard" wxWidgets headers) */
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ------------------------------------------------------------------
#include "wxMsh.h"
#include "wxMsAccounth.h"
#include "wxMsAccountsDialogh.h"
#include "wxMsAccountDetailsh.h"
#include "wxMsPop3AdvancedOptionsDlgh.h"
#if defined( _MSC_VER )
#include "Urlmon.h"
#endif
// ------------------------------------------------------------------
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
// only good for MSVC
// this block needs to go AFTER all headers
#include <crtdbg.h>
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif
#endif
// -------------------------------------------------------------
// Constructor
MyAccountsDetailsDialog::MyAccountsDetailsDialog( MyAccountsDialog* parent ) :
MyBaseAccountsDetailsDialog( parent )
{
m_parent = parent;
m_pCurrent = NULL;
m_wsTestRawCapaString = wxEmptyString;
m_bTestHasCapa = m_bTestHasUidl = false;
// clean up local iniPrefs_t - does NOT cause memory leaks
// makes sure the temporary data are all initialized properly
m_iniAcctDetailsPrefs.lPrefVer = 0l;
for( int i = 0; i < IE_MAX; i++ )
{
m_iniAcctDetailsPrefs.data[i].wsKeyStr = m_iniAcctDetailsPrefs.data[i].wsPathStr = wxEmptyString;
m_iniAcctDetailsPrefs.data[i].eType = eLong;
}
}
//------------------------------------------------------------------
// Called automagically by InitDialog() to set up the data
// prior to the dialog being shown
// Note since this overrides a predefined function, it MUST have
// the name and return type as given here
/**
* For now set the first account data.
* Down the road, we will have to save the last used account
* and display its data
*/
bool MyAccountsDetailsDialog::TransferDataToWindow( void )
{
int i;
if ( m_parent->m_bEditingAccount )
{
MyAccountList::iterator iter;
for ( i = 0, iter = wxGetApp().m_AccountList.begin();
iter != wxGetApp().m_AccountList.end(); ++iter, i++ )
{
MyMsAccountEl *current = *iter;
if( i == m_parent->m_iSelectedAccount )
{
m_pCurrent = current;
m_textCtrlAccountName->SetValue( current->m_wsAcctName );
m_textCtrlPop3ServerUrl->SetValue( current->m_wsPopServerUrl );
m_textCtrlUserName->SetValue( current->m_wsUserName );
m_textCtrlPassword->SetValue( current->m_wsPassword );
m_checkBoxRememberPW->SetValue( current->m_bSavePassword );
}
}
}
else // we must be adding a new account
{
m_textCtrlAccountName->Clear();
m_textCtrlPop3ServerUrl->Clear();
m_textCtrlUserName->Clear();
m_textCtrlPassword->Clear();
m_checkBoxRememberPW->SetValue( false );
}
m_notebookAcctDetails->SetSelection( 0 ); // select 'incoming' page
Fit();
return true;
}
//------------------------------------------------------------------
// Called automagically when dialog is dismissed via OK button
// Note since this overrides a predefined function, it MUST have
// the name and return type as given here
bool MyAccountsDetailsDialog::TransferDataFromWindow( void )
{
// Note for the style chosen, this is always true - textctrl does not accept CR/LF etc
// bool bIsSingleLine = m_textCtrlAccountName->IsSingleLine();
wxString wsAcctName = m_textCtrlAccountName->GetLineText( 0 );
if ( wsAcctName.IsEmpty() )
{
wxMessageBox( _T("The account name cannot be empty!"), "Notice", wxOK );
m_textCtrlUserName->SetFocus();
m_textCtrlPop3ServerUrl->SetFocus();
return false;
}
wxString wsPopServerUrl = m_textCtrlPop3ServerUrl->GetLineText( 0 );
if ( wsPopServerUrl.IsEmpty() )
{
wxMessageBox( _T("The server address cannot be empty!"), "Notice", wxOK );
m_textCtrlPop3ServerUrl->SetFocus();
return false;
}
wxString wsUserName = m_textCtrlUserName->GetLineText( 0 );
if ( wsUserName.IsEmpty() )
{
wxMessageBox( _T("The user name cannot be empty!"), "Notice", wxOK );
return false;
}
if ( m_parent->m_bEditingAccount ) // update the existing account
{
// since we saved the pointer to the item in the account list
m_pCurrent->m_wsAcctName = wsAcctName;
m_pCurrent->m_wsPopServerUrl =wsPopServerUrl;
m_pCurrent->m_wsUserName = wsUserName;
m_pCurrent->m_wsPassword = m_textCtrlPassword->GetLineText( 0 );
if( m_checkBoxRememberPW->GetValue() )
{
m_pCurrent->m_bSavePassword = true;
}
else
{
m_pCurrent->m_bSavePassword = false;
}
}
else // must be adding a new account
{
// make sure we have no duplicate account names
size_t i;
wxString wsT;
MyAccountList::iterator iter;
for ( i = 0, iter = wxGetApp().m_AccountList.begin();
iter != wxGetApp().m_AccountList.end(); ++iter, i++ )
{
MyMsAccountEl *current = *iter;
if ( current->m_wsAcctName == wsAcctName )
{
wsT.Printf(
_("Another account with the name %s already exists!\n")
+_("Please chose a different name."),
current->m_wsAcctName );
wxMessageBox( wsT, "Notice", wxOK );
m_textCtrlAccountName->SetFocus();
return false;
}
}
// we must have a new account - add its info to the array
MyMsAccountEl *p = new MyMsAccountEl;
p->m_bEnabled = true; // enable a new account by default
p->m_wsPopServerUrl = m_textCtrlPop3ServerUrl->GetValue();
// set the current default account type/kind
p->m_wsAcctKind = _T("POP3");
p->m_wsAcctName = m_textCtrlAccountName->GetValue();
p->m_wsUserName = m_textCtrlUserName->GetValue();
if( m_checkBoxRememberPW->GetValue() )
{
p->m_wsPassword = m_textCtrlPassword->GetValue();
p->m_bSavePassword = m_checkBoxRememberPW->GetValue();
}
else
{
p->m_wsPassword = wxEmptyString;
p->m_bSavePassword = false;
}
// add any results from the server test
p->m_wsRawCapaString = m_wsTestRawCapaString;
p->m_bHasCapa = m_bTestHasCapa;
p->m_bHasUidl = m_bTestHasUidl;
wxGetApp().m_AccountList.Append( p );
}
Fit();
return true;
}
// ------------------------------------------------------------------
void MyAccountsDialog::OnAccountAdd( wxCommandEvent& event )
{
m_bEditingAccount = false;
int j = 0;
MyAccountsDetailsDialog dlg( this );
wxGetApp().MakeConfigCopy( g_iniPrefs, dlg.m_iniAcctDetailsPrefs );
// data setup and saving is handled by the two functions
// MyAccountsDialog::TransferDataTo/FromWindow()
// all we need to do is 'Show' it ...
if ( dlg.ShowModal() == wxID_OK )
{
// all info MUST be saved here or else aborting the dialog
// will have bad side effects as some of the INI data will/may
// have been changed but not everything
wxGetApp().MakeConfigCopy( dlg.m_iniAcctDetailsPrefs, g_iniPrefs );
// also redraw the accounts grid completely
m_gridMailAccounts->BeginBatch();
m_gridMailAccounts->ClearGrid(); // clear the data
int iNRows = m_gridMailAccounts->GetNumberRows();
if ( iNRows )
m_gridMailAccounts->DeleteRows( 0, iNRows ); // clear the grid itself
MyAccountList::iterator iter;
for ( j = 0, iter = wxGetApp().m_AccountList.begin();
iter != wxGetApp().m_AccountList.end(); ++iter, j++)
{
MyMsAccountEl *current = *iter;
// ...process the current element...
m_gridMailAccounts->InsertRows( j, 1 );
m_gridMailAccounts->SetCellRenderer( j, 0, new wxGridCellBoolRenderer);
m_gridMailAccounts->SetCellEditor( j, 0, new wxGridCellBoolEditor);
m_gridMailAccounts->SetCellAlignment( j, 0, wxALIGN_CENTRE, wxALIGN_CENTRE );
m_gridMailAccounts->SetCellValue( j, 0, current->m_bEnabled ? _T("1") : _T("") );
m_gridMailAccounts->SetCellValue( j, 1, current->m_wsAcctName );
m_gridMailAccounts->SetCellValue( j, 2, current->m_wsPopServerUrl );
m_gridMailAccounts->SetCellValue( j, 3, current->m_wsUserName );
// password & rest are not displayed in this dialog
}
m_gridMailAccounts->EndBatch();
}
#if defined _DEBUG
int i = m_gridMailAccounts->GetNumberRows();
i++;
i--; // keep GCC happy
#endif
AccountGridSize();
m_gridMailAccounts->SelectRow( j );
}
// ------------------------------------------------------------------
void MyAccountsDialog::OnAccountEdit( wxCommandEvent& event )
{
m_bEditingAccount = true;
wxArrayInt waiRows = m_gridMailAccounts->GetSelectedRows();
if ( (waiRows.GetCount() > 1) || ( waiRows.GetCount() == 0 ) )
{
wxMessageBox( _("No account selected!"), _T(""), wxOK | wxICON_INFORMATION );
return;
}
MyAccountsDetailsDialog dlg( this );
wxGetApp().MakeConfigCopy( g_iniPrefs, dlg.m_iniAcctDetailsPrefs );
// data setup and saving is handled by the two functions
// MyAccountsDialog::TransferDataTo/FromWindow()
// all we need to do is 'Show' it ...
if ( dlg.ShowModal() == wxID_OK )
{
// all info MUST be saved here or else aborting the dialog
// will have bad side effects as some of the INI data will
// have been changed but not everything
wxGetApp().MakeConfigCopy( dlg.m_iniAcctDetailsPrefs, g_iniPrefs );
int j;
// display the information
// see if we have a row with the same account already
int iNRows = m_gridMailAccounts->GetNumberRows();
// also redraw the accounts grid completely
m_gridMailAccounts->BeginBatch();
m_gridMailAccounts->ClearGrid();
m_gridMailAccounts->DeleteRows( 0, iNRows );
MyAccountList::iterator iter;
for ( j = 0, iter = wxGetApp().m_AccountList.begin();
iter != wxGetApp().m_AccountList.end(); ++iter, j++)
{
MyMsAccountEl *current = *iter;
// ...process the current element...
m_gridMailAccounts->InsertRows( j, 1 );
m_gridMailAccounts->SetCellRenderer( j, 0, new wxGridCellBoolRenderer);
m_gridMailAccounts->SetCellEditor( j, 0, new wxGridCellBoolEditor);
m_gridMailAccounts->SetCellAlignment( j, 0, wxALIGN_CENTRE, wxALIGN_CENTRE );
m_gridMailAccounts->SetCellValue( j, 0, current->m_bEnabled ? _T("1") : _T("") );
m_gridMailAccounts->SetCellValue( j, 1, current->m_wsAcctName );
m_gridMailAccounts->SetCellValue( j, 2, current->m_wsPopServerUrl );
m_gridMailAccounts->SetCellValue( j, 3, current->m_wsUserName );
// password & rest are not displayed in this dialog
}
m_gridMailAccounts->EndBatch();
}
AccountGridSize();
m_gridMailAccounts->SelectRow( waiRows[0] );
}
// ------------------------------------------------------------------
void MyAccountsDialog::OnAccountDelete( wxCommandEvent& event )
{
wxArrayInt waiRows = m_gridMailAccounts->GetSelectedRows();
if ( (waiRows.GetCount() > 1) || ( waiRows.GetCount() == 0 ) )
return;
// remove the requested item
int j;
MyAccountList::iterator iter;
for ( j = 0, iter = wxGetApp().m_AccountList.begin();
iter != wxGetApp().m_AccountList.end(); ++iter, j++)
{
if( waiRows[0] == j )
{
wxGetApp().m_AccountList.remove( *iter );
break;
}
}
int iNRows = m_gridMailAccounts->GetNumberRows();
// redraw the accounts grid completely
m_gridMailAccounts->BeginBatch();
m_gridMailAccounts->ClearGrid(); // clear the data
m_gridMailAccounts->DeleteRows( 0, iNRows ); // clear the grid itself
for ( j = 0, iter = wxGetApp().m_AccountList.begin();
iter != wxGetApp().m_AccountList.end(); ++iter, j++)
{
MyMsAccountEl *current = *iter;
// ...process the current element...
m_gridMailAccounts->InsertRows( j, 1 );
m_gridMailAccounts->SetCellRenderer( j, 0, new wxGridCellBoolRenderer);
m_gridMailAccounts->SetCellEditor( j, 0, new wxGridCellBoolEditor);
m_gridMailAccounts->SetCellAlignment( j, 0, wxALIGN_CENTRE, wxALIGN_CENTRE );
m_gridMailAccounts->SetCellValue( j, 0, current->m_bEnabled ? _T("1") : _T("") );
m_gridMailAccounts->SetCellValue( j, 1, current->m_wsAcctName );
m_gridMailAccounts->SetCellValue( j, 2, current->m_wsPopServerUrl );
m_gridMailAccounts->SetCellValue( j, 3, current->m_wsUserName );
// password & rest are not displayed in this dialog
}
m_gridMailAccounts->EndBatch();
m_gridMailAccounts->SelectRow( waiRows[0] );
}
// ------------------------------------------------------------------
void MyAccountsDetailsDialog::OnAdvancedPopConfig(wxCommandEvent& event)
{
MyAdvancedPopConfigDlg dlg( this );
if ( dlg.ShowModal() == wxID_OK )
{
;
}
}
// ------------------------------- eof ------------------------------