Safe write for nodes.dat
[amule.git] / src / PrefsUnifiedDlg.cpp
blob8c88c45f7ccea62014b99dfa8cf579de464f3420
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2011 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.
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 #ifndef __WXMAC__
85 EVT_CHECKBOX(IDC_ENABLETRAYICON, PrefsUnifiedDlg::OnCheckBoxChange)
86 #endif
87 EVT_CHECKBOX(IDC_VERTTOOLBAR, PrefsUnifiedDlg::OnCheckBoxChange)
88 EVT_CHECKBOX(IDC_SUPPORT_PO, PrefsUnifiedDlg::OnCheckBoxChange)
89 EVT_CHECKBOX(IDC_ENABLE_PO_OUTGOING, PrefsUnifiedDlg::OnCheckBoxChange)
90 EVT_CHECKBOX(IDC_ENFORCE_PO_INCOMING, PrefsUnifiedDlg::OnCheckBoxChange)
91 EVT_CHECKBOX(IDC_SHOWRATEONTITLE, PrefsUnifiedDlg::OnCheckBoxChange)
92 EVT_CHECKBOX(IDC_NETWORKED2K, PrefsUnifiedDlg::OnCheckBoxChange)
93 EVT_CHECKBOX(IDC_NETWORKKAD, PrefsUnifiedDlg::OnCheckBoxChange)
94 EVT_CHECKBOX(IDC_UPNP_ENABLED, PrefsUnifiedDlg::OnCheckBoxChange)
95 EVT_CHECKBOX(IDC_UPNP_WEBSERVER_ENABLED,PrefsUnifiedDlg::OnCheckBoxChange)
98 EVT_BUTTON(ID_PREFS_OK_TOP, PrefsUnifiedDlg::OnOk)
99 EVT_BUTTON(ID_PREFS_CANCEL_TOP, PrefsUnifiedDlg::OnCancel)
101 // Browse buttons
102 // EVT_BUTTON(IDC_SELSKIN, PrefsUnifiedDlg::OnButtonDir)
103 EVT_BUTTON(IDC_BROWSEV, PrefsUnifiedDlg::OnButtonBrowseApplication)
104 EVT_BUTTON(IDC_SELTEMPDIR, PrefsUnifiedDlg::OnButtonDir)
105 EVT_BUTTON(IDC_SELINCDIR, PrefsUnifiedDlg::OnButtonDir)
106 EVT_BUTTON(IDC_SELOSDIR, PrefsUnifiedDlg::OnButtonDir)
107 EVT_BUTTON(IDC_SELBROWSER, PrefsUnifiedDlg::OnButtonBrowseApplication)
109 EVT_SPINCTRL(IDC_TOOLTIPDELAY, PrefsUnifiedDlg::OnToolTipDelayChange)
111 EVT_BUTTON(IDC_EDITADR, PrefsUnifiedDlg::OnButtonEditAddr)
112 EVT_BUTTON(IDC_IPFRELOAD, PrefsUnifiedDlg::OnButtonIPFilterReload)
113 EVT_BUTTON(IDC_COLOR_BUTTON, PrefsUnifiedDlg::OnButtonColorChange)
114 EVT_BUTTON(IDC_IPFILTERUPDATE, PrefsUnifiedDlg::OnButtonIPFilterUpdate)
115 EVT_CHOICE(IDC_COLORSELECTOR, PrefsUnifiedDlg::OnColorCategorySelected)
116 EVT_LIST_ITEM_SELECTED(ID_PREFSLISTCTRL,PrefsUnifiedDlg::OnPrefsPageChange)
118 EVT_INIT_DIALOG(PrefsUnifiedDlg::OnInitDialog)
120 EVT_COMMAND_SCROLL(IDC_SLIDER, PrefsUnifiedDlg::OnScrollBarChange)
121 EVT_COMMAND_SCROLL(IDC_SLIDER3, PrefsUnifiedDlg::OnScrollBarChange)
122 EVT_COMMAND_SCROLL(IDC_SLIDER4, PrefsUnifiedDlg::OnScrollBarChange)
123 EVT_COMMAND_SCROLL(IDC_SLIDER2, PrefsUnifiedDlg::OnScrollBarChange)
124 EVT_COMMAND_SCROLL(IDC_FILEBUFFERSIZE, PrefsUnifiedDlg::OnScrollBarChange)
125 EVT_COMMAND_SCROLL(IDC_QUEUESIZE, PrefsUnifiedDlg::OnScrollBarChange)
126 EVT_COMMAND_SCROLL(IDC_SERVERKEEPALIVE, PrefsUnifiedDlg::OnScrollBarChange)
128 EVT_SPINCTRL(IDC_MAXUP, PrefsUnifiedDlg::OnRateLimitChanged)
130 EVT_LIST_ITEM_SELECTED(IDC_EVENTLIST, PrefsUnifiedDlg::OnUserEventSelected)
132 EVT_CHOICE(IDC_LANGUAGE, PrefsUnifiedDlg::OnLanguageChoice)
134 EVT_CLOSE(PrefsUnifiedDlg::OnClose)
136 END_EVENT_TABLE()
140 * Creates an command-event for the given checkbox.
142 * This can be used enforce logical constraints by passing by
143 * sending a check-box event for each checkbox, when transfering
144 * to the UI. However, it should also be used for checkboxes that
145 * have no side-effects other than enabling/disabling other
146 * widgets in the preferences dialogs.
148 void SendCheckBoxEvent(wxWindow* parent, int id)
150 wxCheckBox* widget = CastByID(id, parent, wxCheckBox);
151 wxCHECK_RET(widget, wxT("Invalid widget in CreateEvent"));
153 wxCommandEvent evt(wxEVT_COMMAND_CHECKBOX_CLICKED, id);
154 evt.SetInt(widget->IsChecked() ? 1 : 0);
156 parent->GetEventHandler()->ProcessEvent(evt);
162 * This struct provides a general way to represent config-tabs.
164 struct PrefsPage
166 //! The title of the page, used on the listctrl.
167 wxString m_title;
168 //! Function pointer to the wxDesigner function creating the dialog.
169 wxSizer* (*m_function)(wxWindow*, bool, bool );
170 //! The index of the image used on the list.
171 int m_imageidx;
175 PrefsPage pages[] =
177 { wxTRANSLATE("General"), PreferencesGeneralTab, 13 },
178 { wxTRANSLATE("Connection"), PreferencesConnectionTab, 14 },
179 { wxTRANSLATE("Directories"), PreferencesDirectoriesTab, 17 },
180 { wxTRANSLATE("Servers"), PreferencesServerTab, 15 },
181 { wxTRANSLATE("Files"), PreferencesFilesTab, 16 },
182 { wxTRANSLATE("Security"), PreferencesSecurityTab, 22 },
183 { wxTRANSLATE("Interface"), PreferencesGuiTweaksTab, 19 },
184 { wxTRANSLATE("Statistics"), PreferencesStatisticsTab, 10 },
185 { wxTRANSLATE("Proxy"), PreferencesProxyTab, 24 },
186 { wxTRANSLATE("Filters"), PreferencesFilteringTab, 23 },
187 { wxTRANSLATE("Remote Controls"), PreferencesRemoteControlsTab, 11 },
188 { wxTRANSLATE("Online Signature"), PreferencesOnlineSigTab, 21 },
189 { wxTRANSLATE("Advanced"), PreferencesaMuleTweaksTab, 12 },
190 { wxTRANSLATE("Events"), PreferencesEventsTab, 5 }
191 #ifdef __DEBUG__
192 ,{ wxTRANSLATE("Debugging"), PreferencesDebug, 25 }
193 #endif
197 PrefsUnifiedDlg::PrefsUnifiedDlg(wxWindow *parent)
199 wxDialog(parent, -1, _("Preferences"),
200 wxDefaultPosition, wxDefaultSize,
201 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
203 preferencesDlgTop(this, false);
205 m_PrefsIcons = CastChild(ID_PREFSLISTCTRL, wxListCtrl);
206 wxImageList *icon_list = new wxImageList(16, 16);
207 m_PrefsIcons->AssignImageList(icon_list, wxIMAGE_LIST_SMALL);
209 // Add the single column used
210 m_PrefsIcons->InsertColumn(
211 0, wxEmptyString, wxLIST_FORMAT_LEFT,
212 m_PrefsIcons->GetSize().GetWidth()-5);
214 // Temp variables for finding the smallest height and width needed
215 int width = 0;
216 int height = 0;
218 // Add each page to the page-list
219 for (unsigned int i = 0; i < itemsof(pages); ++i) {
220 // Add the icon and label associated with the page
221 icon_list->Add(amuleSpecial(pages[i].m_imageidx));
222 m_PrefsIcons->InsertItem(i, wxGetTranslation(pages[i].m_title), i);
225 // Set list-width so that there aren't any scrollers
226 m_PrefsIcons->SetColumnWidth(0, wxLIST_AUTOSIZE);
227 m_PrefsIcons->SetMinSize(wxSize(m_PrefsIcons->GetColumnWidth(0) + 10, -1));
228 m_PrefsIcons->SetMaxSize(wxSize(m_PrefsIcons->GetColumnWidth(0) + 10, -1));
230 // Now add the pages and calculate the minimum size
231 wxPanel * DefaultWidget = NULL;
232 for (unsigned int i = 0; i < itemsof(pages); ++i) {
233 // Create a container widget and the contents of the page
234 wxPanel * Widget = new wxPanel(this, -1);
235 // Widget is stored as user data in the list control
236 m_PrefsIcons->SetItemPtrData(i, (wxUIntPtr) Widget);
237 pages[i].m_function(Widget, true, true);
238 if (i == 0) {
239 DefaultWidget = Widget;
242 // Add it to the sizer
243 prefs_sizer->Add(Widget, 0, wxGROW|wxEXPAND);
245 if (pages[i].m_function == PreferencesGeneralTab) {
246 // This must be done now or pages won't Fit();
247 #ifdef __WXMSW__
248 CastChild(IDC_BROWSERTABS, wxCheckBox)->Enable(false);
249 #endif /* __WXMSW__ */
250 CastChild(IDC_PREVIEW_NOTE, wxStaticText)->SetLabel(_("The following variables will be substituted:\n %PARTFILE - full path to the file\n %PARTNAME - file name only"));
251 #ifdef __WXMAC__
252 FindWindow(IDC_ENABLETRAYICON)->Show(false);
253 FindWindow(IDC_MINTRAY)->Show(false);
254 #endif
255 } else if (pages[i].m_function == PreferencesEventsTab) {
257 #define USEREVENTS_REPLACE_VAR(VAR, DESC, CODE) + wxString(wxT("\n %") VAR wxT(" - ")) + wxGetTranslation(DESC)
258 #define USEREVENTS_EVENT(ID, NAME, VARS) case CUserEvents::ID: CreateEventPanels(idx, wxEmptyString VARS, Widget); break;
260 wxListCtrl *list = CastChild(IDC_EVENTLIST, wxListCtrl);
261 list->InsertColumn(0, wxEmptyString);
262 for (unsigned int idx = 0; idx < CUserEvents::GetCount(); ++idx) {
263 long lidx = list->InsertItem(idx,
264 wxGetTranslation(CUserEvents::GetDisplayName(
265 static_cast<enum CUserEvents::EventType>(idx))));
266 if (lidx != -1) {
267 list->SetItemData(lidx,
268 USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT);
269 switch (idx) {
270 USEREVENTS_EVENTLIST()
271 /* This macro expands to handle all user event types. Here is an example:
272 case CUserEvents::NewChatSession: {
273 CreateEventPanels(idx, wxString(wxT("\n %SENDER - ")) + wxTRANSLATE("Message sender."), Widget);
274 break;
275 } */
279 list->SetColumnWidth(0, wxLIST_AUTOSIZE);
281 else if (pages[i].m_function == PreferencesServerTab) {
282 m_IndexServerTab = i;
283 m_ServerWidget = Widget;
285 else if (pages[i].m_function == PreferencesaMuleTweaksTab) {
286 wxStaticText *txt = CastChild(IDC_AMULE_TWEAKS_WARNING, wxStaticText);
287 // Do not wrap this line, Windows _() can't handle wrapped strings
288 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."));
289 #if defined CLIENT_GUI || !PLATFORMSPECIFIC_CAN_PREVENT_SLEEP_MODE
290 CastChild(IDC_PREVENT_SLEEP, wxCheckBox)->Enable(false);
291 thePrefs::SetPreventSleepWhileDownloading(false);
292 #endif
294 #ifdef __DEBUG__
295 else if (pages[i].m_function == PreferencesDebug) {
296 int count = theLogger.GetDebugCategoryCount();
297 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
299 for ( int j = 0; j < count; j++ ) {
300 list->Append( theLogger.GetDebugCategory( j ).GetName() );
303 #endif
305 // Align and resize the page
306 Fit();
307 Layout();
309 // Find the greatest sizes
310 wxSize size = prefs_sizer->GetSize();
311 if (size.GetWidth() > width) {
312 width = size.GetWidth();
315 if (size.GetHeight() > height) {
316 height = size.GetHeight();
319 // Hide it for now
320 prefs_sizer->Detach(Widget);
321 Widget->Show(false);
324 // Default to the General tab
325 m_CurrentPanel = DefaultWidget;
326 prefs_sizer->Add(DefaultWidget, 0, wxGROW|wxEXPAND);
327 m_CurrentPanel->Show( true );
329 // Select the first item
330 m_PrefsIcons->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
332 // We now have the needed minimum height and width
333 prefs_sizer->SetMinSize(width, height);
335 // Don't show server prefs if ED2K is disabled
336 m_ServerTabVisible = true;
337 EnableServerTab(thePrefs::GetNetworkED2K());
339 // Store some often used pointers
340 m_ShareSelector = CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl);
341 m_buttonColor = CastChild(IDC_COLOR_BUTTON, wxButton);
342 m_choiceColor = CastChild(IDC_COLORSELECTOR, wxChoice);
344 // Connect the Cfgs with their widgets
345 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
346 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
347 // Checking for failures
348 if ( !it->second->ConnectToWidget(it->first, this) ) {
349 AddLogLineNS(CFormat(_("Failed to connect Cfg to widget with the ID %d and key %s"))
350 % it->first % it->second->GetKey());
353 Fit();
355 // It must not be resized to something smaller than what it currently is
356 wxSize size = GetClientSize();
357 SetSizeHints(size.GetWidth(), size.GetHeight());
359 // Position the dialog.
360 Center();
364 void PrefsUnifiedDlg::EnableServerTab(bool enable)
366 if (enable && !m_ServerTabVisible) {
367 // turn server widget on
368 m_PrefsIcons->InsertItem(m_IndexServerTab, wxGetTranslation(pages[m_IndexServerTab].m_title), m_IndexServerTab);
369 m_PrefsIcons->SetItemPtrData(m_IndexServerTab, (wxUIntPtr) m_ServerWidget);
370 m_ServerTabVisible = true;
371 } else if (!enable && m_ServerTabVisible) {
372 // turn server widget off
373 m_PrefsIcons->DeleteItem(m_IndexServerTab);
374 m_ServerTabVisible = false;
379 Cfg_Base* PrefsUnifiedDlg::GetCfg(int id)
381 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.find( id );
383 if ( it != thePrefs::s_CfgList.end() ) {
384 return it->second;
387 return NULL;
391 bool PrefsUnifiedDlg::TransferToWindow()
393 // Connect the Cfgs with their widgets
394 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
395 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
396 // Checking for failures
397 if ( !it->second->TransferToWindow() ) {
398 AddLogLineNS(CFormat(_("Failed to transfer data from Cfg to Widget with the ID %d and key %s"))
399 % it->first % it->second->GetKey());
403 m_ShareSelector->SetSharedDirectories(&theApp->glob_prefs->shareddir_list);
405 for ( int i = 0; i < cntStatColors; i++ ) {
406 thePrefs::s_colors[i] = CMuleColour(CStatisticsDlg::acrStat[i]).GetULong();
407 thePrefs::s_colors_ref[i] = CMuleColour(CStatisticsDlg::acrStat[i]).GetULong();
410 // Connection tab
411 wxSpinEvent e;
412 OnTCPClientPortChange(e);
414 // Proxy tab initialization
415 FindWindow(ID_PROXY_TYPE)->SetToolTip(_("The type of proxy you are connecting to"));
416 if (!CastChild(ID_PROXY_ENABLE_PROXY, wxCheckBox)->IsChecked()) {
417 FindWindow(ID_PROXY_TYPE)->Enable(false);
418 FindWindow(ID_PROXY_NAME)->Enable(false);
419 FindWindow(ID_PROXY_PORT)->Enable(false);
421 if (!CastChild(ID_PROXY_ENABLE_PASSWORD, wxCheckBox)->IsChecked()) {
422 FindWindow(ID_PROXY_USER)->Enable(false);
423 FindWindow(ID_PROXY_PASSWORD)->Enable(false);
425 // This option from the proxy tab is currently unused
426 FindWindow(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY)->Enable(false);
428 // Enable/Disable some controls
429 FindWindow( IDC_MINDISKSPACE )->Enable( thePrefs::IsCheckDiskspaceEnabled() );
430 FindWindow( IDC_OSDIR )->Enable( thePrefs::IsOnlineSignatureEnabled() );
431 FindWindow( IDC_OSUPDATE )->Enable( thePrefs::IsOnlineSignatureEnabled() );
432 FindWindow( IDC_UDPENABLE )->Enable( !thePrefs::GetNetworkKademlia());
433 FindWindow( IDC_UDPPORT )->Enable( thePrefs::s_UDPEnable );
434 FindWindow( IDC_SERVERRETRIES )->Enable( thePrefs::DeadServer() );
435 FindWindow( IDC_STARTNEXTFILE_SAME )->Enable(thePrefs::StartNextFile());
436 FindWindow( IDC_STARTNEXTFILE_ALPHA )->Enable(thePrefs::StartNextFile());
438 #ifndef __WXMAC__
439 FindWindow(IDC_MINTRAY)->Enable(thePrefs::UseTrayIcon());
440 #endif
442 if (!CastChild(IDC_MSGFILTER, wxCheckBox)->IsChecked()) {
443 FindWindow(IDC_MSGFILTER_ALL)->Enable(false);
444 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(false);
445 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(false);
446 FindWindow(IDC_MSGFILTER_WORD)->Enable(false);
447 FindWindow(IDC_MSGWORD)->Enable(false);
448 } else if (CastChild(IDC_MSGFILTER_ALL, wxCheckBox)->IsChecked()) {
449 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(false);
450 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(false);
451 FindWindow(IDC_MSGFILTER_WORD)->Enable(false);
452 FindWindow(IDC_MSGWORD)->Enable(false);
455 FindWindow(IDC_MSGWORD)->Enable(CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
456 FindWindow(IDC_COMMENTWORD)->Enable(CastChild(IDC_FILTERCOMMENTS, wxCheckBox)->IsChecked());
458 #ifdef CLIENT_GUI
459 // Disable dirpickers unless it's a localhost connection
460 if (!theApp->m_connect->IsConnectedToLocalHost()) {
461 FindWindow(IDC_SELINCDIR)->Enable(false);
462 FindWindow(IDC_SELTEMPDIR)->Enable(false);
464 #endif
466 // Protocol obfuscation
467 ::SendCheckBoxEvent(this, IDC_SUPPORT_PO);
468 ::SendCheckBoxEvent(this, IDC_ENABLE_PO_OUTGOING);
469 ::SendCheckBoxEvent(this, IDC_ENFORCE_PO_INCOMING);
471 #ifndef ENABLE_IP2COUNTRY
472 CastChild(IDC_SHOW_COUNTRY_FLAGS, wxCheckBox)->Enable(false);
473 thePrefs::SetGeoIPEnabled(false);
474 #endif
476 #ifdef __SVN__
477 // Version is always shown on the title in development versions
478 CastChild(IDC_SHOWVERSIONONTITLE, wxCheckBox)->SetValue(true);
479 CastChild(IDC_SHOWVERSIONONTITLE, wxCheckBox)->Enable(false);
480 #endif
482 // Show rates on title
483 FindWindow(IDC_RATESBEFORETITLE)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
484 FindWindow(IDC_RATESAFTERTITLE)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
485 CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->SetValue(thePrefs::GetShowRatesOnTitle() != 0);
486 CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->SetValue(thePrefs::GetShowRatesOnTitle() == 2);
487 CastChild(IDC_RATESAFTERTITLE, wxRadioButton)->SetValue(thePrefs::GetShowRatesOnTitle() != 2);
489 // UPNP
490 #ifndef ENABLE_UPNP
491 FindWindow(IDC_UPNP_ENABLED)->Enable(false);
492 FindWindow(IDC_UPNPTCPPORT)->Enable(false);
493 FindWindow(IDC_UPNPTCPPORTTEXT)->Enable(false);
494 thePrefs::SetUPnPEnabled(false);
495 FindWindow(IDC_UPNP_WEBSERVER_ENABLED)->Enable(false);
496 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(false);
497 FindWindow(IDC_WEBUPNPTCPPORTTEXT)->Enable(false);
498 thePrefs::SetUPnPWebServerEnabled(false);
499 FindWindow(IDC_UPNP_EC_ENABLED)->Enable(false);
500 thePrefs::SetUPnPECEnabled(false);
501 #else
502 FindWindow(IDC_UPNPTCPPORT)->Enable(thePrefs::GetUPnPEnabled());
503 FindWindow(IDC_UPNPTCPPORTTEXT)->Enable(thePrefs::GetUPnPEnabled());
504 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(thePrefs::GetUPnPWebServerEnabled());
505 FindWindow(IDC_WEBUPNPTCPPORTTEXT)->Enable(thePrefs::GetUPnPWebServerEnabled());
506 #endif
508 #ifdef __DEBUG__
509 // Set debugging toggles
510 int count = theLogger.GetDebugCategoryCount();
511 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
513 for ( int i = 0; i < count; i++ ) {
514 list->Check( i, theLogger.GetDebugCategory( i ).IsEnabled() );
516 #endif
518 return true;
522 bool PrefsUnifiedDlg::TransferFromWindow()
524 // Connect the Cfgs with their widgets
525 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
526 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
527 // Checking for failures
528 if ( !it->second->TransferFromWindow() ) {
529 AddLogLineNS(CFormat(_("Failed to transfer data from Widget to Cfg with the ID %d and key %s"))
530 % it->first % it->second->GetKey());
534 theApp->glob_prefs->shareddir_list.clear();
535 m_ShareSelector->GetSharedDirectories(&theApp->glob_prefs->shareddir_list);
537 for ( int i = 0; i < cntStatColors; i++ ) {
538 if ( thePrefs::s_colors[i] != thePrefs::s_colors_ref[i] ) {
539 CStatisticsDlg::acrStat[i] = thePrefs::s_colors[i];
540 theApp->amuledlg->m_statisticswnd->ApplyStatsColor(i);
543 theApp->amuledlg->m_kademliawnd->SetGraphColors();
546 #ifdef __DEBUG__
547 // Get debugging toggles
548 int count = theLogger.GetDebugCategoryCount();
549 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
551 for ( int i = 0; i < count; i++ ) {
552 theLogger.SetEnabled( theLogger.GetDebugCategory( i ).GetType(), list->IsChecked( i ) );
554 #endif
556 thePrefs::SetShowRatesOnTitle(CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->GetValue() ? (CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->GetValue() ? 2 : 1) : 0);
558 #ifdef CLIENT_GUI
559 // Send preferences to core.
560 theApp->glob_prefs->SendToRemote();
561 #endif
563 return true;
567 bool PrefsUnifiedDlg::CfgChanged(int ID)
569 Cfg_Base* cfg = GetCfg(ID);
571 if ( cfg ) {
572 return cfg->HasChanged();
575 return false;
579 void PrefsUnifiedDlg::OnOk(wxCommandEvent& WXUNUSED(event))
581 TransferFromWindow();
583 bool restart_needed = false;
584 wxString restart_needed_msg = _("aMule must be restarted to enable these changes:\n\n");
586 // do sanity checking, special processing, and user notifications here
587 thePrefs::CheckUlDlRatio();
589 if (CfgChanged(IDC_PORT)) {
590 restart_needed = true;
591 restart_needed_msg += _("- TCP port changed.\n");
594 if (CfgChanged(IDC_UDPPORT)) {
595 restart_needed = true;
596 restart_needed_msg += _("- UDP port changed.\n");
599 if (CfgChanged(IDC_EXT_CONN_TCP_PORT)) {
600 restart_needed = true;
601 restart_needed_msg += _("- External connect port changed.\n");
603 if (CfgChanged(IDC_EXT_CONN_ACCEPT)) {
604 restart_needed = true;
605 restart_needed_msg += _("- External connect acceptance changed.\n");
607 if (CfgChanged(IDC_EXT_CONN_IP)) {
608 restart_needed = true;
609 restart_needed_msg += _("- External connect interface changed.\n");
612 // Force port checking
613 thePrefs::SetPort(thePrefs::GetPort());
615 if ((CPath::GetFileSize(theApp->ConfigDir + wxT("addresses.dat")) == 0) &&
616 CastChild(IDC_AUTOSERVER, wxCheckBox)->IsChecked() ) {
617 thePrefs::UnsetAutoServerStart();
618 wxMessageBox(_("Your Auto-update server list is empty.\n'Auto-update server list at startup' will be disabled."),
619 _("Message"), wxOK | wxICON_INFORMATION, this);
622 if (thePrefs::AcceptExternalConnections() && thePrefs::ECPassword().IsEmpty()) {
623 thePrefs::EnableExternalConnections( false );
625 wxMessageBox( _("You have enabled external connections but have not specified a password.\nExternal connections cannot be enabled unless a valid password is specified."));
628 // save the preferences on ok
629 theApp->glob_prefs->Save();
631 if (CfgChanged(IDC_FED2KLH) && theApp->amuledlg->GetActiveDialog() != CamuleDlg::DT_SEARCH_WND) {
632 theApp->amuledlg->ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
635 if (CfgChanged(IDC_LANGUAGE)) {
636 restart_needed = true;
637 restart_needed_msg += _("- Language changed.\n");
640 if (CfgChanged(IDC_TEMPFILES)) {
641 restart_needed = true;
642 restart_needed_msg += _("- Temp folder changed.\n");
645 if (CfgChanged(IDC_NETWORKED2K) && thePrefs::GetNetworkED2K()) {
646 restart_needed = true;
647 restart_needed_msg += _("- ED2K network enabled.\n");
650 if (CfgChanged(IDC_INCFILES) || CfgChanged(IDC_TEMPFILES) || m_ShareSelector->HasChanged ) {
651 theApp->sharedfiles->Reload();
654 if (CfgChanged(IDC_OSDIR) || CfgChanged(IDC_ONLINESIG)) {
655 wxTextCtrl* widget = CastChild( IDC_OSDIR, wxTextCtrl );
657 // Build the filenames for the two OS files
658 theApp->SetOSFiles( widget->GetValue() );
661 if (CfgChanged(IDC_IPFCLIENTS) && thePrefs::IsFilteringClients()) {
662 theApp->clientlist->FilterQueues();
665 if (CfgChanged(IDC_IPFSERVERS) && thePrefs::IsFilteringServers()) {
666 theApp->serverlist->FilterServers();
669 if (CfgChanged(ID_IPFILTERLEVEL)) {
670 theApp->ipfilter->Reload();
673 theApp->ResetTitle();
675 if (thePrefs::GetShowRatesOnTitle()) {
676 // This avoids a 5 seconds delay to show the title
677 theApp->amuledlg->ShowTransferRate();
678 } else {
679 // This resets the title
680 theApp->amuledlg->SetTitle(theApp->m_FrameTitle);
683 if (CfgChanged(IDC_EXTCATINFO)) {
684 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
687 // Changes related to the statistics-dlg
688 if (CfgChanged(IDC_SLIDER)) {
689 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
690 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
693 if ( CfgChanged(IDC_SLIDER3) ) {
694 theApp->amuledlg->m_statisticswnd->ResetAveragingTime();
697 if (CfgChanged(IDC_DOWNLOAD_CAP)) {
698 theApp->amuledlg->m_statisticswnd->SetARange( true, thePrefs::GetMaxGraphDownloadRate() );
701 if (CfgChanged(IDC_UPLOAD_CAP)) {
702 theApp->amuledlg->m_statisticswnd->SetARange( false, thePrefs::GetMaxGraphUploadRate() );
705 if (CfgChanged(IDC_SKIN)) {
706 theApp->amuledlg->Create_Toolbar(thePrefs::VerticalToolbar());
709 if (!thePrefs::GetNetworkED2K() && theApp->IsConnectedED2K()) {
710 theApp->DisconnectED2K();
713 if (!thePrefs::GetNetworkKademlia() && theApp->IsConnectedKad()) {
714 theApp->StopKad();
717 if (!thePrefs::GetNetworkED2K() && !thePrefs::GetNetworkKademlia()) {
718 wxMessageBox(
719 _("Both eD2k and Kad network are disabled.\nYou won't be able to connect until you enable at least one of them."));
722 if (thePrefs::GetNetworkKademlia() && thePrefs::IsUDPDisabled()) {
723 wxMessageBox(_("Kad will not start if your UDP port is disabled.\nEnable UDP port or disable Kad."),
724 _("Message"), wxOK | wxICON_INFORMATION, this);
727 if (CfgChanged(IDC_NETWORKKAD) || CfgChanged(IDC_NETWORKED2K)) {
728 theApp->amuledlg->DoNetworkRearrange();
731 if (CfgChanged(IDC_SHOW_COUNTRY_FLAGS)) {
732 theApp->amuledlg->EnableIP2Country();
735 if (restart_needed) {
736 wxMessageBox(restart_needed_msg + _("\nYou MUST restart aMule now.\nIf you do not restart now, don't complain if anything bad happens.\n"),
737 _("WARNING"), wxOK | wxICON_EXCLAMATION, this);
740 Show(false);
744 void PrefsUnifiedDlg::OnClose(wxCloseEvent& event)
746 Show(false);
748 // Try to keep the window alive when possible
749 if (event.CanVeto()) {
750 event.Veto();
751 } else {
752 if (theApp->amuledlg) {
753 theApp->amuledlg->m_prefsDialog = NULL;
756 // Un-Connect the Cfgs
757 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
758 for (; it != thePrefs::s_CfgList.end(); ++it) {
759 // Checking for failures
760 it->second->ConnectToWidget( 0 );
763 Destroy();
768 void PrefsUnifiedDlg::OnCancel(wxCommandEvent& WXUNUSED(event))
770 Show(false);
771 // restore state of server tab if necessary
772 EnableServerTab(thePrefs::GetNetworkED2K());
776 void PrefsUnifiedDlg::OnCheckBoxChange(wxCommandEvent& event)
778 bool value = event.IsChecked();
779 int id = event.GetId();
781 // Check if this checkbox is one of the User Events checkboxes
782 if (id >= USEREVENTS_FIRST_ID &&
783 id < USEREVENTS_FIRST_ID +
784 (int)CUserEvents::GetCount() * USEREVENTS_IDS_PER_EVENT) {
785 // The corresponding text control always has
786 // an ID one greater than the checkbox
787 FindWindow(id + 1)->Enable(value);
788 return;
791 switch ( id ) {
792 case IDC_UDPENABLE:
793 FindWindow( IDC_UDPPORT )->Enable(value);
794 break;
796 case IDC_UPNP_ENABLED:
797 FindWindow(IDC_UPNPTCPPORT)->Enable(value);
798 FindWindow(IDC_UPNPTCPPORTTEXT)->Enable(value);
799 break;
801 case IDC_UPNP_WEBSERVER_ENABLED:
802 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(value);
803 FindWindow(IDC_WEBUPNPTCPPORTTEXT)->Enable(value);
804 break;
806 case IDC_NETWORKKAD: {
807 wxCheckBox * udpPort = (wxCheckBox *) FindWindow(IDC_UDPENABLE);
808 if (value) {
809 // Kad enabled: disable check box, turn UDP on, enable port spin control
810 udpPort->Enable(false);
811 udpPort->SetValue(true);
812 FindWindow(IDC_UDPPORT)->Enable(true);
813 } else {
814 // Kad disabled: enable check box
815 udpPort->Enable(true);
817 break;
820 case IDC_CHECKDISKSPACE:
821 FindWindow( IDC_MINDISKSPACE )->Enable(value);
822 break;
824 case IDC_ONLINESIG:
825 FindWindow( IDC_OSDIR )->Enable(value);;
826 FindWindow(IDC_OSUPDATE)->Enable(value);
827 break;
829 case IDC_REMOVEDEAD:
830 FindWindow( IDC_SERVERRETRIES )->Enable(value);;
831 break;
833 case IDC_AUTOSERVER:
834 if ((CPath::GetFileSize(theApp->ConfigDir + wxT("addresses.dat")) == 0) &&
835 CastChild(event.GetId(), wxCheckBox)->IsChecked() ) {
836 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."),
837 _("Message"), wxOK | wxICON_INFORMATION);
838 CastChild(event.GetId(), wxCheckBox)->SetValue(false);
840 break;
842 case IDC_MSGFILTER:
843 // Toogle All filter options
844 FindWindow(IDC_MSGFILTER_ALL)->Enable(value);
845 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(value);
846 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(value);
847 FindWindow(IDC_MSGFILTER_WORD)->Enable(value);
848 if (value) {
849 FindWindow(IDC_MSGWORD)->Enable(
850 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
851 } else {
852 FindWindow(IDC_MSGWORD)->Enable(false);
854 break;
856 case IDC_MSGFILTER_ALL:
857 // Toogle filtering by data.
858 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(!value);
859 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(!value);
860 FindWindow(IDC_MSGFILTER_WORD)->Enable(!value);
861 if (!value) {
862 FindWindow(IDC_MSGWORD)->Enable(
863 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
864 } else {
865 FindWindow(IDC_MSGWORD)->Enable(false);
867 break;
869 case IDC_MSGFILTER_WORD:
870 // Toogle filter word list.
871 FindWindow(IDC_MSGWORD)->Enable(value);
872 break;
874 case IDC_FILTERCOMMENTS:
875 FindWindow(IDC_COMMENTWORD)->Enable(value);
876 break;
878 case ID_PROXY_ENABLE_PROXY:
879 FindWindow(ID_PROXY_TYPE)->Enable(value);
880 FindWindow(ID_PROXY_NAME)->Enable(value);
881 FindWindow(ID_PROXY_PORT)->Enable(value);
882 break;
884 case ID_PROXY_ENABLE_PASSWORD:
885 FindWindow(ID_PROXY_USER)->Enable(value);
886 FindWindow(ID_PROXY_PASSWORD)->Enable(value);
887 break;
889 case IDC_STARTNEXTFILE:
890 FindWindow(IDC_STARTNEXTFILE_SAME)->Enable(value);
891 FindWindow(IDC_STARTNEXTFILE_ALPHA)->Enable(value);
892 break;
893 #ifndef __WXMAC__
894 case IDC_ENABLETRAYICON:
895 FindWindow(IDC_MINTRAY)->Enable(value);
896 if (value) {
897 theApp->amuledlg->CreateSystray();
898 } else {
899 theApp->amuledlg->RemoveSystray();
901 thePrefs::SetUseTrayIcon(value);
902 break;
903 #endif
904 case ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY:
905 break;
907 case IDC_VERTTOOLBAR:
908 theApp->amuledlg->Create_Toolbar(value);
909 // Update the first tool (conn button)
910 theApp->amuledlg->ShowConnectionState();
911 theApp->amuledlg->Layout();
912 break;
914 case IDC_ENFORCE_PO_INCOMING:
915 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(!value);
916 break;
918 case IDC_ENABLE_PO_OUTGOING:
919 FindWindow(IDC_SUPPORT_PO)->Enable(!value);
920 FindWindow(IDC_ENFORCE_PO_INCOMING)->Enable(value);
921 break;
923 case IDC_SUPPORT_PO:
924 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(value);
925 break;
927 case IDC_SHOWRATEONTITLE:
928 FindWindow(IDC_RATESBEFORETITLE)->Enable(value);
929 FindWindow(IDC_RATESAFTERTITLE)->Enable(value);
930 break;
932 case IDC_NETWORKED2K: {
933 EnableServerTab(value);
934 wxSpinEvent e;
935 OnTCPClientPortChange(e);
936 break;
939 default:
940 break;
945 void PrefsUnifiedDlg::OnButtonColorChange(wxCommandEvent& WXUNUSED(event))
947 int index = m_choiceColor->GetSelection();
948 wxColour col = wxGetColourFromUser( this, CMuleColour(thePrefs::s_colors[index]) );
949 if ( col.Ok() ) {
950 m_buttonColor->SetBackgroundColour( col );
951 thePrefs::s_colors[index] = CMuleColour(col).GetULong();
956 void PrefsUnifiedDlg::OnColorCategorySelected(wxCommandEvent& WXUNUSED(evt))
958 m_buttonColor->SetBackgroundColour(CMuleColour(thePrefs::s_colors[ m_choiceColor->GetSelection() ] ) );
962 void PrefsUnifiedDlg::OnButtonDir(wxCommandEvent& event)
964 wxString type;
966 int id = 0;
967 switch ( event.GetId() ) {
968 case IDC_SELTEMPDIR:
969 id = IDC_TEMPFILES;
970 type = _("Temporary files");
971 break;
973 case IDC_SELINCDIR:
974 id = IDC_INCFILES;
975 type = _("Incoming files");
976 break;
978 case IDC_SELOSDIR:
979 id = IDC_OSDIR;
980 type = _("Online Signatures");
981 break;
983 // case IDC_SELSKIN:
984 // id = IDC_SKIN;
985 // type = _("Skins directory");
986 // break;
988 default:
989 wxFAIL;
990 return;
993 type = CFormat(_("Choose a folder for %s")) % type;
994 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
995 wxString dir = widget->GetValue();
996 wxString str = wxDirSelector(
997 type, dir,
998 wxDD_DEFAULT_STYLE,
999 wxDefaultPosition, this);
1000 if (!str.IsEmpty()) {
1001 widget->SetValue(str);
1006 void PrefsUnifiedDlg::OnButtonBrowseApplication(wxCommandEvent& event)
1008 wxString title;
1009 int id = 0;
1010 switch ( event.GetId() ) {
1011 case IDC_BROWSEV:
1012 id = IDC_VIDEOPLAYER;
1013 title = _("Browse for videoplayer");
1014 break;
1015 case IDC_SELBROWSER:
1016 id = IDC_BROWSERSELF;
1017 title = _("Select browser");
1018 break;
1019 default:
1020 wxFAIL;
1021 return;
1023 wxString wildcard = CFormat(_("Executable%s"))
1024 #ifdef __WXMSW__
1025 % wxT(" (*.exe)|*.exe");
1026 #else
1027 % wxT("|*");
1028 #endif
1030 wxString str = wxFileSelector( title, wxEmptyString, wxEmptyString,
1031 wxEmptyString, wildcard, 0, this );
1033 if ( !str.IsEmpty() ) {
1034 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
1035 widget->SetValue( str );
1040 void PrefsUnifiedDlg::OnButtonEditAddr(wxCommandEvent& WXUNUSED(evt))
1042 wxString fullpath( theApp->ConfigDir + wxT("addresses.dat") );
1044 EditServerListDlg* test = new EditServerListDlg(this, _("Edit server list"),
1045 _("Add here URL's to download server.met files.\nOnly one url on each line."),
1046 fullpath );
1048 test->ShowModal();
1049 delete test;
1053 void PrefsUnifiedDlg::OnButtonIPFilterReload(wxCommandEvent& WXUNUSED(event))
1055 theApp->ipfilter->Reload();
1059 void PrefsUnifiedDlg::OnButtonIPFilterUpdate(wxCommandEvent& WXUNUSED(event))
1061 theApp->ipfilter->Update( CastChild( IDC_IPFILTERURL, wxTextCtrl )->GetValue() );
1065 void PrefsUnifiedDlg::OnPrefsPageChange(wxListEvent& event)
1067 prefs_sizer->Detach( m_CurrentPanel );
1068 m_CurrentPanel->Show( false );
1070 m_CurrentPanel = (wxPanel *) m_PrefsIcons->GetItemData(event.GetIndex());
1071 if (pages[event.GetIndex()].m_function == PreferencesDirectoriesTab) {
1072 CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl)->Init();
1075 prefs_sizer->Add( m_CurrentPanel, 0, wxGROW|wxEXPAND );
1076 m_CurrentPanel->Show( true );
1078 Layout();
1080 event.Skip();
1084 void PrefsUnifiedDlg::OnToolTipDelayChange(wxSpinEvent& event)
1086 wxToolTip::SetDelay( event.GetPosition() * 1000 );
1090 void PrefsUnifiedDlg::OnInitDialog( wxInitDialogEvent& WXUNUSED(evt) )
1092 // This function exists solely to avoid automatic transfer-to-widget calls
1096 void PrefsUnifiedDlg::OnScrollBarChange( wxScrollEvent& event )
1098 int id = 0;
1099 wxString label;
1101 switch ( event.GetId() ) {
1102 case IDC_SLIDER:
1103 id = IDC_SLIDERINFO;
1104 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1105 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(event.GetPosition());
1106 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(event.GetPosition());
1107 break;
1109 case IDC_SLIDER3:
1110 id = IDC_SLIDERINFO3;
1111 label = CFormat(wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event.GetPosition())) % event.GetPosition();
1112 theApp->m_statistics->SetAverageMinutes(event.GetPosition());
1113 break;
1115 case IDC_SLIDER4:
1116 id = IDC_SLIDERINFO4;
1117 label = CFormat(_("Connections Graph Scale: %d")) % event.GetPosition();
1118 theApp->amuledlg->m_statisticswnd->GetConnScope()->SetRanges(0, event.GetPosition());
1119 break;
1121 case IDC_SLIDER2:
1122 id = IDC_SLIDERINFO2;
1123 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1124 break;
1126 case IDC_FILEBUFFERSIZE:
1127 id = IDC_FILEBUFFERSIZE_STATIC;
1128 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1129 label = CFormat(wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event.GetPosition() * 15000)) % (event.GetPosition() * 15000);
1130 break;
1132 case IDC_QUEUESIZE:
1133 id = IDC_QUEUESIZE_STATIC;
1134 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1135 label = CFormat(wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event.GetPosition() * 100)) % (event.GetPosition() * 100);
1136 break;
1138 case IDC_SERVERKEEPALIVE:
1139 id = IDC_SERVERKEEPALIVE_LABEL;
1141 if ( event.GetPosition() ) {
1142 label = CFormat(wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event.GetPosition())) % event.GetPosition();
1143 } else {
1144 label = _("Server connection refresh interval: Disabled");
1146 break;
1148 default:
1149 return;
1152 wxStaticText* widget = CastChild( id, wxStaticText );
1154 if (widget) {
1155 widget->SetLabel( label );
1156 widget->GetParent()->Layout();
1161 void PrefsUnifiedDlg::OnRateLimitChanged( wxSpinEvent& event )
1163 // Here we do immediate sanity checking of the up/down ratio,
1164 // so that the user can see if his choice is illegal
1166 // We only do checks if the rate is limited
1167 if ( event.GetPosition() != (int)UNLIMITED ) {
1168 wxSpinCtrl* dlrate = CastChild( IDC_MAXDOWN, wxSpinCtrl );
1170 if ( event.GetPosition() < 4 ) {
1171 if ( ( event.GetPosition() * 3 < dlrate->GetValue() ) ||
1172 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1173 dlrate->SetValue( event.GetPosition() * 3 );
1175 } else if ( event.GetPosition() < 10 ) {
1176 if ( ( event.GetPosition() * 4 < dlrate->GetValue() ) ||
1177 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1178 dlrate->SetValue( event.GetPosition() * 4 );
1185 void PrefsUnifiedDlg::OnTCPClientPortChange(wxSpinEvent& WXUNUSED(event))
1187 CastChild(ID_TEXT_CLIENT_UDP_PORT, wxStaticText)->SetLabel(
1188 m_ServerTabVisible ? (wxString() << (CastChild(IDC_PORT, wxSpinCtrl)->GetValue() + 3))
1189 : wxString(_("disabled")));
1192 void PrefsUnifiedDlg::OnUserEventSelected(wxListEvent& event)
1194 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1195 IDC_PREFS_EVENTS_PAGE->Hide(i+1);
1198 IDC_PREFS_EVENTS_PAGE->Show((event.GetData() - USEREVENTS_FIRST_ID) / USEREVENTS_IDS_PER_EVENT + 1, true);
1200 IDC_PREFS_EVENTS_PAGE->Layout();
1202 event.Skip();
1205 void PrefsUnifiedDlg::OnLanguageChoice(wxCommandEvent &evt)
1207 thePrefs::GetCfgLang()->UpdateChoice(evt.GetSelection());
1210 void PrefsUnifiedDlg::CreateEventPanels(const int idx, const wxString& vars, wxWindow* parent)
1212 wxStaticBox *item8 = new wxStaticBox( parent, -1, CFormat(_("Execute command on '%s' event")) % wxGetTranslation(CUserEvents::GetDisplayName(static_cast<enum CUserEvents::EventType>(idx))) );
1213 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxVERTICAL );
1215 wxCheckBox *item9 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 1, _("Enable command execution on core"), wxDefaultPosition, wxDefaultSize, 0 );
1216 item7->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1218 wxFlexGridSizer *item10 = new wxFlexGridSizer( 3, 0, 0 );
1219 item10->AddGrowableCol( 2 );
1221 item10->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1223 wxStaticText *item11 = new wxStaticText( parent, -1, _("Core command:"), wxDefaultPosition, wxDefaultSize, 0 );
1224 item10->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
1226 wxTextCtrl *item12 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 2, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1227 item12->Enable(CUserEvents::IsCoreCommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1228 item10->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1230 item7->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1232 wxCheckBox *item14 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 3, _("Enable command execution on GUI"), wxDefaultPosition, wxDefaultSize, 0 );
1233 item7->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1235 wxFlexGridSizer *item15 = new wxFlexGridSizer( 3, 0, 0 );
1236 item15->AddGrowableCol( 2 );
1238 item15->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1240 wxStaticText *item16 = new wxStaticText( parent, -1, _("GUI command:"), wxDefaultPosition, wxDefaultSize, 0 );
1241 item15->Add( item16, 0, wxALIGN_CENTER|wxALL, 5 );
1243 wxTextCtrl *item17 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 4, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1244 item17->Enable(CUserEvents::IsGUICommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1245 item15->Add( item17, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1247 item7->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1249 wxStaticText *item13 = new wxStaticText( parent, -1, _("The following variables will be replaced:") + vars, wxDefaultPosition, wxDefaultSize, 0 );
1250 item7->Add( item13, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1252 IDC_PREFS_EVENTS_PAGE->Add(item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
1254 IDC_PREFS_EVENTS_PAGE->Layout();
1255 IDC_PREFS_EVENTS_PAGE->Hide(idx + 1);
1257 // File_checked_for_headers