OptionsGeneral.cpp 6.4 KB

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