Format string mayhem
[amule.git] / src / PrefsUnifiedDlg.cpp
blobce01cb423a538cc7f349b569634f36249fbac6a6
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Original author: Emilio Sandoz
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "PrefsUnifiedDlg.h"
29 #include <common/Constants.h>
31 #include <wx/colordlg.h>
32 #include <wx/tooltip.h>
34 #include "amule.h" // Needed for theApp
35 #include "amuleDlg.h"
36 #include "MuleColour.h"
37 #include "EditServerListDlg.h"
38 #include "SharedFileList.h" // Needed for CSharedFileList
39 #include "StatisticsDlg.h" // Needed for graph parameters, colors
40 #include "IPFilter.h" // Needed for CIPFilter
41 #include "SearchList.h"
42 #include "ClientList.h"
43 #include "DirectoryTreeCtrl.h" // Needed for CDirectoryTreeCtrl
44 #include "Preferences.h"
45 #include "muuli_wdr.h"
46 #include "Logger.h"
47 #include <common/Format.h> // Needed for CFormat
48 #include "TransferWnd.h" // Needed for CTransferWnd::UpdateCatTabTitles()
49 #include "KadDlg.h" // Needed for CKadDlg
50 #include "OScopeCtrl.h" // Needed for OScopeCtrl
51 #include "ServerList.h"
52 #include "UserEvents.h"
54 BEGIN_EVENT_TABLE(PrefsUnifiedDlg,wxDialog)
55 // Events
56 #define USEREVENTS_EVENT(ID, NAME, VARS) \
57 EVT_CHECKBOX(USEREVENTS_FIRST_ID + CUserEvents::ID * USEREVENTS_IDS_PER_EVENT + 1, PrefsUnifiedDlg::OnCheckBoxChange) \
58 EVT_CHECKBOX(USEREVENTS_FIRST_ID + CUserEvents::ID * USEREVENTS_IDS_PER_EVENT + 3, PrefsUnifiedDlg::OnCheckBoxChange)
59 USEREVENTS_EVENTLIST()
60 #undef USEREVENTS_EVENT
62 // Proxy
63 EVT_CHECKBOX(ID_PROXY_ENABLE_PROXY, PrefsUnifiedDlg::OnCheckBoxChange)
64 EVT_CHECKBOX(ID_PROXY_ENABLE_PASSWORD, PrefsUnifiedDlg::OnCheckBoxChange)
65 // EVT_CHECKBOX(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, PrefsUnifiedDlg::OnCheckBoxChange)
67 // Connection
68 EVT_SPINCTRL(IDC_PORT, PrefsUnifiedDlg::OnTCPClientPortChange)
70 // The rest. Organize it!
71 EVT_CHECKBOX(IDC_UDPENABLE, PrefsUnifiedDlg::OnCheckBoxChange)
72 EVT_CHECKBOX(IDC_CHECKDISKSPACE, PrefsUnifiedDlg::OnCheckBoxChange)
73 EVT_CHECKBOX(IDC_ONLINESIG, PrefsUnifiedDlg::OnCheckBoxChange)
74 EVT_CHECKBOX(IDC_REMOVEDEAD, PrefsUnifiedDlg::OnCheckBoxChange)
75 EVT_CHECKBOX(IDC_AUTOSERVER, PrefsUnifiedDlg::OnCheckBoxChange)
76 EVT_CHECKBOX(IDC_AUTOIPFILTER, PrefsUnifiedDlg::OnCheckBoxChange)
77 EVT_CHECKBOX(IDC_MSGFILTER, PrefsUnifiedDlg::OnCheckBoxChange)
78 EVT_CHECKBOX(IDC_MSGFILTER_ALL, PrefsUnifiedDlg::OnCheckBoxChange)
79 EVT_CHECKBOX(IDC_MSGFILTER_WORD, PrefsUnifiedDlg::OnCheckBoxChange)
80 EVT_CHECKBOX(IDC_FILTERCOMMENTS, PrefsUnifiedDlg::OnCheckBoxChange)
81 EVT_CHECKBOX(IDC_STARTNEXTFILE, PrefsUnifiedDlg::OnCheckBoxChange)
82 EVT_CHECKBOX(IDC_ENABLETRAYICON, PrefsUnifiedDlg::OnCheckBoxChange)
83 EVT_CHECKBOX(IDC_VERTTOOLBAR, PrefsUnifiedDlg::OnCheckBoxChange)
84 EVT_CHECKBOX(IDC_SUPPORT_PO, PrefsUnifiedDlg::OnCheckBoxChange)
85 EVT_CHECKBOX(IDC_ENABLE_PO_OUTGOING, PrefsUnifiedDlg::OnCheckBoxChange)
86 EVT_CHECKBOX(IDC_ENFORCE_PO_INCOMING, PrefsUnifiedDlg::OnCheckBoxChange)
87 EVT_CHECKBOX(IDC_SHOWRATEONTITLE, PrefsUnifiedDlg::OnCheckBoxChange)
88 EVT_CHECKBOX(IDC_NETWORKED2K, PrefsUnifiedDlg::OnCheckBoxChange)
90 EVT_BUTTON(ID_PREFS_OK_TOP, PrefsUnifiedDlg::OnOk)
91 EVT_BUTTON(ID_PREFS_CANCEL_TOP, PrefsUnifiedDlg::OnCancel)
93 // Browse buttons
94 // EVT_BUTTON(IDC_SELSKIN, PrefsUnifiedDlg::OnButtonDir)
95 EVT_BUTTON(IDC_BROWSEV, PrefsUnifiedDlg::OnButtonBrowseApplication)
96 EVT_BUTTON(IDC_SELTEMPDIR, PrefsUnifiedDlg::OnButtonDir)
97 EVT_BUTTON(IDC_SELINCDIR, PrefsUnifiedDlg::OnButtonDir)
98 EVT_BUTTON(IDC_SELOSDIR, PrefsUnifiedDlg::OnButtonDir)
99 EVT_BUTTON(IDC_SELBROWSER, PrefsUnifiedDlg::OnButtonBrowseApplication)
101 EVT_SPINCTRL(IDC_TOOLTIPDELAY, PrefsUnifiedDlg::OnToolTipDelayChange)
103 EVT_BUTTON(IDC_EDITADR, PrefsUnifiedDlg::OnButtonEditAddr)
104 EVT_BUTTON(IDC_IPFRELOAD, PrefsUnifiedDlg::OnButtonIPFilterReload)
105 EVT_BUTTON(IDC_COLOR_BUTTON, PrefsUnifiedDlg::OnButtonColorChange)
106 EVT_BUTTON(IDC_IPFILTERUPDATE, PrefsUnifiedDlg::OnButtonIPFilterUpdate)
107 EVT_CHOICE(IDC_COLORSELECTOR, PrefsUnifiedDlg::OnColorCategorySelected)
108 EVT_LIST_ITEM_SELECTED(ID_PREFSLISTCTRL,PrefsUnifiedDlg::OnPrefsPageChange)
110 EVT_INIT_DIALOG(PrefsUnifiedDlg::OnInitDialog)
112 EVT_COMMAND_SCROLL(IDC_SLIDER, PrefsUnifiedDlg::OnScrollBarChange)
113 EVT_COMMAND_SCROLL(IDC_SLIDER3, PrefsUnifiedDlg::OnScrollBarChange)
114 EVT_COMMAND_SCROLL(IDC_SLIDER4, PrefsUnifiedDlg::OnScrollBarChange)
115 EVT_COMMAND_SCROLL(IDC_SLIDER2, PrefsUnifiedDlg::OnScrollBarChange)
116 EVT_COMMAND_SCROLL(IDC_FILEBUFFERSIZE, PrefsUnifiedDlg::OnScrollBarChange)
117 EVT_COMMAND_SCROLL(IDC_QUEUESIZE, PrefsUnifiedDlg::OnScrollBarChange)
118 EVT_COMMAND_SCROLL(IDC_SERVERKEEPALIVE, PrefsUnifiedDlg::OnScrollBarChange)
120 EVT_SPINCTRL(IDC_MAXUP, PrefsUnifiedDlg::OnRateLimitChanged)
122 EVT_LIST_ITEM_SELECTED(IDC_EVENTLIST, PrefsUnifiedDlg::OnUserEventSelected)
124 EVT_CHOICE(IDC_LANGUAGE, PrefsUnifiedDlg::OnLanguageChoice)
126 EVT_CLOSE(PrefsUnifiedDlg::OnClose)
128 END_EVENT_TABLE()
132 * Creates an command-event for the given checkbox.
134 * This can be used enforce logical constraints by passing by
135 * sending a check-box event for each checkbox, when transfering
136 * to the UI. However, it should also be used for checkboxes that
137 * have no side-effects other than enabling/disabling other
138 * widgets in the preferences dialogs.
140 void SendCheckBoxEvent(wxWindow* parent, int id)
142 wxCheckBox* widget = CastByID(id, parent, wxCheckBox);
143 wxCHECK_RET(widget, wxT("Invalid widget in CreateEvent"));
145 wxCommandEvent evt(wxEVT_COMMAND_CHECKBOX_CLICKED, id);
146 evt.SetInt(widget->IsChecked() ? 1 : 0);
148 parent->GetEventHandler()->ProcessEvent(evt);
154 * This struct provides a general way to represent config-tabs.
156 struct PrefsPage
158 //! The title of the page, used on the listctrl.
159 wxString m_title;
160 //! Function pointer to the wxDesigner function creating the dialog.
161 wxSizer* (*m_function)(wxWindow*, bool, bool );
162 //! The index of the image used on the list.
163 int m_imageidx;
167 PrefsPage pages[] =
169 { wxTRANSLATE("General"), PreferencesGeneralTab, 13 },
170 { wxTRANSLATE("Connection"), PreferencesConnectionTab, 14 },
171 { wxTRANSLATE("Directories"), PreferencesDirectoriesTab, 17 },
172 { wxTRANSLATE("Servers"), PreferencesServerTab, 15 },
173 { wxTRANSLATE("Files"), PreferencesFilesTab, 16 },
174 { wxTRANSLATE("Security"), PreferencesSecurityTab, 22 },
175 { wxTRANSLATE("Interface"), PreferencesGuiTweaksTab, 19 },
176 { wxTRANSLATE("Statistics"), PreferencesStatisticsTab, 10 },
177 { wxTRANSLATE("Proxy"), PreferencesProxyTab, 24 },
178 { wxTRANSLATE("Filters"), PreferencesFilteringTab, 23 },
179 { wxTRANSLATE("Remote Controls"), PreferencesRemoteControlsTab, 11 },
180 { wxTRANSLATE("Online Signature"), PreferencesOnlineSigTab, 21 },
181 { wxTRANSLATE("Advanced"), PreferencesaMuleTweaksTab, 12 },
182 { wxTRANSLATE("Events"), PreferencesEventsTab, 5 }
183 #ifdef __DEBUG__
184 ,{ wxTRANSLATE("Debugging"), PreferencesDebug, 25 }
185 #endif
189 PrefsUnifiedDlg::PrefsUnifiedDlg(wxWindow *parent)
191 wxDialog(parent, -1, _("Preferences"),
192 wxDefaultPosition, wxDefaultSize,
193 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
195 preferencesDlgTop(this, false);
197 m_PrefsIcons = CastChild(ID_PREFSLISTCTRL, wxListCtrl);
198 wxImageList *icon_list = new wxImageList(16, 16);
199 m_PrefsIcons->AssignImageList(icon_list, wxIMAGE_LIST_SMALL);
201 // Add the single column used
202 m_PrefsIcons->InsertColumn(
203 0, wxEmptyString, wxLIST_FORMAT_LEFT,
204 m_PrefsIcons->GetSize().GetWidth()-5);
206 // Temp variables for finding the smallest height and width needed
207 int width = 0;
208 int height = 0;
210 // Add each page to the page-list
211 for (unsigned int i = 0; i < itemsof(pages); ++i) {
212 // Add the icon and label associated with the page
213 icon_list->Add(amuleSpecial(pages[i].m_imageidx));
214 m_PrefsIcons->InsertItem(i, wxGetTranslation(pages[i].m_title), i);
217 // Set list-width so that there aren't any scrollers
218 m_PrefsIcons->SetColumnWidth(0, wxLIST_AUTOSIZE);
219 m_PrefsIcons->SetMinSize(wxSize(m_PrefsIcons->GetColumnWidth(0) + 10, -1));
220 m_PrefsIcons->SetMaxSize(wxSize(m_PrefsIcons->GetColumnWidth(0) + 10, -1));
222 // Now add the pages and calculate the minimum size
223 wxPanel * DefaultWidget = NULL;
224 for (unsigned int i = 0; i < itemsof(pages); ++i) {
225 // Create a container widget and the contents of the page
226 wxPanel * Widget = new wxPanel(this, -1);
227 // Widget is stored as user data in the list control
228 m_PrefsIcons->SetItemPtrData(i, (wxUIntPtr) Widget);
229 pages[i].m_function(Widget, true, true);
230 if (i == 0) {
231 DefaultWidget = Widget;
234 // Add it to the sizer
235 prefs_sizer->Add(Widget, 0, wxGROW|wxEXPAND);
237 if (pages[i].m_function == PreferencesGeneralTab) {
238 // This must be done now or pages won't Fit();
239 #ifdef __WXMSW__
240 CastChild(IDC_BROWSERTABS, wxCheckBox)->Enable(false);
241 #endif /* __WXMSW__ */
242 CastChild(IDC_PREVIEW_NOTE, wxStaticText)->SetLabel(_("The following variables will be substituted:\n %PARTFILE - full path to the file\n %PARTNAME - file name only"));
243 } else if (pages[i].m_function == PreferencesEventsTab) {
245 #define USEREVENTS_REPLACE_VAR(VAR, DESC, CODE) + wxString(wxT("\n %") VAR wxT(" - ")) + wxGetTranslation(DESC)
246 #define USEREVENTS_EVENT(ID, NAME, VARS) case CUserEvents::ID: CreateEventPanels(idx, wxEmptyString VARS, Widget); break;
248 wxListCtrl *list = CastChild(IDC_EVENTLIST, wxListCtrl);
249 list->InsertColumn(0, wxEmptyString);
250 for (unsigned int idx = 0; idx < CUserEvents::GetCount(); ++idx) {
251 long lidx = list->InsertItem(idx,
252 wxGetTranslation(CUserEvents::GetDisplayName(
253 static_cast<enum CUserEvents::EventType>(idx))));
254 if (lidx != -1) {
255 list->SetItemData(lidx,
256 USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT);
257 switch (idx) {
258 USEREVENTS_EVENTLIST()
262 list->SetColumnWidth(0, wxLIST_AUTOSIZE);
264 else if (pages[i].m_function == PreferencesServerTab) {
265 m_IndexServerTab = i;
266 m_ServerWidget = Widget;
268 else if (pages[i].m_function == PreferencesaMuleTweaksTab) {
269 wxStaticText *txt = CastChild(IDC_AMULE_TWEAKS_WARNING, wxStaticText);
270 // Do not wrap this line, Windows _() can't handle wrapped strings
271 txt->SetLabel(_("Do not change these setting unless you know\nwhat you are doing, otherwise you can easily\nmake things worse for yourself.\n\naMule will run fine without adjusting any of\nthese settings."));
273 #ifdef __DEBUG__
274 else if (pages[i].m_function == PreferencesDebug) {
275 int count = theLogger.GetDebugCategoryCount();
276 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
278 for ( int j = 0; j < count; j++ ) {
279 list->Append( theLogger.GetDebugCategory( j ).GetName() );
282 #endif
284 // Align and resize the page
285 Fit();
286 Layout();
288 // Find the greatest sizes
289 wxSize size = prefs_sizer->GetSize();
290 if (size.GetWidth() > width) {
291 width = size.GetWidth();
294 if (size.GetHeight() > height) {
295 height = size.GetHeight();
298 // Hide it for now
299 prefs_sizer->Detach(Widget);
300 Widget->Show(false);
303 // Default to the General tab
304 m_CurrentPanel = DefaultWidget;
305 prefs_sizer->Add(DefaultWidget, 0, wxGROW|wxEXPAND);
306 m_CurrentPanel->Show( true );
308 // Select the first item
309 m_PrefsIcons->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
311 // We now have the needed minimum height and width
312 prefs_sizer->SetMinSize(width, height);
314 // Don't show server prefs if ED2K is disabled
315 m_ServerTabVisible = true;
316 EnableServerTab(thePrefs::GetNetworkED2K());
318 // Store some often used pointers
319 m_ShareSelector = CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl);
320 m_buttonColor = CastChild(IDC_COLOR_BUTTON, wxButton);
321 m_choiceColor = CastChild(IDC_COLORSELECTOR, wxChoice);
323 // Connect the Cfgs with their widgets
324 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
325 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
326 // Checking for failures
327 if ( !it->second->ConnectToWidget(it->first, this) ) {
328 AddLogLineNS(CFormat(_("Failed to connect Cfg to widget with the ID %d and key %s"))
329 % it->first % it->second->GetKey());
332 Fit();
334 // It must not be resized to something smaller than what it currently is
335 wxSize size = GetClientSize();
336 SetSizeHints(size.GetWidth(), size.GetHeight());
338 #ifdef __WXMSW__
339 FindWindow(IDC_VERTTOOLBAR)->Enable(false);
340 #endif
342 // Position the dialog.
343 Center();
347 void PrefsUnifiedDlg::EnableServerTab(bool enable)
349 if (enable && !m_ServerTabVisible) {
350 // turn server widget on
351 m_PrefsIcons->InsertItem(m_IndexServerTab, wxGetTranslation(pages[m_IndexServerTab].m_title), m_IndexServerTab);
352 m_PrefsIcons->SetItemPtrData(m_IndexServerTab, (wxUIntPtr) m_ServerWidget);
353 m_ServerTabVisible = true;
354 } else if (!enable && m_ServerTabVisible) {
355 // turn server widget off
356 m_PrefsIcons->DeleteItem(m_IndexServerTab);
357 m_ServerTabVisible = false;
362 Cfg_Base* PrefsUnifiedDlg::GetCfg(int id)
364 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.find( id );
366 if ( it != thePrefs::s_CfgList.end() ) {
367 return it->second;
370 return NULL;
374 bool PrefsUnifiedDlg::TransferToWindow()
376 // Connect the Cfgs with their widgets
377 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
378 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
379 // Checking for failures
380 if ( !it->second->TransferToWindow() ) {
381 AddLogLineNS(CFormat(_("Failed to transfer data from Cfg to Widget with the ID %d and key %s"))
382 % it->first % it->second->GetKey());
386 m_ShareSelector->SetSharedDirectories(&theApp->glob_prefs->shareddir_list);
388 for ( int i = 0; i < cntStatColors; i++ ) {
389 thePrefs::s_colors[i] = CMuleColour(CStatisticsDlg::acrStat[i]).GetULong();
390 thePrefs::s_colors_ref[i] = CMuleColour(CStatisticsDlg::acrStat[i]).GetULong();
393 // Connection tab
394 wxSpinEvent e;
395 OnTCPClientPortChange(e);
397 // Proxy tab initialization
398 if (!CastChild(ID_PROXY_ENABLE_PROXY, wxCheckBox)->IsChecked()) {
399 FindWindow(ID_PROXY_TYPE)->Enable(false);
400 FindWindow(ID_PROXY_NAME)->Enable(false);
401 FindWindow(ID_PROXY_PORT)->Enable(false);
403 if (!CastChild(ID_PROXY_ENABLE_PASSWORD, wxCheckBox)->IsChecked()) {
404 FindWindow(ID_PROXY_USER)->Enable(false);
405 FindWindow(ID_PROXY_PASSWORD)->Enable(false);
407 // This option from the proxy tab is currently unused
408 FindWindow(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY)->Enable(false);
410 // Enable/Disable some controls
411 FindWindow( IDC_MINDISKSPACE )->Enable( thePrefs::IsCheckDiskspaceEnabled() );
412 FindWindow( IDC_OSDIR )->Enable( thePrefs::IsOnlineSignatureEnabled() );
413 FindWindow( IDC_OSUPDATE )->Enable( thePrefs::IsOnlineSignatureEnabled() );
414 FindWindow( IDC_UDPPORT )->Enable( thePrefs::s_UDPEnable );
415 FindWindow( IDC_SERVERRETRIES )->Enable( thePrefs::DeadServer() );
416 FindWindow( IDC_STARTNEXTFILE_SAME )->Enable(thePrefs::StartNextFile());
418 #ifdef __WXMAC__
419 FindWindow(IDC_ENABLETRAYICON)->Enable(false);
420 FindWindow(IDC_MINTRAY)->Enable(false);
421 #else
422 FindWindow(IDC_MINTRAY)->Enable(thePrefs::UseTrayIcon());
423 #endif
425 if (!CastChild(IDC_MSGFILTER, wxCheckBox)->IsChecked()) {
426 FindWindow(IDC_MSGFILTER_ALL)->Enable(false);
427 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(false);
428 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(false);
429 FindWindow(IDC_MSGFILTER_WORD)->Enable(false);
430 FindWindow(IDC_MSGWORD)->Enable(false);
431 } else if (CastChild(IDC_MSGFILTER_ALL, wxCheckBox)->IsChecked()) {
432 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(false);
433 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(false);
434 FindWindow(IDC_MSGFILTER_WORD)->Enable(false);
435 FindWindow(IDC_MSGWORD)->Enable(false);
438 FindWindow(IDC_MSGWORD)->Enable(CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
439 FindWindow(IDC_COMMENTWORD)->Enable(CastChild(IDC_FILTERCOMMENTS, wxCheckBox)->IsChecked());
441 #ifdef CLIENT_GUI
442 // Disable dirpickers unless it's a localhost connection
443 if (!theApp->m_connect->IsConnectedToLocalHost()) {
444 FindWindow(IDC_SELINCDIR)->Enable(false);
445 FindWindow(IDC_SELTEMPDIR)->Enable(false);
447 #endif
449 // Protocol obfuscation
450 ::SendCheckBoxEvent(this, IDC_SUPPORT_PO);
451 ::SendCheckBoxEvent(this, IDC_ENABLE_PO_OUTGOING);
452 ::SendCheckBoxEvent(this, IDC_ENFORCE_PO_INCOMING);
454 // Show rates on title
455 FindWindow(IDC_RATESBEFORETITLE)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
456 FindWindow(IDC_RATESAFTERTITLE)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
457 CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->SetValue(thePrefs::GetShowRatesOnTitle() != 0);
458 CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->SetValue(thePrefs::GetShowRatesOnTitle() == 2);
459 CastChild(IDC_RATESAFTERTITLE, wxRadioButton)->SetValue(thePrefs::GetShowRatesOnTitle() != 2);
461 // UPNP
462 #ifndef ENABLE_UPNP
463 FindWindow(IDC_UPNP_ENABLED)->Enable(false);
464 FindWindow(IDC_UPNPTCPPORT)->Enable(false);
465 thePrefs::SetUPnPEnabled(false);
466 // TODO: grey out "UPnP TCP Port", "Webserver UPnP TCP Port"
467 FindWindow(IDC_UPNP_WEBSERVER_ENABLED)->Enable(false);
468 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(false);
469 thePrefs::SetUPnPWebServerEnabled(false);
470 FindWindow(IDC_UPNP_EC_ENABLED)->Enable(false);
471 thePrefs::SetUPnPECEnabled(false);
472 #endif
474 #ifdef __DEBUG__
475 // Set debugging toggles
476 int count = theLogger.GetDebugCategoryCount();
477 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
479 for ( int i = 0; i < count; i++ ) {
480 list->Check( i, theLogger.GetDebugCategory( i ).IsEnabled() );
482 #endif
484 return true;
488 bool PrefsUnifiedDlg::TransferFromWindow()
490 // Connect the Cfgs with their widgets
491 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
492 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
493 // Checking for failures
494 if ( !it->second->TransferFromWindow() ) {
495 AddLogLineNS(CFormat(_("Failed to transfer data from Widget to Cfg with the ID %d and key %s"))
496 % it->first % it->second->GetKey());
500 theApp->glob_prefs->shareddir_list.clear();
501 m_ShareSelector->GetSharedDirectories(&theApp->glob_prefs->shareddir_list);
503 for ( int i = 0; i < cntStatColors; i++ ) {
504 if ( thePrefs::s_colors[i] != thePrefs::s_colors_ref[i] ) {
505 CStatisticsDlg::acrStat[i] = thePrefs::s_colors[i];
506 theApp->amuledlg->m_statisticswnd->ApplyStatsColor(i);
509 theApp->amuledlg->m_kademliawnd->SetGraphColors();
512 #ifdef __DEBUG__
513 // Get debugging toggles
514 int count = theLogger.GetDebugCategoryCount();
515 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
517 for ( int i = 0; i < count; i++ ) {
518 theLogger.SetEnabled( theLogger.GetDebugCategory( i ).GetType(), list->IsChecked( i ) );
520 #endif
522 thePrefs::SetShowRatesOnTitle(CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->GetValue() ? (CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->GetValue() ? 2 : 1) : 0);
524 #ifdef CLIENT_GUI
525 // Send preferences to core.
526 theApp->glob_prefs->SendToRemote();
527 #endif
529 return true;
533 bool PrefsUnifiedDlg::CfgChanged(int ID)
535 Cfg_Base* cfg = GetCfg(ID);
537 if ( cfg ) {
538 return cfg->HasChanged();
541 return false;
545 void PrefsUnifiedDlg::OnOk(wxCommandEvent& WXUNUSED(event))
547 TransferFromWindow();
549 bool restart_needed = false;
550 wxString restart_needed_msg = _("aMule must be restarted to enable these changes:\n\n");
552 // do sanity checking, special processing, and user notifications here
553 thePrefs::CheckUlDlRatio();
555 if (CfgChanged(IDC_PORT)) {
556 restart_needed = true;
557 restart_needed_msg += _("- TCP port changed.\n");
560 if (CfgChanged(IDC_UDPPORT)) {
561 restart_needed = true;
562 restart_needed_msg += _("- UDP port changed.\n");
565 // Force port checking
566 thePrefs::SetPort(thePrefs::GetPort());
568 if ((CPath::GetFileSize(theApp->ConfigDir + wxT("addresses.dat")) == 0) &&
569 CastChild(IDC_AUTOSERVER, wxCheckBox)->IsChecked() ) {
570 thePrefs::UnsetAutoServerStart();
571 wxMessageBox(_("Your Auto-update server list is empty.\n'Auto-update server list at startup' will be disabled."),
572 _("Message"), wxOK | wxICON_INFORMATION, this);
575 if (thePrefs::AcceptExternalConnections() && thePrefs::ECPassword().IsEmpty()) {
576 thePrefs::EnableExternalConnections( false );
578 wxMessageBox( _("You have enabled external connections but have not specified a password.\nExternal connections cannot be enabled unless a valid password is specified."));
581 // save the preferences on ok
582 theApp->glob_prefs->Save();
584 if (CfgChanged(IDC_FED2KLH) && theApp->amuledlg->GetActiveDialog() != CamuleDlg::DT_SEARCH_WND) {
585 theApp->amuledlg->ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
588 if (CfgChanged(IDC_LANGUAGE)) {
589 restart_needed = true;
590 restart_needed_msg += _("- Language changed.\n");
593 if (CfgChanged(IDC_TEMPFILES)) {
594 restart_needed = true;
595 restart_needed_msg += _("- Temp folder changed.\n");
598 if (CfgChanged(IDC_NETWORKED2K) && thePrefs::GetNetworkED2K()) {
599 restart_needed = true;
600 restart_needed_msg += _("- ED2K network enabled.\n");
603 if (CfgChanged(IDC_INCFILES) || CfgChanged(IDC_TEMPFILES) || m_ShareSelector->HasChanged ) {
604 theApp->sharedfiles->Reload();
607 if (CfgChanged(IDC_OSDIR) || CfgChanged(IDC_ONLINESIG)) {
608 wxTextCtrl* widget = CastChild( IDC_OSDIR, wxTextCtrl );
610 // Build the filenames for the two OS files
611 theApp->SetOSFiles( widget->GetValue() );
614 if (CfgChanged(IDC_IPFCLIENTS) && thePrefs::IsFilteringClients()) {
615 theApp->clientlist->FilterQueues();
618 if (CfgChanged(IDC_IPFSERVERS) && thePrefs::IsFilteringServers()) {
619 theApp->serverlist->FilterServers();
622 if (CfgChanged(ID_IPFILTERLEVEL)) {
623 theApp->ipfilter->Reload();
626 if (thePrefs::GetShowRatesOnTitle()) {
627 // This avoids a 5 seconds delay to show the title
628 theApp->amuledlg->ShowTransferRate();
629 } else {
630 // This resets the title
631 theApp->amuledlg->SetTitle(theApp->m_FrameTitle);
634 if (CfgChanged(IDC_EXTCATINFO)) {
635 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
638 // Changes related to the statistics-dlg
639 if (CfgChanged(IDC_SLIDER)) {
640 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
641 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
644 if ( CfgChanged(IDC_SLIDER3) ) {
645 theApp->amuledlg->m_statisticswnd->ResetAveragingTime();
648 if (CfgChanged(IDC_DOWNLOAD_CAP)) {
649 theApp->amuledlg->m_statisticswnd->SetARange( true, thePrefs::GetMaxGraphDownloadRate() );
652 if (CfgChanged(IDC_UPLOAD_CAP)) {
653 theApp->amuledlg->m_statisticswnd->SetARange( false, thePrefs::GetMaxGraphUploadRate() );
656 if (CfgChanged(IDC_SKIN)) {
657 theApp->amuledlg->Create_Toolbar(thePrefs::VerticalToolbar());
660 if (!thePrefs::GetNetworkED2K() && theApp->IsConnectedED2K()) {
661 theApp->DisconnectED2K();
664 if (!thePrefs::GetNetworkKademlia() && theApp->IsConnectedKad()) {
665 theApp->StopKad();
668 if (!thePrefs::GetNetworkED2K() && !thePrefs::GetNetworkKademlia()) {
669 wxMessageBox(
670 _("Both eD2k and Kad network are disabled.\nYou won't be able to connect until you enable at least one of them."));
673 if (thePrefs::GetNetworkKademlia() && thePrefs::IsUDPDisabled()) {
674 wxMessageBox(_("Kad will not start if your UDP port is disabled.\nEnable UDP port or disable Kad."),
675 _("Message"), wxOK | wxICON_INFORMATION, this);
678 if (CfgChanged(IDC_NETWORKKAD) || CfgChanged(IDC_NETWORKED2K)) {
679 theApp->amuledlg->DoNetworkRearrange();
682 if (restart_needed) {
683 wxMessageBox(restart_needed_msg + _("\nYou MUST restart aMule now.\nIf you do not restart now, don't complain if anything bad happens.\n"),
684 _("WARNING"), wxOK | wxICON_EXCLAMATION, this);
687 Show(false);
691 void PrefsUnifiedDlg::OnClose(wxCloseEvent& event)
693 Show(false);
695 // Try to keep the window alive when possible
696 if (event.CanVeto()) {
697 event.Veto();
698 } else {
699 if (theApp->amuledlg) {
700 theApp->amuledlg->m_prefsDialog = NULL;
703 // Un-Connect the Cfgs
704 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
705 for (; it != thePrefs::s_CfgList.end(); ++it) {
706 // Checking for failures
707 it->second->ConnectToWidget( 0 );
710 Destroy();
715 void PrefsUnifiedDlg::OnCancel(wxCommandEvent& WXUNUSED(event))
717 Show(false);
718 // restore state of server tab if necessary
719 EnableServerTab(thePrefs::GetNetworkED2K());
723 void PrefsUnifiedDlg::OnCheckBoxChange(wxCommandEvent& event)
725 bool value = event.IsChecked();
726 int id = event.GetId();
728 // Check if this checkbox is one of the User Events checkboxes
729 if (id >= USEREVENTS_FIRST_ID &&
730 id < USEREVENTS_FIRST_ID +
731 (int)CUserEvents::GetCount() * USEREVENTS_IDS_PER_EVENT) {
732 // The corresponding text control always has
733 // an ID one greater than the checkbox
734 FindWindow(id + 1)->Enable(value);
735 return;
738 switch ( id ) {
739 case IDC_UDPENABLE:
740 FindWindow( IDC_UDPPORT )->Enable(value);
741 break;
743 case IDC_CHECKDISKSPACE:
744 FindWindow( IDC_MINDISKSPACE )->Enable(value);
745 break;
747 case IDC_ONLINESIG:
748 FindWindow( IDC_OSDIR )->Enable(value);;
749 FindWindow(IDC_OSUPDATE)->Enable(value);
750 break;
752 case IDC_REMOVEDEAD:
753 FindWindow( IDC_SERVERRETRIES )->Enable(value);;
754 break;
756 case IDC_AUTOSERVER:
757 if ((CPath::GetFileSize(theApp->ConfigDir + wxT("addresses.dat")) == 0) &&
758 CastChild(event.GetId(), wxCheckBox)->IsChecked() ) {
759 wxMessageBox(_("Your Auto-update servers list is in blank.\nPlease fill in at least one URL to point to a valid server.met file.\nClick on the button \"List\" by this checkbox to enter an URL."),
760 _("Message"), wxOK | wxICON_INFORMATION);
761 CastChild(event.GetId(), wxCheckBox)->SetValue(false);
763 break;
765 case IDC_MSGFILTER:
766 // Toogle All filter options
767 FindWindow(IDC_MSGFILTER_ALL)->Enable(value);
768 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(value);
769 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(value);
770 FindWindow(IDC_MSGFILTER_WORD)->Enable(value);
771 if (value) {
772 FindWindow(IDC_MSGWORD)->Enable(
773 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
774 } else {
775 FindWindow(IDC_MSGWORD)->Enable(false);
777 break;
779 case IDC_MSGFILTER_ALL:
780 // Toogle filtering by data.
781 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(!value);
782 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(!value);
783 FindWindow(IDC_MSGFILTER_WORD)->Enable(!value);
784 if (!value) {
785 FindWindow(IDC_MSGWORD)->Enable(
786 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
787 } else {
788 FindWindow(IDC_MSGWORD)->Enable(false);
790 break;
792 case IDC_MSGFILTER_WORD:
793 // Toogle filter word list.
794 FindWindow(IDC_MSGWORD)->Enable(value);
795 break;
797 case IDC_FILTERCOMMENTS:
798 FindWindow(IDC_COMMENTWORD)->Enable(value);
799 break;
801 case ID_PROXY_ENABLE_PROXY:
802 FindWindow(ID_PROXY_TYPE)->Enable(value);
803 FindWindow(ID_PROXY_NAME)->Enable(value);
804 FindWindow(ID_PROXY_PORT)->Enable(value);
805 break;
807 case ID_PROXY_ENABLE_PASSWORD:
808 FindWindow(ID_PROXY_USER)->Enable(value);
809 FindWindow(ID_PROXY_PASSWORD)->Enable(value);
810 break;
812 case IDC_STARTNEXTFILE:
813 FindWindow(IDC_STARTNEXTFILE_SAME)->Enable(value);
814 break;
816 case IDC_ENABLETRAYICON:
817 FindWindow(IDC_MINTRAY)->Enable(value);
818 if (value) {
819 theApp->amuledlg->CreateSystray();
820 } else {
821 theApp->amuledlg->RemoveSystray();
823 thePrefs::SetUseTrayIcon(value);
824 break;
826 case ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY:
827 break;
829 case IDC_VERTTOOLBAR:
830 theApp->amuledlg->Create_Toolbar(value);
831 // Update the first tool (conn button)
832 theApp->amuledlg->ShowConnectionState();
833 break;
835 case IDC_ENFORCE_PO_INCOMING:
836 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(!value);
837 break;
839 case IDC_ENABLE_PO_OUTGOING:
840 FindWindow(IDC_SUPPORT_PO)->Enable(!value);
841 FindWindow(IDC_ENFORCE_PO_INCOMING)->Enable(value);
842 break;
844 case IDC_SUPPORT_PO:
845 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(value);
846 break;
848 case IDC_SHOWRATEONTITLE:
849 FindWindow(IDC_RATESBEFORETITLE)->Enable(value);
850 FindWindow(IDC_RATESAFTERTITLE)->Enable(value);
851 break;
853 case IDC_NETWORKED2K: {
854 EnableServerTab(value);
855 wxSpinEvent e;
856 OnTCPClientPortChange(e);
857 break;
860 default:
861 break;
866 void PrefsUnifiedDlg::OnButtonColorChange(wxCommandEvent& WXUNUSED(event))
868 int index = m_choiceColor->GetSelection();
869 wxColour col = wxGetColourFromUser( this, CMuleColour(thePrefs::s_colors[index]) );
870 if ( col.Ok() ) {
871 m_buttonColor->SetBackgroundColour( col );
872 thePrefs::s_colors[index] = CMuleColour(col).GetULong();
877 void PrefsUnifiedDlg::OnColorCategorySelected(wxCommandEvent& WXUNUSED(evt))
879 m_buttonColor->SetBackgroundColour(CMuleColour(thePrefs::s_colors[ m_choiceColor->GetSelection() ] ) );
883 void PrefsUnifiedDlg::OnButtonDir(wxCommandEvent& event)
885 wxString type;
887 int id = 0;
888 switch ( event.GetId() ) {
889 case IDC_SELTEMPDIR:
890 id = IDC_TEMPFILES;
891 type = _("Temporary files");
892 break;
894 case IDC_SELINCDIR:
895 id = IDC_INCFILES;
896 type = _("Incoming files");
897 break;
899 case IDC_SELOSDIR:
900 id = IDC_OSDIR;
901 type = _("Online Signatures");
902 break;
904 // case IDC_SELSKIN:
905 // id = IDC_SKIN;
906 // type = _("Skins directory");
907 // break;
909 default:
910 wxFAIL;
911 return;
914 type = CFormat(_("Choose a folder for %s")) % type;
915 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
916 wxString dir = widget->GetValue();
917 wxString str = wxDirSelector(
918 type, dir,
919 wxDD_DEFAULT_STYLE,
920 wxDefaultPosition, this);
921 if (!str.IsEmpty()) {
922 widget->SetValue(str);
927 void PrefsUnifiedDlg::OnButtonBrowseApplication(wxCommandEvent& event)
929 wxString title;
930 int id = 0;
931 switch ( event.GetId() ) {
932 case IDC_BROWSEV:
933 id = IDC_VIDEOPLAYER;
934 title = _("Browse for videoplayer");
935 break;
936 case IDC_SELBROWSER:
937 id = IDC_BROWSERSELF;
938 title = _("Select browser");
939 break;
940 default:
941 wxFAIL;
942 return;
944 wxString wildcard = CFormat(_("Executable%s"))
945 #ifdef __WXMSW__
946 % wxT(" (*.exe)|*.exe");
947 #else
948 % wxT("|*");
949 #endif
951 wxString str = wxFileSelector( title, wxEmptyString, wxEmptyString,
952 wxEmptyString, wildcard, 0, this );
954 if ( !str.IsEmpty() ) {
955 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
956 widget->SetValue( str );
961 void PrefsUnifiedDlg::OnButtonEditAddr(wxCommandEvent& WXUNUSED(evt))
963 wxString fullpath( theApp->ConfigDir + wxT("addresses.dat") );
965 EditServerListDlg* test = new EditServerListDlg(this, _("Edit server list"),
966 _("Add here URL's to download server.met files.\nOnly one url on each line."),
967 fullpath );
969 test->ShowModal();
970 delete test;
974 void PrefsUnifiedDlg::OnButtonIPFilterReload(wxCommandEvent& WXUNUSED(event))
976 theApp->ipfilter->Reload();
980 void PrefsUnifiedDlg::OnButtonIPFilterUpdate(wxCommandEvent& WXUNUSED(event))
982 theApp->ipfilter->Update( CastChild( IDC_IPFILTERURL, wxTextCtrl )->GetValue() );
986 void PrefsUnifiedDlg::OnPrefsPageChange(wxListEvent& event)
988 prefs_sizer->Detach( m_CurrentPanel );
989 m_CurrentPanel->Show( false );
991 m_CurrentPanel = (wxPanel *) m_PrefsIcons->GetItemData(event.GetIndex());
992 if (pages[event.GetIndex()].m_function == PreferencesDirectoriesTab) {
993 CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl)->Init();
996 prefs_sizer->Add( m_CurrentPanel, 0, wxGROW|wxEXPAND );
997 m_CurrentPanel->Show( true );
999 Layout();
1001 event.Skip();
1005 void PrefsUnifiedDlg::OnToolTipDelayChange(wxSpinEvent& event)
1007 wxToolTip::SetDelay( event.GetPosition() * 1000 );
1011 void PrefsUnifiedDlg::OnInitDialog( wxInitDialogEvent& WXUNUSED(evt) )
1013 // This function exists solely to avoid automatic transfer-to-widget calls
1017 void PrefsUnifiedDlg::OnScrollBarChange( wxScrollEvent& event )
1019 int id = 0;
1020 wxString label;
1022 switch ( event.GetId() ) {
1023 case IDC_SLIDER:
1024 id = IDC_SLIDERINFO;
1025 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1026 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(event.GetPosition());
1027 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(event.GetPosition());
1028 break;
1030 case IDC_SLIDER3:
1031 id = IDC_SLIDERINFO3;
1032 label = CFormat(wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event.GetPosition())) % event.GetPosition();
1033 theApp->m_statistics->SetAverageMinutes(event.GetPosition());
1034 break;
1036 case IDC_SLIDER4:
1037 id = IDC_SLIDERINFO4;
1038 label = CFormat(_("Connections Graph Scale: %d")) % event.GetPosition();
1039 theApp->amuledlg->m_statisticswnd->GetConnScope()->SetRanges(0, event.GetPosition());
1040 break;
1042 case IDC_SLIDER2:
1043 id = IDC_SLIDERINFO2;
1044 label = CFormat(wxPLURAL("Update delay : %d second", "Update delay : %d seconds", event.GetPosition())) % event.GetPosition();
1045 break;
1047 case IDC_FILEBUFFERSIZE:
1048 id = IDC_FILEBUFFERSIZE_STATIC;
1049 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1050 label = CFormat(wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event.GetPosition() * 15000)) % (event.GetPosition() * 15000);
1051 break;
1053 case IDC_QUEUESIZE:
1054 id = IDC_QUEUESIZE_STATIC;
1055 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1056 label = CFormat(wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event.GetPosition() * 100)) % (event.GetPosition() * 100);
1057 break;
1059 case IDC_SERVERKEEPALIVE:
1060 id = IDC_SERVERKEEPALIVE_LABEL;
1062 if ( event.GetPosition() ) {
1063 label = CFormat(wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event.GetPosition())) % event.GetPosition();
1064 } else {
1065 label = _("Server connection refresh interval: Disabled");
1067 break;
1069 default:
1070 return;
1073 wxStaticText* widget = CastChild( id, wxStaticText );
1075 if (widget) {
1076 widget->SetLabel( label );
1077 widget->GetParent()->Layout();
1082 void PrefsUnifiedDlg::OnRateLimitChanged( wxSpinEvent& event )
1084 // Here we do immediate sanity checking of the up/down ratio,
1085 // so that the user can see if his choice is illegal
1087 // We only do checks if the rate is limited
1088 if ( event.GetPosition() != (int)UNLIMITED ) {
1089 wxSpinCtrl* dlrate = CastChild( IDC_MAXDOWN, wxSpinCtrl );
1091 if ( event.GetPosition() < 4 ) {
1092 if ( ( event.GetPosition() * 3 < dlrate->GetValue() ) ||
1093 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1094 dlrate->SetValue( event.GetPosition() * 3 );
1096 } else if ( event.GetPosition() < 10 ) {
1097 if ( ( event.GetPosition() * 4 < dlrate->GetValue() ) ||
1098 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1099 dlrate->SetValue( event.GetPosition() * 4 );
1106 void PrefsUnifiedDlg::OnTCPClientPortChange(wxSpinEvent& WXUNUSED(event))
1108 CastChild(ID_TEXT_CLIENT_UDP_PORT, wxStaticText)->SetLabel(
1109 m_ServerTabVisible ? (wxString() << (CastChild(IDC_PORT, wxSpinCtrl)->GetValue() + 3))
1110 : wxString(_("disabled")));
1113 void PrefsUnifiedDlg::OnUserEventSelected(wxListEvent& event)
1115 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1116 IDC_PREFS_EVENTS_PAGE->Hide(i+1);
1119 IDC_PREFS_EVENTS_PAGE->Show((event.GetData() - USEREVENTS_FIRST_ID) / USEREVENTS_IDS_PER_EVENT + 1, true);
1121 IDC_PREFS_EVENTS_PAGE->Layout();
1123 event.Skip();
1126 void PrefsUnifiedDlg::OnLanguageChoice(wxCommandEvent &evt)
1128 thePrefs::GetCfgLang()->UpdateChoice(evt.GetSelection());
1131 void PrefsUnifiedDlg::CreateEventPanels(const int idx, const wxString& vars, wxWindow* parent)
1133 wxStaticBox *item8 = new wxStaticBox( parent, -1, CFormat(_("Execute command on `%s' event")) % wxGetTranslation(CUserEvents::GetDisplayName(static_cast<enum CUserEvents::EventType>(idx))) );
1134 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxVERTICAL );
1136 wxCheckBox *item9 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 1, _("Enable command execution on core"), wxDefaultPosition, wxDefaultSize, 0 );
1137 item7->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1139 wxFlexGridSizer *item10 = new wxFlexGridSizer( 3, 0, 0 );
1140 item10->AddGrowableCol( 2 );
1142 item10->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1144 wxStaticText *item11 = new wxStaticText( parent, -1, _("Core command:"), wxDefaultPosition, wxDefaultSize, 0 );
1145 item10->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
1147 wxTextCtrl *item12 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 2, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1148 item12->Enable(CUserEvents::IsCoreCommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1149 item10->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1151 item7->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1153 wxCheckBox *item14 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 3, _("Enable command execution on GUI"), wxDefaultPosition, wxDefaultSize, 0 );
1154 item7->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1156 wxFlexGridSizer *item15 = new wxFlexGridSizer( 3, 0, 0 );
1157 item15->AddGrowableCol( 2 );
1159 item15->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1161 wxStaticText *item16 = new wxStaticText( parent, -1, _("GUI command:"), wxDefaultPosition, wxDefaultSize, 0 );
1162 item15->Add( item16, 0, wxALIGN_CENTER|wxALL, 5 );
1164 wxTextCtrl *item17 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 4, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1165 item17->Enable(CUserEvents::IsGUICommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1166 item15->Add( item17, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1168 item7->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1170 wxStaticText *item13 = new wxStaticText( parent, -1, _("The following variables will be replaced:") + vars, wxDefaultPosition, wxDefaultSize, 0 );
1171 item7->Add( item13, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1173 IDC_PREFS_EVENTS_PAGE->Add(item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
1175 IDC_PREFS_EVENTS_PAGE->Layout();
1176 IDC_PREFS_EVENTS_PAGE->Hide(idx + 1);
1178 // File_checked_for_headers