1 /*************************************************************************
2 Copyright (C) 2006 Madhan Kanagavel
3 copyright (C) 2011, 2012 Nikolay & Stefano Giorgio.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *************************************************************************/
19
20 #include "optionsdialog.h"
21 #include "constants.h"
22 #include "paths.h"
23
24 #include "../resources/main-setup.xpm"
25 #include "../resources/preferences-attachments.xpm"
26 #include "../resources/preferences-network.xpm"
27 #include "../resources/preferences-other.xpm"
28 #include "../resources/view.xpm"
29
30 #include "mmOptionGeneralSettings.h"
31 #include "mmOptionViewSettings.h"
32 #include "mmOptionAttachmentSettings.h"
33 #include "mmOptionNetSettings.h"
34 #include "mmOptionMiscSettings.h"
35
36 wxIMPLEMENT_DYNAMIC_CLASS(mmOptionsDialog, wxDialog);
37
wxBEGIN_EVENT_TABLE(mmOptionsDialog,wxDialog)38 wxBEGIN_EVENT_TABLE( mmOptionsDialog, wxDialog )
39 EVT_BUTTON(wxID_OK, mmOptionsDialog::OnOk)
40 EVT_BUTTON(wxID_APPLY, mmOptionsDialog::OnApply)
41 wxEND_EVENT_TABLE()
42
43 mmOptionsDialog::mmOptionsDialog( )
44 {
45 }
46
~mmOptionsDialog()47 mmOptionsDialog::~mmOptionsDialog( )
48 {
49 delete m_imageList;
50 }
51
mmOptionsDialog(wxWindow * parent,mmGUIApp * app)52 mmOptionsDialog::mmOptionsDialog(wxWindow* parent, mmGUIApp* app): m_app(app)
53 {
54 long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCLOSE_BOX;
55 Create(parent, wxID_ANY, _("MMEX Options"), wxDefaultPosition, wxSize(500, 400), style);
56 }
57
Create(wxWindow * parent,wxWindowID id,const wxString & caption,const wxPoint & pos,const wxSize & size,long style)58 bool mmOptionsDialog::Create(wxWindow* parent
59 , wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style)
60 {
61 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
62 wxDialog::Create(parent, id, caption, pos, size, style);
63
64 CreateControls();
65 GetSizer()->Fit(this);
66 GetSizer()->SetSizeHints(this);
67 this->SetInitialSize();
68 SetIcon(mmex::getProgramIcon());
69
70 Centre();
71 return TRUE;
72 }
73
CreateControls()74 void mmOptionsDialog::CreateControls()
75 {
76 wxSize imageSize(48, 48);
77 m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
78 m_imageList->Add(wxBitmap(view_xpm));
79 m_imageList->Add(wxBitmap(preferences_attachments_xpm));
80 m_imageList->Add(wxBitmap(main_setup_xpm));
81 m_imageList->Add(wxBitmap(preferences_other_xpm));
82 m_imageList->Add(wxBitmap(preferences_network_xpm));
83
84 wxBoxSizer* mainDialogSizer = new wxBoxSizer(wxVERTICAL);
85 this->SetSizer(mainDialogSizer);
86
87 wxPanel* mainDialogPanel = new wxPanel(this, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
88 mainDialogSizer->Add(mainDialogPanel, 1, wxGROW|wxALL, 5);
89
90 wxBoxSizer* mainDialogPanelSizer = new wxBoxSizer(wxVERTICAL);
91 mainDialogPanel->SetSizer(mainDialogPanelSizer);
92
93 m_notebook = new wxListbook(mainDialogPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLB_LEFT);
94 m_notebook->SetImageList(m_imageList);
95
96 /*********************************************************************************************
97 General Panel
98 **********************************************************************************************/
99 mmOptionGeneralSettings* general_panel = new mmOptionGeneralSettings(m_notebook, m_app);
100 m_panel_list.push_back(general_panel);
101
102 /*********************************************************************************************
103 Views Panel
104 **********************************************************************************************/
105 mmOptionViewSettings* views_panel = new mmOptionViewSettings(m_notebook);
106 m_panel_list.push_back(views_panel);
107
108 /*********************************************************************************************
109 Attachments Panel
110 **********************************************************************************************/
111 mmOptionAttachmentSettings* attachment_panel = new mmOptionAttachmentSettings(m_notebook);
112 m_panel_list.push_back(attachment_panel);
113
114 /*********************************************************************************************
115 Network Panel
116 **********************************************************************************************/
117 mmOptionNetSettings* network_panel = new mmOptionNetSettings(m_notebook);
118 m_panel_list.push_back(network_panel);
119
120 /*********************************************************************************************
121 Others Panel
122 **********************************************************************************************/
123 mmOptionMiscSettings* others_panel = new mmOptionMiscSettings(m_notebook);
124 m_panel_list.push_back(others_panel);
125
126 /**********************************************************************************************
127 Add the panels to the notebook
128 **********************************************************************************************/
129 m_notebook->InsertPage(0, general_panel, _("General"), true, 2);
130 m_notebook->InsertPage(1, views_panel, _("View Options"), false, 0);
131 m_notebook->InsertPage(2, attachment_panel, _("Attachments"), false, 1);
132 m_notebook->InsertPage(3, network_panel, _("Network"), false, 4);
133 m_notebook->InsertPage(4, others_panel, _("Others"), false, 3);
134
135 mainDialogPanelSizer->Add(m_notebook, g_flagsExpand);
136 mainDialogPanelSizer->Layout();
137
138 /**********************************************************************************************
139 Button Panel with OK and Cancel Buttons
140 **********************************************************************************************/
141 wxStaticLine* panelSeparatorLine = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
142 mainDialogSizer->Add(panelSeparatorLine, 0, wxGROW | wxLEFT | wxRIGHT, 10);
143
144 wxPanel* buttonPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
145 wxBoxSizer* buttonPanelSizer = new wxBoxSizer(wxHORIZONTAL);
146 buttonPanel->SetSizer(buttonPanelSizer);
147 mainDialogSizer->Add(buttonPanel, wxSizerFlags(g_flags).Center());
148
149 wxButton* itemButtonOK = new wxButton(buttonPanel, wxID_OK, _("&OK "));
150 wxButton* itemButtonApply = new wxButton(buttonPanel, wxID_APPLY, _("&Apply"));
151 wxButton* itemButtonCancel = new wxButton(buttonPanel, wxID_CANCEL, wxGetTranslation(g_CancelLabel));
152 buttonPanelSizer->Add(itemButtonOK, g_flags);
153 buttonPanelSizer->Add(itemButtonApply, g_flags);
154 buttonPanelSizer->Add(itemButtonCancel, g_flags);
155 itemButtonOK->SetFocus();
156 }
157
158 /// Saves the updated System Options to the appropriate databases.
SaveNewSystemSettings()159 void mmOptionsDialog::SaveNewSystemSettings()
160 {
161 Model_Infotable::instance().Savepoint();
162 Model_Setting::instance().Savepoint();
163
164 for (const auto notebook_panel : m_panel_list)
165 notebook_panel->SaveSettings();
166
167 Model_Setting::instance().ReleaseSavepoint();
168 Model_Infotable::instance().ReleaseSavepoint();
169 }
170
OnOk(wxCommandEvent &)171 void mmOptionsDialog::OnOk(wxCommandEvent& /*event*/)
172 {
173 this->SaveNewSystemSettings();
174 EndModal(wxID_OK);
175 }
176
OnApply(wxCommandEvent &)177 void mmOptionsDialog::OnApply(wxCommandEvent& /*event*/)
178 {
179 Model_Infotable::instance().Savepoint();
180 Model_Setting::instance().Savepoint();
181
182 int selected_page = m_notebook->GetSelection();
183 m_panel_list[selected_page]->SaveSettings();
184
185 Model_Setting::instance().ReleaseSavepoint();
186 Model_Infotable::instance().ReleaseSavepoint();
187
188 wxString msg = msg.Format(_("%s page has been saved."), m_notebook->GetPageText(selected_page));
189 wxMessageBox(msg, "MMEX Options");
190 }
191