1 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 /// Name: wxCasPrefs Class
4 /// Purpose: Display user preferences dialog and manage configuration storage system
6 /// Author: ThePolish <thepolish@vipmail.ru>
8 /// Copyright (c) 2004-2011 ThePolish ( thepolish@vipmail.ru )
10 /// Derived from CAS by Pedro de Oliveira <falso@rdk.homeip.net>
12 /// Pixmaps from aMule http://www.amule.org
14 /// This program is free software; you can redistribute it and/or modify
15 /// it under the terms of the GNU General Public License as published by
16 /// the Free Software Foundation; either version 2 of the License, or
17 /// (at your option) any later version.
19 /// This program is distributed in the hope that it will be useful,
20 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
21 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 /// GNU General Public License for more details.
24 /// You should have received a copy of the GNU General Public License
25 /// along with this program; if not, write to the
26 /// Free Software Foundation, Inc.,
27 /// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31 #include <wx/config.h>
32 #include <wx/dirdlg.h>
34 #include "wxcasprefs.h"
36 #include "wxcasframe.h"
39 WxCasPrefs::WxCasPrefs ( wxWindow
* parent
) : wxDialog ( parent
, -1,
44 wxConfigBase
* prefs
= wxConfigBase::Get();
46 // Main vertical Sizer
47 m_mainVBox
= new wxBoxSizer ( wxVERTICAL
);
51 new wxStaticBox ( this, -1, _( "Directory containing amulesig.dat file" ) );
52 m_osPathSBoxSizer
= new wxStaticBoxSizer ( m_osPathSBox
, wxHORIZONTAL
);
54 m_osPathTextCtrl
= new wxTextCtrl ( this, -1, wxEmptyString
);
55 m_osPathBrowseButton
=
56 new wxButton ( this, ID_OSPATH_BROWSE_BUTTON
, wxString ( _( "Browse" ) ) );
60 prefs
->Read ( WxCasCte::AMULESIG_PATH_KEY
, &str
,
61 WxCasCte::DEFAULT_AMULESIG_PATH
);
64 wxInt32 charExtent
, y
;
65 m_osPathTextCtrl
->GetTextExtent ( wxT( "8" ), &charExtent
, &y
);
66 m_osPathTextCtrl
->SetSize ( wxSize ( charExtent
* ( str
.Length () + 1 ), -1 ) );
68 m_osPathTextCtrl
->SetValue ( str
);
71 ( "Enter here the directory where your amulesig.dat file is" ) );
73 m_osPathSBoxSizer
->Add ( m_osPathTextCtrl
, 1, wxALL
| wxALIGN_CENTER
, 5 );
74 m_osPathSBoxSizer
->Add ( m_osPathBrowseButton
, 0, wxALL
| wxALIGN_CENTER
, 5 );
76 m_mainVBox
->Add ( m_osPathSBoxSizer
, 0, wxGROW
| wxALIGN_CENTER
| wxALL
, 10 );
79 m_refreshSBox
= new wxStaticBox ( this, -1, wxEmptyString
);
80 m_refreshSBoxSizer
= new wxStaticBoxSizer ( m_refreshSBox
, wxHORIZONTAL
);
83 m_refreshSpinButton
= new wxSpinCtrl ( this, -1 );
84 m_refreshSpinButton
->SetRange ( WxCasCte::MIN_REFRESH_RATE
,
85 WxCasCte::MAX_REFRESH_RATE
);
86 m_refreshSpinButton
->SetValue ( prefs
->
87 Read ( WxCasCte::REFRESH_RATE_KEY
,
88 WxCasCte::DEFAULT_REFRESH_RATE
) );
90 new wxStaticText ( this, -1, _( "Refresh rate interval in seconds" ), wxDefaultPosition
,
91 wxDefaultSize
, wxALIGN_CENTRE
);
92 m_refreshSBoxSizer
->Add ( m_refreshSpinButton
, 0, wxALL
| wxALIGN_CENTER
, 5 );
93 m_refreshSBoxSizer
->Add ( m_refreshStaticText
, 1, wxALL
| wxALIGN_CENTER
, 5 );
95 m_mainVBox
->Add ( m_refreshSBoxSizer
, 0, wxGROW
| wxALIGN_CENTER
| wxALL
,
98 // Auto generate stat image
99 m_autoStatImgSBox
= new wxStaticBox ( this, -1, wxEmptyString
);
100 m_autoStatImgSBoxSizer
=
101 new wxStaticBoxSizer ( m_autoStatImgSBox
, wxVERTICAL
);
104 new wxCheckBox ( this, ID_AUTOSTATIMG_CHECK
,
106 ( "Generate a stat image at every refresh event" ) );
107 m_autoStatImgSBoxSizer
->Add ( m_autoStatImgCheck
, 0,
108 wxGROW
| wxALIGN_CENTER_VERTICAL
| wxALL
, 5 );
110 m_autoStatImgHBoxSizer
= new wxBoxSizer ( wxHORIZONTAL
);
114 wxT ( "PNG" ), wxT ( "JPG" ), wxT ( "BMP" ) };
117 new wxComboBox ( this, ID_AUTOSTATIMG_COMBO
,
119 Read ( WxCasCte::AUTOSTATIMG_TYPE_KEY
,
120 WxCasCte::DEFAULT_AUTOSTATIMG_TYPE
),
121 wxDefaultPosition
, wxDefaultSize
, 3, strs
,
122 wxCB_DROPDOWN
| wxCB_READONLY
);
124 m_autoStatImgTextCtrl
= new wxTextCtrl ( this, -1, wxEmptyString
);
125 m_autoStatImgTextCtrl
->SetValue ( prefs
->
126 Read ( WxCasCte::AUTOSTATIMG_DIR_KEY
,
127 WxCasCte::DEFAULT_AUTOSTATIMG_PATH
) );
128 m_autoStatImgTextCtrl
->
130 ( "Enter here the directory where you want to generate the statistic image" ) );
132 m_autoStatImgButton
=
133 new wxButton ( this, ID_AUTOSTATIMG_BROWSE_BUTTON
, wxString ( _( "Browse" ) ) );
135 m_autoStatImgHBoxSizer
->Add ( m_autoStatImgCombo
, 0, wxALIGN_CENTER
| wxALL
,
137 m_autoStatImgHBoxSizer
->Add ( m_autoStatImgTextCtrl
, 1,
138 wxALIGN_CENTER
| wxALL
, 5 );
139 m_autoStatImgHBoxSizer
->Add ( m_autoStatImgButton
, 0, wxALIGN_CENTER
| wxALL
,
142 m_autoStatImgSBoxSizer
->Add ( m_autoStatImgHBoxSizer
, 0,
143 wxGROW
| wxALIGN_CENTER_VERTICAL
| wxALL
, 5 );
145 m_mainVBox
->Add ( m_autoStatImgSBoxSizer
, 0, wxGROW
| wxALIGN_CENTER
| wxALL
,
148 // Auto FTP update stat image
149 m_ftpUpdateSBox
= new wxStaticBox ( this, -1, wxEmptyString
);
150 m_ftpUpdateSBoxSizer
=
151 new wxStaticBoxSizer ( m_ftpUpdateSBox
, wxVERTICAL
);
155 new wxCheckBox ( this, ID_FTP_UPDATE_CHECK
,
157 ( "Upload periodicaly your stat image to FTP server" ) );
158 m_ftpUpdateSBoxSizer
->Add ( m_ftpUpdateCheck
, 0,
159 wxGROW
| wxALIGN_CENTER_VERTICAL
| wxALL
, 5 );
162 m_ftpUpdateGridSizer
= new wxGridSizer( 2 );
165 m_ftpUrlStaticText
= new wxStaticText ( this, -1, _( "FTP Url" ) );
166 m_ftpUpdateGridSizer
->Add ( m_ftpUrlStaticText
, 1,
167 wxALIGN_LEFT
| wxALIGN_BOTTOM
| wxALL
, 5 );
169 m_ftpPathStaticText
= new wxStaticText ( this, -1, _( "FTP Path" ) );
170 m_ftpUpdateGridSizer
->Add ( m_ftpPathStaticText
, 1,
171 wxALIGN_LEFT
| wxALIGN_BOTTOM
| wxALL
, 5 );
173 m_ftpUrlTextCtrl
= new wxTextCtrl ( this, -1, wxEmptyString
);
174 m_ftpUrlTextCtrl
->SetValue ( prefs
->
175 Read ( WxCasCte::FTP_URL_KEY
,
176 WxCasCte::DEFAULT_FTP_URL
) );
179 ( "Enter here the URL of your FTP server" ) );
181 m_ftpUpdateGridSizer
->Add ( m_ftpUrlTextCtrl
, 1,
182 wxGROW
| wxALIGN_LEFT
| wxALIGN_TOP
| wxALL
, 5 );
185 m_ftpPathTextCtrl
= new wxTextCtrl ( this, -1, wxEmptyString
);
186 m_ftpPathTextCtrl
->SetValue ( prefs
->
187 Read ( WxCasCte::FTP_PATH_KEY
,
188 WxCasCte::DEFAULT_FTP_PATH
) );
191 ( "Enter here the directory where putting your stat image on FTP server" ) );
193 m_ftpUpdateGridSizer
->Add ( m_ftpPathTextCtrl
, 1,
194 wxGROW
| wxALIGN_LEFT
| wxALIGN_TOP
| wxALL
, 5 );
197 m_ftpUserStaticText
= new wxStaticText ( this, -1, _( "User" ) );
198 m_ftpUpdateGridSizer
->Add ( m_ftpUserStaticText
, 1,
199 wxALIGN_LEFT
| wxALIGN_BOTTOM
| wxALL
, 5 );
201 m_ftpPasswdStaticText
= new wxStaticText ( this, -1, _( "Password" ) );
202 m_ftpUpdateGridSizer
->Add ( m_ftpPasswdStaticText
, 1,
203 wxALIGN_LEFT
| wxALIGN_BOTTOM
| wxALL
, 5 );
206 m_ftpUserTextCtrl
= new wxTextCtrl ( this, -1, wxEmptyString
);
207 m_ftpUserTextCtrl
->SetValue ( prefs
->
208 Read ( WxCasCte::FTP_USER_KEY
,
209 WxCasCte::DEFAULT_FTP_USER
) );
212 ( "Enter here the User name to log into your FTP server" ) );
214 m_ftpUpdateGridSizer
->Add ( m_ftpUserTextCtrl
, 1,
215 wxGROW
| wxALIGN_LEFT
| wxALIGN_TOP
| wxALL
, 5 );
218 m_ftpPasswdTextCtrl
= new wxTextCtrl ( this, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_PASSWORD
);
219 m_ftpPasswdTextCtrl
->SetValue ( prefs
->
220 Read ( WxCasCte::FTP_PASSWD_KEY
,
221 WxCasCte::DEFAULT_FTP_PASSWD
) );
222 m_ftpPasswdTextCtrl
->
224 ( "Enter here the User password to log into your FTP server" ) );
226 m_ftpUpdateGridSizer
->Add ( m_ftpPasswdTextCtrl
, 1,
227 wxGROW
| wxALIGN_LEFT
| wxALIGN_TOP
| wxALL
, 5 );
230 // Add to static sizer
231 m_ftpUpdateSBoxSizer
->Add ( m_ftpUpdateGridSizer
, 1,
232 wxGROW
| wxALIGN_CENTER_VERTICAL
| wxALL
, 5 );
235 m_ftpRateHBoxSizer
= new wxBoxSizer( wxHORIZONTAL
);
236 m_ftpUpdateSpinButton
= new wxSpinCtrl ( this, -1 );
237 m_ftpUpdateSpinButton
->SetRange ( WxCasCte::MIN_FTP_RATE
,
238 WxCasCte::MAX_FTP_RATE
);
239 m_ftpUpdateSpinButton
->SetValue ( prefs
->
240 Read ( WxCasCte::FTP_UPDATE_RATE_KEY
,
241 WxCasCte::DEFAULT_FTP_UPDATE_RATE
) );
242 m_ftpUpdateStaticText
=
243 new wxStaticText ( this, -1, _( "FTP update rate interval in minutes" ), wxDefaultPosition
,
244 wxDefaultSize
, wxALIGN_CENTRE
);
245 m_ftpRateHBoxSizer
->Add ( m_ftpUpdateSpinButton
, 0, wxALL
| wxALIGN_CENTER
, 5 );
246 m_ftpRateHBoxSizer
->Add ( m_ftpUpdateStaticText
, 1, wxALL
| wxALIGN_CENTER
, 5 );
248 m_ftpUpdateSBoxSizer
->Add ( m_ftpRateHBoxSizer
, 0,
249 wxGROW
| wxALIGN_CENTER_VERTICAL
| wxALL
, 5 );
252 m_mainVBox
->Add ( m_ftpUpdateSBoxSizer
, 0, wxGROW
| wxALIGN_CENTER
| wxALL
,
255 // Mask auto stat img disabled controls
256 if (prefs
->Read( WxCasCte::ENABLE_AUTOSTATIMG_KEY
,
257 WxCasCte::DEFAULT_AUTOSTATIMG_ISENABLED
) ) {
258 m_autoStatImgCheck
->SetValue( TRUE
);
260 m_autoStatImgCheck
->SetValue ( FALSE
);
261 EnableAutoStatImgCtrls( FALSE
);
263 m_ftpUpdateCheck
->Enable ( FALSE
);
264 EnableFtpUpdateCtrls( FALSE
);
267 // Mask Ftp update disabled controls
268 if (prefs
->Read( WxCasCte::ENABLE_FTP_UPDATE_KEY
,
269 WxCasCte::DEFAULT_FTP_UPDATE_ISENABLED
) ) {
270 m_ftpUpdateCheck
->SetValue( TRUE
);
272 m_ftpUpdateCheck
->SetValue ( FALSE
);
273 EnableFtpUpdateCtrls( FALSE
);
277 m_staticLine
= new wxStaticLine ( this, -1 );
278 m_mainVBox
->Add ( m_staticLine
, 0, wxGROW
| wxALIGN_CENTER
| wxALL
);
281 m_buttonHBox
= new wxBoxSizer ( wxHORIZONTAL
);
283 new wxButton ( this, ID_VALIDATE_BUTTON
, wxString ( _( "Validate" ) ) );
285 new wxButton ( this, wxID_CANCEL
, wxString ( _( "Cancel" ) ) );
287 m_buttonHBox
->Add ( m_validateButton
, 0, wxALIGN_CENTER
| wxALL
, 5 );
288 m_buttonHBox
->Add ( m_cancelButton
, 0, wxALIGN_CENTER
| wxALL
, 5 );
290 m_mainVBox
->Add ( m_buttonHBox
, 0, wxALIGN_CENTER
| wxALL
, 10 );
293 SetAutoLayout ( TRUE
);
294 SetSizerAndFit ( m_mainVBox
);
296 m_validateButton
->SetFocus ();
297 m_validateButton
->SetDefault ();
301 WxCasPrefs::~WxCasPrefs ()
305 BEGIN_EVENT_TABLE ( WxCasPrefs
, wxDialog
)
306 EVT_BUTTON ( ID_OSPATH_BROWSE_BUTTON
, WxCasPrefs::OnOSPathBrowseButton
)
307 EVT_BUTTON ( ID_AUTOSTATIMG_BROWSE_BUTTON
, WxCasPrefs::OnAutoStatImgBrowseButton
)
308 EVT_BUTTON ( ID_VALIDATE_BUTTON
, WxCasPrefs::OnValidateButton
)
309 EVT_CHECKBOX ( ID_AUTOSTATIMG_CHECK
, WxCasPrefs::OnAutoStatImgCheck
)
310 EVT_CHECKBOX ( ID_FTP_UPDATE_CHECK
, WxCasPrefs::OnFtpUpdateCheck
)
313 // Browse for OS Path
314 void WxCasPrefs::OnOSPathBrowseButton ( wxCommandEvent
& WXUNUSED( event
) )
316 const wxString
&dir
= wxDirSelector(_
317 ("Folder containing your signature file"),
318 WxCasCte::DEFAULT_AMULESIG_PATH
,
320 wxDefaultPosition
, this);
321 if ( !dir
.empty () ) {
322 m_osPathTextCtrl
->SetValue ( dir
);
326 // Browse for stat image Path
328 WxCasPrefs::OnAutoStatImgBrowseButton ( wxCommandEvent
& WXUNUSED( event
) )
330 const wxString
& dir
= wxDirSelector(
331 _("Folder where generating the statistic image"),
332 WxCasCte::DEFAULT_AUTOSTATIMG_PATH
,
334 wxDefaultPosition
, this);
336 if ( !dir
.empty () ) {
337 m_autoStatImgTextCtrl
->SetValue ( dir
);
341 // Auto Generate Stat Image Check Button
343 WxCasPrefs::OnAutoStatImgCheck ( wxCommandEvent
& WXUNUSED( event
) )
345 if ( m_autoStatImgCheck
->GetValue () ) {
346 EnableAutoStatImgCtrls( TRUE
);
348 m_ftpUpdateCheck
->Enable ( TRUE
);
349 if ( m_ftpUpdateCheck
->GetValue () ) {
350 EnableFtpUpdateCtrls( TRUE
);
353 EnableAutoStatImgCtrls( FALSE
);
355 m_ftpUpdateCheck
->Enable ( FALSE
);
356 EnableFtpUpdateCtrls( FALSE
);
360 // Ftp update Check Button
362 WxCasPrefs::OnFtpUpdateCheck ( wxCommandEvent
& WXUNUSED( event
) )
364 if ( m_ftpUpdateCheck
->GetValue () ) {
365 EnableFtpUpdateCtrls( TRUE
);
367 EnableFtpUpdateCtrls( FALSE
);
372 WxCasPrefs::OnValidateButton ( wxCommandEvent
& WXUNUSED( event
) )
375 wxConfigBase
* prefs
= wxConfigBase::Get();
377 // Write amulesig dir
378 if ( prefs
->Read ( WxCasCte::AMULESIG_PATH_KEY
,
379 WxCasCte::DEFAULT_AMULESIG_PATH
) !=
380 m_osPathTextCtrl
->GetValue () ) {
381 // Reload amulesig.dat
382 wxFileName
amulesig( m_osPathTextCtrl
->GetValue (),
383 WxCasCte::AMULESIG_FILENAME
);
384 ( ( WxCasFrame
* ) GetParent() ) ->SetAmuleSigFile( amulesig
);
386 prefs
->Write ( WxCasCte::AMULESIG_PATH_KEY
,
387 m_osPathTextCtrl
->GetValue () );
390 // Restart timer if refresh interval has changed
391 if ( prefs
->Read ( WxCasCte::REFRESH_RATE_KEY
, WxCasCte::DEFAULT_REFRESH_RATE
) !=
392 m_refreshSpinButton
->GetValue () ) {
393 ( ( WxCasFrame
* ) GetParent() ) ->ChangeRefreshPeriod( 1000 * m_refreshSpinButton
->GetValue () );
395 // Write refresh interval
396 prefs
->Write ( WxCasCte::REFRESH_RATE_KEY
,
397 m_refreshSpinButton
->GetValue () );
400 // Write auto stat img state
401 prefs
->Write ( WxCasCte::ENABLE_AUTOSTATIMG_KEY
,
402 m_autoStatImgCheck
->GetValue () );
404 // If auto stat img is enabled
405 if ( m_autoStatImgCheck
->GetValue () ) {
406 prefs
->Write ( WxCasCte::AUTOSTATIMG_DIR_KEY
,
407 m_autoStatImgTextCtrl
->GetValue () );
409 prefs
->Write ( WxCasCte::AUTOSTATIMG_TYPE_KEY
,
410 m_autoStatImgCombo
->GetValue () );
412 // Write Ftp update state
413 prefs
->Write ( WxCasCte::ENABLE_FTP_UPDATE_KEY
,
414 m_ftpUpdateCheck
->GetValue () );
416 // If Ftp update is enabled
417 if ( m_ftpUpdateCheck
->GetValue () ) {
418 // Restart timer if update interval has changed
419 if ( prefs
->Read ( WxCasCte::FTP_UPDATE_RATE_KEY
, WxCasCte::DEFAULT_FTP_UPDATE_RATE
) !=
420 m_ftpUpdateSpinButton
->GetValue () ) {
421 ( ( WxCasFrame
* ) GetParent() ) ->ChangeFtpUpdatePeriod( 60000 * m_refreshSpinButton
->GetValue () );
422 prefs
->Write ( WxCasCte::FTP_UPDATE_RATE_KEY
,
423 m_ftpUpdateSpinButton
->GetValue () );
425 // Write Ftp parameters
426 prefs
->Write ( WxCasCte::FTP_URL_KEY
,
427 m_ftpUrlTextCtrl
->GetValue () );
429 prefs
->Write ( WxCasCte::FTP_PATH_KEY
,
430 m_ftpPathTextCtrl
->GetValue () );
432 prefs
->Write ( WxCasCte::FTP_USER_KEY
,
433 m_ftpUserTextCtrl
->GetValue () );
435 prefs
->Write ( WxCasCte::FTP_PASSWD_KEY
,
436 m_ftpPasswdTextCtrl
->GetValue () );
440 // Force config writing
444 this->EndModal ( this->GetReturnCode () );
447 // Enable/Disable auto img ctrls
449 WxCasPrefs::EnableAutoStatImgCtrls( bool state
)
451 m_autoStatImgTextCtrl
->Enable ( state
);
452 m_autoStatImgButton
->Enable ( state
);
453 m_autoStatImgCombo
->Enable ( state
);
456 // Enable/Disable Ftp update ctrls
458 WxCasPrefs::EnableFtpUpdateCtrls( bool state
)
460 m_ftpUpdateSpinButton
->Enable ( state
);
461 m_ftpUpdateStaticText
->Enable ( state
);
462 m_ftpUrlTextCtrl
->Enable ( state
);
463 m_ftpUrlStaticText
->Enable ( state
);
464 m_ftpPathTextCtrl
->Enable ( state
);
465 m_ftpPathStaticText
->Enable ( state
);
466 m_ftpUserTextCtrl
->Enable ( state
);
467 m_ftpUserStaticText
->Enable ( state
);
468 m_ftpPasswdTextCtrl
->Enable ( state
);
469 m_ftpPasswdStaticText
->Enable ( state
);
471 // File_checked_for_headers