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

📄 transferwnd.cpp

📁 非常出名开源客户端下载的程序emule
💻 CPP
📖 第 1 页 / 共 2 页
字号:

			info.Format(GetResString(IDS_DL_FILENAME)+": %s (%s %s)\n"
				+GetResString(IDS_FD_HASH) +" %s\n"
				+GetResString(IDS_PARTINFOS)+
				GetResString(IDS_PARTINFOS2)+"\n%s",
				partfile->GetFileName(), CastItoXBytes(partfile->GetFileSize()),GetResString(IDS_BYTES),
						strHash,
						partfile->GetPartMetFileName(), partfile->GetPartCount(),GetResString(IDS_AVAIL),partfile->GetAvailablePartCount(),availability,
						(int)partfile->GetPercentCompleted(), compl, partfile->GetTransferingSrcCount(),
						GetResString(IDS_LASTSEENCOMPL)+" "+lsc+"\n"+
						GetResString(IDS_FD_LASTCHANGE)+" "+lastdwl
						);
		}
		else if (content->type == 3 || content->type == 2) // for sources
		{
			CUpDownClient* client = (CUpDownClient*)content->value;
			in_addr server;
			server.S_un.S_addr = client->GetServerIP();

			info.Format(GetResString(IDS_NICKNAME)+" %s\n"
				+GetResString(IDS_SERVER)+" %s:%d\n"
				+GetResString(IDS_SOURCEINFO),
						client->GetUserName(),
						inet_ntoa(server), client->GetServerPort(),
						client->GetAskedCountDown(), client->GetAvailablePartCount());
			if (content->type == 2)
			{	// normal client
				info += GetResString(IDS_CLIENTSOURCENAME) + CString(client->GetClientFilename());
			}
			else
			{	// client asked twice
				info += GetResString(IDS_ASKEDFAF);
			}
         //-For File Comment-// 
         try { 
			 if (content->type==2){
				if (client->GetFileComment() != "") { 
					info += "\n" + GetResString(IDS_CMT_READ)  + " " + CString(client->GetFileComment()); 
				} 
				else { 
					//No comment entered 
					info += "\n" + GetResString(IDS_CMT_NONE); 
				} 
				info += "\n" + GetRateString(client->GetFileRate());
			 }
         } catch(...) { 
            //Information not received = not connected or connecting 
            info += "\n" + GetResString(IDS_CMT_NOTCONNECTED); 
         } 
         //-End file comment-//
		}
	}
	else if (control_id == IDC_UPLOADLIST)
	{
		if (uploadlistctrl.GetItemCount() < 1)
			return FALSE;
		int sel = GetItemUnderMouse(&uploadlistctrl);
		if (sel < 0 || sel == 65535)
			return FALSE;

		CUpDownClient* client = (CUpDownClient*)uploadlistctrl.GetItemData(sel);
		CKnownFile* file = theApp.sharedfiles->GetFileByID(client->GetUploadFileID());
		// build info text and display it
		info.Format(GetResString(IDS_USERINFO), client->GetUserName());
		if (file)
		{
			info += GetResString(IDS_SF_REQUESTED) + CString(file->GetFileName()) + "\n";
			CString stat;
			stat.Format(GetResString(IDS_FILESTATS_SESSION)+GetResString(IDS_FILESTATS_TOTAL),
						file->statistic.GetAccepts(), file->statistic.GetRequests(), file->statistic.GetTransferred(),
						file->statistic.GetAllTimeAccepts(), file->statistic.GetAllTimeRequests(), file->statistic.GetAllTimeTransferred());
			info += stat;
		}
		else
		{
			info += GetResString(IDS_REQ_UNKNOWNFILE);
		}

	}
/*	no tooltips needed ATM
	else if (control_id == IDC_QUEUELIST)
	{
		if (queuelistctrl.GetItemCount() < 1)
			return FALSE;
		int sel = GetItemUnderMouse(&queuelistctrl);
		if (sel < 0 || sel == 65535)
			return FALSE;

		// build info text and display it
		CUpDownClient* client = (CUpDownClient*)uploadlistctrl.GetItemData(sel);
		in_addr server;
		server.S_un.S_addr = client->GetServerIP();

		info.Format("Nickname: %s\n"
					"Server %s:%d\n"
					"AskedCount: %d - AvailablePartCount: %d",
					client->GetUserName(),
					inet_ntoa(server), client->GetServerPort(),
					client->GetAskedCount(), client->GetAvailablePartCount());

	}
*/
	m_strToolTip.ReleaseBuffer(); // release old used buffer
	m_strToolTip = info;
	pText->lpszText = m_strToolTip.GetBuffer(1);
	pText->hinst = NULL; // we are not using a resource
	PostMessage(WM_ACTIVATE);
	return TRUE;
}

void CTransferWnd::SwitchUploadList()
{
	if( windowtransferstate == 1){
		windowtransferstate = 2;		
		if( theApp.glob_prefs->IsQueueListDisabled()){
			SwitchUploadList();
			return;
		}
		uploadlistctrl.Hide();
		clientlistctrl.Hide();
		GetDlgItem(IDC_QUEUE_REFRESH_BUTTON)->ShowWindow(SW_SHOW);
		queuelistctrl.Visable();
		GetDlgItem(IDC_UPLOAD_ICO)->SetWindowText(GetResString(IDS_ONQUEUE));
	}
	else if( windowtransferstate == 2){
		windowtransferstate = 0;
		if( theApp.glob_prefs->IsKnownClientListDisabled()){
			SwitchUploadList();
			return;
		}
		uploadlistctrl.Hide();
		queuelistctrl.Hide();
		clientlistctrl.Visable();
		GetDlgItem(IDC_QUEUE_REFRESH_BUTTON)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_UPLOAD_ICO)->SetWindowText(GetResString(IDS_CLIENTLIST));
	}
	else{
		queuelistctrl.Hide();
		clientlistctrl.Hide();
		uploadlistctrl.Visable();
		GetDlgItem(IDC_QUEUE_REFRESH_BUTTON)->ShowWindow(SW_HIDE);
		windowtransferstate = 1;
		GetDlgItem(IDC_UPLOAD_ICO)->SetWindowText(GetResString(IDS_TW_UPLOADS));
	}
}

void CTransferWnd::Localize(){
	GetDlgItem(IDC_DOWNLOAD_TEXT)->SetWindowText(GetResString(IDS_TW_DOWNLOADS));
	GetDlgItem(IDC_UPLOAD_ICO)->SetWindowText(GetResString(IDS_TW_UPLOADS));
	GetDlgItem(IDC_TSTATIC1)->SetWindowText(GetResString(IDS_TW_QUEUE));
	GetDlgItem(IDC_QUEUE_REFRESH_BUTTON)->SetWindowText(GetResString(IDS_SV_UPDATE));

	uploadlistctrl.Localize();
	queuelistctrl.Localize();
	downloadlistctrl.Localize();
	clientlistctrl.Localize();
}

void CTransferWnd::OnBnClickedQueueRefreshButton()
{
	CUpDownClient* update = theApp.uploadqueue->GetNextClient(NULL);

	while( update ){
		theApp.emuledlg->transferwnd.queuelistctrl.RefreshClient( update);
		update = theApp.uploadqueue->GetNextClient(update);
	}
}

void CTransferWnd::OnHoverUploadList(NMHDR *pNMHDR, LRESULT *pResult)
{
	downloadlistactive=false;
	*pResult = 0;
}

void CTransferWnd::OnHoverDownloadList(NMHDR *pNMHDR, LRESULT *pResult)
{
	downloadlistactive=true;
	*pResult = 0;
}

void CTransferWnd::OnTcnSelchangeDltab(NMHDR *pNMHDR, LRESULT *pResult)
{
	downloadlistctrl.ChangeCategory(m_dlTab.GetCurSel());
	*pResult = 0;
}

// Ornis' download categories
void CTransferWnd::OnNMRclickDltab(NMHDR *pNMHDR, LRESULT *pResult)
{
	// Menu for category
	CTitleMenu menu;
	POINT point;
	::GetCursorPos(&point);

	CPoint pt(point);
	rightclickindex=GetTabUnderMouse(&pt);

	UINT flag;
	flag=(rightclickindex==0) ? MF_GRAYED:MF_STRING;

	CMenu m_PrioMenu;
	m_PrioMenu.CreateMenu();
	m_PrioMenu.AppendMenu(MF_STRING,MP_PRIOLOW,GetResString(IDS_PRIOLOW));
	m_PrioMenu.AppendMenu(MF_STRING,MP_PRIONORMAL,GetResString(IDS_PRIONORMAL));
	m_PrioMenu.AppendMenu(MF_STRING,MP_PRIOHIGH, GetResString(IDS_PRIOHIGH));
	m_PrioMenu.AppendMenu(MF_STRING,MP_PRIOAUTO, GetResString(IDS_PRIOAUTO));

	menu.CreatePopupMenu();
	menu.AddMenuTitle(GetResString(IDS_CAT));
	
	if (rightclickindex==0 && theApp.glob_prefs->GetCatCount()>1 ){
		CString invertitem=theApp.glob_prefs->ShowAllNotCats() ? GetResString(IDS_CAT_REINVADD):GetResString(IDS_CAT_INVADD);
		menu.AppendMenu(MF_STRING,MP_CAT_INVALL,invertitem);
		menu.AppendMenu(MF_SEPARATOR);
	}
	menu.AppendMenu(MF_STRING,MP_CAT_ADD,GetResString(IDS_CAT_ADD));
	menu.AppendMenu(flag,MP_CAT_EDIT,GetResString(IDS_CAT_EDIT));
	menu.AppendMenu(flag,MP_CAT_REMOVE, GetResString(IDS_CAT_REMOVE));
	menu.AppendMenu(MF_SEPARATOR);
	menu.AppendMenu(MF_STRING|MF_POPUP,(UINT_PTR)m_PrioMenu.m_hMenu, GetResString(IDS_PRIORITY) );

	menu.AppendMenu(MF_STRING,MP_CANCEL,GetResString(IDS_MAIN_BTN_CANCEL) );
	menu.AppendMenu(MF_STRING,MP_STOP, GetResString(IDS_DL_STOP));
	menu.AppendMenu(MF_STRING,MP_PAUSE, GetResString(IDS_DL_PAUSE));
	menu.AppendMenu(MF_STRING,MP_RESUME, GetResString(IDS_DL_RESUME));

	menu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
	menu.DestroyMenu();
	m_PrioMenu.DestroyMenu();

	*pResult = 0;
}


void CTransferWnd::OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult)
{
    int iSel = downloadlistctrl.GetSelectionMark();
	if (iSel==-1) return;
	if (((CtrlItem_Struct*)downloadlistctrl.GetItemData(iSel))->type != FILE_TYPE) return;
	
	m_bIsDragging = true;

	POINT pt;
	::GetCursorPos(&pt);
    int nOffset = 10;
    pt.x += nOffset;
    pt.y += nOffset;

	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	m_nDragIndex = pNMLV->iItem;
	m_pDragImage = downloadlistctrl.CreateDragImage( downloadlistctrl.GetSelectionMark() ,&pt);
    m_pDragImage->BeginDrag( 0, CPoint(10,10) );
    m_pDragImage->DragEnter( GetDesktopWindow(), pNMLV->ptAction );
    SetCapture();
	m_nDropIndex = -1;

	*pResult = 0;
}

void CTransferWnd::OnMouseMove(UINT nFlags, CPoint point)
{
	if( !(nFlags & MK_LBUTTON) ) m_bIsDragging = false;

	if (m_bIsDragging){
		//// Move the drag image
		CPoint pt(point);           //get our current mouse coordinates
		ClientToScreen(&pt);        //convert to screen coordinates

		m_nDropIndex=GetTabUnderMouse(&pt);
		m_dlTab.SetCurSel(m_nDropIndex);
		m_dlTab.Invalidate();

		m_pDragImage->DragMove(pt); //move the drag image to those coordinates
	}
}

void CTransferWnd::OnLButtonUp(UINT nFlags, CPoint point)
{

	if (m_bIsDragging)
	{
		ReleaseCapture ();
		m_bIsDragging = false;
		m_pDragImage->DragLeave (GetDesktopWindow ());
		m_pDragImage->EndDrag ();
		delete m_pDragImage;
		
		if (m_nDropIndex>-1 && (downloadlistctrl.curTab==0 ||
				(downloadlistctrl.curTab>0 && m_nDropIndex!=downloadlistctrl.curTab) )) {

			CPartFile* file;
			int index = -1; 
			POSITION pos = downloadlistctrl.GetFirstSelectedItemPosition(); 
			while(pos != NULL) 
			{ 
				index = downloadlistctrl.GetNextSelectedItem(pos); 
				if(index > -1) 
				{
					if (((CtrlItem_Struct*)downloadlistctrl.GetItemData(index))->type == FILE_TYPE) {
						file=(CPartFile*)((CtrlItem_Struct*)downloadlistctrl.GetItemData(index))->value;
						file->SetCategory(m_nDropIndex);
					}

				} 
			}
			m_dlTab.SetCurSel(downloadlistctrl.curTab);
			if (m_dlTab.GetCurSel()>0 || (theApp.glob_prefs->ShowAllNotCats() && m_dlTab.GetCurSel()==0) )
				downloadlistctrl.ChangeCategory(m_dlTab.GetCurSel());

		} else m_dlTab.SetCurSel(downloadlistctrl.curTab);
		downloadlistctrl.Invalidate();
	}
}

BOOL CTransferWnd::OnCommand(WPARAM wParam,LPARAM lParam ){ 

	switch (wParam){ 
		case MP_CAT_ADD: {
			int newindex=AddCategorie("?",theApp.glob_prefs->GetIncomingDir(),"",false);
			m_dlTab.InsertItem(newindex,theApp.glob_prefs->GetCategory(newindex)->title);
			CCatDialog dialog(newindex);
			dialog.DoModal();
			theApp.emuledlg->searchwnd.UpdateCatTabs();
			EditCatTabLabel(newindex,theApp.glob_prefs->GetCategory(newindex)->title);
			break;
		}
		case MP_CAT_EDIT: {
			CCatDialog dialog(rightclickindex);
			dialog.DoModal();

			CString csName;
			csName.Format("%s", theApp.glob_prefs->GetCategory(rightclickindex)->title );
			EditCatTabLabel(rightclickindex,csName);
			
			theApp.emuledlg->searchwnd.UpdateCatTabs();
			break;
		}
		case MP_CAT_REMOVE: {
			theApp.downloadqueue->ResetCatParts(rightclickindex);
			theApp.glob_prefs->RemoveCat(rightclickindex);
			m_dlTab.DeleteItem(rightclickindex);
			m_dlTab.SetCurSel(0);
			downloadlistctrl.ChangeCategory(0);
			theApp.emuledlg->searchwnd.UpdateCatTabs();
			break;
		}
		case MP_CAT_INVALL: {
			theApp.glob_prefs->InvertShowAllNotCats();
			m_dlTab.SetCurSel(0);
			downloadlistctrl.ChangeCategory(0);
			EditCatTabLabel(0,(theApp.glob_prefs->ShowAllNotCats())? GetResString(IDS_ALLOTHERS):GetResString(IDS_ALL));
			break;
		}
		case MP_PRIOLOW: {
			theApp.downloadqueue->SetCatPrio(rightclickindex,PR_LOW);
			break;
		}
		case MP_PRIONORMAL: {
			theApp.downloadqueue->SetCatPrio(rightclickindex,PR_NORMAL);
			break;
		}
		case MP_PRIOHIGH: {
			theApp.downloadqueue->SetCatPrio(rightclickindex,PR_HIGH);
			break;
		}
		case MP_PRIOAUTO: {
			theApp.downloadqueue->SetCatPrio(rightclickindex,PR_AUTO);
			break;
		}
		case MP_PAUSE: {
			theApp.downloadqueue->SetCatStatus(rightclickindex,MP_PAUSE);
			break;
		}
		case MP_STOP : {
				theApp.downloadqueue->SetCatStatus(rightclickindex,MP_STOP);
			break;
		}
		case MP_CANCEL: {
			if (MessageBox(GetResString(IDS_Q_CANCELDL) ,GetResString(IDS_CANCEL),MB_ICONQUESTION|MB_YESNO) == IDYES)
				theApp.downloadqueue->SetCatStatus(rightclickindex,MP_CANCEL);
			break;
		}
		case MP_RESUME: {
			theApp.downloadqueue->SetCatStatus(rightclickindex,MP_RESUME);
			break;
		}
		case IDC_UPLOAD_ICO: {
			SwitchUploadList();
			break;
		}
		case IDC_QUEUE_REFRESH_BUTTON: {
			OnBnClickedQueueRefreshButton();
			break;
		}
	}
	return TRUE;
}

void CTransferWnd::EditCatTabLabel(int index,CString newlabel) {
	TCITEM tabitem;
	tabitem.mask = TCIF_PARAM;
	m_dlTab.GetItem(index,&tabitem);

	tabitem.mask = TCIF_TEXT;
	tabitem.pszText = newlabel.LockBuffer();
	m_dlTab.SetItem(index,&tabitem);
	newlabel.UnlockBuffer();
}

int CTransferWnd::AddCategorie(CString newtitle,CString newincoming,CString newcomment,bool addTab){
	Category_Struct* newcat=new Category_Struct();

	sprintf(newcat->title,newtitle);
	sprintf(newcat->incomingpath,newincoming);
	sprintf(newcat->comment,newcomment);
	int index=theApp.glob_prefs->AddCat(newcat);
	
	if (addTab) m_dlTab.InsertItem(index,newtitle);
	return index;
}

int CTransferWnd::GetTabUnderMouse(CPoint* point) {
		TCHITTESTINFO hitinfo;
		CRect rect;
		m_dlTab.GetWindowRect(&rect);
		point->Offset(0-rect.left,0);
		hitinfo.pt = *point;

		if( m_dlTab.GetItemRect( 0, &rect ) )
		{
			// Adjust position to top of tab control (allow the mouse the actually
			// be outside the top of tab control and still be able to find the right
			// tab index
			hitinfo.pt.y = rect.top;
		}

		// Find the destination tab...
		unsigned int nTab = m_dlTab.HitTest( &hitinfo );
		if( hitinfo.flags != TCHT_NOWHERE )
			return nTab;
		else return -1;
}

⌨️ 快捷键说明

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