📄 downloadlistctrl.cpp
字号:
DeleteItem(i--);
post++;
}
}
if (pre-post==0) toCollapse->srcarevisible = false;
SetRedraw(true);
}
BEGIN_MESSAGE_MAP(CDownloadListCtrl, CMuleListCtrl)
ON_WM_CONTEXTMENU()
ON_WM_SYSCOLORCHANGE()
ON_NOTIFY_REFLECT(LVN_ITEMACTIVATE, OnItemActivate)
ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnListModified)
ON_NOTIFY_REFLECT(LVN_INSERTITEM, OnListModified)
ON_NOTIFY_REFLECT(LVN_DELETEITEM, OnListModified)
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnClick)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkDownloadlist)
ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)
ON_NOTIFY_REFLECT(LVN_GETINFOTIP, OnLvnGetInfoTip)
END_MESSAGE_MAP()
void CDownloadListCtrl::ExpandCollapseItem(int item,uint8 expand,bool collapsesource){
if (item==-1) return;
CtrlItem_Struct* content = (CtrlItem_Struct*)this->GetItemData(item);
// modifier-keys -view filtering [Ese Juani+xrmb]
bool isShift=GetAsyncKeyState(VK_SHIFT) < 0;
bool isCtrl=GetAsyncKeyState(VK_CONTROL) < 0;
bool isAlt=GetAsyncKeyState(VK_MENU) < 0;
if (collapsesource && content->parent!=NULL) {// to collapse/expand files when one of its source is selected
content=content->parent;
LVFINDINFO find;
find.flags = LVFI_PARAM;
find.lParam = (LPARAM)content;
item = FindItem(&find);
if (item==-1) return;
}
if (!content || content->type != FILE_TYPE) return;
CPartFile* partfile = reinterpret_cast<CPartFile*>(content->value);
if (!partfile) return;
if (partfile->GetStatus()==PS_COMPLETE) {
TCHAR* buffer = new TCHAR[MAX_PATH];
_stprintf(buffer,_T("%s"),partfile->GetFullName());
ShellOpenFile(buffer, NULL);
delete[] buffer;
return;
}
// Check if the source branch is disable
if(partfile->srcarevisible == false ) {
if (expand>COLLAPSE_ONLY){
SetRedraw(false);
// Go throught the whole list to find out the sources for this file
// Remark: don't use GetSourceCount() => UNAVAILABLE_SOURCE
for(ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end(); it++){
const CtrlItem_Struct* cur_item = it->second;
if(cur_item->owner == partfile){
if(isShift || isCtrl || isAlt) {
ASSERT(cur_item->type != FILE_TYPE);
EDownloadState ds=((CUpDownClient*)cur_item->value)->GetDownloadState();
if(!(isShift && ds==DS_DOWNLOADING ||
isCtrl && ((CUpDownClient*)cur_item->value)->GetRemoteQueueRank()>0 ||
isAlt && ds!=DS_NONEEDEDPARTS))
continue; // skip this source
}
partfile->srcarevisible = true;
InsertItem(LVIF_PARAM|LVIF_TEXT,item+1,LPSTR_TEXTCALLBACK,0,0,0,(LPARAM)cur_item);
}
}
SetRedraw(true);
}
}
else {
if (expand==EXPAND_COLLAPSE || expand==COLLAPSE_ONLY) HideSources(partfile,isShift,isCtrl,isAlt);
}
}
// CDownloadListCtrl message handlers
void CDownloadListCtrl::OnItemActivate(NMHDR *pNMHDR, LRESULT *pResult){
LPNMITEMACTIVATE pNMIA = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
if (thePrefs.IsDoubleClickEnabled() || pNMIA->iSubItem > 0)
ExpandCollapseItem(pNMIA->iItem,2);
*pResult = 0;
}
void CDownloadListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
int iSel = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
if (iSel != -1)
{
const CtrlItem_Struct* content = (CtrlItem_Struct*)GetItemData(iSel);
if (content->type == FILE_TYPE)
{
// get merged settings
bool bFirstItem = true;
int iSelectedItems = 0;
int iFilesNotDone = 0;
int iFilesToPause = 0;
int iFilesToStop = 0;
int iFilesToResume = 0;
int iFilesToOpen = 0;
int iFilesGetPreviewParts = 0;
int iFilesPreviewType = 0;
int iFilesToPreview = 0;
int iFilesA4AFAuto = 0;
UINT uPrioMenuItem = 0;
const CPartFile* file1 = NULL;
POSITION pos = GetFirstSelectedItemPosition();
while (pos)
{
const CtrlItem_Struct* pItemData = (CtrlItem_Struct*)GetItemData(GetNextSelectedItem(pos));
if (pItemData->type != FILE_TYPE)
continue;
const CPartFile* pFile = (CPartFile*)pItemData->value;
if (bFirstItem)
file1 = pFile;
iSelectedItems++;
bool bFileDone = (pFile->GetStatus()==PS_COMPLETE || pFile->GetStatus()==PS_COMPLETING);
iFilesNotDone += !bFileDone ? 1 : 0;
iFilesToStop += pFile->CanStopFile() ? 1 : 0;
iFilesToPause += pFile->CanPauseFile() ? 1 : 0;
iFilesToResume += pFile->CanResumeFile() ? 1 : 0;
iFilesToOpen += pFile->CanOpenFile() ? 1 : 0;
iFilesGetPreviewParts += pFile->GetPreviewPrio() ? 1 : 0;
iFilesPreviewType += pFile->IsPreviewableFileType() ? 1 : 0;
iFilesToPreview += pFile->IsReadyForPreview() ? 1 : 0;
iFilesA4AFAuto += (!bFileDone && pFile->IsA4AFAuto()) ? 1 : 0;
UINT uCurPrioMenuItem = 0;
if (pFile->IsAutoDownPriority())
uCurPrioMenuItem = MP_PRIOAUTO;
else if (pFile->GetDownPriority() == PR_HIGH)
uCurPrioMenuItem = MP_PRIOHIGH;
else if (pFile->GetDownPriority() == PR_NORMAL)
uCurPrioMenuItem = MP_PRIONORMAL;
else if (pFile->GetDownPriority() == PR_LOW)
uCurPrioMenuItem = MP_PRIOLOW;
else
ASSERT(0);
if (bFirstItem)
uPrioMenuItem = uCurPrioMenuItem;
else if (uPrioMenuItem != uCurPrioMenuItem)
uPrioMenuItem = 0;
bFirstItem = false;
}
m_FileMenu.EnableMenuItem((UINT_PTR)m_PrioMenu.m_hMenu, iFilesNotDone > 0 ? MF_ENABLED : MF_GRAYED);
m_PrioMenu.CheckMenuRadioItem(MP_PRIOLOW, MP_PRIOAUTO, uPrioMenuItem, 0);
// enable commands if there is at least one item which can be used for the action
m_FileMenu.EnableMenuItem(MP_CANCEL, iFilesNotDone > 0 ? MF_ENABLED : MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_STOP, iFilesToStop > 0 ? MF_ENABLED : MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_PAUSE, iFilesToPause > 0 ? MF_ENABLED : MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_RESUME, iFilesToResume > 0 ? MF_ENABLED : MF_GRAYED);
bool bOpenEnabled = (iSelectedItems == 1 && iFilesToOpen == 1);
m_FileMenu.EnableMenuItem(MP_OPEN, bOpenEnabled ? MF_ENABLED : MF_GRAYED);
if(thePrefs.IsExtControlsEnabled() && !thePrefs.GetPreviewPrio()) {
m_FileMenu.EnableMenuItem(MP_TRY_TO_GET_PREVIEW_PARTS, (iSelectedItems == 1 && iFilesPreviewType == 1 && iFilesToPreview == 0 && iFilesNotDone == 1) ? MF_ENABLED : MF_GRAYED);
m_FileMenu.CheckMenuItem(MP_TRY_TO_GET_PREVIEW_PARTS, (iSelectedItems == 1 && iFilesGetPreviewParts == 1) ? MF_CHECKED : MF_UNCHECKED);
}
m_FileMenu.EnableMenuItem(MP_PREVIEW, (iSelectedItems == 1 && iFilesToPreview == 1) ? MF_ENABLED : MF_GRAYED);
CMenu PreviewMenu;
PreviewMenu.CreateMenu();
int iPreviewMenuEntries = thePreviewApps.GetAllMenuEntries(PreviewMenu, (iSelectedItems == 1) ? file1 : NULL);
if (iPreviewMenuEntries)
m_FileMenu.InsertMenu(MP_METINFO, MF_POPUP | (iSelectedItems == 1 ? MF_ENABLED : MF_GRAYED), (UINT_PTR)PreviewMenu.m_hMenu, GetResString(IDS_DL_PREVIEW));
bool bDetailsEnabled = (iSelectedItems > 0);
m_FileMenu.EnableMenuItem(MP_METINFO, bDetailsEnabled ? MF_ENABLED : MF_GRAYED);
if (thePrefs.IsDoubleClickEnabled() && bOpenEnabled)
m_FileMenu.SetDefaultItem(MP_OPEN);
else if (!thePrefs.IsDoubleClickEnabled() && bDetailsEnabled)
m_FileMenu.SetDefaultItem(MP_METINFO);
else
m_FileMenu.SetDefaultItem((UINT)-1);
m_FileMenu.EnableMenuItem(MP_VIEWFILECOMMENTS, (iSelectedItems == 1 && iFilesNotDone == 1) ? MF_ENABLED : MF_GRAYED);
int total;
m_FileMenu.EnableMenuItem(MP_CLEARCOMPLETED, GetCompleteDownloads(curTab, total) > 0 ? MF_ENABLED : MF_GRAYED);
m_FileMenu.EnableMenuItem((UINT_PTR)m_A4AFMenu.m_hMenu, (iSelectedItems == 1 && iFilesNotDone == 1) ? MF_ENABLED : MF_GRAYED);
m_A4AFMenu.CheckMenuItem(MP_ALL_A4AF_AUTO, (iSelectedItems == 1 && iFilesNotDone == 1 && iFilesA4AFAuto == 1) ? MF_CHECKED : MF_UNCHECKED);
if (thePrefs.IsExtControlsEnabled())
m_FileMenu.EnableMenuItem(MP_ADDSOURCE, (iSelectedItems == 1 && iFilesToStop == 1) ? MF_ENABLED : MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_SHOWED2KLINK, iSelectedItems > 0 ? MF_ENABLED : MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_PASTE, theApp.IsEd2kFileLinkInClipboard() ? MF_ENABLED : MF_GRAYED);
CMenu WebMenu;
WebMenu.CreateMenu();
int iWebMenuEntries = theWebServices.GetFileMenuEntries(WebMenu);
UINT flag = (iWebMenuEntries == 0 || iSelectedItems != 1) ? MF_GRAYED : MF_ENABLED;
m_FileMenu.AppendMenu(MF_POPUP | flag, (UINT_PTR)WebMenu.m_hMenu, GetResString(IDS_WEBSERVICES));
// create cat-submenue
CMenu CatsMenu;
CatsMenu.CreateMenu();
flag = (thePrefs.GetCatCount() == 1) ? MF_GRAYED : MF_ENABLED;
if (thePrefs.GetCatCount()>1) {
for (int i = 0; i < thePrefs.GetCatCount(); i++)
CatsMenu.AppendMenu(MF_STRING,MP_ASSIGNCAT+i, (i==0)?GetResString(IDS_CAT_UNASSIGN):thePrefs.GetCategory(i)->title);
}
m_FileMenu.AppendMenu(MF_POPUP | flag, (UINT_PTR)CatsMenu.m_hMenu, GetResString(IDS_TOCAT));
GetPopupMenuPos(*this, point);
m_FileMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
VERIFY( m_FileMenu.RemoveMenu(m_FileMenu.GetMenuItemCount() - 1, MF_BYPOSITION) );
VERIFY( m_FileMenu.RemoveMenu(m_FileMenu.GetMenuItemCount() - 1, MF_BYPOSITION) );
if (iPreviewMenuEntries)
VERIFY( m_FileMenu.RemoveMenu((UINT)PreviewMenu.m_hMenu, MF_BYCOMMAND) );
VERIFY( WebMenu.DestroyMenu() );
VERIFY( CatsMenu.DestroyMenu() );
VERIFY( PreviewMenu.DestroyMenu() );
}
else{
const CUpDownClient* client = (CUpDownClient*)content->value;
CTitleMenu ClientMenu;
ClientMenu.CreatePopupMenu();
ClientMenu.AddMenuTitle(GetResString(IDS_CLIENTS));
ClientMenu.AppendMenu(MF_STRING, 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));
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));
CMenu A4AFMenu;
A4AFMenu.CreateMenu();
if (thePrefs.IsExtControlsEnabled()) {
// ZZ:DownloadManager -->
if (content->type == UNAVAILABLE_SOURCE) {
A4AFMenu.AppendMenu(MF_STRING,MP_A4AF_CHECK_THIS_NOW,GetResString(IDS_A4AF_CHECK_THIS_NOW));
}
// <-- ZZ:DownloadManager
if (A4AFMenu.GetMenuItemCount()>0)
ClientMenu.AppendMenu(MF_STRING|MF_POPUP,(UINT_PTR)A4AFMenu.m_hMenu, GetResString(IDS_A4AF));
}
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);
VERIFY( A4AFMenu.DestroyMenu() );
VERIFY( ClientMenu.DestroyMenu() );
}
}
else{
int total;
m_FileMenu.EnableMenuItem((UINT_PTR)m_PrioMenu.m_hMenu, MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_CANCEL,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_PAUSE,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_STOP,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_RESUME,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_OPEN, MF_GRAYED);
if(thePrefs.IsExtControlsEnabled() && !thePrefs.GetPreviewPrio()) {
m_FileMenu.EnableMenuItem(MP_TRY_TO_GET_PREVIEW_PARTS, MF_GRAYED);
m_FileMenu.CheckMenuItem(MP_TRY_TO_GET_PREVIEW_PARTS, MF_UNCHECKED);
}
m_FileMenu.EnableMenuItem(MP_PREVIEW,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_METINFO, MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_VIEWFILECOMMENTS, MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_CLEARCOMPLETED, GetCompleteDownloads(curTab,total) > 0 ? MF_ENABLED : MF_GRAYED);
m_FileMenu.EnableMenuItem((UINT_PTR)m_A4AFMenu.m_hMenu, MF_GRAYED);
if (thePrefs.IsExtControlsEnabled())
m_FileMenu.EnableMenuItem(MP_ADDSOURCE, MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_SHOWED2KLINK, MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_PASTE, theApp.IsEd2kFileLinkInClipboard() ? MF_ENABLED : MF_GRAYED);
m_FileMenu.SetDefaultItem((UINT)-1);
// also show the "Web Services" entry, even if its disabled and therefore not useable, it though looks a little
// less confusing this way.
CMenu WebMenu;
WebMenu.CreateMenu();
int iWebMenuEntries = theWebServices.GetFileMenuEntries(WebMenu);
m_FileMenu.AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)WebMenu.m_hMenu, GetResString(IDS_WEBSERVICES));
GetPopupMenuPos(*this, point);
m_FileMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
m_FileMenu.RemoveMenu(m_FileMenu.GetMenuItemCount() - 1, MF_BYPOSITION);
VERIFY( WebMenu.DestroyMenu() );
}
}
BOOL CDownloadListCtrl::OnCommand(WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
case MP_PASTE:
if (theApp.IsEd2kFileLinkInClipboard())
theApp.PasteClipboard(curTab);
return TRUE;
}
int iSel = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
if (iSel != -1)
{
const CtrlItem_Struct* content = (CtrlItem_Struct*)GetItemData(iSel);
if (content->type == FILE_TYPE)
{
//for multiple selections
UINT selectedCount = 0;
CTypedPtrList<CPtrList, CPartFile*> selectedList;
POSITION pos = GetFirstSelectedItemPosition();
while(pos != NULL)
{
int index = GetNextSelectedItem(pos);
if(index > -1)
{
if (((const CtrlItem_Struct*)GetItemData(index))->type == FILE_TYPE)
{
selectedCount++;
selectedList.AddTail((CPartFile*)((const CtrlItem_Struct*)GetItemData(index))->value);
}
}
}
CPartFile* file = (CPartFile*)content->value;
switch (wParam)
{
case MPG_DELETE:
case MP_CANCEL:
{
//for multiple selections
if(selectedCount > 0)
{
SetRedraw(false);
CString fileList;
bool validdelete = false;
bool removecompl =false;
for (pos = selectedList.GetHeadPosition(); pos != 0; )
{
CPartFile* cur_file = selectedList.GetNext(pos);
if (cur_file->GetStatus() != PS_COMPLETING && cur_file->GetStatus() != PS_COMPLETE){
validdelete = true;
if (selectedCount<50)
fileList.Append(_T("\n") + CString(cur_file->GetFileName()));
} else
if (cur_file->GetStatus() == PS_COMPLETE)
removecompl=true;
}
CString quest;
if (selectedCount==1)
quest=GetResString(IDS_Q_CANCELDL2);
else
quest=GetResString(IDS_Q_CANCELDL);
if ( (removecompl && !validdelete ) || (validdelete && AfxMessageBox(quest + fileList,MB_DEFBUTTON2 | MB_ICONQUESTION|MB_YESNO) == IDYES) )
{
while(!selectedList.IsEmpty())
{
HideSources(selectedList.GetHead());
switch(selectedList.GetHead()->GetStatus()) {
case PS_WAITINGFORHASH:
case PS_HASHING:
case PS_COMPLETING:
selectedList.RemoveHead();
break;
case PS_COMPLETE:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -