OptionsGeneral.cpp 8.3 KB

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