2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Original author: Emilio Sandoz
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
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
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"
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
)
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
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)
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
)
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
)
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.
165 //! The title of the page, used on the listctrl.
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.
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 }
191 ,{ wxTRANSLATE("Debugging"), PreferencesDebug
, 25 }
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
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);
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();
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"));
251 FindWindow(IDC_ENABLETRAYICON
)->Show(false);
252 FindWindow(IDC_MINTRAY
)->Show(false);
254 FindWindow(IDC_MACHIDEONCLOSE
)->Show(false);
255 thePrefs::SetHideOnClose(false);
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
))));
269 list
->SetItemData(lidx
,
270 USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
);
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);
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);
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() );
307 // Align and resize the page
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();
322 prefs_sizer
->Detach(Widget
);
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());
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.
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() ) {
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();
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());
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);
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);
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);
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);
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);
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());
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() );
524 m_verticalToolbar
= thePrefs::VerticalToolbar();
525 m_toolbarOrientationChanged
= false;
531 bool PrefsUnifiedDlg::TransferFromWindow()
533 // Connect the Cfgs with their widgets
534 thePrefs::CFGMap::iterator it
= thePrefs::s_CfgList
.begin();
535 for ( ; it
!= thePrefs::s_CfgList
.end(); ++it
) {
536 // Checking for failures
537 if ( !it
->second
->TransferFromWindow() ) {
538 AddLogLineNS(CFormat(_("Failed to transfer data from Widget to Cfg with the ID %d and key %s"))
539 % it
->first
% it
->second
->GetKey());
543 theApp
->glob_prefs
->shareddir_list
.clear();
544 m_ShareSelector
->GetSharedDirectories(&theApp
->glob_prefs
->shareddir_list
);
546 for ( int i
= 0; i
< cntStatColors
; i
++ ) {
547 if ( thePrefs::s_colors
[i
] != thePrefs::s_colors_ref
[i
] ) {
548 CStatisticsDlg::acrStat
[i
] = thePrefs::s_colors
[i
];
549 theApp
->amuledlg
->m_statisticswnd
->ApplyStatsColor(i
);
552 theApp
->amuledlg
->m_kademliawnd
->SetGraphColors();
556 // Get debugging toggles
557 int count
= theLogger
.GetDebugCategoryCount();
558 wxCheckListBox
* list
= CastChild( ID_DEBUGCATS
, wxCheckListBox
);
560 for ( int i
= 0; i
< count
; i
++ ) {
561 theLogger
.SetEnabled( theLogger
.GetDebugCategory( i
).GetType(), list
->IsChecked( i
) );
565 thePrefs::SetShowRatesOnTitle(CastChild(IDC_SHOWRATEONTITLE
, wxCheckBox
)->GetValue() ? (CastChild(IDC_RATESBEFORETITLE
, wxRadioButton
)->GetValue() ? 2 : 1) : 0);
568 // Send preferences to core.
569 theApp
->glob_prefs
->SendToRemote();
576 bool PrefsUnifiedDlg::CfgChanged(int ID
)
578 Cfg_Base
* cfg
= GetCfg(ID
);
581 return cfg
->HasChanged();
588 void PrefsUnifiedDlg::OnOk(wxCommandEvent
& WXUNUSED(event
))
590 TransferFromWindow();
592 bool restart_needed
= false;
593 wxString restart_needed_msg
= _("aMule must be restarted to enable these changes:\n\n");
595 // do sanity checking, special processing, and user notifications here
596 thePrefs::CheckUlDlRatio();
598 if (CfgChanged(IDC_PORT
)) {
599 restart_needed
= true;
600 restart_needed_msg
+= _("- TCP port changed.\n");
603 if (CfgChanged(IDC_UDPPORT
)) {
604 restart_needed
= true;
605 restart_needed_msg
+= _("- UDP port changed.\n");
608 if (CfgChanged(IDC_EXT_CONN_TCP_PORT
)) {
609 restart_needed
= true;
610 restart_needed_msg
+= _("- External connect port changed.\n");
612 if (CfgChanged(IDC_EXT_CONN_ACCEPT
)) {
613 restart_needed
= true;
614 restart_needed_msg
+= _("- External connect acceptance changed.\n");
616 if (CfgChanged(IDC_EXT_CONN_IP
)) {
617 restart_needed
= true;
618 restart_needed_msg
+= _("- External connect interface changed.\n");
620 if (CfgChanged(IDC_SUPPORT_PO
)) {
621 restart_needed
= true;
622 restart_needed_msg
+= _("- Protocol obfuscation support changed.\n");
625 // Force port checking
626 thePrefs::SetPort(thePrefs::GetPort());
628 if ((CPath::GetFileSize(thePrefs::GetConfigDir() + wxT("addresses.dat")) == 0) &&
629 CastChild(IDC_AUTOSERVER
, wxCheckBox
)->IsChecked() ) {
630 thePrefs::UnsetAutoServerStart();
631 wxMessageBox(_("Your Auto-update server list is empty.\n'Auto-update server list at startup' will be disabled."),
632 _("Message"), wxOK
| wxICON_INFORMATION
, this);
635 if (thePrefs::AcceptExternalConnections() && thePrefs::ECPassword().IsEmpty()) {
636 thePrefs::EnableExternalConnections( false );
638 wxMessageBox( _("You have enabled external connections but have not specified a password.\nExternal connections cannot be enabled unless a valid password is specified."));
641 // save the preferences on ok
642 theApp
->glob_prefs
->Save();
644 if (CfgChanged(IDC_FED2KLH
) && theApp
->amuledlg
->GetActiveDialog() != CamuleDlg::DT_SEARCH_WND
) {
645 theApp
->amuledlg
->ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
648 if (CfgChanged(IDC_LANGUAGE
)) {
649 restart_needed
= true;
650 restart_needed_msg
+= _("- Language changed.\n");
653 if (CfgChanged(IDC_TEMPFILES
)) {
654 restart_needed
= true;
655 restart_needed_msg
+= _("- Temp folder changed.\n");
658 if (CfgChanged(IDC_NETWORKED2K
) && thePrefs::GetNetworkED2K()) {
659 restart_needed
= true;
660 restart_needed_msg
+= _("- ED2K network enabled.\n");
663 if (CfgChanged(IDC_INCFILES
) || CfgChanged(IDC_TEMPFILES
) || m_ShareSelector
->HasChanged
) {
664 theApp
->sharedfiles
->Reload();
667 if (CfgChanged(IDC_OSDIR
) || CfgChanged(IDC_ONLINESIG
)) {
668 wxTextCtrl
* widget
= CastChild( IDC_OSDIR
, wxTextCtrl
);
670 // Build the filenames for the two OS files
671 theApp
->SetOSFiles( widget
->GetValue() );
674 if (CfgChanged(IDC_IPFCLIENTS
) && thePrefs::IsFilteringClients()) {
675 theApp
->clientlist
->FilterQueues();
678 if (CfgChanged(IDC_IPFSERVERS
) && thePrefs::IsFilteringServers()) {
679 theApp
->serverlist
->FilterServers();
682 if (CfgChanged(ID_IPFILTERLEVEL
)) {
683 theApp
->ipfilter
->Reload();
686 theApp
->ResetTitle();
688 if (thePrefs::GetShowRatesOnTitle()) {
689 // This avoids a 5 seconds delay to show the title
690 theApp
->amuledlg
->ShowTransferRate();
692 // This resets the title
693 theApp
->amuledlg
->SetTitle(theApp
->m_FrameTitle
);
696 if (CfgChanged(IDC_EXTCATINFO
)) {
697 theApp
->amuledlg
->m_transferwnd
->UpdateCatTabTitles();
700 // Changes related to the statistics-dlg
701 if (CfgChanged(IDC_SLIDER
)) {
702 theApp
->amuledlg
->m_statisticswnd
->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
703 theApp
->amuledlg
->m_kademliawnd
->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
706 if ( CfgChanged(IDC_SLIDER3
) ) {
707 theApp
->amuledlg
->m_statisticswnd
->ResetAveragingTime();
710 if (CfgChanged(IDC_DOWNLOAD_CAP
)) {
711 theApp
->amuledlg
->m_statisticswnd
->SetARange( true, thePrefs::GetMaxGraphDownloadRate() );
714 if (CfgChanged(IDC_UPLOAD_CAP
)) {
715 theApp
->amuledlg
->m_statisticswnd
->SetARange( false, thePrefs::GetMaxGraphUploadRate() );
718 if (CfgChanged(IDC_SKIN
)) {
719 theApp
->amuledlg
->Create_Toolbar(thePrefs::VerticalToolbar());
722 if (!thePrefs::GetNetworkED2K() && theApp
->IsConnectedED2K()) {
723 theApp
->DisconnectED2K();
726 if (!thePrefs::GetNetworkKademlia() && theApp
->IsConnectedKad()) {
730 if (!thePrefs::GetNetworkED2K() && !thePrefs::GetNetworkKademlia()) {
732 _("Both eD2k and Kad network are disabled.\nYou won't be able to connect until you enable at least one of them."));
735 if (thePrefs::GetNetworkKademlia() && thePrefs::IsUDPDisabled()) {
736 wxMessageBox(_("Kad will not start if your UDP port is disabled.\nEnable UDP port or disable Kad."),
737 _("Message"), wxOK
| wxICON_INFORMATION
, this);
740 if (CfgChanged(IDC_NETWORKKAD
) || CfgChanged(IDC_NETWORKED2K
)) {
741 theApp
->amuledlg
->DoNetworkRearrange();
744 if (CfgChanged(IDC_SHOW_COUNTRY_FLAGS
)) {
745 theApp
->amuledlg
->EnableIP2Country();
748 if (restart_needed
) {
749 wxMessageBox(restart_needed_msg
+ _("\nYou MUST restart aMule now.\nIf you do not restart now, don't complain if anything bad happens.\n"),
750 _("WARNING"), wxOK
| wxICON_EXCLAMATION
, this);
757 void PrefsUnifiedDlg::OnClose(wxCloseEvent
& event
)
761 // Try to keep the window alive when possible
762 if (event
.CanVeto()) {
765 if (theApp
->amuledlg
) {
766 theApp
->amuledlg
->m_prefsDialog
= NULL
;
769 // Un-Connect the Cfgs
770 thePrefs::CFGMap::iterator it
= thePrefs::s_CfgList
.begin();
771 for (; it
!= thePrefs::s_CfgList
.end(); ++it
) {
772 // Checking for failures
773 it
->second
->ConnectToWidget( 0 );
781 void PrefsUnifiedDlg::OnCancel(wxCommandEvent
& WXUNUSED(event
))
784 // restore state of server tab if necessary
785 EnableServerTab(thePrefs::GetNetworkED2K());
787 if (m_toolbarOrientationChanged
) {
788 theApp
->amuledlg
->Create_Toolbar(m_verticalToolbar
);
789 // Update the first tool (conn button)
790 theApp
->amuledlg
->ShowConnectionState();
791 theApp
->amuledlg
->Layout();
796 void PrefsUnifiedDlg::OnCheckBoxChange(wxCommandEvent
& event
)
798 bool value
= event
.IsChecked();
799 int id
= event
.GetId();
801 // Check if this checkbox is one of the User Events checkboxes
802 if (id
>= USEREVENTS_FIRST_ID
&&
803 id
< USEREVENTS_FIRST_ID
+
804 (int)CUserEvents::GetCount() * USEREVENTS_IDS_PER_EVENT
) {
805 // The corresponding text control always has
806 // an ID one greater than the checkbox
807 FindWindow(id
+ 1)->Enable(value
);
813 FindWindow( IDC_UDPPORT
)->Enable(value
);
816 case IDC_UPNP_ENABLED
:
817 FindWindow(IDC_UPNPTCPPORT
)->Enable(value
);
818 FindWindow(IDC_UPNPTCPPORTTEXT
)->Enable(value
);
821 case IDC_UPNP_WEBSERVER_ENABLED
:
822 FindWindow(IDC_WEBUPNPTCPPORT
)->Enable(value
);
823 FindWindow(IDC_WEBUPNPTCPPORTTEXT
)->Enable(value
);
826 case IDC_NETWORKKAD
: {
827 wxCheckBox
* udpPort
= (wxCheckBox
*) FindWindow(IDC_UDPENABLE
);
829 // Kad enabled: disable check box, turn UDP on, enable port spin control
830 udpPort
->Enable(false);
831 udpPort
->SetValue(true);
832 FindWindow(IDC_UDPPORT
)->Enable(true);
834 // Kad disabled: enable check box
835 udpPort
->Enable(true);
840 case IDC_CHECKDISKSPACE
:
841 FindWindow( IDC_MINDISKSPACE
)->Enable(value
);
845 FindWindow( IDC_OSDIR
)->Enable(value
);;
846 FindWindow(IDC_OSUPDATE
)->Enable(value
);
850 FindWindow( IDC_SERVERRETRIES
)->Enable(value
);;
854 if ((CPath::GetFileSize(thePrefs::GetConfigDir() + wxT("addresses.dat")) == 0) &&
855 CastChild(event
.GetId(), wxCheckBox
)->IsChecked() ) {
856 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."),
857 _("Message"), wxOK
| wxICON_INFORMATION
);
858 CastChild(event
.GetId(), wxCheckBox
)->SetValue(false);
863 // Toogle All filter options
864 FindWindow(IDC_MSGFILTER_ALL
)->Enable(value
);
865 FindWindow(IDC_MSGFILTER_NONSECURE
)->Enable(value
);
866 FindWindow(IDC_MSGFILTER_NONFRIENDS
)->Enable(value
);
867 FindWindow(IDC_MSGFILTER_WORD
)->Enable(value
);
869 FindWindow(IDC_MSGWORD
)->Enable(
870 CastChild(IDC_MSGFILTER_WORD
, wxCheckBox
)->IsChecked());
872 FindWindow(IDC_MSGWORD
)->Enable(false);
876 case IDC_MSGFILTER_ALL
:
877 // Toogle filtering by data.
878 FindWindow(IDC_MSGFILTER_NONSECURE
)->Enable(!value
);
879 FindWindow(IDC_MSGFILTER_NONFRIENDS
)->Enable(!value
);
880 FindWindow(IDC_MSGFILTER_WORD
)->Enable(!value
);
882 FindWindow(IDC_MSGWORD
)->Enable(
883 CastChild(IDC_MSGFILTER_WORD
, wxCheckBox
)->IsChecked());
885 FindWindow(IDC_MSGWORD
)->Enable(false);
889 case IDC_MSGFILTER_WORD
:
890 // Toogle filter word list.
891 FindWindow(IDC_MSGWORD
)->Enable(value
);
894 case IDC_FILTERCOMMENTS
:
895 FindWindow(IDC_COMMENTWORD
)->Enable(value
);
898 case ID_PROXY_ENABLE_PROXY
:
899 FindWindow(ID_PROXY_TYPE
)->Enable(value
);
900 FindWindow(ID_PROXY_NAME
)->Enable(value
);
901 FindWindow(ID_PROXY_PORT
)->Enable(value
);
904 case ID_PROXY_ENABLE_PASSWORD
:
905 FindWindow(ID_PROXY_USER
)->Enable(value
);
906 FindWindow(ID_PROXY_PASSWORD
)->Enable(value
);
909 case IDC_STARTNEXTFILE
:
910 FindWindow(IDC_STARTNEXTFILE_SAME
)->Enable(value
);
911 FindWindow(IDC_STARTNEXTFILE_ALPHA
)->Enable(value
);
914 case IDC_MACHIDEONCLOSE
:
915 FindWindow(IDC_EXIT
)->Enable(!value
);
916 CastChild(IDC_EXIT
, wxCheckBox
)->SetValue(!value
&& thePrefs::IsConfirmExitEnabled());
919 case IDC_ENABLETRAYICON
:
920 FindWindow(IDC_MINTRAY
)->Enable(value
);
922 theApp
->amuledlg
->CreateSystray();
924 theApp
->amuledlg
->RemoveSystray();
926 thePrefs::SetUseTrayIcon(value
);
929 case ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY
:
932 case IDC_VERTTOOLBAR
:
933 m_toolbarOrientationChanged
= (m_verticalToolbar
!= value
);
934 theApp
->amuledlg
->Create_Toolbar(value
);
935 // Update the first tool (conn button)
936 theApp
->amuledlg
->ShowConnectionState();
937 theApp
->amuledlg
->Layout();
940 case IDC_ENFORCE_PO_INCOMING
:
941 FindWindow(IDC_ENABLE_PO_OUTGOING
)->Enable(!value
);
944 case IDC_ENABLE_PO_OUTGOING
:
945 FindWindow(IDC_SUPPORT_PO
)->Enable(!value
);
946 FindWindow(IDC_ENFORCE_PO_INCOMING
)->Enable(value
);
950 FindWindow(IDC_ENABLE_PO_OUTGOING
)->Enable(value
);
953 case IDC_SHOWRATEONTITLE
:
954 FindWindow(IDC_RATESBEFORETITLE
)->Enable(value
);
955 FindWindow(IDC_RATESAFTERTITLE
)->Enable(value
);
958 case IDC_NETWORKED2K
: {
959 EnableServerTab(value
);
961 OnTCPClientPortChange(e
);
971 void PrefsUnifiedDlg::OnButtonColorChange(wxCommandEvent
& WXUNUSED(event
))
973 int index
= m_choiceColor
->GetSelection();
974 wxColour col
= wxGetColourFromUser( this, CMuleColour(thePrefs::s_colors
[index
]) );
976 m_buttonColor
->SetBackgroundColour( col
);
977 thePrefs::s_colors
[index
] = CMuleColour(col
).GetULong();
982 void PrefsUnifiedDlg::OnColorCategorySelected(wxCommandEvent
& WXUNUSED(evt
))
984 m_buttonColor
->SetBackgroundColour(CMuleColour(thePrefs::s_colors
[ m_choiceColor
->GetSelection() ] ) );
988 void PrefsUnifiedDlg::OnButtonDir(wxCommandEvent
& event
)
993 switch ( event
.GetId() ) {
996 type
= _("Temporary files");
1001 type
= _("Incoming files");
1006 type
= _("Online Signatures");
1009 // case IDC_SELSKIN:
1011 // type = _("Skins directory");
1019 type
= CFormat(_("Choose a folder for %s")) % type
;
1020 wxTextCtrl
* widget
= CastChild( id
, wxTextCtrl
);
1021 wxString dir
= widget
->GetValue();
1022 wxString str
= wxDirSelector(
1025 wxDefaultPosition
, this);
1026 if (!str
.IsEmpty()) {
1027 widget
->SetValue(str
);
1032 void PrefsUnifiedDlg::OnButtonBrowseApplication(wxCommandEvent
& event
)
1036 switch ( event
.GetId() ) {
1038 id
= IDC_VIDEOPLAYER
;
1039 title
= _("Browse for videoplayer");
1041 case IDC_SELBROWSER
:
1042 id
= IDC_BROWSERSELF
;
1043 title
= _("Select browser");
1049 wxString wildcard
= CFormat(_("Executable%s"))
1051 % wxT(" (*.exe)|*.exe");
1056 wxString str
= wxFileSelector( title
, wxEmptyString
, wxEmptyString
,
1057 wxEmptyString
, wildcard
, 0, this );
1059 if ( !str
.IsEmpty() ) {
1060 wxTextCtrl
* widget
= CastChild( id
, wxTextCtrl
);
1061 widget
->SetValue( str
);
1066 void PrefsUnifiedDlg::OnButtonEditAddr(wxCommandEvent
& WXUNUSED(evt
))
1068 wxString
fullpath( thePrefs::GetConfigDir() + wxT("addresses.dat") );
1070 EditServerListDlg
* test
= new EditServerListDlg(this, _("Edit server list"),
1071 _("Add here URL's to download server.met files.\nOnly one url on each line."),
1079 void PrefsUnifiedDlg::OnButtonIPFilterReload(wxCommandEvent
& WXUNUSED(event
))
1081 theApp
->ipfilter
->Reload();
1085 void PrefsUnifiedDlg::OnButtonIPFilterUpdate(wxCommandEvent
& WXUNUSED(event
))
1087 theApp
->ipfilter
->Update( CastChild( IDC_IPFILTERURL
, wxTextCtrl
)->GetValue() );
1091 void PrefsUnifiedDlg::OnPrefsPageChange(wxListEvent
& event
)
1093 prefs_sizer
->Detach( m_CurrentPanel
);
1094 m_CurrentPanel
->Show( false );
1096 m_CurrentPanel
= reinterpret_cast<wxPanel
*>(m_PrefsIcons
->GetItemData(event
.GetIndex()));
1097 if (pages
[event
.GetIndex()].m_function
== PreferencesDirectoriesTab
) {
1098 CastChild(IDC_SHARESELECTOR
, CDirectoryTreeCtrl
)->Init();
1101 prefs_sizer
->Add( m_CurrentPanel
, 0, wxGROW
|wxEXPAND
);
1102 m_CurrentPanel
->Show( true );
1110 void PrefsUnifiedDlg::OnToolTipDelayChange(wxSpinEvent
& event
)
1112 wxToolTip::SetDelay( event
.GetPosition() * 1000 );
1116 void PrefsUnifiedDlg::OnInitDialog( wxInitDialogEvent
& WXUNUSED(evt
) )
1118 // This function exists solely to avoid automatic transfer-to-widget calls
1122 void PrefsUnifiedDlg::OnScrollBarChange( wxScrollEvent
& event
)
1127 switch ( event
.GetId() ) {
1129 id
= IDC_SLIDERINFO
;
1130 label
= CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event
.GetPosition())) % event
.GetPosition();
1131 theApp
->amuledlg
->m_statisticswnd
->SetUpdatePeriod(event
.GetPosition());
1132 theApp
->amuledlg
->m_kademliawnd
->SetUpdatePeriod(event
.GetPosition());
1136 id
= IDC_SLIDERINFO3
;
1137 label
= CFormat(wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event
.GetPosition())) % event
.GetPosition();
1138 theApp
->m_statistics
->SetAverageMinutes(event
.GetPosition());
1142 id
= IDC_SLIDERINFO4
;
1143 label
= CFormat(_("Connections Graph Scale: %d")) % event
.GetPosition();
1144 theApp
->amuledlg
->m_statisticswnd
->GetConnScope()->SetRanges(0, event
.GetPosition());
1148 id
= IDC_SLIDERINFO2
;
1149 label
= CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event
.GetPosition())) % event
.GetPosition();
1152 case IDC_FILEBUFFERSIZE
:
1153 id
= IDC_FILEBUFFERSIZE_STATIC
;
1154 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1155 label
= CFormat(wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event
.GetPosition() * 15000)) % (event
.GetPosition() * 15000);
1159 id
= IDC_QUEUESIZE_STATIC
;
1160 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1161 label
= CFormat(wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event
.GetPosition() * 100)) % (event
.GetPosition() * 100);
1164 case IDC_SERVERKEEPALIVE
:
1165 id
= IDC_SERVERKEEPALIVE_LABEL
;
1167 if ( event
.GetPosition() ) {
1168 label
= CFormat(wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event
.GetPosition())) % event
.GetPosition();
1170 label
= _("Server connection refresh interval: Disabled");
1178 wxStaticText
* widget
= CastChild( id
, wxStaticText
);
1181 widget
->SetLabel( label
);
1182 widget
->GetParent()->Layout();
1187 void PrefsUnifiedDlg::OnRateLimitChanged( wxSpinEvent
& event
)
1189 // Here we do immediate sanity checking of the up/down ratio,
1190 // so that the user can see if his choice is illegal
1192 // We only do checks if the rate is limited
1193 if ( event
.GetPosition() != (int)UNLIMITED
) {
1194 wxSpinCtrl
* dlrate
= CastChild( IDC_MAXDOWN
, wxSpinCtrl
);
1196 if ( event
.GetPosition() < 4 ) {
1197 if ( ( event
.GetPosition() * 3 < dlrate
->GetValue() ) ||
1198 ( dlrate
->GetValue() == (int)UNLIMITED
) ) {
1199 dlrate
->SetValue( event
.GetPosition() * 3 );
1201 } else if ( event
.GetPosition() < 10 ) {
1202 if ( ( event
.GetPosition() * 4 < dlrate
->GetValue() ) ||
1203 ( dlrate
->GetValue() == (int)UNLIMITED
) ) {
1204 dlrate
->SetValue( event
.GetPosition() * 4 );
1211 void PrefsUnifiedDlg::OnTCPClientPortChange(wxSpinEvent
& WXUNUSED(event
))
1213 CastChild(ID_TEXT_CLIENT_UDP_PORT
, wxStaticText
)->SetLabel(
1214 m_ServerTabVisible
? (wxString() << (CastChild(IDC_PORT
, wxSpinCtrl
)->GetValue() + 3))
1215 : wxString(_("disabled")));
1218 void PrefsUnifiedDlg::OnUserEventSelected(wxListEvent
& event
)
1220 for (unsigned int i
= 0; i
< CUserEvents::GetCount(); ++i
) {
1221 IDC_PREFS_EVENTS_PAGE
->Hide(i
+1);
1224 IDC_PREFS_EVENTS_PAGE
->Show((event
.GetData() - USEREVENTS_FIRST_ID
) / USEREVENTS_IDS_PER_EVENT
+ 1, true);
1226 IDC_PREFS_EVENTS_PAGE
->Layout();
1231 void PrefsUnifiedDlg::OnLanguageChoice(wxCommandEvent
&evt
)
1233 thePrefs::GetCfgLang()->UpdateChoice(evt
.GetSelection());
1236 void PrefsUnifiedDlg::CreateEventPanels(const int idx
, const wxString
& vars
, wxWindow
* parent
)
1238 wxStaticBox
*item8
= new wxStaticBox( parent
, -1, CFormat(_("Execute command on '%s' event")) % wxGetTranslation(CUserEvents::GetDisplayName(static_cast<enum CUserEvents::EventType
>(idx
))) );
1239 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxVERTICAL
);
1241 wxCheckBox
*item9
= new wxCheckBox( parent
, USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
+ 1, _("Enable command execution on core"), wxDefaultPosition
, wxDefaultSize
, 0 );
1242 item7
->Add( item9
, 0, wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
, 5 );
1244 wxFlexGridSizer
*item10
= new wxFlexGridSizer( 3, 0, 0 );
1245 item10
->AddGrowableCol( 2 );
1247 item10
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 0 );
1249 wxStaticText
*item11
= new wxStaticText( parent
, -1, _("Core command:"), wxDefaultPosition
, wxDefaultSize
, 0 );
1250 item10
->Add( item11
, 0, wxALIGN_CENTER
|wxALL
, 5 );
1252 wxTextCtrl
*item12
= new wxTextCtrl( parent
, USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
+ 2, wxT(""), wxDefaultPosition
, wxDefaultSize
, 0 );
1253 item12
->Enable(CUserEvents::IsCoreCommandEnabled(static_cast<enum CUserEvents::EventType
>(idx
)));
1254 item10
->Add( item12
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
1256 item7
->Add( item10
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 0 );
1258 wxCheckBox
*item14
= new wxCheckBox( parent
, USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
+ 3, _("Enable command execution on GUI"), wxDefaultPosition
, wxDefaultSize
, 0 );
1259 item7
->Add( item14
, 0, wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
, 5 );
1261 wxFlexGridSizer
*item15
= new wxFlexGridSizer( 3, 0, 0 );
1262 item15
->AddGrowableCol( 2 );
1264 item15
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 0 );
1266 wxStaticText
*item16
= new wxStaticText( parent
, -1, _("GUI command:"), wxDefaultPosition
, wxDefaultSize
, 0 );
1267 item15
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 5 );
1269 wxTextCtrl
*item17
= new wxTextCtrl( parent
, USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
+ 4, wxT(""), wxDefaultPosition
, wxDefaultSize
, 0 );
1270 item17
->Enable(CUserEvents::IsGUICommandEnabled(static_cast<enum CUserEvents::EventType
>(idx
)));
1271 item15
->Add( item17
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
1273 item7
->Add( item15
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 0 );
1275 wxStaticText
*item13
= new wxStaticText( parent
, -1, _("The following variables will be replaced:") + vars
, wxDefaultPosition
, wxDefaultSize
, 0 );
1276 item7
->Add( item13
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
1278 IDC_PREFS_EVENTS_PAGE
->Add(item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
1280 IDC_PREFS_EVENTS_PAGE
->Layout();
1281 IDC_PREFS_EVENTS_PAGE
->Hide(idx
+ 1);
1283 // File_checked_for_headers