00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Prg_Data.h"
00009 #include "FolderBrowser.h"
00010 #include "mfchelp.h"
00011
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #undef THIS_FILE
00015 static char THIS_FILE[] = __FILE__;
00016 #endif
00017
00018 IMPLEMENT_DYNCREATE(CPrg_Data, CPropertyPage)
00019
00020 CPrg_Data::CPrg_Data() : CPropertyPage(CPrg_Data::IDD)
00021 {
00022 m_psp.dwFlags |= PSP_USETITLE;
00023 m_psp.pszTitle = LS (L_DATA);
00024 }
00025
00026 CPrg_Data::~CPrg_Data()
00027 {
00028 }
00029
00030 void CPrg_Data::DoDataExchange(CDataExchange* pDX)
00031 {
00032 CPropertyPage::DoDataExchange(pDX);
00033
00034
00035
00036 }
00037
00038 BEGIN_MESSAGE_MAP(CPrg_Data, CPropertyPage)
00039
00040 ON_WM_CONTEXTMENU()
00041 ON_WM_HELPINFO()
00042 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00043 ON_BN_CLICKED(IDC_KEEP_1, OnKeep1)
00044 ON_BN_CLICKED(IDC_KEEP_2, OnKeep2)
00045 ON_EN_CHANGE(IDC_FOLDER, OnChangeFolder)
00046 ON_EN_CHANGE(IDC_AUTOSAVE, OnChangeAutosave)
00047 ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
00048
00049 END_MESSAGE_MAP()
00050
00051 BOOL CPrg_Data::OnInitDialog()
00052 {
00053 CPropertyPage::OnInitDialog();
00054
00055 CSpinButtonCtrl *pSpin = (CSpinButtonCtrl*) GetDlgItem (IDC_AUTOSAVESPIN);
00056 pSpin->SetRange (1, UD_MAXVAL);
00057 SetDlgItemInt (IDC_AUTOSAVE, _DldsMgr.m_uAutosaveInterval / 60 / 1000, FALSE);
00058
00059 ApplyLanguage ();
00060
00061 CString str = _App.DataFolder ();
00062 if (str.IsEmpty ())
00063 {
00064 CheckDlgButton (IDC_KEEP_1, BST_CHECKED);
00065 }
00066 else
00067 {
00068 CheckDlgButton (IDC_KEEP_2, BST_CHECKED);
00069 SetDlgItemText (IDC_FOLDER, str);
00070 }
00071
00072 UpdateEnabled ();
00073
00074 return TRUE;
00075 }
00076
00077 void CPrg_Data::ApplyLanguage()
00078 {
00079 fsDlgLngInfo lnginfo [] = {
00080 fsDlgLngInfo (IDC_KEEP_1, L_KEEPDATAINUSERSFOLDER),
00081 fsDlgLngInfo (IDC_KEEP_2, L_KEEPINTHISFOLDER, TRUE),
00082 fsDlgLngInfo (IDC__AUTOSAVE, L_AUTOSAVE),
00083 fsDlgLngInfo (IDC__MIN, L_MIN),
00084 fsDlgLngInfo (IDC__DATADESC, L_FDMDATAFILESDESC),
00085 };
00086
00087 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), 0);
00088 }
00089
00090 BOOL CPrg_Data::OnApply()
00091 {
00092 UINT nVal;
00093
00094 nVal = GetDlgItemInt (IDC_AUTOSAVE, NULL, FALSE);
00095
00096 if (nVal == 0)
00097 {
00098
00099 CString str; str.Format (LS (L_ENTERGREATER), 0);
00100 MessageBox (str, LS (L_INPERR), MB_ICONEXCLAMATION);
00101 CEdit *pE = (CEdit*) GetDlgItem (IDC_AUTOSAVE);
00102 pE->SetSel (0, -1);
00103 pE->SetFocus ();
00104 return FALSE;
00105 }
00106
00107 _DldsMgr.m_uAutosaveInterval = nVal * 60 * 1000;
00108
00109 CString strOldVal = _App.DataFolder ();
00110 CString str;
00111 if (IsDlgButtonChecked (IDC_KEEP_2) == BST_CHECKED)
00112 GetDlgItemText (IDC_FOLDER, str);
00113 if (strOldVal != str)
00114 {
00115 _App.DataFolder (str);
00116
00117 extern bool _bNeedRecalcAppDataFolder;
00118 _bNeedRecalcAppDataFolder = true;
00119
00120 CRegKey key;
00121 if (ERROR_SUCCESS != key.Create (HKEY_CURRENT_USER, "Software\\FreeDownloadManager.ORG\\Free Upload Manager"))
00122 key.Open (HKEY_CURRENT_USER, "Software\\FreeDownloadManager.ORG\\Free Upload Manager");
00123
00124 key.SetValue (fsGetAppDataFolder (), "force_data_folder");
00125 }
00126
00127 return CPropertyPage::OnApply();
00128 }
00129
00130 void CPrg_Data::OnContextMenu(CWnd* pWnd, CPoint point)
00131 {
00132 PrepareCHMgr (point);
00133 _CHMgr.ShowMenu ();
00134 }
00135
00136 BOOL CPrg_Data::OnHelpInfo(HELPINFO* pHelpInfo)
00137 {
00138 RECT rc;
00139 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00140 if (pItem == NULL)
00141 return TRUE;
00142 pItem->GetWindowRect (&rc);
00143 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00144 {
00145 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00146 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00147 }
00148 PrepareCHMgr (pHelpInfo->MousePos);
00149 _CHMgr.OnWT ();
00150 return TRUE;
00151 }
00152
00153 void CPrg_Data::OnWhatisthis()
00154 {
00155 _CHMgr.OnWT ();
00156 }
00157
00158 void CPrg_Data::PrepareCHMgr(CPoint point)
00159 {
00160 fsCtrlContextHelp aCH1 [] = {
00161 fsCtrlContextHelp (IDC__AUTOSAVE, LS (L_AUTOSAVEHERE)),
00162 fsCtrlContextHelp (IDC_AUTOSAVE, LS (L_AUTOSAVEHERE)),
00163 };
00164
00165 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00166 CopyMemory (aCH, aCH1, sizeof (aCH));
00167
00168 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00169 }
00170
00171 void CPrg_Data::UpdateEnabled()
00172 {
00173 BOOL b = IsDlgButtonChecked (IDC_KEEP_2) == BST_CHECKED;
00174 GetDlgItem (IDC_FOLDER)->EnableWindow (b);
00175 GetDlgItem (IDC_BROWSE)->EnableWindow (b);
00176 }
00177
00178 void CPrg_Data::OnKeep1()
00179 {
00180 UpdateEnabled ();
00181 SetModified ();
00182 }
00183
00184 void CPrg_Data::OnKeep2()
00185 {
00186 CString str;
00187 GetDlgItemText (IDC_FOLDER, str);
00188
00189 if (str.IsEmpty ())
00190 {
00191 OnBrowse ();
00192 GetDlgItemText (IDC_FOLDER, str);
00193 if (str.IsEmpty ())
00194 {
00195 CheckRadioButton (IDC_KEEP_1, IDC_KEEP_2, IDC_KEEP_1);
00196 return;
00197 }
00198 }
00199
00200 UpdateEnabled ();
00201 SetModified ();
00202 }
00203
00204 void CPrg_Data::OnChangeFolder()
00205 {
00206 SetModified ();
00207 }
00208
00209 void CPrg_Data::OnChangeAutosave()
00210 {
00211 SetModified ();
00212 }
00213
00214 void CPrg_Data::OnBrowse()
00215 {
00216 CString str;
00217 GetDlgItemText (IDC_FOLDER, str);
00218
00219 if (str.GetLength () > 3 && (str [str.GetLength () - 1] == '\\' || str [str.GetLength () - 1] == '/'))
00220 str.GetBuffer (0) [str.GetLength () - 1] = 0;
00221
00222 CFolderBrowser *fb = CFolderBrowser::Create (LS (L_CHOOSEOUTFOLDER), str, NULL, this);
00223 if (fb == NULL)
00224 return;
00225
00226 SetDlgItemText (IDC_FOLDER, fb->GetPath ());
00227 GetDlgItem (IDC_FOLDER)->SetFocus ();
00228 }