📄 downloadlistctrl.cpp
字号:
theApp.CopyTextToClipboard(str);
//AfxMessageBox(GetResString(IDS_COPIED2CB) + str);
break;
}
theApp.CopyTextToClipboard(theApp.CreateED2kLink(file));
break;
case MP_GETHTMLED2KLINK:
if(selectedCount > 1)
{
CString str;
while(!selectedList.IsEmpty()) {
str += theApp.CreateHTMLED2kLink(selectedList.GetHead()) + "\n";
selectedList.RemoveHead();
}
theApp.CopyTextToClipboard(str);
//AfxMessageBox(GetResString(IDS_COPIED2CB) + str);
break;
}
theApp.CopyTextToClipboard(theApp.CreateHTMLED2kLink(file));
break;
case MP_OPEN:{
if(selectedCount > 1)
break;
char* buffer = new char[MAX_PATH];
sprintf(buffer,"%s",file->GetFullName());
ShellOpenFile(buffer);
delete buffer;
break;
}
case MP_PREVIEW:{
if(selectedCount > 1)
break;
file->PreviewFile();
break;
}
case MP_VIEWFILECOMMENTS:{
CCommentDialogLst dialog(file);
dialog.DoModal();
break;
}
}
}
else{
CUpDownClient* client = (CUpDownClient*)content->value;
switch (wParam){
case MP_SHOWLIST:
client->RequestSharedFileList();
break;
case MP_MESSAGE:
theApp.emuledlg->chatwnd.StartSession(client);
break;
case MP_ADDFRIEND:{
theApp.friendlist->AddFriend(client);
break;
}
case MP_DETAIL:
CClientDetailDialog dialog(client);
dialog.DoModal();
break;
}
}
// cleanup multiselection
selectedList.RemoveAll();
}
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 = theApp.glob_prefs->GetColumnSortItem(CPreferences::tableDownload);
bool m_oldSortAscending = theApp.glob_prefs->GetColumnSortAscending(CPreferences::tableDownload);
bool sortAscending = (sortItem != pNMListView->iSubItem) ? true : !m_oldSortAscending;
// Item is column clicked
sortItem = pNMListView->iSubItem;
// Save new preferences
theApp.glob_prefs->SetColumnSortItem(CPreferences::tableDownload, sortItem);
theApp.glob_prefs->SetColumnSortAscending(CPreferences::tableDownload, sortAscending);
// Sort table
SetSortArrow(sortItem, sortAscending);
SortItems(SortProc, sortItem + (sortAscending ? 0:100));
*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 {
CUpDownClient* client1 = (CUpDownClient*)item1->value;
CUpDownClient* client2 = (CUpDownClient*)item2->value;
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;
comp = Compare(client1, client2, lParamSort,sortMod);
}
return sortMod * comp;
}
void CDownloadListCtrl::ClearCompleted(){
// 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 && CheckShowItemInGivenCat(file,curTab))
RemoveFile(file);
}
}
}
void CDownloadListCtrl::SetStyle() {
if (theApp.glob_prefs->IsDoubleClickEnabled())
SetExtendedStyle(LVS_EX_FULLROWSELECT);
else
SetExtendedStyle(LVS_EX_ONECLICKACTIVATE | LVS_EX_FULLROWSELECT);
}
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(CPartFile* file1, CPartFile* file2, LPARAM lParamSort) {
switch(lParamSort){
case 0: //filename asc
return strcmpi(file1->GetFileName(),file2->GetFileName());
case 1: //size asc
return file1->GetFileSize() - file2->GetFileSize();
case 2: //transfered asc
return file1->GetTransfered() - file2->GetTransfered();
case 3: //completed asc
return file1->GetCompletedSize() - file2->GetCompletedSize();
case 4: //speed asc
return 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
return file1->getPartfileStatusRang()-file2->getPartfileStatusRang();
case 9: //Remaining Time asc
return file1->getTimeRemaining()-file2->getTimeRemaining() ;
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;
default:
return 0;
}
}
int CDownloadListCtrl::Compare(CUpDownClient *client1, 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 strcmpi(client1->GetUserName(),client2->GetUserName());
case 1: //size but we use status asc
return client1->GetDownloadState() - client2->GetDownloadState();
case 2://transfered asc
case 3://completed asc
return client1->GetTransferedDown() - client2->GetTransferedDown();
case 4: //speed asc
return client1->GetDownloadDatarate() - client2->GetDownloadDatarate();
case 5: //progress asc
return client1->GetAvailablePartCount() - client2->GetAvailablePartCount();
case 6:
if( client1->GetClientSoft() == client2->GetClientSoft() )
return client2->GetVersion() - client1->GetVersion();
return client1->GetClientSoft() - client2->GetClientSoft();
case 7: //qr asc
if(client1->GetRemoteQueueRank() == 0 && client1->GetDownloadState() == DS_ONQUEUE && client1->IsRemoteQueueFull() == true) return 1;
if(client2->GetRemoteQueueRank() == 0 && client2->GetDownloadState() == DS_ONQUEUE && client2->IsRemoteQueueFull() == true) return -1;
if(client1->GetRemoteQueueRank() == 0) return 1;
if(client2->GetRemoteQueueRank() == 0) return -1;
return client1->GetRemoteQueueRank() - client2->GetRemoteQueueRank();
case 8:
if( client1->GetDownloadState() == client2->GetDownloadState() ){
if( client1->IsRemoteQueueFull() )
return 1;
if( client2->IsRemoteQueueFull() )
return -1;
else
return 0;
}
return client1->GetDownloadState() - client2->GetDownloadState();
default:
return 0;
}
}
void CDownloadListCtrl::CreateMenues() {
if (m_PrioMenu) m_PrioMenu.DestroyMenu();
if (m_FileMenu) m_FileMenu.DestroyMenu();
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));
m_FileMenu.CreatePopupMenu();
m_FileMenu.AddMenuTitle(GetResString(IDS_DOWNLOADMENUTITLE));
m_FileMenu.AppendMenu(MF_STRING|MF_POPUP,(UINT_PTR)m_PrioMenu.m_hMenu, GetResString(IDS_PRIORITY) );
m_FileMenu.AppendMenu(MF_STRING,MP_CANCEL,GetResString(IDS_MAIN_BTN_CANCEL) );
m_FileMenu.AppendMenu(MF_STRING,MP_STOP, GetResString(IDS_DL_STOP));
m_FileMenu.AppendMenu(MF_STRING,MP_PAUSE, GetResString(IDS_DL_PAUSE));
m_FileMenu.AppendMenu(MF_STRING,MP_RESUME, GetResString(IDS_DL_RESUME));
m_FileMenu.AppendMenu(MF_SEPARATOR);
m_FileMenu.AppendMenu(MF_STRING,MP_OPEN, GetResString(IDS_DL_OPEN) );//<--9/21/02
m_FileMenu.AppendMenu(MF_STRING,MP_PREVIEW, GetResString(IDS_DL_PREVIEW) );
m_FileMenu.AppendMenu(MF_STRING,MP_METINFO, GetResString(IDS_DL_INFO) );//<--9/21/02
m_FileMenu.AppendMenu(MF_STRING,MP_VIEWFILECOMMENTS, GetResString(IDS_CMT_SHOWALL) );
m_FileMenu.AppendMenu(MF_SEPARATOR);
m_FileMenu.AppendMenu(MF_STRING,MP_CLEARCOMPLETED, GetResString(IDS_DL_CLEAR));
m_FileMenu.AppendMenu(MF_STRING,MP_GETED2KLINK, GetResString(IDS_DL_LINK1) );
m_FileMenu.AppendMenu(MF_STRING,MP_GETHTMLED2KLINK, GetResString(IDS_DL_LINK2));
m_FileMenu.AppendMenu(MF_SEPARATOR);
SetMenu(&m_FileMenu);
}
CString CDownloadListCtrl::getTextList() {
CString out="";
// Search for file(s)
for(ListItems::iterator it = m_ListItems.begin(); it != m_ListItems.end(); it++){ // const is better
CtrlItem_Struct* cur_item = it->second;
if(cur_item->type == FILE_TYPE){
CPartFile* file = reinterpret_cast<CPartFile*>(cur_item->value);
theApp.emuledlg->AddLogLine(false, file->GetFileName());
char buffer[50+1];
ASSERT(file->GetFileName() != NULL);
strncpy(buffer, file->GetFileName(), 50);
buffer[50] = '\0';
CString temp;
temp.Format("\n%s\t [%.1f%%] %i/%i - %s",
buffer,
file->GetPercentCompleted(),
file->GetTransferingSrcCount(),
file->GetSourceCount(),
file->getPartfileStatus());
out += temp;
}
}
theApp.emuledlg->AddLogLine(false, out);
return out;
}
void CDownloadListCtrl::ShowFilesCount() {
CString counter;
uint16 count=0;//theApp.downloadqueue->GetFileCount();
for(ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end(); it++){
const CtrlItem_Struct* cur_item = it->second;
if (cur_item->type == FILE_TYPE){
CPartFile* file=(CPartFile*)cur_item->value;
if (file->GetCategory()==curTab ||
(!theApp.glob_prefs->ShowAllNotCats() && file->GetCategory()>0 && curTab==0 ) ) count++;
}
}
counter.Format("%s (%u)", GetResString(IDS_TW_DOWNLOADS),count);
theApp.emuledlg->transferwnd.GetDlgItem(IDC_DOWNLOAD_TEXT)->SetWindowText(counter);
}
void CDownloadListCtrl::ShowSelectedFileDetails() {
POINT point;
::GetCursorPos(&point);
CPoint p = point;
ScreenToClient(&p);
int it = HitTest(p);
SetSelectionMark(it); // display selection mark correctly!
if (it == -1) return;
CtrlItem_Struct* content = (CtrlItem_Struct*)this->GetItemData(GetSelectionMark());
if (content->type == FILE_TYPE){
CPartFile* file = (CPartFile*)content->value;
if ((file->HasComment() || file->HasRating()) && p.x<13 ) {
CCommentDialogLst dialog(file);
dialog.DoModal();
}
else {
CFileDetailDialog dialog(file);
dialog.DoModal();
}
}else {
CUpDownClient* client = (CUpDownClient*)content->value;
CClientDetailDialog dialog(client);
dialog.DoModal();
}
}
void CDownloadListCtrl::ChangeCategory(int newsel){
SetRedraw(FALSE);
// remove all displayed files with a different cat and show the correct ones
for(ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end(); it++){
const CtrlItem_Struct* cur_item = it->second;
if (cur_item->type == FILE_TYPE){
CPartFile* file = reinterpret_cast<CPartFile*>(cur_item->value);
if ( (newsel>0 && newsel!=file->GetCategory()) ||
(theApp.glob_prefs->ShowAllNotCats() && newsel==0 && file->GetCategory()>0) ) HideFile(file);
else if (CheckShowItemInGivenCat(file,newsel)) ShowFile(file);
}
}
SetRedraw(TRUE);
curTab=newsel;
ShowFilesCount();
}
void CDownloadListCtrl::HideFile(CPartFile* tohide){
HideSources(tohide);
// Retrieve all entries matching the source
std::pair<ListItems::const_iterator, ListItems::const_iterator> rangeIt = m_ListItems.equal_range(tohide);
for(ListItems::const_iterator it = rangeIt.first; it != rangeIt.second; it++){
CtrlItem_Struct* updateItem = it->second;
// Find entry in CListCtrl and update object
LVFINDINFO find;
find.flags = LVFI_PARAM;
find.lParam = (LPARAM)updateItem;
sint16 result = FindItem(&find);
if(result != (-1)) {
DeleteItem(result);
return;
}
}
}
void CDownloadListCtrl::ShowFile(CPartFile* toshow){
// Retrieve all entries matching the source
std::pair<ListItems::const_iterator, ListItems::const_iterator> rangeIt = m_ListItems.equal_range(toshow);
for(ListItems::const_iterator it = rangeIt.first; it != rangeIt.second; it++){
CtrlItem_Struct* updateItem = it->second;
// Check if entry is already in the List
LVFINDINFO find;
find.flags = LVFI_PARAM;
find.lParam = (LPARAM)updateItem;
sint16 result = FindItem(&find);
if(result == (-1))
InsertItem(LVIF_PARAM,GetItemCount(),0,0,0,0,(LPARAM)updateItem);
return;
}
}
//Checks, if a given item should be shown in a given category
bool CDownloadListCtrl::CheckShowItemInGivenCat(CPartFile* file,int inCategory) {
return ( ((inCategory==0 && !theApp.glob_prefs->ShowAllNotCats()) ||
(inCategory==0 && theApp.glob_prefs->ShowAllNotCats() && file->GetCategory()==0 )) ||
( inCategory>0 && inCategory==file->GetCategory() ) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -