OptionsGeneral.cpp 8.0 KB

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