"Fossies" - the Fresh Open Source Software Archive

Member "filezilla-3.48.1/src/interface/settings/optionspage_dateformatting.cpp" (18 May 2020, 5511 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_dateformatting.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 
    3 #include "settingsdialog.h"
    4 #include "optionspage.h"
    5 #include "optionspage_dateformatting.h"
    6 
    7 #include "../Options.h"
    8 #include "../textctrlex.h"
    9 
   10 #include <wx/hyperlink.h>
   11 #include <wx/statbox.h>
   12 
   13 struct COptionsPageDateFormatting::impl final
   14 {
   15     wxRadioButton* date_system_{};
   16     wxRadioButton* date_iso_{};
   17     wxRadioButton* date_custom_{};
   18     wxTextCtrlEx* date_format_{};
   19     
   20     wxRadioButton* time_system_{};
   21     wxRadioButton* time_iso_{};
   22     wxRadioButton* time_custom_{};
   23     wxTextCtrlEx* time_format_{};
   24 };
   25 
   26 COptionsPageDateFormatting::COptionsPageDateFormatting()
   27     : impl_(std::make_unique<impl>())
   28 {
   29 }
   30 
   31 COptionsPageDateFormatting::~COptionsPageDateFormatting()
   32 {
   33 }
   34 
   35 
   36 bool COptionsPageDateFormatting::CreateControls(wxWindow* parent)
   37 {
   38     auto const& lay = m_pOwner->layout();
   39 
   40     Create(parent);
   41     auto main = lay.createFlex(1);
   42     main->AddGrowableCol(0);
   43     SetSizer(main);
   44 
   45     {
   46         auto [box, inner] = lay.createStatBox(main, _("Date formatting"), 1);
   47         impl_->date_system_ = new wxRadioButton(box, -1, _("Use system &defaults for current language"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
   48         inner->Add(impl_->date_system_);
   49         impl_->date_iso_ = new wxRadioButton(box, -1, _("&ISO 8601 (example: 2007-09-15)"));
   50         inner->Add(impl_->date_iso_);
   51         impl_->date_custom_ = new wxRadioButton(box, -1, _("C&ustom"));
   52         inner->Add(impl_->date_custom_);
   53 
   54         auto row = lay.createFlex(2);
   55         inner->Add(row, 0, wxLEFT, lay.indent);
   56         impl_->date_format_ = new wxTextCtrlEx(box, -1);
   57         row->Add(impl_->date_format_, lay.valign);
   58         row->Add(new wxStaticText(box, -1, _("(example: %Y-%m-%d)")), lay.valign);
   59     }
   60     {
   61         auto [box, inner] = lay.createStatBox(main, _("Time formatting"), 1);
   62         impl_->time_system_ = new wxRadioButton(box, -1, _("Us&e system &defaults for current language"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
   63         inner->Add(impl_->time_system_);
   64         impl_->time_iso_ = new wxRadioButton(box, -1, _("I&SO 8601 (example: 15:47)"));
   65         inner->Add(impl_->time_iso_);
   66         impl_->time_custom_ = new wxRadioButton(box, -1, _("Cus&tom"));
   67         inner->Add(impl_->time_custom_);
   68 
   69         auto row = lay.createFlex(2);
   70         inner->Add(row, 0, wxLEFT, lay.indent);
   71         impl_->time_format_ = new wxTextCtrlEx(box, -1);
   72         row->Add(impl_->time_format_, lay.valign);
   73         row->Add(new wxStaticText(box, -1, _("(example: %Y-%m-%d)")), lay.valign);
   74     }
   75 
   76     auto link = new wxHyperlinkCtrl(this, -1, _("Show details about custom date and time formats"), L"https://wiki.filezilla-project.org/Date_and_Time_formatting");
   77     link->SetToolTip(L"https://wiki.filezilla-project.org/Date_and_Time_formatting");
   78     main->Add(link);
   79 
   80     auto cb = [this](wxCommandEvent const&) { SetCtrlState(); };
   81     impl_->date_system_->Bind(wxEVT_RADIOBUTTON, cb);
   82     impl_->date_iso_->Bind(wxEVT_RADIOBUTTON, cb);
   83     impl_->date_custom_->Bind(wxEVT_RADIOBUTTON, cb);
   84     impl_->time_system_->Bind(wxEVT_RADIOBUTTON, cb);
   85     impl_->time_iso_->Bind(wxEVT_RADIOBUTTON, cb);
   86     impl_->time_custom_->Bind(wxEVT_RADIOBUTTON, cb);
   87 
   88     return true;
   89 }
   90 
   91 bool COptionsPageDateFormatting::LoadPage()
   92 {
   93     std::wstring const dateFormat = m_pOptions->GetOption(OPTION_DATE_FORMAT);
   94     if (dateFormat == _T("1")) {
   95         impl_->date_iso_->SetValue(true);
   96     }
   97     else if (!dateFormat.empty() && dateFormat[0] == '2') {
   98         impl_->date_custom_->SetValue(true);
   99         impl_->date_format_->ChangeValue(dateFormat.substr(1));
  100     }
  101     else {
  102         impl_->date_system_->SetValue(true);
  103     }
  104 
  105     std::wstring const timeFormat = m_pOptions->GetOption(OPTION_TIME_FORMAT);
  106     if (timeFormat == _T("1")) {
  107         impl_->time_iso_->SetValue(true);
  108     }
  109     else if (!timeFormat.empty() && timeFormat[0] == '2') {
  110         impl_->time_custom_->SetValue(true);
  111         impl_->time_format_->ChangeValue(timeFormat.substr(1));
  112     }
  113     else {
  114         impl_->time_system_->SetValue(true);
  115     }
  116 
  117     SetCtrlState();
  118 
  119     return true;
  120 }
  121 
  122 bool COptionsPageDateFormatting::SavePage()
  123 {
  124     std::wstring dateFormat;
  125     if (impl_->date_custom_->GetValue()) {
  126         dateFormat = L"2" + impl_->date_format_->GetValue().ToStdWstring();
  127     }
  128     else if (impl_->date_iso_->GetValue()) {
  129         dateFormat = L"1";
  130     }
  131     else {
  132         dateFormat = L"0";
  133     }
  134     m_pOptions->SetOption(OPTION_DATE_FORMAT, dateFormat);
  135 
  136     std::wstring timeFormat;
  137     if (impl_->time_custom_->GetValue()) {
  138         timeFormat = L"2" + impl_->time_format_->GetValue().ToStdWstring();
  139     }
  140     else if (impl_->time_iso_->GetValue()) {
  141         timeFormat = L"1";
  142     }
  143     else {
  144         timeFormat = L"0";
  145     }
  146     m_pOptions->SetOption(OPTION_TIME_FORMAT, timeFormat);
  147 
  148     return true;
  149 }
  150 
  151 bool COptionsPageDateFormatting::Validate()
  152 {
  153     if (impl_->date_custom_->GetValue()) {
  154         std::wstring const dateformat = impl_->date_format_->GetValue().ToStdWstring();
  155         if (dateformat.empty()) {
  156             return DisplayError(impl_->date_format_, _("Please enter a custom date format."));
  157         }
  158         if (!fz::datetime::verify_format(dateformat)) {
  159             return DisplayError(impl_->date_format_, _("The custom date format is invalid or contains unsupported format specifiers."));
  160         }
  161     }
  162 
  163     if (impl_->time_custom_->GetValue()) {
  164         std::wstring const timeformat = impl_->time_format_->GetValue().ToStdWstring();
  165         if (timeformat.empty()) {
  166             return DisplayError(impl_->time_format_, _("Please enter a custom time format."));
  167         }
  168         if (!fz::datetime::verify_format(timeformat)) {
  169             return DisplayError(impl_->time_format_, _("The custom time format is invalid or contains unsupported format specifiers."));
  170         }
  171     }
  172 
  173     return true;
  174 }
  175 
  176 void COptionsPageDateFormatting::SetCtrlState()
  177 {
  178     impl_->date_format_->Enable(impl_->date_custom_->GetValue());
  179     impl_->time_format_->Enable(impl_->time_custom_->GetValue());
  180 }