Garmin Fleet Management Controller  2.19.0
CDriverLoginDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CDriverLoginDlg.cpp
5 *
6 * Copyright 2009 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "stdafx.h"
11 #include "CFmiApplication.h"
12 #include "CDriverLoginDlg.h"
13 
14 using namespace std;
15 
16 IMPLEMENT_DYNAMIC( CDriverLoginDlg, CDialog )
17 
18 BEGIN_MESSAGE_MAP( CDriverLoginDlg, CDialog )
19  ON_BN_CLICKED( IDC_DRIVERS_BTN_DELETE, OnBnClickedDelete )
20  ON_BN_CLICKED( IDC_DRIVERS_BTN_SET, OnBnClickedSet )
21  ON_EN_CHANGE( IDC_DRIVERS_EDIT_ID, OnEnChangeEditBoxes )
22  ON_EN_CHANGE( IDC_DRIVERS_EDIT_PASSWORD, OnEnChangeEditBoxes )
23  ON_BN_CLICKED( IDOK, OnBnClickedOk )
24  ON_EN_SETFOCUS( IDC_DRIVERS_EDIT_PASSWORD, OnEnSetfocusLoginEdit )
25  ON_EN_KILLFOCUS( IDC_DRIVERS_EDIT_PASSWORD, OnEnKillfocusLoginEdit )
26  ON_EN_SETFOCUS( IDC_DRIVERS_EDIT_ID, OnEnSetfocusLoginEdit )
27  ON_EN_KILLFOCUS( IDC_DRIVERS_EDIT_ID, OnEnKillfocusLoginEdit )
28  ON_LBN_SELCHANGE( IDC_DRIVERS_LST_DRIVERS, OnLbnSelchangeDriverList )
29  ON_LBN_SETFOCUS( IDC_DRIVERS_LST_DRIVERS, OnLbnSetfocusDriverList )
30  ON_LBN_KILLFOCUS( IDC_DRIVERS_LST_DRIVERS, OnLbnKillfocusDriverList )
31 END_MESSAGE_MAP()
32 
33 //----------------------------------------------------------------------
37 //----------------------------------------------------------------------
38 CDriverLoginDlg::CDriverLoginDlg
39  (
40  CWnd * aParent,
41  FmiApplicationLayer & aCom
42  )
43  : CDialog( IDD_DRIVER_LOGINS, aParent )
44  , mCom( aCom )
45  , mSelectedIndex( -1 )
46  , mDriverId( _T("") )
47  , mDriverPassword( _T("") )
48 {
49 }
50 
51 //----------------------------------------------------------------------
53 //----------------------------------------------------------------------
55 {
56 }
57 
58 //----------------------------------------------------------------------
61 //----------------------------------------------------------------------
63  (
64  CDataExchange * aDataExchange
65  )
66 {
67  CDialog::DoDataExchange( aDataExchange );
68  DDX_Control( aDataExchange, IDC_DRIVERS_LST_DRIVERS, mListBox );
69  DDX_Text( aDataExchange, IDC_DRIVERS_EDIT_ID, mDriverId );
70  DDX_Text( aDataExchange, IDC_DRIVERS_EDIT_PASSWORD, mDriverPassword );
71 }
72 
73 //----------------------------------------------------------------------
79 //----------------------------------------------------------------------
81 {
82  CDialog::OnInitDialog();
83 
84  updateListBox();
85 
86  GetDlgItem( IDC_DRIVERS_BTN_DELETE )->EnableWindow( FALSE );
87 
88  SetWindowPos( NULL, 700, 350, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
89 
90  return TRUE;
91 } /* OnInitDialog() */
92 
93 //----------------------------------------------------------------------
96 //----------------------------------------------------------------------
98 {
99  CString listItem;
100 
101  //must keep track of where the list was scrolled to
102  //since we reset content we must reinitialize these
103  mSelectedIndex = mListBox.GetCurSel();
104  int topIndex = mListBox.GetTopIndex();
105 
106  //reset content and then add current canned responses
107  mListBox.ResetContent();
108  FileBackedMap<DriverLoginItem>::const_iterator iter = mCom.mDriverLogins.begin();
109  for( ; iter != mCom.mDriverLogins.end(); iter++ )
110  {
111  if( iter->second.isValid() )
112  {
113  listItem.Format( _T("%s"), iter->second.getDriverId() );
114  mListBox.AddString( listItem );
115  }
116  }
117 
118  //reset scroll and selection
119  mSelectedIndex = -1;
120 
121  //reset scroll and selection
122  mListBox.SetCurSel( mSelectedIndex );
123  mListBox.SetTopIndex( topIndex );
124 
125 } /* updateListBox() */
126 
127 //----------------------------------------------------------------------
130 //----------------------------------------------------------------------
132 {
133  UpdateData( TRUE );
134  if( mSelectedIndex >= 0 )
135  {
136  mCom.mDriverLogins.remove( mCom.mDriverLogins.getKeyAt( mSelectedIndex ) );
137  updateListBox();
138  }
139 
140  if( mSelectedIndex < 0 )
141  {
142  GetDlgItem( IDC_DRIVERS_BTN_DELETE )->EnableWindow( FALSE );
143  }
144 
145 } /* OnBnClickedDelete() */
146 
147 //----------------------------------------------------------------------
150 //----------------------------------------------------------------------
152 {
153  UpdateData( TRUE );
154  char driverId[50];
155  char driverPassword[20];
156 
157  WideCharToMultiByte( CP_UTF8, 0, mDriverId, -1, driverId, sizeof( driverId ), NULL, NULL );
158  WideCharToMultiByte( CP_UTF8, 0, mDriverPassword, -1, driverPassword, sizeof( driverPassword ), NULL, NULL );
159 
160  DriverLoginItem & login = mCom.mDriverLogins.get( driverId );
161  login.setPassword( driverPassword );
162 
163  mCom.mDriverLogins.put( login );
164 
165  updateListBox();
166 
167 } /* OnBnClickedSet() */
168 
169 //----------------------------------------------------------------------
173 //----------------------------------------------------------------------
175 {
176  UpdateData( TRUE );
177  if( mDriverId != "" && mDriverPassword != "" )
178  {
179  GetDlgItem( IDC_DRIVERS_BTN_SET )->EnableWindow( TRUE );
180  }
181  else
182  {
183  GetDlgItem( IDC_DRIVERS_BTN_SET )->EnableWindow( FALSE );
184  }
185 } /* OnEnChangeEditBoxes() */
186 
187 
188 //----------------------------------------------------------------------
193 //----------------------------------------------------------------------
195 {
196  CListBox * driverListBox = (CListBox*) GetDlgItem( IDC_DRIVERS_LST_DRIVERS );
197  mSelectedIndex = driverListBox->GetCurSel();
198 
199  if( mSelectedIndex >= 0 && mSelectedIndex < driverListBox->GetCount() )
200  {
201  DriverLoginItem& item = mCom.mDriverLogins.get( mCom.mDriverLogins.getKeyAt( mSelectedIndex ) );
202 
203  mDriverId = item.getDriverId();
204  mDriverPassword = item.getPassword();
205 
206  UpdateData( FALSE );
207  GetDlgItem( IDC_DRIVERS_BTN_DELETE )->EnableWindow( TRUE );
208 
209  OnEnChangeEditBoxes();
210  }
211  else
212  {
213  GetDlgItem( IDC_DRIVERS_BTN_DELETE )->EnableWindow( FALSE );
214  }
215 
216  driverListBox->SetCurSel( mSelectedIndex );
217 }
218 
219 
220 //----------------------------------------------------------------------
223 //----------------------------------------------------------------------
225 {
226  DestroyWindow();
227  //not modal so don't call OnOK()
228 } /* OnBnClickedOk */
229 
230 //----------------------------------------------------------------------
233 //----------------------------------------------------------------------
235 {
236  DestroyWindow();
237 } /* OnCancel */
238 
239 //----------------------------------------------------------------------
242 //----------------------------------------------------------------------
244 {
245  CDialog::PostNcDestroy();
246 } /* PostNcDestroy() */
247 
248 //----------------------------------------------------------------------
253 //----------------------------------------------------------------------
255 {
256  SendMessage( DM_SETDEFID, IDC_DRIVERS_BTN_SET );
257 } /* OnEnSetfocusLoginEdit */
258 
259 //----------------------------------------------------------------------
264 //----------------------------------------------------------------------
266 {
267  SendMessage( DM_SETDEFID, IDOK );
268 } /* OnEnKillfocusLoginEdit */
269 
270 //----------------------------------------------------------------------
274 //----------------------------------------------------------------------
276 {
277  SendMessage( DM_SETDEFID, IDC_DRIVERS_BTN_DELETE );
278 } /* OnLbnSetfocusDriverList */
279 
280 //----------------------------------------------------------------------
284 //----------------------------------------------------------------------
286 {
287  SendMessage( DM_SETDEFID, IDOK );
288 } /* OnLbnKillfocusDriverList */
afx_msg void OnLbnSelchangeDriverList()
Selection Changed handler for the Driver List box.
#define IDC_DRIVERS_EDIT_ID
Definition: resource.h:379
#define IDC_DRIVERS_EDIT_PASSWORD
Definition: resource.h:378
const_iterator begin()
Iterator positioned at the first element in the map.
Definition: FileBackedMap.h:59
BOOL OnInitDialog()
This function is called when the window is created.
afx_msg void OnBnClickedOk()
Button handler for the OK button.
CString getDriverId() const
Get the driver ID as a CString.
afx_msg void OnLbnKillfocusDriverList()
Handles the kill focus event for the driver list.
afx_msg void OnBnClickedDelete()
Button handler for the Delete button.
STL namespace.
#define IDC_DRIVERS_BTN_DELETE
Definition: resource.h:375
afx_msg void OnBnClickedSet()
Button handler for the Set button.
const_iterator end()
Iterator positioned after the last element in the map.
Definition: FileBackedMap.h:67
virtual ~CDriverLoginDlg()
Destructor.
#define FALSE
Definition: garmin_types.h:46
afx_msg void OnEnKillfocusLoginEdit()
Handles the kill focus event for the driver ID and password edit boxes.
afx_msg void OnEnChangeEditBoxes()
Edit handler for the Driver ID and Driver Password boxes.
#define TRUE
Definition: garmin_types.h:45
Serial communication controller for Garmin and FMI packets.
afx_msg void OnEnSetfocusLoginEdit()
Handles the set focus event for the driver ID and password edit boxes.
#define IDC_DRIVERS_BTN_SET
Definition: resource.h:380
afx_msg void OnCancel()
Handler for the Cancel action.
void updateListBox()
Update the canned response list box from the canned response map owned by FmiApplicationLayer.
Map whose contents are also saved to a file.
Definition: FileBackedMap.h:32
afx_msg void OnLbnSetfocusDriverList()
Handles the set focus event for the driver list.
Dialog allowing the user to manage canned responses.
#define IDD_DRIVER_LOGINS
Definition: resource.h:47
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
void PostNcDestroy()
Called by MFC after the window has been destroyed; performs final termination activities.
CString getPassword() const
Set the ID (key) of this item.
void setPassword(const std::string &aPassword)
Set the password of this driver.
#define IDC_DRIVERS_LST_DRIVERS
Definition: resource.h:381
Data structure to holds an allowed driver login (ID and password). Used by the FmiApplicationLayer to...