"Fossies" - the Fresh Open Source Software Archive

Member "filezilla-3.48.1/src/interface/settings/optionspage_connection.cpp" (7 May 2020, 3762 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 "optionspage_connection.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 "optionspage.h"
    4 #include "optionspage_connection.h"
    5 
    6 #include "../Options.h"
    7 #include "../textctrlex.h"
    8 
    9 #include <wx/statbox.h>
   10 
   11 struct COptionsPageConnection::impl
   12 {
   13     wxTextCtrlEx* timeout_{};
   14     wxTextCtrlEx* tries_{};
   15     wxTextCtrlEx* delay_{};
   16 };
   17 
   18 COptionsPageConnection::COptionsPageConnection()
   19     : impl_(std::make_unique<impl>())
   20 {
   21 }
   22 
   23 COptionsPageConnection::~COptionsPageConnection()
   24 {
   25 }
   26 
   27 bool COptionsPageConnection::CreateControls(wxWindow* parent)
   28 {
   29     auto const& lay = m_pOwner->layout();
   30 
   31     Create(parent);
   32     auto main = lay.createFlex(1);
   33     main->AddGrowableCol(0);
   34     SetSizer(main);
   35 
   36     {
   37         auto [box, inner] = lay.createStatBox(main, _("Timeout"), 1);
   38         auto row = lay.createFlex(3);
   39         inner->Add(row);
   40         row->Add(new wxStaticText(box, -1, _("Time&out in seconds:")), lay.valign);
   41         impl_->timeout_ = new wxTextCtrlEx(box, -1, wxString(), wxDefaultPosition, wxSize(lay.dlgUnits(22), -1));
   42         impl_->timeout_->SetMaxLength(4);
   43         row->Add(impl_->timeout_, lay.valign);
   44         row->Add(new wxStaticText(box, -1, _("(10-9999, 0 to disable)")), lay.valign);
   45         inner->Add(new wxStaticText(box, -1, _("If no data is sent or received during an operation for longer than the specified time, the connection will be closed and FileZilla will try to reconnect.")));
   46     }
   47     {
   48         auto [box, inner] = lay.createStatBox(main, _("Reconnection settings"), 1);
   49         auto rows = lay.createFlex(3);
   50         inner->Add(rows);
   51         rows->Add(new wxStaticText(box, -1, _("&Maximum number of retries:")), lay.valign);
   52         impl_->tries_ = new wxTextCtrlEx(box, -1, wxString(), wxDefaultPosition, wxSize(lay.dlgUnits(22), -1));
   53         impl_->tries_->SetMaxLength(2);
   54         rows->Add(impl_->tries_, lay.valign);
   55         rows->Add(new wxStaticText(box, -1, _("(0-99)")), lay.valign);
   56         rows->Add(new wxStaticText(box, -1, _("&Delay between failed login attempts:")), lay.valign);
   57         impl_->delay_ = new wxTextCtrlEx(box, -1, wxString(), wxDefaultPosition, wxSize(lay.dlgUnits(22), -1));
   58         impl_->delay_->SetMaxLength(3);
   59         rows->Add(impl_->delay_, lay.valign);
   60         rows->Add(new wxStaticText(box, -1, _("(0-999 seconds)")), lay.valign);
   61 
   62         inner->Add(new wxStaticText(box, -1, _("Please note that some servers might ban you if you try to reconnect too often or in too short intervals.")));
   63     }
   64     return true;
   65 }
   66 
   67 bool COptionsPageConnection::LoadPage()
   68 {
   69     impl_->timeout_->ChangeValue(fz::to_wstring(m_pOptions->GetOptionVal(OPTION_TIMEOUT)));
   70     impl_->tries_->ChangeValue(fz::to_wstring(m_pOptions->GetOptionVal(OPTION_RECONNECTCOUNT)));
   71     impl_->delay_->ChangeValue(fz::to_wstring(m_pOptions->GetOptionVal(OPTION_RECONNECTDELAY)));
   72     return true;
   73 }
   74 
   75 bool COptionsPageConnection::SavePage()
   76 {
   77     m_pOptions->SetOption(OPTION_TIMEOUT, impl_->timeout_->GetValue().ToStdWstring());
   78     m_pOptions->SetOption(OPTION_RECONNECTCOUNT, impl_->tries_->GetValue().ToStdWstring());
   79     m_pOptions->SetOption(OPTION_RECONNECTDELAY, impl_->delay_->GetValue().ToStdWstring());
   80     return true;
   81 }
   82 
   83 bool COptionsPageConnection::Validate()
   84 {
   85     auto const timeout = fz::to_integral<int>(impl_->timeout_->GetValue().ToStdWstring(), -1);
   86     if (timeout != 0 && (timeout < 10 || timeout > 9999)) {
   87         return DisplayError(impl_->timeout_, _("Please enter a timeout between 10 and 9999 seconds or 0 to disable timeouts."));
   88     }
   89 
   90     auto const retries = fz::to_integral<int>(impl_->tries_->GetValue().ToStdWstring(), -1);
   91     if (retries < 0 || retries > 99) {
   92         return DisplayError(impl_->tries_, _("Number of retries has to be between 0 and 99."));
   93     }
   94 
   95     auto const delay = fz::to_integral<int>(impl_->delay_->GetValue().ToStdWstring(), -1);
   96     if (delay < 0 || delay > 999) {
   97         return DisplayError(impl_->delay_, _("Delay between failed connection attempts has to be between 1 and 999 seconds."));
   98     }
   99 
  100     return true;
  101 }