📄 configdialog.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.
*/
//---------------------------------------------------------------------------
#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.hpp>
#undef NO_WIN32_LEAN_AND_MEAN
#include <vcl.h>
#include <KCeasy.h>
#pragma hdrstop
#include "ConfigDialog.h"
#include "istring.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TConfigForm *ConfigForm;
//---------------------------------------------------------------------------
// separator for banned words, also change in KCeasy.cpp
// also applies to banned extensions
static const char BannedWordsSepChar = ',';
static const char* BannedWordsSepCharStr = ",";
// word break proc for banned words tmemo
int CALLBACK BanWordBreakProc(char* text, int pos, int len, int code)
{
if(!text)
return 0;
// http://support.microsoft.com/default.aspx?scid=kb;EN-US;109551
// NOTE: text can be unicode on newer versions of windows.
// Try to figure it out with this hack and ignore extended chars.
int step = (len > 1 && text[1] == 0) ? 2 : 1;
switch(code) {
case WB_ISDELIMITER:
if(text[pos*step] == BannedWordsSepChar)
return TRUE;
return FALSE;
case WB_LEFT:
// look for word start left of current pos
text += (pos - 1) * step;
for(;pos > 0 && (*text == BannedWordsSepChar || *text == 0x0A); pos--, text -= step);
for(;pos > 0 && (*text != BannedWordsSepChar && *text != 0x0A); pos--, text -= step);
return pos;
case WB_RIGHT:
// look for word start right of current pos
text += pos * step;
for(;pos < len && *text != BannedWordsSepChar; pos++, text += step);
for(;pos < len && *text == BannedWordsSepChar; pos++, text += step);
return pos;
}
return 0; // shouldn't happen
}
//---------------------------------------------------------------------------
__fastcall TConfigForm::TConfigForm(TComponent* Owner)
: TForm(Owner),
MapChanged(false),
ChatFont(NULL)
{
TranslateComponent(this);
Caption = Brand->ReplaceAppName(Caption);
LangInfoLbl->Caption = Brand->ReplaceAppName(LangInfoLbl->Caption);
PatchTcpIpChk->Caption = Brand->ReplaceAppName(PatchTcpIpChk->Caption);
RunOnStartupChk->Caption = Brand->ReplaceAppName(RunOnStartupChk->Caption);
DownloadNoteStatic->Caption = Brand->ReplaceAppName(DownloadNoteStatic->Caption);
UploadNoteStatic->Caption = Brand->ReplaceAppName(UploadNoteStatic->Caption);
InfoColorLbl->Caption = Brand->ReplaceAppName(InfoColorLbl->Caption);
GiftInfoStatic->Caption = Brand->ReplaceAppName(GiftInfoStatic->Caption);
GiftMappingInfoStatic->Caption = Brand->ReplaceAppName(GiftMappingInfoStatic->Caption);
GiftMappingInfo1Static->Caption = Brand->ReplaceAppName(GiftMappingInfo1Static->Caption);
OpenftSearchNodeLbl->Caption = Brand->ReplaceAppName(OpenftSearchNodeLbl->Caption);
// populate nav tree with page headers
NavTree->Items->BeginUpdate();
NavTree->Items->Clear();
for(int i=0; i<ConfigPages->PageCount; i++) {
AnsiString Title = ConfigPages->Pages[i]->Caption;
int pos = Title.AnsiPos(".");
if(pos == 0) {
MessageDlg("Config header name \"" + Title + "\" translated incorrectly!\n"
"You forgot the dot!",mtError,TMsgDlgButtons() << mbOK,0);
continue;
}
AnsiString First = Title.SubString(1,pos-1);
AnsiString Second = Title.SubString(pos+1,Title.Length()-pos);
if(Second.Length() == 0) {
TTreeNode* Node = NavTree->Items->AddObject(NULL,First,ConfigPages->Pages[i]);
ConfigPages->Pages[i]->Tag = (unsigned int)Node;
} else {
// find right parent and add child
for(int x=ConfigPages->PageCount-1; x>=0; x--) {
if(ConfigPages->Pages[x]->Caption == First + ".") {
TTreeNode* Node = NavTree->Items->AddChildObject((TTreeNode*)ConfigPages->Pages[x]->Tag,
Second,ConfigPages->Pages[i]);
ConfigPages->Pages[i]->Tag = (unsigned int)Node;
break;
}
}
}
// make tab invisible
ConfigPages->Pages[i]->TabVisible = false;
}
NavTree->Items->EndUpdate();
NavTree->FullExpand();
SetStartPage(0);
// general page
ShowStatusPageChk->Checked = Config->GetValueInt("gui/show_status_page");
ShowChatPageChk->Checked = Config->GetValueInt("gui/show_chat_page");
ShowBrowserPageChk->Checked = Config->GetValueInt("gui/show_browser_page");
ShowNetworkStatsChk->Checked = Config->GetValueInt("gui/show_network_stats");
MinimizeToTrayChk->Checked = Config->GetValueInt("gui/minimize_to_tray");
PageIconsAboveTextChk->Checked = Config->GetValueInt("gui/page_icons_above_text");
UseSystemIconsChk->Checked = Config->GetValueInt("gui/use_system_file_icons");
RunOnStartupChk->Checked = Config->GetValueInt("gui/run_on_startup");
CheckForUpdatesChk->Checked = Config->GetValueInt("gui/update_check_interval");
PatchTcpIpChk->Checked = Config->GetValueInt("gui/use_tcpip_patcher");
// languages
DefaultInstance->GetListOfLanguages("default",LangCombo->Items);
// translate iso code to language name
DefaultInstance->bindtextdomainToFile("isolang","locale/isolang.mo");
DefaultInstance->TranslateProperties(LangCombo->Items,"isolang");
// select current language
LangCombo->ItemIndex = LangCombo->Items->IndexOf(dgettext("isolang",GetCurrentLanguage()));
// browser
BrowserEnableTabsChk->Checked = Config->GetValueInt("browser/enable_tabs");
BrowserTabsWithCloseButtonChk->Checked = Config->GetValueInt("browser/tabs_with_close_button");
BrowserOpenBookmarksInNewTabChk->Checked = Config->GetValueInt("browser/open_bookmarks_in_new_tab");
BrowserOpenNewWindowsAsTabsChk->Checked = Config->GetValueInt("browser/open_new_windows_as_tabs");
BrowserHandleMagnetsChk->Checked = Config->GetValueInt("browser/handle_magnets");
BrowserBlockPopupsChk->Checked = Config->GetValueInt("browser/block_popups");
// search page
EraseHistoryOnExitChk->Checked = Config->GetValueInt("search/erase_history_on_exit");
EnableFilteringChk->Checked = Config->GetValueInt("search/enable_filtering");
EnableHashRealmChk->Checked = Config->GetValueInt("search/enable_hash_realm");
EnableTorrentRealmChk->Checked = Config->GetValueInt("search/enable_torrent_realm");
FilterSingleSourceChk->Checked = Config->GetValueInt("search/filter_single_source_replies");
SortByAlphaNumChk->Checked = Config->GetValueInt("search/sort_by_alphanum");
AllowSearchMultiSelectChk->Checked = Config->GetValueInt("search/allow_multiselect");
HighlightDownloadsChk->Checked = Config->GetValueInt("search/highlight_downloads");
HighlightSharedChk->Checked = Config->GetValueInt("search/highlight_shared");
NeverDownloadSharedChk->Checked = Config->GetValueInt("search/never_download_shared");
RealmIconsOnTabsChk->Checked = Config->GetValueInt("search/realm_icons_on_tabs");
FilterBannedWordsChk->Checked = Config->GetValueInt("search/filter_banned_words");
FilterBannedExtensionsChk->Checked = Config->GetValueInt("search/filter_banned_extensions");
// install word wrap proc
SendMessage(BannedWordsMemo->Handle,EM_SETWORDBREAKPROC,0,(LPARAM)BanWordBreakProc);
BannedWordsMemo->Lines->Text = Config->GetValue("search/banned_words").c_str();
SendMessage(BannedExtensionsMemo->Handle,EM_SETWORDBREAKPROC,0,(LPARAM)BanWordBreakProc);
BannedExtensionsMemo->Lines->Text = Config->GetValue("search/banned_extensions").c_str();
// download page
if(Engine->IsUsingLocalGift()) {
MaxSourcesUpDown->Position = Config->GetValueInt("gift/max_sources");
DownloadBwUpDown->Position = (float)Engine->GetShares()->GetDownloadBandwidth()/1024;
// TODO: this doesn't work if we make UpdateDirs() async
Engine->GetShares()->UpdateDirs();
CompletedDirEdit->Text = Engine->GetShares()->GetCompletedDir().c_str();
IncomingDirEdit->Text = Engine->GetShares()->GetIncomingDir().c_str();
KeepCorruptedChk->Checked = Engine->GetShares()->GetKeepCorruptedDownloads();
} else {
MaxSourcesUpDown->Enabled = false;
MaxSourcesEdit->Enabled = false;
DownloadBwUpDown->Enabled = false;
DownloadBwEdit->Enabled = false;
CompletedDirEdit->Enabled = false;
CompletedDirBtn->Enabled = false;
IncomingDirEdit->Enabled = false;
IncomingDirBtn->Enabled = false;
KeepCorruptedChk->Enabled = false;
}
AutoClearDownloadsChk->Checked = Config->GetValueInt("download/autoclear_complete");
ConfirmDownloadCancelChk->Checked = Config->GetValueInt("download/confirm_cancel");
// upload
if(Engine->IsUsingLocalGift()) {
SharingEnabledChk->Checked = Engine->GetShares()->GetSharingEnabled();
MaxUploadsUpDown->Position = Engine->GetShares()->GetMaxUploads();
UploadBwUpDown->Position = (float)Engine->GetShares()->GetUploadBandwidth()/1024;
} else {
SharingEnabledChk->Enabled = false;
MaxUploadsUpDown->Enabled = false;
MaxUploadsEdit->Enabled = false;
UploadBwUpDown->Enabled = false;
UploadBwEdit->Enabled = false;
}
AutoClearUploadsChk->Checked = Config->GetValueInt("upload/autoclear_complete");
// player page
ShowBottomPlayerChk->Checked = Config->GetValueInt("player/show_bottom_controls");
ExternalPlayerChk->Checked = Config->GetValueInt("player/always_use_external");
VlcLoggingChk->Checked = Config->GetValueInt("player/vlc_logging") < 0 ? false : true;
// library page
LibraryUpdateOnConnectChk->Checked = Config->GetValueInt("library/update_on_connect");
LibraryUseRecycleBinChk->Checked = Config->GetValueInt("library/use_recycle_bin");
// chat page
ChatHostEdit->Text = Config->GetValue("chat/host").c_str();
ChatPortEdit->Text = int_to_string(Config->GetValueInt("chat/port")).c_str();
ChatNickEdit->Text = Config->GetValue("chat/nick").c_str();
ChatPwdEdit->Text = Config->GetValue("chat/nickserv_password").c_str();
ChatChannelsEdit->Text = Config->GetValue("chat/channels").c_str();
ChatHighlightChannelsChk->Checked = Config->GetValueInt("chat/highlight_channels");
ChatLogRawChk->Checked = Config->GetValueInt("chat/log_raw_messages");
// chat font and colors
ChatFont = StringToFont(Config->GetValue("chat/font"));
ChatFontEdit->Font->Assign(ChatFont);
ChatFontEdit->Text = Config->GetValue("chat/font").c_str();
NormalColorBox->Selected = StringToColor(Config->GetValue("chat/color_normal").c_str());
OthersColorBox->Selected = StringToColor(Config->GetValue("chat/color_others").c_str());
OwnColorBox->Selected = StringToColor(Config->GetValue("chat/color_own").c_str());
NoticeColorBox->Selected = StringToColor(Config->GetValue("chat/color_notice").c_str());
ActionColorBox->Selected = StringToColor(Config->GetValue("chat/color_action").c_str());
JoinColorBox->Selected = StringToColor(Config->GetValue("chat/color_join").c_str());
InfoColorBox->Selected = StringToColor(Config->GetValue("chat/color_info").c_str());
WarnColorBox->Selected = StringToColor(Config->GetValue("chat/color_warn").c_str());
// giFT page
GiftRemoteRadio->Checked = Config->GetValueInt("gift/remote");
GiftLocalRadio->Checked = !GiftRemoteRadio->Checked;
// local
// WARNING: Accessing OpenFT.conf from here!
OpenftSearchNodeChk->Checked = false;
string ConfPath = Application->ExeName.c_str();
ConfPath.erase(ConfPath.rfind('\\'));
ConfPath += OPENFT_CONF_PATH;
TFileConfig* OpenFTConfig = new TFileConfig(ConfPath);
if(OpenFTConfig->Load(true))
OpenftSearchNodeChk->Checked = (OpenFTConfig->GetValueInt("main/class") == 3);
delete OpenFTConfig;
if(!RunningWindowsNT()) {
OpenftSearchNodeChk->Checked = false;
OpenftSearchNodeChk->Enabled = false;
}
// remote
GiftHostEdit->Text = Config->GetValue("gift/remote_host").c_str();
GiftPortEdit->Text = int_to_string(Config->GetValueInt("gift/remote_port")).c_str();
// path mappings
MapListView->Items->BeginUpdate();
TPathMapper Mapper;
Mapper.Unserialize(Config->GetValue("gift/mapped_paths"));
for(TPathMapper::Iterator itr = Mapper.Begin(); itr != Mapper.End(); ++itr) {
TListItem* Item = MapListView->Items->Add();
Item->Caption = (*itr).Key.c_str();
Item->SubItems->Add((*itr).Path.c_str());
Item->ImageIndex = MainForm->IconManager->GetFolderIconIndex();
}
MapListView->Items->EndUpdate();
}
__fastcall TConfigForm::~TConfigForm()
{
delete ChatFont;
}
void __fastcall TConfigForm::SetStartPage(int Index)
{
ConfigPages->ActivePageIndex = Index;
}
void __fastcall TConfigForm::NavTreeChange(TObject *Sender,
TTreeNode *Node)
{
if(!Node)
return;
ConfigPages->ActivePage = (TTabSheet*)Node->Data;
}
void __fastcall TConfigForm::NavTreeDblClick(TObject *Sender)
{
// don't collapse anything on double click
NavTree->FullExpand();
}
void __fastcall TConfigForm::ConfigPagesChange(TObject *Sender)
{
TTreeNode* Node;
if((Node = (TTreeNode*)ConfigPages->ActivePage->Tag)) {
Node->Focused = true;
Node->Selected = true;
}
}
//---------------------------------------------------------------------------
bool TConfigForm::CheckSanity()
{
if(Engine->IsUsingLocalGift()) {
// don't allow incoming dir to be the same as the completed dir
if(CompletedDirEdit->Text.AnsiCompareIC(IncomingDirEdit->Text) == 0) {
// TRANSLATOR: Message box shown when user tries to set incomplete = completed in config dialog.
MessageDlg(_("You cannot set the Incomplete Folder the same as the Completed Folder!\n") +
_("The Incomplete Folder must not be shared."),mtError,TMsgDlgButtons() << mbOK,0);
return false;
}
}
return true;
}
void __fastcall TConfigForm::OKBtnClick(TObject *Sender)
{
if (!CheckSanity())
return;
// general page
Config->SetValueInt("gui/minimize_to_tray",MinimizeToTrayChk->Checked);
Config->SetValueInt("gui/page_icons_above_text",PageIconsAboveTextChk->Checked);
Config->SetValueInt("gui/use_system_file_icons",UseSystemIconsChk->Checked);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -