00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Downloads_Bittorrent_General.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_General::CDownloads_Bittorrent_General()
00017 {
00018 }
00019
00020 CDownloads_Bittorrent_General::~CDownloads_Bittorrent_General()
00021 {
00022 }
00023
00024 BEGIN_MESSAGE_MAP(CDownloads_Bittorrent_General, CListCtrl)
00025
00026 ON_WM_SHOWWINDOW()
00027 ON_COMMAND(ID_UPDATE, OnCmdUpdate)
00028
00029 END_MESSAGE_MAP()
00030
00031 BOOL CDownloads_Bittorrent_General::Create(CWnd *pParent)
00032 {
00033 CRect rc (0, 0, 50, 50);
00034
00035 if (FALSE == CListCtrl::Create (WS_CHILD | LVS_NOCOLUMNHEADER | LVS_REPORT | LVS_SINGLESEL,
00036 rc, pParent, 0xaa1))
00037 return FALSE;
00038
00039 SetExtendedStyle (LVS_EX_FULLROWSELECT);
00040
00041 InsertColumn (0, "");
00042 InsertColumn (1, "");
00043
00044 return TRUE;
00045 }
00046
00047 void CDownloads_Bittorrent_General::set_ActiveDownload(vmsDownloadSmartPtr dld)
00048 {
00049 m_dld = dld;
00050 if (dld == NULL)
00051 return;
00052 UpdateStat ();
00053 }
00054
00055 void CDownloads_Bittorrent_General::UpdateStat()
00056 {
00057 if (m_dld == NULL)
00058 return;
00059
00060 if (IsWindowVisible () == FALSE)
00061 return;
00062
00063 DeleteAllItems ();
00064
00065 vmsBtDownloadManager *mgr = m_dld->pMgr->GetBtDownloadMgr ();
00066
00067 CString str = LS (L_INFO_HASH); str += ':';
00068 InsertItem (0, str);
00069 str = mgr->get_InfoHash ();
00070 str.MakeUpper ();
00071 str.Insert (8, ' ');
00072 str.Insert (8+8+1, ' ');
00073 str.Insert (8+8+8+2, ' ');
00074 str.Insert (8+8+8+8+3, ' ');
00075 SetItemText (0, 1, str);
00076
00077 str = LS (L_PIECES); str += ':';
00078 InsertItem (1, str);
00079 str.Format ("%d x %s", mgr->get_PieceCount (),
00080 BytesToString (mgr->get_PieceSize ()));
00081 SetItemText (1, 1, str);
00082
00083 InsertItem (2, "");
00084
00085 str = LS (L_TRACKER); str += ':';
00086 InsertItem (3, str);
00087 SetItemText (3, 1, mgr->get_CurrentTracker ());
00088 str = LS (L_TRACKER_STATUS); str += ':';
00089 InsertItem (4, str);
00090 SetItemText (4, 1, mgr->m_strTrackerStatus);
00091
00092 InsertItem (5, "");
00093
00094 str = LS (L_UPLOAD_SPEED); str += ':';
00095 InsertItem (6, str);
00096 str = LS (L_BYTES_UPLOADED); str += ':';
00097 InsertItem (7, str);
00098 str = LS (L_SHARE_RATING); str += ':';
00099 InsertItem (8, str);
00100 UpdateUploadStat ();
00101
00102 InsertItem (9, "");
00103
00104 str = LS (L_PEERS); str += ':';
00105 InsertItem (10, str);
00106 UpdatePeersStat ();
00107
00108 InsertItem (11, "");
00109
00110 str = LS (L_WASTED_BYTE_COUNT); str += ':';
00111 InsertItem (12, str);
00112 UpdateWastedStat ();
00113
00114 SetColumnWidth (0, LVSCW_AUTOSIZE);
00115 SetColumnWidth (1, LVSCW_AUTOSIZE);
00116
00117 int w = GetColumnWidth (0);
00118 SetColumnWidth (0, w + 33);
00119 }
00120
00121 void CDownloads_Bittorrent_General::ApplyLanguage()
00122 {
00123 if (m_dld != NULL)
00124 UpdateStat ();
00125 }
00126
00127 void CDownloads_Bittorrent_General::UpdateUploadStat()
00128 {
00129 if (m_dld == NULL || GetItemCount () < 9)
00130 return;
00131
00132 if (IsWindowVisible () == FALSE)
00133 return;
00134
00135 vmsBtDownloadManager *mgr = m_dld->pMgr->GetBtDownloadMgr ();
00136
00137 CString str = BytesToString (mgr->GetUploadSpeed ());
00138 str += '/'; str += LS (L_S);
00139 SetItemText (6, 1, str);
00140
00141 SetItemText (7, 1, BytesToString (mgr->get_TotalUploadedByteCount ()));
00142
00143 str.Format ("%.*g", 4, (float)mgr->get_ShareRating ());
00144 SetItemText (8, 1, str);
00145 }
00146
00147 void CDownloads_Bittorrent_General::UpdatePeersStat()
00148 {
00149 if (m_dld == NULL || GetItemCount () < 11)
00150 return;
00151
00152 if (IsWindowVisible () == FALSE)
00153 return;
00154
00155 CString str;
00156 int nPeersConnected, nSeedsTotal, nLeechersTotal, nSeedsConnected;
00157 m_dld->pMgr->GetBtDownloadMgr ()->get_PeersStat (
00158 &nPeersConnected, &nSeedsTotal, &nLeechersTotal, &nSeedsConnected);
00159 if (nSeedsTotal != -1 && nLeechersTotal != -1)
00160 str.Format ("total: %d, seeds: %d, connected: %d (%d - seeds)",
00161 nSeedsTotal+nLeechersTotal, nSeedsTotal, nPeersConnected, nSeedsConnected);
00162 else
00163 str.Format ("connected: %d (%d - seeds)", nPeersConnected, nSeedsConnected);
00164 SetItemText (10, 1, str);
00165 }
00166
00167 void CDownloads_Bittorrent_General::UpdateWastedStat()
00168 {
00169 if (m_dld == NULL || GetItemCount () < 13)
00170 return;
00171
00172 if (IsWindowVisible () == FALSE)
00173 return;
00174
00175 SetItemText (12, 1,
00176 BytesToString (m_dld->pMgr->GetBtDownloadMgr ()->get_WastedByteCount ()));
00177 }
00178
00179 void CDownloads_Bittorrent_General::OnShowWindow(BOOL bShow, UINT nStatus)
00180 {
00181 CListCtrl::OnShowWindow(bShow, nStatus);
00182
00183 PostMessage (WM_COMMAND, ID_UPDATE);
00184 }
00185
00186 void CDownloads_Bittorrent_General::OnCmdUpdate()
00187 {
00188 UpdateStat ();
00189 Invalidate ();
00190 }