OptionsGeneral.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. m_csTitle = theApp.m_Language.GetString("GeneralTitle", "General");
  20. m_psp.pszTitle = m_csTitle;
  21. m_psp.dwFlags |= PSP_USETITLE;
  22. //{{AFX_DATA_INIT(COptionsGeneral)
  23. m_csPlaySound = _T("");
  24. //}}AFX_DATA_INIT
  25. }
  26. COptionsGeneral::~COptionsGeneral()
  27. {
  28. }
  29. void COptionsGeneral::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CPropertyPage::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(COptionsGeneral)
  33. DDX_Control(pDX, IDC_EDIT_SAVE_DELAY, m_SaveDelay);
  34. DDX_Control(pDX, IDC_COMBO_LANGUAGE, m_cbLanguage);
  35. DDX_Control(pDX, IDC_EDIT_MAX_SIZE, m_MaxClipSize);
  36. DDX_Control(pDX, IDC_SEND_PASTE_MESSAGE, m_btSendPasteMessage);
  37. DDX_Control(pDX, IDC_HIDE_DITO_ON_HOT_KEY, m_btHideDittoOnHotKey);
  38. DDX_Control(pDX, IDC_DESC_TEXT_SIZE, m_DescTextSize);
  39. DDX_Control(pDX, IDC_GET_PATH, m_btGetPath);
  40. DDX_Control(pDX, IDC_PATH, m_ePath);
  41. DDX_Control(pDX, IDC_SET_DB_PATH, m_btSetDatabasePath);
  42. DDX_Control(pDX, IDC_CHECK_UPDATES, m_btCheckForUpdates);
  43. DDX_Control(pDX, IDC_EXPIRE_AFTER, m_eExpireAfter);
  44. DDX_Control(pDX, IDC_MAX_SAVED_COPIES, m_eMaxSavedCopies);
  45. DDX_Control(pDX, IDC_MAXIMUM, m_btMaximumCheck);
  46. DDX_Control(pDX, IDC_EXPIRE, m_btExpire);
  47. DDX_Control(pDX, IDC_DISPLAY_IN_SYSTEMTRAY, m_btShowIconInSysTray);
  48. DDX_Control(pDX, IDC_START_ON_STARTUP, m_btRunOnStartup);
  49. DDX_Text(pDX, IDC_EDIT_PLAY_SOUND, m_csPlaySound);
  50. //}}AFX_DATA_MAP
  51. DDX_Control(pDX, IDC_ALLOW_DUPLICATES, m_btAllowDuplicates);
  52. DDX_Control(pDX, IDC_UPDATE_TIME_ON_PASTE, m_btUpdateTimeOnPaste);
  53. DDX_Control(pDX, IDC_SAVE_MULTIPASTE, m_btSaveMultiPaste);
  54. }
  55. BEGIN_MESSAGE_MAP(COptionsGeneral, CPropertyPage)
  56. //{{AFX_MSG_MAP(COptionsGeneral)
  57. ON_BN_CLICKED(IDC_BT_COMPACT_AND_REPAIR, OnBtCompactAndRepair)
  58. ON_BN_CLICKED(IDC_CHECK_FOR_UPDATES, OnCheckForUpdates)
  59. ON_BN_CLICKED(IDC_SET_DB_PATH, OnSetDbPath)
  60. ON_BN_CLICKED(IDC_GET_PATH, OnGetPath)
  61. ON_BN_CLICKED(IDC_SELECT_SOUND, OnSelectSound)
  62. ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
  63. ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout)
  64. //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66. /////////////////////////////////////////////////////////////////////////////
  67. // COptionsGeneral message handlers
  68. BOOL COptionsGeneral::OnInitDialog()
  69. {
  70. CPropertyPage::OnInitDialog();
  71. m_pParent = (COptionsSheet *)GetParent();
  72. m_btRunOnStartup.SetCheck(CGetSetOptions::GetRunOnStartUp());
  73. m_btShowIconInSysTray.SetCheck(CGetSetOptions::GetShowIconInSysTray());
  74. m_btMaximumCheck.SetCheck(CGetSetOptions::GetCheckForMaxEntries());
  75. m_btExpire.SetCheck(CGetSetOptions::GetCheckForExpiredEntries());
  76. m_btCheckForUpdates.SetCheck(CGetSetOptions::GetCheckForUpdates());
  77. m_eExpireAfter.SetNumber(CGetSetOptions::GetExpiredEntries());
  78. m_eMaxSavedCopies.SetNumber(CGetSetOptions::GetMaxEntries());
  79. m_DescTextSize.SetNumber(g_Opt.m_bDescTextSize);
  80. m_SaveDelay.SetNumber(g_Opt.m_lSaveClipDelay);
  81. m_btAllowDuplicates.SetCheck( g_Opt.m_bAllowDuplicates );
  82. m_btUpdateTimeOnPaste.SetCheck( g_Opt.m_bUpdateTimeOnPaste );
  83. m_btSaveMultiPaste.SetCheck( g_Opt.m_bSaveMultiPaste );
  84. m_btHideDittoOnHotKey.SetCheck(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown);
  85. m_btSendPasteMessage.SetCheck(g_Opt.m_bSendPasteMessageAfterSelection);
  86. if(g_Opt.m_lMaxClipSizeInBytes > 0)
  87. {
  88. CString csMax;
  89. csMax.Format("%d", g_Opt.m_lMaxClipSizeInBytes);
  90. m_MaxClipSize.SetWindowText(csMax);
  91. }
  92. CString csPath = CGetSetOptions::GetDBPath(FALSE);
  93. if(csPath.IsEmpty())
  94. {
  95. m_ePath.EnableWindow(FALSE);
  96. m_btGetPath.EnableWindow(FALSE);
  97. csPath = CGetSetOptions::GetDBPath();
  98. m_ePath.SetWindowText(csPath);
  99. }
  100. else
  101. {
  102. m_btSetDatabasePath.SetCheck(BST_CHECKED);
  103. m_ePath.SetWindowText(csPath);
  104. }
  105. m_csPlaySound = g_Opt.m_csPlaySoundOnCopy;
  106. FillLanguages();
  107. UpdateData(FALSE);
  108. theApp.m_Language.UpdateOptionGeneral(this);
  109. return TRUE;
  110. }
  111. void COptionsGeneral::FillLanguages()
  112. {
  113. CString csFile = CGetSetOptions::GetExeFileName();
  114. csFile = GetFilePath(csFile);
  115. csFile += "language\\*.xml";
  116. CString csLanguage = CGetSetOptions::GetLanguageFile();
  117. CFileFind find;
  118. BOOL bCont = find.FindFile(csFile);
  119. while(bCont)
  120. {
  121. bCont = find.FindNextFile();
  122. int nIndex = m_cbLanguage.AddString(find.GetFileTitle());
  123. if(find.GetFileTitle() == csLanguage)
  124. m_cbLanguage.SetCurSel(nIndex);
  125. }
  126. }
  127. BOOL COptionsGeneral::OnApply()
  128. {
  129. UpdateData();
  130. ::SendMessage(theApp.m_MainhWnd, WM_SHOW_TRAY_ICON, m_btShowIconInSysTray.GetCheck(), 0);
  131. CGetSetOptions::SetShowIconInSysTray(m_btShowIconInSysTray.GetCheck());
  132. CGetSetOptions::SetRunOnStartUp(m_btRunOnStartup.GetCheck());
  133. CGetSetOptions::SetCheckForMaxEntries(m_btMaximumCheck.GetCheck());
  134. CGetSetOptions::SetCheckForExpiredEntries(m_btExpire.GetCheck());
  135. CGetSetOptions::SetCheckForUpdates(m_btCheckForUpdates.GetCheck());
  136. CGetSetOptions::SetHideDittoOnHotKeyIfAlreadyShown(m_btHideDittoOnHotKey.GetCheck());
  137. CGetSetOptions::SetSendPasteAfterSelection(m_btSendPasteMessage.GetCheck());
  138. CGetSetOptions::SetMaxEntries(m_eMaxSavedCopies.GetNumber());
  139. CGetSetOptions::SetExpiredEntries(m_eExpireAfter.GetNumber());
  140. CGetSetOptions::SetDescTextSize(m_DescTextSize.GetNumber());
  141. CGetSetOptions::SetSaveClipDelay(m_SaveDelay.GetNumber());
  142. CGetSetOptions::SetPlaySoundOnCopy(m_csPlaySound);
  143. g_Opt.SetAllowDuplicates(m_btAllowDuplicates.GetCheck());
  144. g_Opt.SetUpdateTimeOnPaste(m_btUpdateTimeOnPaste.GetCheck());
  145. g_Opt.SetSaveMultiPaste(m_btSaveMultiPaste.GetCheck());
  146. CString csLanguage;
  147. m_cbLanguage.GetLBText(m_cbLanguage.GetCurSel(), csLanguage);
  148. g_Opt.SetLanguageFile(csLanguage);
  149. if(!theApp.m_Language.LoadLanguageFile(csLanguage))
  150. {
  151. CString cs;
  152. cs.Format("Error loading language file - %s - \n\n%s", csLanguage, theApp.m_Language.m_csLastError);
  153. MessageBox(cs, "Ditto", MB_OK);
  154. }
  155. CString csMax;
  156. m_MaxClipSize.GetWindowText(csMax);
  157. g_Opt.SetMaxClipSizeInBytes(atoi(csMax));
  158. if(m_btSetDatabasePath.GetCheck() == BST_CHECKED)
  159. {
  160. CString csPath;
  161. m_ePath.GetWindowText(csPath);
  162. bool bSetPath = true;
  163. if(csPath.IsEmpty() == FALSE)
  164. {
  165. if(_access(csPath, 0) == -1)
  166. {
  167. CString cs;
  168. cs.Format("The database %s does not exist.\n\nCreate a new database?", csPath);
  169. if(MessageBox(cs, "Ditto", MB_YESNO) == IDYES)
  170. {
  171. theApp.CloseDB();
  172. // -- create a new one
  173. if(CreateDB(csPath))
  174. {
  175. CGetSetOptions::SetDBPath(csPath);
  176. }
  177. else
  178. MessageBox("Error Creating Database");
  179. bSetPath = false;
  180. }
  181. else
  182. return FALSE;
  183. }
  184. else
  185. {
  186. if(ValidDB(csPath) == FALSE)
  187. {
  188. MessageBox("Invalid Database", "Ditto", MB_OK);
  189. m_ePath.SetFocus();
  190. return FALSE;
  191. }
  192. }
  193. }
  194. if((csPath != CGetSetOptions::GetDBPath(FALSE)) && (bSetPath))
  195. {
  196. CGetSetOptions::SetDBPath(csPath);
  197. theApp.CloseDB();
  198. }
  199. }
  200. return CPropertyPage::OnApply();
  201. }
  202. BOOL COptionsGeneral::OnSetActive()
  203. {
  204. return CPropertyPage::OnSetActive();
  205. }
  206. void COptionsGeneral::OnBtCompactAndRepair()
  207. {
  208. CWaitCursor wait;
  209. CompactDatabase();
  210. UpdateWindow();
  211. RepairDatabase();
  212. }
  213. void COptionsGeneral::OnCheckForUpdates()
  214. {
  215. CInternetUpdate update;
  216. if(update.CheckForUpdate(m_hWnd, FALSE, TRUE))
  217. {
  218. ::PostMessage(theApp.m_MainhWnd, WM_CLOSE_APP, 0, 0);
  219. m_pParent->EndDialog(-1);
  220. }
  221. }
  222. void COptionsGeneral::OnSetDbPath()
  223. {
  224. if(m_btSetDatabasePath.GetCheck() == BST_CHECKED)
  225. {
  226. m_ePath.EnableWindow(TRUE);
  227. m_btGetPath.EnableWindow(TRUE);
  228. }
  229. else
  230. {
  231. m_ePath.EnableWindow(FALSE);
  232. m_btGetPath.EnableWindow(FALSE);
  233. }
  234. }
  235. void COptionsGeneral::OnGetPath()
  236. {
  237. OPENFILENAME FileName;
  238. char szFileName[400];
  239. char szDir[400];
  240. memset(&FileName, 0, sizeof(FileName));
  241. memset(szFileName, 0, sizeof(szFileName));
  242. memset(&szDir, 0, sizeof(szDir));
  243. FileName.lStructSize = sizeof(FileName);
  244. FileName.lpstrTitle = "Open Database";
  245. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  246. FileName.nMaxFile = 400;
  247. FileName.lpstrFile = szFileName;
  248. FileName.lpstrInitialDir = szDir;
  249. FileName.lpstrFilter = "Database Files (.MDB)\0*.mdb";
  250. FileName.lpstrDefExt = "mdb";
  251. if(GetOpenFileName(&FileName) == 0)
  252. return;
  253. CString csPath(FileName.lpstrFile);
  254. if(ValidDB(csPath) == FALSE)
  255. {
  256. MessageBox("Invalid Database", "Ditto", MB_OK);
  257. m_ePath.SetFocus();
  258. }
  259. else
  260. m_ePath.SetWindowText(csPath);
  261. }
  262. void COptionsGeneral::OnSelectSound()
  263. {
  264. OPENFILENAME FileName;
  265. char szFileName[400];
  266. char szDir[400];
  267. memset(&FileName, 0, sizeof(FileName));
  268. memset(szFileName, 0, sizeof(szFileName));
  269. memset(&szDir, 0, sizeof(szDir));
  270. FileName.lStructSize = sizeof(FileName);
  271. FileName.lpstrTitle = "Select .wav file";
  272. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  273. FileName.nMaxFile = 400;
  274. FileName.lpstrFile = szFileName;
  275. FileName.lpstrInitialDir = szDir;
  276. FileName.lpstrFilter = "Sounds(*.wav)\0*.wav";
  277. FileName.lpstrDefExt = "wav";
  278. if(GetOpenFileName(&FileName) == 0)
  279. return;
  280. CString csPath(FileName.lpstrFile);
  281. if(csPath.GetLength())
  282. m_csPlaySound = csPath;
  283. UpdateData(FALSE);
  284. }
  285. void COptionsGeneral::OnButtonPlay()
  286. {
  287. UpdateData();
  288. PlaySound(m_csPlaySound, NULL, SND_FILENAME|SND_ASYNC);
  289. }
  290. void COptionsGeneral::OnButtonAbout()
  291. {
  292. CMultiLanguage Lang;
  293. CString csLanguage;
  294. m_cbLanguage.GetLBText(m_cbLanguage.GetCurSel(), csLanguage);
  295. Lang.SetOnlyGetHeader(true);
  296. if(Lang.LoadLanguageFile(csLanguage))
  297. {
  298. CString csMessage;
  299. csMessage.Format("Language - %s\n"
  300. "Version - %d\n"
  301. "Author - %s\n"
  302. "Notes - %s", csLanguage,
  303. Lang.GetVersion(),
  304. Lang.GetAuthor(),
  305. Lang.GetNotes());
  306. MessageBox(csMessage, "Ditto", MB_OK);
  307. }
  308. else
  309. {
  310. CString csError;
  311. csError.Format("Error loading language file - %s - reason = ", csLanguage, Lang.m_csLastError);
  312. MessageBox(csError, "Ditto", MB_OK);
  313. }
  314. }