00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Downloads_Bittorrent_Files.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 CDownloads_Bittorrent_Files::CDownloads_Bittorrent_Files()
00017 {
00018 }
00019
00020 CDownloads_Bittorrent_Files::~CDownloads_Bittorrent_Files()
00021 {
00022 }
00023
00024 BEGIN_MESSAGE_MAP(CDownloads_Bittorrent_Files, CListCtrl)
00025
00026 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetdispinfo)
00027
00028 END_MESSAGE_MAP()
00029
00030 BOOL CDownloads_Bittorrent_Files::Create(CWnd *pwndParent)
00031 {
00032 CRect rc (0, 0, 50, 50);
00033
00034 if (FALSE == CListCtrl::Create (WS_CHILD | LVS_REPORT | LVS_SINGLESEL |
00035 LVS_NOSORTHEADER | LVS_OWNERDATA,
00036 rc, pwndParent, 0x3ea1))
00037 return FALSE;
00038
00039 SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
00040
00041 InsertColumn (0, "Name");
00042 InsertColumn (1, "Size");
00043 InsertColumn (2, "Progress", LVCFMT_LEFT, GetStringWidth ("100%") + 20);
00044
00045 return TRUE;
00046 }
00047
00048 void CDownloads_Bittorrent_Files::ApplyLanguage()
00049 {
00050 HDITEM item;
00051 item.mask = HDI_TEXT;
00052
00053 item.pszText = (LPSTR) LS (L_NAME);
00054 GetHeaderCtrl ()->SetItem (0, &item);
00055
00056 item.pszText = (LPSTR) LS (L_SIZE);
00057 GetHeaderCtrl ()->SetItem (1, &item);
00058
00059 item.pszText = (LPSTR) LS (L_PROGRESS);
00060 GetHeaderCtrl ()->SetItem (2, &item);
00061 }
00062
00063 void CDownloads_Bittorrent_Files::set_ActiveDownload(vmsDownloadSmartPtr dld)
00064 {
00065 m_nFileNameOffset = 0;
00066 SetItemCount (0);
00067 m_dld = dld;
00068 if (dld == NULL)
00069 return;
00070
00071 vmsBtDownloadManager *mgr = dld->pMgr->GetBtDownloadMgr ();
00072
00073 m_nFileNameOffset = mgr->get_RootFolderName ().Length ();
00074 if (m_nFileNameOffset)
00075 m_nFileNameOffset++;
00076
00077 int w = 0;
00078 for (int i = 0; i < mgr->get_FileCount (); i++)
00079 w = max (w, GetStringWidth (mgr->get_FileName (i) + m_nFileNameOffset));
00080 SetColumnWidth (0, w+30);
00081
00082 w = 0;
00083 for (i = 0; i < mgr->get_FileCount (); i++)
00084 w = max (w, GetStringWidth (BytesToString (mgr->get_FileSize (i))));
00085 SetColumnWidth (1, w+30);
00086
00087 SetItemCount (m_dld->pMgr->GetBtDownloadMgr ()->get_FileCount ());
00088 }
00089
00090 void CDownloads_Bittorrent_Files::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
00091 {
00092 LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
00093 LV_ITEM* pItem = &(pDispInfo)->item;
00094
00095 try{
00096
00097 if (pItem->mask & LVIF_TEXT)
00098 {
00099 switch (pItem->iSubItem)
00100 {
00101 case 0:
00102 lstrcpyn (pItem->pszText,
00103 m_dld->pMgr->GetBtDownloadMgr ()->get_FileName (pItem->iItem) + m_nFileNameOffset,
00104 pItem->cchTextMax);
00105 break;
00106
00107 case 1:
00108 lstrcpy (pItem->pszText, BytesToString (m_dld->pMgr->GetBtDownloadMgr ()->get_FileSize (pItem->iItem)));
00109 break;
00110
00111 case 2:
00112 CString str;
00113 str.Format ("%d%%", m_dld->pMgr->GetBtDownloadMgr ()->get_FilePercentDone (pItem->iItem));
00114 lstrcpy (pItem->pszText, str);
00115 break;
00116 }
00117 }
00118
00119 }catch (...) {}
00120
00121 *pResult = 0;
00122 }
00123
00124 void CDownloads_Bittorrent_Files::UpdateProgress()
00125 {
00126 if (IsWindowVisible () == FALSE)
00127 return;
00128
00129 CRect rc;
00130 GetHeaderCtrl ()->GetItemRect (2, &rc);
00131
00132 CRect rc2; GetClientRect (&rc2);
00133
00134 rc.top = 0;
00135 rc.bottom = rc2.bottom;
00136 rc.left += 3; rc.right -= 3;
00137
00138 InvalidateRect (&rc, FALSE);
00139 }