📄 sharedfilesctrl.cpp
字号:
theApp.emuledlg->sharedfileswnd->GetDlgItem(IDC_TRAFFIC_TEXT)->SetWindowText(GetResString(IDS_SF_FILES) + str);
}
#define DLC_DT_TEXT (DT_LEFT|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX|DT_END_ELLIPSIS)
void CSharedFilesCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if( !theApp.emuledlg->IsRunning() )
return;
if( !lpDrawItemStruct->itemData)
return;
CDC* odc = CDC::FromHandle(lpDrawItemStruct->hDC);
BOOL bCtrlFocused = ((GetFocus() == this ) || (GetStyle() & LVS_SHOWSELALWAYS));
if( odc && (lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED )){
if(bCtrlFocused)
odc->SetBkColor(m_crHighlight);
else
odc->SetBkColor(m_crNoHighlight);
}
else
odc->SetBkColor(m_crWindow);
/*const*/ CKnownFile* file = (CKnownFile*)lpDrawItemStruct->itemData;
CMemDC dc(CDC::FromHandle(lpDrawItemStruct->hDC), &lpDrawItemStruct->rcItem);
CFont* pOldFont = dc.SelectObject(GetFont());
RECT cur_rec = lpDrawItemStruct->rcItem;
COLORREF crOldTextColor = dc.SetTextColor(m_crWindowText);
int iOldBkMode;
if (m_crWindowTextBk == CLR_NONE){
DefWindowProc(WM_ERASEBKGND, (WPARAM)(HDC)dc, 0);
iOldBkMode = dc.SetBkMode(TRANSPARENT);
}
else
iOldBkMode = OPAQUE;
CHeaderCtrl *pHeaderCtrl = GetHeaderCtrl();
int iCount = pHeaderCtrl->GetItemCount();
const int iMarginX = 4;
cur_rec.right = cur_rec.left - iMarginX*2;
cur_rec.left += iMarginX;
CString buffer;
int iIconDrawWidth = theApp.GetSmallSytemIconSize().cx + 3;
for(int iCurrent = 0; iCurrent < iCount; iCurrent++){
int iColumn = pHeaderCtrl->OrderToIndex(iCurrent);
if( !IsColumnHidden(iColumn) ){
UINT uDTFlags = DLC_DT_TEXT;
cur_rec.right += GetColumnWidth(iColumn);
switch(iColumn){
case 0:{
int iImage = theApp.GetFileTypeSystemImageIdx(file->GetFileName());
if (theApp.GetSystemImageList() != NULL)
::ImageList_Draw(theApp.GetSystemImageList(), iImage, dc->GetSafeHdc(), cur_rec.left, cur_rec.top, ILD_NORMAL|ILD_TRANSPARENT);
if (!file->GetFileComment().IsEmpty() || file->GetFileRating())
m_ImageList.Draw(dc, 0, CPoint(cur_rec.left, cur_rec.top), ILD_NORMAL | ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1));
cur_rec.left += iIconDrawWidth;
buffer = file->GetFileName();
break;
}
case 1:
buffer = CastItoXBytes(file->GetFileSize(), false, false);
uDTFlags |= DT_RIGHT;
break;
case 2:
buffer = file->GetFileTypeDisplayStr();
break;
case 3:{
switch (file->GetUpPriority()) {
case PR_VERYLOW :
buffer = GetResString(IDS_PRIOVERYLOW);
break;
case PR_LOW :
if( file->IsAutoUpPriority() )
buffer = GetResString(IDS_PRIOAUTOLOW);
else
buffer = GetResString(IDS_PRIOLOW);
break;
case PR_NORMAL :
if( file->IsAutoUpPriority() )
buffer = GetResString(IDS_PRIOAUTONORMAL);
else
buffer = GetResString(IDS_PRIONORMAL);
break;
case PR_HIGH :
if( file->IsAutoUpPriority() )
buffer = GetResString(IDS_PRIOAUTOHIGH);
else
buffer = GetResString(IDS_PRIOHIGH);
break;
case PR_VERYHIGH :
buffer = GetResString(IDS_PRIORELEASE);
break;
default:
buffer.Empty();
}
break;
}
case 4:
buffer = md4str(file->GetFileHash());
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:{
CPoint pt(cur_rec.left, cur_rec.top);
m_ImageList.Draw(dc, file->GetPublishedED2K() ? 1 : 0, pt, ILD_NORMAL | ILD_TRANSPARENT);
pt.x += 16;
bool bSharedInKad;
if ((uint32)time(NULL) < file->GetLastPublishTimeKadSrc())
{
if (theApp.IsFirewalled() && theApp.IsConnected())
{
if (theApp.clientlist->GetBuddy() && (file->GetLastPublishBuddy() == theApp.clientlist->GetBuddy()->GetIP()))
bSharedInKad = true;
else
bSharedInKad = false;
}
else
bSharedInKad = true;
}
else
bSharedInKad = false;
m_ImageList.Draw(dc, bSharedInKad ? 2 : 0, pt, ILD_NORMAL | ILD_TRANSPARENT);
buffer.Empty();
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::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 > 0 ? MF_ENABLED : MF_GRAYED);
m_SharedFilesMenu.EnableMenuItem(MP_DETAIL, iSelectedItems > 0 ? MF_ENABLED : MF_GRAYED);
m_SharedFilesMenu.EnableMenuItem(thePrefs.GetShowCopyEd2kLinkCmd() ? MP_GETED2KLINK : 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:{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -