2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2008 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>
31 #include <wx/colordlg.h>
32 #include <wx/tooltip.h>
34 #include "amule.h" // Needed for theApp
36 #include "MuleColour.h"
37 #include "EditServerListDlg.h"
38 #include "SharedFileList.h" // Needed for CSharedFileList
39 #include "StatisticsDlg.h" // Needed for graph parameters, colors
40 #include "IPFilter.h" // Needed for CIPFilter
41 #include "SearchList.h"
42 #include "ClientList.h"
43 #include "DirectoryTreeCtrl.h" // Needed for CDirectoryTreeCtrl
44 #include "Preferences.h"
45 #include "muuli_wdr.h"
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 "UserEvents.h"
54 BEGIN_EVENT_TABLE(PrefsUnifiedDlg
,wxDialog
)
56 #define USEREVENTS_EVENT(ID, NAME, VARS) \
57 EVT_CHECKBOX(USEREVENTS_FIRST_ID + CUserEvents::ID * USEREVENTS_IDS_PER_EVENT + 1, PrefsUnifiedDlg::OnCheckBoxChange) \
58 EVT_CHECKBOX(USEREVENTS_FIRST_ID + CUserEvents::ID * USEREVENTS_IDS_PER_EVENT + 3, PrefsUnifiedDlg::OnCheckBoxChange)
59 USEREVENTS_EVENTLIST()
60 #undef USEREVENTS_EVENT
63 EVT_CHECKBOX(ID_PROXY_ENABLE_PROXY
, PrefsUnifiedDlg::OnCheckBoxChange
)
64 EVT_CHECKBOX(ID_PROXY_ENABLE_PASSWORD
, PrefsUnifiedDlg::OnCheckBoxChange
)
65 // EVT_CHECKBOX(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, PrefsUnifiedDlg::OnCheckBoxChange)
68 EVT_SPINCTRL(IDC_PORT
, PrefsUnifiedDlg::OnTCPClientPortChange
)
70 // The rest. Organize it!
71 EVT_CHECKBOX(IDC_UDPENABLE
, PrefsUnifiedDlg::OnCheckBoxChange
)
72 EVT_CHECKBOX(IDC_CHECKDISKSPACE
, PrefsUnifiedDlg::OnCheckBoxChange
)
73 EVT_CHECKBOX(IDC_ONLINESIG
, PrefsUnifiedDlg::OnCheckBoxChange
)
74 EVT_CHECKBOX(IDC_REMOVEDEAD
, PrefsUnifiedDlg::OnCheckBoxChange
)
75 EVT_CHECKBOX(IDC_AUTOSERVER
, PrefsUnifiedDlg::OnCheckBoxChange
)
76 EVT_CHECKBOX(IDC_AUTOIPFILTER
, PrefsUnifiedDlg::OnCheckBoxChange
)
77 EVT_CHECKBOX(IDC_MSGFILTER
, PrefsUnifiedDlg::OnCheckBoxChange
)
78 EVT_CHECKBOX(IDC_MSGFILTER_ALL
, PrefsUnifiedDlg::OnCheckBoxChange
)
79 EVT_CHECKBOX(IDC_MSGFILTER_WORD
, PrefsUnifiedDlg::OnCheckBoxChange
)
80 EVT_CHECKBOX(IDC_FILTERCOMMENTS
, PrefsUnifiedDlg::OnCheckBoxChange
)
81 EVT_CHECKBOX(IDC_STARTNEXTFILE
, PrefsUnifiedDlg::OnCheckBoxChange
)
82 EVT_CHECKBOX(IDC_ENABLETRAYICON
, PrefsUnifiedDlg::OnCheckBoxChange
)
83 EVT_CHECKBOX(IDC_VERTTOOLBAR
, PrefsUnifiedDlg::OnCheckBoxChange
)
84 EVT_CHECKBOX(IDC_SUPPORT_PO
, PrefsUnifiedDlg::OnCheckBoxChange
)
85 EVT_CHECKBOX(IDC_ENABLE_PO_OUTGOING
, PrefsUnifiedDlg::OnCheckBoxChange
)
86 EVT_CHECKBOX(IDC_ENFORCE_PO_INCOMING
, PrefsUnifiedDlg::OnCheckBoxChange
)
87 EVT_CHECKBOX(IDC_SHOWRATEONTITLE
, PrefsUnifiedDlg::OnCheckBoxChange
)
89 EVT_BUTTON(ID_PREFS_OK_TOP
, PrefsUnifiedDlg::OnOk
)
90 EVT_BUTTON(ID_PREFS_CANCEL_TOP
, PrefsUnifiedDlg::OnCancel
)
93 // EVT_BUTTON(IDC_SELSKIN, PrefsUnifiedDlg::OnButtonDir)
94 EVT_BUTTON(IDC_BROWSEV
, PrefsUnifiedDlg::OnButtonBrowseApplication
)
95 EVT_BUTTON(IDC_SELTEMPDIR
, PrefsUnifiedDlg::OnButtonDir
)
96 EVT_BUTTON(IDC_SELINCDIR
, PrefsUnifiedDlg::OnButtonDir
)
97 EVT_BUTTON(IDC_SELOSDIR
, PrefsUnifiedDlg::OnButtonDir
)
98 EVT_BUTTON(IDC_SELBROWSER
, PrefsUnifiedDlg::OnButtonBrowseApplication
)
100 EVT_SPINCTRL(IDC_TOOLTIPDELAY
, PrefsUnifiedDlg::OnToolTipDelayChange
)
102 EVT_BUTTON(IDC_EDITADR
, PrefsUnifiedDlg::OnButtonEditAddr
)
103 EVT_BUTTON(IDC_IPFRELOAD
, PrefsUnifiedDlg::OnButtonIPFilterReload
)
104 EVT_BUTTON(IDC_COLOR_BUTTON
, PrefsUnifiedDlg::OnButtonColorChange
)
105 EVT_BUTTON(IDC_IPFILTERUPDATE
, PrefsUnifiedDlg::OnButtonIPFilterUpdate
)
106 EVT_CHOICE(IDC_COLORSELECTOR
, PrefsUnifiedDlg::OnColorCategorySelected
)
107 EVT_LIST_ITEM_SELECTED(ID_PREFSLISTCTRL
,PrefsUnifiedDlg::OnPrefsPageChange
)
109 EVT_INIT_DIALOG(PrefsUnifiedDlg::OnInitDialog
)
111 EVT_COMMAND_SCROLL(IDC_SLIDER
, PrefsUnifiedDlg::OnScrollBarChange
)
112 EVT_COMMAND_SCROLL(IDC_SLIDER3
, PrefsUnifiedDlg::OnScrollBarChange
)
113 EVT_COMMAND_SCROLL(IDC_SLIDER4
, PrefsUnifiedDlg::OnScrollBarChange
)
114 EVT_COMMAND_SCROLL(IDC_SLIDER2
, PrefsUnifiedDlg::OnScrollBarChange
)
115 EVT_COMMAND_SCROLL(IDC_FILEBUFFERSIZE
, PrefsUnifiedDlg::OnScrollBarChange
)
116 EVT_COMMAND_SCROLL(IDC_QUEUESIZE
, PrefsUnifiedDlg::OnScrollBarChange
)
117 EVT_COMMAND_SCROLL(IDC_SERVERKEEPALIVE
, PrefsUnifiedDlg::OnScrollBarChange
)
119 EVT_SPINCTRL(IDC_MAXUP
, PrefsUnifiedDlg::OnRateLimitChanged
)
121 EVT_LIST_ITEM_SELECTED(IDC_EVENTLIST
, PrefsUnifiedDlg::OnUserEventSelected
)
123 EVT_CLOSE(PrefsUnifiedDlg::OnClose
)
129 * Creates an command-event for the given checkbox.
131 * This can be used enforce logical constraints by passing by
132 * sending a check-box event for each checkbox, when transfering
133 * to the UI. However, it should also be used for checkboxes that
134 * have no side-effects other than enabling/disabling other
135 * widgets in the preferences dialogs.
137 void SendCheckBoxEvent(wxWindow
* parent
, int id
)
139 wxCheckBox
* widget
= CastByID(id
, parent
, wxCheckBox
);
140 wxCHECK_RET(widget
, wxT("Invalid widget in CreateEvent"));
142 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
, id
);
143 evt
.SetInt(widget
->IsChecked() ? 1 : 0);
145 parent
->ProcessEvent(evt
);
151 * This struct provides a general way to represent config-tabs.
155 //! The title of the page, used on the listctrl.
157 //! Function pointer to the wxDesigner function creating the dialog.
158 wxSizer
* (*m_function
)(wxWindow
*, bool, bool );
159 //! The index of the image used on the list.
161 //! The actual widget. To be set later.
168 { wxTRANSLATE("General"), PreferencesGeneralTab
, 13, NULL
},
169 { wxTRANSLATE("Connection"), PreferencesConnectionTab
, 14, NULL
},
170 { wxTRANSLATE("Directories"), PreferencesDirectoriesTab
, 17, NULL
},
171 { wxTRANSLATE("Servers"), PreferencesServerTab
, 15, NULL
},
172 { wxTRANSLATE("Files"), PreferencesFilesTab
, 16, NULL
},
173 { wxTRANSLATE("Security"), PreferencesSecurityTab
, 22, NULL
},
174 { wxTRANSLATE("Interface"), PreferencesGuiTweaksTab
, 19, NULL
},
175 { wxTRANSLATE("Statistics"), PreferencesStatisticsTab
, 10, NULL
},
176 { wxTRANSLATE("Proxy"), PreferencesProxyTab
, 24, NULL
},
177 { wxTRANSLATE("Filters"), PreferencesFilteringTab
, 23, NULL
},
178 { wxTRANSLATE("Remote Controls"), PreferencesRemoteControlsTab
, 11, NULL
},
179 { wxTRANSLATE("Online Signature"), PreferencesOnlineSigTab
, 21, NULL
},
180 { wxTRANSLATE("Advanced"), PreferencesaMuleTweaksTab
, 12, NULL
},
181 { wxTRANSLATE("Events"), PreferencesEventsTab
, 5, NULL
}
183 ,{ wxTRANSLATE("Debugging"), PreferencesDebug
, 25, NULL
}
188 PrefsUnifiedDlg::PrefsUnifiedDlg(wxWindow
*parent
)
190 wxDialog(parent
, -1, _("Preferences"),
191 wxDefaultPosition
, wxDefaultSize
,
192 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
)
194 preferencesDlgTop(this, false);
196 wxListCtrl
*PrefsIcons
= CastChild(ID_PREFSLISTCTRL
, wxListCtrl
);
197 wxImageList
*icon_list
= new wxImageList(16, 16);
198 PrefsIcons
->AssignImageList(icon_list
, wxIMAGE_LIST_SMALL
);
200 // Add the single column used
201 PrefsIcons
->InsertColumn(
202 0, wxEmptyString
, wxLIST_FORMAT_LEFT
,
203 PrefsIcons
->GetSize().GetWidth()-5);
205 // Temp variables for finding the smallest height and width needed
209 // Add each page to the page-list
210 for (unsigned int i
= 0; i
< itemsof(pages
); ++i
) {
211 // Add the icon and label assosiated with the page
212 icon_list
->Add(amuleSpecial(pages
[i
].m_imageidx
));
213 PrefsIcons
->InsertItem(i
, wxGetTranslation(pages
[i
].m_title
), i
);
216 // Set list-width so that there arn't any scrollers
217 PrefsIcons
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
218 PrefsIcons
->SetMinSize(wxSize(PrefsIcons
->GetColumnWidth(0) + 10, -1));
219 PrefsIcons
->SetMaxSize(wxSize(PrefsIcons
->GetColumnWidth(0) + 10, -1));
221 // Now add the pages and calculate the minimum size
222 for (unsigned int i
= 0; i
< itemsof(pages
); ++i
) {
223 // Create a container widget and the contents of the page
224 pages
[i
].m_widget
= new wxPanel(this, -1);
225 pages
[i
].m_function(pages
[i
].m_widget
, true, true);
227 // Add it to the sizer
228 prefs_sizer
->Add(pages
[i
].m_widget
, 0, wxGROW
|wxEXPAND
);
230 if (pages
[i
].m_function
== PreferencesGeneralTab
) {
231 // This must be done now or pages won't Fit();
233 CastChild(IDC_BROWSERTABS
, wxCheckBox
)->Enable(false);
234 #endif /* __WXMSW__ */
235 } else if (pages
[i
].m_function
== PreferencesEventsTab
) {
237 #define USEREVENTS_REPLACE_VAR(VAR, DESC, CODE) + wxString(wxT("\n %") VAR wxT(" - ")) + wxGetTranslation(DESC)
238 #define USEREVENTS_EVENT(ID, NAME, VARS) case CUserEvents::ID: CreateEventPanels(idx, wxEmptyString VARS, pages[i].m_widget); break;
240 wxListCtrl
*list
= CastChild(IDC_EVENTLIST
, wxListCtrl
);
241 list
->InsertColumn(0, wxEmptyString
);
242 for (unsigned int idx
= 0; idx
< CUserEvents::GetCount(); ++idx
) {
243 long lidx
= list
->InsertItem(idx
,
244 wxGetTranslation(CUserEvents::GetDisplayName(
245 static_cast<enum CUserEvents::EventType
>(idx
))));
247 list
->SetItemData(lidx
,
248 USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
);
250 USEREVENTS_EVENTLIST()
254 list
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
257 else if (pages
[i
].m_function
== PreferencesDebug
) {
258 int count
= CLogger::GetDebugCategoryCount();
259 wxCheckListBox
* list
= CastChild( ID_DEBUGCATS
, wxCheckListBox
);
261 for ( int j
= 0; j
< count
; j
++ ) {
262 list
->Append( CLogger::GetDebugCategory( j
).GetName() );
267 // Align and resize the page
271 // Find the greatest sizes
272 wxSize size
= prefs_sizer
->GetSize();
273 if (size
.GetWidth() > width
) {
274 width
= size
.GetWidth();
277 if (size
.GetHeight() > height
) {
278 height
= size
.GetHeight();
282 prefs_sizer
->Detach(pages
[i
].m_widget
);
283 pages
[i
].m_widget
->Show(false);
286 // Default to the General tab
287 m_CurrentPanel
= pages
[0].m_widget
;
288 prefs_sizer
->Add(pages
[0].m_widget
, 0, wxGROW
|wxEXPAND
);
289 m_CurrentPanel
->Show( true );
291 // Select the first item
292 PrefsIcons
->SetItemState(0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
294 // We now have the needed minimum height and width
295 prefs_sizer
->SetMinSize(width
, height
);
297 // Store some often used pointers
298 m_ShareSelector
= CastChild(IDC_SHARESELECTOR
, CDirectoryTreeCtrl
);
299 m_buttonColor
= CastChild(IDC_COLOR_BUTTON
, wxButton
);
300 m_choiceColor
= CastChild(IDC_COLORSELECTOR
, wxChoice
);
302 // Connect the Cfgs with their widgets
303 thePrefs::CFGMap::iterator it
= thePrefs::s_CfgList
.begin();
304 for ( ; it
!= thePrefs::s_CfgList
.end(); ++it
) {
305 // Checking for failures
306 if ( !it
->second
->ConnectToWidget(it
->first
, this) ) {
307 printf("Failed to connect Cfg to widget with the ID %d and key %s\n",
308 it
->first
, (const char *)unicode2char(it
->second
->GetKey()));
313 // It must not be resized to something smaller than what it currently is
314 wxSize size
= GetClientSize();
315 SetSizeHints(size
.GetWidth(), size
.GetHeight());
318 FindWindow(IDC_VERTTOOLBAR
)->Enable(false);
321 // Position the dialog.
326 Cfg_Base
* PrefsUnifiedDlg::GetCfg(int id
)
328 thePrefs::CFGMap::iterator it
= thePrefs::s_CfgList
.find( id
);
330 if ( it
!= thePrefs::s_CfgList
.end() ) {
338 bool PrefsUnifiedDlg::TransferToWindow()
340 // Connect the Cfgs with their widgets
341 thePrefs::CFGMap::iterator it
= thePrefs::s_CfgList
.begin();
342 for ( ; it
!= thePrefs::s_CfgList
.end(); ++it
) {
343 // Checking for failures
344 if ( !it
->second
->TransferToWindow() ) {
345 printf("Failed to transfer data from Cfg to Widget with the ID %d and key %s\n",
346 it
->first
, (const char *)unicode2char(it
->second
->GetKey()));
350 m_ShareSelector
->SetSharedDirectories(&theApp
->glob_prefs
->shareddir_list
);
352 for ( int i
= 0; i
< cntStatColors
; i
++ ) {
353 thePrefs::s_colors
[i
] = CMuleColour(CStatisticsDlg::acrStat
[i
]).GetULong();
354 thePrefs::s_colors_ref
[i
] = CMuleColour(CStatisticsDlg::acrStat
[i
]).GetULong();
359 OnTCPClientPortChange(e
);
361 // Proxy tab initialization
362 if (!CastChild(ID_PROXY_ENABLE_PROXY
, wxCheckBox
)->IsChecked()) {
363 FindWindow(ID_PROXY_TYPE
)->Enable(false);
364 FindWindow(ID_PROXY_NAME
)->Enable(false);
365 FindWindow(ID_PROXY_PORT
)->Enable(false);
367 if (!CastChild(ID_PROXY_ENABLE_PASSWORD
, wxCheckBox
)->IsChecked()) {
368 FindWindow(ID_PROXY_USER
)->Enable(false);
369 FindWindow(ID_PROXY_PASSWORD
)->Enable(false);
371 // This option from the proxy tab is currently unused
372 FindWindow(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY
)->Enable(false);
374 // Enable/Disable some controls
375 FindWindow( IDC_MINDISKSPACE
)->Enable( thePrefs::IsCheckDiskspaceEnabled() );
376 FindWindow( IDC_OSDIR
)->Enable( thePrefs::IsOnlineSignatureEnabled() );
377 FindWindow( IDC_OSUPDATE
)->Enable( thePrefs::IsOnlineSignatureEnabled() );
378 FindWindow( IDC_UDPPORT
)->Enable( thePrefs::s_UDPEnable
);
379 FindWindow( IDC_SERVERRETRIES
)->Enable( thePrefs::DeadServer() );
380 FindWindow( IDC_STARTNEXTFILE_SAME
)->Enable(thePrefs::StartNextFile());
383 FindWindow(IDC_ENABLETRAYICON
)->Enable(false);
384 FindWindow(IDC_MINTRAY
)->Enable(false);
386 FindWindow(IDC_MINTRAY
)->Enable(thePrefs::UseTrayIcon());
389 if (!CastChild(IDC_MSGFILTER
, wxCheckBox
)->IsChecked()) {
390 FindWindow(IDC_MSGFILTER_ALL
)->Enable(false);
391 FindWindow(IDC_MSGFILTER_NONSECURE
)->Enable(false);
392 FindWindow(IDC_MSGFILTER_NONFRIENDS
)->Enable(false);
393 FindWindow(IDC_MSGFILTER_WORD
)->Enable(false);
394 FindWindow(IDC_MSGWORD
)->Enable(false);
395 } else if (CastChild(IDC_MSGFILTER_ALL
, wxCheckBox
)->IsChecked()) {
396 FindWindow(IDC_MSGFILTER_NONSECURE
)->Enable(false);
397 FindWindow(IDC_MSGFILTER_NONFRIENDS
)->Enable(false);
398 FindWindow(IDC_MSGFILTER_WORD
)->Enable(false);
399 FindWindow(IDC_MSGWORD
)->Enable(false);
402 FindWindow(IDC_MSGWORD
)->Enable(CastChild(IDC_MSGFILTER_WORD
, wxCheckBox
)->IsChecked());
403 FindWindow(IDC_COMMENTWORD
)->Enable(CastChild(IDC_FILTERCOMMENTS
, wxCheckBox
)->IsChecked());
405 // Protocol obfuscation
406 ::SendCheckBoxEvent(this, IDC_SUPPORT_PO
);
407 ::SendCheckBoxEvent(this, IDC_ENABLE_PO_OUTGOING
);
408 ::SendCheckBoxEvent(this, IDC_ENFORCE_PO_INCOMING
);
410 // Show rates on title
411 FindWindow(IDC_RATESBEFORETITLE
)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
412 FindWindow(IDC_RATESAFTERTITLE
)->Enable(thePrefs::GetShowRatesOnTitle() != 0);
413 CastChild(IDC_SHOWRATEONTITLE
, wxCheckBox
)->SetValue(thePrefs::GetShowRatesOnTitle() != 0);
414 CastChild(IDC_RATESBEFORETITLE
, wxRadioButton
)->SetValue(thePrefs::GetShowRatesOnTitle() == 2);
415 CastChild(IDC_RATESAFTERTITLE
, wxRadioButton
)->SetValue(thePrefs::GetShowRatesOnTitle() != 2);
418 // Set debugging toggles
419 int count
= CLogger::GetDebugCategoryCount();
420 wxCheckListBox
* list
= CastChild( ID_DEBUGCATS
, wxCheckListBox
);
422 for ( int i
= 0; i
< count
; i
++ ) {
423 list
->Check( i
, CLogger::GetDebugCategory( i
).IsEnabled() );
431 bool PrefsUnifiedDlg::TransferFromWindow()
433 // Connect the Cfgs with their widgets
434 thePrefs::CFGMap::iterator it
= thePrefs::s_CfgList
.begin();
435 for ( ; it
!= thePrefs::s_CfgList
.end(); ++it
) {
436 // Checking for failures
437 if ( !it
->second
->TransferFromWindow() ) {
438 printf("Failed to transfer data from Widget to Cfg with the ID %d and key %s\n",
439 it
->first
, (const char *)unicode2char(it
->second
->GetKey()));
443 theApp
->glob_prefs
->shareddir_list
.clear();
444 m_ShareSelector
->GetSharedDirectories(&theApp
->glob_prefs
->shareddir_list
);
446 for ( int i
= 0; i
< cntStatColors
; i
++ ) {
447 if ( thePrefs::s_colors
[i
] != thePrefs::s_colors_ref
[i
] ) {
448 CStatisticsDlg::acrStat
[i
] = thePrefs::s_colors
[i
];
449 theApp
->amuledlg
->m_statisticswnd
->ApplyStatsColor(i
);
452 theApp
->amuledlg
->m_kademliawnd
->SetGraphColors();
456 // Get debugging toggles
457 int count
= CLogger::GetDebugCategoryCount();
458 wxCheckListBox
* list
= CastChild( ID_DEBUGCATS
, wxCheckListBox
);
460 for ( int i
= 0; i
< count
; i
++ ) {
461 CLogger::SetEnabled( CLogger::GetDebugCategory( i
).GetType(), list
->IsChecked( i
) );
465 thePrefs::SetShowRatesOnTitle(CastChild(IDC_SHOWRATEONTITLE
, wxCheckBox
)->GetValue() ? (CastChild(IDC_RATESBEFORETITLE
, wxRadioButton
)->GetValue() ? 2 : 1) : 0);
468 // Send preferences to core.
469 theApp
->glob_prefs
->SendToRemote();
476 bool PrefsUnifiedDlg::CfgChanged(int ID
)
478 Cfg_Base
* cfg
= GetCfg(ID
);
481 return cfg
->HasChanged();
488 void PrefsUnifiedDlg::OnOk(wxCommandEvent
& WXUNUSED(event
))
490 TransferFromWindow();
492 bool restart_needed
= false;
493 wxString restart_needed_msg
= _("aMule must be restarted to enable these changes:\n\n");
495 // do sanity checking, special processing, and user notifications here
496 thePrefs::CheckUlDlRatio();
498 if (CfgChanged(IDC_PORT
)) {
499 restart_needed
= true;
500 restart_needed_msg
+= _("- TCP port changed.\n");
503 if (CfgChanged(IDC_UDPPORT
)) {
504 restart_needed
= true;
505 restart_needed_msg
+= _("- UDP port changed.\n");
508 // Force port checking
509 thePrefs::SetPort(thePrefs::GetPort());
511 if ((CPath::GetFileSize(theApp
->ConfigDir
+ wxT("addresses.dat")) == 0) &&
512 CastChild(IDC_AUTOSERVER
, wxCheckBox
)->IsChecked() ) {
513 thePrefs::UnsetAutoServerStart();
514 wxMessageBox(_("Your Auto-update server list is empty.\n'Auto-update server list at startup' will be disabled."),
515 _("Message"), wxOK
| wxICON_INFORMATION
, this);
518 if (thePrefs::AcceptExternalConnections() && thePrefs::ECPassword().IsEmpty()) {
519 thePrefs::EnableExternalConnections( false );
521 wxMessageBox( _("You have enabled external connections but have not specified a password.\nExternal connections cannot be enabled unless a valid password is specified."));
524 // save the preferences on ok
525 theApp
->glob_prefs
->Save();
527 if (CfgChanged(IDC_FED2KLH
) && theApp
->amuledlg
->GetActiveDialog() != CamuleDlg::DT_SEARCH_WND
) {
528 theApp
->amuledlg
->ShowED2KLinksHandler( thePrefs::GetFED2KLH() );
531 if (CfgChanged(IDC_LANGUAGE
)) {
532 restart_needed
= true;
533 restart_needed_msg
+= _("- Language changed.\n");
536 if (CfgChanged(IDC_TEMPFILES
)) {
537 restart_needed
= true;
538 restart_needed_msg
+= _("- Temp folder changed.\n");
541 if (CfgChanged(IDC_INCFILES
) || CfgChanged(IDC_TEMPFILES
) || m_ShareSelector
->HasChanged
) {
542 theApp
->sharedfiles
->Reload();
545 if (CfgChanged(IDC_OSDIR
) || CfgChanged(IDC_ONLINESIG
)) {
546 wxTextCtrl
* widget
= CastChild( IDC_OSDIR
, wxTextCtrl
);
548 // Build the filenames for the two OS files
549 theApp
->SetOSFiles( widget
->GetValue() );
552 if (CfgChanged(IDC_IPFCLIENTS
) || CfgChanged(IDC_IPFSERVERS
) || CfgChanged(ID_IPFILTERLEVEL
)) {
553 if (thePrefs::IsFilteringClients()) {
554 theApp
->clientlist
->FilterQueues();
556 if (thePrefs::IsFilteringServers()) {
557 theApp
->serverlist
->FilterServers();
561 if (thePrefs::GetShowRatesOnTitle()) {
562 // This avoids a 5 seconds delay to show the title
563 theApp
->amuledlg
->ShowTransferRate();
565 // This resets the title
566 theApp
->amuledlg
->SetTitle(theApp
->m_FrameTitle
);
569 if (CfgChanged(IDC_EXTCATINFO
)) {
570 theApp
->amuledlg
->m_transferwnd
->UpdateCatTabTitles();
573 // Changes related to the statistics-dlg
574 if (CfgChanged(IDC_SLIDER
)) {
575 theApp
->amuledlg
->m_statisticswnd
->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
576 theApp
->amuledlg
->m_kademliawnd
->SetUpdatePeriod(thePrefs::GetTrafficOMeterInterval());
579 if ( CfgChanged(IDC_SLIDER3
) ) {
580 theApp
->amuledlg
->m_statisticswnd
->ResetAveragingTime();
583 if (CfgChanged(IDC_DOWNLOAD_CAP
)) {
584 theApp
->amuledlg
->m_statisticswnd
->SetARange( true, thePrefs::GetMaxGraphDownloadRate() );
587 if (CfgChanged(IDC_UPLOAD_CAP
)) {
588 theApp
->amuledlg
->m_statisticswnd
->SetARange( false, thePrefs::GetMaxGraphUploadRate() );
591 if (CfgChanged(IDC_SKIN
)) {
592 theApp
->amuledlg
->Create_Toolbar(thePrefs::VerticalToolbar());
595 if (!thePrefs::GetNetworkED2K() && theApp
->IsConnectedED2K()) {
596 theApp
->DisconnectED2K();
599 if (!thePrefs::GetNetworkKademlia() && theApp
->IsConnectedKad()) {
603 if (!thePrefs::GetNetworkED2K() && !thePrefs::GetNetworkKademlia()) {
605 _("Both eD2k and Kad network are disabled.\nYou won't be able to connect until you enable at least one of them."));
608 if (thePrefs::GetNetworkKademlia() && thePrefs::IsUDPDisabled()) {
609 wxMessageBox(_("Kad will not start if your UDP port is disabled.\nEnable UDP port or disable Kad."),
610 _("Message"), wxOK
| wxICON_INFORMATION
, this);
613 if (CfgChanged(IDC_NETWORKKAD
) || CfgChanged(IDC_NETWORKED2K
)) {
614 theApp
->amuledlg
->DoNetworkRearrange();
617 if (restart_needed
) {
618 wxMessageBox(restart_needed_msg
+ _("\nYou MUST restart aMule now.\nIf you do not restart now, don't complain if anything bad happens.\n"), _("WARNING"),wxICON_EXCLAMATION
,this);
625 void PrefsUnifiedDlg::OnClose(wxCloseEvent
& event
)
629 // Try to keep the window alive when possible
630 if (event
.CanVeto()) {
633 if (theApp
->amuledlg
) {
634 theApp
->amuledlg
->m_prefsDialog
= NULL
;
637 // Un-Connect the Cfgs
638 thePrefs::CFGMap::iterator it
= thePrefs::s_CfgList
.begin();
639 for (; it
!= thePrefs::s_CfgList
.end(); ++it
) {
640 // Checking for failures
641 it
->second
->ConnectToWidget( 0 );
649 void PrefsUnifiedDlg::OnCancel(wxCommandEvent
& WXUNUSED(event
))
655 void PrefsUnifiedDlg::OnCheckBoxChange(wxCommandEvent
& event
)
657 bool value
= event
.IsChecked();
658 int id
= event
.GetId();
660 // Check if this checkbox is one of the User Events checkboxes
661 if (id
>= USEREVENTS_FIRST_ID
&&
662 id
< USEREVENTS_FIRST_ID
+
663 (int)CUserEvents::GetCount() * USEREVENTS_IDS_PER_EVENT
) {
664 // The corresponding text control always has
665 // an ID one greater than the checkbox
666 FindWindow(id
+ 1)->Enable(value
);
672 FindWindow( IDC_UDPPORT
)->Enable(value
);
675 case IDC_CHECKDISKSPACE
:
676 FindWindow( IDC_MINDISKSPACE
)->Enable(value
);
680 FindWindow( IDC_OSDIR
)->Enable(value
);;
681 FindWindow(IDC_OSUPDATE
)->Enable(value
);
685 FindWindow( IDC_SERVERRETRIES
)->Enable(value
);;
689 if ((CPath::GetFileSize(theApp
->ConfigDir
+ wxT("addresses.dat")) == 0) &&
690 CastChild(event
.GetId(), wxCheckBox
)->IsChecked() ) {
691 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."),
692 _("Message"), wxOK
| wxICON_INFORMATION
);
693 CastChild(event
.GetId(), wxCheckBox
)->SetValue(false);
698 // Toogle All filter options
699 FindWindow(IDC_MSGFILTER_ALL
)->Enable(value
);
700 FindWindow(IDC_MSGFILTER_NONSECURE
)->Enable(value
);
701 FindWindow(IDC_MSGFILTER_NONFRIENDS
)->Enable(value
);
702 FindWindow(IDC_MSGFILTER_WORD
)->Enable(value
);
704 FindWindow(IDC_MSGWORD
)->Enable(
705 CastChild(IDC_MSGFILTER_WORD
, wxCheckBox
)->IsChecked());
707 FindWindow(IDC_MSGWORD
)->Enable(false);
711 case IDC_MSGFILTER_ALL
:
712 // Toogle filtering by data.
713 FindWindow(IDC_MSGFILTER_NONSECURE
)->Enable(!value
);
714 FindWindow(IDC_MSGFILTER_NONFRIENDS
)->Enable(!value
);
715 FindWindow(IDC_MSGFILTER_WORD
)->Enable(!value
);
717 FindWindow(IDC_MSGWORD
)->Enable(
718 CastChild(IDC_MSGFILTER_WORD
, wxCheckBox
)->IsChecked());
720 FindWindow(IDC_MSGWORD
)->Enable(false);
724 case IDC_MSGFILTER_WORD
:
725 // Toogle filter word list.
726 FindWindow(IDC_MSGWORD
)->Enable(value
);
729 case IDC_FILTERCOMMENTS
:
730 FindWindow(IDC_COMMENTWORD
)->Enable(value
);
733 case ID_PROXY_ENABLE_PROXY
:
734 FindWindow(ID_PROXY_TYPE
)->Enable(value
);
735 FindWindow(ID_PROXY_NAME
)->Enable(value
);
736 FindWindow(ID_PROXY_PORT
)->Enable(value
);
739 case ID_PROXY_ENABLE_PASSWORD
:
740 FindWindow(ID_PROXY_USER
)->Enable(value
);
741 FindWindow(ID_PROXY_PASSWORD
)->Enable(value
);
744 case IDC_STARTNEXTFILE
:
745 FindWindow(IDC_STARTNEXTFILE_SAME
)->Enable(value
);
748 case IDC_ENABLETRAYICON
:
749 FindWindow(IDC_MINTRAY
)->Enable(value
);
751 theApp
->amuledlg
->CreateSystray();
753 theApp
->amuledlg
->RemoveSystray();
755 thePrefs::SetUseTrayIcon(value
);
758 case ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY
:
761 case IDC_VERTTOOLBAR
:
762 theApp
->amuledlg
->Create_Toolbar(value
);
763 // Update the first tool (conn button)
764 theApp
->amuledlg
->ShowConnectionState();
767 case IDC_ENFORCE_PO_INCOMING
:
768 FindWindow(IDC_ENABLE_PO_OUTGOING
)->Enable(!value
);
771 case IDC_ENABLE_PO_OUTGOING
:
772 FindWindow(IDC_SUPPORT_PO
)->Enable(!value
);
773 FindWindow(IDC_ENFORCE_PO_INCOMING
)->Enable(value
);
777 FindWindow(IDC_ENABLE_PO_OUTGOING
)->Enable(value
);
780 case IDC_SHOWRATEONTITLE
:
781 FindWindow(IDC_RATESBEFORETITLE
)->Enable(value
);
782 FindWindow(IDC_RATESAFTERTITLE
)->Enable(value
);
791 void PrefsUnifiedDlg::OnButtonColorChange(wxCommandEvent
& WXUNUSED(event
))
793 int index
= m_choiceColor
->GetSelection();
794 wxColour col
= wxGetColourFromUser( this, CMuleColour(thePrefs::s_colors
[index
]) );
796 m_buttonColor
->SetBackgroundColour( col
);
797 thePrefs::s_colors
[index
] = CMuleColour(col
).GetULong();
802 void PrefsUnifiedDlg::OnColorCategorySelected(wxCommandEvent
& WXUNUSED(evt
))
804 m_buttonColor
->SetBackgroundColour(CMuleColour(thePrefs::s_colors
[ m_choiceColor
->GetSelection() ] ) );
808 void PrefsUnifiedDlg::OnButtonDir(wxCommandEvent
& event
)
813 switch ( event
.GetId() ) {
816 type
= _("Temporary files");
821 type
= _("Incoming files");
826 type
= _("Online Signatures");
831 // type = _("Skins directory");
839 type
= CFormat(_("Choose a folder for %s")) % type
;
840 wxTextCtrl
* widget
= CastChild( id
, wxTextCtrl
);
841 wxString dir
= widget
->GetValue();
842 wxString str
= wxDirSelector(
845 wxDefaultPosition
, this);
846 if (!str
.IsEmpty()) {
847 widget
->SetValue(str
);
852 void PrefsUnifiedDlg::OnButtonBrowseApplication(wxCommandEvent
& event
)
856 switch ( event
.GetId() ) {
858 id
= IDC_VIDEOPLAYER
;
859 title
= _("Browse for videoplayer");
862 id
= IDC_BROWSERSELF
;
863 title
= _("Select browser");
869 wxString wildcard
= CFormat(_("Executable%s"))
871 % wxT(" (*.exe)|*.exe");
876 wxString str
= wxFileSelector( title
, wxEmptyString
, wxEmptyString
,
877 wxEmptyString
, wildcard
, 0, this );
879 if ( !str
.IsEmpty() ) {
880 wxTextCtrl
* widget
= CastChild( id
, wxTextCtrl
);
881 widget
->SetValue( str
);
886 void PrefsUnifiedDlg::OnButtonEditAddr(wxCommandEvent
& WXUNUSED(evt
))
888 wxString
fullpath( theApp
->ConfigDir
+ wxT("addresses.dat") );
890 EditServerListDlg
* test
= new EditServerListDlg(this, _("Edit server list"),
891 _("Add here URL's to download server.met files.\nOnly one url on each line."),
899 void PrefsUnifiedDlg::OnButtonIPFilterReload(wxCommandEvent
& WXUNUSED(event
))
901 theApp
->ipfilter
->Reload();
905 void PrefsUnifiedDlg::OnButtonIPFilterUpdate(wxCommandEvent
& WXUNUSED(event
))
907 theApp
->ipfilter
->Update( CastChild( IDC_IPFILTERURL
, wxTextCtrl
)->GetValue() );
911 void PrefsUnifiedDlg::OnPrefsPageChange(wxListEvent
& event
)
913 prefs_sizer
->Detach( m_CurrentPanel
);
914 m_CurrentPanel
->Show( false );
916 m_CurrentPanel
= pages
[ event
.GetIndex() ].m_widget
;
918 prefs_sizer
->Add( m_CurrentPanel
, 0, wxGROW
|wxEXPAND
);
919 m_CurrentPanel
->Show( true );
927 void PrefsUnifiedDlg::OnToolTipDelayChange(wxSpinEvent
& event
)
929 wxToolTip::SetDelay( event
.GetPosition() * 1000 );
933 void PrefsUnifiedDlg::OnInitDialog( wxInitDialogEvent
& WXUNUSED(evt
) )
935 // This function exists solely to avoid automatic transfer-to-widget calls
939 void PrefsUnifiedDlg::OnScrollBarChange( wxScrollEvent
& event
)
944 switch ( event
.GetId() ) {
947 label
= wxString::Format( wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event
.GetPosition()), event
.GetPosition() );
948 theApp
->amuledlg
->m_statisticswnd
->SetUpdatePeriod(event
.GetPosition());
949 theApp
->amuledlg
->m_kademliawnd
->SetUpdatePeriod(event
.GetPosition());
953 id
= IDC_SLIDERINFO3
;
954 label
= wxString::Format( wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event
.GetPosition()), event
.GetPosition() );
955 theApp
->m_statistics
->SetAverageMinutes(event
.GetPosition());
959 id
= IDC_SLIDERINFO4
;
960 label
= wxString::Format( _("Connections Graph Scale: %d"), event
.GetPosition() );
961 theApp
->amuledlg
->m_statisticswnd
->GetConnScope()->SetRanges(0,event
.GetPosition());
965 id
= IDC_SLIDERINFO2
;
966 label
= wxString::Format( wxPLURAL("Update delay : %d second", "Update delay : %d seconds", event
.GetPosition()), event
.GetPosition() );
969 case IDC_FILEBUFFERSIZE
:
970 id
= IDC_FILEBUFFERSIZE_STATIC
;
971 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
972 label
= wxString::Format( wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event
.GetPosition() * 15000), event
.GetPosition() * 15000 );
976 id
= IDC_QUEUESIZE_STATIC
;
977 // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation
978 label
= wxString::Format( wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event
.GetPosition() * 100), event
.GetPosition() * 100 );
981 case IDC_SERVERKEEPALIVE
:
982 id
= IDC_SERVERKEEPALIVE_LABEL
;
984 if ( event
.GetPosition() ) {
985 label
= wxString::Format( wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event
.GetPosition()), event
.GetPosition() );
987 label
= wxString::Format( _("Server connection refresh interval: Disabled") );
995 wxStaticText
* widget
= CastChild( id
, wxStaticText
);
998 widget
->SetLabel( label
);
999 widget
->GetParent()->Layout();
1004 void PrefsUnifiedDlg::OnRateLimitChanged( wxSpinEvent
& event
)
1006 // Here we do immediate sainity checking of the up/down ratio,
1007 // so that the user can see if his choice is illegal
1009 // We only do checks if the rate is limited
1010 if ( event
.GetPosition() != (int)UNLIMITED
) {
1011 wxSpinCtrl
* dlrate
= CastChild( IDC_MAXDOWN
, wxSpinCtrl
);
1013 if ( event
.GetPosition() < 4 ) {
1014 if ( ( event
.GetPosition() * 3 < dlrate
->GetValue() ) ||
1015 ( dlrate
->GetValue() == (int)UNLIMITED
) ) {
1016 dlrate
->SetValue( event
.GetPosition() * 3 );
1018 } else if ( event
.GetPosition() < 10 ) {
1019 if ( ( event
.GetPosition() * 4 < dlrate
->GetValue() ) ||
1020 ( dlrate
->GetValue() == (int)UNLIMITED
) ) {
1021 dlrate
->SetValue( event
.GetPosition() * 4 );
1028 void PrefsUnifiedDlg::OnTCPClientPortChange(wxSpinEvent
& WXUNUSED(event
))
1030 CastChild(ID_TEXT_CLIENT_UDP_PORT
, wxStaticText
)->SetLabel(wxString() << (CastChild(IDC_PORT
, wxSpinCtrl
)->GetValue() + 3));
1033 void PrefsUnifiedDlg::OnUserEventSelected(wxListEvent
& event
)
1035 for (unsigned int i
= 0; i
< CUserEvents::GetCount(); ++i
) {
1036 IDC_PREFS_EVENTS_PAGE
->Hide(i
+1);
1039 IDC_PREFS_EVENTS_PAGE
->Show((event
.GetData() - USEREVENTS_FIRST_ID
) / USEREVENTS_IDS_PER_EVENT
+ 1, true);
1041 IDC_PREFS_EVENTS_PAGE
->Layout();
1046 void PrefsUnifiedDlg::CreateEventPanels(const int idx
, const wxString
& vars
, wxWindow
* parent
)
1048 wxStaticBox
*item8
= new wxStaticBox( parent
, -1, CFormat(_("Execute command on `%s' event")) % wxGetTranslation(CUserEvents::GetDisplayName(static_cast<enum CUserEvents::EventType
>(idx
))) );
1049 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxVERTICAL
);
1051 wxCheckBox
*item9
= new wxCheckBox( parent
, USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
+ 1, _("Enable command execution on core"), wxDefaultPosition
, wxDefaultSize
, 0 );
1052 item7
->Add( item9
, 0, wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
, 5 );
1054 wxFlexGridSizer
*item10
= new wxFlexGridSizer( 3, 0, 0 );
1055 item10
->AddGrowableCol( 2 );
1057 item10
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 0 );
1059 wxStaticText
*item11
= new wxStaticText( parent
, -1, _("Core command:"), wxDefaultPosition
, wxDefaultSize
, 0 );
1060 item10
->Add( item11
, 0, wxALIGN_CENTER
|wxALL
, 5 );
1062 wxTextCtrl
*item12
= new wxTextCtrl( parent
, USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
+ 2, wxT(""), wxDefaultPosition
, wxDefaultSize
, 0 );
1063 item12
->Enable(CUserEvents::IsCoreCommandEnabled(static_cast<enum CUserEvents::EventType
>(idx
)));
1064 item10
->Add( item12
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
1066 item7
->Add( item10
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 0 );
1068 wxCheckBox
*item14
= new wxCheckBox( parent
, USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
+ 3, _("Enable command execution on GUI"), wxDefaultPosition
, wxDefaultSize
, 0 );
1069 item7
->Add( item14
, 0, wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
, 5 );
1071 wxFlexGridSizer
*item15
= new wxFlexGridSizer( 3, 0, 0 );
1072 item15
->AddGrowableCol( 2 );
1074 item15
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 0 );
1076 wxStaticText
*item16
= new wxStaticText( parent
, -1, _("GUI command:"), wxDefaultPosition
, wxDefaultSize
, 0 );
1077 item15
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 5 );
1079 wxTextCtrl
*item17
= new wxTextCtrl( parent
, USEREVENTS_FIRST_ID
+ idx
* USEREVENTS_IDS_PER_EVENT
+ 4, wxT(""), wxDefaultPosition
, wxDefaultSize
, 0 );
1080 item17
->Enable(CUserEvents::IsGUICommandEnabled(static_cast<enum CUserEvents::EventType
>(idx
)));
1081 item15
->Add( item17
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
1083 item7
->Add( item15
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 0 );
1085 wxStaticText
*item13
= new wxStaticText( parent
, -1, _("The following variables will be replaced:") + vars
, wxDefaultPosition
, wxDefaultSize
, 0 );
1086 item7
->Add( item13
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
1088 IDC_PREFS_EVENTS_PAGE
->Add(item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
1090 IDC_PREFS_EVENTS_PAGE
->Layout();
1091 IDC_PREFS_EVENTS_PAGE
->Hide(idx
+ 1);
1093 // File_checked_for_headers