📄 sharedfilesctrl.cpp
字号:
break;
case 5:
buffer.Format(_T("%u (%u)"), file->statistic.GetRequests(), file->statistic.GetAllTimeRequests());
break;
case 6:
buffer.Format(_T("%u (%u)"), file->statistic.GetAccepts(), file->statistic.GetAllTimeAccepts());
break;
case 7:
buffer.Format(_T("%s (%s)"), CastItoXBytes(file->statistic.GetTransferred(), false, false), CastItoXBytes(file->statistic.GetAllTimeTransferred(), false, false));
break;
case 8:
if( file->GetPartCount()){
cur_rec.bottom--;
cur_rec.top++;
file->DrawShareStatusBar(dc,&cur_rec,false,thePrefs.UseFlatBar());
cur_rec.bottom++;
cur_rec.top--;
}
break;
case 9:
buffer = file->GetPath();
PathRemoveBackslash(buffer.GetBuffer());
buffer.ReleaseBuffer();
break;
case 10:
if (file->m_nCompleteSourcesCountLo == 0){
buffer.Format(_T("< %u"), file->m_nCompleteSourcesCountHi);
}
else if (file->m_nCompleteSourcesCountLo == file->m_nCompleteSourcesCountHi)
buffer.Format(_T("%u"), file->m_nCompleteSourcesCountLo);
else
buffer.Format(_T("%u - %u"), file->m_nCompleteSourcesCountLo, file->m_nCompleteSourcesCountHi);
break;
case 11:{
if(file->GetPublishedED2K())
buffer = GetResString(IDS_YES);
else
buffer = GetResString(IDS_NO);
buffer += _T("|");
if( (uint32)time(NULL)-file->GetLastPublishTimeKadSrc() < KADEMLIAREPUBLISHTIMES )
buffer += GetResString(IDS_YES);
else
buffer += GetResString(IDS_NO);
//buffer += "|"; //VeryCD
//if( (uint32)time(NULL)-file->GetLastPublishTimeKad2Src() < KADEMLIAREPUBLISHTIMES )
// buffer += GetResString(IDS_YES);
//else
// buffer += GetResString(IDS_NO);
break;
}
}
if( iColumn != 8 )
dc->DrawText(buffer, buffer.GetLength(),&cur_rec,uDTFlags);
if( iColumn == 0 )
cur_rec.left -= iIconDrawWidth;
cur_rec.left += GetColumnWidth(iColumn);
}
}
ShowFilesCount();
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(m_crWindow));
outline_rec.top++;
outline_rec.bottom--;
outline_rec.left++;
outline_rec.right--;
if (lpDrawItemStruct->itemID > 0 && GetItemState(lpDrawItemStruct->itemID - 1, LVIS_SELECTED))
outline_rec.top--;
if (lpDrawItemStruct->itemID + 1 < (UINT)GetItemCount() && GetItemState(lpDrawItemStruct->itemID + 1, LVIS_SELECTED))
outline_rec.bottom++;
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);
}
void CSharedFilesCtrl::ShowFile(const CKnownFile* file)
{
if (InsertItem(LVIF_TEXT|LVIF_PARAM,GetItemCount(),LPSTR_TEXTCALLBACK,0,0,0,(LPARAM)file) >= 0)
UpdateFile(file);
}
void CSharedFilesCtrl::RemoveFile(const CKnownFile *toRemove)
{
LVFINDINFO info;
info.flags = LVFI_PARAM;
info.lParam = (LPARAM)toRemove;
int nItem = FindItem(&info);
if(nItem != -1)
DeleteItem(nItem);
ShowFilesCount();
}
BEGIN_MESSAGE_MAP(CSharedFilesCtrl, CMuleListCtrl)
ON_WM_CONTEXTMENU()
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnClick)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk)
ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
// CSharedFilesCtrl message handlers
void CSharedFilesCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
// get merged settings
bool bFirstItem = true;
int iSelectedItems = GetSelectedCount();
int iCompleteFileSelected = -1;
UINT uPrioMenuItem = 0;
const CKnownFile* pSingleSelFile = NULL;
POSITION pos = GetFirstSelectedItemPosition();
while (pos)
{
const CKnownFile* pFile = (CKnownFile*)GetItemData(GetNextSelectedItem(pos));
if (bFirstItem)
pSingleSelFile = pFile;
else
pSingleSelFile = NULL;
int iCurCompleteFile = pFile->IsPartFile() ? 0 : 1;
if (bFirstItem)
iCompleteFileSelected = iCurCompleteFile;
else if (iCompleteFileSelected != iCurCompleteFile)
iCompleteFileSelected = -1;
UINT uCurPrioMenuItem = 0;
if (pFile->IsAutoUpPriority())
uCurPrioMenuItem = MP_PRIOAUTO;
else if (pFile->GetUpPriority() == PR_VERYLOW)
uCurPrioMenuItem = MP_PRIOVERYLOW;
else if (pFile->GetUpPriority() == PR_LOW)
uCurPrioMenuItem = MP_PRIOLOW;
else if (pFile->GetUpPriority() == PR_NORMAL)
uCurPrioMenuItem = MP_PRIONORMAL;
else if (pFile->GetUpPriority() == PR_HIGH)
uCurPrioMenuItem = MP_PRIOHIGH;
else if (pFile->GetUpPriority() == PR_VERYHIGH)
uCurPrioMenuItem = MP_PRIOVERYHIGH;
else
ASSERT(0);
if (bFirstItem)
uPrioMenuItem = uCurPrioMenuItem;
else if (uPrioMenuItem != uCurPrioMenuItem)
uPrioMenuItem = 0;
bFirstItem = false;
}
m_SharedFilesMenu.EnableMenuItem((UINT_PTR)m_PrioMenu.m_hMenu, iSelectedItems > 0 ? MF_ENABLED : MF_GRAYED);
m_PrioMenu.CheckMenuRadioItem(MP_PRIOVERYLOW, MP_PRIOAUTO, uPrioMenuItem, 0);
bool bSingleCompleteFileSelected = (iSelectedItems == 1 && iCompleteFileSelected == 1);
m_SharedFilesMenu.EnableMenuItem(MP_OPEN, bSingleCompleteFileSelected ? MF_ENABLED : MF_GRAYED);
UINT uInsertedMenuItem = 0;
static const TCHAR _szSkinPkgSuffix[] = _T(".") EMULSKIN_BASEEXT _T(".zip");
if (bSingleCompleteFileSelected
&& pSingleSelFile
&& pSingleSelFile->GetFilePath().Right(ARRSIZE(_szSkinPkgSuffix)-1).CompareNoCase(_szSkinPkgSuffix) == 0)
{
MENUITEMINFO mii = {0};
mii.cbSize = sizeof mii;
mii.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID;
mii.fType = MFT_STRING;
mii.fState = MFS_ENABLED;
mii.wID = MP_INSTALL_SKIN;
CString strBuff(GetResString(IDS_INSTALL_SKIN));
mii.dwTypeData = const_cast<LPTSTR>((LPCTSTR)strBuff);
if (::InsertMenuItem(m_SharedFilesMenu, MP_OPENFOLDER, FALSE, &mii))
uInsertedMenuItem = mii.wID;
}
m_SharedFilesMenu.EnableMenuItem(MP_OPENFOLDER, bSingleCompleteFileSelected ? MF_ENABLED : MF_GRAYED);
m_SharedFilesMenu.EnableMenuItem(MP_RENAME, bSingleCompleteFileSelected ? MF_ENABLED : MF_GRAYED);
m_SharedFilesMenu.EnableMenuItem(MP_REMOVE, iCompleteFileSelected > 0 ? MF_ENABLED : MF_GRAYED);
m_SharedFilesMenu.SetDefaultItem(bSingleCompleteFileSelected ? MP_OPEN : -1);
m_SharedFilesMenu.EnableMenuItem(MP_CMT, iSelectedItems == 1 ? MF_ENABLED : MF_GRAYED);
m_SharedFilesMenu.EnableMenuItem(MP_DETAIL, iSelectedItems > 0 ? MF_ENABLED : MF_GRAYED);
m_SharedFilesMenu.EnableMenuItem(MP_SHOWED2KLINK, iSelectedItems > 0 ? MF_ENABLED : MF_GRAYED);
#if defined(_DEBUG)
//JOHNTODO: Not for release as we need kad lowID users in the network to see how well this work work. Also, we do not support these links yet.
if (iSelectedItems > 0 && theApp.IsConnected() && theApp.IsFirewalled() && theApp.clientlist->GetBuddy())
m_SharedFilesMenu.EnableMenuItem(MP_GETKADSOURCELINK, MF_ENABLED);
else
m_SharedFilesMenu.EnableMenuItem(MP_GETKADSOURCELINK, MF_GRAYED);
#endif
m_SharedFilesMenu.EnableMenuItem(Irc_SetSendLink, iSelectedItems == 1 && theApp.emuledlg->ircwnd->IsConnected() ? MF_ENABLED : MF_GRAYED);
CTitleMenu WebMenu;
WebMenu.CreateMenu();
WebMenu.AddMenuTitle(NULL, true);
int iWebMenuEntries = theWebServices.GetFileMenuEntries(&WebMenu);
UINT flag2 = (iWebMenuEntries == 0 || iSelectedItems != 1) ? MF_GRAYED : MF_STRING;
m_SharedFilesMenu.AppendMenu(flag2 | MF_POPUP, (UINT_PTR)WebMenu.m_hMenu, GetResString(IDS_WEBSERVICES), _T("WEB"));
GetPopupMenuPos(*this, point);
m_SharedFilesMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON,point.x,point.y,this);
m_SharedFilesMenu.RemoveMenu(m_SharedFilesMenu.GetMenuItemCount()-1,MF_BYPOSITION);
VERIFY( WebMenu.DestroyMenu() );
if (uInsertedMenuItem)
VERIFY( m_SharedFilesMenu.RemoveMenu(uInsertedMenuItem, MF_BYCOMMAND) );
}
BOOL CSharedFilesCtrl::OnCommand(WPARAM wParam, LPARAM lParam)
{
CTypedPtrList<CPtrList, CKnownFile*> selectedList;
POSITION pos = GetFirstSelectedItemPosition();
while (pos != NULL){
int index = GetNextSelectedItem(pos);
if (index >= 0)
selectedList.AddTail((CKnownFile*)GetItemData(index));
}
if (selectedList.GetCount() > 0)
{
CKnownFile* file = NULL;
if (selectedList.GetCount() == 1)
file = selectedList.GetHead();
switch (wParam){
case Irc_SetSendLink:
if (file)
theApp.emuledlg->ircwnd->SetSendFileString(CreateED2kLink(file));
break;
case MP_GETED2KLINK:{
CString str;
POSITION pos = selectedList.GetHeadPosition();
while (pos != NULL)
{
file = selectedList.GetNext(pos);
if (!str.IsEmpty())
str += _T("\r\n");
str += CreateED2kLink(file);
}
theApp.CopyTextToClipboard(str);
break;
}
#if defined(_DEBUG)
//JOHNTODO: Not for release as we need kad lowID users in the network to see how well this work work. Also, we do not support these links yet.
case MP_GETKADSOURCELINK:{
CString str;
POSITION pos = selectedList.GetHeadPosition();
while (pos != NULL)
{
file = selectedList.GetNext(pos);
if (!str.IsEmpty())
str += _T("\r\n");
str += theApp.CreateKadSourceLink(file);
}
theApp.CopyTextToClipboard(str);
break;
}
#endif
// file operations
case MP_OPEN:
if (file && !file->IsPartFile())
OpenFile(file);
break;
case MP_INSTALL_SKIN:
if (file && !file->IsPartFile())
InstallSkin(file->GetFilePath());
break;
case MP_OPENFOLDER:
if (file && !file->IsPartFile()){
CString path = file->GetPath();
int bspos = path.ReverseFind(_T('\\'));
ShellExecute(NULL, _T("open"), path.Left(bspos), NULL, NULL, SW_SHOW);
}
break;
case MP_RENAME:
case MPG_F2:
if (file && !file->IsPartFile()){
InputBox inputbox;
CString title = GetResString(IDS_RENAME);
title.Remove(_T('&'));
inputbox.SetLabels(title, GetResString(IDS_DL_FILENAME), file->GetFileName());
inputbox.SetEditFilenameMode();
inputbox.DoModal();
CString newname = inputbox.GetInput();
if (!inputbox.WasCancelled() && newname.GetLength()>0)
{
// at least prevent users from specifying something like "..\dir\file"
static const TCHAR _szInvFileNameChars[] = _T("\\/:*?\"<>|");
if (newname.FindOneOf(_szInvFileNameChars) != -1){
AfxMessageBox(GetErrorMessage(ERROR_BAD_PATHNAME));
break;
}
CString newpath;
PathCombine(newpath.GetBuffer(MAX_PATH), file->GetPath(), newname);
newpath.ReleaseBuffer();
if (_trename(file->GetFilePath(), newpath) != 0){
CString strError;
strError.Format(GetResString(IDS_ERR_RENAMESF), file->GetFilePath(), newpath, strerror(errno));
AfxMessageBox(strError);
break;
}
if (file->IsKindOf(RUNTIME_CLASS(CPartFile)))
file->SetFileName(newname);
else
{
theApp.sharedfiles->RemoveKeywords(file);
file->SetFileName(newname);
theApp.sharedfiles->AddKeywords(file);
}
file->SetFilePath(newpath);
UpdateFile(file);
}
}
else if (wParam == MPG_F2)
MessageBeep((UINT)-1);
break;
case MP_REMOVE:
case MPG_DELETE:{
if (IDNO == AfxMessageBox(GetResString(IDS_CONFIRM_FILEDELETE),MB_ICONWARNING | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_YESNO))
return TRUE;
while (!selectedList.IsEmpty())
{
CKnownFile* myfile = selectedList.GetHead();
selectedList.RemoveHead();
if (!myfile || myfile->IsPartFile())
continue;
bool delsucc = false;
if (!PathFileExists(myfile->GetFilePath()))
delsucc = true;
else{
// Delete
if (!thePrefs.GetRemoveToBin()){
delsucc = DeleteFile(myfile->GetFilePath());
}
else{
// delete to recycle bin :(
TCHAR todel[MAX_PATH+1];
memset(todel, 0, sizeof todel);
_tcsncpy(todel, myfile->GetFilePath(), ARRSIZE(todel)-2);
SHFILEOPSTRUCT fp = {0};
fp.wFunc = FO_DELETE;
fp.hwnd = theApp.emuledlg->m_hWnd;
fp.pFrom = todel;
fp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT;// | FOF_NOERRORUI
delsucc = (SHFileOperation(&fp) == 0);
}
}
if (delsucc){
theApp.sharedfiles->RemoveFile(myfile);
if (myfile->IsKindOf(RUNTIME_CLASS(CPartFile)))
theApp.emuledlg->transferwnd->downloadlistctrl.ClearCompleted(static_cast<CPartFile*>(myfile));
}
else{
CString strError;
strError.Format(_T("Failed to delete file \"%s\"\r\n\r\n%s"), myfile->GetFilePath(), GetErrorMessage(GetLastError()));
AfxMessageBox(strError);
}
}
break;
}
case MP_CMT:
if (file)
ShowComments(file);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -