📄 kceasy.cpp
字号:
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ApplicationEventsActivate(TObject *Sender)
{
// IE seems to lose focus when switching away so restore it now. Note
// that BrowserForm may not have been created yet on first start up.
if(BrowserForm && VisiblePage == BrowserForm)
{
BrowserForm->SetFocus();
BrowserForm->PageActivated();
}
}
void __fastcall TMainForm::WMTaskbarCreated(TMessage& Msg)
{
if(TrayIcon)
TrayIcon->RestoreIcon();
}
//---------------------------------------------------------------------------
TToolButton* TMainForm::PageButtonFromForm(TForm* Page)
{
if(Page == BrowserForm)
return BrowserPageBtn;
else if(Page == SearchForm)
return SearchPageBtn;
else if(Page == TransferForm)
return TransferPageBtn;
else if(Page == LibraryForm)
return LibraryPageBtn;
else if(Page == PlayerForm)
return PlayerPageBtn;
else if(Page == ChatForm)
return ChatPageBtn;
else if(Page == StatusForm)
return StatusPageBtn;
return NULL;
}
TForm* __fastcall TMainForm::GetVisiblePage()
{
return VisiblePage;
}
void __fastcall TMainForm::SetVisiblePage(TForm* Form)
{
TForm* OldPage = VisiblePage;
VisiblePage = Form;
if(VisiblePage == OldPage)
return;
if (VisiblePage) {
VisiblePage->Show();
VisiblePage->SetFocus();
PageButtonFromForm(VisiblePage)->Down = true;
}
if(OldPage) {
PageButtonFromForm(OldPage)->Down = false;
OldPage->Hide();
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::BrowserPageBtnClick(TObject *Sender)
{
SetVisiblePage(BrowserForm);
BrowserForm->PageActivated();
}
void __fastcall TMainForm::SearchPageBtnClick(TObject *Sender)
{
SetVisiblePage(SearchForm);
SearchForm->PageActivated();
}
void __fastcall TMainForm::TransferPageBtnClick(TObject *Sender)
{
SetVisiblePage(TransferForm);
}
void __fastcall TMainForm::LibraryPageBtnClick(TObject *Sender)
{
SetVisiblePage(LibraryForm);
}
void __fastcall TMainForm::PlayerPageBtnClick(TObject *Sender)
{
SetVisiblePage(PlayerForm);
}
void __fastcall TMainForm::ChatPageBtnClick(TObject *Sender)
{
SetVisiblePage(ChatForm);
ChatForm->PageActivated();
}
void __fastcall TMainForm::StatusPageBtnClick(TObject *Sender)
{
SetVisiblePage(StatusForm);
}
//---------------------------------------------------------------------------
// engine callback
void __fastcall TMainForm::WMEngineCallback(TMessage& Msg)
{
TCallbackInfo* CbInfo = (TCallbackInfo*)Msg.WParam;
BrowserForm->EngineCallback(CbInfo);
SearchForm->EngineCallback(CbInfo);
TransferForm->EngineCallback(CbInfo);
LibraryForm->EngineCallback(CbInfo);
PlayerForm->EngineCallback(CbInfo);
StatusForm->EngineCallback(CbInfo);
switch(CbInfo->Code) {
case CbcStateChange: {
if(Engine->IsOnline()) {
// set if path mapper is needed
PathMapper->SetNeedToMap(!Engine->IsUsingLocalGift());
// enable various gui elements
ConnectMnu->Enabled = false;
DisconnectMnu->Enabled = true;
SearchPageBtn->Enabled = true;
TransferPageBtn->Enabled = true;
LibraryPageBtn->Enabled = true;
PlayerPageBtn->Enabled = true;
if(GetVisiblePage() == NULL)
SetVisiblePage(SearchForm);
// TRANSLATOR: status bar when online
MainStatusBar->Panels->Items[0]->Text = _("Online");
} else if(Engine->IsOffline()) {
if(ShuttingDown) {
Application->Terminate();
break;
}
ConnectMnu->Enabled = true;
DisconnectMnu->Enabled = false;
if(GetVisiblePage() == SearchForm ||
GetVisiblePage() == TransferForm ||
GetVisiblePage() == LibraryForm ||
GetVisiblePage() == PlayerForm)
{
if(BrowserPageBtn->Visible)
SetVisiblePage(BrowserForm);
else
SetVisiblePage(NULL);
}
SearchPageBtn->Enabled = false;
TransferPageBtn->Enabled = false;
LibraryPageBtn->Enabled = false;
PlayerPageBtn->Enabled = false;
// TRANSLATOR: status bar when offline
MainStatusBar->Panels->Items[0]->Text = _("Offline");
// if the connection close was unexpected tell the user and reconnect if gift is local
if(((int)CbInfo->Data2) == 1 && Config->GetValueInt("gift/remote") == 0) {
if(Engine->GetState () == TEngine::LaunchFailed) {
// TRANSLATOR: message box when giFT cannot be started
MessageDlg(_("{AppName} couldn't start the giFT backend required to connect.\n") +
_("You probably have a corrupt or incomplete install.\n" ) +
_("Reinstall {AppName} and make sure you also install giFT."),
mtError,TMsgDlgButtons() << mbOK,0);
} else {
// make copy of giftd.log
string src = Engine->GetLauncher()->GetConfPath() + "\\giftd.log";
string dst = Engine->GetLauncher()->GetConfPath() + "\\error.log";
CopyFile(src.c_str(), dst.c_str(), FALSE);
// TRANSLATOR: message box when giFT crashed
AnsiString Msg = AnsiString::Format(_("The connection to the giFT backend was unexpectedly lost.\n\n") +
_("An error log has been created at {AppName}\\giFT\\conf\\error.log.\n") +
_("Please email this file along with a description of when the problem ") +
_("occured to %s so the issue can be resolved.\n") +
_("Thank You.\n\n{AppName} will restart giFT now."),
ARRAYOFCONST((Brand->GetSupportEmail())));
// reconnect if users still wants to
if (MessageDlg(Msg,mtError,TMsgDlgButtons() << mbOK << mbCancel,0) == ID_OK)
ConnectMnu->Click();
}
}
}
break;
}
case CbcNetworksUpdate: {
AnsiString RemoteIndicator = "";
if (!Engine->IsUsingLocalGift())
RemoteIndicator = AnsiString::Format("[%s:%u] ", ARRAYOFCONST((Engine->GetGiftHost().c_str(),Engine->GetGiftPort())));
// TRANSLATOR: status bar when online
AnsiString Buf = AnsiString::Format(_("Online %s- Connected to %d of %d networks"),
ARRAYOFCONST((RemoteIndicator,
(int)((TNetworks*)CbInfo->Data1)->GetTotalConnected(),
(int)((TNetworks*)CbInfo->Data1)->GetNetworkCount())));
if (Config->GetValueInt("gui/show_network_stats")) {
// TRANSLATOR: status bar when online with stats
Buf += AnsiString::Format(_(" (%s users)"),
ARRAYOFCONST((FormatNumber(((TNetworks*)CbInfo->Data1)->GetTotalUsers()).c_str())));
}
MainStatusBar->Panels->Items[0]->Text = Buf;
break;
}
case CbcNetworkError:
if(ShuttingDown)
break; // we will get a state change right afterwards which will close us
AnsiString ErrMsg;
// TRANSLATOR: Message box on network error.
ErrMsg = _("Network Error:\n") + ((string*)CbInfo->Data1)->c_str();
if(Engine->IsUsingLocalGift() && !Engine->GetLauncher()->IsRunning()) {
// TRANSLATOR: In message box on network error if gift is not running.
ErrMsg += _("\ngiFT is not running!");
}
MessageDlg(ErrMsg,mtError,TMsgDlgButtons() << mbOK,0);
ConnectMnu->Enabled = true;
DisconnectMnu->Enabled = false;
// TRANSLATOR: status bar when offline
MainStatusBar->Panels->Items[0]->Text = _("Offline");
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ConnectMnuClick(TObject *Sender)
{
if(Config->GetValueInt("gift/remote")) {
Engine->TurnOnline(Config->GetValue("gift/remote_host"),Config->GetValueInt("gift/remote_port"));
} else {
if(!Engine->TurnOnline()) {
// TRANSLATOR: message box when connect fails
MessageDlg(_("{AppName} is unable to find giFT on the local machine.\n") +
_("If you don't know what this means you probably haven't installed KCeasy properly.\n") +
_("Reinstall it and make sure you also install giFT.\n") +
_("Otherwise enter the host and port you want to connect to manually in the configuration menu."),
mtError,TMsgDlgButtons() << mbOK,0);
Config->SetValueInt("gift/remote",1);
Config->Save();
ConfigMnu->Click();
} else {
// Remove SP2 limit if necessary. Calling this more than once is
// a nop.
RemoveSP2Limit();
}
}
}
void __fastcall TMainForm::DisconnectMnuClick(TObject *Sender)
{
Engine->TurnOffline();
}
void __fastcall TMainForm::ConfigMnuClick(TObject *Sender)
{
TConfigForm* ConfigDlg = new TConfigForm(this);
if(ConfigDlg->ShowModal() == mrOk) {
Config->Save();
// update used language
UseLanguage(Config->GetValue("gui/language").c_str());
// set main toolbar style
MainToolBar->List = !Config->GetValueInt("gui/page_icons_above_text");
for(int i = 0; i < MainToolBar->ButtonCount; i++)
MainToolBar->Buttons[i]->AutoSize = MainToolBar->List;
// update player controls
PlayerPanel->Visible = Config->GetValueInt("player/show_bottom_controls");
BottomSpacerPanel->Visible = PlayerPanel->Visible;
// update banned words / exntensions
string Banned = Config->GetValue("search/banned_words");
Engine->SetBannedWords(string_split(Banned,","));
Banned = Config->GetValue("search/banned_extensions");
Engine->SetBannedExtensions(string_split(Banned,","));
// update browser page
BrowserPageBtn->Visible = Config->GetValueInt("gui/show_browser_page");
if(!BrowserPageBtn->Visible && GetVisiblePage() == BrowserForm)
SetVisiblePage(SearchPageBtn->Enabled ? SearchForm : NULL);
BrowserForm->ConfigChanged();
// update status page
StatusPageBtn->Visible = Config->GetValueInt("gui/show_status_page");
if(!StatusPageBtn->Visible) {
if(GetVisiblePage() == StatusForm)
SetVisiblePage(SearchPageBtn->Enabled ? SearchForm : NULL);
StatusForm->GiftLoggingBtn->Down = false;
StatusForm->InterfaceLoggingBtn->Down = false;
}
// update chat page
ChatPageBtn->Visible = Config->GetValueInt("gui/show_chat_page");
if(!ChatPageBtn->Visible) {
if(GetVisiblePage() == ChatForm)
SetVisiblePage(SearchPageBtn->Enabled ? SearchForm : NULL);
// disconnect chat
ChatForm->Disconnect();
}
// update run registry key
if(Config->GetValueInt("gui/run_on_startup"))
WriteRegKey(Brand->ReplaceAppName(AnsiString(KCEASY_STARTUP_KEY)).c_str(),(Application->ExeName + " /hide").c_str());
else
WriteRegKey(Brand->ReplaceAppName(AnsiString(KCEASY_STARTUP_KEY)).c_str(),NULL);
// update tray icon
if(Config->GetValueInt("gui/minimize_to_tray")) {
if(TrayIcon == NULL) {
TrayIcon = new TTrayIcon(TrayPopup);
TrayIcon->SetHint(Brand->GetAppName().c_str());
}
} else {
if(TrayIcon != NULL) {
TrayIcon->RestoreApp();
delete TrayIcon;
TrayIcon = NULL;
}
}
// update wizard menu
if(Config->GetValueInt("gift/remote")) {
ConfigWizardMnu->Enabled = false;
RemoveSharesDbMnu->Enabled = false;
UpdateBanlistsMnu->Enabled = false;
} else {
ConfigWizardMnu->Enabled = true;
RemoveSharesDbMnu->Enabled = true;
UpdateBanlistsMnu->Enabled = true;
}
}
delete ConfigDlg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -