Always include the boost-package. Otherwise it won't get searched on a second run.
[amule.git] / src / PrefsUnifiedDlg.cpp
blob5e273143962d56a4a24fda20d64dbf7343ba6f17
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 static 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 #if !wxCHECK_VERSION(2,9,0)
515 CastChild(IDC_NOTIF, wxCheckBox)->SetValue(false);
516 FindWindow(IDC_NOTIF)->Enable(false);
517 #endif
519 #ifdef __DEBUG__
520 // Set debugging toggles
521 int count = theLogger.GetDebugCategoryCount();
522 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
524 for ( int i = 0; i < count; i++ ) {
525 list->Check( i, theLogger.GetDebugCategory( i ).IsEnabled() );
527 #endif
529 m_verticalToolbar = thePrefs::VerticalToolbar();
530 m_toolbarOrientationChanged = false;
532 return true;
536 bool PrefsUnifiedDlg::TransferFromWindow()
538 // Connect the Cfgs with their widgets
539 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
540 for ( ; it != thePrefs::s_CfgList.end(); ++it ) {
541 // Checking for failures
542 if ( !it->second->TransferFromWindow() ) {
543 AddLogLineNS(CFormat(_("Failed to transfer data from Widget to Cfg with the ID %d and key %s"))
544 % it->first % it->second->GetKey());
548 theApp->glob_prefs->shareddir_list.clear();
549 m_ShareSelector->GetSharedDirectories(&theApp->glob_prefs->shareddir_list);
551 for ( int i = 0; i < cntStatColors; i++ ) {
552 if ( thePrefs::s_colors[i] != thePrefs::s_colors_ref[i] ) {
553 CStatisticsDlg::acrStat[i] = thePrefs::s_colors[i];
554 theApp->amuledlg->m_statisticswnd->ApplyStatsColor(i);
557 theApp->amuledlg->m_kademliawnd->SetGraphColors();
560 #ifdef __DEBUG__
561 // Get debugging toggles
562 int count = theLogger.GetDebugCategoryCount();
563 wxCheckListBox* list = CastChild( ID_DEBUGCATS, wxCheckListBox );
565 for ( int i = 0; i < count; i++ ) {
566 theLogger.SetEnabled( theLogger.GetDebugCategory( i ).GetType(), list->IsChecked( i ) );
568 #endif
570 thePrefs::SetShowRatesOnTitle(CastChild(IDC_SHOWRATEONTITLE, wxCheckBox)->GetValue() ? (CastChild(IDC_RATESBEFORETITLE, wxRadioButton)->GetValue() ? 2 : 1) : 0);
572 #ifdef CLIENT_GUI
573 // Send preferences to core.
574 theApp->glob_prefs->SendToRemote();
575 #endif
577 return true;
581 bool PrefsUnifiedDlg::CfgChanged(int ID)
583 Cfg_Base* cfg = GetCfg(ID);
585 if ( cfg ) {
586 return cfg->HasChanged();
589 return false;
593 void PrefsUnifiedDlg::OnOk(wxCommandEvent& WXUNUSED(event))
595 TransferFromWindow();
597 bool restart_needed = false;
598 wxString restart_needed_msg = _("aMule must be restarted to enable these changes:\n\n");
600 // do sanity checking, special processing, and user notifications here
601 thePrefs::CheckUlDlRatio();
603 if (CfgChanged(IDC_PORT)) {
604 restart_needed = true;
605 restart_needed_msg += _("- TCP port changed.\n");
608 if (CfgChanged(IDC_UDPPORT)) {
609 restart_needed = true;
610 restart_needed_msg += _("- UDP port changed.\n");
613 if (CfgChanged(IDC_EXT_CONN_TCP_PORT)) {
614 restart_needed = true;
615 restart_needed_msg += _("- External connect port changed.\n");
617 if (CfgChanged(IDC_EXT_CONN_ACCEPT)) {
618 restart_needed = true;
619 restart_needed_msg += _("- External connect acceptance changed.\n");
621 if (CfgChanged(IDC_EXT_CONN_IP)) {
622 restart_needed = true;
623 restart_needed_msg += _("- External connect interface changed.\n");
625 if (CfgChanged(IDC_SUPPORT_PO)) {
626 restart_needed = true;
627 restart_needed_msg += _("- Protocol obfuscation support changed.\n");
630 // Force port checking
631 thePrefs::SetPort(thePrefs::GetPort());
633 if ((CPath::GetFileSize(thePrefs::GetConfigDir() + wxT("addresses.dat")) == 0) &&
634 CastChild(IDC_AUTOSERVER, wxCheckBox)->IsChecked() ) {
635 thePrefs::UnsetAutoServerStart();
636 wxMessageBox(_("Your Auto-update server list is empty.\n'Auto-update server list at startup' will be disabled."),
637 _("Message"), wxOK | wxICON_INFORMATION, this);
640 if (thePrefs::AcceptExternalConnections() && thePrefs::ECPassword().IsEmpty()) {
641 thePrefs::EnableExternalConnections( false );
643 wxMessageBox( _("You have enabled external connections but have not specified a password.\nExternal connections cannot be enabled unless a valid password is specified."));
646 // save the preferences on ok
647 theApp->glob_prefs->Save();
649 if (CfgChanged(IDC_FED2KLH) && theApp->amuledlg->GetActiveDialog() != CamuleDlg::DT_SEARCH_WND) {
650 theApp->amuledlg->ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
653 if (CfgChanged(IDC_LANGUAGE)) {
654 restart_needed = true;
655 restart_needed_msg += _("- Language changed.\n");
658 if (CfgChanged(IDC_TEMPFILES)) {
659 restart_needed = true;
660 restart_needed_msg += _("- Temp folder changed.\n");
663 if (CfgChanged(IDC_NETWORKED2K) && thePrefs::GetNetworkED2K()) {
664 restart_needed = true;
665 restart_needed_msg += _("- ED2K network enabled.\n");
668 if (CfgChanged(IDC_INCFILES) || CfgChanged(IDC_TEMPFILES) || m_ShareSelector->HasChanged ) {
669 theApp->sharedfiles->Reload();
672 if (CfgChanged(IDC_OSDIR) || CfgChanged(IDC_ONLINESIG)) {
673 wxTextCtrl* widget = CastChild( IDC_OSDIR, wxTextCtrl );
675 // Build the filenames for the two OS files
676 theApp->SetOSFiles( widget->GetValue() );
679 if (CfgChanged(IDC_IPFCLIENTS) && thePrefs::IsFilteringClients()) {
680 theApp->clientlist->FilterQueues();
683 if (CfgChanged(IDC_IPFSERVERS) && thePrefs::IsFilteringServers()) {
684 theApp->serverlist->FilterServers();
687 if (CfgChanged(ID_IPFILTERLEVEL)) {
688 theApp->ipfilter->Reload();
691 theApp->ResetTitle();
693 if (thePrefs::GetShowRatesOnTitle()) {
694 // This avoids a 5 seconds delay to show the title
695 theApp->amuledlg->ShowTransferRate();
696 } else {
697 // This resets the title
698 theApp->amuledlg->SetTitle(theApp->m_FrameTitle);
701 if (CfgChanged(IDC_EXTCATINFO)) {
702 theApp->amuledlg->m_transferwnd->UpdateCatTabTitles();
705 // Changes related to the statistics-dlg
706 if (CfgChanged(IDC_SLIDER)) {
707 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
708 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
711 if ( CfgChanged(IDC_SLIDER3) ) {
712 theApp->amuledlg->m_statisticswnd->ResetAveragingTime();
715 if (CfgChanged(IDC_DOWNLOAD_CAP)) {
716 theApp->amuledlg->m_statisticswnd->SetARange( true, thePrefs::GetMaxGraphDownloadRate() );
719 if (CfgChanged(IDC_UPLOAD_CAP)) {
720 theApp->amuledlg->m_statisticswnd->SetARange( false, thePrefs::GetMaxGraphUploadRate() );
723 if (CfgChanged(IDC_SKIN)) {
724 theApp->amuledlg->Create_Toolbar(thePrefs::VerticalToolbar());
727 if (!thePrefs::GetNetworkED2K() && theApp->IsConnectedED2K()) {
728 theApp->DisconnectED2K();
731 if (!thePrefs::GetNetworkKademlia() && theApp->IsConnectedKad()) {
732 theApp->StopKad();
735 if (!thePrefs::GetNetworkED2K() && !thePrefs::GetNetworkKademlia()) {
736 wxMessageBox(
737 _("Both eD2k and Kad network are disabled.\nYou won't be able to connect until you enable at least one of them."));
740 if (thePrefs::GetNetworkKademlia() && thePrefs::IsUDPDisabled()) {
741 wxMessageBox(_("Kad will not start if your UDP port is disabled.\nEnable UDP port or disable Kad."),
742 _("Message"), wxOK | wxICON_INFORMATION, this);
745 if (CfgChanged(IDC_NETWORKKAD) || CfgChanged(IDC_NETWORKED2K)) {
746 theApp->amuledlg->DoNetworkRearrange();
749 if (CfgChanged(IDC_SHOW_COUNTRY_FLAGS)) {
750 theApp->amuledlg->EnableIP2Country();
753 if (restart_needed) {
754 wxMessageBox(restart_needed_msg + _("\nYou MUST restart aMule now.\nIf you do not restart now, don't complain if anything bad happens.\n"),
755 _("WARNING"), wxOK | wxICON_EXCLAMATION, this);
758 Show(false);
762 void PrefsUnifiedDlg::OnClose(wxCloseEvent& event)
764 Show(false);
766 // Try to keep the window alive when possible
767 if (event.CanVeto()) {
768 event.Veto();
769 } else {
770 if (theApp->amuledlg) {
771 theApp->amuledlg->m_prefsDialog = NULL;
774 // Un-Connect the Cfgs
775 thePrefs::CFGMap::iterator it = thePrefs::s_CfgList.begin();
776 for (; it != thePrefs::s_CfgList.end(); ++it) {
777 // Checking for failures
778 it->second->ConnectToWidget( 0 );
781 Destroy();
786 void PrefsUnifiedDlg::OnCancel(wxCommandEvent& WXUNUSED(event))
788 Show(false);
789 // restore state of server tab if necessary
790 EnableServerTab(thePrefs::GetNetworkED2K());
792 if (m_toolbarOrientationChanged) {
793 theApp->amuledlg->Create_Toolbar(m_verticalToolbar);
794 // Update the first tool (conn button)
795 theApp->amuledlg->ShowConnectionState();
796 theApp->amuledlg->Layout();
801 void PrefsUnifiedDlg::OnCheckBoxChange(wxCommandEvent& event)
803 bool value = event.IsChecked();
804 int id = event.GetId();
806 // Check if this checkbox is one of the User Events checkboxes
807 if (id >= USEREVENTS_FIRST_ID &&
808 id < USEREVENTS_FIRST_ID +
809 (int)CUserEvents::GetCount() * USEREVENTS_IDS_PER_EVENT) {
810 // The corresponding text control always has
811 // an ID one greater than the checkbox
812 FindWindow(id + 1)->Enable(value);
813 return;
816 switch ( id ) {
817 case IDC_UDPENABLE:
818 FindWindow( IDC_UDPPORT )->Enable(value);
819 break;
821 case IDC_UPNP_ENABLED:
822 FindWindow(IDC_UPNPTCPPORT)->Enable(value);
823 FindWindow(IDC_UPNPTCPPORTTEXT)->Enable(value);
824 break;
826 case IDC_UPNP_WEBSERVER_ENABLED:
827 FindWindow(IDC_WEBUPNPTCPPORT)->Enable(value);
828 FindWindow(IDC_WEBUPNPTCPPORTTEXT)->Enable(value);
829 break;
831 case IDC_NETWORKKAD: {
832 wxCheckBox * udpPort = (wxCheckBox *) FindWindow(IDC_UDPENABLE);
833 if (value) {
834 // Kad enabled: disable check box, turn UDP on, enable port spin control
835 udpPort->Enable(false);
836 udpPort->SetValue(true);
837 FindWindow(IDC_UDPPORT)->Enable(true);
838 } else {
839 // Kad disabled: enable check box
840 udpPort->Enable(true);
842 break;
845 case IDC_CHECKDISKSPACE:
846 FindWindow( IDC_MINDISKSPACE )->Enable(value);
847 break;
849 case IDC_ONLINESIG:
850 FindWindow( IDC_OSDIR )->Enable(value);;
851 FindWindow(IDC_OSUPDATE)->Enable(value);
852 break;
854 case IDC_REMOVEDEAD:
855 FindWindow( IDC_SERVERRETRIES )->Enable(value);;
856 break;
858 case IDC_AUTOSERVER:
859 if ((CPath::GetFileSize(thePrefs::GetConfigDir() + wxT("addresses.dat")) == 0) &&
860 CastChild(event.GetId(), wxCheckBox)->IsChecked() ) {
861 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."),
862 _("Message"), wxOK | wxICON_INFORMATION);
863 CastChild(event.GetId(), wxCheckBox)->SetValue(false);
865 break;
867 case IDC_MSGFILTER:
868 // Toogle All filter options
869 FindWindow(IDC_MSGFILTER_ALL)->Enable(value);
870 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(value);
871 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(value);
872 FindWindow(IDC_MSGFILTER_WORD)->Enable(value);
873 if (value) {
874 FindWindow(IDC_MSGWORD)->Enable(
875 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
876 } else {
877 FindWindow(IDC_MSGWORD)->Enable(false);
879 break;
881 case IDC_MSGFILTER_ALL:
882 // Toogle filtering by data.
883 FindWindow(IDC_MSGFILTER_NONSECURE)->Enable(!value);
884 FindWindow(IDC_MSGFILTER_NONFRIENDS)->Enable(!value);
885 FindWindow(IDC_MSGFILTER_WORD)->Enable(!value);
886 if (!value) {
887 FindWindow(IDC_MSGWORD)->Enable(
888 CastChild(IDC_MSGFILTER_WORD, wxCheckBox)->IsChecked());
889 } else {
890 FindWindow(IDC_MSGWORD)->Enable(false);
892 break;
894 case IDC_MSGFILTER_WORD:
895 // Toogle filter word list.
896 FindWindow(IDC_MSGWORD)->Enable(value);
897 break;
899 case IDC_FILTERCOMMENTS:
900 FindWindow(IDC_COMMENTWORD)->Enable(value);
901 break;
903 case ID_PROXY_ENABLE_PROXY:
904 FindWindow(ID_PROXY_TYPE)->Enable(value);
905 FindWindow(ID_PROXY_NAME)->Enable(value);
906 FindWindow(ID_PROXY_PORT)->Enable(value);
907 break;
909 case ID_PROXY_ENABLE_PASSWORD:
910 FindWindow(ID_PROXY_USER)->Enable(value);
911 FindWindow(ID_PROXY_PASSWORD)->Enable(value);
912 break;
914 case IDC_STARTNEXTFILE:
915 FindWindow(IDC_STARTNEXTFILE_SAME)->Enable(value);
916 FindWindow(IDC_STARTNEXTFILE_ALPHA)->Enable(value);
917 break;
919 case IDC_MACHIDEONCLOSE:
920 FindWindow(IDC_EXIT)->Enable(!value);
921 CastChild(IDC_EXIT, wxCheckBox)->SetValue(!value && thePrefs::IsConfirmExitEnabled());
922 break;
924 case IDC_ENABLETRAYICON:
925 FindWindow(IDC_MINTRAY)->Enable(value);
926 if (value) {
927 theApp->amuledlg->CreateSystray();
928 } else {
929 theApp->amuledlg->RemoveSystray();
931 thePrefs::SetUseTrayIcon(value);
932 break;
934 case IDC_NOTIF:
935 FindWindow(IDC_NOTIF)->Enable(value);
936 break;
938 case ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY:
939 break;
941 case IDC_VERTTOOLBAR:
942 m_toolbarOrientationChanged = (m_verticalToolbar != value);
943 theApp->amuledlg->Create_Toolbar(value);
944 // Update the first tool (conn button)
945 theApp->amuledlg->ShowConnectionState();
946 theApp->amuledlg->Layout();
947 break;
949 case IDC_ENFORCE_PO_INCOMING:
950 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(!value);
951 break;
953 case IDC_ENABLE_PO_OUTGOING:
954 FindWindow(IDC_SUPPORT_PO)->Enable(!value);
955 FindWindow(IDC_ENFORCE_PO_INCOMING)->Enable(value);
956 break;
958 case IDC_SUPPORT_PO:
959 FindWindow(IDC_ENABLE_PO_OUTGOING)->Enable(value);
960 break;
962 case IDC_SHOWRATEONTITLE:
963 FindWindow(IDC_RATESBEFORETITLE)->Enable(value);
964 FindWindow(IDC_RATESAFTERTITLE)->Enable(value);
965 break;
967 case IDC_NETWORKED2K: {
968 EnableServerTab(value);
969 wxSpinEvent e;
970 OnTCPClientPortChange(e);
971 break;
974 default:
975 break;
980 void PrefsUnifiedDlg::OnButtonColorChange(wxCommandEvent& WXUNUSED(event))
982 int index = m_choiceColor->GetSelection();
983 wxColour col = wxGetColourFromUser( this, CMuleColour(thePrefs::s_colors[index]) );
984 if ( col.Ok() ) {
985 m_buttonColor->SetBackgroundColour( col );
986 thePrefs::s_colors[index] = CMuleColour(col).GetULong();
991 void PrefsUnifiedDlg::OnColorCategorySelected(wxCommandEvent& WXUNUSED(evt))
993 m_buttonColor->SetBackgroundColour(CMuleColour(thePrefs::s_colors[ m_choiceColor->GetSelection() ] ) );
997 void PrefsUnifiedDlg::OnButtonDir(wxCommandEvent& event)
999 wxString type;
1001 int id = 0;
1002 switch ( event.GetId() ) {
1003 case IDC_SELTEMPDIR:
1004 id = IDC_TEMPFILES;
1005 type = _("Temporary files");
1006 break;
1008 case IDC_SELINCDIR:
1009 id = IDC_INCFILES;
1010 type = _("Incoming files");
1011 break;
1013 case IDC_SELOSDIR:
1014 id = IDC_OSDIR;
1015 type = _("Online Signatures");
1016 break;
1018 // case IDC_SELSKIN:
1019 // id = IDC_SKIN;
1020 // type = _("Skins directory");
1021 // break;
1023 default:
1024 wxFAIL;
1025 return;
1028 type = CFormat(_("Choose a folder for %s")) % type;
1029 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
1030 wxString dir = widget->GetValue();
1031 wxString str = wxDirSelector(
1032 type, dir,
1033 wxDD_DEFAULT_STYLE,
1034 wxDefaultPosition, this);
1035 if (!str.IsEmpty()) {
1036 widget->SetValue(str);
1041 void PrefsUnifiedDlg::OnButtonBrowseApplication(wxCommandEvent& event)
1043 wxString title;
1044 int id = 0;
1045 switch ( event.GetId() ) {
1046 case IDC_BROWSEV:
1047 id = IDC_VIDEOPLAYER;
1048 title = _("Browse for videoplayer");
1049 break;
1050 case IDC_SELBROWSER:
1051 id = IDC_BROWSERSELF;
1052 title = _("Select browser");
1053 break;
1054 default:
1055 wxFAIL;
1056 return;
1058 wxString wildcard = CFormat(_("Executable%s"))
1059 #ifdef __WINDOWS__
1060 % wxT(" (*.exe)|*.exe");
1061 #else
1062 % wxT("|*");
1063 #endif
1065 wxString str = wxFileSelector( title, wxEmptyString, wxEmptyString,
1066 wxEmptyString, wildcard, 0, this );
1068 if ( !str.IsEmpty() ) {
1069 wxTextCtrl* widget = CastChild( id, wxTextCtrl );
1070 widget->SetValue( str );
1075 void PrefsUnifiedDlg::OnButtonEditAddr(wxCommandEvent& WXUNUSED(evt))
1077 wxString fullpath( thePrefs::GetConfigDir() + wxT("addresses.dat") );
1079 EditServerListDlg* test = new EditServerListDlg(this, _("Edit server list"),
1080 _("Add here URL's to download server.met files.\nOnly one url on each line."),
1081 fullpath );
1083 test->ShowModal();
1084 delete test;
1088 void PrefsUnifiedDlg::OnButtonIPFilterReload(wxCommandEvent& WXUNUSED(event))
1090 theApp->ipfilter->Reload();
1094 void PrefsUnifiedDlg::OnButtonIPFilterUpdate(wxCommandEvent& WXUNUSED(event))
1096 theApp->ipfilter->Update( CastChild( IDC_IPFILTERURL, wxTextCtrl )->GetValue() );
1100 void PrefsUnifiedDlg::OnPrefsPageChange(wxListEvent& event)
1102 prefs_sizer->Detach( m_CurrentPanel );
1103 m_CurrentPanel->Show( false );
1105 m_CurrentPanel = reinterpret_cast<wxPanel*>(m_PrefsIcons->GetItemData(event.GetIndex()));
1106 if (pages[event.GetIndex()].m_function == PreferencesDirectoriesTab) {
1107 CastChild(IDC_SHARESELECTOR, CDirectoryTreeCtrl)->Init();
1110 prefs_sizer->Add( m_CurrentPanel, 0, wxGROW|wxEXPAND );
1111 m_CurrentPanel->Show( true );
1113 Layout();
1115 event.Skip();
1119 void PrefsUnifiedDlg::OnToolTipDelayChange(wxSpinEvent& event)
1121 wxToolTip::SetDelay( event.GetPosition() * 1000 );
1125 void PrefsUnifiedDlg::OnInitDialog( wxInitDialogEvent& WXUNUSED(evt) )
1127 // This function exists solely to avoid automatic transfer-to-widget calls
1131 void PrefsUnifiedDlg::OnScrollBarChange( wxScrollEvent& event )
1133 int id = 0;
1134 wxString label;
1136 switch ( event.GetId() ) {
1137 case IDC_SLIDER:
1138 id = IDC_SLIDERINFO;
1139 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1140 theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(event.GetPosition());
1141 theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(event.GetPosition());
1142 break;
1144 case IDC_SLIDER3:
1145 id = IDC_SLIDERINFO3;
1146 label = CFormat(wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event.GetPosition())) % event.GetPosition();
1147 theApp->m_statistics->SetAverageMinutes(event.GetPosition());
1148 break;
1150 case IDC_SLIDER4:
1151 id = IDC_SLIDERINFO4;
1152 label = CFormat(_("Connections Graph Scale: %d")) % event.GetPosition();
1153 theApp->amuledlg->m_statisticswnd->GetConnScope()->SetRanges(0, event.GetPosition());
1154 break;
1156 case IDC_SLIDER2:
1157 id = IDC_SLIDERINFO2;
1158 label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition();
1159 break;
1161 case IDC_FILEBUFFERSIZE:
1162 id = IDC_FILEBUFFERSIZE_STATIC;
1163 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1164 label = CFormat(wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event.GetPosition() * 15000)) % (event.GetPosition() * 15000);
1165 break;
1167 case IDC_QUEUESIZE:
1168 id = IDC_QUEUESIZE_STATIC;
1169 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
1170 label = CFormat(wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event.GetPosition() * 100)) % (event.GetPosition() * 100);
1171 break;
1173 case IDC_SERVERKEEPALIVE:
1174 id = IDC_SERVERKEEPALIVE_LABEL;
1176 if ( event.GetPosition() ) {
1177 label = CFormat(wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event.GetPosition())) % event.GetPosition();
1178 } else {
1179 label = _("Server connection refresh interval: Disabled");
1181 break;
1183 default:
1184 return;
1187 wxStaticText* widget = CastChild( id, wxStaticText );
1189 if (widget) {
1190 widget->SetLabel( label );
1191 widget->GetParent()->Layout();
1196 void PrefsUnifiedDlg::OnRateLimitChanged( wxSpinEvent& event )
1198 // Here we do immediate sanity checking of the up/down ratio,
1199 // so that the user can see if his choice is illegal
1201 // We only do checks if the rate is limited
1202 if ( event.GetPosition() != (int)UNLIMITED ) {
1203 wxSpinCtrl* dlrate = CastChild( IDC_MAXDOWN, wxSpinCtrl );
1205 if ( event.GetPosition() < 4 ) {
1206 if ( ( event.GetPosition() * 3 < dlrate->GetValue() ) ||
1207 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1208 dlrate->SetValue( event.GetPosition() * 3 );
1210 } else if ( event.GetPosition() < 10 ) {
1211 if ( ( event.GetPosition() * 4 < dlrate->GetValue() ) ||
1212 ( dlrate->GetValue() == (int)UNLIMITED ) ) {
1213 dlrate->SetValue( event.GetPosition() * 4 );
1220 void PrefsUnifiedDlg::OnTCPClientPortChange(wxSpinEvent& WXUNUSED(event))
1222 CastChild(ID_TEXT_CLIENT_UDP_PORT, wxStaticText)->SetLabel(
1223 m_ServerTabVisible ? (wxString() << (CastChild(IDC_PORT, wxSpinCtrl)->GetValue() + 3))
1224 : wxString(_("disabled")));
1227 void PrefsUnifiedDlg::OnUserEventSelected(wxListEvent& event)
1229 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1230 IDC_PREFS_EVENTS_PAGE->Hide(i+1);
1233 IDC_PREFS_EVENTS_PAGE->Show((event.GetData() - USEREVENTS_FIRST_ID) / USEREVENTS_IDS_PER_EVENT + 1, true);
1235 IDC_PREFS_EVENTS_PAGE->Layout();
1237 event.Skip();
1240 void PrefsUnifiedDlg::OnLanguageChoice(wxCommandEvent &evt)
1242 thePrefs::GetCfgLang()->UpdateChoice(evt.GetSelection());
1245 void PrefsUnifiedDlg::CreateEventPanels(const int idx, const wxString& vars, wxWindow* parent)
1247 wxStaticBox *item8 = new wxStaticBox( parent, -1, CFormat(_("Execute command on '%s' event")) % wxGetTranslation(CUserEvents::GetDisplayName(static_cast<enum CUserEvents::EventType>(idx))) );
1248 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxVERTICAL );
1250 wxCheckBox *item9 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 1, _("Enable command execution on core"), wxDefaultPosition, wxDefaultSize, 0 );
1251 item7->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1253 wxFlexGridSizer *item10 = new wxFlexGridSizer( 3, 0, 0 );
1254 item10->AddGrowableCol( 2 );
1256 item10->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1258 wxStaticText *item11 = new wxStaticText( parent, -1, _("Core command:"), wxDefaultPosition, wxDefaultSize, 0 );
1259 item10->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
1261 wxTextCtrl *item12 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 2, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1262 item12->Enable(CUserEvents::IsCoreCommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1263 item10->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1265 item7->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1267 wxCheckBox *item14 = new wxCheckBox( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 3, _("Enable command execution on GUI"), wxDefaultPosition, wxDefaultSize, 0 );
1268 item7->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
1270 wxFlexGridSizer *item15 = new wxFlexGridSizer( 3, 0, 0 );
1271 item15->AddGrowableCol( 2 );
1273 item15->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 0 );
1275 wxStaticText *item16 = new wxStaticText( parent, -1, _("GUI command:"), wxDefaultPosition, wxDefaultSize, 0 );
1276 item15->Add( item16, 0, wxALIGN_CENTER|wxALL, 5 );
1278 wxTextCtrl *item17 = new wxTextCtrl( parent, USEREVENTS_FIRST_ID + idx * USEREVENTS_IDS_PER_EVENT + 4, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1279 item17->Enable(CUserEvents::IsGUICommandEnabled(static_cast<enum CUserEvents::EventType>(idx)));
1280 item15->Add( item17, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1282 item7->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
1284 wxStaticText *item13 = new wxStaticText( parent, -1, _("The following variables will be replaced:") + vars, wxDefaultPosition, wxDefaultSize, 0 );
1285 item7->Add( item13, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1287 IDC_PREFS_EVENTS_PAGE->Add(item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
1289 IDC_PREFS_EVENTS_PAGE->Layout();
1290 IDC_PREFS_EVENTS_PAGE->Hide(idx + 1);
1292 // File_checked_for_headers