source: filezilla/trunk/fuentes/src/interface/settings/optionspage_logging.cpp @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 3.2 KB
Line 
1#include <filezilla.h>
2#include "../Options.h"
3#include "settingsdialog.h"
4#include "optionspage.h"
5#include "optionspage_logging.h"
6
7BEGIN_EVENT_TABLE(COptionsPageLogging, COptionsPage)
8EVT_BUTTON(XRCID("ID_BROWSE"), COptionsPageLogging::OnBrowse)
9EVT_CHECKBOX(XRCID("ID_LOGFILE"), COptionsPageLogging::OnCheck)
10EVT_CHECKBOX(XRCID("ID_DOLIMIT"), COptionsPageLogging::OnCheck)
11END_EVENT_TABLE()
12
13bool COptionsPageLogging::LoadPage()
14{
15        bool failure = false;
16
17        SetCheck(XRCID("ID_TIMESTAMPS"), m_pOptions->GetOptionVal(OPTION_MESSAGELOG_TIMESTAMP) ? true : false, failure);
18
19        const wxString filename = m_pOptions->GetOption(OPTION_LOGGING_FILE);
20        SetCheck(XRCID("ID_LOGFILE"), !filename.empty(), failure);
21        SetText(XRCID("ID_FILENAME"), filename, failure);
22
23        int limit = m_pOptions->GetOptionVal(OPTION_LOGGING_FILE_SIZELIMIT);
24        if (limit < 0 || limit > 2000)
25                limit = 0;
26        SetCheck(XRCID("ID_DOLIMIT"), limit > 0, failure);
27        if (!failure)
28                XRCCTRL(*this, "ID_LIMIT", wxTextCtrl)->SetMaxLength(4);
29
30        wxString v;
31        if (limit > 0)
32                v = wxString::Format(_T("%d"), limit);
33        SetText(XRCID("ID_LIMIT"), v, failure);
34
35        if (!failure)
36                SetCtrlState();
37
38        return !failure;
39}
40
41bool COptionsPageLogging::SavePage()
42{
43        m_pOptions->SetOption(OPTION_MESSAGELOG_TIMESTAMP, GetCheck(XRCID("ID_TIMESTAMPS")) ? 1 : 0);
44
45        wxString filename;
46        if (GetCheck(XRCID("ID_LOGFILE")))
47                filename = GetText(XRCID("ID_FILENAME"));
48        m_pOptions->SetOption(OPTION_LOGGING_FILE, filename);
49
50        if (GetCheck(XRCID("ID_DOLIMIT")))
51                SetOptionFromText(XRCID("ID_LIMIT"), OPTION_LOGGING_FILE_SIZELIMIT);
52        else
53                m_pOptions->SetOption(OPTION_LOGGING_FILE_SIZELIMIT, 0);
54
55        return true;
56}
57
58bool COptionsPageLogging::Validate()
59{
60        bool log_to_file = GetCheck(XRCID("ID_LOGFILE"));
61        bool limit = GetCheck(XRCID("ID_DOLIMIT"));
62
63        if (log_to_file)
64        {
65                wxTextCtrl *pFileName = XRCCTRL(*this, "ID_FILENAME", wxTextCtrl);
66                if (pFileName->GetValue().empty())
67                        return DisplayError(pFileName, _("You need to enter a name for the log file."));
68
69                wxFileName fn(pFileName->GetValue());
70                if (!fn.IsOk() || !fn.DirExists())
71                        return DisplayError(pFileName, _("Directory containing the logfile does not exist or filename is invalid."));
72
73                if (limit)
74                {
75                        unsigned long v;
76                        wxTextCtrl *pLimit = XRCCTRL(*this, "ID_LIMIT", wxTextCtrl);
77                        if (!pLimit->GetValue().ToULong(&v) || v < 1 || v > 2000)
78                                return DisplayError(pLimit, _("The limit needs to be between 1 and 2000 MiB"));
79                }
80        }
81        return true;
82}
83
84void COptionsPageLogging::SetCtrlState()
85{
86        bool log_to_file = GetCheck(XRCID("ID_LOGFILE"));
87        bool limit = GetCheck(XRCID("ID_DOLIMIT"));
88
89        XRCCTRL(*this, "ID_FILENAME", wxTextCtrl)->Enable(log_to_file);
90        XRCCTRL(*this, "ID_BROWSE", wxButton)->Enable(log_to_file);
91        XRCCTRL(*this, "ID_DOLIMIT", wxCheckBox)->Enable(log_to_file);
92        XRCCTRL(*this, "ID_LIMIT", wxTextCtrl)->Enable(log_to_file && limit);
93}
94
95void COptionsPageLogging::OnBrowse(wxCommandEvent& event)
96{
97        wxFileDialog dlg(this, _("Log file"), wxString(), _T("filezilla.log"), _T("Log files (*.log)|*.log"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
98
99        if (dlg.ShowModal() != wxID_OK)
100                return;
101
102        XRCCTRL(*this, "ID_FILENAME", wxTextCtrl)->ChangeValue(dlg.GetPath());
103}
104
105void COptionsPageLogging::OnCheck(wxCommandEvent& event)
106{
107        SetCtrlState();
108}
Note: See TracBrowser for help on using the repository browser.