"Fossies" - the Fresh Open Source Software Archive

Member "filezilla-3.48.1/src/interface/settings/settingsdialog.cpp" (18 May 2020, 7767 Bytes) of package /linux/misc/FileZilla_3.48.1_src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "settingsdialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.48.0_vs_3.48.1.

    1 #include <filezilla.h>
    2 #include "settingsdialog.h"
    3 #include "../Options.h"
    4 #include "optionspage.h"
    5 #include "optionspage_connection.h"
    6 #include "optionspage_connection_ftp.h"
    7 #include "optionspage_connection_active.h"
    8 #include "optionspage_connection_passive.h"
    9 #include "optionspage_ftpproxy.h"
   10 #include "optionspage_connection_sftp.h"
   11 #include "optionspage_filetype.h"
   12 #include "optionspage_fileexists.h"
   13 #include "optionspage_themes.h"
   14 #include "optionspage_language.h"
   15 #include "optionspage_transfer.h"
   16 #include "optionspage_updatecheck.h"
   17 #include "optionspage_logging.h"
   18 #include "optionspage_debug.h"
   19 #include "optionspage_interface.h"
   20 #include "optionspage_dateformatting.h"
   21 #include "optionspage_sizeformatting.h"
   22 #include "optionspage_edit.h"
   23 #include "optionspage_edit_associations.h"
   24 #include "optionspage_passwords.h"
   25 #include "optionspage_proxy.h"
   26 #include "optionspage_filelists.h"
   27 #include "../filezillaapp.h"
   28 #include "../Mainfrm.h"
   29 #include "../treectrlex.h"
   30 #include "../xrc_helper.h"
   31 
   32 BEGIN_EVENT_TABLE(CSettingsDialog, wxDialogEx)
   33 EVT_TREE_SEL_CHANGING(XRCID("ID_TREE"), CSettingsDialog::OnPageChanging)
   34 EVT_TREE_SEL_CHANGED(XRCID("ID_TREE"), CSettingsDialog::OnPageChanged)
   35 EVT_BUTTON(XRCID("wxID_OK"), CSettingsDialog::OnOK)
   36 EVT_BUTTON(XRCID("wxID_CANCEL"), CSettingsDialog::OnCancel)
   37 END_EVENT_TABLE()
   38 
   39 CSettingsDialog::CSettingsDialog(CFileZillaEngineContext & engine_context)
   40     : m_engine_context(engine_context)
   41 {
   42     m_pOptions = COptions::Get();
   43 }
   44 
   45 CSettingsDialog::~CSettingsDialog()
   46 {
   47 }
   48 
   49 bool CSettingsDialog::Create(CMainFrame* pMainFrame)
   50 {
   51     m_pMainFrame = pMainFrame;
   52 
   53     SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
   54     if (!wxDialogEx::Create(pMainFrame, -1, _("Settings"))) {
   55         return false;
   56     }
   57 
   58     auto & lay = layout();
   59     auto * main = lay.createMain(this, 2);
   60     main->AddGrowableRow(0);
   61 
   62     auto* left = lay.createFlex(1);
   63     left->AddGrowableRow(1);
   64     main->Add(left, 1, wxGROW);
   65 
   66     left->Add(new wxStaticText(this, -1, _("Select &page:")));
   67 
   68     tree_ = new wxTreeCtrlEx(this, XRCID("ID_TREE"), wxDefaultPosition, wxDefaultSize, DEFAULT_TREE_STYLE | wxTR_HIDE_ROOT);
   69     tree_->SetFocus();
   70     left->Add(tree_, 1, wxGROW);
   71 
   72     auto ok = new wxButton(this, wxID_OK, _("OK"));
   73     ok->SetDefault();
   74     left->Add(ok, lay.grow);
   75     left->Add(new wxButton(this, wxID_CANCEL, _("Cancel")), lay.grow);
   76 
   77     pagePanel_ = new wxPanel(this);
   78     main->Add(pagePanel_, lay.grow);
   79 
   80     if (!LoadPages()) {
   81         return false;
   82     }
   83 
   84     return true;
   85 }
   86 
   87 void CSettingsDialog::AddPage(wxString const& name, COptionsPage* page, int nest)
   88 {
   89     wxTreeItemId parent = tree_->GetRootItem();
   90     while (nest--) {
   91         parent = tree_->GetLastChild(parent);
   92         wxCHECK_RET(parent != wxTreeItemId(), "Nesting level too deep");
   93     }
   94 
   95     t_page p;
   96     p.page = page;
   97     p.id = tree_->AppendItem(parent, name);
   98     if (parent != tree_->GetRootItem()) {
   99         tree_->Expand(parent);
  100     }
  101 
  102     m_pages.push_back(p);
  103 }
  104 
  105 bool CSettingsDialog::LoadPages()
  106 {
  107     InitXrc(L"settings.xrc");
  108 
  109     // Get the tree control.
  110 
  111     if (!tree_) {
  112         return false;
  113     }
  114 
  115     tree_->AddRoot(wxString());
  116 
  117     // Create the instances of the page classes and fill the tree.
  118     AddPage(_("Connection"), new COptionsPageConnection, 0);
  119     AddPage(_("FTP"), new COptionsPageConnectionFTP, 1);
  120     AddPage(_("Active mode"), new COptionsPageConnectionActive, 2);
  121     AddPage(_("Passive mode"), new COptionsPageConnectionPassive, 2);
  122     AddPage(_("FTP Proxy"), new COptionsPageFtpProxy, 2);
  123     AddPage(_("SFTP"), new COptionsPageConnectionSFTP, 1);
  124     AddPage(_("Generic proxy"), new COptionsPageProxy, 1);
  125     AddPage(_("Transfers"), new COptionsPageTransfer, 0);
  126     AddPage(_("FTP: File Types"), new COptionsPageFiletype, 1);
  127     AddPage(_("File exists action"), new COptionsPageFileExists, 1);
  128     AddPage(_("Interface"), new COptionsPageInterface, 0);
  129     AddPage(_("Passwords"), new COptionsPagePasswords, 1);
  130     AddPage(_("Themes"), new COptionsPageThemes, 1);
  131     AddPage(_("Date/time format"), new COptionsPageDateFormatting, 1);
  132     AddPage(_("Filesize format"), new COptionsPageSizeFormatting, 1);
  133     AddPage(_("File lists"), new COptionsPageFilelists, 1);
  134     AddPage(_("Language"), new COptionsPageLanguage, 0);
  135     AddPage(_("File editing"), new COptionsPageEdit, 0);
  136     AddPage(_("Filetype associations"), new COptionsPageEditAssociations, 1);
  137 #if FZ_MANUALUPDATECHECK && FZ_AUTOUPDATECHECK
  138     if (!m_pOptions->GetOptionVal(OPTION_DEFAULT_DISABLEUPDATECHECK)) {
  139         AddPage(_("Updates"), new COptionsPageUpdateCheck, 0);
  140     }
  141 #endif //FZ_MANUALUPDATECHECK && FZ_AUTOUPDATECHECK
  142     AddPage(_("Logging"), new COptionsPageLogging, 0);
  143     AddPage(_("Debug"), new COptionsPageDebug, 0);
  144 
  145     tree_->SetQuickBestSize(false);
  146     tree_->InvalidateBestSize();
  147     tree_->SetInitialSize();
  148 
  149     // Compensate for scrollbar
  150     wxSize size = tree_->GetBestSize();
  151     int scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, tree_);
  152     size.x += scrollWidth + 2;
  153     size.y = 400;
  154     tree_->SetInitialSize(size);
  155     Layout();
  156 
  157     // Before we can initialize the pages, get the target panel in the settings
  158     // dialog.
  159     if (!pagePanel_) {
  160         return false;
  161     }
  162 
  163     // Keep track of maximum page size
  164     size = wxSize();
  165 
  166     for (auto const& page : m_pages) {
  167         if (!page.page->CreatePage(m_pOptions, this, pagePanel_, size)) {
  168             return false;
  169         }
  170     }
  171 
  172     if (!LoadSettings()) {
  173         wxMessageBoxEx(_("Failed to load panels, invalid resource files?"));
  174         return false;
  175     }
  176 
  177     wxSize canvas;
  178     canvas.x = GetSize().x - pagePanel_->GetSize().x;
  179     canvas.y = GetSize().y - pagePanel_->GetSize().y;
  180 
  181     // Wrap pages nicely
  182     std::vector<wxWindow*> pages;
  183     for (auto const& page : m_pages) {
  184         pages.push_back(page.page);
  185     }
  186     wxGetApp().GetWrapEngine()->WrapRecursive(pages, 1.33, "Settings", canvas);
  187 
  188 #ifdef __WXGTK__
  189     // Pre-show dialog under GTK, else panels won't get initialized properly
  190     Show();
  191 #endif
  192 
  193     // Keep track of maximum page size
  194     size = wxSize(0, 0);
  195     for (auto const& page : m_pages) {
  196         auto sizer = page.page->GetSizer();
  197         if (sizer) {
  198             size.IncTo(sizer->GetMinSize());
  199         }
  200     }
  201 
  202     wxSize panelSize = size;
  203 #ifdef __WXGTK__
  204     panelSize.x += 1;
  205 #endif
  206     pagePanel_->SetInitialSize(panelSize);
  207 
  208     // Adjust pages sizes according to maximum size
  209     for (auto const& page : m_pages) {
  210         auto sizer = page.page->GetSizer();
  211         if (sizer) {
  212             sizer->SetMinSize(size);
  213             sizer->Fit(page.page);
  214             sizer->SetSizeHints(page.page);
  215         }
  216         if (GetLayoutDirection() == wxLayout_RightToLeft) {
  217             page.page->Move(wxPoint(1, 0));
  218         }
  219     }
  220 
  221     GetSizer()->Fit(this);
  222     GetSizer()->SetSizeHints(this);
  223 
  224     for (auto const& page : m_pages) {
  225         page.page->Hide();
  226     }
  227 
  228     // Select first page
  229     tree_->SelectItem(m_pages[0].id);
  230     if (!m_activePanel) {
  231         m_activePanel = m_pages[0].page;
  232         m_activePanel->Display();
  233     }
  234 
  235     return true;
  236 }
  237 
  238 bool CSettingsDialog::LoadSettings()
  239 {
  240     for (auto const& page : m_pages) {
  241         if (!page.page->LoadPage()) {
  242             return false;
  243         }
  244     }
  245 
  246     return true;
  247 }
  248 
  249 void CSettingsDialog::OnPageChanged(wxTreeEvent& event)
  250 {
  251     if (m_activePanel) {
  252         m_activePanel->Hide();
  253     }
  254 
  255     wxTreeItemId item = event.GetItem();
  256 
  257     for (auto const& page : m_pages) {
  258         if (page.id == item) {
  259             m_activePanel = page.page;
  260             m_activePanel->Display();
  261             break;
  262         }
  263     }
  264 }
  265 
  266 void CSettingsDialog::OnOK(wxCommandEvent&)
  267 {
  268     for (auto const& page : m_pages) {
  269         if (!page.page->Validate()) {
  270             if (m_activePanel != page.page) {
  271                 tree_->SelectItem(page.id);
  272             }
  273             return;
  274         }
  275     }
  276 
  277     for (auto const& page : m_pages) {
  278         page.page->SavePage();
  279     }
  280 
  281     EndModal(wxID_OK);
  282 }
  283 
  284 void CSettingsDialog::OnCancel(wxCommandEvent&)
  285 {
  286     EndModal(wxID_CANCEL);
  287 
  288     for (auto const& saved : m_oldValues) {
  289         m_pOptions->SetOption(saved.first, saved.second);
  290     }
  291 }
  292 
  293 void CSettingsDialog::OnPageChanging(wxTreeEvent& event)
  294 {
  295     if (!m_activePanel) {
  296         return;
  297     }
  298 
  299     if (!m_activePanel->Validate()) {
  300         event.Veto();
  301     }
  302 }
  303 
  304 void CSettingsDialog::RememberOldValue(int option)
  305 {
  306     m_oldValues[option] = m_pOptions->GetOption(option);
  307 }