Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

CtrlHomePanel.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlHomePanel.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "CtrlHomePanel.h"
00026 
00027 #include "Statistics.h"
00028 #include "Network.h"
00029 #include "Neighbours.h"
00030 #include "Neighbour.h"
00031 #include "GraphItem.h"
00032 #include "Library.h"
00033 #include "LibraryBuilder.h"
00034 #include "LibraryHistory.h"
00035 #include "SharedFile.h"
00036 #include "Transfers.h"
00037 #include "Downloads.h"
00038 #include "Download.h"
00039 
00040 #include "CoolInterface.h"
00041 #include "ShellIcons.h"
00042 #include "RichDocument.h"
00043 #include "RichElement.h"
00044 #include "FragmentBar.h"
00045 #include "FileExecutor.h"
00046 #include "Skin.h"
00047 #include "XML.h"
00048 
00049 #ifdef _DEBUG
00050 #define new DEBUG_NEW
00051 #undef THIS_FILE
00052 static char THIS_FILE[] = __FILE__;
00053 #endif
00054 
00055 IMPLEMENT_DYNAMIC(CHomePanel, CTaskPanel)
00056 BEGIN_MESSAGE_MAP(CHomePanel, CTaskPanel)
00057         //{{AFX_MSG_MAP(CHomePanel)
00058         ON_WM_CREATE()
00059         //}}AFX_MSG_MAP
00060 END_MESSAGE_MAP()
00061 
00062 IMPLEMENT_DYNAMIC(CHomeDownloadsBox, CRichTaskBox)
00063 BEGIN_MESSAGE_MAP(CHomeDownloadsBox, CRichTaskBox)
00064         //{{AFX_MSG_MAP(CHomeDownloadsBox)
00065         ON_WM_CREATE()
00066         ON_WM_SIZE()
00067         ON_WM_PAINT()
00068         ON_WM_SETCURSOR()
00069         ON_WM_LBUTTONUP()
00070         ON_WM_TIMER()
00071         //}}AFX_MSG_MAP
00072 END_MESSAGE_MAP()
00073 
00074 IMPLEMENT_DYNAMIC(CHomeLibraryBox, CRichTaskBox)
00075 BEGIN_MESSAGE_MAP(CHomeLibraryBox, CRichTaskBox)
00076         //{{AFX_MSG_MAP(CHomeLibraryBox)
00077         ON_WM_CREATE()
00078         ON_WM_SIZE()
00079         ON_WM_PAINT()
00080         ON_WM_SETCURSOR()
00081         ON_WM_LBUTTONUP()
00082         ON_WM_TIMER()
00083         //}}AFX_MSG_MAP
00084 END_MESSAGE_MAP()
00085 
00086 IMPLEMENT_DYNAMIC(CHomeUploadsBox, CRichTaskBox)
00087 BEGIN_MESSAGE_MAP(CHomeUploadsBox, CRichTaskBox)
00088         //{{AFX_MSG_MAP(CHomeUploadsBox)
00089         //}}AFX_MSG_MAP
00090 END_MESSAGE_MAP()
00091 
00092 IMPLEMENT_DYNAMIC(CHomeConnectionBox, CRichTaskBox)
00093 BEGIN_MESSAGE_MAP(CHomeConnectionBox, CRichTaskBox)
00094         //{{AFX_MSG_MAP(CHomeConnectionBox)
00095         //}}AFX_MSG_MAP
00096 END_MESSAGE_MAP()
00097 
00098 IMPLEMENT_DYNAMIC(CHomeTorrentsBox, CRichTaskBox)
00099 BEGIN_MESSAGE_MAP(CHomeTorrentsBox, CRichTaskBox)
00100         //{{AFX_MSG_MAP(CHomeTorrentsBox)
00101         //}}AFX_MSG_MAP
00102 END_MESSAGE_MAP()
00103 
00104 
00106 // CHomePanel construction
00107 
00108 CHomePanel::CHomePanel()
00109 {
00110         // SetMargin( 0, 0 );
00111 }
00112 
00113 CHomePanel::~CHomePanel()
00114 {
00115 }
00116 
00118 // CHomePanel message handlers
00119 
00120 BOOL CHomePanel::Create(CWnd* pParentWnd)
00121 {
00122         CRect rect( 0, 0, 200, 0 );
00123         return CTaskPanel::Create( WS_VISIBLE, rect, pParentWnd, IDC_HOME_PANEL );
00124 }
00125 
00126 int CHomePanel::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00127 {
00128         if ( CTaskPanel::OnCreate( lpCreateStruct ) == -1 ) return -1;
00129         
00130         m_boxDownloads.Create( this, _T("Downloads"), IDR_DOWNLOADSFRAME );
00131         m_boxUploads.Create( this, _T("Uploads"), IDR_UPLOADSFRAME );
00132         m_boxConnection.Create( this, _T("Connection"), IDR_NEIGHBOURSFRAME );
00133         m_boxLibrary.Create( this, _T("Library"), IDR_LIBRARYFRAME );
00134         m_boxTorrents.Create( this, _T("Torrents"), IDR_BITTORRENT_ICON );
00135         
00136         AddBox( &m_boxDownloads );
00137         AddBox( &m_boxLibrary );
00138         AddBox( &m_boxConnection );
00139         if ( ! Settings.Interface.LowResMode ) 
00140         {
00141                 AddBox( &m_boxUploads );
00142                 if( Settings.BitTorrent.AdvancedInterface ) AddBox( &m_boxTorrents );
00143         }
00144         
00145         // SetStretchBox( &m_boxLibrary );
00146         
00147         return 0;
00148 }
00149 
00150 void CHomePanel::Setup()
00151 {
00152         SetWatermark( Skin.GetWatermark( _T("CHomePanel") ) );
00153         SetFooter( Skin.GetWatermark( _T("CHomePanel.Footer") ), TRUE );
00154         
00155         m_boxDownloads.Setup();
00156         m_boxUploads.Setup();
00157         m_boxConnection.Setup();
00158         m_boxLibrary.Setup();
00159         m_boxTorrents.Setup();
00160         
00161         Update();
00162         Invalidate();
00163 }
00164 
00165 void CHomePanel::Update()
00166 {
00167         m_boxDownloads.Update();
00168         m_boxUploads.Update();
00169         m_boxConnection.Update();
00170         m_boxLibrary.Update();
00171         m_boxTorrents.Update();
00172 }
00173 
00174 
00176 // CHomeDownloadsBox construction
00177 
00178 CHomeDownloadsBox::CHomeDownloadsBox()
00179 {
00180         SetPrimary();
00181 }
00182 
00183 CHomeDownloadsBox::~CHomeDownloadsBox()
00184 {
00185         for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00186         {
00187                 delete (Item*)m_pList.GetAt( nItem );
00188         }
00189 }
00190 
00192 // CHomeDownloadsBox message handlers
00193 
00194 int CHomeDownloadsBox::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00195 {
00196         if ( CRichTaskBox::OnCreate( lpCreateStruct ) == -1 ) return -1;
00197         
00198         m_pFont.CreateFont( -(theApp.m_nDefaultFontSize - 1), 0, 0, 0, FW_NORMAL, FALSE, TRUE, FALSE,
00199                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
00200                 DEFAULT_PITCH|FF_DONTCARE, theApp.m_sDefaultFont );
00201         
00202         m_hHand = theApp.LoadCursor( IDC_HAND );
00203         
00204         m_wndTip.Create( this, &Settings.Interface.TipDownloads );
00205         
00206         return 0;
00207 }
00208 
00209 void CHomeDownloadsBox::Setup()
00210 {
00211         if ( m_pDocument ) delete m_pDocument;
00212         m_pDocument = NULL;
00213         m_pdDownloadsNone = m_pdDownloadsOne = m_pdDownloadsMany = NULL;
00214         
00215         SetCaptionmark( Skin.GetWatermark( _T("CHomeDownloadsBox.Caption") ) );
00216         
00217         CXMLElement* pXML = Skin.GetDocument( _T("CHomeDownloadsBox") );
00218         if ( pXML == NULL ) return;
00219         
00220         SetCaption( pXML->GetAttributeValue( _T("title"), _T("Downloads") ) );
00221         
00222         m_pDocument = new CRichDocument();
00223         
00224         CMapStringToPtr pMap;
00225         if ( ! m_pDocument->LoadXML( pXML, &pMap ) ) return;
00226         
00227         pMap.Lookup( _T("DownloadsNone"), (void*&)m_pdDownloadsNone );
00228         pMap.Lookup( _T("DownloadsOne"), (void*&)m_pdDownloadsOne );
00229         pMap.Lookup( _T("DownloadsMany"), (void*&)m_pdDownloadsMany );
00230         
00231         if ( m_pdDownloadsMany ) m_sDownloadsMany = m_pdDownloadsMany->m_sText;
00232         
00233         GetView().SetDocument( m_pDocument );
00234         Update();
00235 }
00236 
00237 void CHomeDownloadsBox::Update()
00238 {
00239         if ( m_pDocument == NULL ) return;
00240         
00241         CSingleLock pLock( &Transfers.m_pSection );
00242         if ( ! pLock.Lock( 50 ) ) return;
00243         
00244         BOOL bChanged = FALSE;
00245         CString str;
00246         
00247         for ( int nItem = m_pList.GetSize() - 1 ; nItem >= 0 ; nItem-- )
00248         {
00249                 Item* pItem = (Item*)m_pList.GetAt( nItem );
00250                 
00251                 if ( ! Downloads.CheckActive( pItem->m_pDownload, 6 ) )
00252                 {
00253                         delete pItem;
00254                         m_pList.RemoveAt( nItem );
00255                         bChanged = TRUE;
00256                         m_pHover = NULL;
00257                         KillTimer( 2 );
00258                 }
00259         }
00260         
00261         int nCount = 0;
00262         int nInsert = 0;
00263         
00264         for ( POSITION pos = Downloads.GetReverseIterator() ; pos && nCount < 6 ; )
00265         {
00266                 CDownload* pDownload = Downloads.GetPrevious( pos );
00267                 if ( pDownload->IsPaused() ) continue;
00268                 if ( pDownload->IsCompleted() ) continue;
00269                 
00270                 Item* pItem = NULL;
00271                 
00272                 for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00273                 {
00274                         pItem = (Item*)m_pList.GetAt( nItem );
00275                         if ( pItem->m_pDownload == pDownload ) break;
00276                         pItem = NULL;
00277                 }
00278                 
00279                 if ( pItem == NULL )
00280                 {
00281                         pItem                           = new Item();
00282                         pItem->m_pDownload      = pDownload;
00283                         pItem->m_sText          = pDownload->GetDisplayName();
00284                         pItem->m_nIcon16        = ShellIcons.Get( pItem->m_sText, 16 );
00285                         m_pList.InsertAt( nInsert++, pItem );
00286                         bChanged = TRUE;
00287                         m_pHover = NULL;
00288                         KillTimer( 2 );
00289                 }
00290                 
00291                 QWORD nComplete = pDownload->GetVolumeComplete();
00292                 BOOL bPaused    = pDownload->GetFirstTransfer() == NULL;
00293                 
00294                 if ( pItem->m_nComplete != nComplete ||
00295                          pItem->m_bPaused != bPaused ||
00296                          pItem->m_nSize != pDownload->m_nSize )
00297                 {
00298                         pItem->m_nSize          = pDownload->m_nSize;
00299                         pItem->m_nComplete      = nComplete;
00300                         pItem->m_bPaused        = bPaused;
00301                         bChanged = TRUE;
00302                 }
00303                 
00304                 nCount++;
00305         }
00306         
00307         nCount = m_pList.GetSize() * 18;
00308         if ( nCount ) nCount += 6;
00309         
00310         m_pDocument->ShowGroup( 1, m_pList.GetSize() == 0 );
00311         
00312         int nActive = (int)CGraphItem::GetValue( GRC_DOWNLOADS_FILES );
00313         
00314         if ( nActive > 1 )
00315         {
00316                 if ( m_pdDownloadsMany )
00317                 {
00318                         str.Format( m_sDownloadsMany, nActive );
00319                         m_pdDownloadsMany->SetText( str );
00320                         m_pdDownloadsMany->Show( TRUE );
00321                 }
00322                 if ( m_pdDownloadsOne ) m_pdDownloadsOne->Show( FALSE );
00323                 if ( m_pdDownloadsNone ) m_pdDownloadsNone->Show( FALSE );
00324         }
00325         else if ( nActive == 1 )
00326         {
00327                 if ( m_pdDownloadsMany ) m_pdDownloadsMany->Show( FALSE );
00328                 if ( m_pdDownloadsOne ) m_pdDownloadsOne->Show( TRUE );
00329                 if ( m_pdDownloadsNone ) m_pdDownloadsNone->Show( FALSE );
00330         }
00331         else
00332         {
00333                 if ( m_pdDownloadsMany ) m_pdDownloadsMany->Show( FALSE );
00334                 if ( m_pdDownloadsOne ) m_pdDownloadsOne->Show( FALSE );
00335                 if ( m_pdDownloadsNone ) m_pdDownloadsNone->Show( TRUE );
00336         }
00337         
00338         m_pDocument->ShowGroup( 1, nActive == 0 );
00339         
00340         if ( GetView().IsModified() )
00341         {
00342                 CRect rc;
00343                 GetClientRect( &rc );
00344                 m_nWidth = rc.Width();
00345                 nCount += m_wndView.FullHeightMove( 0, nCount, m_nWidth );
00346         }
00347         else
00348         {
00349                 CRect rc;
00350                 m_wndView.GetWindowRect( &rc );
00351                 ScreenToClient( &rc );
00352                 
00353                 if ( rc.top != nCount )
00354                 {
00355                         m_nWidth = rc.Width();
00356                         nCount += m_wndView.FullHeightMove( 0, nCount, m_nWidth );
00357                 }
00358                 else
00359                 {
00360                         m_wndView.GetClientRect( &rc );
00361                         nCount += rc.Height();
00362                 }
00363         }
00364         
00365         SetSize( nCount );
00366         
00367         if ( bChanged ) Invalidate();
00368 }
00369 
00370 void CHomeDownloadsBox::OnSize(UINT nType, int cx, int cy) 
00371 {
00372         CTaskBox::OnSize( nType, cx, cy );
00373         
00374         if ( m_nWidth != cx )
00375         {
00376                 m_nWidth = cx;
00377                 int nCount = m_pList.GetSize() * 18;
00378                 if ( nCount ) nCount += 6;
00379                 nCount += m_wndView.FullHeightMove( 0, nCount, m_nWidth );
00380                 SetSize( nCount );
00381         }
00382 }
00383 
00384 void CHomeDownloadsBox::OnPaint() 
00385 {
00386         CRect rcClient, rcIcon, rcText;
00387         CPaintDC dc( this );
00388         
00389         GetClientRect( &rcClient );
00390         m_wndView.GetClientRect( &rcIcon );
00391         rcClient.bottom -= rcIcon.Height();
00392         rcClient.top += 6;
00393         
00394         rcIcon.SetRect( 4, rcClient.top, 4 + 20, rcClient.top + 16 );
00395         rcText.SetRect( rcIcon.right, rcIcon.top, rcClient.right - 4, rcIcon.bottom );
00396         rcIcon.DeflateRect( 0, 2 );
00397 
00398         dc.SetBkMode( OPAQUE );
00399         dc.SetBkColor( CoolInterface.m_crWindow );
00400         dc.SetTextColor( RGB( 0, 0, 255 ) );
00401         
00402         CFont* pOldFont = (CFont*)dc.SelectObject( &m_pFont );
00403         
00404         COLORREF crAlt[3] = { RGB( 0, 153, 255 ), RGB( 190, 0, 0 ), RGB( 0, 153, 0 ) };
00405         
00406         for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00407         {
00408                 Item* pItem = (Item*)m_pList.GetAt( nItem );
00409                 
00410                 if ( pItem->m_nComplete == 0 || pItem->m_nSize == SIZE_UNKNOWN )
00411                 {
00412                         ShellIcons.Draw( &dc, pItem->m_nIcon16, 16,
00413                                 ( rcIcon.left + rcIcon.right ) / 2 - 8, rcIcon.top,
00414                                 CoolInterface.m_crWindow );
00415                 }
00416                 else
00417                 {
00418                         COLORREF cr = pItem->m_bPaused ? RGB( 192, 192, 192 ) : crAlt[ nItem % 3 ];
00419                         dc.Draw3dRect( &rcIcon, RGB( 50, 50, 50 ), RGB( 50, 50, 50 ) );
00420                         rcIcon.DeflateRect( 1, 1 );
00421                         CFragmentBar::DrawFragment( &dc, &rcIcon, pItem->m_nSize, 0, pItem->m_nComplete, cr, TRUE );
00422                         dc.FillSolidRect( &rcIcon, CoolInterface.m_crWindow );
00423                         rcIcon.InflateRect( 1, 1 );
00424                         dc.ExcludeClipRect( &rcIcon );
00425                 }
00426                 
00427                 CString str = pItem->m_sText;
00428                 
00429                 if ( dc.GetTextExtent( str ).cx > rcText.Width() - 8 )
00430                 {
00431                         while ( str.GetLength() && dc.GetTextExtent( str + _T('\x2026') ).cx > rcText.Width() - 8 )
00432                         {
00433                                 str = str.Left( str.GetLength() - 1 );
00434                         }
00435                         str += _T('\x2026');
00436                 }
00437                 
00438                 dc.SetTextColor( m_pHover == pItem ? RGB( 255, 0, 0 ) : RGB( 0, 0, 255 ) );
00439                 dc.ExtTextOut( rcText.left + 4, rcText.top + 2, ETO_CLIPPED|ETO_OPAQUE,
00440                         &rcText, str, NULL );
00441                 
00442                 dc.ExcludeClipRect( &rcText );
00443                 
00444                 rcIcon.OffsetRect( 0, 18 );
00445                 rcText.OffsetRect( 0, 18 );
00446         }
00447 
00448         
00449         rcClient.top = 0;
00450         dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
00451         dc.SelectObject( pOldFont );
00452 }
00453 
00454 CHomeDownloadsBox::Item* CHomeDownloadsBox::HitTest(const CPoint& point) const
00455 {
00456         CRect rcClient, rcIcon, rcText;
00457         
00458         GetClientRect( &rcClient );
00459         rcClient.top += 6;
00460         
00461         rcIcon.SetRect( 4, rcClient.top, 4 + 20, rcClient.top + 16 );
00462         rcText.SetRect( rcIcon.right, rcIcon.top, rcClient.right - 4, rcIcon.bottom );
00463         
00464         for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00465         {
00466                 Item* pItem = (Item*)m_pList.GetAt( nItem );
00467                 
00468                 if ( rcIcon.PtInRect( point ) || rcText.PtInRect( point ) ) return pItem;
00469                 
00470                 rcIcon.OffsetRect( 0, 18 );
00471                 rcText.OffsetRect( 0, 18 );
00472         }
00473         
00474         return NULL;
00475 }
00476 
00477 BOOL CHomeDownloadsBox::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
00478 {
00479         CPoint point;
00480         GetCursorPos( &point );
00481         ScreenToClient( &point );
00482         
00483         Item* pItem = HitTest( point );
00484         
00485         if ( pItem != NULL )
00486                 m_wndTip.Show( pItem->m_pDownload );
00487         else
00488                 m_wndTip.Hide();
00489         
00490         if ( pItem != m_pHover )
00491         {
00492                 if ( pItem != NULL && m_pHover == NULL )
00493                         SetTimer( 2, 200, NULL );
00494                 else if ( pItem == NULL && m_pHover != NULL )
00495                         KillTimer( 2 );
00496                 
00497                 m_pHover = pItem;
00498                 Invalidate();
00499         }
00500         
00501         if ( m_pHover != NULL )
00502         {
00503                 ::SetCursor( m_hHand );
00504                 return TRUE;
00505         }
00506         
00507         return CTaskBox::OnSetCursor( pWnd, nHitTest, message );
00508 }
00509 
00510 void CHomeDownloadsBox::OnLButtonUp(UINT nFlags, CPoint point) 
00511 {
00512         if ( Item* pItem = HitTest( point ) )
00513         {
00514                 m_pHover = NULL;
00515                 KillTimer( 2 );
00516                 Invalidate();
00517                 
00518                 ExecuteDownload( pItem->m_pDownload );
00519         }
00520         
00521         CTaskBox::OnLButtonUp( nFlags, point );
00522 }
00523 
00524 void CHomeDownloadsBox::OnTimer(UINT nIDEvent)
00525 {
00526         CTaskBox::OnTimer( nIDEvent );
00527         
00528         CPoint point;
00529         CRect rect;
00530         
00531         GetCursorPos( &point );
00532         GetWindowRect( &rect );
00533         
00534         if ( rect.PtInRect( point ) ) return;
00535         
00536         KillTimer( 2 );
00537         
00538         if ( m_pHover != NULL )
00539         {
00540                 m_pHover = NULL;
00541                 Invalidate();
00542         }
00543 }
00544 
00545 BOOL CHomeDownloadsBox::ExecuteDownload(CDownload* pDownload)
00546 {
00547         CSingleLock pLock( &Transfers.m_pSection );
00548         if ( ! pLock.Lock( 1000 ) ) return FALSE;
00549         if ( ! Downloads.Check( pDownload ) ) return FALSE;
00550         if ( ! pDownload->IsStarted() ) return FALSE;
00551         
00552         if ( pDownload->IsCompleted() )
00553         {
00554                 CString strName = pDownload->m_sLocalName;
00555                 
00556                 if ( pDownload->m_bVerify == TS_FALSE )
00557                 {
00558                         CString strFormat, strMessage;
00559                         
00560                         LoadString( strFormat, IDS_LIBRARY_VERIFY_FAIL );
00561                         strMessage.Format( strFormat, (LPCTSTR)strName );
00562                         
00563                         pLock.Unlock();
00564                         UINT nResponse = AfxMessageBox( strMessage, MB_ICONEXCLAMATION|MB_YESNO|MB_DEFBUTTON2 );
00565                         if ( nResponse != IDYES ) return FALSE;
00566                         pLock.Lock();
00567                 }
00568                 
00569                 pLock.Unlock();
00570                 CFileExecutor::Execute( strName, FALSE );
00571         }
00572         else if ( pDownload->IsStarted() && ! pDownload->IsMoving() )
00573         {
00574                 CString strType;
00575                 
00576                 int nExtPos = pDownload->m_sLocalName.ReverseFind( '.' );
00577                 if ( nExtPos > 0 ) strType = pDownload->m_sLocalName.Mid( nExtPos + 1 );
00578                 strType = _T("|") + strType + _T("|");
00579                 
00580                 if ( _tcsistr( Settings.Library.SafeExecute, strType ) == NULL )
00581                 {
00582                         CString strFormat, strPrompt;
00583                         
00584                         LoadString( strFormat, IDS_LIBRARY_CONFIRM_EXECUTE );
00585                         strPrompt.Format( strFormat, (LPCTSTR)pDownload->m_sLocalName );
00586                         
00587                         pLock.Unlock();
00588                         int nResult = AfxMessageBox( strPrompt, MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 );
00589                         if ( nResult != IDYES ) return FALSE;
00590                         pLock.Lock();
00591                 }
00592                 
00593                 if ( Downloads.Check( pDownload ) ) pDownload->Preview( &pLock );
00594         }
00595         else
00596         {
00597                 AfxGetMainWnd()->PostMessage( WM_COMMAND, ID_VIEW_DOWNLOADS );
00598         }
00599         
00600         return TRUE;
00601 }
00602 
00604 // CHomeLibraryBox
00605 
00606 CHomeLibraryBox::CHomeLibraryBox()
00607 {
00608         SetPrimary();
00609 }
00610 
00611 CHomeLibraryBox::~CHomeLibraryBox()
00612 {
00613         for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00614         {
00615                 delete (Item*)m_pList.GetAt( nItem );
00616         }
00617 }
00618 
00620 // CHomeLibraryBox message handlers
00621 
00622 int CHomeLibraryBox::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00623 {
00624         if ( CRichTaskBox::OnCreate( lpCreateStruct ) == -1 ) return -1;
00625         
00626         m_pFont.CreateFont( -(theApp.m_nDefaultFontSize - 1), 0, 0, 0, FW_NORMAL, FALSE, TRUE, FALSE,
00627                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
00628                 DEFAULT_PITCH|FF_DONTCARE, theApp.m_sDefaultFont );
00629         
00630         m_hHand = theApp.LoadCursor( IDC_HAND );
00631         
00632         return 0;
00633 }
00634 
00635 void CHomeLibraryBox::Setup()
00636 {
00637         if ( m_pDocument ) delete m_pDocument;
00638         m_pDocument = NULL;
00639         m_pdLibraryFiles = m_pdLibraryVolume = m_pdLibraryHashRemaining = NULL;
00640         
00641         SetCaptionmark( Skin.GetWatermark( _T("CHomeLibraryBox.Caption") ) );
00642         
00643         CXMLElement* pXML = Skin.GetDocument( _T("CHomeLibraryBox") );
00644         if ( pXML == NULL ) return;
00645         
00646         SetCaption( pXML->GetAttributeValue( _T("title"), _T("Library") ) );
00647         
00648         m_pDocument = new CRichDocument();
00649         
00650         CMapStringToPtr pMap;
00651         if ( ! m_pDocument->LoadXML( pXML, &pMap ) ) return;
00652         
00653         pMap.Lookup( _T("LibraryFiles"), (void*&)m_pdLibraryFiles );
00654         pMap.Lookup( _T("LibraryVolume"), (void*&)m_pdLibraryVolume );
00655         pMap.Lookup( _T("LibraryHashRemaining"), (void*&)m_pdLibraryHashRemaining );
00656         
00657         SetDocument( m_pDocument );
00658         
00659         Update();
00660 }
00661 
00662 void CHomeLibraryBox::Update()
00663 {
00664         if ( m_pDocument == NULL ) return;
00665         
00666         CSingleLock pLock( &Library.m_pSection );
00667         if ( ! pLock.Lock( 50 ) ) return;
00668         
00669         BOOL bChanged = FALSE;
00670         int nCount = 0;
00671         CString str;
00672         
00673         for ( int nItem = m_pList.GetSize() - 1 ; nItem >= 0 ; nItem-- )
00674         {
00675                 Item* pItem = (Item*)m_pList.GetAt( nItem );
00676                 
00677                 if ( ! LibraryHistory.Check( pItem->m_pRecent, 6 ) ||
00678                         NULL == pItem->m_pRecent->m_pFile )
00679                 {
00680                         delete pItem;
00681                         m_pList.RemoveAt( nItem );
00682                         bChanged = TRUE;
00683                 }
00684         }
00685         
00686         for ( POSITION pos = LibraryHistory.GetIterator() ; pos && nCount < 6 ; )
00687         {
00688                 CLibraryRecent* pRecent = LibraryHistory.GetNext( pos );
00689                 if ( pRecent->m_pFile == NULL ) continue;
00690                 
00691         int nItem = m_pList.GetSize() - 1;
00692                 for ( ; nItem >= 0 ; nItem-- )
00693                 {
00694                         Item* pItem = (Item*)m_pList.GetAt( nItem );
00695                         if ( pItem->m_pRecent == pRecent ) break;
00696                 }
00697                 
00698                 if ( nItem < 0 )
00699                 {
00700                         Item* pItem                     = new Item();
00701                         pItem->m_pRecent        = pRecent;
00702                         pItem->m_nIndex         = pRecent->m_pFile->m_nIndex;
00703                         pItem->m_sText          = pRecent->m_pFile->m_sName;
00704                         pItem->m_nIcon16        = ShellIcons.Get( pItem->m_sText, 16 );
00705                         
00706                         m_pList.InsertAt( nCount, pItem );
00707                         bChanged = TRUE;
00708                 }
00709                 
00710                 nCount++;
00711         }
00712         
00713         nCount = m_pList.GetSize() * 18;
00714         if ( nCount ) nCount += 6;
00715         
00716         m_pDocument->ShowGroup( 2, m_pList.GetSize() == 0 );
00717         
00718         QWORD nVolume;
00719         DWORD nFiles;
00720         
00721         LibraryMaps.GetStatistics( &nFiles, &nVolume );
00722         
00723         if ( m_pdLibraryFiles )
00724         {
00725                 str.Format( _T("%lu "), nFiles );
00726                 if ( m_pdLibraryFiles->m_sText.Compare( str ) != 0 )
00727                 {
00728                         m_pdLibraryFiles->SetText( str );
00729                         bChanged = TRUE;
00730                 }
00731         }
00732         
00733         if ( m_pdLibraryVolume )
00734         {
00735                 str = Settings.SmartVolume( nVolume, TRUE ) + ' ';
00736                 if ( m_pdLibraryVolume->m_sText.Compare( str ) != 0 )
00737                 {
00738                         m_pdLibraryVolume->SetText( str );
00739                         bChanged = TRUE;
00740                 }
00741         }
00742         
00743         int nHashing = LibraryBuilder.GetRemaining();
00744         
00745         if ( nHashing > 0 )
00746         {
00747                 str.Format( _T("%lu "), nHashing );
00748                 if ( m_pdLibraryHashRemaining ) 
00749                 {
00750                         if ( m_pdLibraryHashRemaining->m_sText.Compare( str ) != 0 )
00751                         {
00752                                 m_pdLibraryHashRemaining->SetText( str );
00753                                 bChanged = TRUE;
00754                         }
00755                 }
00756                 m_pDocument->ShowGroup( 1, TRUE );
00757                 
00758                 BOOL bPriority = LibraryBuilder.GetBoostPriority();
00759                 m_pDocument->ShowGroup( 3, bPriority == FALSE );
00760                 m_pDocument->ShowGroup( 4, bPriority == TRUE );
00761         }
00762         else
00763         {
00764                 m_pDocument->ShowGroup( 1, FALSE );
00765                 m_pDocument->ShowGroup( 3, FALSE );
00766                 m_pDocument->ShowGroup( 4, FALSE );
00767         }
00768         
00769         if ( GetView().IsModified() )
00770         {
00771                 CRect rc;
00772                 GetClientRect( &rc );
00773                 m_nWidth = rc.Width();
00774                 nCount += m_wndView.FullHeightMove( 0, nCount, m_nWidth );
00775         }
00776         else
00777         {
00778                 CRect rc;
00779                 m_wndView.GetWindowRect( &rc );
00780                 ScreenToClient( &rc );
00781                 
00782                 if ( rc.top != nCount )
00783                 {
00784                         m_nWidth = rc.Width();
00785                         nCount += m_wndView.FullHeightMove( 0, nCount, m_nWidth );
00786                 }
00787                 else
00788                 {
00789                         m_wndView.GetClientRect( &rc );
00790                         nCount += rc.Height();
00791                 }
00792         }
00793         
00794         SetSize( nCount );
00795         
00796         if ( bChanged )
00797         {
00798                 m_pHover = NULL;
00799                 KillTimer( 2 );
00800                 m_wndView.Invalidate();
00801         }
00802 }
00803 
00804 void CHomeLibraryBox::OnSize(UINT nType, int cx, int cy) 
00805 {
00806         CTaskBox::OnSize( nType, cx, cy );
00807         
00808         if ( m_nWidth != cx )
00809         {
00810                 m_nWidth = cx;
00811                 int nCount = m_pList.GetSize() * 18;
00812                 if ( nCount ) nCount += 6;
00813                 nCount += m_wndView.FullHeightMove( 0, nCount, m_nWidth );
00814                 SetSize( nCount );
00815         }
00816 }
00817 
00818 void CHomeLibraryBox::OnPaint() 
00819 {
00820         CRect rcClient, rcIcon, rcText;
00821         CPaintDC dc( this );
00822         
00823         GetClientRect( &rcClient );
00824         m_wndView.GetClientRect( &rcIcon );
00825         rcClient.bottom -= rcIcon.Height();
00826         rcClient.top += 6;
00827         
00828         rcIcon.SetRect( 4, rcClient.top, 4 + 16, rcClient.top + 16 );
00829         rcText.SetRect( rcIcon.right, rcIcon.top, rcClient.right - 4, rcIcon.bottom );
00830         
00831         dc.SetBkMode( OPAQUE );
00832         dc.SetBkColor( CoolInterface.m_crWindow );
00833         dc.SetTextColor( RGB( 0, 0, 255 ) );
00834         
00835         CFont* pOldFont = (CFont*)dc.SelectObject( &m_pFont );
00836         
00837         for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00838         {
00839                 Item* pItem = (Item*)m_pList.GetAt( nItem );
00840                 
00841                 ShellIcons.Draw( &dc, pItem->m_nIcon16, 16, rcIcon.left, rcIcon.top,
00842                         CoolInterface.m_crWindow );
00843                 
00844                 CString str = pItem->m_sText;
00845                 
00846                 if ( dc.GetTextExtent( str ).cx > rcText.Width() - 8 )
00847                 {
00848                         while ( str.GetLength() && dc.GetTextExtent( str + _T('\x2026') ).cx > rcText.Width() - 8 )
00849                         {
00850                                 str = str.Left( str.GetLength() - 1 );
00851                         }
00852                         str += _T('\x2026');
00853                 }
00854                 
00855                 dc.SetTextColor( m_pHover == pItem ? RGB( 255, 0, 0 ) : RGB( 0, 0, 255 ) );
00856                 dc.ExtTextOut( rcText.left + 4, rcText.top + 2, ETO_CLIPPED|ETO_OPAQUE,
00857                         &rcText, str, NULL );
00858                 
00859                 dc.ExcludeClipRect( &rcIcon );
00860                 dc.ExcludeClipRect( &rcText );
00861                 
00862                 rcIcon.OffsetRect( 0, 18 );
00863                 rcText.OffsetRect( 0, 18 );
00864         }
00865         
00866         rcClient.top = 0;
00867         dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
00868         dc.SelectObject( pOldFont );
00869 }
00870 
00871 CHomeLibraryBox::Item* CHomeLibraryBox::HitTest(const CPoint& point) const
00872 {
00873         CRect rcClient, rcIcon, rcText;
00874         
00875         GetClientRect( &rcClient );
00876         rcClient.top += 6;
00877         
00878         rcIcon.SetRect( 4, rcClient.top, 4 + 16, rcClient.top + 16 );
00879         rcText.SetRect( rcIcon.right, rcIcon.top, rcClient.right - 4, rcIcon.bottom );
00880         
00881         for ( int nItem = 0 ; nItem < m_pList.GetSize() ; nItem++ )
00882         {
00883                 Item* pItem = (Item*)m_pList.GetAt( nItem );
00884                 
00885                 if ( rcIcon.PtInRect( point ) || rcText.PtInRect( point ) ) return pItem;
00886                 
00887                 rcIcon.OffsetRect( 0, 18 );
00888                 rcText.OffsetRect( 0, 18 );
00889         }
00890         
00891         return NULL;
00892 }
00893 
00894 BOOL CHomeLibraryBox::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
00895 {
00896         CPoint point;
00897         GetCursorPos( &point );
00898         ScreenToClient( &point );
00899         
00900         Item* pItem = HitTest( point );
00901         
00902         if ( pItem != m_pHover )
00903         {
00904                 if ( pItem != NULL && m_pHover == NULL )
00905                         SetTimer( 2, 200, NULL );
00906                 else if ( pItem == NULL && m_pHover != NULL )
00907                         KillTimer( 2 );
00908                 
00909                 m_pHover = pItem;
00910                 Invalidate();
00911         }
00912         
00913         if ( m_pHover != NULL )
00914         {
00915                 ::SetCursor( m_hHand );
00916                 return TRUE;
00917         }
00918         
00919         return CTaskBox::OnSetCursor( pWnd, nHitTest, message );
00920 }
00921 
00922 void CHomeLibraryBox::OnLButtonUp(UINT nFlags, CPoint point) 
00923 {
00924         if ( Item* pItem = HitTest( point ) )
00925         {
00926                 CSingleLock oLock( &Library.m_pSection, TRUE );
00927                 if ( CLibraryFile* pFile = Library.LookupFile( pItem->m_nIndex ) )
00928                 {
00929                         if ( pFile->m_pFolder )
00930                         {
00931                                 CString strPath = pFile->GetPath();
00932                                 oLock.Unlock();
00933                                 CFileExecutor::Execute( strPath, FALSE );
00934                         }
00935                         else
00936                         {
00937                                 oLock.Unlock();
00938                         }
00939                         m_pHover = NULL;
00940                         KillTimer( 2 );
00941                         Invalidate();
00942                 }
00943         }
00944         
00945         CTaskBox::OnLButtonUp( nFlags, point );
00946 }
00947 
00948 void CHomeLibraryBox::OnTimer(UINT nIDEvent)
00949 {
00950         CTaskBox::OnTimer( nIDEvent );
00951         
00952         CPoint point;
00953         CRect rect;
00954         
00955         GetCursorPos( &point );
00956         GetWindowRect( &rect );
00957         
00958         if ( rect.PtInRect( point ) ) return;
00959         
00960         KillTimer( 2 );
00961         
00962         if ( m_pHover != NULL )
00963         {
00964                 m_pHover = NULL;
00965                 Invalidate();
00966         }
00967 }
00968 
00970 // CHomeUploadsBox construction
00971 
00972 CHomeUploadsBox::CHomeUploadsBox()
00973 {
00974         SetPrimary();
00975 }
00976 
00977 CHomeUploadsBox::~CHomeUploadsBox()
00978 {
00979 }
00980 
00982 // CHomeUploadsBox message handlers
00983 
00984 void CHomeUploadsBox::Setup()
00985 {
00986         if ( m_pDocument ) delete m_pDocument;
00987         m_pDocument = NULL;
00988         m_pdUploadsNone = m_pdUploadsOne = m_pdUploadsMany = NULL;
00989         m_pdUploadedNone = m_pdUploadedOne = m_pdUploadedMany = NULL;
00990         
00991         SetCaptionmark( Skin.GetWatermark( _T("CHomeUploadsBox.Caption") ) );
00992         
00993         CXMLElement* pXML = Skin.GetDocument( _T("CHomeUploadsBox") );
00994         if ( pXML == NULL ) return;
00995         
00996         SetCaption( pXML->GetAttributeValue( _T("title"), _T("Uploads") ) );
00997         
00998         m_pDocument = new CRichDocument();
00999         
01000         CMapStringToPtr pMap;
01001         if ( ! m_pDocument->LoadXML( pXML, &pMap ) ) return;
01002         
01003         pMap.Lookup( _T("UploadsNone"), (void*&)m_pdUploadsNone );
01004         pMap.Lookup( _T("UploadsOne"), (void*&)m_pdUploadsOne );
01005         pMap.Lookup( _T("UploadsMany"), (void*&)m_pdUploadsMany );
01006         pMap.Lookup( _T("UploadedNone"), (void*&)m_pdUploadedNone );
01007         pMap.Lookup( _T("UploadedOne"), (void*&)m_pdUploadedOne );
01008         pMap.Lookup( _T("UploadedMany"), (void*&)m_pdUploadedMany );
01009         
01010         if ( m_pdUploadedOne ) m_sUploadedOne = m_pdUploadedOne->m_sText;
01011         if ( m_pdUploadedMany ) m_sUploadedMany = m_pdUploadedMany->m_sText;
01012         
01013         if ( m_pdUploadsMany ) m_sUploadsMany = m_pdUploadsMany->m_sText;
01014         
01015         SetDocument( m_pDocument );
01016         
01017         Update();
01018 }
01019 
01020 void CHomeUploadsBox::Update()
01021 {
01022         if ( m_pDocument == NULL ) return;
01023         
01024         CString str;
01025         
01026         int nCount = (int)CGraphItem::GetValue( GRC_UPLOADS_TRANSFERS );
01027         
01028         if ( nCount > 1 )
01029         {
01030                 if ( m_pdUploadsMany )
01031                 {
01032                         str.Format( m_sUploadsMany, nCount );
01033                         m_pdUploadsMany->SetText( str );
01034                         m_pdUploadsMany->Show( TRUE );
01035                 }
01036                 if ( m_pdUploadsOne ) m_pdUploadsOne->Show( FALSE );
01037                 if ( m_pdUploadsNone ) m_pdUploadsNone->Show( FALSE );
01038         }
01039         else if ( nCount == 1 )
01040         {
01041                 if ( m_pdUploadsMany ) m_pdUploadsMany->Show( FALSE );
01042                 if ( m_pdUploadsOne ) m_pdUploadsOne->Show( TRUE );
01043                 if ( m_pdUploadsNone ) m_pdUploadsNone->Show( FALSE );
01044         }
01045         else
01046         {
01047                 if ( m_pdUploadsMany ) m_pdUploadsMany->Show( FALSE );
01048                 if ( m_pdUploadsOne ) m_pdUploadsOne->Show( FALSE );
01049                 if ( m_pdUploadsNone ) m_pdUploadsNone->Show( TRUE );
01050         }
01051         
01052         if ( Statistics.Today.Uploads.Files == 0 )
01053         {
01054                 if ( m_pdUploadedNone ) m_pdUploadedNone->Show( TRUE );
01055                 if ( m_pdUploadedOne )  m_pdUploadedOne->Show( FALSE );
01056                 if ( m_pdUploadedMany ) m_pdUploadedMany->Show( FALSE );
01057         }
01058         else if ( Statistics.Today.Uploads.Files == 1 )
01059         {
01060                 str.Format( m_sUploadedOne, (LPCTSTR)Settings.SmartVolume( Statistics.Today.Uploads.Volume, TRUE ) );
01061 
01062                 if ( m_pdUploadedNone ) m_pdUploadedNone->Show( FALSE );
01063                 if ( m_pdUploadedMany ) m_pdUploadedMany->Show( FALSE );
01064 
01065                 if ( m_pdUploadedOne )
01066                 {
01067                         m_pdUploadedOne->SetText( str );
01068                         m_pdUploadedOne->Show( TRUE );
01069                 }
01070         }
01071         else
01072         {
01073                 str.Format( m_sUploadedMany, (int)Statistics.Today.Uploads.Files,
01074                         (LPCTSTR)Settings.SmartVolume( Statistics.Today.Uploads.Volume, TRUE ) );
01075                 
01076                 if ( m_pdUploadedNone ) m_pdUploadedNone->Show( FALSE );
01077                 if ( m_pdUploadedOne )  m_pdUploadedOne->Show( FALSE );
01078                 
01079                 if ( m_pdUploadedMany )
01080                 {
01081                         m_pdUploadedMany->SetText( str );
01082                         m_pdUploadedMany->Show( TRUE );
01083                 }
01084         }
01085         
01086         CRichTaskBox::Update();
01087 }
01088 
01090 // CHomeConnectionBox construction
01091 
01092 CHomeConnectionBox::CHomeConnectionBox()
01093 {
01094         SetPrimary();
01095 }
01096 
01097 CHomeConnectionBox::~CHomeConnectionBox()
01098 {
01099 }
01100 
01102 // CHomeConnectionBox message handlers
01103 
01104 void CHomeConnectionBox::Setup()
01105 {
01106         if ( m_pDocument ) delete m_pDocument;
01107         m_pDocument = NULL;
01108         m_pdConnectedHours = m_pdConnectedMinutes = NULL;
01109         
01110         for ( int nP = 0 ; nP < 4 ; nP++ )
01111         {
01112                 for ( int nT = 0 ; nT < 3 ; nT++ )
01113                 {
01114                         m_pdCount[ nP ][ nT ] = NULL;
01115                         m_sCount[ nP ][ nT ].Empty();
01116                 }
01117         }
01118         
01119         SetCaptionmark( Skin.GetWatermark( _T("CHomeConnectionBox.Caption") ) );
01120         
01121         CXMLElement* pXML = Skin.GetDocument( _T("CHomeConnectionBox") );
01122         if ( pXML == NULL ) return;
01123         
01124         SetCaption( pXML->GetAttributeValue( _T("title"), _T("Connection") ) );
01125         
01126         m_pDocument = new CRichDocument();
01127         
01128         CMapStringToPtr pMap;
01129         if ( ! m_pDocument->LoadXML( pXML, &pMap ) ) return;
01130         
01131         pMap.Lookup( _T("ConnectedHours"), (void*&)m_pdConnectedHours );
01132         pMap.Lookup( _T("ConnectedMinutes"), (void*&)m_pdConnectedMinutes );
01133         
01134         pMap.Lookup( _T("G1Peers"), (void*&)m_pdCount[PROTOCOL_G1][ntNode] );
01135         pMap.Lookup( _T("G1Hubs"), (void*&)m_pdCount[PROTOCOL_G1][ntHub] );
01136         pMap.Lookup( _T("G1Leaves"), (void*&)m_pdCount[PROTOCOL_G1][ntLeaf] );
01137         
01138         pMap.Lookup( _T("G2Peers"), (void*&)m_pdCount[PROTOCOL_G2][ntNode] );
01139         pMap.Lookup( _T("G2Hubs"), (void*&)m_pdCount[PROTOCOL_G2][ntHub] );
01140         pMap.Lookup( _T("G2Leaves"), (void*&)m_pdCount[PROTOCOL_G2][ntLeaf] );
01141         
01142         pMap.Lookup( _T("EDServers"), (void*&)m_pdCount[PROTOCOL_ED2K][ntHub] );
01143         
01144         for ( int nP = 0 ; nP < 4 ; nP++ )
01145         {
01146                 for ( int nT = 0 ; nT < 3 ; nT++ )
01147                 {
01148                         if ( m_pdCount[ nP ][ nT ] != NULL )
01149                         {
01150                                 m_sCount[ nP ][ nT ] = m_pdCount[ nP ][ nT ]->m_sText;
01151                         }
01152                 }
01153         }
01154         
01155         SetDocument( m_pDocument );
01156         
01157         Update();
01158 }
01159 
01160 void CHomeConnectionBox::Update()
01161 {
01162         if ( m_pDocument == NULL ) return;
01163         
01164         CSingleLock pLock( &Network.m_pSection );
01165         if ( ! pLock.Lock( 50 ) ) return;
01166         
01167         int nCount[4][4], nTotal = 0;
01168         CString str;
01169         
01170         ZeroMemory( nCount, sizeof(int) * 4 * 4 );
01171         
01172         for ( POSITION pos = Neighbours.GetIterator() ; pos ; )
01173         {
01174                 CNeighbour* pNeighbour = Neighbours.GetNext( pos );
01175                 
01176                 if ( pNeighbour->m_nState >= nrsConnected )
01177                 {
01178                         nCount[ pNeighbour->m_nProtocol ][ pNeighbour->m_nNodeType+1 ] ++;
01179                         nTotal ++;
01180                 }
01181                 else
01182                 {
01183                         nCount[ pNeighbour->m_nProtocol ][ 0 ] ++;
01184                 }
01185         }
01186         
01187         nCount[ PROTOCOL_G1 ][ 0 ] += nCount[ 0 ][ 0 ];
01188         nCount[ PROTOCOL_G2 ][ 0 ] += nCount[ 0 ][ 0 ];
01189         
01190         BOOL bConnected = Network.IsConnected();
01191         m_pDocument->ShowGroup( 1, ! bConnected );
01192         m_pDocument->ShowGroup( 2, bConnected );
01193         
01194         BOOL* pEnable[4] =
01195         {
01196                 NULL, &Settings.Gnutella1.EnableToday, &Settings.Gnutella2.EnableToday,
01197                 &Settings.eDonkey.EnableToday
01198         };
01199         
01200         BOOL bDetail = Settings.General.GUIMode != GUI_BASIC;
01201         
01202         for ( int nProtocol = PROTOCOL_G1 ; nProtocol <= PROTOCOL_ED2K ; nProtocol++ )
01203         {
01204                 int nBase = nProtocol * 10;
01205                 
01206                 if ( bConnected && *pEnable[ nProtocol ] )
01207                 {
01208                         m_pDocument->ShowGroup( nBase, TRUE );
01209                         
01210                         if ( nCount[ nProtocol ][ ntLeaf+1 ] )
01211                         {
01212                                 if ( m_pdCount[ nProtocol ][ ntLeaf ] && bDetail )
01213                                 {
01214                                         str.Format( m_sCount[ nProtocol ][ ntLeaf ], nCount[ nProtocol ][ ntLeaf+1 ] );
01215                                         m_pdCount[ nProtocol ][ ntLeaf ]->SetText( str );
01216                                         
01217                                         m_pDocument->ShowGroup( nBase + 3, FALSE );
01218                                         m_pDocument->ShowGroup( nBase + 4, FALSE );
01219                                         m_pDocument->ShowGroup( nBase + 5, TRUE );
01220                                 }
01221                                 else
01222                                 {
01223                                         m_pDocument->ShowGroup( nBase + 3, TRUE );
01224                                         m_pDocument->ShowGroup( nBase + 4, FALSE );
01225                                         m_pDocument->ShowGroup( nBase + 5, FALSE );
01226                                 }
01227                         }
01228                         else if ( nCount[ nProtocol ][ ntHub+1 ] )
01229                         {
01230                                 if ( m_pdCount[ nProtocol ][ ntHub ] && bDetail )
01231                                 {
01232                                         str.Format( m_sCount[ nProtocol ][ ntHub ], nCount[ nProtocol ][ ntHub+1 ] );
01233                                         m_pdCount[ nProtocol ][ ntHub ]->SetText( str );
01234                                         
01235                                         m_pDocument->ShowGroup( nBase + 3, FALSE );
01236                                         m_pDocument->ShowGroup( nBase + 4, TRUE );
01237                                         m_pDocument->ShowGroup( nBase + 5, FALSE );
01238                                 }
01239                                 else
01240                                 {
01241                                         m_pDocument->ShowGroup( nBase + 3, TRUE );
01242                                         m_pDocument->ShowGroup( nBase + 4, FALSE );
01243                                         m_pDocument->ShowGroup( nBase + 5, FALSE );
01244                                 }
01245                         }
01246                         else if ( nCount[ nProtocol ][ ntNode+1 ] )
01247                         {
01248                                 m_pDocument->ShowGroup( nBase + 3, TRUE );
01249                                 m_pDocument->ShowGroup( nBase + 4, FALSE );
01250                                 m_pDocument->ShowGroup( nBase + 5, FALSE );
01251                         }
01252                         else
01253                         {
01254                                 m_pDocument->ShowGroup( nBase + 3, FALSE );
01255                                 m_pDocument->ShowGroup( nBase + 4, FALSE );
01256                                 m_pDocument->ShowGroup( nBase + 5, FALSE );
01257                         }
01258                         
01259                         if ( nCount[ nProtocol ][ ntNode+1 ] ||
01260                                  nCount[ nProtocol ][ ntHub+1 ] ||
01261                                  nCount[ nProtocol ][ ntLeaf+1 ] )
01262                         {
01263                                 m_pDocument->ShowGroup( nBase + 1, FALSE );
01264                                 m_pDocument->ShowGroup( nBase + 2, FALSE );
01265                         }
01266                         else
01267                         {
01268                                 m_pDocument->ShowGroup( nBase + 1, nCount[ nProtocol ][ 0 ] == 0 );
01269                                 m_pDocument->ShowGroup( nBase + 2, nCount[ nProtocol ][ 0 ] != 0 );
01270                         }
01271                 }
01272                 else
01273                 {
01274                         m_pDocument->ShowGroupRange( nBase, nBase + 9, FALSE );
01275                 }
01276         }
01277         
01278         str.Format( _T("%I64i "), Statistics.Today.Timer.Connected / ( 60 * 60 ) );
01279         if ( m_pdConnectedHours ) m_pdConnectedHours->SetText( str );
01280         str.Format( _T("%I64i "), ( Statistics.Today.Timer.Connected / 60 ) % 60 );
01281         if ( m_pdConnectedMinutes ) m_pdConnectedMinutes->SetText( str );
01282         
01283         CRichTaskBox::Update();
01284 }
01285 
01287 // CHomeTorrentsBox construction
01288 
01289 CHomeTorrentsBox::CHomeTorrentsBox()
01290 {
01291         SetPrimary();
01292 }
01293 
01294 CHomeTorrentsBox::~CHomeTorrentsBox()
01295 {
01296 }
01297 
01299 // CHomeTorrentsBox message handlers
01300 
01301 void CHomeTorrentsBox::Setup()
01302 {
01303         if ( m_pDocument ) delete m_pDocument;
01304         m_pDocument = NULL;
01305         m_pdTorrentsNone = m_pdTorrentsOne = m_pdTorrentsMany = m_pdReseedTorrent = NULL;
01306         
01307         SetCaptionmark( Skin.GetWatermark( _T("CHomeTorrentsBox.Caption") ) );
01308         
01309         CXMLElement* pXML = Skin.GetDocument( _T("CHomeTorrentsBox") );
01310         if ( pXML == NULL ) return;
01311         
01312         SetCaption( pXML->GetAttributeValue( _T("title"), _T("Torrents") ) );
01313         
01314         m_pDocument = new CRichDocument();
01315         
01316         CMapStringToPtr pMap;
01317         if ( ! m_pDocument->LoadXML( pXML, &pMap ) ) return;
01318         
01319         pMap.Lookup( _T("TorrentsNone"), (void*&)m_pdTorrentsNone );
01320         pMap.Lookup( _T("TorrentsOne"), (void*&)m_pdTorrentsOne );
01321         pMap.Lookup( _T("TorrentsMany"), (void*&)m_pdTorrentsMany );
01322         
01323         if ( m_pdTorrentsMany ) m_sTorrentsMany = m_pdTorrentsMany->m_sText;
01324 
01325         pMap.Lookup( _T("ReseedTorrent"), (void*&)m_pdReseedTorrent );
01326         if ( m_pdReseedTorrent ) m_sReseedTorrent = m_pdReseedTorrent->m_sText;
01327 
01328         GetView().SetDocument( m_pDocument );
01329         Update();
01330 }
01331 
01332 void CHomeTorrentsBox::Update()
01333 {
01334         if ( m_pDocument == NULL ) return;
01335         
01336         
01337         // Torrent Count
01338         int nCount = Downloads.GetSeedCount();
01339         
01340         if ( nCount > 1 )
01341         {
01342                 if ( m_pdTorrentsMany )
01343                 {
01344                         CString str;
01345                         str.Format( m_sTorrentsMany, nCount );
01346                         m_pdTorrentsMany->SetText( str );
01347                         m_pdTorrentsMany->Show( TRUE );
01348                 }
01349                 if ( m_pdTorrentsOne ) m_pdTorrentsOne->Show( FALSE );
01350                 if ( m_pdTorrentsNone ) m_pdTorrentsNone->Show( FALSE );
01351         }
01352         else if ( nCount == 1 )
01353         {
01354                 if ( m_pdTorrentsMany ) m_pdTorrentsMany->Show( FALSE );
01355                 if ( m_pdTorrentsOne ) m_pdTorrentsOne->Show( TRUE );
01356                 if ( m_pdTorrentsNone ) m_pdTorrentsNone->Show( FALSE );
01357         }
01358         else
01359         {
01360                 if ( m_pdTorrentsMany ) m_pdTorrentsMany->Show( FALSE );
01361                 if ( m_pdTorrentsOne ) m_pdTorrentsOne->Show( FALSE );
01362                 if ( m_pdTorrentsNone ) m_pdTorrentsNone->Show( TRUE );
01363         }
01364 
01365         // Seed torrent
01366         m_pDocument->ShowGroup( 1, FALSE );
01367         m_pDocument->ShowGroup( 2, TRUE );
01368 
01369         // Re-seed last torrent option
01370         if ( m_pdReseedTorrent )
01371         {
01372                 if ( ( LibraryHistory.LastSeededTorrent.m_sName.IsEmpty() ) ||
01373                          ( LibraryHistory.LastSeededTorrent.m_sPath.IsEmpty() ) ||
01374                          ( Downloads.FindByBTH( &LibraryHistory.LastSeededTorrent.m_pBTH ) != NULL ) )
01375                 {
01376                         // No 'Last seeded' torrent, or it's already seeding
01377                         m_pdReseedTorrent->Show( FALSE );
01378                 }
01379                 else
01380                 {
01381                         // We could re-seed this torrent...
01382                         CString str;
01383                         str.Format( m_sReseedTorrent, LibraryHistory.LastSeededTorrent.m_sName );
01384                         m_pdReseedTorrent->SetText( str );
01385                         m_pdReseedTorrent->Show( TRUE );
01386                         // Change 'seed' to 'seed another'
01387                         m_pDocument->ShowGroup( 1, TRUE );
01388                         m_pDocument->ShowGroup( 2, FALSE );
01389                 }
01390         }
01391         
01392         CRichTaskBox::Update();
01393 }
01394 
01395 

Generated on Thu Dec 15 10:39:35 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2