00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "SpiderWnd.h"
00009 #include "SpiderAddPageDlg.h"
00010 #include "WPDS_Sheet.h"
00011 #include "MainFrm.h"
00012 #include "plugincmds.h"
00013
00014 #ifdef _DEBUG
00015 #define new DEBUG_NEW
00016 #undef THIS_FILE
00017 static char THIS_FILE[] = __FILE__;
00018 #endif
00019
00020 CSpiderWnd *_pwndSpider = NULL;
00021
00022 CSpiderWnd::CSpiderWnd()
00023 {
00024 m_mgr.SetEventsFunc (_DownloaderEvents, this);
00025 }
00026
00027 CSpiderWnd::~CSpiderWnd()
00028 {
00029 }
00030
00031 BEGIN_MESSAGE_MAP(CSpiderWnd, CWnd)
00032
00033 ON_WM_CREATE()
00034 ON_WM_SIZE()
00035 ON_WM_TIMER()
00036 ON_COMMAND(ID_SPIDER_DELETE, OnSpiderDelete)
00037 ON_COMMAND(ID_SPIDER_OPENFOLDER, OnSpiderOpenfolder)
00038 ON_COMMAND(ID_SPIDER_OPENPAGE, OnSpiderOpenpage)
00039 ON_COMMAND(ID_SPIDER_SCHEDULE, OnSpiderSchedule)
00040 ON_COMMAND(ID_SPIDER_SETTINGS, OnSpiderSettings)
00041 ON_COMMAND(ID_SPIDER_STARTAUTOMATICALLY, OnSpiderStartautomatically)
00042 ON_COMMAND(ID_SPIDER_STARTDL, OnSpiderStartdl)
00043 ON_COMMAND(ID_SPIDER_STOPDL, OnSpiderStopdl)
00044 ON_COMMAND(ID_SPIDER_DL, OnSpiderDl)
00045 ON_WM_SETFOCUS()
00046
00047
00048 ON_MESSAGE (WM_WGP_SHUTDOWN, OnAppExit)
00049 ON_MESSAGE (WM_WGP_READYTOSHUTDOWN, OnAppQueryExit)
00050 ON_MESSAGE (WM_WGP_UPDATE_MENUMAIN, OnUpdateMenu)
00051 ON_MESSAGE (WM_WGP_UPDATE_MENUVIEW, OnUpdateMenuView)
00052 ON_MESSAGE (WM_WGP_UPDATE_CMDITEM, OnUpdateToolBar)
00053 ON_MESSAGE (WM_WGP_INSERT, OnInsert)
00054
00055 ON_COMMAND(WGP_MENU_VIEWSMPLITEM_CMDSTART+0, OnShowTree)
00056
00057 ON_COMMAND_RANGE(ID_LOW_1, ID_LOW_3, OnPagesListShowCol)
00058
00059 END_MESSAGE_MAP()
00060
00061 HWND CSpiderWnd::Plugin_CreateMainWindow(HWND hParent)
00062 {
00063 fsnew1 (_pwndSpider, CSpiderWnd);
00064
00065 _pwndSpider->Create (CWnd::FromHandle (hParent));
00066
00067 return _pwndSpider->m_hWnd;
00068 }
00069
00070 BOOL CSpiderWnd::Create(CWnd *pParent)
00071 {
00072 CRect rc (0, 0, 50, 50);
00073
00074 if (FALSE == CWnd::Create (AfxRegisterWndClass (0, NULL,
00075 NULL, NULL), NULL, WS_CHILD | WS_VISIBLE, rc, pParent, 0x9a16))
00076 return FALSE;
00077
00078 return TRUE;
00079 }
00080
00081 void CSpiderWnd::Plugin_GetToolBarInfo(wgTButtonInfo **ppButtons, int *pcButtons)
00082 {
00083 static wgTButtonInfo btns [] =
00084 {
00085 wgTButtonInfo (ID_SPIDER_DL, TBSTYLE_BUTTON, ""),
00086 wgTButtonInfo (ID_SPIDER_STARTDL, TBSTYLE_BUTTON, ""),
00087 wgTButtonInfo (ID_SPIDER_STOPDL, TBSTYLE_BUTTON, ""),
00088 wgTButtonInfo (ID_SPIDER_SCHEDULE, TBSTYLE_BUTTON, ""),
00089 };
00090
00091 btns [0].pszToolTip = LS (L_DLWEBPAGE);
00092 btns [1].pszToolTip = LS (L_STARTDL);
00093 btns [2].pszToolTip = LS (L_STOPDL);
00094 btns [3].pszToolTip = LS (L_SCHEDULEDL);
00095
00096 *ppButtons = btns;
00097 *pcButtons = sizeof (btns) / sizeof (wgTButtonInfo);
00098 }
00099
00100 void CSpiderWnd::Plugin_GetMenuImages(fsSetImage **ppImages, int *pcImages)
00101 {
00102 static fsSetImage images [] =
00103 {
00104 fsSetImage (ID_SPIDER_DL, 0),
00105 fsSetImage (ID_SPIDER_STARTDL, 1),
00106 fsSetImage (ID_SPIDER_STOPDL, 2),
00107 fsSetImage (ID_SPIDER_SCHEDULE, 3),
00108 fsSetImage (ID_SPIDER_SETTINGS, 4),
00109 fsSetImage (ID_SPIDER_DELETE, 5),
00110 };
00111
00112 *ppImages = images;
00113 *pcImages = sizeof (images) / sizeof (fsSetImage);
00114 }
00115
00116 void CSpiderWnd::Plugin_GetMenuViewItems(wgMenuViewItem **ppItems, int *cItems)
00117 {
00118 static wgMenuViewItem aItems [] = {
00119 wgMenuViewItem ("", &_pwndSpider->m_bShowTree),
00120 };
00121
00122 aItems [0].pszName = LS (L_WEBPAGETREE);
00123
00124 *ppItems = aItems;
00125 *cItems = sizeof (aItems) / sizeof (wgMenuViewItem);
00126 }
00127
00128 void CSpiderWnd::Plugin_GetPluginNames(LPCSTR *ppszLong, LPCSTR *ppszShort)
00129 {
00130 *ppszLong = *ppszShort = LS (L_HTMLSPIDER);
00131 }
00132
00133 int CSpiderWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00134 {
00135 if (CWnd::OnCreate(lpCreateStruct) == -1)
00136 return -1;
00137
00138 if (FALSE == m_wndTasks.Create (this))
00139 return -1;
00140
00141 if (FALSE == m_wndTaskTree.Create (this))
00142 return -1;
00143
00144 if (FALSE == m_wndSplitter.Create (AfxGetInstanceHandle (), m_hWnd, WST_HORIZONTAL))
00145 return -1;
00146
00147 m_wndSplitter.SetWnd1 (m_wndTasks);
00148 m_wndSplitter.SetWnd2 (m_wndTaskTree);
00149 m_wndSplitter.SetRatio (_App.View_SplitterRatio ("Spider_T_TT"));
00150
00151 m_bShowTree = _App.View_SpiderTree ();
00152 ShowTree (m_bShowTree);
00153
00154 LoadPages ();
00155
00156 SetTimer (1, 1000, NULL);
00157
00158 return 0;
00159 }
00160
00161 void CSpiderWnd::OnSize(UINT , int cx, int cy)
00162 {
00163 if (m_bShowTree)
00164 m_wndSplitter.ApplyRatio ();
00165 else
00166 m_wndTasks.MoveWindow (0, 0, cx, cy);
00167 }
00168
00169 void CSpiderWnd::ShowTree(BOOL bShow)
00170 {
00171 UINT nShow = bShow ? SW_SHOW : SW_HIDE;
00172 m_wndTaskTree.ShowWindow (nShow);
00173 ::ShowWindow (m_wndSplitter.m_wndSplitter, nShow);
00174
00175 m_bShowTree = bShow;
00176 _App.View_SpiderTree (bShow);
00177
00178 RECT rc;
00179 GetClientRect (&rc);
00180 OnSize (0, rc.right, rc.bottom);
00181 }
00182
00183 LRESULT CSpiderWnd::OnAppExit(WPARAM, LPARAM)
00184 {
00185 SaveAll (TRUE);
00186 return 0;
00187 }
00188
00189 LRESULT CSpiderWnd::OnAppQueryExit(WPARAM, LPARAM)
00190 {
00191 return 0;
00192 }
00193
00194 LRESULT CSpiderWnd::OnUpdateMenu(WPARAM, LPARAM lp)
00195 {
00196 m_wndTasks.UpdateMenu (CMenu::FromHandle (*((HMENU*)lp)));
00197 return 0;
00198 }
00199
00200 LRESULT CSpiderWnd::OnUpdateToolBar(WPARAM wp, LPARAM)
00201 {
00202 return m_wndTasks.UpdateToolBar (wp);
00203 }
00204
00205 void CSpiderWnd::OnShowTree()
00206 {
00207 ShowTree (m_bShowTree == FALSE);
00208 }
00209
00210 void CSpiderWnd::SaveAll(BOOL bMsgIfErr)
00211 {
00212 _App.View_SplitterRatio ("Spider_T_TT", m_wndSplitter.GetRatio ());
00213 m_wndTasks.SaveState ("SpiderTasks");
00214 SavePages (bMsgIfErr);
00215 }
00216
00217 void CSpiderWnd::OnSpiderDl()
00218 {
00219 m_wndTasks.OnSpiderDl ();
00220 }
00221
00222 fsWebPageDownloader* CSpiderWnd::AddWebPage(LPCSTR pszStartUrl, BOOL bReqTopMost)
00223 {
00224 fsWebPageDownloader *wpd;
00225 fsnew1 (wpd, fsWebPageDownloader);
00226
00227 CSpiderAddPageDlg dlg;
00228 dlg.m_wpd = wpd;
00229 if (pszStartUrl)
00230 dlg.m_strStartUrl = pszStartUrl;
00231 else
00232 dlg.m_strStartUrl = "";
00233
00234 dlg.m_bReqTopMost = bReqTopMost;
00235
00236 if (_DlgMgr.DoModal (&dlg) == IDCANCEL)
00237 {
00238 delete wpd;
00239 return NULL;
00240 }
00241
00242 m_mgr.Add (wpd);
00243
00244 if (wpd->Create (dlg.m_strUrl, dlg.m_bAutoStart, dlg.m_bScheduled ? &dlg.m_task : NULL) == FALSE)
00245 m_mgr.Delete (wpd);
00246 else
00247 m_wndTasks.AddWebPage (wpd);
00248
00249 return wpd;
00250 }
00251
00252 void CSpiderWnd::_DownloaderEvents(fsWebPageDownloader *dldr, fsWPDEvent ev, int info, LPVOID lp)
00253 {
00254 CSpiderWnd* pThis = (CSpiderWnd*) lp;
00255
00256 switch (ev)
00257 {
00258 case WPDE_DLDEVENTRECEIVED:
00259 pThis->m_wndTaskTree.UpdateDownload ((fsDownload*) info);
00260 break;
00261
00262 case WPDE_FILEADDED:
00263 pThis->m_wndTaskTree.OnFileAdded (t_wptree (info));
00264 break;
00265
00266 case WPDE_DLDWILLBEDELETED:
00267 pThis->m_wndTaskTree.OnDldWillBeDeleted ((fsDownload*) info);
00268 break;
00269
00270 case WPDE_DLDRESTORED:
00271 pThis->m_wndTaskTree.UpdateDownload ((fsDownload*) info);
00272 break;
00273
00274 case WPDE_WEBPAGEWILLBEDELETED:
00275 pThis->m_wndTaskTree.OnWebPageWillBeDeleted ((fsDLWebPage*) info);
00276 pThis->m_wndTasks.UpdateWebPage (dldr);
00277 break;
00278
00279 case WPDE_DONE:
00280 CString strtmp;
00281 char szUrl [10000];
00282 dldr->GetDownloadingSiteName (szUrl);
00283 strtmp.Format ("%s - %s", szUrl, LS (L_DONE));
00284 CMainFrame::ShowTimeoutBalloon (strtmp, PRG_NAME);
00285 break;
00286 }
00287
00288 pThis->m_wndTasks.UpdateWebPage (dldr);
00289 }
00290
00291 void CSpiderWnd::OnTimer(UINT nIDEvent)
00292 {
00293
00294
00295 for (int i = 0; i < m_mgr.GetWPDCount (); i++)
00296 {
00297 try{
00298 fsWebPageDownloader *wpd = m_mgr.GetWPD (i);
00299 if (wpd->IsDownloading ())
00300 m_wndTasks.UpdateWebPage (wpd);
00301 }catch (...){}
00302 }
00303
00304 CWnd::OnTimer(nIDEvent);
00305 }
00306
00307 fsWebPageDownloadsMgr* CSpiderWnd::GetMgr()
00308 {
00309 return &m_mgr;
00310 }
00311
00312 void CSpiderWnd::LoadPages()
00313 {
00314 do
00315 {
00316 if (FALSE == m_mgr.Load ())
00317 {
00318
00319 break;
00320 }
00321 else
00322 break;
00323 }
00324 while (TRUE);
00325
00326 for (int i = 0; i < m_mgr.GetWPDCount (); i++)
00327 m_wndTasks.AddWebPage (m_mgr.GetWPD (i));
00328 }
00329
00330 void CSpiderWnd::SavePages(BOOL bMsgIfErr)
00331 {
00332 do
00333 {
00334 if (FALSE == m_mgr.Save () && bMsgIfErr)
00335 {
00336
00337 break;
00338 }
00339 else
00340 break;
00341 }
00342 while (TRUE);
00343 }
00344
00345 void CSpiderWnd::SetupDefSettings()
00346 {
00347 fsWPDSettings wpds;
00348 fsWebPageDownloader::ReadDefaultWPDS (&wpds);
00349 CWPDS_Sheet sheet (LS (L_SPIDERDEFSETTINGS), this);
00350 sheet.Init (&wpds, FALSE, NULL, true);
00351
00352 _DlgMgr.OnDoModal (&sheet);
00353 sheet.DoModal ();
00354 _DlgMgr.OnEndDialog (&sheet);
00355
00356 _App.Spider_Depth (wpds.iDepth);
00357 _App.Spider_DownloadFiles (wpds.bDownloadFiles);
00358 _App.Spider_DownloadImages (wpds.bDownloadImages);
00359 _App.Spider_DownloadStyles (wpds.bDownloadStyles);
00360 _App.Spider_Exts (wpds.strExts);
00361 _App.Spider_ExtsType (wpds.enExtsType);
00362 _App.Spider_HTMLExts (wpds.strHTMLExts);
00363 _App.Spider_NotAllFiles (wpds.bNotAllFiles);
00364 _App.Spider_NotAllImages (wpds.bNotAllImages);
00365 _App.Spider_NotAllPages (wpds.bNotAllPages);
00366 _App.Spider_ImgExts (wpds.strImgsExts);
00367 _App.Spider_ImgExtsType (wpds.enImgsExtsType);
00368 _App.Spider_SavePagesUnderHTM (wpds.bSavePagesUnderHTM);
00369 }
00370
00371 void CSpiderWnd::ApplyLanguage()
00372 {
00373 m_wndTasks.ApplyLanguage ();
00374 }
00375
00376 void CSpiderWnd::OnSpiderDelete()
00377 {
00378 m_wndTasks.OnSpiderDelete ();
00379 }
00380
00381 void CSpiderWnd::OnSpiderOpenfolder()
00382 {
00383 m_wndTasks.OnSpiderOpenfolder ();
00384 }
00385
00386 void CSpiderWnd::OnSpiderOpenpage()
00387 {
00388 m_wndTasks.OnSpiderOpenpage ();
00389 }
00390
00391 void CSpiderWnd::OnSpiderSchedule()
00392 {
00393 m_wndTasks.OnSpiderSchedule ();
00394 }
00395
00396 void CSpiderWnd::OnSpiderSettings()
00397 {
00398 m_wndTasks.OnSpiderSettings ();
00399 }
00400
00401 void CSpiderWnd::OnSpiderStartautomatically()
00402 {
00403 m_wndTasks.OnSpiderStartautomatically ();
00404 }
00405
00406 void CSpiderWnd::OnSpiderStartdl()
00407 {
00408 m_wndTasks.OnSpiderStartdl ();
00409 }
00410
00411 void CSpiderWnd::OnSpiderStopdl()
00412 {
00413 m_wndTasks.OnSpiderStopdl ();
00414 }
00415
00416 void CSpiderWnd::OnSetFocus(CWnd* pOldWnd)
00417 {
00418 CWnd::OnSetFocus(pOldWnd);
00419 m_wndTasks.SetFocus ();
00420 }
00421
00422 void CSpiderWnd::UpdateTasksIcons()
00423 {
00424 m_wndTasks.UpdateIcons ();
00425 m_wndTaskTree.UpdateAll ();
00426 }
00427
00428 void CSpiderWnd::Plugin_SetLanguage(wgLanguage, HMENU hMenuMain, HMENU hMenuView)
00429 {
00430 CMenu *menu = CMenu::FromHandle (hMenuMain);
00431 _pwndSpider->m_wndTasks.ApplyLanguageToMenu (menu);
00432 _pwndSpider->ApplyLanguage ();
00433 _pwndSpider->ApplyLanguageToMenuView (CMenu::FromHandle (hMenuView));
00434 }
00435
00436 void CSpiderWnd::ApplyLanguageToMenuView(CMenu *menu)
00437 {
00438 menu->ModifyMenu (0, MF_BYPOSITION | MF_STRING, 0, LS (L_LISTOFPAGES));
00439
00440 UINT aCmds [] = {ID_LOW_1, ID_LOW_2, ID_LOW_3};
00441 LPCSTR apszCmds [] = {LS (L_WEBPAGEURL), LS (L_PROGRESS), LS (L_FILES)};
00442
00443 for (int i = 0; i < sizeof (aCmds) / sizeof (UINT); i++)
00444 menu->ModifyMenu (aCmds [i], MF_BYCOMMAND|MF_STRING, aCmds [i], apszCmds [i]);
00445 }
00446
00447 LRESULT CSpiderWnd::OnUpdateMenuView(WPARAM, LPARAM lp)
00448 {
00449 HMENU* pMenus = (HMENU*) lp;
00450 UpdatePagesListColMenu (CMenu::FromHandle (pMenus [0]));
00451 return 0;
00452 }
00453
00454 void CSpiderWnd::UpdatePagesListColMenu(CMenu *menu)
00455 {
00456 BOOL bEn = m_wndTasks.GetHeaderCtrl ()->GetItemCount () > 1;
00457 for (int i = 0; i < 3; i++)
00458 {
00459 if (m_wndTasks.IsColumnShown (i))
00460 {
00461 menu->CheckMenuItem (ID_LOW_1+i, MF_CHECKED);
00462 if (bEn == FALSE)
00463 menu->EnableMenuItem (ID_LOW_1+i, MF_GRAYED);
00464 }
00465 }
00466 }
00467
00468 void CSpiderWnd::OnPagesListShowCol(UINT uCmd)
00469 {
00470 int iCol = uCmd - ID_LOW_1;
00471 m_wndTasks.ChangeColumnVisibility (iCol);
00472 }
00473
00474 LRESULT CSpiderWnd::OnInsert(WPARAM, LPARAM)
00475 {
00476 m_wndTasks.OnSpiderDl ();
00477 return 0;
00478 }
00479
00480 HMENU CSpiderWnd::Plugin_GetMainMenu()
00481 {
00482 return LoadMenu (AfxGetInstanceHandle (), MAKEINTRESOURCE (IDM_SPIDER));
00483 }
00484
00485 HMENU CSpiderWnd::Plugin_GetViewMenu()
00486 {
00487 return LoadMenu (AfxGetInstanceHandle (), MAKEINTRESOURCE (IDM_SPIDER_VIEW));
00488 }