📄 queuelistctrl.cpp
字号:
Sbuffer = GetResString(IDS_PRIORELEASE);
break; }
default:
Sbuffer.Empty();
}
}
else
Sbuffer = _T("?");
break;
case 3:
Sbuffer.Format(_T("%i"),client->GetScore(false,false,true));
break;
case 4:
if (client->HasLowID()){
if (client->m_bAddNextConnect)
Sbuffer.Format(_T("%i ****"),client->GetScore(false));
else
Sbuffer.Format(_T("%i LowID"),client->GetScore(false));
}
else
Sbuffer.Format(_T("%i"),client->GetScore(false));
break;
case 5:
Sbuffer.Format(_T("%i"),client->GetAskedCount());
break;
case 6:
Sbuffer = CastSecondsToHM((::GetTickCount() - client->GetLastUpRequest())/1000);
break;
case 7:
Sbuffer = CastSecondsToHM((::GetTickCount() - client->GetWaitStartTime())/1000);
break;
case 8:
if(client->IsBanned())
Sbuffer = GetResString(IDS_YES);
else
Sbuffer = GetResString(IDS_NO);
break;
case 9:
if( client->GetUpPartCount()){
cur_rec.bottom--;
cur_rec.top++;
client->DrawUpStatusBar(dc,&cur_rec,false,thePrefs.UseFlatBar());
cur_rec.bottom++;
cur_rec.top--;
}
break;
}
if( iColumn != 9 && iColumn != 0)
dc->DrawText(Sbuffer,Sbuffer.GetLength(),&cur_rec,DLC_DT_TEXT);
cur_rec.left += GetColumnWidth(iColumn);
}
}
//draw rectangle around selected item(s)
if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED))
{
RECT outline_rec = lpDrawItemStruct->rcItem;
outline_rec.top--;
outline_rec.bottom++;
dc->FrameRect(&outline_rec, &CBrush(GetBkColor()));
outline_rec.top++;
outline_rec.bottom--;
outline_rec.left++;
outline_rec.right--;
if(bCtrlFocused)
dc->FrameRect(&outline_rec, &CBrush(m_crFocusLine));
else
dc->FrameRect(&outline_rec, &CBrush(m_crNoFocusLine));
}
if (m_crWindowTextBk == CLR_NONE)
dc.SetBkMode(iOldBkMode);
dc.SelectObject(pOldFont);
dc.SetTextColor(crOldTextColor);
}
BEGIN_MESSAGE_MAP(CQueueListCtrl, CMuleListCtrl)
ON_WM_CONTEXTMENU()
ON_WM_SYSCOLORCHANGE()
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnClick)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)
END_MESSAGE_MAP()
// CQueueListCtrl message handlers
void CQueueListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
int iSel = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
const CUpDownClient* client = (iSel != -1) ? (CUpDownClient*)GetItemData(iSel) : NULL;
CTitleMenu ClientMenu;
ClientMenu.CreatePopupMenu();
ClientMenu.AddMenuTitle(GetResString(IDS_CLIENTS));
ClientMenu.AppendMenu(MF_STRING | (client ? MF_ENABLED : MF_GRAYED), MP_DETAIL, GetResString(IDS_SHOWDETAILS));
ClientMenu.SetDefaultItem(MP_DETAIL);
ClientMenu.AppendMenu(MF_STRING | ((client && client->IsEd2kClient() && !client->IsFriend()) ? MF_ENABLED : MF_GRAYED), MP_ADDFRIEND, GetResString(IDS_ADDFRIEND));
ClientMenu.AppendMenu(MF_STRING | ((client && client->IsEd2kClient()) ? MF_ENABLED : MF_GRAYED), MP_MESSAGE, GetResString(IDS_SEND_MSG));
ClientMenu.AppendMenu(MF_STRING | ((client && client->IsEd2kClient() && client->GetViewSharedFilesSupport()) ? MF_ENABLED : MF_GRAYED), MP_SHOWLIST, GetResString(IDS_VIEWFILES));
ClientMenu.AppendMenu(MF_STRING | ((client && client->IsEd2kClient() && client->IsBanned()) ? MF_ENABLED : MF_GRAYED), MP_UNBAN, GetResString(IDS_UNBAN));
if (Kademlia::CKademlia::isRunning() && !Kademlia::CKademlia::isConnected())
ClientMenu.AppendMenu(MF_STRING | ((client && client->IsEd2kClient() && client->GetKadPort()!=0) ? MF_ENABLED : MF_GRAYED), MP_BOOT, GetResString(IDS_BOOTSTRAP));
ClientMenu.AppendMenu(MF_STRING,MP_SHOWMPAGE, GetResString(IDS_SHOWMPAGE)); //VeryCD:从VeryCD网站查看用户资料
if (!client || !client->GetUserName() || !strstr(client->GetUserName(), "VeryCD:"))
ClientMenu.EnableMenuItem(MP_SHOWMPAGE,MF_GRAYED);
GetPopupMenuPos(*this, point);
ClientMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
}
BOOL CQueueListCtrl::OnCommand(WPARAM wParam,LPARAM lParam )
{
int iSel = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
if (iSel != -1){
CUpDownClient* client = (CUpDownClient*)GetItemData(iSel);
switch (wParam){
case MP_SHOWLIST:
client->RequestSharedFileList();
break;
case MP_MESSAGE:
theApp.emuledlg->chatwnd->StartSession(client);
break;
case MP_ADDFRIEND:
if (theApp.friendlist->AddFriend(client))
Update(iSel);
break;
case MP_UNBAN:
if (client->IsBanned()){
client->UnBan();
Update(iSel);
}
break;
case MPG_ALTENTER:
case MP_DETAIL:{
CClientDetailDialog dialog(client);
dialog.DoModal();
break;
}
case MP_BOOT:
if (client->GetKadPort())
Kademlia::CKademlia::bootstrap(ntohl(client->GetIP()), client->GetKadPort());
break;
case MP_SHOWMPAGE:{
char *pdest1;
char *pdest2;
int result;
CString Start;
pdest1 = strstr( client->GetUserName(), "VeryCD:" );
if(strstr( pdest1, "]" ))
{
pdest2 = strstr( pdest1, "]" );
result = (int)(pdest2 - pdest1 - 7);
Start = pdest1;
Start = Start.Mid(7,result);
CString temp = "http://www.VeryCD.com/" + Start;
ShellOpenFile(temp);
}
break;
}
}
}
return true;
}
void CQueueListCtrl::OnColumnClick( NMHDR* pNMHDR, LRESULT* pResult){
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// Barry - Store sort order in preferences
// Determine ascending based on whether already sorted on this column
int sortItem = thePrefs.GetColumnSortItem(CPreferences::tableQueue);
bool m_oldSortAscending = thePrefs.GetColumnSortAscending(CPreferences::tableQueue);
bool sortAscending = (sortItem != pNMListView->iSubItem) ? true : !m_oldSortAscending;
// Item is column clicked
sortItem = pNMListView->iSubItem;
// Save new preferences
thePrefs.SetColumnSortItem(CPreferences::tableQueue, sortItem);
thePrefs.SetColumnSortAscending(CPreferences::tableQueue, sortAscending);
// Sort table
SetSortArrow(sortItem, sortAscending);
SortItems(SortProc, sortItem + (sortAscending ? 0:100));
*pResult = 0;
}
int CQueueListCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
const CUpDownClient* item1 = (CUpDownClient*)lParam1;
const CUpDownClient* item2 = (CUpDownClient*)lParam2;
switch(lParamSort){
case 0:
if(item1->GetUserName() && item2->GetUserName())
return CompareLocaleStringNoCase(item1->GetUserName(), item2->GetUserName());
else if(item1->GetUserName())
return 1;
else
return -1;
case 100:
if(item2->GetUserName() && item1->GetUserName())
return CompareLocaleStringNoCase(item2->GetUserName(), item1->GetUserName());
else if(item2->GetUserName())
return 1;
else
return -1;
case 1: {
CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID());
CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID());
if( (file1 != NULL) && (file2 != NULL))
return CompareLocaleStringNoCase(file1->GetFileName(), file2->GetFileName());
else if( file1 == NULL )
return 1;
else
return -1;
}
case 101: {
CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID());
CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID());
if( (file1 != NULL) && (file2 != NULL))
return CompareLocaleStringNoCase(file2->GetFileName(), file1->GetFileName());
else if( file1 == NULL )
return 1;
else
return -1;
}
case 2: {
CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID());
CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID());
if( (file1 != NULL) && (file2 != NULL))
return ((file1->GetUpPriority()==PR_VERYLOW) ? -1 : file1->GetUpPriority()) - ((file2->GetUpPriority()==PR_VERYLOW) ? -1 : file2->GetUpPriority());
else if( file1 == NULL )
return 1;
else
return -1;
}
case 102:{
CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID());
CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID());
if( (file1 != NULL) && (file2 != NULL))
return ((file2->GetUpPriority()==PR_VERYLOW) ? -1 : file2->GetUpPriority()) - ((file1->GetUpPriority()==PR_VERYLOW) ? -1 : file1->GetUpPriority());
else if( file1 == NULL )
return 1;
else
return -1;
}
case 3:
return CompareUnsigned(item1->GetScore(false,false,true), item2->GetScore(false,false,true));
case 103:
return CompareUnsigned(item2->GetScore(false,false,true), item1->GetScore(false,false,true));
case 4:
return CompareUnsigned(item1->GetScore(false), item2->GetScore(false));
case 104:
return CompareUnsigned(item2->GetScore(false), item1->GetScore(false));
case 5:
return item1->GetAskedCount() - item2->GetAskedCount();
case 105:
return item2->GetAskedCount() - item1->GetAskedCount();
case 6:
return item1->GetLastUpRequest() - item2->GetLastUpRequest();
case 106:
return item2->GetLastUpRequest() - item1->GetLastUpRequest();
case 7:
return item1->GetWaitStartTime() - item2->GetWaitStartTime();
case 107:
return item2->GetWaitStartTime() - item1->GetWaitStartTime();
case 8:
return item1->IsBanned() - item2->IsBanned();
case 108:
return item2->IsBanned() - item1->IsBanned();
case 9:
return item1->GetUpPartCount() - item2->GetUpPartCount();
case 109:
return item2->GetUpPartCount() - item1->GetUpPartCount();
default:
return 0;
}
}
// Barry - Refresh the queue every 10 secs
void CALLBACK CQueueListCtrl::QueueUpdateTimer(HWND hwnd, UINT uiMsg, UINT idEvent, DWORD dwTime)
{
// NOTE: Always handle all type of MFC exceptions in TimerProcs - otherwise we'll get mem leaks
try
{
if ( !theApp.emuledlg->IsRunning() // Don't do anything if the app is shutting down - can cause unhandled exceptions
|| !thePrefs.GetUpdateQueueList()
|| theApp.emuledlg->activewnd != theApp.emuledlg->transferwnd
|| !theApp.emuledlg->transferwnd->queuelistctrl.IsWindowVisible() )
return;
const CUpDownClient* update = theApp.uploadqueue->GetNextClient(NULL);
while( update )
{
theApp.emuledlg->transferwnd->queuelistctrl.RefreshClient(update);
update = theApp.uploadqueue->GetNextClient(update);
}
}
CATCH_DFLT_EXCEPTIONS(_T("CQueueListCtrl::QueueUpdateTimer"))
}
void CQueueListCtrl::ShowQueueClients()
{
DeleteAllItems();
/*const*/ CUpDownClient* update = theApp.uploadqueue->GetNextClient(NULL);
while( update )
{
AddClient(update, false);
update = theApp.uploadqueue->GetNextClient(update);
}
}
void CQueueListCtrl::ShowSelectedUserDetails()
{
POINT point;
::GetCursorPos(&point);
CPoint p = point;
ScreenToClient(&p);
int it = HitTest(p);
if (it == -1)
return;
SetItemState(-1, 0, LVIS_SELECTED);
SetItemState(it, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
SetSelectionMark(it); // display selection mark correctly!
const CUpDownClient* client = (CUpDownClient*)GetItemData(GetSelectionMark());
if (client){
CClientDetailDialog dialog(client);
dialog.DoModal();
}
}
void CQueueListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
{
int iSel = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
if (iSel != -1) {
const CUpDownClient* client = (CUpDownClient*)GetItemData(iSel);
if (client){
CClientDetailDialog dialog(client);
dialog.DoModal();
}
}
*pResult = 0;
}
void CQueueListCtrl::OnGetDispInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
if (theApp.emuledlg->IsRunning()){
// Although we have an owner drawn listview control we store the text for the primary item in the listview, to be
// capable of quick searching those items via the keyboard. Because our listview items may change their contents,
// we do this via a text callback function. The listview control will send us the LVN_DISPINFO notification if
// it needs to know the contents of the primary item.
//
// But, the listview control sends this notification all the time, even if we do not search for an item. At least
// this notification is only sent for the visible items and not for all items in the list. Though, because this
// function is invoked *very* often, no *NOT* put any time consuming code here in.
if (pDispInfo->item.mask & LVIF_TEXT){
const CUpDownClient* pClient = reinterpret_cast<CUpDownClient*>(pDispInfo->item.lParam);
if (pClient != NULL){
switch (pDispInfo->item.iSubItem){
case 0:
if (pClient->GetUserName() != NULL && pDispInfo->item.cchTextMax > 0){
_tcsncpy(pDispInfo->item.pszText, pClient->GetUserName(), pDispInfo->item.cchTextMax);
pDispInfo->item.pszText[pDispInfo->item.cchTextMax-1] = _T('\0');
}
break;
default:
// shouldn't happen
pDispInfo->item.pszText[0] = _T('\0');
break;
}
}
}
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -