📄 transferpage.cpp
字号:
{
// create state file path
if(PathMapper->GetNeedToMap()) {
// if we need to map we assume that gift is not running on windows
// which means we need to prepend a '.' for the state file
Path = DirFromPath(Download->GetIncomingPath()) + "/." +
FileFromPath(Download->GetIncomingPath()) + ".state";
} else {
Path = Download->GetIncomingPath() + ".state";
}
} else {
return;
}
if(!PathMapper->PathUsable(Path))
return;
if(!PlayerForm->PlayFile(PathMapper->Map(Path)))
return;
// switch page if video
if(Download->GetFileType() == FTVideo)
MainForm->SetVisiblePage(PlayerForm);
}
void __fastcall TTransferForm::LaunchTorrentDownloadMnuClick(
TObject *Sender)
{
if(!DownloadTree->FocusedNode)
return;
TDownload* Download = ((TDownloadNodeData*)DownloadTree->GetNodeData(DownloadTree->FocusedNode))->Download;
// only launch completed torrents
if(Download->GetState() != TDownload::Completed ||
Download->GetFileType() != FTTorrent)
{
return;
}
if(!PathMapper->PathUsable(Download->GetCompletedPath()))
return;
string Path = PathMapper->Map(Download->GetCompletedPath());
if(TFileLauncher::IsFileTooDangerous(Path) || TFileLauncher::IsFileDangerous(Path))
return;
if(!TFileLauncher::LaunchFile(Path))
TFileLauncher::ShowTorrentLaunchFailedMsg(Path);
}
void __fastcall TTransferForm::OpenExternallyDownloadMnuClick(
TObject *Sender)
{
if(!DownloadTree->FocusedNode)
return;
TDownload* Download = ((TDownloadNodeData*)DownloadTree->GetNodeData(DownloadTree->FocusedNode))->Download;
// only open completed files externally
if(Download->GetState() != TDownload::Completed)
return;
if(!PathMapper->PathUsable(Download->GetCompletedPath()))
return;
string Path = PathMapper->Map(Download->GetCompletedPath());
if(TFileLauncher::IsFileTooDangerous(Path))
return;
if(TFileLauncher::IsFileDangerous(Path)) {
if(!TFileLauncher::UserWantsToLaunch(Path))
return;
}
if(!TFileLauncher::LaunchFile(Path))
TFileLauncher::ShowLaunchFailedMsg(Path);
}
void __fastcall TTransferForm::PauseDownloadMnuClick(TObject *Sender)
{
// loop through transfers to pause
for(TVirtualNode* Node = DownloadTree->GetFirstSelected();Node;Node = DownloadTree->GetNextSelected(Node)) {
// this may pause a download more than once if multiple sources were selected
TDownloadNodeData* NodeData = (TDownloadNodeData*)DownloadTree->GetNodeData(Node);
NodeData->Download->Pause();
}
}
void __fastcall TTransferForm::PauseAllDownloadsMnuClick(TObject *Sender)
{
Engine->LockDownloads();
TEngine::TDownloadIterator itr = Engine->GetDownloadsBegin();
for(;itr != Engine->GetDownloadsEnd();++itr)
(*itr)->Pause();
Engine->ReleaseDownloads();
}
void __fastcall TTransferForm::ResumeDownloadMnuClick(TObject *Sender)
{
// loop through transfers to resume
for(TVirtualNode* Node = DownloadTree->GetFirstSelected();Node;Node = DownloadTree->GetNextSelected(Node)) {
// this may resume a download more than once if multiple sources were selected
TDownloadNodeData* NodeData = (TDownloadNodeData*)DownloadTree->GetNodeData(Node);
NodeData->Download->Resume();
}
}
void __fastcall TTransferForm::ResumeAllDownloadsMnuClick(TObject *Sender)
{
Engine->LockDownloads();
TEngine::TDownloadIterator itr = Engine->GetDownloadsBegin();
for(;itr != Engine->GetDownloadsEnd();++itr)
(*itr)->Resume();
Engine->ReleaseDownloads();
}
void __fastcall TTransferForm::CancelDownloadMnuClick(TObject *Sender)
{
list<TDownload*> Downloads;
AnsiString FilesStr;
// collect list of downloads to cancel
for(TVirtualNode* Node = DownloadTree->GetFirstSelected();Node;Node = DownloadTree->GetNextSelected(Node)) {
TDownloadNodeData* NodeData = (TDownloadNodeData*)DownloadTree->GetNodeData(Node);
// multiple sources might be selected so make the Downloads list unique
if(find(Downloads.begin(), Downloads.end(), NodeData->Download) == Downloads.end() &&
(NodeData->Download->GetState() == TDownload::Downloading ||
NodeData->Download->GetState() == TDownload::Queued ||
NodeData->Download->GetState() == TDownload::Paused))
{
Downloads.push_front(NodeData->Download);
FilesStr += AnsiString(NodeData->Download->GetSaveFileName().c_str()) + "\n";
}
}
if(Downloads.empty())
return;
if (Config->GetValueInt("download/confirm_cancel")) {
// TRANSLATOR: Message box confirming cancellation of download.
if(MessageDlg(_("Are you sure you want to cancel the following downloads?\n\n") + FilesStr,
mtConfirmation,TMsgDlgButtons() <<mbYes << mbNo,0) != mrYes) {
return;
}
}
// CHECKME: should we not lock the downloads while doing this?
for (list<TDownload*>::iterator itr = Downloads.begin(); itr != Downloads.end(); ++itr) {
(*itr)->Cancel();
// don't remove download here if autoclear is on because it will be done
// in the engine callback.
if(!Config->GetValueInt("download/autoclear_complete"))
Engine->RemoveDownload(*itr);
}
}
void __fastcall TTransferForm::CancelAllDownloadMnuClick(TObject *Sender)
{
// TRANSLATOR: Message box confirming cancellation of all downloads.
if(MessageDlg(_("Are you sure you want to cancel ALL downloads?"),mtConfirmation,TMsgDlgButtons() <<mbYes << mbNo,0) != mrYes)
return;
Engine->LockDownloads();
TEngine::TDownloadIterator itr = Engine->GetDownloadsBegin();
for(;itr != Engine->GetDownloadsEnd();++itr)
(*itr)->Cancel();
Engine->ReleaseDownloads();
}
class TSource
{
public:
TSource(TDownload *d, TDlSource* s) : Download(d), Source(s) {};
TDownload* Download;
TDlSource* Source;
};
void __fastcall TTransferForm::RemoveDownloadSourceMnuClick(
TObject *Sender)
{
list<TSource> Sources;
AnsiString FilesStr;
// collect list of sources to remove
for(TVirtualNode* Node = DownloadTree->GetFirstSelected();Node;Node = DownloadTree->GetNextSelected(Node)) {
TDownloadNodeData* NodeData = (TDownloadNodeData*)DownloadTree->GetNodeData(Node);
if(NodeData->Source) {
Sources.push_front(TSource(NodeData->Download,NodeData->Source));
FilesStr += AnsiString(NodeData->Source->SourceId.c_str()) + "\n";
}
}
if(Sources.empty())
return;
// TRANSLATOR: Message box confirming removal of download source.
if(MessageDlg(_("Are you sure you want to remove the following sources?\n\n") + FilesStr,
mtConfirmation,TMsgDlgButtons() <<mbYes << mbNo,0) != mrYes) {
return;
}
// do it
for (list<TSource>::iterator itr = Sources.begin(); itr != Sources.end(); ++itr)
(*itr).Download->RemoveSource((*itr).Source);
}
void __fastcall TTransferForm::FindMoreSourcesDownloadMnuClick(
TObject *Sender)
{
// loop through all selected transfers
for(TVirtualNode* Node = DownloadTree->GetFirstSelected();Node;Node = DownloadTree->GetNextSelected(Node)) {
// this may hit a download more than once if multiple sources were selected
TDownloadNodeData* NodeData = (TDownloadNodeData*)DownloadTree->GetNodeData(Node);
NodeData->Download->FindMoreSources();
}
}
void __fastcall TTransferForm::FindMoreSourcesAllDownloadsMnuClick(
TObject *Sender)
{
Engine->LockDownloads();
TEngine::TDownloadIterator itr = Engine->GetDownloadsBegin();
for(;itr != Engine->GetDownloadsEnd();++itr)
(*itr)->FindMoreSources();
Engine->ReleaseDownloads();
}
void __fastcall TTransferForm::ClearDownloadsMnuClick(TObject *Sender)
{
Engine->LockDownloads();
TEngine::TDownloadIterator itr = Engine->GetDownloadsBegin();
while(itr != Engine->GetDownloadsEnd()) {
if((*itr)->GetState() == TDownload::Completed ||
(*itr)->GetState() == TDownload::Cancelled ||
(*itr)->GetState() == TDownload::Failed)
{
Engine->RemoveDownload((*itr));
itr = Engine->GetDownloadsBegin(); // itr is invalid after remove
} else
++itr;
}
Engine->ReleaseDownloads();
}
void __fastcall TTransferForm::FindMoreFromUserDownloadMnuClick(
TObject *Sender)
{
TDownloadNodeData* NodeData = (TDownloadNodeData*)DownloadTree->GetNodeData(DownloadTree->FocusedNode);
if(!NodeData || !NodeData->Source)
return;
SearchForm->RunSearch(NodeData->Source->GetUser()->GetId().c_str(), SRUser);
MainForm->SetVisiblePage(SearchForm);
}
//---------------------------------------------------------------------------
// uploads
//---------------------------------------------------------------------------
void __fastcall TTransferForm::UploadTreeGetText(TBaseVirtualTree *Sender,
PVirtualNode Node, TColumnIndex Column, TVSTTextType TextType,
WideString &CellText)
{
if(TextType != ttNormal)
return;
TUpload* Upload = ((TUploadNodeData*)Sender->GetNodeData(Node))->Upload;
switch(Column) {
case 0: // file name
CellText = Upload->GetFileName().c_str(); break;
case 1: // user
CellText = Upload->GetSource()->GetUser()->GetSmartName().c_str();
break;
case 2: // network
CellText = Upload->GetNetwork().c_str(); break;
case 3: // progress bar, owner drawn
break;
case 4: // status
#if 0
CellText = Upload->GetSource()->ProtoState.c_str();
#else
switch(Upload->GetState()) {
// TRANSLATOR: Upload status.
case TUpload::New: CellText = _("New"); break;
// TRANSLATOR: Upload status.
case TUpload::Queued: CellText = _("Queued"); break;
// TRANSLATOR: Upload status.
case TUpload::Uploading: CellText = _("Uploading"); break;
// TRANSLATOR: Upload status.
case TUpload::Completed: CellText = _("Completed"); break;
case TUpload::Cancelled:
// TRANSLATOR: Upload status.
CellText = _("Cancelled");
#if 0
CellText += WideString(" (") + Upload->GetSource()->ProtoState.c_str() + ")";
#endif
break;
}
#endif
break;
case 5: // size
CellText = FormatNumber(Upload->GetSource()->Transmitted,"B",2).c_str();
CellText += " / ";
CellText += FormatNumber(Upload->GetSource()->Size,"B",2).c_str();
break;
case 6: // speed
if(Upload->GetState() == TUpload::Uploading)
CellText = FormatNumber(Upload->GetThroughput(),"Bps",2).c_str();
break;
case 7: // ETA
if(Upload->GetState() == TUpload::Uploading)
CellText = FormatTime(Upload->GetTimeLeft()).c_str();
break;
case 8: // title
CellText = Upload->GetMetaData().Get("title").c_str();
break;
case 9: // artist
CellText = Upload->GetMetaData().Get("artist").c_str();
break;
}
}
void __fastcall TTransferForm::UploadTreeGetImageIndex(
TBaseVirtualTree *Sender, PVirtualNode Node, TVTImageKind Kind,
TColumnIndex Column, bool &Ghosted, int &ImageIndex)
{
TUploadNodeData* NodeData = (TUploadNodeData*)Sender->GetNodeData(Node);
if(UploadTree->Header->MainColumn == Column) {
if(Kind == ikNormal || Kind == ikSelected)
ImageIndex = NodeData->ImageIndex;
else
ImageIndex = -1;
} else if(Column == 2) {
if(Kind == ikNormal || Kind == ikSelected)
ImageIndex = NodeData->NetworkImageIndex;
}
}
void __fastcall TTransferForm::UploadTreeGetHint(TBaseVirtualTree *Sender,
PVirtualNode Node, TColumnIndex Column,
TVTTooltipLineBreakStyle &LineBreakStyle, WideString &HintText)
{
TUpload* Upload = ((TUploadNodeData*)Sender->GetNodeData(Node))->Upload;
if(Upload->GetPath() != "")
// TRANSLATOR: Upload tool tip.
HintText = _("File: ") + Upload->GetPath().c_str();
else
// TRANSLATOR: Upload tool tip.
HintText = _("File: ") + Upload->GetFileName().c_str();
for(THashSet::Iterator itr = Upload->GetHashes()->Begin(); itr != Upload->GetHashes()->End(); ++itr)
// TRANSLATOR: Upload tool tip.
HintText += _("\nHash: ") + (*itr)->GetGiftHash().c_str();
// TRANSLATOR: Upload tool tip.
HintText += _("\nTotal size: ") + FormatNumber(Upload->GetFileSize(),"Byte").c_str();
// TRANSLATOR: Upload tool tip.
HintText += _("\nNetwork: ") + Upload->GetNetwork().c_str();
// TRANSLATOR: Upload tool tip.
HintText += _("\nUser: ") + Upload->GetSource()->GetUser()->GetId().c_str();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -