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

WndUploads.cpp

Go to the documentation of this file.
00001 //
00002 // WndUploads.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 "Transfers.h"
00026 #include "Uploads.h"
00027 #include "UploadQueues.h"
00028 #include "UploadQueue.h"
00029 #include "UploadFiles.h"
00030 #include "UploadFile.h"
00031 #include "UploadTransfer.h"
00032 #include "Library.h"
00033 #include "FileExecutor.h"
00034 #include "Security.h"
00035 
00036 #include "Skin.h"
00037 #include "ChatWindows.h"
00038 #include "WindowManager.h"
00039 #include "WndDownloads.h"
00040 #include "WndUploads.h"
00041 #include "WndBrowseHost.h"
00042 #include "DlgSettingsManager.h"
00043 #include "DlgQueueProperties.h"
00044 #include ".\wnduploads.h"
00045 
00046 #include "DlgHelp.h"
00047 #include "LibraryDictionary.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_SERIAL(CUploadsWnd, CPanelWnd, 0)
00056 
00057 BEGIN_MESSAGE_MAP(CUploadsWnd, CPanelWnd)
00058         ON_WM_CREATE()
00059         ON_WM_DESTROY()
00060         ON_WM_SIZE()
00061         ON_WM_TIMER()
00062         ON_WM_CONTEXTMENU()
00063         ON_WM_MDIACTIVATE()
00064         ON_UPDATE_COMMAND_UI(ID_UPLOADS_DISCONNECT, OnUpdateUploadsDisconnect)
00065         ON_COMMAND(ID_UPLOADS_DISCONNECT, OnUploadsDisconnect)
00066         ON_UPDATE_COMMAND_UI(ID_UPLOADS_LAUNCH, OnUpdateUploadsLaunch)
00067         ON_COMMAND(ID_UPLOADS_LAUNCH, OnUploadsLaunch)
00068         ON_UPDATE_COMMAND_UI(ID_UPLOADS_CLEAR, OnUpdateUploadsClear)
00069         ON_COMMAND(ID_UPLOADS_CLEAR, OnUploadsClear)
00070         ON_COMMAND(ID_UPLOADS_CLEAR_COMPLETED, OnUploadsClearCompleted)
00071         ON_UPDATE_COMMAND_UI(ID_UPLOADS_CHAT, OnUpdateUploadsChat)
00072         ON_COMMAND(ID_UPLOADS_CHAT, OnUploadsChat)
00073         ON_UPDATE_COMMAND_UI(ID_UPLOADS_AUTO_CLEAR, OnUpdateUploadsAutoClear)
00074         ON_COMMAND(ID_UPLOADS_AUTO_CLEAR, OnUploadsAutoClear)
00075         ON_UPDATE_COMMAND_UI(ID_SECURITY_BAN, OnUpdateSecurityBan)
00076         ON_COMMAND(ID_SECURITY_BAN, OnSecurityBan)
00077         ON_UPDATE_COMMAND_UI(ID_BROWSE_LAUNCH, OnUpdateBrowseLaunch)
00078         ON_COMMAND(ID_BROWSE_LAUNCH, OnBrowseLaunch)
00079         ON_UPDATE_COMMAND_UI(ID_UPLOADS_START, OnUpdateUploadsStart)
00080         ON_COMMAND(ID_UPLOADS_START, OnUploadsStart)
00081         ON_UPDATE_COMMAND_UI(ID_UPLOADS_EDIT_QUEUE, OnUpdateEditQueue)
00082         ON_COMMAND(ID_UPLOADS_EDIT_QUEUE, OnEditQueue)
00083         ON_COMMAND(ID_UPLOADS_HELP, OnUploadsHelp)
00084         ON_COMMAND(ID_UPLOADS_SETTINGS, OnUploadsSettings)
00085         ON_UPDATE_COMMAND_UI(ID_UPLOADS_FILTER_ALL, OnUpdateUploadsFilterAll)
00086         ON_COMMAND(ID_UPLOADS_FILTER_ALL, OnUploadsFilterAll)
00087         ON_UPDATE_COMMAND_UI(ID_UPLOADS_FILTER_ACTIVE, OnUpdateUploadsFilterActive)
00088         ON_COMMAND(ID_UPLOADS_FILTER_ACTIVE, OnUploadsFilterActive)
00089         ON_UPDATE_COMMAND_UI(ID_UPLOADS_FILTER_QUEUED, OnUpdateUploadsFilterQueued)
00090         ON_COMMAND(ID_UPLOADS_FILTER_QUEUED, OnUploadsFilterQueued)
00091         ON_UPDATE_COMMAND_UI(ID_UPLOADS_FILTER_HISTORY, OnUpdateUploadsFilterHistory)
00092         ON_COMMAND(ID_UPLOADS_FILTER_HISTORY, OnUploadsFilterHistory)
00093         ON_COMMAND(ID_UPLOADS_FILTER_MENU, OnUploadsFilterMenu)
00094         ON_UPDATE_COMMAND_UI(ID_UPLOADS_FILTER_TORRENT, OnUpdateUploadsFilterTorrent)
00095         ON_COMMAND(ID_UPLOADS_FILTER_TORRENT, OnUploadsFilterTorrent)
00096 END_MESSAGE_MAP()
00097 
00098 
00100 // CUploadsWnd construction
00101 
00102 CUploadsWnd::CUploadsWnd() : CPanelWnd( Settings.General.GUIMode == GUI_TABBED, TRUE )
00103 {
00104         Create( IDR_UPLOADSFRAME );
00105 }
00106 
00107 CUploadsWnd::~CUploadsWnd()
00108 {
00109 }
00110 
00112 // CUploadsWnd message handlers
00113 
00114 int CUploadsWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00115 {
00116         if ( CPanelWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00117 
00118         m_wndUploads.Create( this, IDC_UPLOADS );
00119 
00120         if ( ! m_wndToolBar.Create( this, WS_CHILD|WS_VISIBLE|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
00121         m_wndToolBar.SetBarStyle( m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_BORDER_TOP );
00122         m_wndToolBar.SetSyncObject( &Transfers.m_pSection );
00123 
00124         LoadState( NULL, TRUE );
00125 
00126         SetTimer( 2, 2000, NULL );
00127         PostMessage( WM_TIMER, 2 );
00128 
00129         SetTimer( 4, 5000, NULL );
00130         PostMessage( WM_TIMER, 4 );
00131 
00132         m_tSel                  = 0;
00133         m_tLastUpdate   = 0;
00134 
00135         return 0;
00136 }
00137 
00138 void CUploadsWnd::OnDestroy()
00139 {
00140         KillTimer( 4 );
00141         SaveState();
00142         CPanelWnd::OnDestroy();
00143 }
00144 
00145 BOOL CUploadsWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
00146 {
00147         if ( m_wndToolBar.m_hWnd )
00148         {
00149                 if ( m_wndToolBar.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00150         }
00151 
00152         return CPanelWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00153 }
00154 
00155 void CUploadsWnd::OnSize(UINT nType, int cx, int cy)
00156 {
00157         CPanelWnd::OnSize( nType, cx, cy );
00158         SizeListAndBar( &m_wndUploads, &m_wndToolBar );
00159 }
00160 
00161 void CUploadsWnd::OnSkinChange()
00162 {
00163         CPanelWnd::OnSkinChange();
00164         Skin.Translate( _T("CUploadCtrl"), &m_wndUploads.m_wndHeader);
00165         Skin.CreateToolBar( _T("CUploadsWnd"), &m_wndToolBar );
00166 }
00167 
00168 void CUploadsWnd::OnTimer(UINT nIDEvent)
00169 {
00170         // Reset Selection Timer event (posted by ctrluploads)
00171         if ( nIDEvent == 5 ) m_tSel     = 0;
00172 
00173         // Clear event (5 second timer)
00174         if ( nIDEvent == 4 )
00175         {
00176                 CSingleLock pLock( &Transfers.m_pSection );
00177                 if ( ! pLock.Lock( 10 ) ) return;
00178 
00179                 DWORD tNow = GetTickCount();
00180                 BOOL bCull = Uploads.GetCount( NULL ) > 75;
00181 
00182                 for ( POSITION pos = Uploads.GetIterator() ; pos ; )
00183                 {
00184                         CUploadTransfer* pUpload = Uploads.GetNext( pos );
00185 
00186                         if ( pUpload->m_nState == upsNull &&
00187                                  tNow - pUpload->m_tConnected > Settings.Uploads.ClearDelay )
00188                         {
00189                                 if ( Settings.Uploads.AutoClear || pUpload->m_nUploaded == 0 || bCull )
00190                                 {
00191                                         pUpload->Remove( FALSE );
00192                                 }
00193                         }
00194                 }
00195         }
00196 
00197         // Update event (2 second timer)
00198         if ( nIDEvent == 2 )
00199         {
00200                 DWORD tNow = GetTickCount();
00201 
00202                 // If the window is visible or hasn't been updated in 10 seconds
00203                 if ( ( IsWindowVisible() && IsActive( FALSE ) ) || ( ( tNow - m_tLastUpdate ) > 10*1000 ) )
00204                 {
00205                         m_wndUploads.Update();
00206                         m_tLastUpdate = tNow;
00207                 }
00208         }
00209 }
00210 
00211 void CUploadsWnd::OnContextMenu(CWnd* pWnd, CPoint point)
00212 {
00213         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00214         CUploadQueue* pQueue;
00215         CUploadFile* pUpload;
00216 
00217         CPoint ptLocal( point );
00218         m_wndUploads.ScreenToClient( &ptLocal );
00219         m_tSel = 0;
00220 
00221         if ( m_wndUploads.HitTest( ptLocal, &pQueue, &pUpload, NULL, NULL ) )
00222         {
00223                 if ( pUpload != NULL )
00224                 {
00225                         pLock.Unlock();
00226                         TrackPopupMenu( _T("CUploadsWnd.Upload"), point, ID_UPLOADS_LAUNCH );
00227                         return;
00228                 }
00229         }
00230 
00231         if( ( pQueue == NULL ) || ( Settings.General.GUIMode == GUI_BASIC ) ||          //If we're not pointing at a queue, or in basic mode
00232                 ( pQueue == UploadQueues.m_pHistoryQueue ) || ( pQueue == UploadQueues.m_pTorrentQueue ) )      //Or pointing at a pre-defined queue
00233                 TrackPopupMenu( _T("CUploadsWnd.Nothing"), point, ID_UPLOADS_HELP );
00234         else
00235                 TrackPopupMenu( _T("CUploadsWnd.Queue"), point, ID_UPLOADS_EDIT_QUEUE );
00236 
00237         pLock.Unlock();
00238 }
00239 
00240 void CUploadsWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
00241 {
00242         CPanelWnd::OnMDIActivate( bActivate, pActivateWnd, pDeactivateWnd );
00243         if ( bActivate ) m_wndUploads.SetFocus();
00244 }
00245 
00246 BOOL CUploadsWnd::IsSelected(CUploadFile* pFile)
00247 {
00248         if ( ! pFile->m_bSelected ) return FALSE;
00249 
00250         if ( CUploadTransfer* pTransfer = pFile->GetActive() )
00251         {
00252                 if ( pTransfer->m_nProtocol == PROTOCOL_BT )
00253                 {
00254                         if ( 0 == ( Settings.Uploads.FilterMask & ULF_TORRENT ) ) return FALSE;
00255                 }
00256                 else if ( pTransfer->m_pQueue != NULL )
00257                 {
00258                         if ( pTransfer->m_pQueue->m_bExpanded == FALSE ) return FALSE;
00259 
00260                         if ( pTransfer->m_pQueue->m_pActive.Find( pTransfer ) != NULL )
00261                         {
00262                                 if ( 0 == ( Settings.Uploads.FilterMask & ULF_ACTIVE ) ) return FALSE;
00263                         }
00264                         else
00265                         {
00266                                 if ( 0 == ( Settings.Uploads.FilterMask & ULF_QUEUED ) ) return FALSE;
00267                         }
00268                 }
00269                 else
00270                 {
00271                         if ( 0 == ( Settings.Uploads.FilterMask & ULF_HISTORY ) ) return FALSE;
00272                 }
00273         }
00274         else
00275         {
00276                 if ( 0 == ( Settings.Uploads.FilterMask & ULF_HISTORY ) ) return FALSE;
00277         }
00278 
00279         return TRUE;
00280 }
00281 
00282 void CUploadsWnd::Prepare()
00283 {
00284         DWORD tNow = GetTickCount();
00285         if ( tNow - m_tSel < 250 ) return;
00286         m_tSel = tNow;
00287 
00288         m_bSelFile = m_bSelUpload = FALSE;
00289         m_bSelActive = m_bSelQueued = FALSE;
00290         m_bSelHttp = m_bSelDonkey = FALSE;
00291         m_bSelSourceAcceptConnections = m_bSelSourceExtended = FALSE;
00292 
00293         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00294 
00295         for ( POSITION posFile = UploadFiles.GetIterator() ; posFile ; )
00296         {
00297                 CUploadFile* pFile = UploadFiles.GetNext( posFile );
00298 
00299                 if ( pFile->m_bSelected && IsSelected( pFile ) )
00300                 {
00301                         m_bSelFile = TRUE;
00302 
00303                         if ( CUploadTransfer* pTransfer = pFile->GetActive() )
00304                         {
00305                                 m_bSelUpload = TRUE;
00306                                 if ( pTransfer->m_nProtocol == PROTOCOL_HTTP ) m_bSelHttp = TRUE;
00307                                 if ( pTransfer->m_nProtocol == PROTOCOL_ED2K ) m_bSelDonkey = TRUE;
00308 
00309                                 if ( pTransfer->m_pQueue != NULL )
00310                                 {
00311                                         if ( pTransfer->m_pQueue->m_pActive.Find( pTransfer ) != NULL )
00312                                                 m_bSelActive = TRUE;
00313                                         else
00314                                                 m_bSelQueued = TRUE;
00315                                 }
00316                                 else if ( pTransfer->m_nState != upsNull )
00317                                 {
00318                                         m_bSelActive = TRUE;
00319                                 }
00320 
00321                                 if ( pTransfer->m_bClientExtended )
00322                                         m_bSelSourceExtended = TRUE;
00323 
00324                                 //m_bSelSourceAcceptConnections = pTransfer->
00325 
00326                         }
00327                 }
00328         }
00329 }
00330 
00332 // CUploadsWnd command handlers
00333 
00334 void CUploadsWnd::OnUpdateUploadsDisconnect(CCmdUI* pCmdUI)
00335 {
00336         Prepare();
00337         pCmdUI->Enable( m_bSelActive );
00338 }
00339 
00340 void CUploadsWnd::OnUploadsDisconnect()
00341 {
00342         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00343         CList<CUploadFile*> pList;
00344 
00345         for ( POSITION pos = UploadFiles.GetIterator() ; pos ; )
00346         {
00347                 CUploadFile* pFile = UploadFiles.GetNext( pos );
00348                 if ( IsSelected( pFile ) ) pList.AddTail( pFile );
00349         }
00350 
00351         while ( ! pList.IsEmpty() )
00352         {
00353                 CUploadFile* pFile = pList.RemoveHead();
00354 
00355                 if ( UploadFiles.Check( pFile ) && pFile->GetActive() != NULL )
00356                 {
00357                         CUploadTransfer* pUpload = pFile->GetActive();
00358 
00359                         if ( pUpload->m_nProtocol == PROTOCOL_ED2K && pUpload->m_nState != upsNull )
00360                         {
00361                                 CString strFormat, strMessage;
00362                                 LoadString( strFormat, IDS_UPLOAD_CANCEL_ED2K );
00363                                 strMessage.Format( strFormat, (LPCTSTR)pUpload->m_sFileName );
00364                                 pLock.Unlock();
00365                                 UINT nResp = AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON2 );
00366                                 pLock.Lock();
00367                                 if ( nResp == IDCANCEL ) break;
00368                                 if ( nResp != IDYES || ! Uploads.Check( pUpload ) ) continue;
00369                         }
00370 
00371                         pUpload->Close( TRUE );
00372                 }
00373         }
00374 }
00375 
00376 void CUploadsWnd::OnUpdateUploadsStart(CCmdUI* pCmdUI)
00377 {
00378         Prepare();
00379         pCmdUI->Enable( m_bSelQueued );
00380 }
00381 
00382 void CUploadsWnd::OnUploadsStart()
00383 {
00384         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00385 
00386         for ( POSITION pos = UploadFiles.GetIterator() ; pos ; )
00387         {
00388                 CUploadFile* pFile = UploadFiles.GetNext( pos );
00389 
00390                 if ( IsSelected( pFile ) && pFile->GetActive() != NULL )
00391                 {
00392                         pFile->GetActive()->Promote();
00393                 }
00394         }
00395 }
00396 
00397 void CUploadsWnd::OnUpdateUploadsClear(CCmdUI* pCmdUI)
00398 {
00399         Prepare();
00400         pCmdUI->Enable( m_bSelFile );
00401 }
00402 
00403 void CUploadsWnd::OnUploadsClear()
00404 {
00405         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00406         CList<CUploadFile*> pList;
00407 
00408         for ( POSITION pos = UploadFiles.GetIterator() ; pos ; )
00409         {
00410                 CUploadFile* pFile = UploadFiles.GetNext( pos );
00411                 if ( IsSelected( pFile ) ) pList.AddTail( pFile );
00412         }
00413 
00414         while ( ! pList.IsEmpty() )
00415         {
00416                 CUploadFile* pFile = pList.RemoveHead();
00417 
00418                 if ( UploadFiles.Check( pFile ) )
00419                 {
00420                         CUploadTransfer* pUpload = pFile->GetActive();
00421 
00422                         if ( pUpload != NULL && pUpload->m_nProtocol == PROTOCOL_ED2K && pUpload->m_nState != upsNull )
00423                         {
00424                                 CString strFormat, strMessage;
00425                                 LoadString( strFormat, IDS_UPLOAD_CANCEL_ED2K );
00426                                 strMessage.Format( strFormat, (LPCTSTR)pUpload->m_sFileName );
00427                                 pLock.Unlock();
00428                                 UINT nResp = AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON2 );
00429                                 pLock.Lock();
00430                                 if ( nResp == IDCANCEL ) break;
00431                                 if ( nResp != IDYES || ! UploadFiles.Check( pFile ) ) continue;
00432                         }
00433 
00434                         pFile->Remove();
00435                 }
00436         }
00437 }
00438 
00439 void CUploadsWnd::OnUpdateUploadsLaunch(CCmdUI* pCmdUI)
00440 {
00441         Prepare();
00442         pCmdUI->Enable( m_bSelFile );
00443 }
00444 
00445 void CUploadsWnd::OnUploadsLaunch()
00446 {
00447         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00448         CList<CUploadFile*> pList;
00449 
00450         for ( POSITION pos = UploadFiles.GetIterator() ; pos ; )
00451         {
00452                 CUploadFile* pFile = UploadFiles.GetNext( pos );
00453                 if ( IsSelected( pFile ) ) pList.AddTail( pFile );
00454         }
00455 
00456         while ( ! pList.IsEmpty() )
00457         {
00458                 CUploadFile* pFile = pList.RemoveHead();
00459 
00460                 if ( UploadFiles.Check( pFile ) )
00461                 {
00462                         CString strPath = pFile->m_sPath;
00463 
00464                         pLock.Unlock();
00465                         if ( ! CFileExecutor::Execute( strPath ) ) break;
00466                         pLock.Lock();
00467                 }
00468         }
00469 }
00470 
00471 void CUploadsWnd::OnUpdateUploadsChat(CCmdUI* pCmdUI)
00472 {
00473         // If chat is disabled, grey out the option
00474         if ( ! Settings.Community.ChatEnable )
00475         {
00476                 pCmdUI->Enable( FALSE );
00477                 return;
00478         }
00479 
00480         // Check to see if chat is possible
00481         Prepare();
00482         pCmdUI->Enable( m_bSelHttp ||                                                                   // Enable chat for HTTP clients
00483                 ( m_bSelDonkey && Settings.Community.ChatAllNetworks ) ||       // ED2K clients,
00484                 ( m_bSelSourceExtended ) );                                                                     // or for any client supporting G2 chat
00485 }
00486 
00487 void CUploadsWnd::OnUploadsChat()
00488 {
00489         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00490 
00491         for ( POSITION pos = UploadFiles.GetIterator() ; pos ; )
00492         {
00493                 CUploadFile* pFile = UploadFiles.GetNext( pos );
00494 
00495                 if ( IsSelected( pFile ) && pFile->GetActive() != NULL )
00496                 {
00497                         if ( pFile->GetActive()->m_nProtocol == PROTOCOL_HTTP )         // HTTP chat. (G2, G1)
00498                                 ChatWindows.OpenPrivate( NULL, &pFile->GetActive()->m_pHost, FALSE, PROTOCOL_HTTP );
00499                         else if ( pFile->GetActive()->m_bClientExtended )                       // Client accepts G2 chat
00500                                 ChatWindows.OpenPrivate( NULL, &pFile->GetActive()->m_pHost, FALSE, PROTOCOL_G2 );
00501                         else if ( pFile->GetActive()->m_nProtocol == PROTOCOL_ED2K )// ED2K chat.
00502                                 ChatWindows.OpenPrivate( NULL, &pFile->GetActive()->m_pHost, FALSE, PROTOCOL_ED2K );
00503                         else            // Should never be called
00504                                 theApp.Message( MSG_ERROR, _T("Error while initiating chat- Unable to select protocol") );
00505                 }
00506         }
00507 }
00508 
00509 void CUploadsWnd::OnUpdateSecurityBan(CCmdUI* pCmdUI)
00510 {
00511         Prepare();
00512         pCmdUI->Enable( m_bSelUpload );
00513 }
00514 
00515 void CUploadsWnd::OnSecurityBan()
00516 {
00517         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00518         CList<CUploadFile*> pList;
00519 
00520         for ( POSITION pos = UploadFiles.GetIterator() ; pos ; )
00521         {
00522                 CUploadFile* pFile = UploadFiles.GetNext( pos );
00523                 if ( IsSelected( pFile ) ) pList.AddTail( pFile );
00524         }
00525 
00526         while ( ! pList.IsEmpty() )
00527         {
00528                 CUploadFile* pFile = pList.RemoveHead();
00529 
00530                 if ( UploadFiles.Check( pFile ) && pFile->GetActive() != NULL )
00531                 {
00532                         CUploadTransfer* pUpload = pFile->GetActive();
00533 
00534                         IN_ADDR pAddress = pUpload->m_pHost.sin_addr;
00535                         pUpload->Remove( FALSE );
00536                         pLock.Unlock();
00537                         Security.Ban( &pAddress, banSession );
00538                         pLock.Lock();
00539                 }
00540         }
00541 }
00542 
00543 void CUploadsWnd::OnUpdateBrowseLaunch(CCmdUI* pCmdUI)
00544 {
00545         Prepare();
00546         pCmdUI->Enable( ( m_bSelHttp || m_bSelSourceExtended ) );
00547 }
00548 
00549 void CUploadsWnd::OnBrowseLaunch()
00550 {
00551         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00552         CList<CUploadFile*> pList;
00553 
00554         for ( POSITION pos = UploadFiles.GetIterator() ; pos ; )
00555         {
00556                 CUploadFile* pFile = UploadFiles.GetNext( pos );
00557                 if ( IsSelected( pFile ) ) pList.AddTail( pFile );
00558         }
00559 
00560         while ( ! pList.IsEmpty() )
00561         {
00562                 CUploadFile* pFile = pList.RemoveHead();
00563 
00564                 if ( UploadFiles.Check( pFile ) && pFile->GetActive() != NULL )
00565                 {
00566                         SOCKADDR_IN pAddress = pFile->GetActive()->m_pHost;
00567                         pLock.Unlock();
00568                         new CBrowseHostWnd( &pAddress );
00569                         pLock.Lock();
00570                 }
00571         }
00572 }
00573 
00574 void CUploadsWnd::OnUploadsClearCompleted()
00575 {
00576         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00577 
00578         for ( POSITION pos = Uploads.GetIterator() ; pos ; )
00579         {
00580                 CUploadTransfer* pUpload = Uploads.GetNext( pos );
00581                 if ( pUpload->m_nState == upsNull ) pUpload->Remove( FALSE );
00582         }
00583 
00584         m_wndUploads.Update();
00585 }
00586 
00587 void CUploadsWnd::OnUpdateUploadsAutoClear(CCmdUI* pCmdUI)
00588 {
00589         pCmdUI->SetCheck( Settings.Uploads.AutoClear );
00590 }
00591 
00592 void CUploadsWnd::OnUploadsAutoClear()
00593 {
00594         Settings.Uploads.AutoClear = ! Settings.Uploads.AutoClear;
00595         if ( Settings.Uploads.AutoClear ) OnTimer( 4 );
00596 }
00597 
00598 void CUploadsWnd::OnUpdateEditQueue(CCmdUI* pCmdUI)
00599 {
00600         Prepare();
00601         pCmdUI->Enable( ! m_bSelFile );
00602 }
00603 
00604 void CUploadsWnd::OnEditQueue()
00605 {
00606         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00607 
00608         for ( POSITION pos = UploadQueues.GetIterator() ; pos ; )
00609         {
00610                 CUploadQueue* pQueue = UploadQueues.GetNext( pos );
00611 
00612                 if ( pQueue->m_bSelected )
00613                 {
00614                         CSettingsManagerDlg::Run( _T("CUploadsSettingsPage") );
00615                         return;
00616                 }
00617         }
00618 
00619 }
00620 
00621 void CUploadsWnd::OnUploadsHelp()
00622 {
00623         CHelpDlg::Show( _T("UploadHelp") );
00624 }
00625 
00626 void CUploadsWnd::OnUploadsSettings()
00627 {
00628         CSettingsManagerDlg::Run( _T("CUploadsSettingsPage") );
00629 }
00630 
00631 BOOL CUploadsWnd::PreTranslateMessage(MSG* pMsg)
00632 {
00633         if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_DELETE )
00634         {
00635                 OnUploadsClear();
00636                 return TRUE;
00637         }
00638         else if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB )
00639         {
00640                 GetManager()->Open( RUNTIME_CLASS(CDownloadsWnd) );
00641                 return TRUE;
00642         }
00643 
00644         return CPanelWnd::PreTranslateMessage( pMsg );
00645 }
00646 
00647 void CUploadsWnd::OnUploadsFilterMenu()
00648 {
00649         CMenu* pMenu = Skin.GetMenu( _T("CUploadsWnd.Filter") );
00650         m_wndToolBar.ThrowMenu( ID_UPLOADS_FILTER_MENU, pMenu, NULL, FALSE, TRUE );
00651 }
00652 
00653 void CUploadsWnd::OnUpdateUploadsFilterAll(CCmdUI* pCmdUI)
00654 {
00655         pCmdUI->SetCheck( ( Settings.Uploads.FilterMask & ULF_ALL ) == ULF_ALL );
00656 }
00657 
00658 void CUploadsWnd::OnUploadsFilterAll()
00659 {
00660         Settings.Uploads.FilterMask |= ULF_ALL;
00661         m_wndUploads.Update();
00662 }
00663 
00664 void CUploadsWnd::OnUpdateUploadsFilterActive(CCmdUI* pCmdUI)
00665 {
00666         pCmdUI->SetCheck( ( Settings.Uploads.FilterMask & ULF_ACTIVE ) > 0 );
00667 }
00668 
00669 void CUploadsWnd::OnUploadsFilterActive()
00670 {
00671         Settings.Uploads.FilterMask ^= ULF_ACTIVE;
00672         m_wndUploads.Update();
00673 }
00674 
00675 void CUploadsWnd::OnUpdateUploadsFilterQueued(CCmdUI* pCmdUI)
00676 {
00677         pCmdUI->SetCheck( ( Settings.Uploads.FilterMask & ULF_QUEUED ) > 0 );
00678 }
00679 
00680 void CUploadsWnd::OnUploadsFilterQueued()
00681 {
00682         Settings.Uploads.FilterMask ^= ULF_QUEUED;
00683         m_wndUploads.Update();
00684 }
00685 
00686 void CUploadsWnd::OnUpdateUploadsFilterHistory(CCmdUI* pCmdUI)
00687 {
00688         pCmdUI->SetCheck( ( Settings.Uploads.FilterMask & ULF_HISTORY ) > 0 );
00689 }
00690 
00691 void CUploadsWnd::OnUploadsFilterHistory()
00692 {
00693         Settings.Uploads.FilterMask ^= ULF_HISTORY;
00694         m_wndUploads.Update();
00695 }
00696 
00697 void CUploadsWnd::OnUpdateUploadsFilterTorrent(CCmdUI *pCmdUI)
00698 {
00699         pCmdUI->SetCheck( ( Settings.Uploads.FilterMask & ULF_TORRENT ) > 0 );
00700 }
00701 
00702 void CUploadsWnd::OnUploadsFilterTorrent()
00703 {
00704         Settings.Uploads.FilterMask ^= ULF_TORRENT;
00705         m_wndUploads.Update();
00706 }

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