📄 downloadlistctrl.cpp
字号:
case MP_ALL_A4AF_AUTO:
file->SetA4AFAuto(!file->IsA4AFAuto());
break;
case MPG_F2:
if (file->GetStatus() != PS_COMPLETE && file->GetStatus() != PS_COMPLETING)
{
InputBox inputbox;
CString title=GetResString(IDS_RENAME);
title.Remove(_T('&'));
inputbox.SetLabels(title ,GetResString(IDS_DL_FILENAME),file->GetFileName());
inputbox.SetEditFilenameMode();
inputbox.DoModal();
CString nn=inputbox.GetInput();
if (!inputbox.WasCancelled() && nn.GetLength()>0){
file->SetFileName(nn,true);
file->UpdateDisplayedInfo();
file->SavePartFile();
}
}
else
MessageBeep((UINT)-1);
break;
case MPG_ALTENTER:
case MP_METINFO:
ShowFileDialog();
break;
case MP_GETED2KLINK:{
CString str;
while (!selectedList.IsEmpty()){
if (!str.IsEmpty())
str += _T("\r\n");
str += CreateED2kLink(selectedList.GetHead());
selectedList.RemoveHead();
}
theApp.CopyTextToClipboard(str);
break;
}
case MP_GETHTMLED2KLINK:{
CString str;
while (!selectedList.IsEmpty()){
if (!str.IsEmpty())
str += _T("<br />\r\n");
str += CreateHTMLED2kLink(selectedList.GetHead());
selectedList.RemoveHead();
}
theApp.CopyTextToClipboard(str);
break;
}
case MP_OPEN:
if(selectedCount > 1)
break;
file->OpenFile();
break;
case MP_PREVIEW:{
if(selectedCount > 1)
break;
file->PreviewFile();
break;
}
case MP_VIEWFILECOMMENTS:
ShowFileDialog(NULL, true);
break;
default:
if (wParam>=MP_WEBURL && wParam<=MP_WEBURL+99){
theWebServices.RunURL(file, wParam);
}
else if (wParam>=MP_ASSIGNCAT && wParam<=MP_ASSIGNCAT+99){
SetRedraw(FALSE);
while (!selectedList.IsEmpty()){
CPartFile *partfile = selectedList.GetHead();
partfile->SetCategory(wParam - MP_ASSIGNCAT);
partfile->UpdateDisplayedInfo(true);
selectedList.RemoveHead();
}
SetRedraw(TRUE);
ChangeCategory(curTab);
}
else if (wParam>=MP_PREVIEW_APP_MIN && wParam<=MP_PREVIEW_APP_MAX){
thePreviewApps.RunApp(file, wParam);
}
break;
}
}
else{
CUpDownClient* client = (CUpDownClient*)content->value;
CPartFile* file = (CPartFile*)content->owner; // added by sivka
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))
UpdateItem(client);
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;
// ZZ:DownloadManager -->
case MP_A4AF_CHECK_THIS_NOW:
if (file->GetStatus(false) == PS_READY || file->GetStatus(false) == PS_EMPTY)
{
if (client->GetDownloadState() != DS_DOWNLOADING)
{
client->SwapToAnotherFile(_T("Manual init of source check. Test to be like ProcessA4AFClients(). CDownloadListCtrl::OnCommand() MP_SWAP_A4AF_DEBUG_THIS"), false, false, false, NULL, true, true, true); // ZZ:DownloadManager
UpdateItem(file);
}
}
break;
// <-- ZZ:DownloadManager
}
}
}
else /*nothing selected*/
{
switch (wParam){
case MP_CLEARCOMPLETED:
ClearCompleted();
break;
}
}
return TRUE;
}
void CDownloadListCtrl::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::tableDownload);
bool m_oldSortAscending = thePrefs.GetColumnSortAscending(CPreferences::tableDownload);
if (sortItem==9) {
m_bRemainSort=(sortItem != pNMListView->iSubItem) ? false : (m_oldSortAscending?m_bRemainSort:!m_bRemainSort);
}
bool sortAscending = (sortItem != pNMListView->iSubItem) ? true : !m_oldSortAscending;
// Item is column clicked
sortItem = pNMListView->iSubItem;
// Save new preferences
thePrefs.SetColumnSortItem(CPreferences::tableDownload, sortItem);
thePrefs.SetColumnSortAscending(CPreferences::tableDownload, sortAscending);
thePrefs.TransferlistRemainSortStyle(m_bRemainSort);
// Sort table
uint8 adder=0;
if (sortItem!=9 || !m_bRemainSort)
SetSortArrow(sortItem, sortAscending);
else {
SetSortArrow(sortItem, sortAscending?arrowDoubleUp : arrowDoubleDown);
adder=81;
}
SortItems(SortProc, sortItem + (sortAscending ? 0:100) + adder );
*pResult = 0;
}
int CDownloadListCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort){
CtrlItem_Struct* item1 = (CtrlItem_Struct*)lParam1;
CtrlItem_Struct* item2 = (CtrlItem_Struct*)lParam2;
int sortMod = 1;
if(lParamSort >= 100) {
sortMod = -1;
lParamSort -= 100;
}
int comp;
if(item1->type == FILE_TYPE && item2->type != FILE_TYPE) {
if(item1->value == item2->parent->value)
return -1;
comp = Compare((CPartFile*)item1->value, (CPartFile*)(item2->parent->value), lParamSort);
} else if(item2->type == FILE_TYPE && item1->type != FILE_TYPE) {
if(item1->parent->value == item2->value)
return 1;
comp = Compare((CPartFile*)(item1->parent->value), (CPartFile*)item2->value, lParamSort);
} else if (item1->type == FILE_TYPE) {
CPartFile* file1 = (CPartFile*)item1->value;
CPartFile* file2 = (CPartFile*)item2->value;
comp = Compare(file1, file2, lParamSort);
} else {
comp = Compare((CPartFile*)(item1->parent->value), (CPartFile*)(item2->parent->value), lParamSort);
if(comp != 0)
return sortMod * comp;
if (item1->type != item2->type)
return item1->type - item2->type;
CUpDownClient* client1 = (CUpDownClient*)item1->value;
CUpDownClient* client2 = (CUpDownClient*)item2->value;
comp = Compare(client1, client2, lParamSort,sortMod);
}
return sortMod * comp;
}
void CDownloadListCtrl::ClearCompleted(bool ignorecats){
// Search for completed file(s)
for(ListItems::iterator it = m_ListItems.begin(); it != m_ListItems.end(); ){
CtrlItem_Struct* cur_item = it->second;
it++; // Already point to the next iterator.
if(cur_item->type == FILE_TYPE){
CPartFile* file = reinterpret_cast<CPartFile*>(cur_item->value);
if(file->IsPartFile() == false && (file->CheckShowItemInGivenCat(curTab) || ignorecats) ){
if (RemoveFile(file))
it = m_ListItems.begin();
}
}
}
}
void CDownloadListCtrl::ClearCompleted(const CPartFile* pFile)
{
if (!pFile->IsPartFile())
{
for (ListItems::iterator it = m_ListItems.begin(); it != m_ListItems.end(); )
{
CtrlItem_Struct* cur_item = it->second;
it++;
if (cur_item->type == FILE_TYPE)
{
const CPartFile* pCurFile = reinterpret_cast<CPartFile*>(cur_item->value);
if (pCurFile == pFile)
{
RemoveFile(pCurFile);
return;
}
}
}
}
}
void CDownloadListCtrl::SetStyle() {
if (thePrefs.IsDoubleClickEnabled())
SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
else
SetExtendedStyle(LVS_EX_ONECLICKACTIVATE | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
}
void CDownloadListCtrl::OnListModified(NMHDR *pNMHDR, LRESULT *pResult) {
NM_LISTVIEW *pNMListView = (NM_LISTVIEW*)pNMHDR;
//this works because true is equal to 1 and false equal to 0
BOOL notLast = pNMListView->iItem + 1 != GetItemCount();
BOOL notFirst = pNMListView->iItem != 0;
RedrawItems(pNMListView->iItem - notFirst, pNMListView->iItem + notLast);
}
int CDownloadListCtrl::Compare(const CPartFile* file1, const CPartFile* file2, LPARAM lParamSort)
{
switch(lParamSort){
case 0: //filename asc
return _tcsicmp(file1->GetFileName(),file2->GetFileName());
case 1: //size asc
return CompareUnsigned(file1->GetFileSize(), file2->GetFileSize());
case 2: //transfered asc
return CompareUnsigned(file1->GetTransfered(), file2->GetTransfered());
case 3: //completed asc
return CompareUnsigned(file1->GetCompletedSize(), file2->GetCompletedSize());
case 4: //speed asc
return CompareUnsigned(file1->GetDatarate(), file2->GetDatarate());
case 5: //progress asc
{
float comp = file1->GetPercentCompleted() - file2->GetPercentCompleted();
if(comp > 0)
return 1;
else if(comp < 0)
return -1;
else
return 0;
}
case 6: //sources asc
return file1->GetSourceCount() - file2->GetSourceCount();
case 7: //priority asc
return file1->GetDownPriority() - file2->GetDownPriority();
case 8: //Status asc
{
int comp = file1->getPartfileStatusRang()-file2->getPartfileStatusRang();
// Second sort order on filename
if(comp == 0) {
comp = _tcsicmp(file1->GetFileName(),file2->GetFileName());
}
return comp;
}
case 9: //Remaining Time asc
{
//Make ascending sort so we can have the smaller remaining time on the top
//instead of unknowns so we can see which files are about to finish better..
sint32 f1 = file1->getTimeRemaining();
sint32 f2 = file2->getTimeRemaining();
//Same, do nothing.
if( f1 == f2 )
return 0;
//If decending, put first on top as it is unknown
//If ascending, put first on bottom as it is unknown
if( f1 == -1 )
return 1;
//If decending, put second on top as it is unknown
//If ascending, put second on bottom as it is unknown
if( f2 == -1 )
return -1;
//If decending, put first on top as it is bigger.
//If ascending, put first on bottom as it is bigger.
return f1 - f2;
}
case 90: //Remaining SIZE asc
return CompareUnsigned(file1->GetFileSize()-file1->GetCompletedSize(), file2->GetFileSize()-file2->GetCompletedSize());
case 10: //last seen complete asc
if (file1->lastseencomplete > file2->lastseencomplete)
return 1;
else if(file1->lastseencomplete < file2->lastseencomplete)
return -1;
else
return 0;
case 11: //last received Time asc
if (file1->GetFileDate() > file2->GetFileDate())
return 1;
else if(file1->GetFileDate() < file2->GetFileDate())
return -1;
else
return 0;
case 12:
//TODO: 'GetCategory' SHOULD be a 'const' function and 'GetResString' should NOT be called..
return _tcsicmp(
(const_cast<CPartFile*>(file1)->GetCategory()!=0)?thePrefs.GetCategory(const_cast<CPartFile*>(file1)->GetCategory())->title:GetResString(IDS_ALL),
(const_cast<CPartFile*>(file2)->GetCategory()!=0)?thePrefs.GetCategory(const_cast<CPartFile*>(file2)->GetCategory())->title:GetResString(IDS_ALL)
);
return 0;
default:
return 0;
}
}
int CDownloadListCtrl::Compare(const CUpDownClient *client1, const CUpDownClient *client2, LPARAM lParamSort, int sortMod)
{
switch(lParamSort){
case 0: //name asc
if(client1->GetUserName() == client2->GetUserName())
return 0;
else if(!client1->GetUserName())
return 1;
else if(!client2->GetUserName())
return -1;
return _tcsicmp(client1->GetUserName(),client2->GetUserName());
case 1: //size but we use status asc
return client1->GetSourceFrom() - client2->GetSourceFrom();
case 2://transfered asc
case 3://completed asc
return CompareUnsigned(client1->GetTransferedDown(), client2->GetTransferedDown());
case 4: //speed asc
return CompareUnsigned(client1->GetDownloadDatarate(), client2->GetDownloadDatarate());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -