Format string mayhem
[amule.git] / src / Preferences.cpp
blobc15868a5113385d71080b27735fcf09e48496336
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
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.
20 //
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
26 #include <wx/wx.h>
27 #include "Preferences.h"
29 #include <protocol/ed2k/Constants.h>
30 #include <common/Constants.h>
31 #include <common/DataFileVersion.h>
33 #include <wx/config.h>
34 #include <wx/dir.h>
35 #include <wx/stdpaths.h>
36 #include <wx/stopwatch.h>
37 #include <wx/tokenzr.h>
38 #include <wx/utils.h> // Needed for wxBusyCursor
40 #include "amule.h"
41 #ifdef HAVE_CONFIG_H
42 #include "config.h" // Needed for PACKAGE_STRING
43 #endif
45 #include "CFile.h"
46 #include <common/MD5Sum.h>
47 #include "Logger.h"
48 #include <common/Format.h> // Needed for CFormat
49 #include <common/TextFile.h> // Needed for CTextFile
50 #include <common/ClientVersion.h>
52 #include "UserEvents.h"
54 #ifndef AMULE_DAEMON
55 #include <wx/valgen.h>
56 #include "muuli_wdr.h"
57 #include "StatisticsDlg.h"
58 #include "MuleColour.h"
59 #endif
61 #ifndef CLIENT_GUI
62 #include "RandomFunctions.h"
63 #include "PlatformSpecific.h" // Needed for PlatformSpecific::GetMaxConnections()
64 #endif
66 // Needed for IP filtering prefs
67 #include "ClientList.h"
68 #include "ServerList.h"
69 #include "IPFilter.h"
71 #define DEFAULT_TCP_PORT 4662
72 #define DEFAULT_UDP_PORT 4672
74 // Static variables
75 unsigned long CPreferences::s_colors[cntStatColors];
76 unsigned long CPreferences::s_colors_ref[cntStatColors];
78 CPreferences::CFGMap CPreferences::s_CfgList;
79 CPreferences::CFGList CPreferences::s_MiscList;
82 /* Proxy */
83 CProxyData CPreferences::s_ProxyData;
85 /* The rest, organize it! */
86 wxString CPreferences::s_nick;
87 Cfg_Lang_Base * CPreferences::s_cfgLang;
88 uint16 CPreferences::s_maxupload;
89 uint16 CPreferences::s_maxdownload;
90 uint16 CPreferences::s_slotallocation;
91 wxString CPreferences::s_Addr;
92 uint16 CPreferences::s_port;
93 uint16 CPreferences::s_udpport;
94 bool CPreferences::s_UDPEnable;
95 uint16 CPreferences::s_maxconnections;
96 bool CPreferences::s_reconnect;
97 bool CPreferences::s_autoconnect;
98 bool CPreferences::s_autoconnectstaticonly;
99 bool CPreferences::s_UPnPEnabled;
100 bool CPreferences::s_UPnPECEnabled;
101 bool CPreferences::s_UPnPWebServerEnabled;
102 uint16 CPreferences::s_UPnPTCPPort;
103 bool CPreferences::s_autoserverlist;
104 bool CPreferences::s_deadserver;
105 CPath CPreferences::s_incomingdir;
106 CPath CPreferences::s_tempdir;
107 bool CPreferences::s_ICH;
108 uint8 CPreferences::s_depth3D;
109 bool CPreferences::s_scorsystem;
110 bool CPreferences::s_mintotray;
111 bool CPreferences::s_trayiconenabled;
112 bool CPreferences::s_addnewfilespaused;
113 bool CPreferences::s_addserversfromserver;
114 bool CPreferences::s_addserversfromclient;
115 uint16 CPreferences::s_maxsourceperfile;
116 uint16 CPreferences::s_trafficOMeterInterval;
117 uint16 CPreferences::s_statsInterval;
118 uint32 CPreferences::s_maxGraphDownloadRate;
119 uint32 CPreferences::s_maxGraphUploadRate;
120 bool CPreferences::s_confirmExit;
121 bool CPreferences::s_filterLanIP;
122 bool CPreferences::s_paranoidfilter;
123 bool CPreferences::s_IPFilterSys;
124 bool CPreferences::s_onlineSig;
125 uint16 CPreferences::s_OSUpdate;
126 uint64 CPreferences::s_totalDownloadedBytes;
127 uint64 CPreferences::s_totalUploadedBytes;
128 wxString CPreferences::s_languageID;
129 uint8 CPreferences::s_iSeeShares;
130 uint8 CPreferences::s_iToolDelayTime;
131 uint8 CPreferences::s_splitterbarPosition;
132 uint16 CPreferences::s_deadserverretries;
133 uint32 CPreferences::s_dwServerKeepAliveTimeoutMins;
134 uint8 CPreferences::s_statsMax;
135 uint8 CPreferences::s_statsAverageMinutes;
136 bool CPreferences::s_bpreviewprio;
137 bool CPreferences::s_smartidcheck;
138 uint8 CPreferences::s_smartidstate;
139 bool CPreferences::s_safeServerConnect;
140 bool CPreferences::s_startMinimized;
141 uint16 CPreferences::s_MaxConperFive;
142 bool CPreferences::s_checkDiskspace;
143 uint32 CPreferences::s_uMinFreeDiskSpace;
144 wxString CPreferences::s_yourHostname;
145 bool CPreferences::s_bVerbose;
146 bool CPreferences::s_bmanualhighprio;
147 bool CPreferences::s_bstartnextfile;
148 bool CPreferences::s_bstartnextfilesame;
149 bool CPreferences::s_bshowoverhead;
150 bool CPreferences::s_bDAP;
151 bool CPreferences::s_bUAP;
152 uint8_t CPreferences::s_showRatesOnTitle;
153 wxString CPreferences::s_VideoPlayer;
154 bool CPreferences::s_showAllNotCats;
155 bool CPreferences::s_msgonlyfriends;
156 bool CPreferences::s_msgsecure;
157 uint8 CPreferences::s_filterlevel;
158 uint8 CPreferences::s_iFileBufferSize;
159 uint8 CPreferences::s_iQueueSize;
160 wxString CPreferences::s_datetimeformat;
161 wxString CPreferences::s_sWebPath;
162 wxString CPreferences::s_sWebPassword;
163 wxString CPreferences::s_sWebLowPassword;
164 uint16 CPreferences::s_nWebPort;
165 uint16 CPreferences::s_nWebUPnPTCPPort;
166 bool CPreferences::s_bWebEnabled;
167 bool CPreferences::s_bWebUseGzip;
168 uint32 CPreferences::s_nWebPageRefresh;
169 bool CPreferences::s_bWebLowEnabled;
170 wxString CPreferences::s_WebTemplate;
171 bool CPreferences::s_showCatTabInfos;
172 AllCategoryFilter CPreferences::s_allcatFilter;
173 uint8 CPreferences::s_NoNeededSources;
174 bool CPreferences::s_DropFullQueueSources;
175 bool CPreferences::s_DropHighQueueRankingSources;
176 uint32 CPreferences::s_HighQueueRanking;
177 uint32 CPreferences::s_AutoDropTimer;
178 bool CPreferences::s_AcceptExternalConnections;
179 wxString CPreferences::s_ECAddr;
180 uint32 CPreferences::s_ECPort;
181 wxString CPreferences::s_ECPassword;
182 bool CPreferences::s_IPFilterClients;
183 bool CPreferences::s_IPFilterServers;
184 bool CPreferences::s_UseSrcSeeds;
185 bool CPreferences::s_ProgBar;
186 bool CPreferences::s_Percent;
187 bool CPreferences::s_SecIdent;
188 bool CPreferences::s_ExtractMetaData;
189 bool CPreferences::s_allocFullFile;
190 wxString CPreferences::s_CustomBrowser;
191 bool CPreferences::s_BrowserTab;
192 CPath CPreferences::s_OSDirectory;
193 wxString CPreferences::s_Skin;
194 bool CPreferences::s_FastED2KLinksHandler;
195 bool CPreferences::s_ToolbarOrientation;
196 bool CPreferences::s_AICHTrustEveryHash;
197 wxString CPreferences::s_CommentFilterString;
198 bool CPreferences::s_IPFilterAutoLoad;
199 wxString CPreferences::s_IPFilterURL;
200 CMD4Hash CPreferences::s_userhash;
201 bool CPreferences::s_MustFilterMessages;
202 wxString CPreferences::s_MessageFilterString;
203 bool CPreferences::s_FilterAllMessages;
204 bool CPreferences::s_FilterComments;
205 bool CPreferences::s_FilterSomeMessages;
206 bool CPreferences::s_ShowMessagesInLog;
207 bool CPreferences::s_IsAdvancedSpamfilterEnabled;
208 bool CPreferences::s_IsChatCaptchaEnabled;
209 bool CPreferences::s_ShareHiddenFiles;
210 bool CPreferences::s_AutoSortDownload;
211 bool CPreferences::s_NewVersionCheck;
212 bool CPreferences::s_ConnectToKad;
213 bool CPreferences::s_ConnectToED2K;
214 unsigned CPreferences::s_maxClientVersions;
215 bool CPreferences::s_DropSlowSources;
216 bool CPreferences::s_IsClientCryptLayerSupported;
217 bool CPreferences::s_bCryptLayerRequested;
218 bool CPreferences::s_IsClientCryptLayerRequired;
219 uint32 CPreferences::s_dwKadUDPKey;
220 uint8 CPreferences::s_byCryptTCPPaddingLength;
222 wxString CPreferences::s_Ed2kURL;
223 wxString CPreferences::s_KadURL;
224 bool CPreferences::s_GeoIPEnabled;
225 wxString CPreferences::s_GeoIPUpdateUrl;
229 * Template Cfg class for connecting with widgets.
231 * This template provides the base functionionality needed to syncronize a
232 * variable with a widget. However, please note that wxGenericValidator only
233 * supports a few types (int, wxString, bool and wxArrayInt), so this template
234 * can't always be used directly.
236 * Cfg_Str and Cfg_Bool are able to use this template directly, whereas Cfg_Int
237 * makes use of serveral workaround to enable it to be used with integers other
238 * than int.
240 template <typename TYPE>
241 class Cfg_Tmpl : public Cfg_Base
243 public:
245 * Constructor.
247 * @param keyname
248 * @param value
249 * @param defaultVal
251 Cfg_Tmpl( const wxString& keyname, TYPE& value, const TYPE& defaultVal )
252 : Cfg_Base( keyname ),
253 m_value( value ),
254 m_default( defaultVal ),
255 m_widget( NULL )
258 #ifndef AMULE_DAEMON
260 * Connects the Cfg to a widget.
262 * @param id The ID of the widget to be connected.
263 * @param parent The parent of the widget. Use this to speed up searches.
265 * This function works by setting the wxValidator of the class. This however
266 * poses some restrictions on which variable types can be used for this
267 * template, as noted above. It also poses some limits on the widget types,
268 * refer to the wx documentation for those.
270 virtual bool ConnectToWidget( int id, wxWindow* parent = NULL )
272 if ( id ) {
273 m_widget = wxWindow::FindWindowById( id, parent );
275 if ( m_widget ) {
276 wxGenericValidator validator( &m_value );
278 m_widget->SetValidator( validator );
280 return true;
282 } else {
283 m_widget = NULL;
286 return false;
290 /** Updates the assosiated variable, returning true on success. */
291 virtual bool TransferFromWindow()
293 if ( m_widget ) {
294 wxValidator* validator = m_widget->GetValidator();
296 if ( validator ) {
297 TYPE temp = m_value;
299 if ( validator->TransferFromWindow() ) {
300 SetChanged( temp != m_value );
302 return true;
307 return false;
310 /** Updates the assosiated widget, returning true on success. */
311 virtual bool TransferToWindow()
313 if ( m_widget ) {
314 wxValidator* validator = m_widget->GetValidator();
316 if ( validator )
317 return validator->TransferToWindow();
320 return false;
323 #endif
325 /** Sets the default value. */
326 void SetDefault(const TYPE& defaultVal)
328 m_default = defaultVal;
331 protected:
332 //! Reference to the associated variable
333 TYPE& m_value;
335 //! Default variable value
336 TYPE m_default;
338 //! Pointer to the widget assigned to the Cfg instance
339 wxWindow* m_widget;
343 /** Cfg class for wxStrings. */
344 class Cfg_Str : public Cfg_Tmpl<wxString>
346 public:
347 /** Constructor. */
348 Cfg_Str( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
349 : Cfg_Tmpl<wxString>( keyname, value, defaultVal )
352 /** Loads the string, using the specified default value. */
353 virtual void LoadFromFile(wxConfigBase* cfg)
355 cfg->Read( GetKey(), &m_value, m_default );
359 /** Saves the string to the specified wxConfig object. */
360 virtual void SaveToFile(wxConfigBase* cfg)
362 cfg->Write( GetKey(), m_value );
368 * Cfg-class for encrypting strings, for example for passwords.
370 class Cfg_Str_Encrypted : public Cfg_Str
372 public:
373 Cfg_Str_Encrypted( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
374 : Cfg_Str( keyname, value, defaultVal )
377 #ifndef AMULE_DAEMON
378 virtual bool TransferFromWindow()
380 // Shakraw: when storing value, store it encrypted here (only if changed in prefs)
381 if ( Cfg_Str::TransferFromWindow() ) {
383 // Only recalucate the hash for new, non-empty passwords
384 if ( HasChanged() && !m_value.IsEmpty() ) {
385 m_value = MD5Sum( m_value ).GetHash();
388 return true;
392 return false;
394 #endif
398 /** Cfg class for CPath. */
399 class Cfg_Path : public Cfg_Str
401 public:
402 /** Constructor. */
403 Cfg_Path(const wxString& keyname, CPath& value, const wxString& defaultVal = wxEmptyString )
404 : Cfg_Str(keyname, m_temp_path, defaultVal)
405 , m_real_path(value)
408 /** @see Cfg_Str::LoadFromFile. */
409 virtual void LoadFromFile(wxConfigBase* cfg)
411 Cfg_Str::LoadFromFile(cfg);
413 m_real_path = CPath::FromUniv(m_temp_path);
417 /** @see Cfg_Str::SaveToFile. */
418 virtual void SaveToFile(wxConfigBase* cfg)
420 m_temp_path = CPath::ToUniv(m_real_path);
422 Cfg_Str::SaveToFile(cfg);
426 /** @see Cfg_Tmpl::TransferToWindow. */
427 virtual bool TransferToWindow()
429 m_temp_path = m_real_path.GetRaw();
431 return Cfg_Str::TransferToWindow();
434 /** @see Cfg_Tmpl::TransferFromWindow. */
435 virtual bool TransferFromWindow()
437 if (Cfg_Str::TransferFromWindow()) {
438 m_real_path = CPath(m_temp_path);
439 return true;
442 return false;
445 private:
446 wxString m_temp_path;
447 CPath& m_real_path;
452 * Cfg class that takes care of integer types.
454 * This template is needed since wxValidator only supports normals ints, and
455 * wxConfig for the matter only supports longs, thus some worksarounds are
456 * needed.
458 * There are two work-arounds:
459 * 1) wxValidator only supports int*, so we need a immediate variable to act
460 * as a storage. Thus we use Cfg_Tmpl<int> as base class. Thus this class
461 * contains a integer which we use to pass the value back and forth
462 * between the widgets.
464 * 2) wxConfig uses longs to save and read values, thus we need an immediate
465 * stage when loading and saving the value.
467 template <typename TYPE>
468 class Cfg_Int : public Cfg_Tmpl<int>
470 public:
471 Cfg_Int( const wxString& keyname, TYPE& value, int defaultVal = 0 )
472 : Cfg_Tmpl<int>( keyname, m_temp_value, defaultVal ),
473 m_real_value( value ),
474 m_temp_value( value )
478 virtual void LoadFromFile(wxConfigBase* cfg)
480 long tmp = 0;
481 cfg->Read( GetKey(), &tmp, m_default );
483 // Set the temp value
484 m_temp_value = (int)tmp;
485 // Set the actual value
486 m_real_value = (TYPE)tmp;
489 virtual void SaveToFile(wxConfigBase* cfg)
491 cfg->Write( GetKey(), (long)m_real_value );
495 #ifndef AMULE_DAEMON
496 virtual bool TransferFromWindow()
498 if ( Cfg_Tmpl<int>::TransferFromWindow() ) {
499 m_real_value = (TYPE)m_temp_value;
501 return true;
504 return false;
507 virtual bool TransferToWindow()
509 m_temp_value = (int)m_real_value;
511 if ( Cfg_Tmpl<int>::TransferToWindow() ) {
513 // In order to let us update labels on slider-changes, we trigger a event
514 wxSlider *slider = dynamic_cast<wxSlider *>(m_widget);
515 if (slider) {
516 int id = m_widget->GetId();
517 int pos = slider->GetValue();
518 wxScrollEvent evt( wxEVT_SCROLL_THUMBRELEASE, id, pos );
519 m_widget->GetEventHandler()->ProcessEvent( evt );
522 return true;
525 return false;
527 #endif
529 protected:
531 TYPE& m_real_value;
532 int m_temp_value;
537 * Helper function for creating new Cfg_Ints.
539 * @param keyname The cfg-key under which the item should be saved.
540 * @param value The variable to syncronize. The type of this variable defines the type used to create the Cfg_Int.
541 * @param defaultVal The default value if the key isn't found when loading the value.
542 * @return A pointer to the new Cfg_Int object. The caller is responsible for deleting it.
544 * This template-function returns a Cfg_Int of the appropriate type for the
545 * variable used as argument and should be used to avoid having to specify
546 * the integer type when adding a new Cfg_Int, since that's just increases
547 * the maintainence burden.
549 template <class TYPE>
550 Cfg_Base* MkCfg_Int( const wxString& keyname, TYPE& value, int defaultVal )
552 return new Cfg_Int<TYPE>( keyname, value, defaultVal );
557 * Cfg-class for bools.
559 class Cfg_Bool : public Cfg_Tmpl<bool>
561 public:
562 Cfg_Bool( const wxString& keyname, bool& value, bool defaultVal )
563 : Cfg_Tmpl<bool>( keyname, value, defaultVal )
567 virtual void LoadFromFile(wxConfigBase* cfg)
569 cfg->Read( GetKey(), &m_value, m_default );
572 virtual void SaveToFile(wxConfigBase* cfg)
574 cfg->Write( GetKey(), m_value );
580 * Cfg-class for uint64s, with no associated widgets.
582 class Cfg_Counter : public Cfg_Base
584 public:
585 Cfg_Counter( const wxString& keyname, uint64& value )
586 : Cfg_Base( keyname ),
587 m_value( value )
590 virtual void LoadFromFile(wxConfigBase* cfg)
592 wxString buffer;
594 cfg->Read( GetKey(), &buffer, wxT("0") );
596 uint64 tmp = 0;
597 for (unsigned int i = 0; i < buffer.Length(); ++i) {
598 if ((buffer[i] >= wxChar('0')) &&(buffer[i] <= wxChar('9'))) {
599 tmp = tmp * 10 + (buffer[i] - wxChar('0'));
600 } else {
601 tmp = 0;
602 break;
605 m_value = tmp;
608 virtual void SaveToFile(wxConfigBase* cfg)
610 wxString str = CFormat( wxT("%llu") ) % m_value;
612 cfg->Write( GetKey(), str );
616 protected:
617 uint64& m_value;
621 #ifndef AMULE_DAEMON
623 class Cfg_Colour : public Cfg_Base
625 public:
626 Cfg_Colour(const wxString& key, wxColour& colour)
627 : Cfg_Base(key),
628 m_colour(colour),
629 m_default(CMuleColour(colour).GetULong())
632 virtual void LoadFromFile(wxConfigBase* cfg)
634 long int rgb;
635 cfg->Read(GetKey(), &rgb, m_default);
636 m_colour.Set(rgb);
639 virtual void SaveToFile(wxConfigBase* cfg)
641 cfg->Write(GetKey(), static_cast<long int>(CMuleColour(m_colour).GetULong()));
644 private:
645 wxColour& m_colour;
646 long int m_default;
650 typedef struct {
651 int id;
652 bool available;
653 wxString displayname;
654 wxString name;
655 } LangInfo;
659 * The languages aMule has translation for.
661 * Add new languages here.
662 * Then activate the test code in Cfg_Lang::UpdateChoice below!
664 static LangInfo aMuleLanguages[] = {
665 { wxLANGUAGE_DEFAULT, true, wxEmptyString, wxTRANSLATE("System default") },
666 { wxLANGUAGE_ALBANIAN, false, wxEmptyString, wxTRANSLATE("Albanian") },
667 { wxLANGUAGE_ARABIC, false, wxEmptyString, wxTRANSLATE("Arabic") },
668 { wxLANGUAGE_ASTURIAN, false, wxEmptyString, wxTRANSLATE("Asturian") },
669 { wxLANGUAGE_BASQUE, false, wxEmptyString, wxTRANSLATE("Basque") },
670 { wxLANGUAGE_BULGARIAN, false, wxEmptyString, wxTRANSLATE("Bulgarian") },
671 { wxLANGUAGE_CATALAN, false, wxEmptyString, wxTRANSLATE("Catalan") },
672 { wxLANGUAGE_CHINESE_SIMPLIFIED, false, wxEmptyString, wxTRANSLATE("Chinese (Simplified)") },
673 { wxLANGUAGE_CHINESE_TRADITIONAL, false, wxEmptyString, wxTRANSLATE("Chinese (Traditional)") },
674 { wxLANGUAGE_CROATIAN, false, wxEmptyString, wxTRANSLATE("Croatian") },
675 { wxLANGUAGE_CZECH, false, wxEmptyString, wxTRANSLATE("Czech") },
676 { wxLANGUAGE_DANISH, false, wxEmptyString, wxTRANSLATE("Danish") },
677 { wxLANGUAGE_DUTCH, false, wxEmptyString, wxTRANSLATE("Dutch") },
678 { wxLANGUAGE_ENGLISH, false, wxEmptyString, wxTRANSLATE("English (U.K.)") },
679 { wxLANGUAGE_ESTONIAN, false, wxEmptyString, wxTRANSLATE("Estonian") },
680 { wxLANGUAGE_FINNISH, false, wxEmptyString, wxTRANSLATE("Finnish") },
681 { wxLANGUAGE_FRENCH, false, wxEmptyString, wxTRANSLATE("French") },
682 { wxLANGUAGE_GALICIAN, false, wxEmptyString, wxTRANSLATE("Galician") },
683 { wxLANGUAGE_GERMAN, false, wxEmptyString, wxTRANSLATE("German") },
684 { wxLANGUAGE_GREEK, false, wxEmptyString, wxTRANSLATE("Greek") },
685 { wxLANGUAGE_HEBREW, false, wxEmptyString, wxTRANSLATE("Hebrew") },
686 { wxLANGUAGE_HUNGARIAN, false, wxEmptyString, wxTRANSLATE("Hungarian") },
687 { wxLANGUAGE_ITALIAN, false, wxEmptyString, wxTRANSLATE("Italian") },
688 { wxLANGUAGE_ITALIAN_SWISS, false, wxEmptyString, wxTRANSLATE("Italian (Swiss)") },
689 { wxLANGUAGE_JAPANESE, false, wxEmptyString, wxTRANSLATE("Japanese") },
690 { wxLANGUAGE_KOREAN, false, wxEmptyString, wxTRANSLATE("Korean") },
691 { wxLANGUAGE_LITHUANIAN, false, wxEmptyString, wxTRANSLATE("Lithuanian") },
692 { wxLANGUAGE_NORWEGIAN_NYNORSK, false, wxEmptyString, wxTRANSLATE("Norwegian (Nynorsk)") },
693 { wxLANGUAGE_POLISH, false, wxEmptyString, wxTRANSLATE("Polish") },
694 { wxLANGUAGE_PORTUGUESE, false, wxEmptyString, wxTRANSLATE("Portuguese") },
695 { wxLANGUAGE_PORTUGUESE_BRAZILIAN, false, wxEmptyString, wxTRANSLATE("Portuguese (Brazilian)") },
696 { wxLANGUAGE_ROMANIAN, false, wxEmptyString, wxTRANSLATE("Romanian") },
697 { wxLANGUAGE_RUSSIAN, false, wxEmptyString, wxTRANSLATE("Russian") },
698 { wxLANGUAGE_SLOVENIAN, false, wxEmptyString, wxTRANSLATE("Slovenian") },
699 { wxLANGUAGE_SPANISH, false, wxEmptyString, wxTRANSLATE("Spanish") },
700 { wxLANGUAGE_SWEDISH, false, wxEmptyString, wxTRANSLATE("Swedish") },
701 { wxLANGUAGE_TURKISH, false, wxEmptyString, wxTRANSLATE("Turkish") },
702 { wxLANGUAGE_UKRAINIAN, false, wxEmptyString, wxTRANSLATE("Ukrainian") },
706 typedef Cfg_Int<int> Cfg_PureInt;
708 class Cfg_Lang : public Cfg_PureInt, public Cfg_Lang_Base
710 public:
711 Cfg_Lang()
712 : Cfg_PureInt( wxEmptyString, m_selection, 0 )
714 m_languagesReady = false;
715 m_changePos = 0;
718 virtual void LoadFromFile(wxConfigBase* WXUNUSED(cfg)) {}
719 virtual void SaveToFile(wxConfigBase* WXUNUSED(cfg)) {}
722 virtual bool TransferFromWindow()
724 if ( Cfg_PureInt::TransferFromWindow() ) {
725 // find wx ID of selected language
726 int i = 0;
727 while (m_selection > 0) {
728 i++;
729 if (aMuleLanguages[i].available) {
730 m_selection--;
733 int id = aMuleLanguages[i].id;
735 // save language selection
736 thePrefs::SetLanguageID(wxLang2Str(id));
738 return true;
741 return false;
745 virtual bool TransferToWindow()
747 m_langSelector = dynamic_cast<wxChoice*>(m_widget); // doesn't work in ctor!
748 if (m_languagesReady) {
749 FillChoice();
750 } else {
751 int wxId = StrLang2wx(thePrefs::GetLanguageID());
752 m_langSelector->Clear();
753 m_selection = 0;
754 for (uint32 i = 0; i < itemsof(aMuleLanguages); i++) {
755 if ( aMuleLanguages[i].id == wxId ) {
756 m_langSelector->Append(wxString(wxGetTranslation(aMuleLanguages[i].name)) + wxT(" [") + aMuleLanguages[i].name + wxT("]"));
757 break;
760 m_langSelector->Append(_("Change Language"));
761 m_changePos = m_langSelector->GetCount() - 1;
764 return Cfg_PureInt::TransferToWindow();
767 virtual void UpdateChoice(int pos)
769 if (!m_languagesReady && pos == m_changePos) {
770 // Find available languages and translate them.
771 // This is only done when the user selects "Change Language"
772 // Language is changed rarely, and the go-through-all locales takes a considerable
773 // time when the settings dialog is opened for the first time.
774 wxBusyCursor busyCursor;
775 aMuleLanguages[0].displayname = wxGetTranslation(aMuleLanguages[0].name);
776 for (unsigned int i = 1; i < itemsof(aMuleLanguages); ++i) {
777 if (wxLocale::IsAvailable(aMuleLanguages[i].id)) {
778 // This supresses error-messages about invalid locales.
779 wxLogNull logTarget;
780 wxLocale locale_to_check;
782 InitLocale(locale_to_check, aMuleLanguages[i].id);
783 if (locale_to_check.IsOk() && locale_to_check.IsLoaded(wxT(PACKAGE))) {
784 aMuleLanguages[i].displayname = wxString(wxGetTranslation(aMuleLanguages[i].name)) + wxT(" [") + aMuleLanguages[i].name + wxT("]");
785 aMuleLanguages[i].available = true;
786 #if 0
787 // Check for language problems
788 // Activate this code temporarily after messing with the languages!
789 int wxid = StrLang2wx(wxLang2Str(aMuleLanguages[i].id));
790 if (wxid != aMuleLanguages[i].id) {
791 AddDebugLogLineN(logGeneral, CFormat(wxT("Language problem for %s : aMule id %d != wx id %d"))
792 % aMuleLanguages[i].name % aMuleLanguages[i].id % wxid);
794 #endif
798 // Restore original locale
799 wxLocale tmpLocale;
800 InitLocale(tmpLocale, theApp->m_locale.GetLanguage());
801 FillChoice();
802 m_langSelector->SetSelection(m_selection);
803 m_languagesReady = true;
807 protected:
808 int m_selection;
810 private:
811 void FillChoice()
813 int wxId = StrLang2wx(thePrefs::GetLanguageID());
814 m_langSelector->Clear();
815 // Add all available languages and find the index of the selected language.
816 for ( unsigned int i = 0, j = 0; i < itemsof(aMuleLanguages); i++) {
817 if (aMuleLanguages[i].available) {
818 m_langSelector->Append(aMuleLanguages[i].displayname);
819 if ( aMuleLanguages[i].id == wxId ) {
820 m_selection = j;
822 j++;
827 bool m_languagesReady; // true: all translations calculated
828 int m_changePos;
829 wxChoice * m_langSelector;
832 #endif /* ! AMULE_DAEMON */
834 void Cfg_Lang_Base::UpdateChoice(int) {} // dummy
836 class Cfg_Skin : public Cfg_Str
838 public:
839 Cfg_Skin( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
840 : Cfg_Str( keyname, value, defaultVal ),
841 m_is_skin(false)
844 #ifndef AMULE_DAEMON
845 virtual bool TransferFromWindow()
847 if ( Cfg_Str::TransferFromWindow() ) {
848 if (m_is_skin) {
849 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
850 // "- default -" is always the first
851 if (skinSelector->GetSelection() == 0) {
852 m_value.Clear();
855 return true;
858 return false;
862 virtual bool TransferToWindow()
865 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
866 skinSelector->Clear();
868 wxString folder;
869 int flags = wxDIR_DIRS;
870 wxString filespec;
871 wxString defaultSelection = _("- default -");
872 //#warning there has to be a better way...
873 if ( GetKey() == wxT("/SkinGUIOptions/Skin") ) {
874 folder = wxT("skins");
875 m_is_skin = true;
876 flags = wxDIR_FILES;
877 filespec = wxT("*.zip");
878 skinSelector->Append(defaultSelection);
879 } else {
880 folder = wxT("webserver");
882 wxString dirName(JoinPaths(GetConfigDir(theApp->m_configFile), folder));
883 wxString Filename;
884 wxDir d;
886 if (wxDir::Exists(dirName) &&
887 d.Open(dirName) &&
888 d.GetFirst(& Filename, filespec, flags)
893 if (m_is_skin) {
894 Filename = wxT("User:") + Filename;
896 skinSelector->Append(Filename);
898 while (d.GetNext(&Filename));
901 wxString dataDir;
902 if (m_is_skin) {
903 dataDir = wxStandardPaths::Get().GetDataDir();
904 } else {
905 dataDir = wxStandardPaths::Get().GetResourcesDir();
907 #if !defined(__WXMSW__) && !defined(__WXMAC__)
908 dataDir = dataDir.BeforeLast(wxT('/')) + wxT("/amule");
909 #endif
910 wxString systemDir(JoinPaths(dataDir,folder));
912 if (wxDir::Exists(systemDir) &&
913 d.Open(systemDir) &&
914 d.GetFirst(& Filename, filespec, flags)
919 if (m_is_skin) {
920 Filename = wxT("System:") + Filename;
922 // avoid duplicates for webserver templates
923 if (skinSelector->FindString(Filename) == wxNOT_FOUND) {
924 skinSelector->Append(Filename);
927 while (d.GetNext(&Filename));
930 if ( skinSelector->GetCount() == 0 ) {
931 skinSelector->Append(_("no options available"));
934 int id = skinSelector->FindString(m_value);
935 if ( id == wxNOT_FOUND ) {
936 id = 0;
937 if (m_is_skin) {
938 m_value = defaultSelection;
941 skinSelector->SetSelection(id);
943 return Cfg_Str::TransferToWindow();
945 #endif /* ! AMULE_DAEMON */
947 protected:
948 bool m_is_skin;
952 /// new implementation
953 CPreferences::CPreferences()
955 srand( wxGetLocalTimeMillis().GetLo() ); // we need random numbers sometimes
957 // load preferences.dat or set standard values
958 wxString fullpath(theApp->ConfigDir + wxT("preferences.dat"));
959 CFile preffile;
960 if (wxFileExists(fullpath)) {
961 if (preffile.Open(fullpath, CFile::read)) {
962 try {
963 preffile.ReadUInt8(); // Version. Value is not used.
964 s_userhash = preffile.ReadHash();
965 } catch (const CSafeIOException& e) {
966 AddDebugLogLineC(logGeneral,
967 wxT("Error while reading userhash: ") + e.what());
972 if (s_userhash.IsEmpty()) {
973 for (int i = 0; i < 8; i++) {
974 RawPokeUInt16(s_userhash.GetHash() + (i * 2), rand());
977 Save();
980 // Mark hash as an eMule-type hash
981 // See also CUpDownClient::GetHashType
982 s_userhash[5] = 14;
983 s_userhash[14] = 111;
985 #ifndef CLIENT_GUI
986 LoadPreferences();
987 ReloadSharedFolders();
989 // serverlist adresses
990 CTextFile slistfile;
991 if (slistfile.Open(theApp->ConfigDir + wxT("addresses.dat"), CTextFile::read)) {
992 adresses_list = slistfile.ReadLines();
994 #endif
998 // Gets called at init time
1000 void CPreferences::BuildItemList( const wxString& appdir )
1002 #ifndef AMULE_DAEMON
1003 #define NewCfgItem(ID, COMMAND) s_CfgList[ID] = COMMAND
1004 #else
1005 int current_id = 0;
1006 #define NewCfgItem(ID, COMMAND) s_CfgList[++current_id] = COMMAND
1007 #endif /* AMULE_DAEMON */
1010 * User settings
1012 NewCfgItem(IDC_NICK, (new Cfg_Str( wxT("/eMule/Nick"), s_nick, wxT("http://www.aMule.org") )));
1013 #ifndef AMULE_DAEMON
1014 Cfg_Lang * cfgLang = new Cfg_Lang();
1015 s_cfgLang = cfgLang;
1016 NewCfgItem(IDC_LANGUAGE, cfgLang);
1017 #endif
1020 * Browser options
1022 #ifdef __WXMAC__
1023 wxString customBrowser = wxT("/usr/bin/open");
1024 #else
1025 wxString customBrowser; // left empty
1026 #endif
1028 NewCfgItem(IDC_BROWSERTABS, (new Cfg_Bool( wxT("/Browser/OpenPageInTab"), s_BrowserTab, true )));
1029 NewCfgItem(IDC_BROWSERSELF, (new Cfg_Str( wxT("/Browser/CustomBrowserString"), s_CustomBrowser, customBrowser )));
1033 * Misc
1035 NewCfgItem(IDC_QUEUESIZE, (MkCfg_Int( wxT("/eMule/QueueSizePref"), s_iQueueSize, 50 )));
1038 #ifdef __DEBUG__
1040 * Debugging
1042 NewCfgItem(ID_VERBOSEDEBUG, (new Cfg_Bool( wxT("/eMule/VerboseDebug"), s_bVerbose, false )));
1043 #endif
1046 * Connection settings
1048 NewCfgItem(IDC_MAXUP, (MkCfg_Int( wxT("/eMule/MaxUpload"), s_maxupload, 0 )));
1049 NewCfgItem(IDC_MAXDOWN, (MkCfg_Int( wxT("/eMule/MaxDownload"), s_maxdownload, 0 )));
1050 NewCfgItem(IDC_SLOTALLOC, (MkCfg_Int( wxT("/eMule/SlotAllocation"), s_slotallocation, 2 )));
1051 NewCfgItem(IDC_PORT, (MkCfg_Int( wxT("/eMule/Port"), s_port, DEFAULT_TCP_PORT )));
1052 NewCfgItem(IDC_UDPPORT, (MkCfg_Int( wxT("/eMule/UDPPort"), s_udpport, DEFAULT_UDP_PORT )));
1053 NewCfgItem(IDC_UDPENABLE, (new Cfg_Bool( wxT("/eMule/UDPEnable"), s_UDPEnable, true )));
1054 NewCfgItem(IDC_ADDRESS, (new Cfg_Str( wxT("/eMule/Address"), s_Addr, wxEmptyString)));
1055 NewCfgItem(IDC_AUTOCONNECT, (new Cfg_Bool( wxT("/eMule/Autoconnect"), s_autoconnect, true )));
1056 NewCfgItem(IDC_MAXSOURCEPERFILE, (MkCfg_Int( wxT("/eMule/MaxSourcesPerFile"), s_maxsourceperfile, 300 )));
1057 NewCfgItem(IDC_MAXCON, (MkCfg_Int( wxT("/eMule/MaxConnections"), s_maxconnections, GetRecommendedMaxConnections() )));
1058 NewCfgItem(IDC_MAXCON5SEC, (MkCfg_Int( wxT("/eMule/MaxConnectionsPerFiveSeconds"), s_MaxConperFive, 20 )));
1061 * Proxy
1063 NewCfgItem(ID_PROXY_ENABLE_PROXY, (new Cfg_Bool( wxT("/Proxy/ProxyEnableProxy"), s_ProxyData.m_proxyEnable, false )));
1064 NewCfgItem(ID_PROXY_TYPE, (MkCfg_Int( wxT("/Proxy/ProxyType"), s_ProxyData.m_proxyType, 0 )));
1065 NewCfgItem(ID_PROXY_NAME, (new Cfg_Str( wxT("/Proxy/ProxyName"), s_ProxyData.m_proxyHostName, wxEmptyString )));
1066 NewCfgItem(ID_PROXY_PORT, (MkCfg_Int( wxT("/Proxy/ProxyPort"), s_ProxyData.m_proxyPort, 1080 )));
1067 NewCfgItem(ID_PROXY_ENABLE_PASSWORD, (new Cfg_Bool( wxT("/Proxy/ProxyEnablePassword"), s_ProxyData.m_enablePassword, false )));
1068 NewCfgItem(ID_PROXY_USER, (new Cfg_Str( wxT("/Proxy/ProxyUser"), s_ProxyData.m_userName, wxEmptyString )));
1069 NewCfgItem(ID_PROXY_PASSWORD, (new Cfg_Str( wxT("/Proxy/ProxyPassword"), s_ProxyData.m_password, wxEmptyString )));
1070 // These were copied from eMule config file, maybe someone with windows can complete this?
1071 // NewCfgItem(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, (new Cfg_Bool( wxT("/Proxy/Proxy????"), s_Proxy????, false )));
1074 * Servers
1075 **/
1076 NewCfgItem(IDC_REMOVEDEAD, (new Cfg_Bool( wxT("/eMule/RemoveDeadServer"), s_deadserver, 1 )));
1077 NewCfgItem(IDC_SERVERRETRIES, (MkCfg_Int( wxT("/eMule/DeadServerRetry"), s_deadserverretries, 3 )));
1078 NewCfgItem(IDC_SERVERKEEPALIVE, (MkCfg_Int( wxT("/eMule/ServerKeepAliveTimeout"), s_dwServerKeepAliveTimeoutMins, 0 )));
1079 NewCfgItem(IDC_RECONN, (new Cfg_Bool( wxT("/eMule/Reconnect"), s_reconnect, true )));
1080 NewCfgItem(IDC_SCORE, (new Cfg_Bool( wxT("/eMule/Scoresystem"), s_scorsystem, true )));
1081 NewCfgItem(IDC_AUTOSERVER, (new Cfg_Bool( wxT("/eMule/Serverlist"), s_autoserverlist, false )));
1082 NewCfgItem(IDC_UPDATESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/AddServerListFromServer"), s_addserversfromserver, false)));
1083 NewCfgItem(IDC_UPDATESERVERCLIENT, (new Cfg_Bool( wxT("/eMule/AddServerListFromClient"), s_addserversfromclient, false )));
1084 NewCfgItem(IDC_SAFESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/SafeServerConnect"), s_safeServerConnect, false )));
1085 NewCfgItem(IDC_AUTOCONNECTSTATICONLY, (new Cfg_Bool( wxT("/eMule/AutoConnectStaticOnly"), s_autoconnectstaticonly, false )));
1086 NewCfgItem(IDC_UPNP_ENABLED, (new Cfg_Bool( wxT("/eMule/UPnPEnabled"), s_UPnPEnabled, false )));
1087 NewCfgItem(IDC_UPNPTCPPORT, (MkCfg_Int( wxT("/eMule/UPnPTCPPort"), s_UPnPTCPPort, 50000 )));
1088 NewCfgItem(IDC_SMARTIDCHECK, (new Cfg_Bool( wxT("/eMule/SmartIdCheck"), s_smartidcheck, true )));
1089 // Enabled networks
1090 NewCfgItem( IDC_NETWORKKAD, (new Cfg_Bool( wxT("/eMule/ConnectToKad"), s_ConnectToKad, true )) );
1091 NewCfgItem( IDC_NETWORKED2K, ( new Cfg_Bool( wxT("/eMule/ConnectToED2K"), s_ConnectToED2K, true ) ));
1095 * Files
1097 NewCfgItem(IDC_TEMPFILES, (new Cfg_Path( wxT("/eMule/TempDir"), s_tempdir, appdir + wxT("Temp") )));
1099 #if defined(__WXMAC__) || defined(__WXMSW__)
1100 wxString incpath = wxStandardPaths::Get().GetDocumentsDir();
1101 if (incpath.IsEmpty()) {
1102 // There is a built-in possibility for this call to fail, though I can't imagine a reason for that.
1103 incpath = appdir + wxT("Incoming");
1104 } else {
1105 incpath = JoinPaths(incpath, wxT("aMule Downloads"));
1107 #else
1108 wxString incpath = appdir + wxT("Incoming");
1109 #endif
1110 NewCfgItem(IDC_INCFILES, (new Cfg_Path( wxT("/eMule/IncomingDir"), s_incomingdir, incpath )));
1112 NewCfgItem(IDC_ICH, (new Cfg_Bool( wxT("/eMule/ICH"), s_ICH, true )));
1113 NewCfgItem(IDC_AICHTRUST, (new Cfg_Bool( wxT("/eMule/AICHTrust"), s_AICHTrustEveryHash, false )));
1114 NewCfgItem(IDC_CHECKDISKSPACE, (new Cfg_Bool( wxT("/eMule/CheckDiskspace"), s_checkDiskspace, true )));
1115 NewCfgItem(IDC_MINDISKSPACE, (MkCfg_Int( wxT("/eMule/MinFreeDiskSpace"), s_uMinFreeDiskSpace, 1 )));
1116 NewCfgItem(IDC_ADDNEWFILESPAUSED, (new Cfg_Bool( wxT("/eMule/AddNewFilesPaused"), s_addnewfilespaused, false )));
1117 NewCfgItem(IDC_PREVIEWPRIO, (new Cfg_Bool( wxT("/eMule/PreviewPrio"), s_bpreviewprio, false )));
1118 NewCfgItem(IDC_MANUALSERVERHIGHPRIO, (new Cfg_Bool( wxT("/eMule/ManualHighPrio"), s_bmanualhighprio, false )));
1119 NewCfgItem(IDC_STARTNEXTFILE, (new Cfg_Bool( wxT("/eMule/StartNextFile"), s_bstartnextfile, false )));
1120 NewCfgItem(IDC_STARTNEXTFILE_SAME, (new Cfg_Bool( wxT("/eMule/StartNextFileSameCat"), s_bstartnextfilesame, false )));
1121 NewCfgItem(IDC_SRCSEEDS, (new Cfg_Bool( wxT("/ExternalConnect/UseSrcSeeds"), s_UseSrcSeeds, false )));
1122 NewCfgItem(IDC_FILEBUFFERSIZE, (MkCfg_Int( wxT("/eMule/FileBufferSizePref"), s_iFileBufferSize, 16 )));
1123 NewCfgItem(IDC_DAP, (new Cfg_Bool( wxT("/eMule/DAPPref"), s_bDAP, true )));
1124 NewCfgItem(IDC_UAP, (new Cfg_Bool( wxT("/eMule/UAPPref"), s_bUAP, true )));
1125 NewCfgItem(IDC_ALLOCFULLFILE, (new Cfg_Bool( wxT("/eMule/AllocateFullFile"), s_allocFullFile, false )));
1128 * Web Server
1130 NewCfgItem(IDC_OSDIR, (new Cfg_Path( wxT("/eMule/OSDirectory"), s_OSDirectory, appdir )));
1131 NewCfgItem(IDC_ONLINESIG, (new Cfg_Bool( wxT("/eMule/OnlineSignature"), s_onlineSig, false )));
1132 NewCfgItem(IDC_OSUPDATE, (MkCfg_Int( wxT("/eMule/OnlineSignatureUpdate"), s_OSUpdate, 5 )));
1133 NewCfgItem(IDC_ENABLE_WEB, (new Cfg_Bool( wxT("/WebServer/Enabled"), s_bWebEnabled, false )));
1134 NewCfgItem(IDC_WEB_PASSWD, (new Cfg_Str_Encrypted( wxT("/WebServer/Password"), s_sWebPassword )));
1135 NewCfgItem(IDC_WEB_PASSWD_LOW, (new Cfg_Str_Encrypted( wxT("/WebServer/PasswordLow"), s_sWebLowPassword )));
1136 NewCfgItem(IDC_WEB_PORT, (MkCfg_Int( wxT("/WebServer/Port"), s_nWebPort, 4711 )));
1137 NewCfgItem(IDC_WEBUPNPTCPPORT, (MkCfg_Int( wxT("/WebServer/WebUPnPTCPPort"), s_nWebUPnPTCPPort, 50001 )));
1138 NewCfgItem(IDC_UPNP_WEBSERVER_ENABLED,
1139 (new Cfg_Bool( wxT("/WebServer/UPnPWebServerEnabled"), s_UPnPWebServerEnabled, false )));
1140 NewCfgItem(IDC_WEB_GZIP, (new Cfg_Bool( wxT("/WebServer/UseGzip"), s_bWebUseGzip, true )));
1141 NewCfgItem(IDC_ENABLE_WEB_LOW, (new Cfg_Bool( wxT("/WebServer/UseLowRightsUser"), s_bWebLowEnabled, false )));
1142 NewCfgItem(IDC_WEB_REFRESH_TIMEOUT, (MkCfg_Int( wxT("/WebServer/PageRefreshTime"), s_nWebPageRefresh, 120 )));
1143 NewCfgItem(IDC_WEBTEMPLATE, (new Cfg_Skin( wxT("/WebServer/Template"), s_WebTemplate, wxEmptyString )));
1146 * External Connections
1148 NewCfgItem(IDC_EXT_CONN_ACCEPT, (new Cfg_Bool( wxT("/ExternalConnect/AcceptExternalConnections"), s_AcceptExternalConnections, false )));
1149 NewCfgItem(IDC_EXT_CONN_IP, (new Cfg_Str( wxT("/ExternalConnect/ECAddress"), s_ECAddr, wxEmptyString )));
1150 NewCfgItem(IDC_EXT_CONN_TCP_PORT, (MkCfg_Int( wxT("/ExternalConnect/ECPort"), s_ECPort, 4712 )));
1151 NewCfgItem(IDC_EXT_CONN_PASSWD, (new Cfg_Str_Encrypted( wxT("/ExternalConnect/ECPassword"), s_ECPassword, wxEmptyString )));
1152 NewCfgItem(IDC_UPNP_EC_ENABLED, (new Cfg_Bool( wxT("/ExternalConnect/UPnPECEnabled"), s_UPnPECEnabled, false )));
1155 * GUI behavior
1157 NewCfgItem(IDC_ENABLETRAYICON, (new Cfg_Bool( wxT("/eMule/EnableTrayIcon"), s_trayiconenabled, false )));
1158 NewCfgItem(IDC_MINTRAY, (new Cfg_Bool( wxT("/eMule/MinToTray"), s_mintotray, false )));
1159 NewCfgItem(IDC_EXIT, (new Cfg_Bool( wxT("/eMule/ConfirmExit"), s_confirmExit, true )));
1160 NewCfgItem(IDC_STARTMIN, (new Cfg_Bool( wxT("/eMule/StartupMinimized"), s_startMinimized, false )));
1163 * GUI appearence
1165 NewCfgItem(IDC_3DDEPTH, (MkCfg_Int( wxT("/eMule/3DDepth"), s_depth3D, 10 )));
1166 NewCfgItem(IDC_TOOLTIPDELAY, (MkCfg_Int( wxT("/eMule/ToolTipDelay"), s_iToolDelayTime, 1 )));
1167 NewCfgItem(IDC_SHOWOVERHEAD, (new Cfg_Bool( wxT("/eMule/ShowOverhead"), s_bshowoverhead, false )));
1168 NewCfgItem(IDC_EXTCATINFO, (new Cfg_Bool( wxT("/eMule/ShowInfoOnCatTabs"), s_showCatTabInfos, true )));
1169 NewCfgItem(IDC_FED2KLH, (new Cfg_Bool( wxT("/Razor_Preferences/FastED2KLinksHandler"), s_FastED2KLinksHandler, true )));
1170 NewCfgItem(IDC_PROGBAR, (new Cfg_Bool( wxT("/ExternalConnect/ShowProgressBar"), s_ProgBar, true )));
1171 NewCfgItem(IDC_PERCENT, (new Cfg_Bool( wxT("/ExternalConnect/ShowPercent"), s_Percent, true )));
1172 NewCfgItem(IDC_SKIN, (new Cfg_Skin( wxT("/SkinGUIOptions/Skin"), s_Skin, wxEmptyString )));
1173 NewCfgItem(IDC_VERTTOOLBAR, (new Cfg_Bool( wxT("/eMule/VerticalToolbar"), s_ToolbarOrientation, false )));
1176 * External Apps
1178 NewCfgItem(IDC_VIDEOPLAYER, (new Cfg_Str( wxT("/eMule/VideoPlayer"), s_VideoPlayer, wxEmptyString )));
1181 * Statistics
1183 NewCfgItem(IDC_SLIDER, (MkCfg_Int( wxT("/eMule/StatGraphsInterval"), s_trafficOMeterInterval, 3 )));
1184 NewCfgItem(IDC_SLIDER2, (MkCfg_Int( wxT("/eMule/statsInterval"), s_statsInterval, 30 )));
1185 NewCfgItem(IDC_DOWNLOAD_CAP, (MkCfg_Int( wxT("/eMule/DownloadCapacity"), s_maxGraphDownloadRate, 300 )));
1186 NewCfgItem(IDC_UPLOAD_CAP, (MkCfg_Int( wxT("/eMule/UploadCapacity"), s_maxGraphUploadRate, 100 )));
1187 NewCfgItem(IDC_SLIDER3, (MkCfg_Int( wxT("/eMule/StatsAverageMinutes"), s_statsAverageMinutes, 5 )));
1188 NewCfgItem(IDC_SLIDER4, (MkCfg_Int( wxT("/eMule/VariousStatisticsMaxValue"), s_statsMax, 100 )));
1189 NewCfgItem(IDC_CLIENTVERSIONS, (MkCfg_Int( wxT("/Statistics/MaxClientVersions"), s_maxClientVersions, 0 )));
1192 * Security
1194 NewCfgItem(IDC_SEESHARES, (MkCfg_Int( wxT("/eMule/SeeShare"), s_iSeeShares, 2 )));
1195 NewCfgItem(IDC_SECIDENT, (new Cfg_Bool( wxT("/ExternalConnect/UseSecIdent"), s_SecIdent, true )));
1196 NewCfgItem(IDC_IPFCLIENTS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterClients"), s_IPFilterClients, true )));
1197 NewCfgItem(IDC_IPFSERVERS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterServers"), s_IPFilterServers, true )));
1198 NewCfgItem(IDC_FILTERLAN, (new Cfg_Bool( wxT("/eMule/FilterLanIPs"), s_filterLanIP, true )));
1199 NewCfgItem(IDC_PARANOID, (new Cfg_Bool( wxT("/eMule/ParanoidFiltering"), s_paranoidfilter, true )));
1200 NewCfgItem(IDC_AUTOIPFILTER, (new Cfg_Bool( wxT("/eMule/IPFilterAutoLoad"), s_IPFilterAutoLoad, true )));
1201 NewCfgItem(IDC_IPFILTERURL, (new Cfg_Str( wxT("/eMule/IPFilterURL"), s_IPFilterURL, wxEmptyString )));
1202 NewCfgItem(ID_IPFILTERLEVEL, (MkCfg_Int( wxT("/eMule/FilterLevel"), s_filterlevel, 127 )));
1203 NewCfgItem(IDC_IPFILTERSYS, (new Cfg_Bool( wxT("/eMule/IPFilterSystem"), s_IPFilterSys, false )));
1205 /**
1206 * Message Filter
1208 NewCfgItem(IDC_MSGFILTER, (new Cfg_Bool( wxT("/eMule/FilterMessages"), s_MustFilterMessages, true )));
1209 NewCfgItem(IDC_MSGFILTER_ALL, (new Cfg_Bool( wxT("/eMule/FilterAllMessages"), s_FilterAllMessages, false )));
1210 NewCfgItem(IDC_MSGFILTER_NONFRIENDS, (new Cfg_Bool( wxT("/eMule/MessagesFromFriendsOnly"), s_msgonlyfriends, false )));
1211 NewCfgItem(IDC_MSGFILTER_NONSECURE, (new Cfg_Bool( wxT("/eMule/MessageFromValidSourcesOnly"), s_msgsecure, true )));
1212 NewCfgItem(IDC_MSGFILTER_WORD, (new Cfg_Bool( wxT("/eMule/FilterWordMessages"), s_FilterSomeMessages, false )));
1213 NewCfgItem(IDC_MSGWORD, (new Cfg_Str( wxT("/eMule/MessageFilter"), s_MessageFilterString, wxEmptyString )));
1214 NewCfgItem(IDC_MSGLOG, (new Cfg_Bool( wxT("/eMule/ShowMessagesInLog"), s_ShowMessagesInLog, true )));
1215 //Todo NewCfgItem(IDC_MSGADVSPAM, (new Cfg_Bool( wxT("/eMule/AdvancedSpamFilter"), s_IsAdvancedSpamfilterEnabled, true )));
1216 //Todo NewCfgItem(IDC_MSGCAPTCHA, (new Cfg_Bool( wxT("/eMule/MessageUseCaptchas"), s_IsChatCaptchaEnabled, true )));
1217 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/AdvancedSpamFilter"), s_IsAdvancedSpamfilterEnabled, true ) );
1218 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/MessageUseCaptchas"), s_IsChatCaptchaEnabled, true ) );
1220 NewCfgItem(IDC_FILTERCOMMENTS, (new Cfg_Bool( wxT("/eMule/FilterComments"), s_FilterComments, false )));
1221 NewCfgItem(IDC_COMMENTWORD, (new Cfg_Str( wxT("/eMule/CommentFilter"), s_CommentFilterString, wxEmptyString )));
1224 * Hidden files sharing
1225 **/
1226 NewCfgItem(IDC_SHAREHIDDENFILES, (new Cfg_Bool( wxT("/eMule/ShareHiddenFiles"), s_ShareHiddenFiles, false )));
1229 * Auto-Sorting of downloads
1231 NewCfgItem(IDC_AUTOSORT, (new Cfg_Bool( wxT("/eMule/AutoSortDownloads"), s_AutoSortDownload, false )));
1234 * Version check
1236 NewCfgItem(IDC_NEWVERSION, (new Cfg_Bool( wxT("/eMule/NewVersionCheck"), s_NewVersionCheck, true )));
1239 * Obfuscation
1241 NewCfgItem( IDC_SUPPORT_PO, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerSupported"), s_IsClientCryptLayerSupported, true )));
1242 NewCfgItem( IDC_ENABLE_PO_OUTGOING, ( new Cfg_Bool( wxT("/Obfuscation/IsCryptLayerRequested"), s_bCryptLayerRequested, true )));
1243 NewCfgItem( IDC_ENFORCE_PO_INCOMING, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerRequired"), s_IsClientCryptLayerRequired, false )));
1244 #ifndef CLIENT_GUI
1245 // There is no need for GUI items for this two.
1246 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoPaddingLenght"), s_byCryptTCPPaddingLength, 254 ) );
1247 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoKadUDPKey"), s_dwKadUDPKey, GetRandomUint32() ) );
1248 #endif
1251 * The following doesn't have an associated widget or section
1253 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Language"), s_languageID ) );
1254 s_MiscList.push_back( new Cfg_Counter( wxT("/Statistics/TotalDownloadedBytes"), s_totalDownloadedBytes ) );
1255 s_MiscList.push_back( new Cfg_Counter( wxT("/Statistics/TotalUploadedBytes"), s_totalUploadedBytes ) );
1256 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SplitterbarPosition"), s_splitterbarPosition, 75 ) );
1257 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/YourHostname"), s_yourHostname, wxEmptyString ) );
1258 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/DateTimeFormat"), s_datetimeformat, wxT("%A, %x, %X") ) );
1260 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/AllcatType"), s_allcatFilter, 0 ) );
1261 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/ShowAllNotCats"), s_showAllNotCats, false ) );
1263 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SmartIdState"), s_smartidstate, 0 ) );
1265 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/DropSlowSources"), s_DropSlowSources, false ) );
1267 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/KadNodesUrl"), s_KadURL, wxT("http://download.tuxfamily.org/technosalad/utils/nodes.dat") ) );
1268 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Ed2kServersUrl"), s_Ed2kURL, wxT("http://gruk.org/server.met.gz") ) );
1269 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/ShowRatesOnTitle"), s_showRatesOnTitle, 0 ));
1271 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/GeoIPEnabled"), s_GeoIPEnabled, true ) );
1272 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/GeoLiteCountryUpdateUrl"), s_GeoIPUpdateUrl, wxT("http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz") ) );
1273 wxConfigBase::Get()->DeleteEntry(wxT("/eMule/GeoIPUpdateUrl")); // get rid of the old one for a while
1275 s_MiscList.push_back( new Cfg_Str( wxT("/WebServer/Path"), s_sWebPath, wxT("amuleweb") ) );
1277 #ifndef AMULE_DAEMON
1278 // Colors have been moved from global prefs to CStatisticsDlg
1279 for ( int i = 0; i < cntStatColors; i++ ) {
1280 wxString str = CFormat(wxT("/eMule/StatColor%i")) % i;
1281 s_MiscList.push_back( new Cfg_Colour( str, CStatisticsDlg::acrStat[i] ) );
1283 #endif
1285 // User events
1286 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1287 // We can't use NewCfgItem here, because we need to find these items
1288 // later, which would be impossible in amuled with NewCfgItem.
1289 // The IDs we assign here are high enough to not cause any collision
1290 // even on the daemon.
1291 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT + 1] = new Cfg_Bool(wxT("/UserEvents/") + CUserEvents::GetKey(i) + wxT("/CoreEnabled"), CUserEvents::GetCoreEnableVar(i), false);
1292 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT + 2] = new Cfg_Str(wxT("/UserEvents/") + CUserEvents::GetKey(i) + wxT("/CoreCommand"), CUserEvents::GetCoreCommandVar(i), wxEmptyString);
1293 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT + 3] = new Cfg_Bool(wxT("/UserEvents/") + CUserEvents::GetKey(i) + wxT("/GUIEnabled"), CUserEvents::GetGUIEnableVar(i), false);
1294 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT + 4] = new Cfg_Str(wxT("/UserEvents/") + CUserEvents::GetKey(i) + wxT("/GUICommand"), CUserEvents::GetGUICommandVar(i), wxEmptyString);
1299 void CPreferences::EraseItemList()
1301 while ( s_CfgList.begin() != s_CfgList.end() ) {
1302 delete s_CfgList.begin()->second;
1303 s_CfgList.erase( s_CfgList.begin() );
1306 CFGList::iterator it = s_MiscList.begin();
1307 for ( ; it != s_MiscList.end(); ) {
1308 delete *it;
1309 it = s_MiscList.erase( it );
1314 void CPreferences::LoadAllItems(wxConfigBase* cfg)
1316 #ifndef CLIENT_GUI
1317 // Preserve values from old config. The global config object may not be set yet
1318 // when BuildItemList() is called, so we need to provide defaults later - here.
1319 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletion"))) {
1320 bool ExecOnCompletion;
1321 cfg->Read(wxT("/eMule/ExecOnCompletion"), &ExecOnCompletion, false);
1322 // Assign to core command, that's the most likely it was.
1323 static_cast<Cfg_Bool*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT + 1])->SetDefault(ExecOnCompletion);
1324 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletion"));
1326 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletionCommand"))) {
1327 wxString ExecOnCompletionCommand;
1328 cfg->Read(wxT("/eMule/ExecOnCompletionCommand"), &ExecOnCompletionCommand, wxEmptyString);
1329 static_cast<Cfg_Str*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT + 2])->SetDefault(ExecOnCompletionCommand);
1330 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletionCommand"));
1332 #endif
1333 CFGMap::iterator it_a = s_CfgList.begin();
1334 for ( ; it_a != s_CfgList.end(); ++it_a ) {
1335 it_a->second->LoadFromFile( cfg );
1338 CFGList::iterator it_b = s_MiscList.begin();
1339 for ( ; it_b != s_MiscList.end(); ++it_b ) {
1340 (*it_b)->LoadFromFile( cfg );
1343 // Preserve old value of UDPDisable
1344 if (cfg->HasEntry(wxT("/eMule/UDPDisable"))) {
1345 bool UDPDisable;
1346 cfg->Read(wxT("/eMule/UDPDisable"), &UDPDisable, false);
1347 SetUDPDisable(UDPDisable);
1348 cfg->DeleteEntry(wxT("/eMule/UDPDisable"));
1351 // Preserve old value of UseSkinFiles
1352 if (cfg->HasEntry(wxT("/SkinGUIOptions/UseSkinFiles"))) {
1353 bool UseSkinFiles;
1354 cfg->Read(wxT("/SkinGUIOptions/UseSkinFiles"), &UseSkinFiles, false);
1355 if (!UseSkinFiles) {
1356 s_Skin.Clear();
1358 cfg->DeleteEntry(wxT("/SkinGUIOptions/UseSkinFiles"));
1361 #ifdef __DEBUG__
1362 // Load debug-categories
1363 int count = theLogger.GetDebugCategoryCount();
1365 for ( int i = 0; i < count; i++ ) {
1366 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1368 bool enabled = false;
1369 cfg->Read( wxT("/Debug/Cat_") + cat.GetName(), &enabled );
1371 theLogger.SetEnabled( cat.GetType(), enabled );
1373 #endif
1375 // Now do some post-processing / sanity checking on the values we just loaded
1376 #ifndef CLIENT_GUI
1377 CheckUlDlRatio();
1378 SetPort(s_port);
1379 if (s_byCryptTCPPaddingLength > 254) {
1380 s_byCryptTCPPaddingLength = GetRandomUint8() % 254;
1382 SetSlotAllocation(s_slotallocation);
1383 #endif
1387 void CPreferences::SaveAllItems(wxConfigBase* cfg)
1389 // Save the Cfg values
1390 CFGMap::iterator it_a = s_CfgList.begin();
1391 for ( ; it_a != s_CfgList.end(); ++it_a )
1392 it_a->second->SaveToFile( cfg );
1394 CFGList::iterator it_b = s_MiscList.begin();
1395 for ( ; it_b != s_MiscList.end(); ++it_b )
1396 (*it_b)->SaveToFile( cfg );
1399 // Save debug-categories
1400 #ifdef __DEBUG__
1401 int count = theLogger.GetDebugCategoryCount();
1403 for ( int i = 0; i < count; i++ ) {
1404 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1406 cfg->Write( wxT("/Debug/Cat_") + cat.GetName(), cat.IsEnabled() );
1408 #endif
1411 void CPreferences::SetMaxUpload(uint16 in)
1413 if ( s_maxupload != in ) {
1414 s_maxupload = in;
1416 // Ensure that the ratio is upheld
1417 CheckUlDlRatio();
1422 void CPreferences::SetMaxDownload(uint16 in)
1424 if ( s_maxdownload != in ) {
1425 s_maxdownload = in;
1427 // Ensure that the ratio is upheld
1428 CheckUlDlRatio();
1433 void CPreferences::UnsetAutoServerStart()
1435 s_autoserverlist = false;
1439 // Here we slightly limit the users' ability to be a bad citizen: for very low upload rates
1440 // we force a low download rate, so as to discourage this type of leeching.
1441 // We're Open Source, and whoever wants it can do his own mod to get around this, but the
1442 // packaged product will try to enforce good behavior.
1444 // Kry note: of course, any leecher mod will be banned asap.
1445 void CPreferences::CheckUlDlRatio()
1447 // Backwards compatibility
1448 if ( s_maxupload == 0xFFFF )
1449 s_maxupload = UNLIMITED;
1451 // Backwards compatibility
1452 if ( s_maxdownload == 0xFFFF )
1453 s_maxdownload = UNLIMITED;
1455 if ( s_maxupload == UNLIMITED )
1456 return;
1458 // Enforce the limits
1459 if ( s_maxupload < 4 ) {
1460 if ( ( s_maxupload * 3 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1461 s_maxdownload = s_maxupload * 3 ;
1462 } else if ( s_maxupload < 10 ) {
1463 if ( ( s_maxupload * 4 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1464 s_maxdownload = s_maxupload * 4;
1469 void CPreferences::Save()
1471 wxString fullpath(theApp->ConfigDir + wxT("preferences.dat"));
1473 CFile preffile;
1474 if (!wxFileExists(fullpath)) {
1475 preffile.Create(fullpath);
1478 if (preffile.Open(fullpath, CFile::read_write)) {
1479 try {
1480 preffile.WriteUInt8(PREFFILE_VERSION);
1481 preffile.WriteHash(s_userhash);
1482 } catch (const CIOFailureException& e) {
1483 AddDebugLogLineC(logGeneral, wxT("IO failure while saving user-hash: ") + e.what());
1487 SavePreferences();
1489 #ifndef CLIENT_GUI
1490 CTextFile sdirfile;
1491 if (sdirfile.Open(theApp->ConfigDir + wxT("shareddir.dat"), CTextFile::write)) {
1492 for (size_t i = 0; i < shareddir_list.size(); ++i) {
1493 sdirfile.WriteLine(CPath::ToUniv(shareddir_list[i]), wxConvUTF8);
1497 #endif
1501 CPreferences::~CPreferences()
1503 DeleteContents(m_CatList);
1507 int32 CPreferences::GetRecommendedMaxConnections()
1509 #ifndef CLIENT_GUI
1510 int iRealMax = PlatformSpecific::GetMaxConnections();
1511 if(iRealMax == -1 || iRealMax > 520) {
1512 return 500;
1514 if(iRealMax < 20) {
1515 return iRealMax;
1517 if(iRealMax <= 256) {
1518 return iRealMax - 10;
1520 return iRealMax - 20;
1521 #else
1522 return 500;
1523 #endif
1527 void CPreferences::SavePreferences()
1529 wxConfigBase* cfg = wxConfigBase::Get();
1531 cfg->Write( wxT("/eMule/AppVersion"), wxT(VERSION) );
1533 // Save the options
1534 SaveAllItems( cfg );
1536 // Ensure that the changes are saved to disk.
1537 cfg->Flush();
1541 void CPreferences::SaveCats()
1543 if ( GetCatCount() ) {
1544 wxConfigBase* cfg = wxConfigBase::Get();
1546 // Save the main cat.
1547 cfg->Write( wxT("/eMule/AllcatType"), (int)s_allcatFilter);
1549 // The first category is the default one and should not be counted
1551 cfg->Write( wxT("/General/Count"), (long)(m_CatList.size() - 1) );
1553 uint32 maxcat = m_CatList.size();
1554 for (uint32 i = 1; i < maxcat; i++) {
1555 cfg->SetPath(CFormat(wxT("/Cat#%i")) % i);
1557 cfg->Write( wxT("Title"), m_CatList[i]->title );
1558 cfg->Write( wxT("Incoming"), CPath::ToUniv(m_CatList[i]->path) );
1559 cfg->Write( wxT("Comment"), m_CatList[i]->comment );
1560 cfg->Write( wxT("Color"), wxString(CFormat(wxT("%u")) % m_CatList[i]->color));
1561 cfg->Write( wxT("Priority"), (int)m_CatList[i]->prio );
1563 // remove deleted cats from config
1564 while (cfg->DeleteGroup(CFormat(wxT("/Cat#%i")) % maxcat++)) {}
1566 cfg->Flush();
1571 void CPreferences::LoadPreferences()
1573 LoadCats();
1577 void CPreferences::LoadCats()
1579 // default cat ... Meow! =(^.^)=
1580 Category_Struct* defaultcat = new Category_Struct;
1581 defaultcat->prio = 0;
1582 defaultcat->color = 0;
1584 AddCat( defaultcat );
1586 wxConfigBase* cfg = wxConfigBase::Get();
1588 long max = cfg->Read( wxT("/General/Count"), 0l );
1590 for ( int i = 1; i <= max ; i++ ) {
1591 cfg->SetPath(CFormat(wxT("/Cat#%i")) % i);
1593 Category_Struct* newcat = new Category_Struct;
1595 newcat->title = cfg->Read( wxT("Title"), wxEmptyString );
1596 newcat->path = CPath::FromUniv(cfg->Read(wxT("Incoming"), wxEmptyString));
1598 // Some sanity checking
1599 if ( newcat->title.IsEmpty() || !newcat->path.IsOk() ) {
1600 AddLogLineN(_("Invalid category found, skipping"));
1602 delete newcat;
1603 continue;
1606 newcat->comment = cfg->Read( wxT("Comment"), wxEmptyString );
1607 newcat->prio = cfg->Read( wxT("Priority"), 0l );
1608 newcat->color = StrToULong(cfg->Read(wxT("Color"), wxT("0")));
1610 AddCat(newcat);
1612 if (!newcat->path.DirExists()) {
1613 CPath::MakeDir(newcat->path);
1619 uint16 CPreferences::GetDefaultMaxConperFive()
1621 return MAXCONPER5SEC;
1625 uint32 CPreferences::AddCat(Category_Struct* cat)
1627 m_CatList.push_back( cat );
1629 return m_CatList.size() - 1;
1633 void CPreferences::RemoveCat(size_t index)
1635 if ( index < m_CatList.size() ) {
1636 CatList::iterator it = m_CatList.begin() + index;
1638 delete *it;
1640 m_CatList.erase( it );
1645 uint32 CPreferences::GetCatCount()
1647 return m_CatList.size();
1651 Category_Struct* CPreferences::GetCategory(size_t index)
1653 wxASSERT( index < m_CatList.size() );
1655 return m_CatList[index];
1659 const CPath& CPreferences::GetCatPath(uint8 index)
1661 wxASSERT( index < m_CatList.size() );
1663 return m_CatList[index]->path;
1667 uint32 CPreferences::GetCatColor(size_t index)
1669 wxASSERT( index < m_CatList.size() );
1671 return m_CatList[index]->color;
1674 bool CPreferences::CreateCategory(
1675 Category_Struct *& category,
1676 const wxString& name,
1677 const CPath& path,
1678 const wxString& comment,
1679 uint32 color,
1680 uint8 prio)
1682 category = new Category_Struct();
1683 category->path = thePrefs::GetIncomingDir(); // set a default in case path is invalid
1684 uint32 cat = AddCat(category);
1685 return UpdateCategory(cat, name, path, comment, color, prio);
1688 bool CPreferences::UpdateCategory(
1689 uint8 cat,
1690 const wxString& name,
1691 const CPath& path,
1692 const wxString& comment,
1693 uint32 color,
1694 uint8 prio)
1696 Category_Struct *category = m_CatList[cat];
1698 // return true if path is ok, false if not
1699 bool ret = true;
1700 if (!path.IsOk() || (!path.DirExists() && !CPath::MakeDir(path))) {
1701 ret = false;
1702 // keep path as it was
1703 } else {
1704 category->path = path;
1706 category->title = name;
1707 category->comment = comment;
1708 category->color = color;
1709 category->prio = prio;
1711 SaveCats();
1712 return ret;
1716 wxString CPreferences::GetBrowser()
1718 wxString cmd(s_CustomBrowser);
1719 #ifndef __WXMSW__
1720 if( s_BrowserTab ) {
1721 // This is certainly not the best way to do it, but I'm lazy
1722 if ((wxT("mozilla") == cmd.Right(7)) || (wxT("firefox") == cmd.Right(7))
1723 || (wxT("MozillaFirebird") == cmd.Right(15))) {
1724 cmd += wxT(" -remote 'openURL(%s, new-tab)'");
1726 if ((wxT("galeon") == cmd.Right(6)) || (wxT("epiphany") == cmd.Right(8))) {
1727 cmd += wxT(" -n '%s'");
1729 if (wxT("opera") == cmd.Right(5)) {
1730 cmd += wxT(" --newpage '%s'");
1732 if (wxT("netscape") == cmd.Right(8)) {
1733 cmd += wxT(" -remote 'openURLs(%s,new-tab)'");
1736 #endif /* !__WXMSW__ */
1737 return cmd;
1740 void CPreferences::SetFilteringClients(bool val)
1742 if (val != s_IPFilterClients) {
1743 s_IPFilterClients = val;
1744 if (val) {
1745 theApp->clientlist->FilterQueues();
1750 void CPreferences::SetFilteringServers(bool val)
1752 if (val != s_IPFilterServers) {
1753 s_IPFilterServers = val;
1754 if (val) {
1755 theApp->serverlist->FilterServers();
1760 void CPreferences::SetIPFilterLevel(uint8 level)
1762 if (level != s_filterlevel) {
1763 // Set the new access-level
1764 s_filterlevel = level;
1765 // and reload the filter
1766 theApp->ipfilter->Reload();
1770 void CPreferences::SetPort(uint16 val)
1772 // Warning: Check for +3, because server UDP is TCP+3
1774 if (val +3 > 65535) {
1775 AddLogLineC(_("TCP port can't be higher than 65532 due to server UDP socket being TCP+3"));
1776 AddLogLineN(CFormat(_("Default port will be used (%d)")) % DEFAULT_TCP_PORT);
1777 s_port = DEFAULT_TCP_PORT;
1778 } else {
1779 s_port = val;
1784 void CPreferences::ReloadSharedFolders()
1786 #ifndef CLIENT_GUI
1787 shareddir_list.clear();
1789 CTextFile file;
1790 if (file.Open(theApp->ConfigDir + wxT("shareddir.dat"), CTextFile::read)) {
1791 wxArrayString lines = file.ReadLines(txtReadDefault, wxConvUTF8);
1793 for (size_t i = 0; i < lines.size(); ++i) {
1794 CPath path = CPath::FromUniv(lines[i]);
1796 if (path.DirExists()) {
1797 shareddir_list.push_back(path);
1798 } else {
1799 AddLogLineN(CFormat(_("Dropping non-existing shared directory: %s")) % path.GetRaw());
1803 #endif
1807 bool CPreferences::IsMessageFiltered(const wxString& message)
1809 if (s_FilterAllMessages) {
1810 return true;
1811 } else {
1812 if (s_FilterSomeMessages) {
1813 if (s_MessageFilterString.IsSameAs(wxT("*"))){
1814 // Filter anything
1815 return true;
1816 } else {
1817 wxStringTokenizer tokenizer( s_MessageFilterString, wxT(",") );
1818 while (tokenizer.HasMoreTokens()) {
1819 if ( message.Lower().Trim(false).Trim(true).Contains(
1820 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1821 return true;
1824 return false;
1826 } else {
1827 return false;
1833 bool CPreferences::IsCommentFiltered(const wxString& comment)
1835 if (s_FilterComments) {
1836 wxStringTokenizer tokenizer( s_CommentFilterString, wxT(",") );
1837 while (tokenizer.HasMoreTokens()) {
1838 if ( comment.Lower().Trim(false).Trim(true).Contains(
1839 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1840 return true;
1844 return false;
1847 wxString CPreferences::GetLastHTTPDownloadURL(uint8 t)
1849 wxConfigBase* cfg = wxConfigBase::Get();
1850 wxString key = CFormat(wxT("/HTTPDownload/URL_%d")) % t;
1851 return cfg->Read(key, wxEmptyString);
1854 void CPreferences::SetLastHTTPDownloadURL(uint8 t, const wxString& val)
1856 wxConfigBase* cfg = wxConfigBase::Get();
1857 wxString key = CFormat(wxT("/HTTPDownload/URL_%d")) % t;
1858 cfg->Write(key, val);
1861 // File_checked_for_headers