OptionsGeneral.cpp 10 KB

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