⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queuectrl.cpp

📁 一个支持FTP,SFTP的客户端程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		}
		if (nIndex == m_nActiveCount)
		{
			pPopup->EnableMenuItem(ID_QUEUECONTEXT_MOVEUP, MF_GRAYED);
		}
			
		if (!iter->priority)
			pPopup->EnableMenuItem(ID_QUEUECONTEXT_PAUSE, MF_GRAYED);
		
		if (!iter->bPaused)
			pPopup->EnableMenuItem(ID_QUEUECONTEXT_RESUME, MF_GRAYED);
		
		if (iter->priority || iter->bPaused)
			pPopup->EnableMenuItem(ID_QUEUECONTEXT_RESETSTATUS, MF_GRAYED);
		
		if (iter->priority==1 && nIndex == FindValidIndex(2)-m_QueueItems.begin())
		{
			pPopup->EnableMenuItem(ID_QUEUECONTEXT_MOVEUP, MF_GRAYED);
		}
		if (iter->priority==2 && nIndex == (FindValidIndex(2)-m_QueueItems.begin()-1))
		{
			pPopup->EnableMenuItem(ID_QUEUECONTEXT_MOVEDOWN, MF_GRAYED);
		}
	}

	if (!selected)
	{
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_PROCESSQUEUE, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_REMOVEFROMQUEUE, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_MOVETOTOP, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_MOVETOBOTTOM, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_MOVEUP, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_MOVEDOWN, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_RESETSTATUS, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_PAUSE, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_RESUME, MF_GRAYED);
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_ABORT, MF_GRAYED);
	}
	else
		if (FindValidIndex(1) == m_QueueItems.begin())
			pPopup->EnableMenuItem(ID_QUEUECONTEXT_PROCESSQUEUE, MF_GRAYED);

	if (DoProcessQueue()==1 || m_QueueItems.empty())
		pPopup->EnableMenuItem(ID_QUEUECONTEXT_PROCESSQUEUE, MF_GRAYED);
	
	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
		pWndPopupOwner);
}

void CQueueCtrl::OnQueuecontextMovedown() 
{
	std::list<int> list;
	for (t_QueueVector::iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
	{
		if (!(iter->nListItemState & LVIS_SELECTED))
			continue;

		int nIndex = iter - m_QueueItems.begin();

		if (iter->bActive)
			continue;
		if (iter->priority==1 && nIndex>=(FindValidIndex(1) - m_QueueItems.begin() - 1))
			continue;
		if (iter->priority==2 && nIndex>=(FindValidIndex(2) - m_QueueItems.begin() - 1))
			continue;
		if (nIndex >= FindValidIndex(1) - m_QueueItems.begin())
			continue;
		list.push_front(nIndex);
	}
	for (std::list<int>::iterator listiter = list.begin(); listiter != list.end(); listiter++)
	{
		CQueueData data = m_QueueItems[*listiter];
		m_QueueItems[*listiter] = m_QueueItems[*listiter + 1];
		m_QueueItems[*listiter + 1] = data;
	}
	RedrawItems(0, GetItemCount() - 1);
}

void CQueueCtrl::OnQueuecontextMovetobottom() 
{
	std::list<int> list;
	for (t_QueueVector::iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
	{
		if (!(iter->nListItemState & LVIS_SELECTED))
			continue;

		int nIndex = iter - m_QueueItems.begin();
	
		if (iter->bActive)
			continue;
		if (nIndex >= FindValidIndex(1) - m_QueueItems.begin())
			continue;
		list.push_front(nIndex);
	}
	int offset2=0;
	int offset=0;
	for (std::list<int>::iterator listiter=list.begin(); listiter!=list.end(); listiter++)
	{
		CQueueData data = m_QueueItems[*listiter];
		m_QueueItems.erase(m_QueueItems.begin() + *listiter);

		if (data.priority==1)
			m_QueueItems.insert(FindValidIndex(1) - offset++, data);
		else
			m_QueueItems.insert(FindValidIndex(2) - offset2++, data);
	}
	SetItemCount(m_QueueItems.size() + m_nActiveCount);
}

void CQueueCtrl::OnQueuecontextMovetotop() 
{
	std::list<int> list;
	for (t_QueueVector::iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
	{
		if (!(iter->nListItemState & LVIS_SELECTED))
			continue;

		int nIndex = iter - m_QueueItems.begin();

		if (iter->bActive)
			continue;
		if (nIndex >= FindValidIndex(1) - m_QueueItems.begin())
			continue;
		list.push_back(nIndex);
	}

	int offset = FindValidIndex(2) - m_QueueItems.begin();
	int offset2 = m_nActiveCount;
	for (std::list<int>::iterator listiter=list.begin(); listiter!=list.end(); listiter++)
	{
		CQueueData data = m_QueueItems[*listiter];
		m_QueueItems.erase(m_QueueItems.begin() + *listiter);

		if (data.priority==1)
			m_QueueItems.insert(m_QueueItems.begin() + offset++, data);
		else
			m_QueueItems.insert(m_QueueItems.begin() + offset2++, data);
	}
	SetItemCount(m_QueueItems.size() + m_nActiveCount);
}

void CQueueCtrl::OnQueuecontextMoveup() 
{
	std::list<int> list;
	for (t_QueueVector::iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
	{
		if (!(iter->nListItemState & LVIS_SELECTED))
			continue;

		int nIndex = iter - m_QueueItems.begin();
	
		if (iter->bActive)
			continue;
		if (nIndex <= m_nActiveCount)
			continue;
		if (iter->priority == 1 && nIndex == FindValidIndex(2) - m_QueueItems.begin())
			continue;
		if (nIndex >= FindValidIndex(1) - m_QueueItems.begin())
			continue;
		if (nIndex == 1)
			m_bMayUsePrimaryConnection = FALSE;
		list.push_back(nIndex);		
	}
	for (std::list<int>::iterator listiter = list.begin(); listiter != list.end(); listiter++)
	{
		CQueueData data = m_QueueItems[*listiter];
		m_QueueItems[*listiter] = m_QueueItems[*listiter - 1];
		m_QueueItems[*listiter - 1] = data;
	}
	SetItemCount(m_QueueItems.size() + m_nActiveCount);
}

void CQueueCtrl::OnQueuecontextProcessqueue() 
{
	CMainFrame *pMainFrame = DYNAMIC_DOWNCAST(CMainFrame, GetParentFrame());
	pMainFrame->TransferQueue(1);
}

void CQueueCtrl::OnQueuecontextRemovefromqueue() 
{
	std::list<int> list;
	for (t_QueueVector::iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
	{
		if (!(iter->nListItemState & LVIS_SELECTED))
			continue;
		
		if (iter == m_QueueItems.begin())
			m_bMayUsePrimaryConnection = FALSE;

		if (iter->bActive)
			continue;
		
		list.push_front(iter - m_QueueItems.begin());
	}
	for (std::list<int>::iterator listiter=list.begin(); listiter!=list.end(); listiter++)
		m_QueueItems.erase(m_QueueItems.begin() + *listiter);

	SetItemCount(m_QueueItems.size() + m_nActiveCount);

	UpdateStatusbar();
}

t_QueueVector::iterator CQueueCtrl::FindValidIndex(int type)
{
	t_QueueVector::iterator iter = m_QueueItems.end();
	
	if (type == 1)
	{
		for (iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
			if (iter->priority == 0)
				break;
	}
	else if (type == 2)
		for (iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
			if (!iter->bActive && iter->priority != 2)
				break;
	return iter;
}

t_QueueVector::const_iterator CQueueCtrl::FindValidIndex(int type) const
{
	t_QueueVector::const_iterator iter = m_QueueItems.end();
	
	if (type == 1)
		for (iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
			if (iter->priority == 0)
				break;
	else if (type == 2)
		for (iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
			if (!iter->bActive)
				break;
	return iter;
}

void CQueueCtrl::OnQueuecontextResetstatus() 
{
	std::list<int> list;
	std::list<CQueueData> list2;
	for (t_QueueVector::iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
	{
		if (!(iter->nListItemState & LVIS_SELECTED))
			continue;
		
		int nIndex = iter - m_QueueItems.begin();
	
		if (iter->priority || iter->bPaused)
			continue;
		list.push_front(nIndex);
		list2.push_front(m_QueueItems[nIndex]);
	}
	for (std::list<int>::iterator listiter=list.begin(); listiter!=list.end(); listiter++)
		m_QueueItems.erase(m_QueueItems.begin() + *listiter);
	for (std::list<CQueueData>::iterator iter2=list2.begin(); iter2!=list2.end(); iter2++)
	{
		iter2->action = "";
		iter2->retrycount = 0;
		iter2->bTransferStarted = FALSE;
		iter2->bTriedAutoResume = false;
		AddItem(*iter2);
	}
	UpdateStatusbar();
}

#define VK_A 65
void CQueueCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (nChar==46)
		OnQueuecontextRemovefromqueue();
	else if(GetKeyState( VK_CONTROL )&128 && nChar == VK_A )
	{
		for (t_QueueVector::iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
			iter->nListItemState = LVIS_SELECTED;
		RedrawItems(0, GetItemCount() - 1);
		return;
	}
			
	
	CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CQueueCtrl::ReloadHeader()
{
	ReloadHeaderItem(0, IDS_HEADER_LOCALNAME);
	ReloadHeaderItem(1, IDS_HEADER_SIZE);
	ReloadHeaderItem(2, IDS_HEADER_DIRECTION);
	ReloadHeaderItem(3, IDS_HEADER_REMOTENAME);
	ReloadHeaderItem(4, IDS_HEADER_HOST);
	ReloadHeaderItem(5, IDS_HEADER_STATUS);
}

void CQueueCtrl::ReloadHeaderItem(int nIndex, UINT nID)
{
	CHeaderCtrl *header = GetHeaderCtrl();
	TCHAR text[100];
	HDITEM item;
	memset(&item, 0, sizeof(HDITEM));
	item.cchTextMax = 100;
	item.mask = HDI_TEXT;
	item.pszText = text;
	header->GetItem(nIndex, &item);
	CString str;
	str.LoadString(nID);
	_tcscpy(text, str);
	header->SetItem(nIndex, &item);
}

void CQueueCtrl::OnDropFiles(HDROP hDropInfo) 
{
	//End of a file drag&drop operation
	m_bMayUsePrimaryConnection=FALSE;
	CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
	if (!((CFtpListCtrl *)pMainFrame->GetFtpPane()->GetListCtrl())->GetItemCount())
	{
		DragFinish(hDropInfo);
		return;
	}
	int dropcount = DragQueryFile(hDropInfo, 0xFFFFFFFF, 0, 0);
	for (int i = 0; i < dropcount; i++)
	{
		int len = DragQueryFile(hDropInfo, i, 0, 0) + 1;
		LPTSTR name = new TCHAR[len + 1];
		DragQueryFile(hDropInfo, i, name, len);
		CFileStatus64 status;
		GetStatus64(name, status);
		CString name2 = name;
		if (status.m_attribute&0x10)
		{
			CString filename = name;
			if (filename.ReverseFind('\\')!=-1)
				filename=filename.Right(filename.GetLength()-filename.ReverseFind('\\')-1);
			pMainFrame->UploadDir(name2 + "\\*.*", filename + "\\", FALSE);
		}
		else
		{
			ASSERT(name2.ReverseFind('\\') != -1);
			CString filename=name2.Mid(name2.ReverseFind('\\')+1);
			CString path=name2.Left(name2.ReverseFind('\\'));
			pMainFrame->AddQueueItem(FALSE,filename,"",path,CServerPath(),FALSE);
		}
		delete [] name;
	}
	DragFinish(hDropInfo);
}

int CQueueCtrl::DoProcessQueue() const
{	
	return m_nProcessQueue;
}

void CQueueCtrl::UpdateStatusbar()
{
	BOOL bUnknown=FALSE;
	__int64 size=0;
	for (t_QueueVector::const_iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
	{
		if (iter->priority || iter->bPaused)
			if (iter->transferFile.size >= 0)
				size += iter->transferFile.size;
			else
				bUnknown = TRUE;
	}

	CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
	CString str;
	CString tmp;
	CString sizestr;
	if (size<(1024*10))
	{
		sizestr.LoadString(IDS_SIZE_BYTES);
		str.Format(ID_INDICATOR_QUEUESIZE,size,sizestr+(bUnknown?"+":""));
	}
	else if (size<(1024*1024*10))
	{
		sizestr.LoadString(IDS_SIZE_KBS);
		str.Format(ID_INDICATOR_QUEUESIZE,size/1024,sizestr+(bUnknown?"+":""));
	}
	else
	{
		sizestr.LoadString(IDS_SIZE_MBS);
		str.Format(ID_INDICATOR_QUEUESIZE,size/1024/1024,sizestr+(bUnknown?"+":""));
	}
	if (!pMainFrame || !pMainFrame->m_wndStatusBar.GetSafeHwnd())
		return;
	int res=pMainFrame->m_wndStatusBar.CommandToIndex(ID_INDICATOR_QUEUESIZE);
	pMainFrame->m_wndStatusBar.GetStatusBarCtrl().SetText(str,pMainFrame->m_wndStatusBar.CommandToIndex(ID_INDICATOR_QUEUESIZE),0);

	HFONT hFont = (HFONT)pMainFrame->m_wndStatusBar.SendMessage(WM_GETFONT);
	CClientDC dcScreen(NULL);
	HGDIOBJ hOldFont = NULL;
	if (hFont != NULL)
		hOldFont = dcScreen.SelectObject(hFont);
	int cx=dcScreen.GetTextExtent(str).cx;
	pMainFrame->m_wndStatusBar.SetPaneInfo(pMainFrame->m_wndStatusBar.CommandToIndex(ID_INDICATOR_QUEUESIZE),ID_INDICATOR_QUEUESIZE,SBPS_NORMAL,cx);
	if (hOldFont != NULL)
		dcScreen.SelectObject(hOldFont);
}

void CQueueCtrl::TransferQueue(int nPriority)
{
	if (nPriority<1 || nPriority>2)
		return;
	if (FindValidIndex(1) == m_QueueItems.begin())
		return;
	int nOldProcessQueue = m_nProcessQueue;
	if (nPriority<m_nProcessQueue || !m_nProcessQueue)
		m_nProcessQueue = nPriority;
	//if (!nOldProcessQueue)
	{
		int nApiIndex=-1;
		int res;
		do
		{
			res = TransferNextFile(nApiIndex);
			if (res==-1)
				ProcessReply(FZ_REPLY_ERROR, nApiIndex);
			else if (res==-2)
				ProcessReply(FZ_REPLY_ERROR|FZ_REPLY_CRITICALERROR, nApiIndex);
		} while (res==1);
	}
	ASSERT(Validate());
}

void CQueueCtrl::StopProcessing()
{
	m_bMayUsePrimaryConnection=FALSE;
	
	CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());

	BOOL bCancelMainTransfer = FALSE;

	t_QueueVector::iterator iter;
	for (iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
	{
		if (!iter->bActive)
			break;
		
		if (!iter->pTransferApi)
			bCancelMainTransfer = TRUE;
		else
			iter->pTransferApi->Cancel();
		iter->bStop = TRUE;
	}
	for (iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -