Improve speed of category tab title updates
[amule.git] / src / PrefsUnifiedDlg.cpp
blobbaf3acc6180fa2692045c42ab3a2831518b8d679
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 "Statistics.h"
53 #include "UserEvents.h"
54 #include "PlatformSpecific.h"
56 BEGIN_EVENT_TABLE(PrefsUnifiedDlg,wxDialog)
57 // Events
58 #define USEREVENTS_EVENT(ID, NAME, VARS) \
59 EVT_CHECKBOX(USEREVENTS_FIRST_ID + CUserEvents::ID * USEREVENTS_IDS_PER_EVENT + 1, PrefsUnifiedDlg::OnCheckBoxChange) \
60 EVT_CHECKBOX(USEREVENTS_FIRST_ID + CUserEvents::ID * USEREVENTS_IDS_PER_EVENT + 3, PrefsUnifiedDlg::OnCheckBoxChange)
61 USEREVENTS_EVENTLIST()
62 #undef USEREVENTS_EVENT
64 // Proxy
65 EVT_CHECKBOX(ID_PROXY_ENABLE_PROXY, PrefsUnifiedDlg::OnCheckBoxChange)
66 EVT_CHECKBOX(ID_PROXY_ENABLE_PASSWORD, PrefsUnifiedDlg::OnCheckBoxChange)
67 // EVT_CHECKBOX(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, PrefsUnifiedDlg::OnCheckBoxChange)
69 // Connection
70 EVT_SPINCTRL(IDC_PORT, PrefsUnifiedDlg::OnTCPClientPortChange)
72 // The rest. Organize it!
73 EVT_CHECKBOX(IDC_UDPENABLE, PrefsUnifiedDlg::OnCheckBoxChange)
74 EVT_CHECKBOX(IDC_CHECKDISKSPACE, PrefsUnifiedDlg::OnCheckBoxChange)
75 EVT_CHECKBOX(IDC_ONLINESIG, PrefsUnifiedDlg::OnCheckBoxChange)
76 EVT_CHECKBOX(IDC_REMOVEDEAD, PrefsUnifiedDlg::OnCheckBoxChange)
77 EVT_CHECKBOX(IDC_AUTOSERVER, PrefsUnifiedDlg::OnCheckBoxChange)
78 EVT_CHECKBOX(IDC_AUTOIPFILTER, PrefsUnifiedDlg::OnCheckBoxChange)
79 EVT_CHECKBOX(IDC_MSGFILTER, PrefsUnifiedDlg::OnCheckBoxChange)
80 EVT_CHECKBOX(IDC_MSGFILTER_ALL, PrefsUnifiedDlg::OnCheckBoxChange)
81 EVT_CHECKBOX(IDC_MSGFILTER_WORD, PrefsUnifiedDlg::OnCheckBoxChange)
82 EVT_CHECKBOX(IDC_FILTERCOMMENTS, PrefsUnifiedDlg::OnCheckBoxChange)
83 EVT_CHECKBOX(IDC_STARTNEXTFILE, PrefsUnifiedDlg::OnCheckBoxChange)
84 EVT_CHECKBOX(IDC_ENABLETRAYICON, PrefsUnifiedDlg::OnCheckBoxChange)
85 EVT_CHECKBOX(IDC_VERTTOOLBAR, PrefsUnifiedDlg::OnCheckBoxChange)
86 EVT_CHECKBOX(IDC_SUPPORT_PO, PrefsUnifiedDlg::OnCheckBoxChange)
87 EVT_CHECKBOX(IDC_ENABLE_PO_OUTGOING, PrefsUnifiedDlg::OnCheckBoxChange)
88 EVT_CHECKBOX(IDC_ENFORCE_PO_INCOMING, PrefsUnifiedDlg::OnCheckBoxChange)
89 EVT_CHECKBOX(IDC_SHOWRATEONTITLE, PrefsUnifiedDlg::OnCheckBoxChange)
90 EVT_CHECKBOX(IDC_NETWORKED2K, PrefsUnifiedDlg::OnCheckBoxChange)
92 EVT_BUTTON(ID_PREFS_OK_TOP, PrefsUnifiedDlg::OnOk)
93 EVT_BUTTON(ID_PREFS_CANCEL_TOP, PrefsUnifiedDlg::OnCancel)
95 // Browse buttons
96 // EVT_BUTTON(IDC_SELSKIN, PrefsUnifiedDlg::OnButtonDir)
97 EVT_BUTTON(IDC_BROWSEV, PrefsUnifiedDlg::OnButtonBrowseApplication)
98 EVT_BUTTON(IDC_SELTEMPDIR, PrefsUnifiedDlg::OnButtonDir)
99 EVT_BUTTON(IDC_SELINCDIR, PrefsUnifiedDlg::OnButtonDir)
100 EVT_BUTTON(IDC_SELOSDIR, PrefsUnifiedDlg::OnButtonDir)
101 EVT_BUTTON(IDC_SELBROWSER, PrefsUnifiedDlg::OnButtonBrowseApplication)
103 EVT_SPINCTRL(IDC_TOOLTIPDELAY, PrefsUnifiedDlg::OnToolTipDelayChange)
105 EVT_BUTTON(IDC_EDITADR, PrefsUnifiedDlg::OnButtonEditAddr)
106 EVT_BUTTON(IDC_IPFRELOAD, PrefsUnifiedDlg::OnButtonIPFilterReload)
107 EVT_BUTTON(IDC_COLOR_BUTTON, PrefsUnifiedDlg::OnButtonColorChange)
108 EVT_BUTTON(IDC_IPFILTERUPDATE, PrefsUnifiedDlg::OnButtonIPFilterUpdate)
109 EVT_CHOICE(IDC_COLORSELECTOR, PrefsUnifiedDlg::OnColorCategorySelected)
110 EVT_LIST_ITEM_SELECTED(ID_PREFSLISTCTRL,PrefsUnifiedDlg::OnPrefsPageChange)
112 EVT_INIT_DIALOG(PrefsUnifiedDlg::OnInitDialog)
114 EVT_COMMAND_SCROLL(IDC_SLIDER, PrefsUnifiedDlg::OnScrollBarChange)
115 EVT_COMMAND_SCROLL(IDC_SLIDER3, PrefsUnifiedDlg::OnScrollBarChange)
116 EVT_COMMAND_SCROLL(IDC_SLIDER4, PrefsUnifiedDlg::OnScrollBarChange)
117 EVT_COMMAND_SCROLL(IDC_SLIDER2, PrefsUnifiedDlg::OnScrollBarChange)
118 EVT_COMMAND_SCROLL(IDC_FILEBUFFERSIZE, PrefsUnifiedDlg::OnScrollBarChange)
119 EVT_COMMAND_SCROLL(IDC_QUEUESIZE, PrefsUnifiedDlg::OnScrollBarChange)
120 EVT_COMMAND_SCROLL(IDC_SERVERKEEPALIVE, PrefsUnifiedDlg::OnScrollBarChange)
122 EVT_SPINCTRL(IDC_MAXUP, PrefsUnifiedDlg::OnRateLimitChanged)
124 EVT_LIST_ITEM_SELECTED(IDC_EVENTLIST, PrefsUnifiedDlg::OnUserEventSelected)
126 EVT_CHOICE(IDC_LANGUAGE, PrefsUnifiedDlg::OnLanguageChoice)
128 EVT_CLOSE(PrefsUnifiedDlg::OnClose)
130 END_EVENT_TABLE()
134 * Creates an command-event for the given checkbox.
136 * This can be used enforce logical constraints by passing by
137 * sending a check-box event for each checkbox, when transfering
138 * to the UI. However, it should also be used for checkboxes that
139 * have no side-effects other than enabling/disabling other
140 * widgets in the preferences dialogs.
142 void SendCheckBoxEvent(wxWindow* parent, int id)
144 wxCheckBox* widget = CastByID(id, parent, wxCheckBox);
145 wxCHECK_RET(widget, wxT("Invalid widget in CreateEvent"));
147 wxCommandEvent evt(wxEVT_COMMAND_CHECKBOX_CLICKED, id);
148 evt.SetInt(widget->IsChecked() ? 1 : 0);
150 parent->GetEventHandler()->ProcessEvent(evt);
156 * This struct provides a general way to represent config-tabs.
158 struct PrefsPage
160 //! The title of the page, used on the listctrl.
161 wxString m_title;
162 //! Function pointer to the wxDesigner function creating the dialog.
163 wxSizer* (*m_function)(wxWindow*, bool, bool );
164 //! The index of the image used on the list.
165 int m_imageidx;
169 PrefsPage pages[] =
171 { wxTRANSLATE("General"), PreferencesGeneralTab, 13 },
172 { wxTRANSLATE("Connection"), PreferencesConnectionTab, 14 },
173 { wxTRANSLATE("Directories"), PreferencesDirectoriesTab, 17 },
174 { wxTRANSLATE("Servers"), PreferencesServerTab, 15 },
175 { wxTRANSLATE("Files"), PreferencesFilesTab, 16 },
176 { wxTRANSLATE("Security"), PreferencesSecurityTab, 22 },
177 { wxTRANSLATE("Interface"), PreferencesGuiTweaksTab, 19 },
178 { wxTRANSLATE("Statistics"), PreferencesStatisticsTab, 10 },
179 { wxTRANSLATE("Proxy"), PreferencesProxyTab, 24 },
180 { wxTRANSLATE("Filters"), PreferencesFilteringTab, 23 },
181 { wxTRANSLATE("Remote Controls"), PreferencesRemoteControlsTab, 11 },
182 { wxTRANSLATE("Online Signature"), PreferencesOnlineSigTab, 21 },
183 { wxTRANSLATE("Advanced"), PreferencesaMuleTweaksTab, 12 },
184 { wxTRANSLATE("Events"), PreferencesEventsTab, 5 }
185 #ifdef __DEBUG__
186 ,{ wxTRANSLATE("Debugging"), PreferencesDebug, 25 }
187 #endif
191 PrefsUnifiedDlg::PrefsUnifiedDlg(wxWindow *parent)
193 wxDialog(parent, -1, _("Preferences"),
194 wxDefaultPosition, wxDefaultSize,
195 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
197 preferencesDlgTop(this, false);
199 m_PrefsIcons = CastChild(ID_PREFSLISTCTRL, wxListCtrl);
200 wxImageList *icon_list = new wxImageList(16, 16);
201 m_PrefsIcons->AssignImageList(icon_list, wxIMAGE_LIST_SMALL);
203 // Add the single column used
204 m_PrefsIcons->InsertColumn(
205 0, wxEmptyString, wxLIST_FORMAT_LEFT,
206 m_PrefsIcons->GetSize().GetWidth()-5);
208 // Temp variables for finding the smallest height and width needed
209 int width = 0;
210 int height = 0;
212 // Add each page to the page-list
213 for (unsigned int i = 0; i < itemsof(pages); ++i) {
214 // Add the icon and label associated with the page
215 icon_list->Add(amuleSpecial(pages[i].m_imageidx));
216 m_PrefsIcons->InsertItem(i, wxGetTranslation(pages[i].m_title), i);
219 // Set list-width so that there aren't any scrollers
220 m_PrefsIcons->SetColumnWidth(0, wxLIST_AUTOSIZE);
221 m_PrefsIcons->SetMinSize(wxSize(m_PrefsIcons->GetColumnWidth(0) + 10, -1));
222 m_PrefsIcons->SetMaxSize(wxSize(m_PrefsIcons->GetColumnWidth(0) + 10, -1));
224 // Now add the pages and calculate the minimum size
225 wxPanel * DefaultWidget = NULL;
226 for (unsigned int i = 0; i < itemsof(pages); ++i) {
227 // Create a container widget and the contents of the page
228 wxPanel * Widget = new wxPanel(this, -1);
229 // Widget is stored as user data in the list control
230 m_PrefsIcons->SetItemPtrData(i, (wxUIntPtr) Widget);
231 pages[i].m_function(Widget, true, true);
232 if (i == 0) {
233 DefaultWidget = Widget;
236 // Add it to the sizer
237 prefs_sizer->Add(Widget, 0, wxGROW|wxEXPAND);
239 if (pages[i].m_function == PreferencesGeneralTab) {
240 // This must be done now or pages won't Fit();
241 #ifdef __WXMSW__
242 CastChild(IDC_BROWSERTABS, wxCheckBox)->Enable(false);
243 #endif /* __WXMSW__ */
244 CastChild(IDC_PREVIEW_NOTE, wxStaticText)->SetLabel(_("The following variables will be substituted:\n %PARTFILE - full path to the file\n %PARTNAME - file name only"));
245 } else if (pages[i].m_function == PreferencesGuiTweaksTab) {
246 #ifndef ENABLE_IP2COUNTRY
247 CastChild(IDC_SHOW_COUNTRY_FLAGS, wxCheckBox)->Enable(false);
248 thePrefs::SetGeoIPEnabled(false);
249 #endif
250 } else if (pages[i].m_function == PreferencesEventsTab) {
252 #define USEREVENTS_REPLACE_VAR(VAR, DESC, CODE) + wxString(wxT("\n %") VAR wxT(" - ")) + wxGetTranslation(DESC)
253 #define USEREVENTS_EVENT(ID, NAME, VARS) case CUserEvents::ID: CreateEventPanels(idx, wxEmptyString VARS, Widget); break;
255 wxListCtrl *list = CastChild(IDC_EVENTLIST, wxListCtrl);
256 list->InsertColumn(0, wxEmptyString);
257 for (unsigned int idx = 0; idx < CUserEvents::GetCount(); ++idx) {
258 long lidx = list->InsertItem(idx,
259 wxGetTranslation(CUserEvents::GetDisplayName(
260 static_cast<enum CUserEvents::EventType>(idx))));
261 if (lidx != -1) {
262 list->SetItemData(lidx,
263 USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT);
264 switch (idx) {
265 USEREVENTS_EVENTLIST()
269 list->SetColumnWidth(0, wxLIST_AUTOSIZE);
271 else if (pages[i].m_function == PreferencesServerTab) {
272 m_IndexServerTab = i;
273 m_ServerWidget = Widget;
275 else if (pages[i].m_function == PreferencesaMuleTweaksTab) {
276 wxStaticText *txt = CastChild(IDC_AMULE_TWEAKS_WARNING, wxStaticText);
277 // Do not wrap this line, Windows _() can't handle wrapped strings
278 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."));
279 #if defined CLIENT_GUI || !PLATFORMSPECIFIC_CAN_PREVENT_SLEEP_MODE
280 CastChild(IDC_PREVENT_SLEEP, wxCheckBox)->Enable(false);
281 thePrefs::SetPreventSleepWhileDownloading(false);
282 #endif
284 #ifdef __DEBUG__
285 else if (pages[i].m_function == PreferencesDebug) {
286 int count = theLogger.GetDebugCategoryCount();
287 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
289 for ( int j = 0; j < count; j++ ) {
290 list->Append( theLogger.GetDebugCategory( j ).GetName() );
293 #endif
295 // Align and resize the page
296 Fit();
297 Layout();
299 // Find the greatest sizes
300 wxSize size = prefs_sizer->GetSize();
301 if (size.GetWidth() > width) {
302 width = size.GetWidth();
305 if (size.GetHeight() > height) {
306 height = size.GetHeight();
309 // Hide it for now
310 prefs_sizer->Detach(Widget);
311 Widget->Show(false);
314 // Default to the General tab
315 m_CurrentPanel = DefaultWidget;
316 prefs_sizer->Add(DefaultWidget, 0, wxGROW|wxEXPAND);
317 m_CurrentPanel->Show( true );
319 // Select the first item
320 m_PrefsIcons->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
322 // We now have the needed minimum height and width
323 prefs_sizer->SetMinSize(width, height);
325 // Don't show server prefs if ED2K is disabled
326 m_ServerTabVisible = true;
327 EnableServerTab(thePrefs::GetNetworkED2K());
329 // Store some often used pointers
330 m_ShareSelector = CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl);
331 m_buttonColor = CastChild(IDC_COLOR_BUTTON, wxButton);
332 m_choiceColor = CastChild(IDC_COLORSELECTOR, wxChoice);
334 // Connect the Cfgs with their widgets
335 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
336 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
337 // Checking for failures
338 if ( !it->second->ConnectToWidget(it->first, this) ) {
339 AddLogLineNS(CFormat(_("Failed to connect Cfg to widget with the ID %d and key %s"))
340 % it->first % it->second->GetKey());
343 Fit();
345 // It must not be resized to something smaller than what it currently is
346 wxSize size = GetClientSize();
347 SetSizeHints(size.GetWidth(), size.GetHeight());
349 // Position the dialog.
350 Center();
354 void PrefsUnifiedDlg::EnableServerTab(bool enable)
356 if (enable && !m_ServerTabVisible) {
357 // turn server widget on
358 m_PrefsIcons->InsertItem(m_IndexServerTab, wxGetTranslation(pages[m_IndexServerTab].m_title), m_IndexServerTab);
359 m_PrefsIcons->SetItemPtrData(m_IndexServerTab, (wxUIntPtr) m_ServerWidget);
360 m_ServerTabVisible = true;
361 } else if (!enable && m_ServerTabVisible) {
362 // turn server widget off
363 m_PrefsIcons->DeleteItem(m_IndexServerTab);
364 m_ServerTabVisible = false;
369 Cfg_Base* PrefsUnifiedDlg::GetCfg(int id)
371 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.find( id );
373 if ( it != thePrefs::s_CfgList.end() ) {
374 return it->second;
377 return NULL;
381 bool PrefsUnifiedDlg::TransferToWindow()
383 // Connect the Cfgs with their widgets
384 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
385 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
386 // Checking for failures
387 if ( !it->second->TransferToWindow() ) {
388 AddLogLineNS(CFormat(_("Failed to transfer data from Cfg to Widget with the ID %d and key %s"))
389 % it->first % it->second->GetKey());
393 m_ShareSelector->SetSharedDirectories(&theApp->glob_prefs->shareddir_list);
395 for ( int i = 0; i < cntStatColors; i++ ) {
396 thePrefs::s_colors[i] = CMuleColour(CStatisticsDlg::acrStat[i]).GetULong();
397 thePrefs::s_colors_ref[i] = CMuleColour(CStatisticsDlg::acrStat[i]).GetULong();
400 // Connection tab
401 wxSpinEvent e;
402 OnTCPClientPortChange(e);
404 // Proxy tab initialization
405 FindWindow(ID_PROXY_TYPE)->SetToolTip(_("The type of proxy you are connecting to"));
406 if (!CastChild(ID_PROXY_ENABLE_PROXY, wxCheckBox)->IsChecked()) {
407 FindWindow(ID_PROXY_TYPE)->Enable(false);
408 FindWindow(ID_PROXY_NAME)->Enable(false);
409 FindWindow(ID_PROXY_PORT)->Enable(false);
411 if (!CastChild(ID_PROXY_ENABLE_PASSWORD, wxCheckBox)->IsChecked()) {
412 FindWindow(ID_PROXY_USER)->Enable(false);
413 FindWindow(ID_PROXY_PASSWORD)->Enable(false);
415 // This option from the proxy tab is currently unused
416 FindWindow(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY)->Enable(false);
418 // Enable/Disable some controls
419 FindWindow( IDC_MINDISKSPACE )->Enable( thePrefs::IsCheckDiskspaceEnabled() );
420 FindWindow( IDC_OSDIR )->Enable( thePrefs::IsOnlineSignatureEnabled() );
421 FindWindow( IDC_OSUPDATE )->Enable( thePrefs::IsOnlineSignatureEnabled() );
422 FindWindow( IDC_UDPPORT )->Enable( thePrefs::s_UDPEnable );
423 FindWindow( IDC_SERVERRETRIES )->Enable( thePrefs::DeadServer() );
424 FindWindow( IDC_STARTNEXTFILE_SAME )->Enable(thePrefs::StartNextFile());
425 FindWindow( IDC_STARTNEXTFILE_ALPHA )->Enable(thePrefs::StartNextFile());
427 #ifdef __WXMAC__
428 FindWindow(IDC_ENABLETRAYICON)->Enable(false);
429 FindWindow(IDC_MINTRAY)->Enable(false);
430 #else
431 FindWindow(IDC_MINTRAY)->Enable(thePrefs::UseTrayIcon());
432 #endif
434 if (!CastChild(IDC_MSGFILTER, wxCheckBox)->IsChecked()) {
435 FindWindow(IDC_MSGFILTER_ALL)->Enable(false);
436 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(false);
437 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(false);
438 FindWindow(IDC_MSGFILTER_WORD)->Enable(false);
439 FindWindow(IDC_MSGWORD)->Enable(false);
440 } else if (CastChild(IDC_MSGFILTER_ALL, wxCheckBox)->IsChecked()) {
441 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(false);
442 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(false);
443 FindWindow(IDC_MSGFILTER_WORD)->Enable(false);
444 FindWindow(IDC_MSGWORD)->Enable(false);
447 FindWindow(IDC_MSGWORD)->Enable(CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
448 FindWindow(IDC_COMMENTWORD)->Enable(CastChild(IDC_FILTERCOMMENTS, wxCheckBox)->IsChecked());
450 #ifdef CLIENT_GUI
451 // Disable dirpickers unless it's a localhost connection
452 if (!theApp->m_connect->IsConnectedToLocalHost()) {
453 FindWindow(IDC_SELINCDIR)->Enable(false);
454 FindWindow(IDC_SELTEMPDIR)->Enable(false);
456 #endif
458 // Protocol obfuscation
459 ::SendCheckBoxEvent(this, IDC_SUPPORT_PO);
460 ::SendCheckBoxEvent(this, IDC_ENABLE_PO_OUTGOING);
461 ::SendCheckBoxEvent(this, IDC_ENFORCE_PO_INCOMING);
463 // Show rates on title
464 FindWindow(IDC_RATESBEFORETITLE)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
465 FindWindow(IDC_RATESAFTERTITLE)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
466 CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->SetValue(thePrefs::GetShowRatesOnTitle() != 0);
467 CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->SetValue(thePrefs::GetShowRatesOnTitle() == 2);
468 CastChild(IDC_RATESAFTERTITLE, wxRadioButton)->SetValue(thePrefs::GetShowRatesOnTitle() != 2);
470 // UPNP
471 #ifndef ENABLE_UPNP
472 FindWindow(IDC_UPNP_ENABLED)->Enable(false);
473 FindWindow(IDC_UPNPTCPPORT)->Enable(false);
474 thePrefs::SetUPnPEnabled(false);
475 // TODO: grey out "UPnP TCP Port", "Webserver UPnP TCP Port"
476 FindWindow(IDC_UPNP_WEBSERVER_ENABLED)->Enable(false);
477 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(false);
478 thePrefs::SetUPnPWebServerEnabled(false);
479 FindWindow(IDC_UPNP_EC_ENABLED)->Enable(false);
480 thePrefs::SetUPnPECEnabled(false);
481 #endif
483 #ifdef __DEBUG__
484 // Set debugging toggles
485 int count = theLogger.GetDebugCategoryCount();
486 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
488 for ( int i = 0; i < count; i++ ) {
489 list->Check( i, theLogger.GetDebugCategory( i ).IsEnabled() );
491 #endif
493 return true;
497 bool PrefsUnifiedDlg::TransferFromWindow()
499 // Connect the Cfgs with their widgets
500 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
501 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
502 // Checking for failures
503 if ( !it->second->TransferFromWindow() ) {
504 AddLogLineNS(CFormat(_("Failed to transfer data from Widget to Cfg with the ID %d and key %s"))
505 % it->first % it->second->GetKey());
509 theApp->glob_prefs->shareddir_list.clear();
510 m_ShareSelector->GetSharedDirectories(&theApp->glob_prefs->shareddir_list);
512 for ( int i = 0; i < cntStatColors; i++ ) {
513 if ( thePrefs::s_colors[i] != thePrefs::s_colors_ref[i] ) {
514 CStatisticsDlg::acrStat[i] = thePrefs::s_colors[i];
515 theApp->amuledlg->m_statisticswnd->ApplyStatsColor(i);
518 theApp->amuledlg->m_kademliawnd->SetGraphColors();
521 #ifdef __DEBUG__
522 // Get debugging toggles
523 int count = theLogger.GetDebugCategoryCount();
524 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
526 for ( int i = 0; i < count; i++ ) {
527 theLogger.SetEnabled( theLogger.GetDebugCategory( i ).GetType(), list->IsChecked( i ) );
529 #endif
531 thePrefs::SetShowRatesOnTitle(CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->GetValue() ? (CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->GetValue() ? 2 : 1) : 0);
533 #ifdef CLIENT_GUI
534 // Send preferences to core.
535 theApp->glob_prefs->SendToRemote();
536 #endif
538 return true;
542 bool PrefsUnifiedDlg::CfgChanged(int ID)
544 Cfg_Base* cfg = GetCfg(ID);
546 if ( cfg ) {
547 return cfg->HasChanged();
550 return false;
554 void PrefsUnifiedDlg::OnOk(wxCommandEvent& WXUNUSED(event))
556 TransferFromWindow();
558 bool restart_needed = false;
559 wxString restart_needed_msg = _("aMule must be restarted to enable these changes:\n\n");
561 // do sanity checking, special processing, and user notifications here
562 thePrefs::CheckUlDlRatio();
564 if (CfgChanged(IDC_PORT)) {
565 restart_needed = true;
566 restart_needed_msg += _("- TCP port changed.\n");
569 if (CfgChanged(IDC_UDPPORT)) {
570 restart_needed = true;
571 restart_needed_msg += _("- UDP port changed.\n");
574 if (CfgChanged(IDC_EXT_CONN_TCP_PORT)) {
575 restart_needed = true;
576 restart_needed_msg += _("- External connect port changed.\n");
578 if (CfgChanged(IDC_EXT_CONN_ACCEPT)) {
579 restart_needed = true;
580 restart_needed_msg += _("- External connect acceptance changed.\n");
582 if (CfgChanged(IDC_EXT_CONN_IP)) {
583 restart_needed = true;
584 restart_needed_msg += _("- External connect interface changed.\n");
587 // Force port checking
588 thePrefs::SetPort(thePrefs::GetPort());
590 if ((CPath::GetFileSize(theApp->ConfigDir + wxT("addresses.dat")) == 0) &&
591 CastChild(IDC_AUTOSERVER, wxCheckBox)->IsChecked() ) {
592 thePrefs::UnsetAutoServerStart();
593 wxMessageBox(_("Your Auto-update server list is empty.\n'Auto-update server list at startup' will be disabled."),
594 _("Message"), wxOK | wxICON_INFORMATION, this);
597 if (thePrefs::AcceptExternalConnections() && thePrefs::ECPassword().IsEmpty()) {
598 thePrefs::EnableExternalConnections( false );
600 wxMessageBox( _("You have enabled external connections but have not specified a password.\nExternal connections cannot be enabled unless a valid password is specified."));
603 // save the preferences on ok
604 theApp->glob_prefs->Save();
606 if (CfgChanged(IDC_FED2KLH) && theApp->amuledlg->GetActiveDialog() != CamuleDlg::DT_SEARCH_WND) {
607 theApp->amuledlg->ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
610 if (CfgChanged(IDC_LANGUAGE)) {
611 restart_needed = true;
612 restart_needed_msg += _("- Language changed.\n");
615 if (CfgChanged(IDC_TEMPFILES)) {
616 restart_needed = true;
617 restart_needed_msg += _("- Temp folder changed.\n");
620 if (CfgChanged(IDC_NETWORKED2K) && thePrefs::GetNetworkED2K()) {
621 restart_needed = true;
622 restart_needed_msg += _("- ED2K network enabled.\n");
625 if (CfgChanged(IDC_INCFILES) || CfgChanged(IDC_TEMPFILES) || m_ShareSelector->HasChanged ) {
626 theApp->sharedfiles->Reload();
629 if (CfgChanged(IDC_OSDIR) || CfgChanged(IDC_ONLINESIG)) {
630 wxTextCtrl* widget = CastChild( IDC_OSDIR, wxTextCtrl );
632 // Build the filenames for the two OS files
633 theApp->SetOSFiles( widget->GetValue() );
636 if (CfgChanged(IDC_IPFCLIENTS) && thePrefs::IsFilteringClients()) {
637 theApp->clientlist->FilterQueues();
640 if (CfgChanged(IDC_IPFSERVERS) && thePrefs::IsFilteringServers()) {
641 theApp->serverlist->FilterServers();
644 if (CfgChanged(ID_IPFILTERLEVEL)) {
645 theApp->ipfilter->Reload();
648 if (thePrefs::GetShowRatesOnTitle()) {
649 // This avoids a 5 seconds delay to show the title
650 theApp->amuledlg->ShowTransferRate();
651 } else {
652 // This resets the title
653 theApp->amuledlg->SetTitle(theApp->m_FrameTitle);
656 if (CfgChanged(IDC_EXTCATINFO)) {
657 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
660 // Changes related to the statistics-dlg
661 if (CfgChanged(IDC_SLIDER)) {
662 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
663 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
666 if ( CfgChanged(IDC_SLIDER3) ) {
667 theApp->amuledlg->m_statisticswnd->ResetAveragingTime();
670 if (CfgChanged(IDC_DOWNLOAD_CAP)) {
671 theApp->amuledlg->m_statisticswnd->SetARange( true, thePrefs::GetMaxGraphDownloadRate() );
674 if (CfgChanged(IDC_UPLOAD_CAP)) {
675 theApp->amuledlg->m_statisticswnd->SetARange( false, thePrefs::GetMaxGraphUploadRate() );
678 if (CfgChanged(IDC_SKIN)) {
679 theApp->amuledlg->Create_Toolbar(thePrefs::VerticalToolbar());
682 if (!thePrefs::GetNetworkED2K() && theApp->IsConnectedED2K()) {
683 theApp->DisconnectED2K();
686 if (!thePrefs::GetNetworkKademlia() && theApp->IsConnectedKad()) {
687 theApp->StopKad();
690 if (!thePrefs::GetNetworkED2K() && !thePrefs::GetNetworkKademlia()) {
691 wxMessageBox(
692 _("Both eD2k and Kad network are disabled.\nYou won't be able to connect until you enable at least one of them."));
695 if (thePrefs::GetNetworkKademlia() && thePrefs::IsUDPDisabled()) {
696 wxMessageBox(_("Kad will not start if your UDP port is disabled.\nEnable UDP port or disable Kad."),
697 _("Message"), wxOK | wxICON_INFORMATION, this);
700 if (CfgChanged(IDC_NETWORKKAD) || CfgChanged(IDC_NETWORKED2K)) {
701 theApp->amuledlg->DoNetworkRearrange();
704 if (CfgChanged(IDC_SHOW_COUNTRY_FLAGS)) {
705 theApp->amuledlg->EnableIP2Country();
708 if (restart_needed) {
709 wxMessageBox(restart_needed_msg + _("\nYou MUST restart aMule now.\nIf you do not restart now, don't complain if anything bad happens.\n"),
710 _("WARNING"), wxOK | wxICON_EXCLAMATION, this);
713 Show(false);
717 void PrefsUnifiedDlg::OnClose(wxCloseEvent& event)
719 Show(false);
721 // Try to keep the window alive when possible
722 if (event.CanVeto()) {
723 event.Veto();
724 } else {
725 if (theApp->amuledlg) {
726 theApp->amuledlg->m_prefsDialog = NULL;
729 // Un-Connect the Cfgs
730 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
731 for (; it != thePrefs::s_CfgList.end(); ++it) {
732 // Checking for failures
733 it->second->ConnectToWidget( 0 );
736 Destroy();
741 void PrefsUnifiedDlg::OnCancel(wxCommandEvent& WXUNUSED(event))
743 Show(false);
744 // restore state of server tab if necessary
745 EnableServerTab(thePrefs::GetNetworkED2K());
749 void PrefsUnifiedDlg::OnCheckBoxChange(wxCommandEvent& event)
751 bool value = event.IsChecked();
752 int id = event.GetId();
754 // Check if this checkbox is one of the User Events checkboxes
755 if (id >= USEREVENTS_FIRST_ID &&
756 id < USEREVENTS_FIRST_ID +
757 (int)CUserEvents::GetCount() * USEREVENTS_IDS_PER_EVENT) {
758 // The corresponding text control always has
759 // an ID one greater than the checkbox
760 FindWindow(id + 1)->Enable(value);
761 return;
764 switch ( id ) {
765 case IDC_UDPENABLE:
766 FindWindow( IDC_UDPPORT )->Enable(value);
767 break;
769 case IDC_CHECKDISKSPACE:
770 FindWindow( IDC_MINDISKSPACE )->Enable(value);
771 break;
773 case IDC_ONLINESIG:
774 FindWindow( IDC_OSDIR )->Enable(value);;
775 FindWindow(IDC_OSUPDATE)->Enable(value);
776 break;
778 case IDC_REMOVEDEAD:
779 FindWindow( IDC_SERVERRETRIES )->Enable(value);;
780 break;
782 case IDC_AUTOSERVER:
783 if ((CPath::GetFileSize(theApp->ConfigDir + wxT("addresses.dat")) == 0) &&
784 CastChild(event.GetId(), wxCheckBox)->IsChecked() ) {
785 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."),
786 _("Message"), wxOK | wxICON_INFORMATION);
787 CastChild(event.GetId(), wxCheckBox)->SetValue(false);
789 break;
791 case IDC_MSGFILTER:
792 // Toogle All filter options
793 FindWindow(IDC_MSGFILTER_ALL)->Enable(value);
794 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(value);
795 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(value);
796 FindWindow(IDC_MSGFILTER_WORD)->Enable(value);
797 if (value) {
798 FindWindow(IDC_MSGWORD)->Enable(
799 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
800 } else {
801 FindWindow(IDC_MSGWORD)->Enable(false);
803 break;
805 case IDC_MSGFILTER_ALL:
806 // Toogle filtering by data.
807 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(!value);
808 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(!value);
809 FindWindow(IDC_MSGFILTER_WORD)->Enable(!value);
810 if (!value) {
811 FindWindow(IDC_MSGWORD)->Enable(
812 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
813 } else {
814 FindWindow(IDC_MSGWORD)->Enable(false);
816 break;
818 case IDC_MSGFILTER_WORD:
819 // Toogle filter word list.
820 FindWindow(IDC_MSGWORD)->Enable(value);
821 break;
823 case IDC_FILTERCOMMENTS:
824 FindWindow(IDC_COMMENTWORD)->Enable(value);
825 break;
827 case ID_PROXY_ENABLE_PROXY:
828 FindWindow(ID_PROXY_TYPE)->Enable(value);
829 FindWindow(ID_PROXY_NAME)->Enable(value);
830 FindWindow(ID_PROXY_PORT)->Enable(value);
831 break;
833 case ID_PROXY_ENABLE_PASSWORD:
834 FindWindow(ID_PROXY_USER)->Enable(value);
835 FindWindow(ID_PROXY_PASSWORD)->Enable(value);
836 break;
838 case IDC_STARTNEXTFILE:
839 FindWindow(IDC_STARTNEXTFILE_SAME)->Enable(value);
840 FindWindow(IDC_STARTNEXTFILE_ALPHA)->Enable(value);
841 break;
843 case IDC_ENABLETRAYICON:
844 FindWindow(IDC_MINTRAY)->Enable(value);
845 if (value) {
846 theApp->amuledlg->CreateSystray();
847 } else {
848 theApp->amuledlg->RemoveSystray();
850 thePrefs::SetUseTrayIcon(value);
851 break;
853 case ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY:
854 break;
856 case IDC_VERTTOOLBAR:
857 theApp->amuledlg->Create_Toolbar(value);
858 // Update the first tool (conn button)
859 theApp->amuledlg->ShowConnectionState();
860 theApp->amuledlg->Layout();
861 break;
863 case IDC_ENFORCE_PO_INCOMING:
864 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(!value);
865 break;
867 case IDC_ENABLE_PO_OUTGOING:
868 FindWindow(IDC_SUPPORT_PO)->Enable(!value);
869 FindWindow(IDC_ENFORCE_PO_INCOMING)->Enable(value);
870 break;
872 case IDC_SUPPORT_PO:
873 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(value);
874 break;
876 case IDC_SHOWRATEONTITLE:
877 FindWindow(IDC_RATESBEFORETITLE)->Enable(value);
878 FindWindow(IDC_RATESAFTERTITLE)->Enable(value);
879 break;
881 case IDC_NETWORKED2K: {
882 EnableServerTab(value);
883 wxSpinEvent e;
884 OnTCPClientPortChange(e);
885 break;
888 default:
889 break;
894 void PrefsUnifiedDlg::OnButtonColorChange(wxCommandEvent& WXUNUSED(event))
896 int index = m_choiceColor->GetSelection();
897 wxColour col = wxGetColourFromUser( this, CMuleColour(thePrefs::s_colors[index]) );
898 if ( col.Ok() ) {
899 m_buttonColor->SetBackgroundColour( col );
900 thePrefs::s_colors[index] = CMuleColour(col).GetULong();
905 void PrefsUnifiedDlg::OnColorCategorySelected(wxCommandEvent& WXUNUSED(evt))
907 m_buttonColor->SetBackgroundColour(CMuleColour(thePrefs::s_colors[ m_choiceColor->GetSelection() ] ) );
911 void PrefsUnifiedDlg::OnButtonDir(wxCommandEvent& event)
913 wxString type;
915 int id = 0;
916 switch ( event.GetId() ) {
917 case IDC_SELTEMPDIR:
918 id = IDC_TEMPFILES;
919 type = _("Temporary files");
920 break;
922 case IDC_SELINCDIR:
923 id = IDC_INCFILES;
924 type = _("Incoming files");
925 break;
927 case IDC_SELOSDIR:
928 id = IDC_OSDIR;
929 type = _("Online Signatures");
930 break;
932 // case IDC_SELSKIN:
933 // id = IDC_SKIN;
934 // type = _("Skins directory");
935 // break;
937 default:
938 wxFAIL;
939 return;
942 type = CFormat(_("Choose a folder for %s")) % type;
943 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
944 wxString dir = widget->GetValue();
945 wxString str = wxDirSelector(
946 type, dir,
947 wxDD_DEFAULT_STYLE,
948 wxDefaultPosition, this);
949 if (!str.IsEmpty()) {
950 widget->SetValue(str);
955 void PrefsUnifiedDlg::OnButtonBrowseApplication(wxCommandEvent& event)
957 wxString title;
958 int id = 0;
959 switch ( event.GetId() ) {
960 case IDC_BROWSEV:
961 id = IDC_VIDEOPLAYER;
962 title = _("Browse for videoplayer");
963 break;
964 case IDC_SELBROWSER:
965 id = IDC_BROWSERSELF;
966 title = _("Select browser");
967 break;
968 default:
969 wxFAIL;
970 return;
972 wxString wildcard = CFormat(_("Executable%s"))
973 #ifdef __WXMSW__
974 % wxT(" (*.exe)|*.exe");
975 #else
976 % wxT("|*");
977 #endif
979 wxString str = wxFileSelector( title, wxEmptyString, wxEmptyString,
980 wxEmptyString, wildcard, 0, this );
982 if ( !str.IsEmpty() ) {
983 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
984 widget->SetValue( str );
989 void PrefsUnifiedDlg::OnButtonEditAddr(wxCommandEvent& WXUNUSED(evt))
991 wxString fullpath( theApp->ConfigDir + wxT("addresses.dat") );
993 EditServerListDlg* test = new EditServerListDlg(this, _("Edit server list"),
994 _("Add here URL's to download server.met files.\nOnly one url on each line."),
995 fullpath );
997 test->ShowModal();
998 delete test;
1002 void PrefsUnifiedDlg::OnButtonIPFilterReload(wxCommandEvent& WXUNUSED(event))
1004 theApp->ipfilter->Reload();
1008 void PrefsUnifiedDlg::OnButtonIPFilterUpdate(wxCommandEvent& WXUNUSED(event))
1010 theApp->ipfilter->Update( CastChild( IDC_IPFILTERURL, wxTextCtrl )->GetValue() );
1014 void PrefsUnifiedDlg::OnPrefsPageChange(wxListEvent& event)
1016 prefs_sizer->Detach( m_CurrentPanel );
1017 m_CurrentPanel->Show( false );
1019 m_CurrentPanel = (wxPanel *) m_PrefsIcons->GetItemData(event.GetIndex());
1020 if (pages[event.GetIndex()].m_function == PreferencesDirectoriesTab) {
1021 CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl)->Init();
1024 prefs_sizer->Add( m_CurrentPanel, 0, wxGROW|wxEXPAND );
1025 m_CurrentPanel->Show( true );
1027 Layout();
1029 event.Skip();
1033 void PrefsUnifiedDlg::OnToolTipDelayChange(wxSpinEvent& event)
1035 wxToolTip::SetDelay( event.GetPosition() * 1000 );
1039 void PrefsUnifiedDlg::OnInitDialog( wxInitDialogEvent& WXUNUSED(evt) )
1041 // This function exists solely to avoid automatic transfer-to-widget calls
1045 void PrefsUnifiedDlg::OnScrollBarChange( wxScrollEvent& event )
1047 int id = 0;
1048 wxString label;
1050 switch ( event.GetId() ) {
1051 case IDC_SLIDER:
1052 id = IDC_SLIDERINFO;
1053 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1054 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(event.GetPosition());
1055 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(event.GetPosition());
1056 break;
1058 case IDC_SLIDER3:
1059 id = IDC_SLIDERINFO3;
1060 label = CFormat(wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event.GetPosition())) % event.GetPosition();
1061 theApp->m_statistics->SetAverageMinutes(event.GetPosition());
1062 break;
1064 case IDC_SLIDER4:
1065 id = IDC_SLIDERINFO4;
1066 label = CFormat(_("Connections Graph Scale: %d")) % event.GetPosition();
1067 theApp->amuledlg->m_statisticswnd->GetConnScope()->SetRanges(0, event.GetPosition());
1068 break;
1070 case IDC_SLIDER2:
1071 id = IDC_SLIDERINFO2;
1072 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1073 break;
1075 case IDC_FILEBUFFERSIZE:
1076 id = IDC_FILEBUFFERSIZE_STATIC;
1077 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1078 label = CFormat(wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event.GetPosition() * 15000)) % (event.GetPosition() * 15000);
1079 break;
1081 case IDC_QUEUESIZE:
1082 id = IDC_QUEUESIZE_STATIC;
1083 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1084 label = CFormat(wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event.GetPosition() * 100)) % (event.GetPosition() * 100);
1085 break;
1087 case IDC_SERVERKEEPALIVE:
1088 id = IDC_SERVERKEEPALIVE_LABEL;
1090 if ( event.GetPosition() ) {
1091 label = CFormat(wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event.GetPosition())) % event.GetPosition();
1092 } else {
1093 label = _("Server connection refresh interval: Disabled");
1095 break;
1097 default:
1098 return;
1101 wxStaticText* widget = CastChild( id, wxStaticText );
1103 if (widget) {
1104 widget->SetLabel( label );
1105 widget->GetParent()->Layout();
1110 void PrefsUnifiedDlg::OnRateLimitChanged( wxSpinEvent& event )
1112 // Here we do immediate sanity checking of the up/down ratio,
1113 // so that the user can see if his choice is illegal
1115 // We only do checks if the rate is limited
1116 if ( event.GetPosition() != (int)UNLIMITED ) {
1117 wxSpinCtrl* dlrate = CastChild( IDC_MAXDOWN, wxSpinCtrl );
1119 if ( event.GetPosition() < 4 ) {
1120 if ( ( event.GetPosition() * 3 < dlrate->GetValue() ) ||
1121 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1122 dlrate->SetValue( event.GetPosition() * 3 );
1124 } else if ( event.GetPosition() < 10 ) {
1125 if ( ( event.GetPosition() * 4 < dlrate->GetValue() ) ||
1126 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1127 dlrate->SetValue( event.GetPosition() * 4 );
1134 void PrefsUnifiedDlg::OnTCPClientPortChange(wxSpinEvent& WXUNUSED(event))
1136 CastChild(ID_TEXT_CLIENT_UDP_PORT, wxStaticText)->SetLabel(
1137 m_ServerTabVisible ? (wxString() << (CastChild(IDC_PORT, wxSpinCtrl)->GetValue() + 3))
1138 : wxString(_("disabled")));
1141 void PrefsUnifiedDlg::OnUserEventSelected(wxListEvent& event)
1143 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1144 IDC_PREFS_EVENTS_PAGE->Hide(i+1);
1147 IDC_PREFS_EVENTS_PAGE->Show((event.GetData() - USEREVENTS_FIRST_ID) / USEREVENTS_IDS_PER_EVENT + 1, true);
1149 IDC_PREFS_EVENTS_PAGE->Layout();
1151 event.Skip();
1154 void PrefsUnifiedDlg::OnLanguageChoice(wxCommandEvent &evt)
1156 thePrefs::GetCfgLang()->UpdateChoice(evt.GetSelection());
1159 void PrefsUnifiedDlg::CreateEventPanels(const int idx, const wxString& vars, wxWindow* parent)
1161 wxStaticBox *item8 = new wxStaticBox( parent, -1, CFormat(_("Execute command on '%s' event")) % wxGetTranslation(CUserEvents::GetDisplayName(static_cast<enum CUserEvents::EventType>(idx))) );
1162 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxVERTICAL );
1164 wxCheckBox *item9 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 1, _("Enable command execution on core"), wxDefaultPosition, wxDefaultSize, 0 );
1165 item7->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1167 wxFlexGridSizer *item10 = new wxFlexGridSizer( 3, 0, 0 );
1168 item10->AddGrowableCol( 2 );
1170 item10->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1172 wxStaticText *item11 = new wxStaticText( parent, -1, _("Core command:"), wxDefaultPosition, wxDefaultSize, 0 );
1173 item10->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
1175 wxTextCtrl *item12 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 2, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1176 item12->Enable(CUserEvents::IsCoreCommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1177 item10->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1179 item7->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1181 wxCheckBox *item14 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 3, _("Enable command execution on GUI"), wxDefaultPosition, wxDefaultSize, 0 );
1182 item7->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1184 wxFlexGridSizer *item15 = new wxFlexGridSizer( 3, 0, 0 );
1185 item15->AddGrowableCol( 2 );
1187 item15->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1189 wxStaticText *item16 = new wxStaticText( parent, -1, _("GUI command:"), wxDefaultPosition, wxDefaultSize, 0 );
1190 item15->Add( item16, 0, wxALIGN_CENTER|wxALL, 5 );
1192 wxTextCtrl *item17 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 4, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1193 item17->Enable(CUserEvents::IsGUICommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1194 item15->Add( item17, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1196 item7->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1198 wxStaticText *item13 = new wxStaticText( parent, -1, _("The following variables will be replaced:") + vars, wxDefaultPosition, wxDefaultSize, 0 );
1199 item7->Add( item13, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1201 IDC_PREFS_EVENTS_PAGE->Add(item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
1203 IDC_PREFS_EVENTS_PAGE->Layout();
1204 IDC_PREFS_EVENTS_PAGE->Hide(idx + 1);
1206 // File_checked_for_headers