DownloadFileView.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:7k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // DownloadFileView.cpp : implementation file
- //
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #include "stdafx.h"
- #include "QuickFTP.h"
- #include "DownloadFileView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDownloadFileView
- IMPLEMENT_DYNCREATE(CDownloadFileView, CView)
- CDownloadFileView::CDownloadFileView()
- {
- m_pFileQueueHead = NULL ;
- m_pFileQueue = NULL ;
- }
- CDownloadFileView::~CDownloadFileView()
- {
- }
- BEGIN_MESSAGE_MAP(CDownloadFileView, CView)
- //{{AFX_MSG_MAP(CDownloadFileView)
- ON_WM_SIZE()
- ON_WM_CREATE()
- ON_COMMAND(IDR_QUEUE_RUN, OnQueueRun)
- ON_COMMAND(IDR_QUEUE_STOP, OnQueueStop)
- ON_COMMAND(ID_SELECT_ALL, OnSelectAll)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDownloadFileView drawing
- void CDownloadFileView::OnDraw(CDC* pDC)
- {
- CQuickFTPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDownloadFileView diagnostics
- #ifdef _DEBUG
- void CDownloadFileView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CDownloadFileView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- #endif //_DEBUG
- CQuickFTPDoc* CDownloadFileView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQuickFTPDoc)));
- return (CQuickFTPDoc*)m_pDocument;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDownloadFileView message handlers
- void CDownloadFileView::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
- // TODO: Add your specialized code here and/or call the base class
- }
- BOOL CDownloadFileView::InitList()
- {
- RefreshList( ) ;
- return true ;
- }
- void CDownloadFileView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- RECT rect ;
- if( m_ListCtrl.m_hWnd != NULL )
- {
- GetClientRect( &rect ) ;
- m_ListCtrl.MoveWindow( &rect , true ) ;
- }
- }
- void CDownloadFileView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- // TODO: Add your specialized code here and/or call the base class
- //get document .
- CQuickFTPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- //the file queue change.
- m_pFileQueue = pDoc->m_pFileQueue ;
- }
- /****************************************************
- ** @Description
- ** Refresh the job list.
- **
- ** @Parameter
- ** void
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDownloadFileView::RefreshList()
- {
- //we must delete previous item .
- if( m_ListCtrl.m_hWnd != NULL )
- m_ListCtrl.DeleteAllItems( ) ;
- //if no file queue return .
- if( m_pFileQueue == NULL )
- return true ;
- //if no item ,return
- m_pFileQueueHead = m_pFileQueue->m_pFileTransmitQueue ;
- if( m_pFileQueueHead == NULL )
- return true ;
- // add item .
- FTPFILEINFO* pCur ;
- int iItem = 0 ;
- pCur = m_pFileQueueHead ;
- while( pCur != NULL )
- {
- m_ListCtrl.AddItem( pCur , iItem ) ;
- iItem ++ ;
- pCur = pCur->pNext ;
- }
- return true ;
- }
- LRESULT CDownloadFileView::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
- switch( message )
- {
- case REFRESH_WND_MSG :
- {
- //refresh
- RefreshList( ) ;
- }
- break ;
- case JOBLIST_KEYDOWN_MSG :
- {
- switch( wParam )
- {
- case VK_DELETE :
- //delete item.
- DeleteSelectItem( ) ;
- break ;
- default :
- break ;
- }
- }
- break ;
- case JOBLIST_RBTN_UP_MSG :
- {
- POINT point ;
- //get cursort position.
- GetCursorPos( &point ) ;
- CMenu PopMenu ;
- PopMenu.LoadMenu( IDR_MAINFRAME ) ;
- CMenu *pPopMenu = PopMenu.GetSubMenu( 4 ) ;
- pPopMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON , point.x , point.y , this ) ;
- PopMenu.DestroyMenu() ;
- }
- break ;
- default :
- break ;
- }
- return CView::DefWindowProc(message, wParam, lParam);
- }
- int CDownloadFileView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- RECT rect ;
- GetClientRect( &rect ) ;
- //create list.
- m_ListCtrl.Create( WS_CHILD|WS_VISIBLE|LVS_REPORT,
- rect , this , IDC_DOWNJOBLIST ) ;
- //set full select.
- m_ListCtrl.SetRowFullSelect( ) ;
- m_ListCtrl.SetParentWnd( m_hWnd ) ;
- InitList( ) ;
- return 0;
- }
- /****************************************************
- ** @Description
- ** set transmit file queue .
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDownloadFileView::SetFileQueue(CFileQueue *pQueue)
- {
- m_pFileQueue = pQueue ;
- m_pFileQueue->m_hParentWnd = m_hWnd ;
- RefreshList( ) ;
- return true ;
- }
- /****************************************************
- ** @Description
- ** Delete the select task .
- **
- ** @Parameter
- ** void
- **
- ** @Return: success return true ,else false .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDownloadFileView::DeleteSelectItem()
- {
- FTPFILEINFO FtpFile ;
- UINT iSelectCount = m_ListCtrl.GetSelectedCount( ) ;
- if( iSelectCount <= 0 )
- return true ;
- int iItem = -1 ;
- for( UINT i= 0 ; i < iSelectCount ; i ++ )
- {
- iItem = m_ListCtrl.GetNextItem( iItem , LVNI_SELECTED ) ;
- m_ListCtrl.GetItemInfo( iItem , &FtpFile ) ;
- m_pFileQueue->DeleteItem( &FtpFile ) ;
- }
- RefreshList( ) ;
- return true ;
- }
- /****************************************************
- ** @Description
- ** set select task status .
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDownloadFileView::SetSelectItemStatus(int iState)
- {
- FTPFILEINFO FtpFile ;
- UINT iSelectCount = m_ListCtrl.GetSelectedCount( ) ;
- if( iSelectCount <= 0 )
- return true ;
- int iItem = -1 ;
- for( UINT i= 0 ; i < iSelectCount ; i ++ )
- {
- iItem = m_ListCtrl.GetNextItem( iItem , LVNI_SELECTED ) ;
- m_ListCtrl.GetItemInfo( iItem , &FtpFile ) ;
- //if want stop the item .
- if( iState == FILE_STATE_STOP )
- {
- if( FtpFile.state == FILE_STATE_RUNNING )
- {
- m_pFtp->StopNowCommand( ) ;
- }
- }
- m_pFileQueue->SetItemState( iState , &FtpFile ) ;
- }
- RefreshList( ) ;
- return true ;
- }
- void CDownloadFileView::OnQueueRun()
- {
- // TODO: Add your command handler code here
- SetSelectItemStatus( FILE_STATE_READY ) ;
- m_pFtp->RunJobList( ) ;
- }
- void CDownloadFileView::OnQueueStop()
- {
- // TODO: Add your command handler code here
- m_pFtp->SetStopSign( false ) ;
- SetSelectItemStatus( FILE_STATE_STOP ) ;
- }
- void CDownloadFileView::OnSelectAll()
- {
- // TODO: Add your command handler code here
- m_ListCtrl.SelectAllItem( ) ;
- }