📄 transferpage.cpp
字号:
ImageIndex = -1;
} else if(Column == 2) {
if(Kind == ikNormal || Kind == ikSelected)
ImageIndex = NodeData->NetworkImageIndex;
}
}
void __fastcall TTransferForm::DownloadTreeGetHint(
TBaseVirtualTree *Sender, PVirtualNode Node, TColumnIndex Column,
TVTTooltipLineBreakStyle &LineBreakStyle, WideString &HintText)
{
TDownload* Download = ((TDownloadNodeData*)Sender->GetNodeData(Node))->Download;
TDlSource* Source = ((TDownloadNodeData*)Sender->GetNodeData(Node))->Source;
// TRANSLATOR: Download tool tip.
HintText = _("File: ") + Download->GetSaveFileName().c_str();
for(THashSet::Iterator itr = Download->GetHashes()->Begin(); itr != Download->GetHashes()->End(); ++itr)
// TRANSLATOR: Download tool tip.
HintText += _("\nHash: ") + (*itr)->GetGiftHash().c_str();
// TRANSLATOR: Download tool tip.
HintText += _("\nTotal size: ") + FormatNumber(Download->GetFileSize(),"Byte").c_str();
if(Source) {
// TRANSLATOR: Download tool tip.
HintText += _("\nNetwork: ") + Source->Network.c_str();
// TRANSLATOR: Download tool tip.
HintText += _("\nUser: ") + Source->GetUser()->GetId().c_str();
} else {
// TRANSLATOR: Download tool tip.
HintText += _("\nNetwork: ") + Download->GetNetwork().c_str();
// TRANSLATOR: Download tool tip.
HintText += _("\nUsers: ") + int_to_string(Download->GetNoOfSources()).c_str();
}
if(!Download->GetMetaData().Empty()) {
HintText += WideString("\n--");
for(TMetaData::Iterator itr=Download->GetMetaData().Begin();itr!=Download->GetMetaData().End();++itr)
HintText += WideString("\n") + (*itr).Name.c_str() + ": " + (*itr).Value.c_str();
}
}
//---------------------------------------------------------------------------
void __fastcall TTransferForm::DownloadTreeCompareNodes(
TBaseVirtualTree *Sender, PVirtualNode Node1, PVirtualNode Node2,
TColumnIndex Column, int &Result)
{
TDownloadNodeData* NodeData1 = (TDownloadNodeData*)Sender->GetNodeData(Node1);
TDownloadNodeData* NodeData2 = (TDownloadNodeData*)Sender->GetNodeData(Node2);
TDownload* Download1 = NodeData1->Download;
TDownload* Download2 = NodeData2->Download;
TDlSource* Source1 = NodeData1->Source;
TDlSource* Source2 = NodeData2->Source;
if(!Download1 || !Download2)
return;
switch(Column) {
case 0: Result = strcmpi(Download1->GetSaveFileName().c_str(),Download2->GetSaveFileName().c_str()); break;
case 1:
if(Source1 && Source2)
Result = strcmpi(Source1->GetUser()->GetSmartName().c_str(),Source2->GetUser()->GetSmartName().c_str());
else
Result = (Node1->ChildCount < Node2->ChildCount) ? -1 : (Node1->ChildCount > Node2->ChildCount);
break;
case 2:
if(Source1 && Source2)
Result = strcmpi(Source1->Network.c_str(),Source2->Network.c_str());
else
Result = strcmpi(Download1->GetNetwork().c_str(),Download2->GetNetwork().c_str());
break;
case 3: {
double a = Source1 ? ((double)Source1->Transmitted) / Source1->Size : ((double)Download1->GetTransmitted()) / Download1->GetFileSize();
double b = Source2 ? ((double)Source2->Transmitted) / Source2->Size : ((double)Download2->GetTransmitted()) / Download2->GetFileSize();
Result = (a < b) ? -1 : (a > b);
break;
}
case 4:
if(Source1 && Source2)
Result = strcmpi(Source1->ProtoState.c_str(),Source2->ProtoState.c_str());
else
Result = (Download1->GetState() < Download2->GetState()) ? -1 : (Download1->GetState() > Download2->GetState());
break;
case 5: {
unsigned int a = Source1 ? Source1->Size : Download1->GetFileSize();
unsigned int b = Source2 ? Source2->Size : Download2->GetFileSize();
Result = (a < b) ? -1 : (a > b);
break;
}
case 6: {
unsigned int a = Source1 ? Source1->Throughput.GetBps() : Download1->GetThroughput();
unsigned int b = Source2 ? Source2->Throughput.GetBps() : Download2->GetThroughput();
Result = (a < b) ? -1 : (a > b);
break;
}
case 7: {
unsigned int a = Source1 ? Source1->GetTimeLeft() : Download1->GetTimeLeft();
unsigned int b = Source2 ? Source2->GetTimeLeft() : Download2->GetTimeLeft();
Result = (a < b) ? -1 : (a > b);
break;
}
case 8: Result = strcmpi(Download1->GetMetaData().Get("title").c_str(),Download2->GetMetaData().Get("title").c_str()); break;
case 9: Result = strcmpi(Download1->GetMetaData().Get("artist").c_str(),Download2->GetMetaData().Get("artist").c_str()); break;
default: Result = 0;
}
}
void __fastcall TTransferForm::DownloadTreeHeaderClick(TVTHeader *Sender,
TColumnIndex Column, TMouseButton Button, TShiftState Shift, int X,
int Y)
{
if(Button != mbLeft)
return;
if(Sender->SortColumn != Column) {
Sender->SortColumn = Column;
Sender->SortDirection = sdAscending;
} else {
Sender->SortDirection = (Sender->SortDirection == sdAscending) ? sdDescending : sdAscending;
}
}
//---------------------------------------------------------------------------
void __fastcall TTransferForm::DownloadTreeAfterCellPaint(
TBaseVirtualTree *Sender, TCanvas *TargetCanvas, PVirtualNode Node,
TColumnIndex Column, TRect &CellRect)
{
if(Column != 3) // progress column
return;
TDownload* Download = ((TDownloadNodeData*)Sender->GetNodeData(Node))->Download;
TDlSource* Source = ((TDownloadNodeData*)Sender->GetNodeData(Node))->Source;
if(Source && Source->State != TDlSource::Active)
return;
else if(Download->GetState() != TDownload::Downloading)
return;
TRect Rect(CellRect);
// erase background
Rect.Left += 1; Rect.Top += 2; Rect.Right -= 2; Rect.Bottom -= 2;
TargetCanvas->Brush->Color = clWindow;
TargetCanvas->FillRect(Rect);
// draw box
TargetCanvas->Brush->Color = TColor(0x00000000);
TargetCanvas->FrameRect(Rect);
// draw bar
Rect.Left += 2; Rect.Top += 2; Rect.Right -= 2; Rect.Bottom -= 2;
if(Source) {
Rect.Right = Rect.Left + ((double)Source->Transmitted) / Source->Size * Rect.Width();
TargetCanvas->Brush->Color = TColor(0x00FFAA00);
} else {
Rect.Right = Rect.Left + ((double)Download->GetTransmitted()) / Download->GetFileSize() * Rect.Width();
TargetCanvas->Brush->Color = TColor(0x00FF0000);
}
TargetCanvas->FillRect(Rect);
}
void __fastcall TTransferForm::DownloadTreeScroll(TBaseVirtualTree *Sender,
int DeltaX, int DeltaY)
{
// workaround for paint problem with focused nodes on scrolling
/*
if(Sender->FocusedNode && DeltaX != 0)
Sender->InvalidateNode(Sender->FocusedNode);
*/
}
void __fastcall TTransferForm::DownloadTreeHeaderDragged(TVTHeader *Sender,
TColumnIndex Column, int OldPosition)
{
// make sure the tree is always in the first column
Sender->MainColumn = Sender->Columns->GetFirstVisibleColumn();
}
void __fastcall TTransferForm::DownloadHeaderPopupPopup(TObject *Sender)
{
TMenuItem* Items = ((TVTHeaderPopupMenu*)Sender)->Items;
// disable hiding of column which contains the tree
for(int i=0;i<Items->Count;i++) {
if(Items->Items[i]->Tag == DownloadTree->Header->MainColumn) {
Items->Items[i]->Enabled = false;
break;
}
}
}
void __fastcall TTransferForm::DownloadTreeKeyPress(TObject *Sender,
char &Key)
{
if(Key == 13)
PlayDownloadMnuClick(NULL);
}
void __fastcall TTransferForm::DownloadTreeDblClick(TObject *Sender)
{
PlayDownloadMnuClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TTransferForm::DownloadPauseBtnClick(TObject *Sender)
{
// use focused item to decide whether to resume or pause
if(!DownloadTree->FocusedNode)
return;
TDownload* Download = ((TDownloadNodeData*)DownloadTree->GetNodeData(DownloadTree->FocusedNode))->Download;
if(Download->GetState() == TDownload::Paused)
ResumeDownloadMnuClick(NULL);
else
PauseDownloadMnuClick(NULL);
}
void __fastcall TTransferForm::DownloadActionBtnClick(TObject *Sender)
{
TPoint Pt = TPoint(DownloadActionBtn->Left + DownloadActionBtn->Width,
DownloadActionBtn->Top + DownloadActionBtn->Height);
Pt = DownloadActionBtn->Parent->ClientToScreen(Pt);
UpdateDownloadPopup(DownloadTree->FocusedNode);
DownloadPopup->Alignment = paRight;
DownloadPopup->Popup(Pt.x,Pt.y);
}
void __fastcall TTransferForm::DownloadTreeGetPopupMenu(
TBaseVirtualTree *Sender, PVirtualNode Node, TColumnIndex Column,
const TPoint &P, bool &AskParent, TPopupMenu *&PopupMenu)
{
UpdateDownloadPopup(Node);
DownloadPopup->Alignment = paLeft;
PopupMenu = DownloadPopup;
}
bool __fastcall TTransferForm::CanPlayDownload(TDownload* Download)
{
if(!Download)
return false;
// one hell of a condition
return (Download->GetFileType() == FTAudio || Download->GetFileType() == FTVideo)
&&
((Download->GetState() == TDownload::Completed &&
PathMapper->PathUsable(Download->GetCompletedPath()))
||
((Download->GetState() == TDownload::Queued ||
Download->GetState() == TDownload::Paused ||
Download->GetState() == TDownload::Downloading) &&
PathMapper->PathUsable(Download->GetIncomingPath()) &&
Config->GetValueInt("player/always_use_external") == 0));
}
void __fastcall TTransferForm::UpdateDownloadPopup (TVirtualNode* Node)
{
// general
ClearDownloadsMnu->Enabled = false;
CancelAllDownloadsMnu->Enabled = false;
FindMoreSourcesAllDownloadsMnu->Enabled = false;
PauseAllDownloadsMnu->Enabled = false;
ResumeAllDownloadsMnu->Enabled = false;
Engine->LockDownloads();
TEngine::TDownloadIterator itr = Engine->GetDownloadsBegin();
for(;itr != Engine->GetDownloadsEnd();++itr) {
CancelAllDownloadsMnu->Enabled = CancelAllDownloadsMnu->Enabled ||
(*itr)->GetState() == TDownload::Downloading ||
(*itr)->GetState() == TDownload::Queued ||
(*itr)->GetState() == TDownload::Paused;
ClearDownloadsMnu->Enabled = ClearDownloadsMnu->Enabled ||
(*itr)->GetState() == TDownload::Completed ||
(*itr)->GetState() == TDownload::Cancelled ||
(*itr)->GetState() == TDownload::Failed;
FindMoreSourcesAllDownloadsMnu->Enabled = FindMoreSourcesAllDownloadsMnu->Enabled ||
(*itr)->GetState() == TDownload::Downloading ||
(*itr)->GetState() == TDownload::Queued ||
(*itr)->GetState() == TDownload::Paused;
PauseAllDownloadsMnu->Enabled = PauseAllDownloadsMnu->Enabled ||
(*itr)->GetState() == TDownload::Downloading ||
(*itr)->GetState() == TDownload::Queued;
ResumeAllDownloadsMnu->Enabled = ResumeAllDownloadsMnu->Enabled ||
(*itr)->GetState() == TDownload::Paused;
}
Engine->ReleaseDownloads();
// node specific
PlayDownloadMnu->Visible = true;
PlayDownloadMnu->Enabled = false;
PlayDownloadMnu->Default = true;
LaunchTorrentDownloadMnu->Visible = false;
LaunchTorrentDownloadMnu->Enabled = false;
OpenExternallyDownloadMnu->Visible = true;
OpenExternallyDownloadMnu->Enabled = false;
PauseDownloadMnu->Enabled = false;
ResumeDownloadMnu->Enabled = false;
CancelDownloadMnu->Enabled = false;
RemoveDownloadSourceMnu->Enabled = false;
FindMoreSourcesDownloadMnu->Enabled = false;
FindMoreFromUserDownloadMnu->Enabled = false;
if(Node) {
TDownload* Download = ((TDownloadNodeData*)DownloadTree->GetNodeData(Node))->Download;
if(Download->GetFileType() == FTTorrent) {
PlayDownloadMnu->Visible = false;
OpenExternallyDownloadMnu->Visible = false;
LaunchTorrentDownloadMnu->Visible = true;
LaunchTorrentDownloadMnu->Default = true;
}
PlayDownloadMnu->Enabled = CanPlayDownload(Download);
LaunchTorrentDownloadMnu->Enabled = Download->GetFileType() == FTTorrent &&
Download->GetState() == TDownload::Completed &&
PathMapper->PathUsable(Download->GetCompletedPath());
OpenExternallyDownloadMnu->Enabled = Download->GetState() == TDownload::Completed &&
PathMapper->PathUsable(Download->GetCompletedPath());
// source specific menu items
FindMoreFromUserDownloadMnu->Enabled = ((TDownloadNodeData*)DownloadTree->GetNodeData(Node))->Source != NULL;
}
for(Node = DownloadTree->GetFirstSelected();Node;Node = DownloadTree->GetNextSelected(Node)) {
TDownload* Download = ((TDownloadNodeData*)DownloadTree->GetNodeData(Node))->Download;
PauseDownloadMnu->Enabled = PauseDownloadMnu->Enabled ||
Download->GetState() == TDownload::Downloading ||
Download->GetState() == TDownload::Queued;
ResumeDownloadMnu->Enabled = ResumeDownloadMnu->Enabled ||
Download->GetState() == TDownload::Paused;
CancelDownloadMnu->Enabled = CancelDownloadMnu->Enabled ||
Download->GetState() == TDownload::Downloading ||
Download->GetState() == TDownload::Queued ||
Download->GetState() == TDownload::Paused;
FindMoreSourcesDownloadMnu->Enabled = CancelDownloadMnu->Enabled;
RemoveDownloadSourceMnu->Enabled = RemoveDownloadSourceMnu->Enabled ||
((TDownloadNodeData*)DownloadTree->GetNodeData(Node))->Source != NULL;
}
// don't enable parent if no child is enabled
SanitizeMenuItems(DownloadPopup->Items);
}
//---------------------------------------------------------------------------
void __fastcall TTransferForm::PlayDownloadMnuClick(TObject *Sender)
{
if(!DownloadTree->FocusedNode)
return;
TDownload* Download = ((TDownloadNodeData*)DownloadTree->GetNodeData(DownloadTree->FocusedNode))->Download;
if(Download->GetFileType() != FTAudio && Download->GetFileType() != FTVideo)
return;
if(Config->GetValueInt("player/always_use_external")) {
OpenExternallyDownloadMnuClick(Sender);
return;
}
// get right path
string Path;
if(Download->GetState() == TDownload::Completed)
Path = Download->GetCompletedPath();
else if((Download->GetState() != TDownload::Cancelled &&
Download->GetState() != TDownload::Failed))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -