Fix the equality operator
[amule.git] / src / PrefsUnifiedDlg.cpp
blobb81d74c5d708166994ff93c48e541162b0387144
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>
30 #include <common/Macros.h> // Needed for itemsof()
32 #include <wx/colordlg.h>
33 #include <wx/tooltip.h>
35 #include "amule.h" // Needed for theApp
36 #include "amuleDlg.h"
37 #include "MuleColour.h"
38 #include "EditServerListDlg.h"
39 #include "SharedFileList.h" // Needed for CSharedFileList
40 #include "StatisticsDlg.h" // Needed for graph parameters, colors
41 #include "IPFilter.h" // Needed for CIPFilter
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" // Needed for PLATFORMSPECIFIC_CAN_PREVENT_SLEEP_MODE
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_MACHIDEONCLOSE, PrefsUnifiedDlg::OnCheckBoxChange)
86 EVT_CHECKBOX(IDC_VERTTOOLBAR, PrefsUnifiedDlg::OnCheckBoxChange)
87 EVT_CHECKBOX(IDC_SUPPORT_PO, PrefsUnifiedDlg::OnCheckBoxChange)
88 EVT_CHECKBOX(IDC_ENABLE_PO_OUTGOING, PrefsUnifiedDlg::OnCheckBoxChange)
89 EVT_CHECKBOX(IDC_ENFORCE_PO_INCOMING, PrefsUnifiedDlg::OnCheckBoxChange)
90 EVT_CHECKBOX(IDC_SHOWRATEONTITLE, PrefsUnifiedDlg::OnCheckBoxChange)
91 EVT_CHECKBOX(IDC_NETWORKED2K, PrefsUnifiedDlg::OnCheckBoxChange)
92 EVT_CHECKBOX(IDC_NETWORKKAD, PrefsUnifiedDlg::OnCheckBoxChange)
93 EVT_CHECKBOX(IDC_UPNP_ENABLED, PrefsUnifiedDlg::OnCheckBoxChange)
94 EVT_CHECKBOX(IDC_UPNP_WEBSERVER_ENABLED,PrefsUnifiedDlg::OnCheckBoxChange)
97 EVT_BUTTON(ID_PREFS_OK_TOP, PrefsUnifiedDlg::OnOk)
98 EVT_BUTTON(ID_PREFS_CANCEL_TOP, PrefsUnifiedDlg::OnCancel)
100 // Browse buttons
101 // EVT_BUTTON(IDC_SELSKIN, PrefsUnifiedDlg::OnButtonDir)
102 EVT_BUTTON(IDC_BROWSEV, PrefsUnifiedDlg::OnButtonBrowseApplication)
103 EVT_BUTTON(IDC_SELTEMPDIR, PrefsUnifiedDlg::OnButtonDir)
104 EVT_BUTTON(IDC_SELINCDIR, PrefsUnifiedDlg::OnButtonDir)
105 EVT_BUTTON(IDC_SELOSDIR, PrefsUnifiedDlg::OnButtonDir)
106 EVT_BUTTON(IDC_SELBROWSER, PrefsUnifiedDlg::OnButtonBrowseApplication)
108 EVT_SPINCTRL(IDC_TOOLTIPDELAY, PrefsUnifiedDlg::OnToolTipDelayChange)
110 EVT_BUTTON(IDC_EDITADR, PrefsUnifiedDlg::OnButtonEditAddr)
111 EVT_BUTTON(IDC_IPFRELOAD, PrefsUnifiedDlg::OnButtonIPFilterReload)
112 EVT_BUTTON(IDC_COLOR_BUTTON, PrefsUnifiedDlg::OnButtonColorChange)
113 EVT_BUTTON(IDC_IPFILTERUPDATE, PrefsUnifiedDlg::OnButtonIPFilterUpdate)
114 EVT_CHOICE(IDC_COLORSELECTOR, PrefsUnifiedDlg::OnColorCategorySelected)
115 EVT_LIST_ITEM_SELECTED(ID_PREFSLISTCTRL,PrefsUnifiedDlg::OnPrefsPageChange)
117 EVT_INIT_DIALOG(PrefsUnifiedDlg::OnInitDialog)
119 EVT_COMMAND_SCROLL(IDC_SLIDER, PrefsUnifiedDlg::OnScrollBarChange)
120 EVT_COMMAND_SCROLL(IDC_SLIDER3, PrefsUnifiedDlg::OnScrollBarChange)
121 EVT_COMMAND_SCROLL(IDC_SLIDER4, PrefsUnifiedDlg::OnScrollBarChange)
122 EVT_COMMAND_SCROLL(IDC_SLIDER2, PrefsUnifiedDlg::OnScrollBarChange)
123 EVT_COMMAND_SCROLL(IDC_FILEBUFFERSIZE, PrefsUnifiedDlg::OnScrollBarChange)
124 EVT_COMMAND_SCROLL(IDC_QUEUESIZE, PrefsUnifiedDlg::OnScrollBarChange)
125 EVT_COMMAND_SCROLL(IDC_SERVERKEEPALIVE, PrefsUnifiedDlg::OnScrollBarChange)
127 EVT_SPINCTRL(IDC_MAXUP, PrefsUnifiedDlg::OnRateLimitChanged)
129 EVT_LIST_ITEM_SELECTED(IDC_EVENTLIST, PrefsUnifiedDlg::OnUserEventSelected)
131 EVT_CHOICE(IDC_LANGUAGE, PrefsUnifiedDlg::OnLanguageChoice)
133 EVT_CLOSE(PrefsUnifiedDlg::OnClose)
135 END_EVENT_TABLE()
139 * Creates an command-event for the given checkbox.
141 * This can be used enforce logical constraints by passing by
142 * sending a check-box event for each checkbox, when transfering
143 * to the UI. However, it should also be used for checkboxes that
144 * have no side-effects other than enabling/disabling other
145 * widgets in the preferences dialogs.
147 void SendCheckBoxEvent(wxWindow* parent, int id)
149 wxCheckBox* widget = CastByID(id, parent, wxCheckBox);
150 wxCHECK_RET(widget, wxT("Invalid widget in CreateEvent"));
152 wxCommandEvent evt(wxEVT_COMMAND_CHECKBOX_CLICKED, id);
153 evt.SetInt(widget->IsChecked() ? 1 : 0);
155 parent->GetEventHandler()->ProcessEvent(evt);
161 * This struct provides a general way to represent config-tabs.
163 struct PrefsPage
165 //! The title of the page, used on the listctrl.
166 wxString m_title;
167 //! Function pointer to the wxDesigner function creating the dialog.
168 wxSizer* (*m_function)(wxWindow*, bool, bool );
169 //! The index of the image used on the list.
170 int m_imageidx;
174 PrefsPage pages[] =
176 { wxTRANSLATE("General"), PreferencesGeneralTab, 13 },
177 { wxTRANSLATE("Connection"), PreferencesConnectionTab, 14 },
178 { wxTRANSLATE("Directories"), PreferencesDirectoriesTab, 17 },
179 { wxTRANSLATE("Servers"), PreferencesServerTab, 15 },
180 { wxTRANSLATE("Files"), PreferencesFilesTab, 16 },
181 { wxTRANSLATE("Security"), PreferencesSecurityTab, 22 },
182 { wxTRANSLATE("Interface"), PreferencesGuiTweaksTab, 19 },
183 { wxTRANSLATE("Statistics"), PreferencesStatisticsTab, 10 },
184 { wxTRANSLATE("Proxy"), PreferencesProxyTab, 24 },
185 { wxTRANSLATE("Filters"), PreferencesFilteringTab, 23 },
186 { wxTRANSLATE("Remote Controls"), PreferencesRemoteControlsTab, 11 },
187 { wxTRANSLATE("Online Signature"), PreferencesOnlineSigTab, 21 },
188 { wxTRANSLATE("Advanced"), PreferencesaMuleTweaksTab, 12 },
189 { wxTRANSLATE("Events"), PreferencesEventsTab, 5 }
190 #ifdef __DEBUG__
191 ,{ wxTRANSLATE("Debugging"), PreferencesDebug, 25 }
192 #endif
196 PrefsUnifiedDlg::PrefsUnifiedDlg(wxWindow *parent)
198 wxDialog(parent, -1, _("Preferences"),
199 wxDefaultPosition, wxDefaultSize,
200 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
202 preferencesDlgTop(this, false);
204 m_PrefsIcons = CastChild(ID_PREFSLISTCTRL, wxListCtrl);
205 wxImageList *icon_list = new wxImageList(16, 16);
206 m_PrefsIcons->AssignImageList(icon_list, wxIMAGE_LIST_SMALL);
208 // Add the single column used
209 m_PrefsIcons->InsertColumn(
210 0, wxEmptyString, wxLIST_FORMAT_LEFT,
211 m_PrefsIcons->GetSize().GetWidth()-5);
213 // Temp variables for finding the smallest height and width needed
214 int width = 0;
215 int height = 0;
217 // Add each page to the page-list
218 for (unsigned int i = 0; i < itemsof(pages); ++i) {
219 // Add the icon and label associated with the page
220 icon_list->Add(amuleSpecial(pages[i].m_imageidx));
221 m_PrefsIcons->InsertItem(i, wxGetTranslation(pages[i].m_title), i);
224 // Set list-width so that there aren't any scrollers
225 m_PrefsIcons->SetColumnWidth(0, wxLIST_AUTOSIZE);
226 m_PrefsIcons->SetMinSize(wxSize(m_PrefsIcons->GetColumnWidth(0) + 10, -1));
227 m_PrefsIcons->SetMaxSize(wxSize(m_PrefsIcons->GetColumnWidth(0) + 10, -1));
229 // Now add the pages and calculate the minimum size
230 wxPanel * DefaultWidget = NULL;
231 for (unsigned int i = 0; i < itemsof(pages); ++i) {
232 // Create a container widget and the contents of the page
233 wxPanel * Widget = new wxPanel(this, -1);
234 // Widget is stored as user data in the list control
235 m_PrefsIcons->SetItemPtrData(i, (wxUIntPtr) Widget);
236 pages[i].m_function(Widget, true, true);
237 if (i == 0) {
238 DefaultWidget = Widget;
241 // Add it to the sizer
242 prefs_sizer->Add(Widget, 0, wxGROW|wxEXPAND);
244 if (pages[i].m_function == PreferencesGeneralTab) {
245 // This must be done now or pages won't Fit();
246 #ifdef __WINDOWS__
247 CastChild(IDC_BROWSERTABS, wxCheckBox)->Enable(false);
248 #endif /* __WINDOWS__ */
249 CastChild(IDC_PREVIEW_NOTE, wxStaticText)->SetLabel(_("The following variables will be substituted:\n %PARTFILE - full path to the file\n %PARTNAME - file name only"));
250 #ifdef __WXMAC__
251 FindWindow(IDC_ENABLETRAYICON)->Show(false);
252 FindWindow(IDC_MINTRAY)->Show(false);
253 #else
254 FindWindow(IDC_MACHIDEONCLOSE)->Show(false);
255 thePrefs::SetHideOnClose(false);
256 #endif
257 } else if (pages[i].m_function == PreferencesEventsTab) {
259 #define USEREVENTS_REPLACE_VAR(VAR, DESC, CODE) + wxString(wxT("\n %") VAR wxT(" - ")) + wxGetTranslation(DESC)
260 #define USEREVENTS_EVENT(ID, NAME, VARS) case CUserEvents::ID: CreateEventPanels(idx, wxEmptyString VARS, Widget); break;
262 wxListCtrl *list = CastChild(IDC_EVENTLIST, wxListCtrl);
263 list->InsertColumn(0, wxEmptyString);
264 for (unsigned int idx = 0; idx < CUserEvents::GetCount(); ++idx) {
265 long lidx = list->InsertItem(idx,
266 wxGetTranslation(CUserEvents::GetDisplayName(
267 static_cast<enum CUserEvents::EventType>(idx))));
268 if (lidx != -1) {
269 list->SetItemData(lidx,
270 USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT);
271 switch (idx) {
272 USEREVENTS_EVENTLIST()
273 /* This macro expands to handle all user event types. Here is an example:
274 case CUserEvents::NewChatSession: {
275 CreateEventPanels(idx, wxString(wxT("\n %SENDER - ")) + wxTRANSLATE("Message sender."), Widget);
276 break;
277 } */
281 list->SetColumnWidth(0, wxLIST_AUTOSIZE);
283 else if (pages[i].m_function == PreferencesServerTab) {
284 m_IndexServerTab = i;
285 m_ServerWidget = Widget;
287 else if (pages[i].m_function == PreferencesaMuleTweaksTab) {
288 wxStaticText *txt = CastChild(IDC_AMULE_TWEAKS_WARNING, wxStaticText);
289 // Do not wrap this line, Windows _() can't handle wrapped strings
290 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."));
291 #if defined CLIENT_GUI || !PLATFORMSPECIFIC_CAN_PREVENT_SLEEP_MODE
292 CastChild(IDC_PREVENT_SLEEP, wxCheckBox)->Enable(false);
293 thePrefs::SetPreventSleepWhileDownloading(false);
294 #endif
296 #ifdef __DEBUG__
297 else if (pages[i].m_function == PreferencesDebug) {
298 int count = theLogger.GetDebugCategoryCount();
299 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
301 for ( int j = 0; j < count; j++ ) {
302 list->Append( theLogger.GetDebugCategory( j ).GetName() );
305 #endif
307 // Align and resize the page
308 Fit();
309 Layout();
311 // Find the greatest sizes
312 wxSize size = prefs_sizer->GetSize();
313 if (size.GetWidth() > width) {
314 width = size.GetWidth();
317 if (size.GetHeight() > height) {
318 height = size.GetHeight();
321 // Hide it for now
322 prefs_sizer->Detach(Widget);
323 Widget->Show(false);
326 // Default to the General tab
327 m_CurrentPanel = DefaultWidget;
328 prefs_sizer->Add(DefaultWidget, 0, wxGROW|wxEXPAND);
329 m_CurrentPanel->Show( true );
331 // Select the first item
332 m_PrefsIcons->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
334 // We now have the needed minimum height and width
335 prefs_sizer->SetMinSize(width, height);
337 // Don't show server prefs if ED2K is disabled
338 m_ServerTabVisible = true;
339 EnableServerTab(thePrefs::GetNetworkED2K());
341 // Store some often used pointers
342 m_ShareSelector = CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl);
343 m_buttonColor = CastChild(IDC_COLOR_BUTTON, wxButton);
344 m_choiceColor = CastChild(IDC_COLORSELECTOR, wxChoice);
346 // Connect the Cfgs with their widgets
347 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
348 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
349 // Checking for failures
350 if ( !it->second->ConnectToWidget(it->first, this) ) {
351 AddLogLineNS(CFormat(_("Failed to connect Cfg to widget with the ID %d and key %s"))
352 % it->first % it->second->GetKey());
355 Fit();
357 // It must not be resized to something smaller than what it currently is
358 wxSize size = GetClientSize();
359 SetSizeHints(size.GetWidth(), size.GetHeight());
361 // Position the dialog.
362 Center();
366 void PrefsUnifiedDlg::EnableServerTab(bool enable)
368 if (enable && !m_ServerTabVisible) {
369 // turn server widget on
370 m_PrefsIcons->InsertItem(m_IndexServerTab, wxGetTranslation(pages[m_IndexServerTab].m_title), m_IndexServerTab);
371 m_PrefsIcons->SetItemPtrData(m_IndexServerTab, (wxUIntPtr) m_ServerWidget);
372 m_ServerTabVisible = true;
373 } else if (!enable && m_ServerTabVisible) {
374 // turn server widget off
375 m_PrefsIcons->DeleteItem(m_IndexServerTab);
376 m_ServerTabVisible = false;
381 Cfg_Base* PrefsUnifiedDlg::GetCfg(int id)
383 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.find( id );
385 if ( it != thePrefs::s_CfgList.end() ) {
386 return it->second;
389 return NULL;
393 bool PrefsUnifiedDlg::TransferToWindow()
395 // Connect the Cfgs with their widgets
396 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
397 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
398 // Checking for failures
399 if ( !it->second->TransferToWindow() ) {
400 AddLogLineNS(CFormat(_("Failed to transfer data from Cfg to Widget with the ID %d and key %s"))
401 % it->first % it->second->GetKey());
405 m_ShareSelector->SetSharedDirectories(&theApp->glob_prefs->shareddir_list);
407 for ( int i = 0; i < cntStatColors; i++ ) {
408 thePrefs::s_colors[i] = CMuleColour(CStatisticsDlg::acrStat[i]).GetULong();
409 thePrefs::s_colors_ref[i] = CMuleColour(CStatisticsDlg::acrStat[i]).GetULong();
412 // Connection tab
413 wxSpinEvent e;
414 OnTCPClientPortChange(e);
416 // Proxy tab initialization
417 FindWindow(ID_PROXY_TYPE)->SetToolTip(_("The type of proxy you are connecting to"));
418 if (!CastChild(ID_PROXY_ENABLE_PROXY, wxCheckBox)->IsChecked()) {
419 FindWindow(ID_PROXY_TYPE)->Enable(false);
420 FindWindow(ID_PROXY_NAME)->Enable(false);
421 FindWindow(ID_PROXY_PORT)->Enable(false);
423 if (!CastChild(ID_PROXY_ENABLE_PASSWORD, wxCheckBox)->IsChecked()) {
424 FindWindow(ID_PROXY_USER)->Enable(false);
425 FindWindow(ID_PROXY_PASSWORD)->Enable(false);
427 // This option from the proxy tab is currently unused
428 FindWindow(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY)->Enable(false);
430 // Enable/Disable some controls
431 FindWindow( IDC_MINDISKSPACE )->Enable( thePrefs::IsCheckDiskspaceEnabled() );
432 FindWindow( IDC_OSDIR )->Enable( thePrefs::IsOnlineSignatureEnabled() );
433 FindWindow( IDC_OSUPDATE )->Enable( thePrefs::IsOnlineSignatureEnabled() );
434 FindWindow( IDC_UDPENABLE )->Enable( !thePrefs::GetNetworkKademlia());
435 FindWindow( IDC_UDPPORT )->Enable( thePrefs::s_UDPEnable );
436 FindWindow( IDC_SERVERRETRIES )->Enable( thePrefs::DeadServer() );
437 FindWindow( IDC_STARTNEXTFILE_SAME )->Enable(thePrefs::StartNextFile());
438 FindWindow( IDC_STARTNEXTFILE_ALPHA )->Enable(thePrefs::StartNextFile());
440 FindWindow(IDC_MACHIDEONCLOSE)->Enable(true);
441 FindWindow(IDC_EXIT)->Enable(!thePrefs::HideOnClose());
442 if (thePrefs::HideOnClose()) {
443 CastChild(IDC_EXIT, wxCheckBox)->SetValue(false);
446 FindWindow(IDC_MINTRAY)->Enable(thePrefs::UseTrayIcon());
448 if (!CastChild(IDC_MSGFILTER, wxCheckBox)->IsChecked()) {
449 FindWindow(IDC_MSGFILTER_ALL)->Enable(false);
450 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(false);
451 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(false);
452 FindWindow(IDC_MSGFILTER_WORD)->Enable(false);
453 FindWindow(IDC_MSGWORD)->Enable(false);
454 } else if (CastChild(IDC_MSGFILTER_ALL, wxCheckBox)->IsChecked()) {
455 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(false);
456 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(false);
457 FindWindow(IDC_MSGFILTER_WORD)->Enable(false);
458 FindWindow(IDC_MSGWORD)->Enable(false);
461 FindWindow(IDC_MSGWORD)->Enable(CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
462 FindWindow(IDC_COMMENTWORD)->Enable(CastChild(IDC_FILTERCOMMENTS, wxCheckBox)->IsChecked());
464 #ifdef CLIENT_GUI
465 // Disable dirpickers unless it's a localhost connection
466 if (!theApp->m_connect->IsConnectedToLocalHost()) {
467 FindWindow(IDC_SELINCDIR)->Enable(false);
468 FindWindow(IDC_SELTEMPDIR)->Enable(false);
470 #endif
472 // Protocol obfuscation
473 ::SendCheckBoxEvent(this, IDC_SUPPORT_PO);
474 ::SendCheckBoxEvent(this, IDC_ENABLE_PO_OUTGOING);
475 ::SendCheckBoxEvent(this, IDC_ENFORCE_PO_INCOMING);
477 #ifndef ENABLE_IP2COUNTRY
478 CastChild(IDC_SHOW_COUNTRY_FLAGS, wxCheckBox)->Enable(false);
479 thePrefs::SetGeoIPEnabled(false);
480 #endif
482 #ifdef __SVN__
483 // Version is always shown on the title in development versions
484 CastChild(IDC_SHOWVERSIONONTITLE, wxCheckBox)->SetValue(true);
485 CastChild(IDC_SHOWVERSIONONTITLE, wxCheckBox)->Enable(false);
486 #endif
488 // Show rates on title
489 FindWindow(IDC_RATESBEFORETITLE)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
490 FindWindow(IDC_RATESAFTERTITLE)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
491 CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->SetValue(thePrefs::GetShowRatesOnTitle() != 0);
492 CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->SetValue(thePrefs::GetShowRatesOnTitle() == 2);
493 CastChild(IDC_RATESAFTERTITLE, wxRadioButton)->SetValue(thePrefs::GetShowRatesOnTitle() != 2);
495 // UPNP
496 #ifndef ENABLE_UPNP
497 FindWindow(IDC_UPNP_ENABLED)->Enable(false);
498 FindWindow(IDC_UPNPTCPPORT)->Enable(false);
499 FindWindow(IDC_UPNPTCPPORTTEXT)->Enable(false);
500 thePrefs::SetUPnPEnabled(false);
501 FindWindow(IDC_UPNP_WEBSERVER_ENABLED)->Enable(false);
502 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(false);
503 FindWindow(IDC_WEBUPNPTCPPORTTEXT)->Enable(false);
504 thePrefs::SetUPnPWebServerEnabled(false);
505 FindWindow(IDC_UPNP_EC_ENABLED)->Enable(false);
506 thePrefs::SetUPnPECEnabled(false);
507 #else
508 FindWindow(IDC_UPNPTCPPORT)->Enable(thePrefs::GetUPnPEnabled());
509 FindWindow(IDC_UPNPTCPPORTTEXT)->Enable(thePrefs::GetUPnPEnabled());
510 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(thePrefs::GetUPnPWebServerEnabled());
511 FindWindow(IDC_WEBUPNPTCPPORTTEXT)->Enable(thePrefs::GetUPnPWebServerEnabled());
512 #endif
514 #ifdef __DEBUG__
515 // Set debugging toggles
516 int count = theLogger.GetDebugCategoryCount();
517 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
519 for ( int i = 0; i < count; i++ ) {
520 list->Check( i, theLogger.GetDebugCategory( i ).IsEnabled() );
522 #endif
524 return true;
528 bool PrefsUnifiedDlg::TransferFromWindow()
530 // Connect the Cfgs with their widgets
531 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
532 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
533 // Checking for failures
534 if ( !it->second->TransferFromWindow() ) {
535 AddLogLineNS(CFormat(_("Failed to transfer data from Widget to Cfg with the ID %d and key %s"))
536 % it->first % it->second->GetKey());
540 theApp->glob_prefs->shareddir_list.clear();
541 m_ShareSelector->GetSharedDirectories(&theApp->glob_prefs->shareddir_list);
543 for ( int i = 0; i < cntStatColors; i++ ) {
544 if ( thePrefs::s_colors[i] != thePrefs::s_colors_ref[i] ) {
545 CStatisticsDlg::acrStat[i] = thePrefs::s_colors[i];
546 theApp->amuledlg->m_statisticswnd->ApplyStatsColor(i);
549 theApp->amuledlg->m_kademliawnd->SetGraphColors();
552 #ifdef __DEBUG__
553 // Get debugging toggles
554 int count = theLogger.GetDebugCategoryCount();
555 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
557 for ( int i = 0; i < count; i++ ) {
558 theLogger.SetEnabled( theLogger.GetDebugCategory( i ).GetType(), list->IsChecked( i ) );
560 #endif
562 thePrefs::SetShowRatesOnTitle(CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->GetValue() ? (CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->GetValue() ? 2 : 1) : 0);
564 #ifdef CLIENT_GUI
565 // Send preferences to core.
566 theApp->glob_prefs->SendToRemote();
567 #endif
569 return true;
573 bool PrefsUnifiedDlg::CfgChanged(int ID)
575 Cfg_Base* cfg = GetCfg(ID);
577 if ( cfg ) {
578 return cfg->HasChanged();
581 return false;
585 void PrefsUnifiedDlg::OnOk(wxCommandEvent& WXUNUSED(event))
587 TransferFromWindow();
589 bool restart_needed = false;
590 wxString restart_needed_msg = _("aMule must be restarted to enable these changes:\n\n");
592 // do sanity checking, special processing, and user notifications here
593 thePrefs::CheckUlDlRatio();
595 if (CfgChanged(IDC_PORT)) {
596 restart_needed = true;
597 restart_needed_msg += _("- TCP port changed.\n");
600 if (CfgChanged(IDC_UDPPORT)) {
601 restart_needed = true;
602 restart_needed_msg += _("- UDP port changed.\n");
605 if (CfgChanged(IDC_EXT_CONN_TCP_PORT)) {
606 restart_needed = true;
607 restart_needed_msg += _("- External connect port changed.\n");
609 if (CfgChanged(IDC_EXT_CONN_ACCEPT)) {
610 restart_needed = true;
611 restart_needed_msg += _("- External connect acceptance changed.\n");
613 if (CfgChanged(IDC_EXT_CONN_IP)) {
614 restart_needed = true;
615 restart_needed_msg += _("- External connect interface changed.\n");
617 if (CfgChanged(IDC_SUPPORT_PO)) {
618 restart_needed = true;
619 restart_needed_msg += _("- Protocol obfuscation support changed.\n");
622 // Force port checking
623 thePrefs::SetPort(thePrefs::GetPort());
625 if ((CPath::GetFileSize(thePrefs::GetConfigDir() + wxT("addresses.dat")) == 0) &&
626 CastChild(IDC_AUTOSERVER, wxCheckBox)->IsChecked() ) {
627 thePrefs::UnsetAutoServerStart();
628 wxMessageBox(_("Your Auto-update server list is empty.\n'Auto-update server list at startup' will be disabled."),
629 _("Message"), wxOK | wxICON_INFORMATION, this);
632 if (thePrefs::AcceptExternalConnections() && thePrefs::ECPassword().IsEmpty()) {
633 thePrefs::EnableExternalConnections( false );
635 wxMessageBox( _("You have enabled external connections but have not specified a password.\nExternal connections cannot be enabled unless a valid password is specified."));
638 // save the preferences on ok
639 theApp->glob_prefs->Save();
641 if (CfgChanged(IDC_FED2KLH) && theApp->amuledlg->GetActiveDialog() != CamuleDlg::DT_SEARCH_WND) {
642 theApp->amuledlg->ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
645 if (CfgChanged(IDC_LANGUAGE)) {
646 restart_needed = true;
647 restart_needed_msg += _("- Language changed.\n");
650 if (CfgChanged(IDC_TEMPFILES)) {
651 restart_needed = true;
652 restart_needed_msg += _("- Temp folder changed.\n");
655 if (CfgChanged(IDC_NETWORKED2K) && thePrefs::GetNetworkED2K()) {
656 restart_needed = true;
657 restart_needed_msg += _("- ED2K network enabled.\n");
660 if (CfgChanged(IDC_INCFILES) || CfgChanged(IDC_TEMPFILES) || m_ShareSelector->HasChanged ) {
661 theApp->sharedfiles->Reload();
664 if (CfgChanged(IDC_OSDIR) || CfgChanged(IDC_ONLINESIG)) {
665 wxTextCtrl* widget = CastChild( IDC_OSDIR, wxTextCtrl );
667 // Build the filenames for the two OS files
668 theApp->SetOSFiles( widget->GetValue() );
671 if (CfgChanged(IDC_IPFCLIENTS) && thePrefs::IsFilteringClients()) {
672 theApp->clientlist->FilterQueues();
675 if (CfgChanged(IDC_IPFSERVERS) && thePrefs::IsFilteringServers()) {
676 theApp->serverlist->FilterServers();
679 if (CfgChanged(ID_IPFILTERLEVEL)) {
680 theApp->ipfilter->Reload();
683 theApp->ResetTitle();
685 if (thePrefs::GetShowRatesOnTitle()) {
686 // This avoids a 5 seconds delay to show the title
687 theApp->amuledlg->ShowTransferRate();
688 } else {
689 // This resets the title
690 theApp->amuledlg->SetTitle(theApp->m_FrameTitle);
693 if (CfgChanged(IDC_EXTCATINFO)) {
694 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
697 // Changes related to the statistics-dlg
698 if (CfgChanged(IDC_SLIDER)) {
699 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
700 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
703 if ( CfgChanged(IDC_SLIDER3) ) {
704 theApp->amuledlg->m_statisticswnd->ResetAveragingTime();
707 if (CfgChanged(IDC_DOWNLOAD_CAP)) {
708 theApp->amuledlg->m_statisticswnd->SetARange( true, thePrefs::GetMaxGraphDownloadRate() );
711 if (CfgChanged(IDC_UPLOAD_CAP)) {
712 theApp->amuledlg->m_statisticswnd->SetARange( false, thePrefs::GetMaxGraphUploadRate() );
715 if (CfgChanged(IDC_SKIN)) {
716 theApp->amuledlg->Create_Toolbar(thePrefs::VerticalToolbar());
719 if (!thePrefs::GetNetworkED2K() && theApp->IsConnectedED2K()) {
720 theApp->DisconnectED2K();
723 if (!thePrefs::GetNetworkKademlia() && theApp->IsConnectedKad()) {
724 theApp->StopKad();
727 if (!thePrefs::GetNetworkED2K() && !thePrefs::GetNetworkKademlia()) {
728 wxMessageBox(
729 _("Both eD2k and Kad network are disabled.\nYou won't be able to connect until you enable at least one of them."));
732 if (thePrefs::GetNetworkKademlia() && thePrefs::IsUDPDisabled()) {
733 wxMessageBox(_("Kad will not start if your UDP port is disabled.\nEnable UDP port or disable Kad."),
734 _("Message"), wxOK | wxICON_INFORMATION, this);
737 if (CfgChanged(IDC_NETWORKKAD) || CfgChanged(IDC_NETWORKED2K)) {
738 theApp->amuledlg->DoNetworkRearrange();
741 if (CfgChanged(IDC_SHOW_COUNTRY_FLAGS)) {
742 theApp->amuledlg->EnableIP2Country();
745 if (restart_needed) {
746 wxMessageBox(restart_needed_msg + _("\nYou MUST restart aMule now.\nIf you do not restart now, don't complain if anything bad happens.\n"),
747 _("WARNING"), wxOK | wxICON_EXCLAMATION, this);
750 Show(false);
754 void PrefsUnifiedDlg::OnClose(wxCloseEvent& event)
756 Show(false);
758 // Try to keep the window alive when possible
759 if (event.CanVeto()) {
760 event.Veto();
761 } else {
762 if (theApp->amuledlg) {
763 theApp->amuledlg->m_prefsDialog = NULL;
766 // Un-Connect the Cfgs
767 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
768 for (; it != thePrefs::s_CfgList.end(); ++it) {
769 // Checking for failures
770 it->second->ConnectToWidget( 0 );
773 Destroy();
778 void PrefsUnifiedDlg::OnCancel(wxCommandEvent& WXUNUSED(event))
780 Show(false);
781 // restore state of server tab if necessary
782 EnableServerTab(thePrefs::GetNetworkED2K());
786 void PrefsUnifiedDlg::OnCheckBoxChange(wxCommandEvent& event)
788 bool value = event.IsChecked();
789 int id = event.GetId();
791 // Check if this checkbox is one of the User Events checkboxes
792 if (id >= USEREVENTS_FIRST_ID &&
793 id < USEREVENTS_FIRST_ID +
794 (int)CUserEvents::GetCount() * USEREVENTS_IDS_PER_EVENT) {
795 // The corresponding text control always has
796 // an ID one greater than the checkbox
797 FindWindow(id + 1)->Enable(value);
798 return;
801 switch ( id ) {
802 case IDC_UDPENABLE:
803 FindWindow( IDC_UDPPORT )->Enable(value);
804 break;
806 case IDC_UPNP_ENABLED:
807 FindWindow(IDC_UPNPTCPPORT)->Enable(value);
808 FindWindow(IDC_UPNPTCPPORTTEXT)->Enable(value);
809 break;
811 case IDC_UPNP_WEBSERVER_ENABLED:
812 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(value);
813 FindWindow(IDC_WEBUPNPTCPPORTTEXT)->Enable(value);
814 break;
816 case IDC_NETWORKKAD: {
817 wxCheckBox * udpPort = (wxCheckBox *) FindWindow(IDC_UDPENABLE);
818 if (value) {
819 // Kad enabled: disable check box, turn UDP on, enable port spin control
820 udpPort->Enable(false);
821 udpPort->SetValue(true);
822 FindWindow(IDC_UDPPORT)->Enable(true);
823 } else {
824 // Kad disabled: enable check box
825 udpPort->Enable(true);
827 break;
830 case IDC_CHECKDISKSPACE:
831 FindWindow( IDC_MINDISKSPACE )->Enable(value);
832 break;
834 case IDC_ONLINESIG:
835 FindWindow( IDC_OSDIR )->Enable(value);;
836 FindWindow(IDC_OSUPDATE)->Enable(value);
837 break;
839 case IDC_REMOVEDEAD:
840 FindWindow( IDC_SERVERRETRIES )->Enable(value);;
841 break;
843 case IDC_AUTOSERVER:
844 if ((CPath::GetFileSize(thePrefs::GetConfigDir() + wxT("addresses.dat")) == 0) &&
845 CastChild(event.GetId(), wxCheckBox)->IsChecked() ) {
846 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."),
847 _("Message"), wxOK | wxICON_INFORMATION);
848 CastChild(event.GetId(), wxCheckBox)->SetValue(false);
850 break;
852 case IDC_MSGFILTER:
853 // Toogle All filter options
854 FindWindow(IDC_MSGFILTER_ALL)->Enable(value);
855 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(value);
856 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(value);
857 FindWindow(IDC_MSGFILTER_WORD)->Enable(value);
858 if (value) {
859 FindWindow(IDC_MSGWORD)->Enable(
860 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
861 } else {
862 FindWindow(IDC_MSGWORD)->Enable(false);
864 break;
866 case IDC_MSGFILTER_ALL:
867 // Toogle filtering by data.
868 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(!value);
869 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(!value);
870 FindWindow(IDC_MSGFILTER_WORD)->Enable(!value);
871 if (!value) {
872 FindWindow(IDC_MSGWORD)->Enable(
873 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
874 } else {
875 FindWindow(IDC_MSGWORD)->Enable(false);
877 break;
879 case IDC_MSGFILTER_WORD:
880 // Toogle filter word list.
881 FindWindow(IDC_MSGWORD)->Enable(value);
882 break;
884 case IDC_FILTERCOMMENTS:
885 FindWindow(IDC_COMMENTWORD)->Enable(value);
886 break;
888 case ID_PROXY_ENABLE_PROXY:
889 FindWindow(ID_PROXY_TYPE)->Enable(value);
890 FindWindow(ID_PROXY_NAME)->Enable(value);
891 FindWindow(ID_PROXY_PORT)->Enable(value);
892 break;
894 case ID_PROXY_ENABLE_PASSWORD:
895 FindWindow(ID_PROXY_USER)->Enable(value);
896 FindWindow(ID_PROXY_PASSWORD)->Enable(value);
897 break;
899 case IDC_STARTNEXTFILE:
900 FindWindow(IDC_STARTNEXTFILE_SAME)->Enable(value);
901 FindWindow(IDC_STARTNEXTFILE_ALPHA)->Enable(value);
902 break;
904 case IDC_MACHIDEONCLOSE:
905 FindWindow(IDC_EXIT)->Enable(!value);
906 CastChild(IDC_EXIT, wxCheckBox)->SetValue(!value && thePrefs::IsConfirmExitEnabled());
907 break;
909 case IDC_ENABLETRAYICON:
910 FindWindow(IDC_MINTRAY)->Enable(value);
911 if (value) {
912 theApp->amuledlg->CreateSystray();
913 } else {
914 theApp->amuledlg->RemoveSystray();
916 thePrefs::SetUseTrayIcon(value);
917 break;
919 case ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY:
920 break;
922 case IDC_VERTTOOLBAR:
923 theApp->amuledlg->Create_Toolbar(value);
924 // Update the first tool (conn button)
925 theApp->amuledlg->ShowConnectionState();
926 theApp->amuledlg->Layout();
927 break;
929 case IDC_ENFORCE_PO_INCOMING:
930 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(!value);
931 break;
933 case IDC_ENABLE_PO_OUTGOING:
934 FindWindow(IDC_SUPPORT_PO)->Enable(!value);
935 FindWindow(IDC_ENFORCE_PO_INCOMING)->Enable(value);
936 break;
938 case IDC_SUPPORT_PO:
939 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(value);
940 break;
942 case IDC_SHOWRATEONTITLE:
943 FindWindow(IDC_RATESBEFORETITLE)->Enable(value);
944 FindWindow(IDC_RATESAFTERTITLE)->Enable(value);
945 break;
947 case IDC_NETWORKED2K: {
948 EnableServerTab(value);
949 wxSpinEvent e;
950 OnTCPClientPortChange(e);
951 break;
954 default:
955 break;
960 void PrefsUnifiedDlg::OnButtonColorChange(wxCommandEvent& WXUNUSED(event))
962 int index = m_choiceColor->GetSelection();
963 wxColour col = wxGetColourFromUser( this, CMuleColour(thePrefs::s_colors[index]) );
964 if ( col.Ok() ) {
965 m_buttonColor->SetBackgroundColour( col );
966 thePrefs::s_colors[index] = CMuleColour(col).GetULong();
971 void PrefsUnifiedDlg::OnColorCategorySelected(wxCommandEvent& WXUNUSED(evt))
973 m_buttonColor->SetBackgroundColour(CMuleColour(thePrefs::s_colors[ m_choiceColor->GetSelection() ] ) );
977 void PrefsUnifiedDlg::OnButtonDir(wxCommandEvent& event)
979 wxString type;
981 int id = 0;
982 switch ( event.GetId() ) {
983 case IDC_SELTEMPDIR:
984 id = IDC_TEMPFILES;
985 type = _("Temporary files");
986 break;
988 case IDC_SELINCDIR:
989 id = IDC_INCFILES;
990 type = _("Incoming files");
991 break;
993 case IDC_SELOSDIR:
994 id = IDC_OSDIR;
995 type = _("Online Signatures");
996 break;
998 // case IDC_SELSKIN:
999 // id = IDC_SKIN;
1000 // type = _("Skins directory");
1001 // break;
1003 default:
1004 wxFAIL;
1005 return;
1008 type = CFormat(_("Choose a folder for %s")) % type;
1009 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
1010 wxString dir = widget->GetValue();
1011 wxString str = wxDirSelector(
1012 type, dir,
1013 wxDD_DEFAULT_STYLE,
1014 wxDefaultPosition, this);
1015 if (!str.IsEmpty()) {
1016 widget->SetValue(str);
1021 void PrefsUnifiedDlg::OnButtonBrowseApplication(wxCommandEvent& event)
1023 wxString title;
1024 int id = 0;
1025 switch ( event.GetId() ) {
1026 case IDC_BROWSEV:
1027 id = IDC_VIDEOPLAYER;
1028 title = _("Browse for videoplayer");
1029 break;
1030 case IDC_SELBROWSER:
1031 id = IDC_BROWSERSELF;
1032 title = _("Select browser");
1033 break;
1034 default:
1035 wxFAIL;
1036 return;
1038 wxString wildcard = CFormat(_("Executable%s"))
1039 #ifdef __WINDOWS__
1040 % wxT(" (*.exe)|*.exe");
1041 #else
1042 % wxT("|*");
1043 #endif
1045 wxString str = wxFileSelector( title, wxEmptyString, wxEmptyString,
1046 wxEmptyString, wildcard, 0, this );
1048 if ( !str.IsEmpty() ) {
1049 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
1050 widget->SetValue( str );
1055 void PrefsUnifiedDlg::OnButtonEditAddr(wxCommandEvent& WXUNUSED(evt))
1057 wxString fullpath( thePrefs::GetConfigDir() + wxT("addresses.dat") );
1059 EditServerListDlg* test = new EditServerListDlg(this, _("Edit server list"),
1060 _("Add here URL's to download server.met files.\nOnly one url on each line."),
1061 fullpath );
1063 test->ShowModal();
1064 delete test;
1068 void PrefsUnifiedDlg::OnButtonIPFilterReload(wxCommandEvent& WXUNUSED(event))
1070 theApp->ipfilter->Reload();
1074 void PrefsUnifiedDlg::OnButtonIPFilterUpdate(wxCommandEvent& WXUNUSED(event))
1076 theApp->ipfilter->Update( CastChild( IDC_IPFILTERURL, wxTextCtrl )->GetValue() );
1080 void PrefsUnifiedDlg::OnPrefsPageChange(wxListEvent& event)
1082 prefs_sizer->Detach( m_CurrentPanel );
1083 m_CurrentPanel->Show( false );
1085 m_CurrentPanel = reinterpret_cast<wxPanel*>(m_PrefsIcons->GetItemData(event.GetIndex()));
1086 if (pages[event.GetIndex()].m_function == PreferencesDirectoriesTab) {
1087 CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl)->Init();
1090 prefs_sizer->Add( m_CurrentPanel, 0, wxGROW|wxEXPAND );
1091 m_CurrentPanel->Show( true );
1093 Layout();
1095 event.Skip();
1099 void PrefsUnifiedDlg::OnToolTipDelayChange(wxSpinEvent& event)
1101 wxToolTip::SetDelay( event.GetPosition() * 1000 );
1105 void PrefsUnifiedDlg::OnInitDialog( wxInitDialogEvent& WXUNUSED(evt) )
1107 // This function exists solely to avoid automatic transfer-to-widget calls
1111 void PrefsUnifiedDlg::OnScrollBarChange( wxScrollEvent& event )
1113 int id = 0;
1114 wxString label;
1116 switch ( event.GetId() ) {
1117 case IDC_SLIDER:
1118 id = IDC_SLIDERINFO;
1119 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1120 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(event.GetPosition());
1121 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(event.GetPosition());
1122 break;
1124 case IDC_SLIDER3:
1125 id = IDC_SLIDERINFO3;
1126 label = CFormat(wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event.GetPosition())) % event.GetPosition();
1127 theApp->m_statistics->SetAverageMinutes(event.GetPosition());
1128 break;
1130 case IDC_SLIDER4:
1131 id = IDC_SLIDERINFO4;
1132 label = CFormat(_("Connections Graph Scale: %d")) % event.GetPosition();
1133 theApp->amuledlg->m_statisticswnd->GetConnScope()->SetRanges(0, event.GetPosition());
1134 break;
1136 case IDC_SLIDER2:
1137 id = IDC_SLIDERINFO2;
1138 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1139 break;
1141 case IDC_FILEBUFFERSIZE:
1142 id = IDC_FILEBUFFERSIZE_STATIC;
1143 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1144 label = CFormat(wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event.GetPosition() * 15000)) % (event.GetPosition() * 15000);
1145 break;
1147 case IDC_QUEUESIZE:
1148 id = IDC_QUEUESIZE_STATIC;
1149 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1150 label = CFormat(wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event.GetPosition() * 100)) % (event.GetPosition() * 100);
1151 break;
1153 case IDC_SERVERKEEPALIVE:
1154 id = IDC_SERVERKEEPALIVE_LABEL;
1156 if ( event.GetPosition() ) {
1157 label = CFormat(wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event.GetPosition())) % event.GetPosition();
1158 } else {
1159 label = _("Server connection refresh interval: Disabled");
1161 break;
1163 default:
1164 return;
1167 wxStaticText* widget = CastChild( id, wxStaticText );
1169 if (widget) {
1170 widget->SetLabel( label );
1171 widget->GetParent()->Layout();
1176 void PrefsUnifiedDlg::OnRateLimitChanged( wxSpinEvent& event )
1178 // Here we do immediate sanity checking of the up/down ratio,
1179 // so that the user can see if his choice is illegal
1181 // We only do checks if the rate is limited
1182 if ( event.GetPosition() != (int)UNLIMITED ) {
1183 wxSpinCtrl* dlrate = CastChild( IDC_MAXDOWN, wxSpinCtrl );
1185 if ( event.GetPosition() < 4 ) {
1186 if ( ( event.GetPosition() * 3 < dlrate->GetValue() ) ||
1187 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1188 dlrate->SetValue( event.GetPosition() * 3 );
1190 } else if ( event.GetPosition() < 10 ) {
1191 if ( ( event.GetPosition() * 4 < dlrate->GetValue() ) ||
1192 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1193 dlrate->SetValue( event.GetPosition() * 4 );
1200 void PrefsUnifiedDlg::OnTCPClientPortChange(wxSpinEvent& WXUNUSED(event))
1202 CastChild(ID_TEXT_CLIENT_UDP_PORT, wxStaticText)->SetLabel(
1203 m_ServerTabVisible ? (wxString() << (CastChild(IDC_PORT, wxSpinCtrl)->GetValue() + 3))
1204 : wxString(_("disabled")));
1207 void PrefsUnifiedDlg::OnUserEventSelected(wxListEvent& event)
1209 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1210 IDC_PREFS_EVENTS_PAGE->Hide(i+1);
1213 IDC_PREFS_EVENTS_PAGE->Show((event.GetData() - USEREVENTS_FIRST_ID) / USEREVENTS_IDS_PER_EVENT + 1, true);
1215 IDC_PREFS_EVENTS_PAGE->Layout();
1217 event.Skip();
1220 void PrefsUnifiedDlg::OnLanguageChoice(wxCommandEvent &evt)
1222 thePrefs::GetCfgLang()->UpdateChoice(evt.GetSelection());
1225 void PrefsUnifiedDlg::CreateEventPanels(const int idx, const wxString& vars, wxWindow* parent)
1227 wxStaticBox *item8 = new wxStaticBox( parent, -1, CFormat(_("Execute command on '%s' event")) % wxGetTranslation(CUserEvents::GetDisplayName(static_cast<enum CUserEvents::EventType>(idx))) );
1228 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxVERTICAL );
1230 wxCheckBox *item9 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 1, _("Enable command execution on core"), wxDefaultPosition, wxDefaultSize, 0 );
1231 item7->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1233 wxFlexGridSizer *item10 = new wxFlexGridSizer( 3, 0, 0 );
1234 item10->AddGrowableCol( 2 );
1236 item10->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1238 wxStaticText *item11 = new wxStaticText( parent, -1, _("Core command:"), wxDefaultPosition, wxDefaultSize, 0 );
1239 item10->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
1241 wxTextCtrl *item12 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 2, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1242 item12->Enable(CUserEvents::IsCoreCommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1243 item10->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1245 item7->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1247 wxCheckBox *item14 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 3, _("Enable command execution on GUI"), wxDefaultPosition, wxDefaultSize, 0 );
1248 item7->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1250 wxFlexGridSizer *item15 = new wxFlexGridSizer( 3, 0, 0 );
1251 item15->AddGrowableCol( 2 );
1253 item15->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1255 wxStaticText *item16 = new wxStaticText( parent, -1, _("GUI command:"), wxDefaultPosition, wxDefaultSize, 0 );
1256 item15->Add( item16, 0, wxALIGN_CENTER|wxALL, 5 );
1258 wxTextCtrl *item17 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 4, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1259 item17->Enable(CUserEvents::IsGUICommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1260 item15->Add( item17, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1262 item7->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1264 wxStaticText *item13 = new wxStaticText( parent, -1, _("The following variables will be replaced:") + vars, wxDefaultPosition, wxDefaultSize, 0 );
1265 item7->Add( item13, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1267 IDC_PREFS_EVENTS_PAGE->Add(item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
1269 IDC_PREFS_EVENTS_PAGE->Layout();
1270 IDC_PREFS_EVENTS_PAGE->Hide(idx + 1);
1272 // File_checked_for_headers