📄 statuspage.cpp
字号:
/*
This file is part of KCeasy (http://www.kceasy.com)
Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
//---------------------------------------------------------------------------
#include <vcl.h>
#include <KCeasy.h>
#pragma hdrstop
#include "StatusPage.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma link "VirtualTrees"
#pragma resource "*.dfm"
TStatusForm *StatusForm;
//---------------------------------------------------------------------------
__fastcall TStatusForm::TStatusForm(TComponent* Owner)
: TForm(Owner)
{
TranslateComponent(this);
NetworksTree->NodeDataSize = sizeof(TNetwork*);
CtrlSplitter->Enabled = false;
Engine->SetDebug(InterfaceLoggingBtn->Down);
Engine->SetGiftLogging(GiftLoggingBtn->Down);
}
__fastcall TStatusForm::~TStatusForm()
{
}
//---------------------------------------------------------------------------
bool __fastcall TStatusForm::EngineCallback(TCallbackInfo* CbInfo)
{
switch(CbInfo->Code) {
case CbcDebug: {
if(CbInfo->Data1 == 0)
StatusForm->InterfaceMemo->Lines->Add(AnsiString("[>] ") + ((string*)CbInfo->Data2)->c_str());
else
StatusForm->InterfaceMemo->Lines->Add(AnsiString("[<] ") + ((string*)CbInfo->Data2)->c_str());
return true;
}
case CbcGiftLog: {
int p1, p2 = 0;
string* str = (string*)CbInfo->Data1;
while((p1 = str->find('\n', p2)) != -1) {
StatusForm->LogMemo->Lines->Add(str->substr(p2,p1-p2).c_str());
p2 = p1 + 1;
}
return true;
}
case CbcStateChange:
if(Engine->IsOffline() || Engine->IsOnline())
NetworksTree->Clear();
GiftLoggingBtn->Enabled = Engine->IsUsingLocalGift();
NetworksUpdateBtn->Enabled = Engine->IsOnline();
return true;
case CbcNetworksUpdate: {
NetworksTree->BeginUpdate();
TNetworks* Nets = (TNetworks*)CbInfo->Data1;
Nets->Lock();
TNetworks::TNetworkIterator itr = Nets->GetBegin();
for(; itr != Nets->GetEnd(); ++itr) {
// add new node if network not in tree
TVirtualNode* Node;
for(Node = NetworksTree->GetFirst(); Node; Node=NetworksTree->GetNextSibling(Node))
if(*((void**)NetworksTree->GetNodeData(Node)) == (void*)(*itr))
break;
if(!Node)
NetworksTree->AddChild(NULL,(void*)(*itr));
}
Nets->Release();
NetworksTree->EndUpdate();
return true;
}
}
return false;
}
//---------------------------------------------------------------------------
void __fastcall TStatusForm::GiftLoggingBtnClick(TObject *Sender)
{
Engine->SetGiftLogging(GiftLoggingBtn->Down);
}
void __fastcall TStatusForm::ClearGiftLogBtnClick(TObject *Sender)
{
StatusForm->LogMemo->Lines->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TStatusForm::InterfaceLoggingBtnClick(TObject *Sender)
{
Engine->SetDebug(InterfaceLoggingBtn->Down);
}
void __fastcall TStatusForm::ClearInterfaceLogBtnClick(TObject *Sender)
{
StatusForm->InterfaceMemo->Lines->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TStatusForm::NetworksUpdateBtnClick(TObject *Sender)
{
if(Engine->IsOnline())
Engine->GetNetworks()->Update();
}
//---------------------------------------------------------------------------
void __fastcall TStatusForm::NetworksTreeGetText(TBaseVirtualTree *Sender,
PVirtualNode Node, TColumnIndex Column, TVSTTextType TextType,
WideString &CellText)
{
if(TextType != ttNormal)
return;
TNetwork* Net = *((TNetwork**)NetworksTree->GetNodeData(Node));
switch(Column) {
case 0: // network name
CellText = Net->GetName().c_str(); break;
case 1: // users
CellText = FormatNumber(Net->GetUsers(),"",-1).c_str(); break;
case 2: // files
CellText = FormatNumber(Net->GetFiles(),"",-1).c_str(); break;
case 3: // size
CellText = (FormatNumber(Net->GetSize(),"",-1) + " GB").c_str(); break;
}
}
void __fastcall TStatusForm::NetworksTreeGetImageIndex(
TBaseVirtualTree *Sender, PVirtualNode Node, TVTImageKind Kind,
TColumnIndex Column, bool &Ghosted, int &ImageIndex)
{
TNetwork* Net = *((TNetwork**)NetworksTree->GetNodeData(Node));
if(Column != 0)
return;
if(Kind == ikNormal || Kind == ikSelected)
ImageIndex = MainForm->IconManager->GetNetworkIconIndex(Net->GetName());
}
void __fastcall TStatusForm::NetworksTreePaintText(
TBaseVirtualTree *Sender, const TCanvas *TargetCanvas,
PVirtualNode Node, TColumnIndex Column, TVSTTextType TextType)
{
TargetCanvas->Font->Color = TColor(0x000000);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -