OptionsGeneral.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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(csLanguage.IsEmpty() == FALSE)
  150. {
  151. if(!theApp.m_Language.LoadLanguageFile(csLanguage))
  152. {
  153. CString cs;
  154. cs.Format("Error loading language file - %s - \n\n%s", csLanguage, theApp.m_Language.m_csLastError);
  155. MessageBox(cs, "Ditto", MB_OK);
  156. }
  157. }
  158. CString csMax;
  159. m_MaxClipSize.GetWindowText(csMax);
  160. g_Opt.SetMaxClipSizeInBytes(atoi(csMax));
  161. if(m_btSetDatabasePath.GetCheck() == BST_CHECKED)
  162. {
  163. CString csPath;
  164. m_ePath.GetWindowText(csPath);
  165. bool bSetPath = true;
  166. if(csPath.IsEmpty() == FALSE)
  167. {
  168. if(_access(csPath, 0) == -1)
  169. {
  170. CString cs;
  171. cs.Format("The database %s does not exist.\n\nCreate a new database?", csPath);
  172. if(MessageBox(cs, "Ditto", MB_YESNO) == IDYES)
  173. {
  174. theApp.CloseDB();
  175. // -- create a new one
  176. if(CreateDB(csPath))
  177. {
  178. CGetSetOptions::SetDBPath(csPath);
  179. }
  180. else
  181. MessageBox("Error Creating Database");
  182. bSetPath = false;
  183. }
  184. else
  185. return FALSE;
  186. }
  187. else
  188. {
  189. if(ValidDB(csPath) == FALSE)
  190. {
  191. MessageBox("Invalid Database", "Ditto", MB_OK);
  192. m_ePath.SetFocus();
  193. return FALSE;
  194. }
  195. }
  196. }
  197. if((csPath != CGetSetOptions::GetDBPath(FALSE)) && (bSetPath))
  198. {
  199. CGetSetOptions::SetDBPath(csPath);
  200. theApp.CloseDB();
  201. }
  202. }
  203. return CPropertyPage::OnApply();
  204. }
  205. BOOL COptionsGeneral::OnSetActive()
  206. {
  207. return CPropertyPage::OnSetActive();
  208. }
  209. void COptionsGeneral::OnBtCompactAndRepair()
  210. {
  211. CWaitCursor wait;
  212. CompactDatabase();
  213. UpdateWindow();
  214. RepairDatabase();
  215. }
  216. void COptionsGeneral::OnCheckForUpdates()
  217. {
  218. CInternetUpdate update;
  219. if(update.CheckForUpdate(m_hWnd, FALSE, TRUE))
  220. {
  221. ::PostMessage(theApp.m_MainhWnd, WM_CLOSE_APP, 0, 0);
  222. m_pParent->EndDialog(-1);
  223. }
  224. }
  225. void COptionsGeneral::OnSetDbPath()
  226. {
  227. if(m_btSetDatabasePath.GetCheck() == BST_CHECKED)
  228. {
  229. m_ePath.EnableWindow(TRUE);
  230. m_btGetPath.EnableWindow(TRUE);
  231. }
  232. else
  233. {
  234. m_ePath.EnableWindow(FALSE);
  235. m_btGetPath.EnableWindow(FALSE);
  236. }
  237. }
  238. void COptionsGeneral::OnGetPath()
  239. {
  240. OPENFILENAME FileName;
  241. char szFileName[400];
  242. char szDir[400];
  243. memset(&FileName, 0, sizeof(FileName));
  244. memset(szFileName, 0, sizeof(szFileName));
  245. memset(&szDir, 0, sizeof(szDir));
  246. FileName.lStructSize = sizeof(FileName);
  247. FileName.lpstrTitle = "Open Database";
  248. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  249. FileName.nMaxFile = 400;
  250. FileName.lpstrFile = szFileName;
  251. FileName.lpstrInitialDir = szDir;
  252. FileName.lpstrFilter = "Database Files (.MDB)\0*.mdb";
  253. FileName.lpstrDefExt = "mdb";
  254. if(GetOpenFileName(&FileName) == 0)
  255. return;
  256. CString csPath(FileName.lpstrFile);
  257. if(ValidDB(csPath) == FALSE)
  258. {
  259. MessageBox("Invalid Database", "Ditto", MB_OK);
  260. m_ePath.SetFocus();
  261. }
  262. else
  263. m_ePath.SetWindowText(csPath);
  264. }
  265. void COptionsGeneral::OnSelectSound()
  266. {
  267. OPENFILENAME FileName;
  268. char szFileName[400];
  269. char szDir[400];
  270. memset(&FileName, 0, sizeof(FileName));
  271. memset(szFileName, 0, sizeof(szFileName));
  272. memset(&szDir, 0, sizeof(szDir));
  273. FileName.lStructSize = sizeof(FileName);
  274. FileName.lpstrTitle = "Select .wav file";
  275. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  276. FileName.nMaxFile = 400;
  277. FileName.lpstrFile = szFileName;
  278. FileName.lpstrInitialDir = szDir;
  279. FileName.lpstrFilter = "Sounds(*.wav)\0*.wav";
  280. FileName.lpstrDefExt = "wav";
  281. if(GetOpenFileName(&FileName) == 0)
  282. return;
  283. CString csPath(FileName.lpstrFile);
  284. if(csPath.GetLength())
  285. m_csPlaySound = csPath;
  286. UpdateData(FALSE);
  287. }
  288. void COptionsGeneral::OnButtonPlay()
  289. {
  290. UpdateData();
  291. PlaySound(m_csPlaySound, NULL, SND_FILENAME|SND_ASYNC);
  292. }
  293. void COptionsGeneral::OnButtonAbout()
  294. {
  295. CMultiLanguage Lang;
  296. CString csLanguage;
  297. m_cbLanguage.GetLBText(m_cbLanguage.GetCurSel(), csLanguage);
  298. Lang.SetOnlyGetHeader(true);
  299. if(Lang.LoadLanguageFile(csLanguage))
  300. {
  301. CString csMessage;
  302. csMessage.Format("Language - %s\n"
  303. "Version - %d\n"
  304. "Author - %s\n"
  305. "Notes - %s", csLanguage,
  306. Lang.GetVersion(),
  307. Lang.GetAuthor(),
  308. Lang.GetNotes());
  309. MessageBox(csMessage, "Ditto", MB_OK);
  310. }
  311. else
  312. {
  313. CString csError;
  314. csError.Format("Error loading language file - %s - reason = ", csLanguage, Lang.m_csLastError);
  315. MessageBox(csError, "Ditto", MB_OK);
  316. }
  317. }