⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configdialog.cpp

📁 Last change: 2008-02-03 This is the source code of KCeasy。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    Config->SetValueInt("gui/show_status_page",ShowStatusPageChk->Checked);
    Config->SetValueInt("gui/show_chat_page",ShowChatPageChk->Checked);
    Config->SetValueInt("gui/show_browser_page",ShowBrowserPageChk->Checked);
    Config->SetValueInt("gui/show_network_stats",ShowNetworkStatsChk->Checked);
    Config->SetValueInt("gui/run_on_startup",RunOnStartupChk->Checked);
    Config->SetValueInt("gui/update_check_interval",CheckForUpdatesChk->Checked ? 6 : 0); // check every 6 days
    Config->SetValueInt("gui/use_tcpip_patcher",PatchTcpIpChk->Checked ? 1 : 0);
    // languages
    AnsiString NewLang = dgettext("isolang",LangCombo->Text);
    if(NewLang.Length() == 2 || NewLang.Length() == 5)
        Config->SetValue("gui/language",NewLang.c_str());

    // browser page
    Config->SetValueInt("browser/enable_tabs",BrowserEnableTabsChk->Checked);
    Config->SetValueInt("browser/tabs_with_close_button",BrowserTabsWithCloseButtonChk->Checked);
    Config->SetValueInt("browser/open_bookmarks_in_new_tab",BrowserOpenBookmarksInNewTabChk->Checked);
    Config->SetValueInt("browser/open_new_windows_as_tabs",BrowserOpenNewWindowsAsTabsChk->Checked);
    Config->SetValueInt("browser/handle_magnets",BrowserHandleMagnetsChk->Checked);
    Config->SetValueInt("browser/block_popups",BrowserBlockPopupsChk->Checked);

    // search page
    Config->SetValueInt("search/erase_history_on_exit",EraseHistoryOnExitChk->Checked);
    Config->SetValueInt("search/enable_filtering",EnableFilteringChk->Checked);
    Config->SetValueInt("search/enable_hash_realm",EnableHashRealmChk->Checked);
    Config->SetValueInt("search/enable_torrent_realm",EnableTorrentRealmChk->Checked);
    Config->SetValueInt("search/filter_single_source_replies",FilterSingleSourceChk->Checked);
    Config->SetValueInt("search/sort_by_alphanum",SortByAlphaNumChk->Checked);
    Config->SetValueInt("search/allow_multiselect",AllowSearchMultiSelectChk->Checked);
    Config->SetValueInt("search/highlight_downloads",HighlightDownloadsChk->Checked);
    Config->SetValueInt("search/highlight_shared",HighlightSharedChk->Checked);
    Config->SetValueInt("search/never_download_shared",NeverDownloadSharedChk->Checked);
    Config->SetValueInt("search/realm_icons_on_tabs",RealmIconsOnTabsChk->Checked);
    Config->SetValueInt("search/filter_banned_words",FilterBannedWordsChk->Checked);
    Config->SetValueInt("search/filter_banned_extensions",FilterBannedExtensionsChk->Checked);

    // remove all bad chars from banned words
    string WordsStr = BannedWordsMemo->Lines->Text.c_str();
    for(int pos = WordsStr.find_first_of("\r\n"); pos != -1; pos = WordsStr.find_first_of("\r\n"))
        WordsStr.erase(pos,1);
    list<string> Words = string_split(WordsStr,BannedWordsSepCharStr);
    for(list<string>::iterator itr = Words.begin(); itr != Words.end();) {
        list<string>::iterator curr_itr = itr;
        ++itr;
        *curr_itr = string_trim (*curr_itr);
        if(*curr_itr == "")
            Words.erase(curr_itr,itr); // invalidates curr_itr
    }
    Config->SetValue("search/banned_words",string_join(Words,BannedWordsSepCharStr));

    // remove all bad chars from banned extensions
    WordsStr = BannedExtensionsMemo->Lines->Text.c_str();
    for(int pos = WordsStr.find_first_of("\r\n"); pos != -1; pos = WordsStr.find_first_of("\r\n"))
        WordsStr.erase(pos,1);
    Words = string_split(WordsStr,BannedWordsSepCharStr);
    for(list<string>::iterator itr = Words.begin(); itr != Words.end();) {
        list<string>::iterator curr_itr = itr;
        ++itr;
        *curr_itr = string_trim (*curr_itr);
        if(*curr_itr == "")
            Words.erase(curr_itr,itr); // invalidates curr_itr
    }
    Config->SetValue("search/banned_extensions",string_join(Words,BannedWordsSepCharStr));

    // download page
    if(Engine->IsUsingLocalGift()) {
        Config->SetValueInt("gift/max_sources",MaxSourcesUpDown->Position);
        Engine->GetShares()->SetDownloadBandwidth(DownloadBwUpDown->Position*1024);
        Engine->GetShares()->SetCompletedDir(CompletedDirEdit->Text.c_str());
        Engine->GetShares()->SetIncomingDir(IncomingDirEdit->Text.c_str());
        Engine->GetShares()->SetKeepCorruptedDownloads(KeepCorruptedChk->Checked);
    }
    Config->SetValueInt("download/autoclear_complete",AutoClearDownloadsChk->Checked);
    Config->SetValueInt("download/confirm_cancel",ConfirmDownloadCancelChk->Checked);

    // upload page
    if(Engine->IsUsingLocalGift()) {
        Engine->GetShares()->SetSharingEnabled(SharingEnabledChk->Checked);
        Engine->GetShares()->SetMaxUploads(MaxUploadsUpDown->Position);
        Engine->GetShares()->SetUploadBandwidth(UploadBwUpDown->Position*1024);
    }
    Config->SetValueInt("upload/autoclear_complete",AutoClearUploadsChk->Checked);

    // player page
    Config->SetValueInt("player/show_bottom_controls",ShowBottomPlayerChk->Checked);
    Config->SetValueInt("player/always_use_external",ExternalPlayerChk->Checked);
    Config->SetValueInt("player/vlc_logging",VlcLoggingChk->Checked ? 2 : -1);

    // library page
    Config->SetValueInt("library/update_on_connect",LibraryUpdateOnConnectChk->Checked);
    Config->SetValueInt("library/use_recycle_bin",LibraryUseRecycleBinChk->Checked);

    // chat page
    Config->SetValue("chat/host",ChatHostEdit->Text.c_str());
    Config->SetValueInt("chat/port",string_to_int(ChatPortEdit->Text.c_str()));
    Config->SetValue("chat/nick",ChatNickEdit->Text.c_str());
    Config->SetValue("chat/nickserv_password",ChatPwdEdit->Text.c_str());
    Config->SetValue("chat/channels",ChatChannelsEdit->Text.c_str());
    Config->SetValueInt("chat/highlight_channels",ChatHighlightChannelsChk->Checked);
    Config->SetValueInt("chat/log_raw_messages",ChatLogRawChk->Checked);
    // chat font and colors
    Config->SetValue("chat/font",FontToString(ChatFont));
    Config->SetValue("chat/color_normal",ColorToString(NormalColorBox->Selected).c_str());
    Config->SetValue("chat/color_others",ColorToString(OthersColorBox->Selected).c_str());
    Config->SetValue("chat/color_own",ColorToString(OwnColorBox->Selected).c_str());
    Config->SetValue("chat/color_notice",ColorToString(NoticeColorBox->Selected).c_str());
    Config->SetValue("chat/color_action",ColorToString(ActionColorBox->Selected).c_str());
    Config->SetValue("chat/color_join",ColorToString(JoinColorBox->Selected).c_str());
    Config->SetValue("chat/color_info",ColorToString(InfoColorBox->Selected).c_str());
    Config->SetValue("chat/color_warn",ColorToString(WarnColorBox->Selected).c_str());

    // giFT page
    Config->SetValueInt("gift/remote",GiftRemoteRadio->Checked);
    if(GiftRemoteRadio->Checked) {
        // remote
        Config->SetValue("gift/remote_host",GiftHostEdit->Text.c_str());
        Config->SetValueInt("gift/remote_port",string_to_int(GiftPortEdit->Text.c_str()));
        // save path mappings
        if(MapChanged) {
            TPathMapper Mapper;
            for(int i=0; i<MapListView->Items->Count; i++)
                Mapper.Insert(MapListView->Items->Item[i]->Caption.c_str(),MapListView->Items->Item[i]->SubItems->Strings[0].c_str(),0);
            *PathMapper = Mapper;
            Config->SetValue("gift/mapped_paths",PathMapper->Serialize());
        }
    } else if(GiftLocalRadio->Checked) {
        // local
        // WARNING: Accessing OpenFT.conf from here!
        string ConfPath = Application->ExeName.c_str();
        ConfPath.erase(ConfPath.rfind('\\'));
        ConfPath += OPENFT_CONF_PATH;
        TFileConfig* OpenFTConfig = new TFileConfig(ConfPath);
        if(OpenFTConfig->Load(true)) {
            OpenFTConfig->SetValueInt("main/class", OpenftSearchNodeChk->Checked ? 3 : 1);
            OpenFTConfig->Save();
        }
        delete OpenFTConfig;
    }
    Config->Save();

    // return mrOK
    ModalResult = mrOk;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::rbtGiftModeChange(TObject *Sender)
{
    bool Remote = GiftRemoteRadio->Checked;
    // remote
    OpenftSearchNodeChk->Enabled = !Remote;
    OpenftSearchNodeLbl->Enabled = !Remote;
    GiftHostLbl->Enabled = Remote;
    GiftHostEdit->Enabled = Remote;
    GiftPortLbl->Enabled = Remote;
    GiftPortEdit->Enabled = Remote;
    GiftMappingGrp->Enabled = Remote;
    MapListView->Enabled = Remote;
    MapLbl->Enabled = Remote;
    MapMatchLbl->Enabled = Remote;
    MapReplacementLbl->Enabled = Remote;
    MapMatchEdit->Enabled = Remote;
    MapReplacementEdit->Enabled = Remote;
    MapRemoveBtn->Enabled = Remote && MapListView->ItemFocused;
    MapAddBtn->Enabled = Remote;
}

void __fastcall TConfigForm::MapListViewSelectItem(TObject *Sender,
      TListItem *Item, bool Selected)
{
    if(MapListView->ItemFocused) {
        MapRemoveBtn->Enabled = true;
        MapMatchEdit->Text = Item->Caption;
        MapReplacementEdit->Text = Item->SubItems->Strings[0];
    } else {
        MapRemoveBtn->Enabled = false;
    }
}

void __fastcall TConfigForm::MapListViewDragDrop(TObject *Sender,
      TObject *Source, int X, int Y)
{
    if(Sender != MapListView)
        return;

    int pos = MapListView->Items->IndexOf(MapListView->GetItemAt(X,Y));
    if(pos == -1)
        return;

    TListItem* OldItem = MapListView->ItemFocused; // should be the one dragged
    TListItem* NewItem = MapListView->Items->Insert(pos);
    if(!NewItem || !OldItem)
        return;

    // copy data of new
    NewItem->Caption = OldItem->Caption;
    NewItem->SubItems->Add(OldItem->SubItems->Strings[0]);
    NewItem->ImageIndex = OldItem->ImageIndex;
    // delete old
    OldItem->Delete();

    MapChanged = true;
}

void __fastcall TConfigForm::MapListViewDragOver(TObject *Sender,
      TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
    Accept = Sender == MapListView;
}

void __fastcall TConfigForm::MapRemoveBtnClick(TObject *Sender)
{
    if(MapListView->ItemFocused) {
        MapListView->ItemFocused->Delete();
        MapRemoveBtn->Enabled = MapListView->ItemFocused != NULL;
        MapChanged = true;
    }
}

void __fastcall TConfigForm::MapAddBtnClick(TObject *Sender)
{
    MapMatchEdit->Text = MapMatchEdit->Text.Trim();
    MapReplacementEdit->Text = MapReplacementEdit->Text.Trim();

    if(MapMatchEdit->Text == "" || MapReplacementEdit->Text == "") {
        MessageBeep(MB_ICONHAND);
        return;
    }

    TListItem* Item = MapListView->Items->Add();
    Item->Caption = MapMatchEdit->Text;
    Item->SubItems->Add(MapReplacementEdit->Text);
    Item->ImageIndex = MainForm->IconManager->GetFolderIconIndex();
    MapChanged = true;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::MaxUploadsEditChange(TObject *Sender)
{
    if(MaxUploadsUpDown->Position == 0)
        // TRANSLATOR: Shown in config dialog for unlimited uploads.
        MaxUploadsEdit->Text = _("Unlimited");
}

void __fastcall TConfigForm::UploadBwEditChange(TObject *Sender)
{
    if(UploadBwUpDown->Position == 0)
        // TRANSLATOR: Shown in config dialog for unlimited upload bandwidth.
        UploadBwEdit->Text = _("Unlimited");
}

void __fastcall TConfigForm::MaxSourcesEditChange(TObject *Sender)
{
    if(MaxSourcesUpDown->Position == 0)
        // TRANSLATOR: Shown in config dialog for unlimited sources.
        MaxSourcesEdit->Text = _("Unlimited");
}

void __fastcall TConfigForm::DownloadBwEditChange(TObject *Sender)
{
    if(DownloadBwUpDown->Position == 0)
        // TRANSLATOR: Shown in config dialog for unlimited download bandwidth.
        DownloadBwEdit->Text = _("Unlimited");
}

void __fastcall TConfigForm::EditOnlyNumericKeyPress(TObject *Sender,
      char &Key)
{
    // allow only numeric and backspace
    if((Key < '0' || Key > '9') && Key != 8)
        Key = 0;
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::CompletedDirBtnClick(TObject *Sender)
{
    char Dir[MAX_PATH];
    BROWSEINFO BrowseInfo;
    LPITEMIDLIST Pidl;

    memset(&BrowseInfo, 0, sizeof(BrowseInfo));
    BrowseInfo.hwndOwner = this->Handle;
    BrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS;
    // TRANSLATOR: Title of folder browser when selecting complete folder in config dialog.
    BrowseInfo.lpszTitle = _("Select Completed Folder").c_str();

    if((Pidl = SHBrowseForFolder(&BrowseInfo))) {
        if(SHGetPathFromIDList(Pidl, Dir)) {
            CompletedDirEdit->Text = Dir;
        }
        CoTaskMemFree(Pidl);
    }
}

void __fastcall TConfigForm::IncomingDirBtnClick(TObject *Sender)
{
    char Dir[MAX_PATH];
    BROWSEINFO BrowseInfo;
    LPITEMIDLIST Pidl;

    memset(&BrowseInfo, 0, sizeof(BrowseInfo));
    BrowseInfo.hwndOwner = this->Handle;
    BrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS;
    // TRANSLATOR: Title of folder browser when selecting incomplete folder in config dialog.
    BrowseInfo.lpszTitle = _("Select Incomplete Folder").c_str();

    if((Pidl = SHBrowseForFolder(&BrowseInfo))) {
        if(SHGetPathFromIDList(Pidl, Dir)) {
            IncomingDirEdit->Text = Dir;
        }
        CoTaskMemFree(Pidl);
    }
}
//---------------------------------------------------------------------------

void __fastcall TConfigForm::ChatFontBtnClick(TObject *Sender)
{
    TFontDialog* Dialog = new TFontDialog(this);
    Dialog->Font->Assign(ChatFont);
    Dialog->Options.Clear();
    Dialog->Options << fdAnsiOnly << fdForceFontExist;

    if(Dialog->Execute()) {
        ChatFont->Assign(Dialog->Font);
        ChatFontEdit->Font->Assign(ChatFont);
        ChatFontEdit->Text = FontToString(ChatFont).c_str();
    }

    delete Dialog;
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -