OptionsGeneral.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // OptionsGeneral.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "OptionsGeneral.h"
  6. #include "InternetUpdate.h"
  7. #include <io.h>
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // COptionsGeneral property page
  15. IMPLEMENT_DYNCREATE(COptionsGeneral, CPropertyPage)
  16. COptionsGeneral::COptionsGeneral() : CPropertyPage(COptionsGeneral::IDD)
  17. {
  18. //{{AFX_DATA_INIT(COptionsGeneral)
  19. //}}AFX_DATA_INIT
  20. }
  21. COptionsGeneral::~COptionsGeneral()
  22. {
  23. }
  24. void COptionsGeneral::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CPropertyPage::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(COptionsGeneral)
  28. DDX_Control(pDX, IDC_GET_PATH, m_btGetPath);
  29. DDX_Control(pDX, IDC_PATH, m_ePath);
  30. DDX_Control(pDX, IDC_SET_DB_PATH, m_btSetDatabasePath);
  31. DDX_Control(pDX, IDC_CHECK_UPDATES, m_btCheckForUpdates);
  32. DDX_Control(pDX, IDC_COMPACT_REPAIR, m_btCompactAndRepair);
  33. DDX_Control(pDX, IDC_EXPIRE_AFTER, m_eExpireAfter);
  34. DDX_Control(pDX, IDC_MAX_SAVED_COPIES, m_eMaxSavedCopies);
  35. DDX_Control(pDX, IDC_MAXIMUM, m_btMaximumCheck);
  36. DDX_Control(pDX, IDC_EXPIRE, m_btExpire);
  37. DDX_Control(pDX, IDC_DISPLAY_IN_SYSTEMTRAY, m_btShowIconInSysTray);
  38. DDX_Control(pDX, IDC_START_ON_STARTUP, m_btRunOnStartup);
  39. //}}AFX_DATA_MAP
  40. DDX_Control(pDX, IDC_ALLOW_DUPLICATES, m_btAllowDuplicates);
  41. DDX_Control(pDX, IDC_UPDATE_TIME_ON_PASTE, m_btUpdateTimeOnPaste);
  42. DDX_Control(pDX, IDC_SAVE_MULTIPASTE, m_btSaveMultiPaste);
  43. }
  44. BEGIN_MESSAGE_MAP(COptionsGeneral, CPropertyPage)
  45. //{{AFX_MSG_MAP(COptionsGeneral)
  46. ON_BN_CLICKED(IDC_BT_COMPACT_AND_REPAIR, OnBtCompactAndRepair)
  47. ON_BN_CLICKED(IDC_CHECK_FOR_UPDATES, OnCheckForUpdates)
  48. ON_BN_CLICKED(IDC_SET_DB_PATH, OnSetDbPath)
  49. ON_BN_CLICKED(IDC_GET_PATH, OnGetPath)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // COptionsGeneral message handlers
  54. BOOL COptionsGeneral::OnInitDialog()
  55. {
  56. CPropertyPage::OnInitDialog();
  57. m_pParent = (COptionsSheet *)GetParent();
  58. m_btRunOnStartup.SetCheck(CGetSetOptions::GetRunOnStartUp());
  59. m_btShowIconInSysTray.SetCheck(CGetSetOptions::GetShowIconInSysTray());
  60. m_btMaximumCheck.SetCheck(CGetSetOptions::GetCheckForMaxEntries());
  61. m_btExpire.SetCheck(CGetSetOptions::GetCheckForExpiredEntries());
  62. m_btCompactAndRepair.SetCheck(CGetSetOptions::GetCompactAndRepairOnExit());
  63. m_btCheckForUpdates.SetCheck(CGetSetOptions::GetCheckForUpdates());
  64. m_eExpireAfter.SetNumber(CGetSetOptions::GetExpiredEntries());
  65. m_eMaxSavedCopies.SetNumber(CGetSetOptions::GetMaxEntries());
  66. m_btAllowDuplicates.SetCheck( g_Opt.m_bAllowDuplicates );
  67. m_btUpdateTimeOnPaste.SetCheck( g_Opt.m_bUpdateTimeOnPaste );
  68. m_btSaveMultiPaste.SetCheck( g_Opt.m_bSaveMultiPaste );
  69. CString csPath = CGetSetOptions::GetDBPath(FALSE);
  70. if(csPath.IsEmpty())
  71. {
  72. m_ePath.EnableWindow(FALSE);
  73. m_btGetPath.EnableWindow(FALSE);
  74. csPath = CGetSetOptions::GetDBPath();
  75. m_ePath.SetWindowText(csPath);
  76. }
  77. else
  78. {
  79. m_btSetDatabasePath.SetCheck(BST_CHECKED);
  80. m_ePath.SetWindowText(csPath);
  81. }
  82. return TRUE;
  83. }
  84. BOOL COptionsGeneral::OnApply()
  85. {
  86. UpdateData();
  87. ::SendMessage(theApp.m_MainhWnd, WM_SHOW_TRAY_ICON, m_btShowIconInSysTray.GetCheck(), 0);
  88. CGetSetOptions::SetShowIconInSysTray(m_btShowIconInSysTray.GetCheck());
  89. CGetSetOptions::SetRunOnStartUp(m_btRunOnStartup.GetCheck());
  90. CGetSetOptions::SetCheckForMaxEntries(m_btMaximumCheck.GetCheck());
  91. CGetSetOptions::SetCheckForExpiredEntries(m_btExpire.GetCheck());
  92. CGetSetOptions::SetCompactAndRepairOnExit(m_btCompactAndRepair.GetCheck());
  93. CGetSetOptions::SetCheckForUpdates(m_btCheckForUpdates.GetCheck());
  94. CGetSetOptions::SetMaxEntries(m_eMaxSavedCopies.GetNumber());
  95. CGetSetOptions::SetExpiredEntries(m_eExpireAfter.GetNumber());
  96. g_Opt.SetAllowDuplicates( m_btAllowDuplicates.GetCheck() );
  97. g_Opt.SetUpdateTimeOnPaste( m_btUpdateTimeOnPaste.GetCheck() );
  98. g_Opt.SetSaveMultiPaste( m_btSaveMultiPaste.GetCheck() );
  99. if(m_btSetDatabasePath.GetCheck() == BST_CHECKED)
  100. {
  101. CString csPath;
  102. m_ePath.GetWindowText(csPath);
  103. bool bSetPath = true;
  104. if(csPath.IsEmpty() == FALSE)
  105. {
  106. if(_access(csPath, 0) == -1)
  107. {
  108. CString cs;
  109. cs.Format("The database %s does not exist.\n\nCreate a new database?", csPath);
  110. if(MessageBox(cs, "Ditto", MB_YESNO) == IDYES)
  111. {
  112. theApp.CloseDB();
  113. // -- create a new one
  114. if(CreateDB(csPath))
  115. {
  116. CGetSetOptions::SetDBPath(csPath);
  117. }
  118. else
  119. MessageBox("Error Creating Database");
  120. bSetPath = false;
  121. }
  122. else
  123. return FALSE;
  124. }
  125. else
  126. {
  127. if(ValidDB(csPath) == FALSE)
  128. {
  129. MessageBox("Invalid Database", "Ditto", MB_OK);
  130. m_ePath.SetFocus();
  131. return FALSE;
  132. }
  133. }
  134. }
  135. if((csPath != CGetSetOptions::GetDBPath(FALSE)) && (bSetPath))
  136. {
  137. CGetSetOptions::SetDBPath(csPath);
  138. theApp.CloseDB();
  139. }
  140. }
  141. return CPropertyPage::OnApply();
  142. }
  143. BOOL COptionsGeneral::OnSetActive()
  144. {
  145. return CPropertyPage::OnSetActive();
  146. }
  147. void COptionsGeneral::OnBtCompactAndRepair()
  148. {
  149. CompactDatabase();
  150. RepairDatabase();
  151. }
  152. void COptionsGeneral::OnCheckForUpdates()
  153. {
  154. CInternetUpdate update;
  155. if(update.CheckForUpdate(m_hWnd, FALSE, TRUE))
  156. {
  157. ::PostMessage(theApp.m_MainhWnd, WM_CLOSE_APP, 0, 0);
  158. m_pParent->EndDialog(-1);
  159. }
  160. }
  161. void COptionsGeneral::OnSetDbPath()
  162. {
  163. if(m_btSetDatabasePath.GetCheck() == BST_CHECKED)
  164. {
  165. m_ePath.EnableWindow(TRUE);
  166. m_btGetPath.EnableWindow(TRUE);
  167. }
  168. else
  169. {
  170. m_ePath.EnableWindow(FALSE);
  171. m_btGetPath.EnableWindow(FALSE);
  172. }
  173. }
  174. void COptionsGeneral::OnGetPath()
  175. {
  176. OPENFILENAME FileName;
  177. char szFileName[400];
  178. char szDir[400];
  179. memset(&FileName, 0, sizeof(FileName));
  180. memset(szFileName, 0, sizeof(szFileName));
  181. memset(&szDir, 0, sizeof(szDir));
  182. FileName.lStructSize = sizeof(FileName);
  183. FileName.lpstrTitle = "Open Database";
  184. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  185. FileName.nMaxFile = 400;
  186. FileName.lpstrFile = szFileName;
  187. FileName.lpstrInitialDir = szDir;
  188. FileName.lpstrFilter = "Database Files (.MDB)\0*.mdb";
  189. FileName.lpstrDefExt = "mdb";
  190. if(GetOpenFileName(&FileName) == 0)
  191. return;
  192. CString csPath(FileName.lpstrFile);
  193. if(ValidDB(csPath) == FALSE)
  194. {
  195. MessageBox("Invalid Database", "Ditto", MB_OK);
  196. m_ePath.SetFocus();
  197. }
  198. else
  199. m_ePath.SetWindowText(csPath);
  200. }