00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "GroupDlg.h"
00009 #include "DownloadsWnd.h"
00010 #include "FolderBrowser.h"
00011 #include "system.h"
00012 #include "CreateDownloadDlg.h"
00013
00014 #ifdef _DEBUG
00015 #define new DEBUG_NEW
00016 #undef THIS_FILE
00017 static char THIS_FILE[] = __FILE__;
00018 #endif
00019
00020 #define ID_FOLDER_MACROS_0 20000
00021
00022 CGroupDlg::CGroupDlg(vmsDownloadsGroupSmartPtr pGroup, vmsDownloadsGroupSmartPtr pParentGroup, CWnd* pParent )
00023 : CDialog(CGroupDlg::IDD, pParent), m_pGroup (pGroup), m_pParentGroup (pParentGroup)
00024 {
00025
00026
00027 m_wndGroups.m_bHasAllGroupsItem = true;
00028 }
00029
00030 void CGroupDlg::DoDataExchange(CDataExchange* pDX)
00031 {
00032 CDialog::DoDataExchange(pDX);
00033
00034 DDX_Control(pDX, IDC_GROUPS, m_wndGroups);
00035 DDX_Control(pDX, IDC_CHOOSEFOLDER, m_btnChooseFolder);
00036
00037 }
00038
00039 BEGIN_MESSAGE_MAP(CGroupDlg, CDialog)
00040
00041 ON_BN_CLICKED(IDC_CHOOSEFOLDER, OnChoosefolder)
00042 ON_EN_CHANGE(IDC_GRPNAME, OnChangeGrpname)
00043 ON_WM_CONTEXTMENU()
00044 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00045 ON_WM_HELPINFO()
00046 ON_BN_CLICKED(IDC_MACROSES, OnMacroses)
00047 ON_CBN_SELCHANGE(IDC_GROUPS, OnSelchangeGroups)
00048 ON_CBN_SELCHANGE(IDC_GRPFOLDER, OnSelchangeGrpfolder)
00049 ON_CBN_EDITCHANGE(IDC_GRPFOLDER, OnEditchangeGrpfolder)
00050
00051 ON_COMMAND_RANGE(ID_FOLDER_MACROS_0, ID_FOLDER_MACROS_0 + 50, OnInsertMacros)
00052 END_MESSAGE_MAP()
00053
00054 BOOL CGroupDlg::OnInitDialog()
00055 {
00056 CDialog::OnInitDialog();
00057
00058 m_btnChooseFolder.SetIcon (SICO (IDI_CHOOSEFOLDER));
00059
00060 m_wndGroups.Fill ();
00061
00062 if (m_pGroup)
00063 {
00064 PDLDS_GROUPS_TREE p = _DldsGrps.FindGroupInTree (m_pGroup)->GetRoot ();
00065 if (p == _DldsGrps.GetGroupsTree ())
00066 m_pParentGroup = NULL;
00067 else
00068 m_pParentGroup = p->GetData ();
00069 m_wndGroups.EnableWindow (FALSE);
00070 }
00071
00072 m_wndGroups.SelectGroup (m_pParentGroup);
00073
00074 CComboBox *pDirs = (CComboBox*) GetDlgItem (IDC_GRPFOLDER);
00075 for (int i = 0; i < _LastFolders.GetRecordCount (); i++)
00076 pDirs->AddString (_LastFolders.GetRecord (i));
00077
00078
00079 if (m_pGroup == NULL)
00080 {
00081 m_strBaseFolder = m_pParentGroup == NULL ?
00082 _DldsGrps.GetGroupsRootOutFolder () : m_pParentGroup->strOutFolder;
00083 SetDlgItemText (IDC_GRPFOLDER, m_strBaseFolder);
00084 m_bPathChanged = FALSE;
00085 }
00086 else
00087 {
00088 m_bPathChanged = TRUE;
00089
00090 if (m_pGroup->strName.GetLength () < m_pGroup->strOutFolder.GetLength ())
00091 {
00092 if (lstrcmp (m_pGroup->strOutFolder + m_pGroup->strOutFolder.GetLength () -
00093 m_pGroup->strName.GetLength (), m_pGroup->strName) == 0)
00094 {
00095 m_strBaseFolder = m_pGroup->strOutFolder;
00096 m_strBaseFolder.Delete (m_pGroup->strOutFolder.GetLength () -
00097 m_pGroup->strName.GetLength (), m_pGroup->strName.GetLength ());
00098 m_bPathChanged = FALSE;
00099 }
00100 }
00101
00102 SetDlgItemText (IDC_GRPFOLDER, m_pGroup->strOutFolder);
00103 SetDlgItemText (IDC_GRPEXTS, m_pGroup->strExts);
00104
00105 if (m_pGroup->nId == GRP_OTHER_ID)
00106 {
00107
00108 ((CEdit*) GetDlgItem (IDC_GRPNAME))->SetReadOnly ();
00109 GetDlgItem (IDC_GRPFOLDER)->SetFocus ();
00110 SetDlgItemText (IDC_GRPNAME, LS (L_OTHER));
00111 }
00112 else
00113 {
00114 SetDlgItemText (IDC_GRPNAME, m_pGroup->strName);
00115 GetDlgItem (IDC_GRPNAME)->SetFocus ();
00116 }
00117 }
00118
00119 SetWindowText (m_pGroup == NULL ? LS (L_CREATEGRP) : LS (L_GRPPROP));
00120
00121 ApplyLanguage ();
00122
00123 return FALSE;
00124 }
00125
00126 void CGroupDlg::OnOK()
00127 {
00128 CString strName, strFolder, strExts;
00129 GetDlgItemText (IDC_GRPNAME, strName);
00130 GetDlgItemText (IDC_GRPFOLDER, strFolder);
00131 GetDlgItemText (IDC_GRPEXTS, strExts);
00132 if (strName.GetLength () == 0)
00133 {
00134 MessageBox (LS (L_ENTERGRPNAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00135 GetDlgItem (IDC_GRPNAME)->SetFocus ();
00136 return;
00137 }
00138
00139 if (-1 != strName.FindOneOf ("/\\"))
00140 {
00141 MessageBox (LS (L_INVALIDGROUPNAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00142 GetDlgItem (IDC_GRPNAME)->SetFocus ();
00143 return;
00144 }
00145
00146 if (FALSE == CCreateDownloadDlg::_CheckFolderName (this, IDC_GRPFOLDER))
00147 return;
00148
00149 if (strFolder.GetLength () == 0)
00150 {
00151 MessageBox (LS (L_ENTERFLRNAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00152 GetDlgItem (IDC_GRPFOLDER)->SetFocus ();
00153 return;
00154 }
00155
00156 bool bNewGroup = m_pGroup == NULL;
00157
00158 if (bNewGroup)
00159 {
00160 m_pGroup.CreateInstance ();
00161 m_pParentGroup = m_wndGroups.GetSelectedGroup ();
00162 _DldsGrps.Add (m_pGroup, m_pParentGroup);
00163 }
00164
00165 m_pGroup->strName = strName;
00166 m_pGroup->strOutFolder = strFolder;
00167 m_pGroup->strExts = strExts;
00168
00169 if (m_pGroup->strOutFolder [m_pGroup->strOutFolder.GetLength () - 1] != '\\' &&
00170 m_pGroup->strOutFolder [m_pGroup->strOutFolder.GetLength () - 1] != '/')
00171 {
00172 m_pGroup->strOutFolder += '\\';
00173 }
00174
00175 fsPathToGoodPath (m_pGroup->strOutFolder);
00176
00177 _LastFolders.AddRecord (m_pGroup->strOutFolder);
00178
00179 if (bNewGroup)
00180 _pwndDownloads->OnNewGroupCreated (m_pGroup);
00181 else
00182 _pwndDownloads->OnGroupNameChanged (m_pGroup);
00183
00184 _DldsGrps.SaveToDisk ();
00185
00186 CDialog::OnOK();
00187 }
00188
00189 void CGroupDlg::OnChoosefolder()
00190 {
00191 CString str = "";
00192 GetDlgItemText (IDC_GRPFOLDER, str);
00193
00194 if (str.GetLength () > 3 && (str [str.GetLength () - 1] == '\\' || str [str.GetLength () - 1] == '/'))
00195 str.GetBuffer (0) [str.GetLength () - 1] = 0;
00196
00197 CFolderBrowser *fb = CFolderBrowser::Create (LS (L_CHOOSEGRPFLDR), str, NULL, this);
00198 if (fb == NULL)
00199 return;
00200
00201 SetDlgItemText (IDC_GRPFOLDER, fb->GetPath ());
00202 m_bPathChanged = TRUE;
00203 }
00204
00205 void CGroupDlg::OnChangeGrpname()
00206 {
00207 if (m_bPathChanged)
00208 return;
00209
00210 CString strName;
00211 GetDlgItemText (IDC_GRPNAME, strName);
00212
00213 SetDlgItemText (IDC_GRPFOLDER, m_strBaseFolder + strName);
00214 }
00215
00216 void CGroupDlg::OnContextMenu(CWnd* , CPoint point)
00217 {
00218 PrepareCHMgr (point);
00219 _CHMgr.ShowMenu ();
00220 }
00221
00222 void CGroupDlg::OnWhatisthis()
00223 {
00224 _CHMgr.OnWT ();
00225 }
00226
00227 void CGroupDlg::ApplyLanguage()
00228 {
00229 fsDlgLngInfo lnginfo [] = {
00230 fsDlgLngInfo (IDC__GROUP, L_GRPNAME),
00231 fsDlgLngInfo (IDC__PARENTGROUP, L_PARENT_GROUP, TRUE),
00232 fsDlgLngInfo (IDC__FOLDER, L_GRPFOLDER),
00233 fsDlgLngInfo (IDC__EXTS, L_GRPEXTS),
00234 fsDlgLngInfo (IDC__DEFPRIOR, L_GRPDEFPRIOR),
00235 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00236 fsDlgLngInfo (IDC_MACROSES, L_MACROSES),
00237 };
00238
00239 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), 0);
00240 }
00241
00242 BOOL CGroupDlg::OnHelpInfo(HELPINFO* pHelpInfo)
00243 {
00244 RECT rc;
00245 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00246 if (pItem == NULL)
00247 return TRUE;
00248 pItem->GetWindowRect (&rc);
00249 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00250 {
00251 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00252 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00253 }
00254 PrepareCHMgr (pHelpInfo->MousePos);
00255 _CHMgr.OnWT ();
00256 return TRUE;
00257 }
00258
00259 void CGroupDlg::PrepareCHMgr(CPoint point)
00260 {
00261 fsCtrlContextHelp aCH1 [] = {
00262 fsCtrlContextHelp (IDC__GROUP, LS (L_ENTERGRPNAMEHERE)),
00263 fsCtrlContextHelp (IDC_GRPNAME, LS (L_ENTERGRPNAMEHERE)),
00264 fsCtrlContextHelp (IDC__FOLDER, LS (L_FOLDERINWHICH)),
00265 fsCtrlContextHelp (IDC_GRPFOLDER, LS (L_FOLDERINWHICH)),
00266 fsCtrlContextHelp (IDC_CHOOSEFOLDER, LS (L_BROWSEFOR)),
00267 fsCtrlContextHelp (IDC__EXTS, LS (L_GRPFILESEXTS)),
00268 fsCtrlContextHelp (IDC_GRPEXTS, LS (L_GRPFILESEXTS)),
00269 fsCtrlContextHelp (IDOK, LS (L_ACCEPTCHANGES)),
00270 fsCtrlContextHelp (IDCANCEL, LS (L_DONTACCEPTCHANGES)),
00271 };
00272
00273 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00274 CopyMemory (aCH, aCH1, sizeof (aCH));
00275
00276 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00277 }
00278
00279 void CGroupDlg::OnMacroses()
00280 {
00281 CMenu menu;
00282 menu.CreatePopupMenu ();
00283
00284 CString str;
00285 str.Format ("%%server%% - %s", LS (L_SERVER_MACROS_DESC));
00286 menu.InsertMenu (0, MF_BYPOSITION | MF_STRING, ID_FOLDER_MACROS_0, str);
00287
00288 str.Format ("%%path_on_server%% - %s", LS (L_PATHONSERVER_MACROS_DESC));
00289 menu.InsertMenu (1, MF_BYPOSITION | MF_STRING, ID_FOLDER_MACROS_0 + 1, str);
00290
00291 str.Format ("%%year%% - %s", LS (L_YEAR_MACROS_DESC));
00292 menu.InsertMenu (2, MF_BYPOSITION | MF_STRING, ID_FOLDER_MACROS_0 + 2, str);
00293
00294 str.Format ("%%month%% - %s", LS (L_MONTH_MACROS_DESC));
00295 menu.InsertMenu (3, MF_BYPOSITION | MF_STRING, ID_FOLDER_MACROS_0 + 3, str);
00296
00297 str.Format ("%%day%% - %s", LS (L_DAY_MACROS_DESC));
00298 menu.InsertMenu (4, MF_BYPOSITION | MF_STRING, ID_FOLDER_MACROS_0 + 4, str);
00299
00300 str.Format ("%%date%% - %s", LS (L_DATE_MACROS_DESC));
00301 menu.InsertMenu (5, MF_BYPOSITION | MF_STRING, ID_FOLDER_MACROS_0 + 5, str);
00302
00303 str.Format ("%%sdrive%% - %s", LS (L_STARTDRIVELETTER));
00304 menu.InsertMenu (6, MF_BYPOSITION | MF_STRING, ID_FOLDER_MACROS_0 + 6, str);
00305
00306 CPoint pt;
00307 GetCursorPos (&pt);
00308 menu.TrackPopupMenu (TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_RIGHTALIGN, pt.x, pt.y, this);
00309 }
00310
00311 void CGroupDlg::OnInsertMacros(UINT nIDMacrosCmd)
00312 {
00313 LPCSTR ppsz [] = {
00314 "%server%", "%path_on_server%", "%year%", "%month%",
00315 "%day%", "%date%", "%sdrive%",
00316 };
00317
00318 LPCSTR pszMacros = ppsz [nIDMacrosCmd - ID_FOLDER_MACROS_0];
00319
00320 CString str;
00321 GetDlgItemText (IDC_GRPFOLDER, str);
00322
00323 if (str.IsEmpty () == FALSE && str [str.GetLength () - 1] != '\\')
00324 str += '\\';
00325
00326 str += pszMacros;
00327
00328 str += '\\';
00329
00330 SetDlgItemText (IDC_GRPFOLDER, str);
00331 }
00332
00333 void CGroupDlg::OnSelchangeGroups()
00334 {
00335 vmsDownloadsGroupSmartPtr pGroup = m_wndGroups.GetSelectedGroup ();
00336 if (pGroup == NULL)
00337 pGroup = _DldsGrps.FindGroup (GRP_OTHER_ID);
00338 m_strBaseFolder = pGroup->strOutFolder;
00339 CString str;
00340 GetDlgItemText (IDC_GRPNAME, str);
00341 SetDlgItemText (IDC_GRPFOLDER, m_strBaseFolder + str);
00342 m_bPathChanged = FALSE;
00343 }
00344
00345 void CGroupDlg::OnSelchangeGrpfolder()
00346 {
00347 m_bPathChanged = TRUE;
00348 }
00349
00350 void CGroupDlg::OnEditchangeGrpfolder()
00351 {
00352 m_bPathChanged = TRUE;
00353 }