00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "SpiderTaskTree.h"
00009 #include "Downloads_Tasks.h"
00010 #include "DownloadsWnd.h"
00011
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #undef THIS_FILE
00015 static char THIS_FILE[] = __FILE__;
00016 #endif
00017
00018 extern CDownloadsWnd *_pwndDownloads;
00019
00020 CSpiderTaskTree::CSpiderTaskTree()
00021 {
00022 m_wpd = NULL;
00023 }
00024
00025 CSpiderTaskTree::~CSpiderTaskTree()
00026 {
00027 }
00028
00029 BEGIN_MESSAGE_MAP(CSpiderTaskTree, CTreeCtrl)
00030
00031 ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
00032 ON_WM_RBUTTONDOWN()
00033 ON_COMMAND(ID_DONTDOWNLOADANDDEL, OnDontdownloadanddel)
00034 ON_NOTIFY_REFLECT(TVN_KEYDOWN, OnKeydown)
00035
00036 END_MESSAGE_MAP()
00037
00038 BOOL CSpiderTaskTree::Create(CWnd *pParent)
00039 {
00040 CRect rc (0, 0, 150, 50);
00041
00042 if (FALSE == CTreeCtrl::Create (TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_SHOWSELALWAYS, rc, pParent, 0x996))
00043 return FALSE;
00044
00045 CBitmap bmpg;
00046 bmpg.Attach (SBMP (IDB_DOWNLOADSTASKS));
00047 m_images.Create (16, 17, ILC_COLOR24 | ILC_MASK, 6, 2);
00048 m_images.Add (&bmpg, RGB (255, 0, 255));
00049 SetImageList (&m_images, TVSIL_NORMAL);
00050
00051 ShowWindow (SW_SHOW);
00052
00053 return TRUE;
00054 }
00055
00056 void CSpiderTaskTree::UpdateAll()
00057 {
00058 DeleteAllItems ();
00059 m_vConfs.clear ();
00060
00061 if (m_wpd == NULL)
00062 return;
00063
00064 t_wptree tree = m_wpd->GetRootPage ();
00065
00066 AddTree (tree, TVI_ROOT);
00067 }
00068
00069 void CSpiderTaskTree::AddTree(t_wptree tree, HTREEITEM hParent)
00070 {
00071 fsDLWebPage &wp = tree->GetData ();
00072 int iImage = GetDownloadImage (&wp);
00073 HTREEITEM hItem = InsertItem (wp.strURL, iImage, iImage, hParent, TVI_SORT);
00074
00075 _Conformity conf;
00076 conf.hItem = hItem;
00077 conf.wptree = tree;
00078 m_vConfs.add (conf);
00079
00080 SetItemData (hItem, (DWORD)tree);
00081
00082
00083 for (int i = 0; i < tree->GetLeafCount (); i++)
00084 AddTree (tree->GetLeaf (i), hItem);
00085
00086 Expand (hItem, TVE_EXPAND);
00087 }
00088
00089 int CSpiderTaskTree::GetDownloadImage(fsDLWebPage *wp)
00090 {
00091 if (wp->dld)
00092 return CDownloads_Tasks::GetDownloadImage (wp->dld);
00093 else if (wp->bState & WPSTATE_DLDWASDELETED)
00094 return 6;
00095 else
00096 return 1;
00097 }
00098
00099 void CSpiderTaskTree::UpdateDownload(vmsDownloadSmartPtr dld)
00100 {
00101 int iIndex = FindDownload (dld);
00102 if (iIndex == -1)
00103 return;
00104
00105 int iImage = GetDownloadImage (&m_vConfs [iIndex].wptree->GetData ());
00106 SetItemImage (m_vConfs [iIndex].hItem, iImage, iImage);
00107 }
00108
00109 int CSpiderTaskTree::FindDownload(vmsDownloadSmartPtr dld)
00110 {
00111 for (int i = 0; i < m_vConfs.size (); i++)
00112 {
00113 if (m_vConfs [i].wptree->GetData ().dld == dld)
00114 return i;
00115 }
00116
00117 return -1;
00118 }
00119
00120 void CSpiderTaskTree::OnFileAdded(t_wptree root)
00121 {
00122 int iIndex = FindTree (root);
00123 if (iIndex == -1)
00124 return;
00125
00126 AddTree (root->GetLeaf (root->GetLeafCount () - 1), m_vConfs [iIndex].hItem);
00127 Expand (m_vConfs [iIndex].hItem, TVE_EXPAND);
00128 }
00129
00130 int CSpiderTaskTree::FindTree(t_wptree tree)
00131 {
00132 for (int i = 0; i < m_vConfs.size (); i++)
00133 {
00134 if (m_vConfs [i].wptree == tree)
00135 return i;
00136 }
00137
00138 return -1;
00139 }
00140
00141 void CSpiderTaskTree::OnDldWillBeDeleted(vmsDownloadSmartPtr dld)
00142 {
00143 int iIndex = FindDownload (dld);
00144 if (iIndex == -1)
00145 return;
00146
00147 int iImage = dld->pMgr->IsDone () ? 1 : 6;
00148 SetItemImage (m_vConfs [iIndex].hItem, iImage, iImage);
00149 }
00150
00151 void CSpiderTaskTree::OnRclick(NMHDR* , LRESULT* pResult)
00152 {
00153 HTREEITEM hItem;
00154
00155 *pResult = 0;
00156
00157 hItem = HitTest (CPoint (m_rbPt.x, m_rbPt.y));
00158
00159 if (hItem)
00160 SelectItem (hItem);
00161 else
00162 return;
00163
00164 ShowContextMenu ();
00165 }
00166
00167 void CSpiderTaskTree::OnRButtonDown(UINT nFlags, CPoint point)
00168 {
00169 m_rbPt = point;
00170 CTreeCtrl::OnRButtonDown(nFlags, point);
00171 }
00172
00173 int CSpiderTaskTree::FindTree(HTREEITEM hItem)
00174 {
00175 for (int i = 0; i < m_vConfs.size (); i++)
00176 {
00177 if (m_vConfs [i].hItem == hItem)
00178 return i;
00179 }
00180
00181 return -1;
00182 }
00183
00184 void CSpiderTaskTree::OnDontdownloadanddel()
00185 {
00186 HTREEITEM hItem = GetSelectedItem ();
00187 if (hItem == NULL)
00188 return;
00189
00190 if (_App.Deleted_ConfirmDeletion ())
00191 if (IDNO == MessageBox (LS (L_AREYOUSURE), LS (L_CONFIRMATION), MB_YESNO|MB_ICONQUESTION))
00192 {
00193 SetFocus ();
00194 return;
00195 }
00196
00197 hItem = GetSelectedItem ();
00198
00199 SetFocus ();
00200
00201 int iItem = FindTree (hItem);
00202 if (iItem == -1)
00203 return;
00204
00205 _pwndDownloads->DeleteDownload (m_vConfs [iItem].wptree->GetData ().dld, TRUE);
00206 }
00207
00208 void CSpiderTaskTree::OnWebPageWillBeDeleted(fsDLWebPage *wp)
00209 {
00210 if (m_wpd == NULL)
00211 return;
00212
00213 t_wptree wptree = m_wpd->FindWebPageTree (wp->dld);
00214
00215 if (wptree == NULL)
00216 return;
00217
00218 int iItem = FindTree (wptree);
00219 if (iItem == -1)
00220 return;
00221
00222 DeleteItem (m_vConfs [iItem].hItem);
00223 m_vConfs.del (iItem);
00224 }
00225
00226 void CSpiderTaskTree::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult)
00227 {
00228 TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
00229
00230
00231 switch (pTVKeyDown->wVKey)
00232 {
00233 case VK_DELETE:
00234 OnDontdownloadanddel ();
00235 break;
00236
00237 case VK_APPS:
00238 CalcCoordsForCurSel ();
00239 ShowContextMenu ();
00240 break;
00241 }
00242
00243 *pResult = 0;
00244 }
00245
00246 void CSpiderTaskTree::CalcCoordsForCurSel()
00247 {
00248 HTREEITEM hCur = GetSelectedItem ();
00249 if (hCur != NULL)
00250 {
00251 RECT rc;
00252 GetItemRect (hCur, &rc, TRUE);
00253 m_rbPt.x = rc.left;
00254 m_rbPt.y = rc.top;
00255 }
00256 else
00257 m_rbPt.x = m_rbPt.y = 30;
00258 }
00259
00260 void CSpiderTaskTree::ShowContextMenu()
00261 {
00262 HTREEITEM hItem = GetSelectedItem ();
00263 if (hItem == NULL)
00264 return;
00265
00266 int iItem = FindTree (hItem);
00267 if (iItem == -1)
00268 return;
00269
00270 CMenu menu;
00271 menu.LoadMenu (IDM_SPIDER_TREE);
00272 CMenu *pPopup = menu.GetSubMenu (0);
00273
00274 CString str = LS (L_DONTDOWNLOADANDDEL); str += "\tDel";
00275 menu.ModifyMenu (ID_DONTDOWNLOADANDDEL, MF_BYCOMMAND|MF_STRING, ID_DONTDOWNLOADANDDEL, str);
00276
00277 fsDLWebPage *wp = &m_vConfs [iItem].wptree->GetData ();
00278 if (wp->dld == NULL || wp->dld->pMgr->IsDone ())
00279 pPopup->EnableMenuItem (ID_DONTDOWNLOADANDDEL, MF_BYCOMMAND | MF_GRAYED);
00280
00281 ClientToScreen (&m_rbPt);
00282 pPopup->TrackPopupMenu (TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_LEFTALIGN, m_rbPt.x, m_rbPt.y, this);
00283 menu.DestroyMenu ();
00284 }