00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Downloads_Info.h"
00009 #include "fsDownloadsMgr.h"
00010
00011 #ifdef _DEBUG
00012 #define new DEBUG_NEW
00013 #undef THIS_FILE
00014 static char THIS_FILE[] = __FILE__;
00015 #endif
00016
00017 CDownloads_Info::CDownloads_Info()
00018 {
00019 m_bBtTabShowing = false;
00020 m_bBtTabWasActive = false;
00021 }
00022
00023 CDownloads_Info::~CDownloads_Info()
00024 {
00025 }
00026
00027 BEGIN_MESSAGE_MAP(CDownloads_Info, CTabCtrl)
00028
00029 ON_WM_CREATE()
00030 ON_WM_SIZE()
00031 ON_WM_PAINT()
00032 ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
00033 ON_WM_ERASEBKGND()
00034
00035 END_MESSAGE_MAP()
00036
00037 BOOL CDownloads_Info::Create(CWnd *pParent)
00038 {
00039 CRect rc (50, 50, 275, 70);
00040
00041 if (FALSE == CTabCtrl::Create (TCS_SINGLELINE|TCS_RIGHTJUSTIFY|TCS_FOCUSNEVER,
00042 rc, pParent, 0x5111))
00043 return FALSE;
00044
00045 LOGFONT lf;
00046 NONCLIENTMETRICS nm;
00047
00048 ZeroMemory (&nm, sizeof (nm));
00049 nm.cbSize = sizeof (nm);
00050 SystemParametersInfo (SPI_GETNONCLIENTMETRICS, nm.cbSize, &nm, 0);
00051 lf = nm.lfMenuFont;
00052 lf.lfCharSet = DEFAULT_CHARSET;
00053
00054 m_itemsFont.CreateFontIndirect (&lf);
00055
00056 SetFont (&m_itemsFont, FALSE);
00057
00058 CBitmap bmp;
00059 bmp.Attach (SBMP (IDB_DOWNLOADSINFO));
00060 m_images.Create (16, 16, ILC_COLOR24 | ILC_MASK, 1, 1);
00061 m_images.Add (&bmp, RGB (255,0,255));
00062 SetImageList (&m_images);
00063
00064 InsertItem (0, LS (L_LOG), 0);
00065 int nBtCorr = 0;
00066 if (IsBtDownloadActive ())
00067 {
00068 InsertItem (1, LS (L_BITTORRENT), 4);
00069 nBtCorr = 1;
00070 m_bBtTabShowing = true;
00071 }
00072 InsertItem (1+nBtCorr, LS (L_PROGRESS), 1);
00073 InsertItem (2+nBtCorr, LS (L_MEDIA_PREVIEW_CONVERT), 2);
00074 InsertItem (3+nBtCorr, LS (L_OPINIONS), 3);
00075
00076 int nCurTab = _App.View_DldInfoCurTab ();
00077 if (nCurTab == DIT_BT && m_bBtTabShowing == false)
00078 {
00079 nCurTab = DIT_LOG;
00080 m_bBtTabWasActive = true;
00081 }
00082 set_CurTab (nCurTab);
00083
00084 ShowWindow (SW_SHOW);
00085
00086 return TRUE;
00087 }
00088
00089 int CDownloads_Info::OnCreate(LPCREATESTRUCT lpCreateStruct)
00090 {
00091 if (CTabCtrl::OnCreate(lpCreateStruct) == -1)
00092 return -1;
00093
00094 CRect rc;
00095 GetItemRect (0, &rc);
00096 m_cy = rc.bottom - rc.top;
00097
00098 if (!m_frame.Create (this))
00099 return -1;
00100
00101 if (!m_log.Create (&m_frame))
00102 return -1;
00103
00104 if (!m_progress.Create (&m_frame))
00105 return -1;
00106
00107 if (!m_video.Create (&m_frame))
00108 return -1;
00109
00110 if (!m_opinions.Create (&m_frame))
00111 return -1;
00112
00113 if (!m_bt.Create (&m_frame))
00114 return -1;
00115
00116 m_frame.SetChildWnd (&m_log);
00117
00118 return 0;
00119 }
00120
00121 void CDownloads_Info::OnSize(UINT nType, int cx, int cy)
00122 {
00123 CTabCtrl::OnSize(nType, cx, cy);
00124
00125 CRect rc;
00126 GetItemRect (0, &rc);
00127 m_cy = rc.bottom - rc.top;
00128 m_cy+=3;
00129
00130 m_frame.MoveWindow (0, m_cy, cx, cy - m_cy);
00131 }
00132
00133 void CDownloads_Info::OnPaint()
00134 {
00135 CTabCtrl::OnPaint();
00136
00137 CDC *dc = GetDC ();
00138
00139 CRect rc;
00140 GetClientRect (&rc);
00141
00142 dc->SetPixel (rc.right-1, 22, GetSysColor (COLOR_3DFACE));
00143
00144 ReleaseDC (dc);
00145 }
00146
00147 void CDownloads_Info::OnSelchange(NMHDR*, LRESULT* pResult)
00148 {
00149 ApplyCurTab ();
00150 if (m_bBtTabWasActive && get_CurTab () != DIT_BT)
00151 m_bBtTabWasActive = false;
00152 else if (m_bBtTabWasActive == false && get_CurTab () == DIT_BT)
00153 m_bBtTabWasActive = true;
00154 *pResult = 0;
00155 }
00156
00157 void CDownloads_Info::ApplyLanguage()
00158 {
00159 TCITEM item;
00160 ZeroMemory (&item, sizeof (item));
00161
00162 item.mask = TCIF_TEXT;
00163 item.pszText = (LPSTR) LS (L_LOG);
00164 SetItem (0, &item);
00165
00166 int nBtCorr = 0;
00167 if (m_bBtTabShowing)
00168 {
00169 item.pszText = (LPSTR) LS (L_BITTORRENT);
00170 SetItem (1, &item);
00171 nBtCorr = 1;
00172 }
00173
00174 item.pszText = (LPSTR) LS (L_PROGRESS);
00175 SetItem (1+nBtCorr, &item);
00176
00177 item.pszText = (LPSTR) LS (L_MEDIA_PREVIEW_CONVERT);
00178 SetItem (2+nBtCorr, &item);
00179
00180 item.pszText = (LPSTR) LS (L_OPINIONS);
00181 SetItem (3+nBtCorr, &item);
00182
00183 m_log.ApplyLanguage ();
00184 m_video.ApplyLanguage ();
00185 m_bt.ApplyLanguage ();
00186 }
00187
00188 void CDownloads_Info::SaveState()
00189 {
00190 m_log.SaveState ("DownloadsLog");
00191 _App.View_DldInfoCurTab (m_bBtTabWasActive ? DIT_BT : get_CurTab ());
00192 m_video.SaveState ();
00193 }
00194
00195 void CDownloads_Info::ApplyCurTab()
00196 {
00197 int cur = GetCurSel ();
00198 int nBtCorr = m_bBtTabShowing ? 1 : 0;
00199
00200 if (cur == 0)
00201 {
00202 m_progress.ShowWindow (SW_HIDE);
00203 m_bt.ShowWindow (SW_HIDE);
00204 m_log.ShowWindow (SW_SHOW);
00205 m_video.ShowWindow (SW_HIDE);
00206 m_opinions.ShowWindow (SW_HIDE);
00207 m_frame.SetChildWnd (&m_log);
00208 }
00209 else if (cur == 1 && nBtCorr == 1)
00210 {
00211 m_log.ShowWindow (SW_HIDE);
00212 m_bt.ShowWindow (SW_SHOW);
00213 m_progress.ShowWindow (SW_HIDE);
00214 m_video.ShowWindow (SW_HIDE);
00215 m_opinions.ShowWindow (SW_HIDE);
00216 m_frame.SetChildWnd (&m_bt);
00217 }
00218 if (cur == 1+nBtCorr)
00219 {
00220
00221 m_log.ShowWindow (SW_HIDE);
00222 m_bt.ShowWindow (SW_HIDE);
00223 m_progress.ShowWindow (SW_SHOW);
00224 m_video.ShowWindow (SW_HIDE);
00225 m_opinions.ShowWindow (SW_HIDE);
00226 m_frame.SetChildWnd (&m_progress);
00227 }
00228 else if (cur == 2+nBtCorr)
00229 {
00230
00231 m_log.ShowWindow (SW_HIDE);
00232 m_bt.ShowWindow (SW_HIDE);
00233 m_progress.ShowWindow (SW_HIDE);
00234 m_video.ShowWindow (SW_SHOW);
00235 m_opinions.ShowWindow (SW_HIDE);
00236 m_frame.SetChildWnd (&m_video);
00237 }
00238 else if (cur == 3+nBtCorr)
00239 {
00240 m_log.ShowWindow (SW_HIDE);
00241 m_bt.ShowWindow (SW_HIDE);
00242 m_progress.ShowWindow (SW_HIDE);
00243 m_video.ShowWindow (SW_HIDE);
00244 m_opinions.ShowWindow (SW_SHOW);
00245 m_opinions.UpdateContent ();
00246 m_frame.SetChildWnd (&m_opinions);
00247 }
00248 }
00249
00250 vmsDownloadSmartPtr CDownloads_Info::Get_ActiveDownload()
00251 {
00252 return m_progress.GetActiveDownload ();
00253 }
00254
00255 void CDownloads_Info::Set_ActiveDownload(vmsDownloadSmartPtr dld)
00256 {
00257 m_activeDld = dld;
00258 ApplyBtTab ();
00259 m_progress.SetActiveDownload (dld);
00260 m_log.SetActiveDownload (dld);
00261 m_video.Set_ActiveDownload (dld);
00262 m_opinions.Set_ActiveDownload (dld);
00263 m_bt.Set_ActiveDownload (dld);
00264 }
00265
00266 void CDownloads_Info::UpdateActiveDownload()
00267 {
00268 if (m_progress.IsWindowVisible ())
00269 m_progress.UpdateDownload ();
00270 }
00271
00272 void CDownloads_Info::AddDownloadEvent(fsDownloadEvents *event)
00273 {
00274 m_log.AddRecord (event);
00275 }
00276
00277 CDownloads_Log* CDownloads_Info::Get_LogWindow()
00278 {
00279 return &m_log;
00280 }
00281
00282 CDownloads_Progress* CDownloads_Info::Get_ProgressWindow()
00283 {
00284 return &m_progress;
00285 }
00286
00287 BOOL CDownloads_Info::OnEraseBkgnd(CDC* pDC)
00288 {
00289
00290 if (m_video.m_wndVideo.m_player.Get_State () != VFPS_CLOSED)
00291 {
00292 CRect rc;
00293
00294 m_video.GetWindowRect(&rc);
00295 ScreenToClient(&rc);
00296
00297 pDC->ExcludeClipRect(&rc);
00298 }
00299
00300 return CTabCtrl::OnEraseBkgnd(pDC);
00301 }
00302
00303 void CDownloads_Info::set_CurTab(int nIndex)
00304 {
00305 if (nIndex != DIT_LOG && m_bBtTabShowing == false)
00306 nIndex--;
00307 SetCurSel (nIndex);
00308 ApplyCurTab ();
00309 }
00310
00311 int CDownloads_Info::get_CurTab()
00312 {
00313 int cur = GetCurSel ();
00314 if (cur != DIT_LOG && m_bBtTabShowing == false)
00315 cur++;
00316 return cur;
00317 }
00318
00319 BOOL CDownloads_Info::IsBtDownloadActive()
00320 {
00321 return m_activeDld != NULL && m_activeDld->pMgr->IsBittorrent ();
00322 }
00323
00324 void CDownloads_Info::UpdateBtStat()
00325 {
00326 if (m_bBtTabShowing == false)
00327 m_bt.Set_ActiveDownload (m_activeDld);
00328 ApplyBtTab ();
00329 m_bt.UpdateStat ();
00330 }
00331
00332 void CDownloads_Info::ApplyBtTab()
00333 {
00334 if (!m_bBtTabShowing != !IsBtDownloadActive ())
00335 {
00336 if (m_bBtTabShowing == false)
00337 {
00338 InsertItem (1, LS (L_BITTORRENT), 4);
00339 m_bBtTabShowing = true;
00340 if (m_bBtTabWasActive)
00341 set_CurTab (DIT_BT);
00342 }
00343 else
00344 {
00345 DeleteItem (1);
00346 m_bBtTabShowing = false;
00347 if (GetCurSel () == -1)
00348 set_CurTab (DIT_LOG);
00349 }
00350 }
00351 }