Upstream tarball 10059
[amule.git] / src / Preferences.cpp
blobae049e81e6287ad674d400d54c3f489a7e36d09d
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>
39 #include "amule.h"
40 #ifdef HAVE_CONFIG_H
41 #include "config.h" // Needed for PACKAGE_STRING
42 #endif
44 #include "CFile.h"
45 #include <common/MD5Sum.h>
46 #include "Logger.h"
47 #include <common/Format.h> // Needed for CFormat
48 #include <common/TextFile.h> // Needed for CTextFile
49 #include <common/ClientVersion.h>
51 #include "UserEvents.h"
53 #ifndef AMULE_DAEMON
54 #include <wx/valgen.h>
55 #include "muuli_wdr.h"
56 #include "StatisticsDlg.h"
57 #include "MuleColour.h"
58 #endif
60 #ifndef CLIENT_GUI
61 #include "RandomFunctions.h"
62 #include "PlatformSpecific.h" // Needed for PlatformSpecific::GetMaxConnections()
63 #endif
65 #define DEFAULT_TCP_PORT 4662
66 #define DEFAULT_UDP_PORT 4672
68 // Static variables
69 unsigned long CPreferences::s_colors[cntStatColors];
70 unsigned long CPreferences::s_colors_ref[cntStatColors];
72 CPreferences::CFGMap CPreferences::s_CfgList;
73 CPreferences::CFGList CPreferences::s_MiscList;
76 /* Proxy */
77 CProxyData CPreferences::s_ProxyData;
79 /* The rest, organize it! */
80 wxString CPreferences::s_nick;
81 uint16 CPreferences::s_maxupload;
82 uint16 CPreferences::s_maxdownload;
83 uint16 CPreferences::s_slotallocation;
84 wxString CPreferences::s_Addr;
85 uint16 CPreferences::s_port;
86 uint16 CPreferences::s_udpport;
87 bool CPreferences::s_UDPEnable;
88 uint16 CPreferences::s_maxconnections;
89 bool CPreferences::s_reconnect;
90 bool CPreferences::s_autoconnect;
91 bool CPreferences::s_autoconnectstaticonly;
92 bool CPreferences::s_UPnPEnabled;
93 bool CPreferences::s_UPnPECEnabled;
94 bool CPreferences::s_UPnPWebServerEnabled;
95 uint16 CPreferences::s_UPnPTCPPort;
96 bool CPreferences::s_autoserverlist;
97 bool CPreferences::s_deadserver;
98 CPath CPreferences::s_incomingdir;
99 CPath CPreferences::s_tempdir;
100 bool CPreferences::s_ICH;
101 uint8 CPreferences::s_depth3D;
102 bool CPreferences::s_scorsystem;
103 bool CPreferences::s_mintotray;
104 bool CPreferences::s_trayiconenabled;
105 bool CPreferences::s_addnewfilespaused;
106 bool CPreferences::s_addserversfromserver;
107 bool CPreferences::s_addserversfromclient;
108 uint16 CPreferences::s_maxsourceperfile;
109 uint16 CPreferences::s_trafficOMeterInterval;
110 uint16 CPreferences::s_statsInterval;
111 uint32 CPreferences::s_maxGraphDownloadRate;
112 uint32 CPreferences::s_maxGraphUploadRate;
113 bool CPreferences::s_confirmExit;
114 bool CPreferences::s_filterLanIP;
115 bool CPreferences::s_paranoidfilter;
116 bool CPreferences::s_IPFilterSys;
117 bool CPreferences::s_onlineSig;
118 uint16 CPreferences::s_OSUpdate;
119 uint64 CPreferences::s_totalDownloadedBytes;
120 uint64 CPreferences::s_totalUploadedBytes;
121 wxString CPreferences::s_languageID;
122 uint8 CPreferences::s_iSeeShares;
123 uint8 CPreferences::s_iToolDelayTime;
124 uint8 CPreferences::s_splitterbarPosition;
125 uint16 CPreferences::s_deadserverretries;
126 uint32 CPreferences::s_dwServerKeepAliveTimeoutMins;
127 uint8 CPreferences::s_statsMax;
128 uint8 CPreferences::s_statsAverageMinutes;
129 bool CPreferences::s_bpreviewprio;
130 bool CPreferences::s_smartidcheck;
131 uint8 CPreferences::s_smartidstate;
132 bool CPreferences::s_safeServerConnect;
133 bool CPreferences::s_startMinimized;
134 uint16 CPreferences::s_MaxConperFive;
135 bool CPreferences::s_checkDiskspace;
136 uint32 CPreferences::s_uMinFreeDiskSpace;
137 wxString CPreferences::s_yourHostname;
138 bool CPreferences::s_bVerbose;
139 bool CPreferences::s_bmanualhighprio;
140 bool CPreferences::s_btransferfullchunks;
141 bool CPreferences::s_bstartnextfile;
142 bool CPreferences::s_bstartnextfilesame;
143 bool CPreferences::s_bshowoverhead;
144 bool CPreferences::s_bDAP;
145 bool CPreferences::s_bUAP;
146 uint8_t CPreferences::s_showRatesOnTitle;
147 wxString CPreferences::s_VideoPlayer;
148 bool CPreferences::s_moviePreviewBackup;
149 bool CPreferences::s_showAllNotCats;
150 bool CPreferences::s_msgonlyfriends;
151 bool CPreferences::s_msgsecure;
152 uint8 CPreferences::s_filterlevel;
153 uint8 CPreferences::s_iFileBufferSize;
154 uint8 CPreferences::s_iQueueSize;
155 wxString CPreferences::s_datetimeformat;
156 wxString CPreferences::s_sWebPath;
157 wxString CPreferences::s_sWebPassword;
158 wxString CPreferences::s_sWebLowPassword;
159 uint16 CPreferences::s_nWebPort;
160 uint16 CPreferences::s_nWebUPnPTCPPort;
161 bool CPreferences::s_bWebEnabled;
162 bool CPreferences::s_bWebUseGzip;
163 uint32 CPreferences::s_nWebPageRefresh;
164 bool CPreferences::s_bWebLowEnabled;
165 wxString CPreferences::s_WebTemplate;
166 bool CPreferences::s_showCatTabInfos;
167 uint32 CPreferences::s_allcatType;
168 uint8 CPreferences::s_NoNeededSources;
169 bool CPreferences::s_DropFullQueueSources;
170 bool CPreferences::s_DropHighQueueRankingSources;
171 uint32 CPreferences::s_HighQueueRanking;
172 uint32 CPreferences::s_AutoDropTimer;
173 bool CPreferences::s_AcceptExternalConnections;
174 wxString CPreferences::s_ECAddr;
175 uint32 CPreferences::s_ECPort;
176 wxString CPreferences::s_ECPassword;
177 bool CPreferences::s_IPFilterClients;
178 bool CPreferences::s_IPFilterServers;
179 bool CPreferences::s_UseSrcSeeds;
180 bool CPreferences::s_ProgBar;
181 bool CPreferences::s_Percent;
182 bool CPreferences::s_SecIdent;
183 bool CPreferences::s_ExtractMetaData;
184 bool CPreferences::s_allocFullFile;
185 wxString CPreferences::s_CustomBrowser;
186 bool CPreferences::s_BrowserTab;
187 CPath CPreferences::s_OSDirectory;
188 wxString CPreferences::s_Skin;
189 bool CPreferences::s_FastED2KLinksHandler;
190 bool CPreferences::s_ToolbarOrientation;
191 bool CPreferences::s_AICHTrustEveryHash;
192 wxString CPreferences::s_CommentFilterString;
193 bool CPreferences::s_IPFilterAutoLoad;
194 wxString CPreferences::s_IPFilterURL;
195 CMD4Hash CPreferences::s_userhash;
196 bool CPreferences::s_MustFilterMessages;
197 wxString CPreferences::s_MessageFilterString;
198 bool CPreferences::s_FilterAllMessages;
199 bool CPreferences::s_FilterComments;
200 bool CPreferences::s_FilterSomeMessages;
201 bool CPreferences::s_ShowMessagesInLog;
202 bool CPreferences::s_IsAdvancedSpamfilterEnabled;
203 bool CPreferences::s_IsChatCaptchaEnabled;
204 bool CPreferences::s_ShareHiddenFiles;
205 bool CPreferences::s_AutoSortDownload;
206 bool CPreferences::s_NewVersionCheck;
207 bool CPreferences::s_ConnectToKad;
208 bool CPreferences::s_ConnectToED2K;
209 unsigned CPreferences::s_maxClientVersions;
210 bool CPreferences::s_DropSlowSources;
211 bool CPreferences::s_IsClientCryptLayerSupported;
212 bool CPreferences::s_bCryptLayerRequested;
213 bool CPreferences::s_IsClientCryptLayerRequired;
214 uint32 CPreferences::s_dwKadUDPKey;
215 uint8 CPreferences::s_byCryptTCPPaddingLength;
217 wxString CPreferences::s_Ed2kURL;
218 wxString CPreferences::s_KadURL;
219 bool CPreferences::s_GeoIPEnabled;
220 wxString CPreferences::s_GeoIPUpdateUrl;
224 * Template Cfg class for connecting with widgets.
226 * This template provides the base functionionality needed to syncronize a
227 * variable with a widget. However, please note that wxGenericValidator only
228 * supports a few types (int, wxString, bool and wxArrayInt), so this template
229 * can't always be used directly.
231 * Cfg_Str and Cfg_Bool are able to use this template directly, whereas Cfg_Int
232 * makes use of serveral workaround to enable it to be used with integers other
233 * than int.
235 template <typename TYPE>
236 class Cfg_Tmpl : public Cfg_Base
238 public:
240 * Constructor.
242 * @param keyname
243 * @param value
244 * @param defaultVal
246 Cfg_Tmpl( const wxString& keyname, TYPE& value, const TYPE& defaultVal )
247 : Cfg_Base( keyname ),
248 m_value( value ),
249 m_default( defaultVal ),
250 m_widget( NULL )
253 #ifndef AMULE_DAEMON
255 * Connects the Cfg to a widget.
257 * @param id The ID of the widget to be connected.
258 * @param parent The parent of the widget. Use this to speed up searches.
260 * This function works by setting the wxValidator of the class. This however
261 * poses some restrictions on which variable types can be used for this
262 * template, as noted above. It also poses some limits on the widget types,
263 * refer to the wx documentation for those.
265 virtual bool ConnectToWidget( int id, wxWindow* parent = NULL )
267 if ( id ) {
268 m_widget = wxWindow::FindWindowById( id, parent );
270 if ( m_widget ) {
271 wxGenericValidator validator( &m_value );
273 m_widget->SetValidator( validator );
275 return true;
277 } else {
278 m_widget = NULL;
281 return false;
285 /** Updates the assosiated variable, returning true on success. */
286 virtual bool TransferFromWindow()
288 if ( m_widget ) {
289 wxValidator* validator = m_widget->GetValidator();
291 if ( validator ) {
292 TYPE temp = m_value;
294 if ( validator->TransferFromWindow() ) {
295 SetChanged( temp != m_value );
297 return true;
302 return false;
305 /** Updates the assosiated widget, returning true on success. */
306 virtual bool TransferToWindow()
308 if ( m_widget ) {
309 wxValidator* validator = m_widget->GetValidator();
311 if ( validator )
312 return validator->TransferToWindow();
315 return false;
318 #endif
320 /** Sets the default value. */
321 void SetDefault(const TYPE& defaultVal)
323 m_default = defaultVal;
326 protected:
327 //! Reference to the associated variable
328 TYPE& m_value;
330 //! Default variable value
331 TYPE m_default;
333 //! Pointer to the widget assigned to the Cfg instance
334 wxWindow* m_widget;
338 /** Cfg class for wxStrings. */
339 class Cfg_Str : public Cfg_Tmpl<wxString>
341 public:
342 /** Constructor. */
343 Cfg_Str( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
344 : Cfg_Tmpl<wxString>( keyname, value, defaultVal )
347 /** Loads the string, using the specified default value. */
348 virtual void LoadFromFile(wxConfigBase* cfg)
350 cfg->Read( GetKey(), &m_value, m_default );
354 /** Saves the string to the specified wxConfig object. */
355 virtual void SaveToFile(wxConfigBase* cfg)
357 cfg->Write( GetKey(), m_value );
363 * Cfg-class for encrypting strings, for example for passwords.
365 class Cfg_Str_Encrypted : public Cfg_Str
367 public:
368 Cfg_Str_Encrypted( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
369 : Cfg_Str( keyname, value, defaultVal )
372 #ifndef AMULE_DAEMON
373 virtual bool TransferFromWindow()
375 // Shakraw: when storing value, store it encrypted here (only if changed in prefs)
376 if ( Cfg_Str::TransferFromWindow() ) {
378 // Only recalucate the hash for new, non-empty passwords
379 if ( HasChanged() && !m_value.IsEmpty() ) {
380 m_value = MD5Sum( m_value ).GetHash();
383 return true;
387 return false;
389 #endif
393 /** Cfg class for CPath. */
394 class Cfg_Path : public Cfg_Str
396 public:
397 /** Constructor. */
398 Cfg_Path(const wxString& keyname, CPath& value, const wxString& defaultVal = wxEmptyString )
399 : Cfg_Str(keyname, m_temp_path, defaultVal)
400 , m_real_path(value)
403 /** @see Cfg_Str::LoadFromFile. */
404 virtual void LoadFromFile(wxConfigBase* cfg)
406 Cfg_Str::LoadFromFile(cfg);
408 m_real_path = CPath::FromUniv(m_temp_path);
412 /** @see Cfg_Str::SaveToFile. */
413 virtual void SaveToFile(wxConfigBase* cfg)
415 m_temp_path = CPath::ToUniv(m_real_path);
417 Cfg_Str::SaveToFile(cfg);
421 /** @see Cfg_Tmpl::TransferToWindow. */
422 virtual bool TransferToWindow()
424 m_temp_path = m_real_path.GetRaw();
426 return Cfg_Str::TransferToWindow();
429 /** @see Cfg_Tmpl::TransferFromWindow. */
430 virtual bool TransferFromWindow()
432 if (Cfg_Str::TransferFromWindow()) {
433 m_real_path = CPath(m_temp_path);
434 return true;
437 return false;
440 private:
441 wxString m_temp_path;
442 CPath& m_real_path;
447 * Cfg class that takes care of integer types.
449 * This template is needed since wxValidator only supports normals ints, and
450 * wxConfig for the matter only supports longs, thus some worksarounds are
451 * needed.
453 * There are two work-arounds:
454 * 1) wxValidator only supports int*, so we need a immediate variable to act
455 * as a storage. Thus we use Cfg_Tmpl<int> as base class. Thus this class
456 * contains a integer which we use to pass the value back and forth
457 * between the widgets.
459 * 2) wxConfig uses longs to save and read values, thus we need an immediate
460 * stage when loading and saving the value.
462 template <typename TYPE>
463 class Cfg_Int : public Cfg_Tmpl<int>
465 public:
466 Cfg_Int( const wxString& keyname, TYPE& value, int defaultVal = 0 )
467 : Cfg_Tmpl<int>( keyname, m_temp_value, defaultVal ),
468 m_real_value( value ),
469 m_temp_value( value )
473 virtual void LoadFromFile(wxConfigBase* cfg)
475 long tmp = 0;
476 cfg->Read( GetKey(), &tmp, m_default );
478 // Set the temp value
479 m_temp_value = (int)tmp;
480 // Set the actual value
481 m_real_value = (TYPE)tmp;
484 virtual void SaveToFile(wxConfigBase* cfg)
486 cfg->Write( GetKey(), (long)m_real_value );
490 #ifndef AMULE_DAEMON
491 virtual bool TransferFromWindow()
493 if ( Cfg_Tmpl<int>::TransferFromWindow() ) {
494 m_real_value = (TYPE)m_temp_value;
496 return true;
499 return false;
502 virtual bool TransferToWindow()
504 m_temp_value = (int)m_real_value;
506 if ( Cfg_Tmpl<int>::TransferToWindow() ) {
508 // In order to let us update labels on slider-changes, we trigger a event
509 wxSlider *slider = dynamic_cast<wxSlider *>(m_widget);
510 if (slider) {
511 int id = m_widget->GetId();
512 int pos = slider->GetValue();
513 wxScrollEvent evt( wxEVT_SCROLL_THUMBRELEASE, id, pos );
514 m_widget->GetEventHandler()->ProcessEvent( evt );
517 return true;
520 return false;
522 #endif
524 protected:
526 TYPE& m_real_value;
527 int m_temp_value;
532 * Helper function for creating new Cfg_Ints.
534 * @param keyname The cfg-key under which the item should be saved.
535 * @param value The variable to syncronize. The type of this variable defines the type used to create the Cfg_Int.
536 * @param defaultVal The default value if the key isn't found when loading the value.
537 * @return A pointer to the new Cfg_Int object. The caller is responsible for deleting it.
539 * This template-function returns a Cfg_Int of the appropriate type for the
540 * variable used as argument and should be used to avoid having to specify
541 * the integer type when adding a new Cfg_Int, since that's just increases
542 * the maintainence burden.
544 template <class TYPE>
545 Cfg_Base* MkCfg_Int( const wxString& keyname, TYPE& value, int defaultVal )
547 return new Cfg_Int<TYPE>( keyname, value, defaultVal );
552 * Cfg-class for bools.
554 class Cfg_Bool : public Cfg_Tmpl<bool>
556 public:
557 Cfg_Bool( const wxString& keyname, bool& value, bool defaultVal )
558 : Cfg_Tmpl<bool>( keyname, value, defaultVal )
562 virtual void LoadFromFile(wxConfigBase* cfg)
564 cfg->Read( GetKey(), &m_value, m_default );
567 virtual void SaveToFile(wxConfigBase* cfg)
569 cfg->Write( GetKey(), m_value );
575 * Cfg-class for uint64s, with no associated widgets.
577 class Cfg_Counter : public Cfg_Base
579 public:
580 Cfg_Counter( const wxString& keyname, uint64& value )
581 : Cfg_Base( keyname ),
582 m_value( value )
585 virtual void LoadFromFile(wxConfigBase* cfg)
587 wxString buffer;
589 cfg->Read( GetKey(), &buffer, wxT("0") );
591 uint64 tmp = 0;
592 for (unsigned int i = 0; i < buffer.Length(); ++i) {
593 if ((buffer[i] >= wxChar('0')) &&(buffer[i] <= wxChar('9'))) {
594 tmp = tmp * 10 + (buffer[i] - wxChar('0'));
595 } else {
596 tmp = 0;
597 break;
600 m_value = tmp;
603 virtual void SaveToFile(wxConfigBase* cfg)
605 wxString str = CFormat( wxT("%llu") ) % m_value;
607 cfg->Write( GetKey(), str );
611 protected:
612 uint64& m_value;
616 #ifndef AMULE_DAEMON
618 class Cfg_Colour : public Cfg_Base
620 public:
621 Cfg_Colour(const wxString& key, wxColour& colour)
622 : Cfg_Base(key),
623 m_colour(colour),
624 m_default(CMuleColour(colour).GetULong())
627 virtual void LoadFromFile(wxConfigBase* cfg)
629 long int rgb;
630 cfg->Read(GetKey(), &rgb, m_default);
631 m_colour.Set(rgb);
634 virtual void SaveToFile(wxConfigBase* cfg)
636 cfg->Write(GetKey(), static_cast<long int>(CMuleColour(m_colour).GetULong()));
639 private:
640 wxColour& m_colour;
641 long int m_default;
645 typedef struct {
646 int id;
647 bool available;
648 wxString displayname;
649 wxString name;
650 } LangInfo;
654 * The languages aMule has translation for.
656 * Add new languages here, as this list overrides the one defined in muuli.wdr
658 static LangInfo aMuleLanguages[] = {
659 { wxLANGUAGE_DEFAULT, true, wxEmptyString, wxTRANSLATE("System default") },
660 { wxLANGUAGE_ALBANIAN, false, wxEmptyString, wxTRANSLATE("Albanian") },
661 { wxLANGUAGE_ARABIC, false, wxEmptyString, wxTRANSLATE("Arabic") },
662 { wxLANGUAGE_ASTURIAN, false, wxEmptyString, wxTRANSLATE("Asturian") },
663 { wxLANGUAGE_BASQUE, false, wxEmptyString, wxTRANSLATE("Basque") },
664 { wxLANGUAGE_BULGARIAN, false, wxEmptyString, wxTRANSLATE("Bulgarian") },
665 { wxLANGUAGE_CATALAN, false, wxEmptyString, wxTRANSLATE("Catalan") },
666 { wxLANGUAGE_CHINESE_SIMPLIFIED, false, wxEmptyString, wxTRANSLATE("Chinese (Simplified)") },
667 { wxLANGUAGE_CHINESE_TRADITIONAL, false, wxEmptyString, wxTRANSLATE("Chinese (Traditional)") },
668 { wxLANGUAGE_CROATIAN, false, wxEmptyString, wxTRANSLATE("Croatian") },
669 { wxLANGUAGE_CZECH, false, wxEmptyString, wxTRANSLATE("Czech") },
670 { wxLANGUAGE_DANISH, false, wxEmptyString, wxTRANSLATE("Danish") },
671 { wxLANGUAGE_DUTCH, false, wxEmptyString, wxTRANSLATE("Dutch") },
672 { wxLANGUAGE_ENGLISH, false, wxEmptyString, wxTRANSLATE("English (U.K.)") },
673 { wxLANGUAGE_ESTONIAN, false, wxEmptyString, wxTRANSLATE("Estonian") },
674 { wxLANGUAGE_FINNISH, false, wxEmptyString, wxTRANSLATE("Finnish") },
675 { wxLANGUAGE_FRENCH, false, wxEmptyString, wxTRANSLATE("French") },
676 { wxLANGUAGE_GALICIAN, false, wxEmptyString, wxTRANSLATE("Galician") },
677 { wxLANGUAGE_GERMAN, false, wxEmptyString, wxTRANSLATE("German") },
678 { wxLANGUAGE_GREEK, false, wxEmptyString, wxTRANSLATE("Greek") },
679 { wxLANGUAGE_HEBREW, false, wxEmptyString, wxTRANSLATE("Hebrew") },
680 { wxLANGUAGE_HUNGARIAN, false, wxEmptyString, wxTRANSLATE("Hungarian") },
681 { wxLANGUAGE_ITALIAN, false, wxEmptyString, wxTRANSLATE("Italian") },
682 { wxLANGUAGE_ITALIAN_SWISS, false, wxEmptyString, wxTRANSLATE("Italian (Swiss)") },
683 { wxLANGUAGE_JAPANESE, false, wxEmptyString, wxTRANSLATE("Japanese") },
684 { wxLANGUAGE_KOREAN, false, wxEmptyString, wxTRANSLATE("Korean") },
685 { wxLANGUAGE_LITHUANIAN, false, wxEmptyString, wxTRANSLATE("Lithuanian") },
686 { wxLANGUAGE_NORWEGIAN_NYNORSK, false, wxEmptyString, wxTRANSLATE("Norwegian (Nynorsk)") },
687 { wxLANGUAGE_POLISH, false, wxEmptyString, wxTRANSLATE("Polish") },
688 { wxLANGUAGE_PORTUGUESE, false, wxEmptyString, wxTRANSLATE("Portuguese") },
689 { wxLANGUAGE_PORTUGUESE_BRAZILIAN, false, wxEmptyString, wxTRANSLATE("Portuguese (Brazilian)") },
690 { wxLANGUAGE_RUSSIAN, false, wxEmptyString, wxTRANSLATE("Russian") },
691 { wxLANGUAGE_SLOVENIAN, false, wxEmptyString, wxTRANSLATE("Slovenian") },
692 { wxLANGUAGE_SPANISH, false, wxEmptyString, wxTRANSLATE("Spanish") },
693 { wxLANGUAGE_SWEDISH, false, wxEmptyString, wxTRANSLATE("Swedish") },
694 { wxLANGUAGE_TURKISH, false, wxEmptyString, wxTRANSLATE("Turkish") },
695 { wxLANGUAGE_UKRAINIAN, false, wxEmptyString, wxTRANSLATE("Ukrainian") },
699 typedef Cfg_Int<int> Cfg_PureInt;
701 class Cfg_Lang : public Cfg_PureInt
703 public:
704 Cfg_Lang()
705 : Cfg_PureInt( wxEmptyString, m_selection, 0 )
709 virtual void LoadFromFile(wxConfigBase* WXUNUSED(cfg)) {}
710 virtual void SaveToFile(wxConfigBase* WXUNUSED(cfg)) {}
713 virtual bool TransferFromWindow()
715 if ( Cfg_PureInt::TransferFromWindow() ) {
716 // find wx ID of selected language
717 int i = 0;
718 while (m_selection > 0) {
719 i++;
720 if (aMuleLanguages[i].available) {
721 m_selection--;
724 int id = aMuleLanguages[i].id;
726 // save language selection
727 thePrefs::SetLanguageID(wxLang2Str(id));
729 return true;
732 return false;
736 virtual bool TransferToWindow()
738 wxChoice *langSelector = dynamic_cast<wxChoice*>(m_widget);
739 // clear existing list
740 langSelector->Clear();
742 m_selection = 0;
743 int wxId = StrLang2wx(thePrefs::GetLanguageID());
745 // Find available languages and translate them
746 // Todo: replace the dropdown with a static text and a button "change"
747 // and move the dropdown to a popup window opened by the button.
748 // Language is changed rarely, and the go-through-all locales takes a considerable
749 // time when the settings dialog is opened for the first time.
750 if (aMuleLanguages[0].displayname == wxEmptyString) {
751 aMuleLanguages[0].displayname = wxGetTranslation(aMuleLanguages[0].name);
752 for (unsigned int i = 1; i < itemsof(aMuleLanguages); ++i) {
753 if (wxLocale::IsAvailable(aMuleLanguages[i].id)) {
754 // This supresses error-messages about invalid locales.
755 wxLogNull logTarget;
756 wxLocale locale_to_check;
758 InitLocale(locale_to_check, aMuleLanguages[i].id);
759 if (locale_to_check.IsOk() && locale_to_check.IsLoaded(wxT(PACKAGE))) {
760 aMuleLanguages[i].displayname = wxString(wxGetTranslation(aMuleLanguages[i].name)) + wxT(" [") + aMuleLanguages[i].name + wxT("]");
761 aMuleLanguages[i].available = true;
765 // Restore original locale
766 wxLocale tmpLocale;
767 InitLocale(tmpLocale, theApp->m_locale.GetLanguage());
770 // Add all available languages and find the index of the selected language.
771 for ( unsigned int i = 0, j = 0; i < itemsof(aMuleLanguages); i++) {
772 if (aMuleLanguages[i].available) {
773 langSelector->Append(aMuleLanguages[i].displayname);
774 if ( aMuleLanguages[i].id == wxId ) {
775 m_selection = j;
777 j++;
781 return Cfg_PureInt::TransferToWindow();
785 protected:
786 int m_selection;
789 #endif /* ! AMULE_DAEMON */
791 class Cfg_Skin : public Cfg_Str
793 public:
794 Cfg_Skin( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
795 : Cfg_Str( keyname, value, defaultVal ),
796 m_is_skin(false)
799 #ifndef AMULE_DAEMON
800 virtual bool TransferFromWindow()
802 if ( Cfg_Str::TransferFromWindow() ) {
803 if (m_is_skin) {
804 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
805 // "- default -" is always the first
806 if (skinSelector->GetSelection() == 0) {
807 m_value.Clear();
810 return true;
813 return false;
817 virtual bool TransferToWindow()
820 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
821 skinSelector->Clear();
823 wxString folder;
824 int flags = wxDIR_DIRS;
825 wxString filespec = wxEmptyString;
826 wxString defaultSelection = _("- default -");
827 //#warning there has to be a better way...
828 if ( GetKey() == wxT("/SkinGUIOptions/Skin") ) {
829 folder = wxT("skins");
830 m_is_skin = true;
831 flags = wxDIR_FILES;
832 filespec = wxT("*.zip");
833 skinSelector->Append(defaultSelection);
834 } else {
835 folder = wxT("webserver");
837 wxString dirName(JoinPaths(GetConfigDir(theApp->m_configFile), folder));
838 wxString Filename;
839 wxDir d;
841 if (wxDir::Exists(dirName) &&
842 d.Open(dirName) &&
843 d.GetFirst(& Filename, filespec, flags)
848 if (m_is_skin) {
849 Filename = wxT("User:") + Filename;
851 skinSelector->Append(Filename);
853 while (d.GetNext(&Filename));
856 wxString dataDir;
857 if (m_is_skin) {
858 dataDir = wxStandardPaths::Get().GetDataDir();
859 } else {
860 dataDir = wxStandardPaths::Get().GetResourcesDir();
862 #if !defined(__WXMSW__) && !defined(__WXMAC__)
863 dataDir = dataDir.BeforeLast(wxT('/')) + wxT("/amule");
864 #endif
865 wxString systemDir(JoinPaths(dataDir,folder));
867 if (wxDir::Exists(systemDir) &&
868 d.Open(systemDir) &&
869 d.GetFirst(& Filename, filespec, flags)
874 if (m_is_skin) {
875 Filename = wxT("System:") + Filename;
877 // avoid duplicates for webserver templates
878 if (skinSelector->FindString(Filename) == wxNOT_FOUND) {
879 skinSelector->Append(Filename);
882 while (d.GetNext(&Filename));
885 if ( skinSelector->GetCount() == 0 ) {
886 skinSelector->Append(_("no options available"));
889 int id = skinSelector->FindString(m_value);
890 if ( id == wxNOT_FOUND ) {
891 id = 0;
892 if (m_is_skin) {
893 m_value = defaultSelection;
896 skinSelector->SetSelection(id);
898 return Cfg_Str::TransferToWindow();
900 #endif /* ! AMULE_DAEMON */
902 protected:
903 bool m_is_skin;
907 /// new implementation
908 CPreferences::CPreferences()
910 srand( wxGetLocalTimeMillis().GetLo() ); // we need random numbers sometimes
912 // load preferences.dat or set standart values
913 wxString fullpath(theApp->ConfigDir + wxT("preferences.dat"));
914 CFile preffile;
915 if (wxFileExists(fullpath)) {
916 if (preffile.Open(fullpath, CFile::read)) {
917 try {
918 preffile.ReadUInt8(); // Version. Value is not used.
919 s_userhash = preffile.ReadHash();
920 } catch (const CSafeIOException& e) {
921 AddDebugLogLineM(true, logGeneral,
922 wxT("Error while reading userhash: ") + e.what());
927 if (s_userhash.IsEmpty()) {
928 for (int i = 0; i < 8; i++) {
929 RawPokeUInt16(s_userhash.GetHash() + (i * 2), rand());
932 Save();
935 // Mark hash as an eMule-type hash
936 // See also CUpDownClient::GetHashType
937 s_userhash[5] = 14;
938 s_userhash[14] = 111;
940 #ifndef CLIENT_GUI
941 LoadPreferences();
942 ReloadSharedFolders();
944 // serverlist adresses
945 CTextFile slistfile;
946 if (slistfile.Open(theApp->ConfigDir + wxT("addresses.dat"), CTextFile::read)) {
947 adresses_list = slistfile.ReadLines();
949 #endif
953 // Gets called at init time
955 void CPreferences::BuildItemList( const wxString& appdir )
957 #ifndef AMULE_DAEMON
958 #define NewCfgItem(ID, COMMAND) s_CfgList[ID] = COMMAND
959 #else
960 int current_id = 0;
961 #define NewCfgItem(ID, COMMAND) s_CfgList[++current_id] = COMMAND
962 #endif /* AMULE_DAEMON */
965 * User settings
967 NewCfgItem(IDC_NICK, (new Cfg_Str( wxT("/eMule/Nick"), s_nick, wxT("http://www.aMule.org") )));
968 #ifndef AMULE_DAEMON
969 NewCfgItem(IDC_LANGUAGE, (new Cfg_Lang()));
970 #endif
973 * Browser options
975 #ifdef __WXMAC__
976 wxString customBrowser = wxT("/usr/bin/open");
977 #else
978 wxString customBrowser; // left empty
979 #endif
981 NewCfgItem(IDC_BROWSERTABS, (new Cfg_Bool( wxT("/Browser/OpenPageInTab"), s_BrowserTab, true )));
982 NewCfgItem(IDC_BROWSERSELF, (new Cfg_Str( wxT("/Browser/CustomBrowserString"), s_CustomBrowser, customBrowser )));
986 * Misc
988 NewCfgItem(IDC_QUEUESIZE, (MkCfg_Int( wxT("/eMule/QueueSizePref"), s_iQueueSize, 50 )));
991 #ifdef __DEBUG__
993 * Debugging
995 NewCfgItem(ID_VERBOSEDEBUG, (new Cfg_Bool( wxT("/eMule/VerboseDebug"), s_bVerbose, false )));
996 #endif
999 * Connection settings
1001 NewCfgItem(IDC_MAXUP, (MkCfg_Int( wxT("/eMule/MaxUpload"), s_maxupload, 0 )));
1002 NewCfgItem(IDC_MAXDOWN, (MkCfg_Int( wxT("/eMule/MaxDownload"), s_maxdownload, 0 )));
1003 NewCfgItem(IDC_SLOTALLOC, (MkCfg_Int( wxT("/eMule/SlotAllocation"), s_slotallocation, 2 )));
1004 NewCfgItem(IDC_PORT, (MkCfg_Int( wxT("/eMule/Port"), s_port, DEFAULT_TCP_PORT )));
1005 NewCfgItem(IDC_UDPPORT, (MkCfg_Int( wxT("/eMule/UDPPort"), s_udpport, DEFAULT_UDP_PORT )));
1006 NewCfgItem(IDC_UDPENABLE, (new Cfg_Bool( wxT("/eMule/UDPEnable"), s_UDPEnable, true )));
1007 NewCfgItem(IDC_ADDRESS, (new Cfg_Str( wxT("/eMule/Address"), s_Addr, wxEmptyString)));
1008 NewCfgItem(IDC_AUTOCONNECT, (new Cfg_Bool( wxT("/eMule/Autoconnect"), s_autoconnect, true )));
1009 NewCfgItem(IDC_MAXSOURCEPERFILE, (MkCfg_Int( wxT("/eMule/MaxSourcesPerFile"), s_maxsourceperfile, 300 )));
1010 NewCfgItem(IDC_MAXCON, (MkCfg_Int( wxT("/eMule/MaxConnections"), s_maxconnections, GetRecommendedMaxConnections() )));
1011 NewCfgItem(IDC_MAXCON5SEC, (MkCfg_Int( wxT("/eMule/MaxConnectionsPerFiveSeconds"), s_MaxConperFive, 20 )));
1014 * Proxy
1016 NewCfgItem(ID_PROXY_ENABLE_PROXY, (new Cfg_Bool( wxT("/Proxy/ProxyEnableProxy"), s_ProxyData.m_proxyEnable, false )));
1017 NewCfgItem(ID_PROXY_TYPE, (MkCfg_Int( wxT("/Proxy/ProxyType"), s_ProxyData.m_proxyType, 0 )));
1018 NewCfgItem(ID_PROXY_NAME, (new Cfg_Str( wxT("/Proxy/ProxyName"), s_ProxyData.m_proxyHostName, wxEmptyString )));
1019 NewCfgItem(ID_PROXY_PORT, (MkCfg_Int( wxT("/Proxy/ProxyPort"), s_ProxyData.m_proxyPort, 1080 )));
1020 NewCfgItem(ID_PROXY_ENABLE_PASSWORD, (new Cfg_Bool( wxT("/Proxy/ProxyEnablePassword"), s_ProxyData.m_enablePassword, false )));
1021 NewCfgItem(ID_PROXY_USER, (new Cfg_Str( wxT("/Proxy/ProxyUser"), s_ProxyData.m_userName, wxEmptyString )));
1022 NewCfgItem(ID_PROXY_PASSWORD, (new Cfg_Str( wxT("/Proxy/ProxyPassword"), s_ProxyData.m_password, wxEmptyString )));
1023 // These were copied from eMule config file, maybe someone with windows can complete this?
1024 // NewCfgItem(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, (new Cfg_Bool( wxT("/Proxy/Proxy????"), s_Proxy????, false )));
1027 * Servers
1028 **/
1029 NewCfgItem(IDC_REMOVEDEAD, (new Cfg_Bool( wxT("/eMule/RemoveDeadServer"), s_deadserver, 1 )));
1030 NewCfgItem(IDC_SERVERRETRIES, (MkCfg_Int( wxT("/eMule/DeadServerRetry"), s_deadserverretries, 3 )));
1031 NewCfgItem(IDC_SERVERKEEPALIVE, (MkCfg_Int( wxT("/eMule/ServerKeepAliveTimeout"), s_dwServerKeepAliveTimeoutMins, 0 )));
1032 NewCfgItem(IDC_RECONN, (new Cfg_Bool( wxT("/eMule/Reconnect"), s_reconnect, true )));
1033 NewCfgItem(IDC_SCORE, (new Cfg_Bool( wxT("/eMule/Scoresystem"), s_scorsystem, true )));
1034 NewCfgItem(IDC_AUTOSERVER, (new Cfg_Bool( wxT("/eMule/Serverlist"), s_autoserverlist, false )));
1035 NewCfgItem(IDC_UPDATESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/AddServerListFromServer"), s_addserversfromserver, false)));
1036 NewCfgItem(IDC_UPDATESERVERCLIENT, (new Cfg_Bool( wxT("/eMule/AddServerListFromClient"), s_addserversfromclient, false )));
1037 NewCfgItem(IDC_SAFESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/SafeServerConnect"), s_safeServerConnect, false )));
1038 NewCfgItem(IDC_AUTOCONNECTSTATICONLY, (new Cfg_Bool( wxT("/eMule/AutoConnectStaticOnly"), s_autoconnectstaticonly, false )));
1039 NewCfgItem(IDC_UPNP_ENABLED, (new Cfg_Bool( wxT("/eMule/UPnPEnabled"), s_UPnPEnabled, false )));
1040 NewCfgItem(IDC_UPNPTCPPORT, (MkCfg_Int( wxT("/eMule/UPnPTCPPort"), s_UPnPTCPPort, 50000 )));
1041 NewCfgItem(IDC_SMARTIDCHECK, (new Cfg_Bool( wxT("/eMule/SmartIdCheck"), s_smartidcheck, true )));
1042 // Enabled networks
1043 NewCfgItem( IDC_NETWORKKAD, (new Cfg_Bool( wxT("/eMule/ConnectToKad"), s_ConnectToKad, true )) );
1044 NewCfgItem( IDC_NETWORKED2K, ( new Cfg_Bool( wxT("/eMule/ConnectToED2K"), s_ConnectToED2K, true ) ));
1048 * Files
1050 NewCfgItem(IDC_TEMPFILES, (new Cfg_Path( wxT("/eMule/TempDir"), s_tempdir, appdir + wxT("Temp") )));
1052 #if defined(__WXMAC__) || defined(__WXMSW__)
1053 wxString incpath = wxStandardPaths::Get().GetDocumentsDir();
1054 if (incpath.IsEmpty()) {
1055 // There is a built-in possibility for this call to fail, though I can't imagine a reason for that.
1056 incpath = appdir + wxT("Incoming");
1057 } else {
1058 incpath = JoinPaths(incpath, wxT("aMule Downloads"));
1060 #else
1061 wxString incpath = appdir + wxT("Incoming");
1062 #endif
1063 NewCfgItem(IDC_INCFILES, (new Cfg_Path( wxT("/eMule/IncomingDir"), s_incomingdir, incpath )));
1065 NewCfgItem(IDC_ICH, (new Cfg_Bool( wxT("/eMule/ICH"), s_ICH, true )));
1066 NewCfgItem(IDC_AICHTRUST, (new Cfg_Bool( wxT("/eMule/AICHTrust"), s_AICHTrustEveryHash, false )));
1067 NewCfgItem(IDC_CHECKDISKSPACE, (new Cfg_Bool( wxT("/eMule/CheckDiskspace"), s_checkDiskspace, true )));
1068 NewCfgItem(IDC_MINDISKSPACE, (MkCfg_Int( wxT("/eMule/MinFreeDiskSpace"), s_uMinFreeDiskSpace, 1 )));
1069 NewCfgItem(IDC_ADDNEWFILESPAUSED, (new Cfg_Bool( wxT("/eMule/AddNewFilesPaused"), s_addnewfilespaused, false )));
1070 NewCfgItem(IDC_PREVIEWPRIO, (new Cfg_Bool( wxT("/eMule/PreviewPrio"), s_bpreviewprio, false )));
1071 NewCfgItem(IDC_MANUALSERVERHIGHPRIO, (new Cfg_Bool( wxT("/eMule/ManualHighPrio"), s_bmanualhighprio, false )));
1072 NewCfgItem(IDC_FULLCHUNKTRANS, (new Cfg_Bool( wxT("/eMule/FullChunkTransfers"), s_btransferfullchunks, true )));
1073 NewCfgItem(IDC_STARTNEXTFILE, (new Cfg_Bool( wxT("/eMule/StartNextFile"), s_bstartnextfile, false )));
1074 NewCfgItem(IDC_STARTNEXTFILE_SAME, (new Cfg_Bool( wxT("/eMule/StartNextFileSameCat"), s_bstartnextfilesame, false )));
1075 NewCfgItem(IDC_SRCSEEDS, (new Cfg_Bool( wxT("/ExternalConnect/UseSrcSeeds"), s_UseSrcSeeds, false )));
1076 NewCfgItem(IDC_FILEBUFFERSIZE, (MkCfg_Int( wxT("/eMule/FileBufferSizePref"), s_iFileBufferSize, 16 )));
1077 NewCfgItem(IDC_DAP, (new Cfg_Bool( wxT("/eMule/DAPPref"), s_bDAP, true )));
1078 NewCfgItem(IDC_UAP, (new Cfg_Bool( wxT("/eMule/UAPPref"), s_bUAP, true )));
1079 NewCfgItem(IDC_ALLOCFULLFILE, (new Cfg_Bool( wxT("/eMule/AllocateFullFile"), s_allocFullFile, false )));
1082 * Web Server
1084 NewCfgItem(IDC_OSDIR, (new Cfg_Path( wxT("/eMule/OSDirectory"), s_OSDirectory, appdir )));
1085 NewCfgItem(IDC_ONLINESIG, (new Cfg_Bool( wxT("/eMule/OnlineSignature"), s_onlineSig, false )));
1086 NewCfgItem(IDC_OSUPDATE, (MkCfg_Int( wxT("/eMule/OnlineSignatureUpdate"), s_OSUpdate, 5 )));
1087 NewCfgItem(IDC_ENABLE_WEB, (new Cfg_Bool( wxT("/WebServer/Enabled"), s_bWebEnabled, false )));
1088 NewCfgItem(IDC_WEB_PASSWD, (new Cfg_Str_Encrypted( wxT("/WebServer/Password"), s_sWebPassword )));
1089 NewCfgItem(IDC_WEB_PASSWD_LOW, (new Cfg_Str_Encrypted( wxT("/WebServer/PasswordLow"), s_sWebLowPassword )));
1090 NewCfgItem(IDC_WEB_PORT, (MkCfg_Int( wxT("/WebServer/Port"), s_nWebPort, 4711 )));
1091 NewCfgItem(IDC_WEBUPNPTCPPORT, (MkCfg_Int( wxT("/WebServer/WebUPnPTCPPort"), s_nWebUPnPTCPPort, 50001 )));
1092 NewCfgItem(IDC_UPNP_WEBSERVER_ENABLED,
1093 (new Cfg_Bool( wxT("/WebServer/UPnPWebServerEnabled"), s_UPnPWebServerEnabled, false )));
1094 NewCfgItem(IDC_WEB_GZIP, (new Cfg_Bool( wxT("/WebServer/UseGzip"), s_bWebUseGzip, true )));
1095 NewCfgItem(IDC_ENABLE_WEB_LOW, (new Cfg_Bool( wxT("/WebServer/UseLowRightsUser"), s_bWebLowEnabled, false )));
1096 NewCfgItem(IDC_WEB_REFRESH_TIMEOUT, (MkCfg_Int( wxT("/WebServer/PageRefreshTime"), s_nWebPageRefresh, 120 )));
1097 NewCfgItem(IDC_WEBTEMPLATE, (new Cfg_Skin( wxT("/WebServer/Template"), s_WebTemplate, wxEmptyString )));
1100 * External Connections
1102 NewCfgItem(IDC_EXT_CONN_ACCEPT, (new Cfg_Bool( wxT("/ExternalConnect/AcceptExternalConnections"), s_AcceptExternalConnections, false )));
1103 NewCfgItem(IDC_EXT_CONN_IP, (new Cfg_Str( wxT("/ExternalConnect/ECAddress"), s_ECAddr, wxEmptyString )));
1104 NewCfgItem(IDC_EXT_CONN_TCP_PORT, (MkCfg_Int( wxT("/ExternalConnect/ECPort"), s_ECPort, 4712 )));
1105 NewCfgItem(IDC_EXT_CONN_PASSWD, (new Cfg_Str_Encrypted( wxT("/ExternalConnect/ECPassword"), s_ECPassword, wxEmptyString )));
1106 NewCfgItem(IDC_UPNP_EC_ENABLED, (new Cfg_Bool( wxT("/ExternalConnect/UPnPECEnabled"), s_UPnPECEnabled, false )));
1109 * GUI behavior
1111 NewCfgItem(IDC_ENABLETRAYICON, (new Cfg_Bool( wxT("/eMule/EnableTrayIcon"), s_trayiconenabled, false )));
1112 NewCfgItem(IDC_MINTRAY, (new Cfg_Bool( wxT("/eMule/MinToTray"), s_mintotray, false )));
1113 NewCfgItem(IDC_EXIT, (new Cfg_Bool( wxT("/eMule/ConfirmExit"), s_confirmExit, true )));
1114 NewCfgItem(IDC_STARTMIN, (new Cfg_Bool( wxT("/eMule/StartupMinimized"), s_startMinimized, false )));
1117 * GUI appearence
1119 NewCfgItem(IDC_3DDEPTH, (MkCfg_Int( wxT("/eMule/3DDepth"), s_depth3D, 10 )));
1120 NewCfgItem(IDC_TOOLTIPDELAY, (MkCfg_Int( wxT("/eMule/ToolTipDelay"), s_iToolDelayTime, 1 )));
1121 NewCfgItem(IDC_SHOWOVERHEAD, (new Cfg_Bool( wxT("/eMule/ShowOverhead"), s_bshowoverhead, false )));
1122 NewCfgItem(IDC_EXTCATINFO, (new Cfg_Bool( wxT("/eMule/ShowInfoOnCatTabs"), s_showCatTabInfos, true )));
1123 NewCfgItem(IDC_FED2KLH, (new Cfg_Bool( wxT("/Razor_Preferences/FastED2KLinksHandler"), s_FastED2KLinksHandler, true )));
1124 NewCfgItem(IDC_PROGBAR, (new Cfg_Bool( wxT("/ExternalConnect/ShowProgressBar"), s_ProgBar, true )));
1125 NewCfgItem(IDC_PERCENT, (new Cfg_Bool( wxT("/ExternalConnect/ShowPercent"), s_Percent, true )));
1126 NewCfgItem(IDC_SKIN, (new Cfg_Skin( wxT("/SkinGUIOptions/Skin"), s_Skin, wxEmptyString )));
1127 NewCfgItem(IDC_VERTTOOLBAR, (new Cfg_Bool( wxT("/eMule/VerticalToolbar"), s_ToolbarOrientation, false )));
1130 * External Apps
1132 NewCfgItem(IDC_VIDEOPLAYER, (new Cfg_Str( wxT("/eMule/VideoPlayer"), s_VideoPlayer, wxEmptyString )));
1133 NewCfgItem(IDC_VIDEOBACKUP, (new Cfg_Bool( wxT("/eMule/VideoPreviewBackupped"), s_moviePreviewBackup, true )));
1136 * Statistics
1138 NewCfgItem(IDC_SLIDER, (MkCfg_Int( wxT("/eMule/StatGraphsInterval"), s_trafficOMeterInterval, 3 )));
1139 NewCfgItem(IDC_SLIDER2, (MkCfg_Int( wxT("/eMule/statsInterval"), s_statsInterval, 30 )));
1140 NewCfgItem(IDC_DOWNLOAD_CAP, (MkCfg_Int( wxT("/eMule/DownloadCapacity"), s_maxGraphDownloadRate, 300 )));
1141 NewCfgItem(IDC_UPLOAD_CAP, (MkCfg_Int( wxT("/eMule/UploadCapacity"), s_maxGraphUploadRate, 100 )));
1142 NewCfgItem(IDC_SLIDER3, (MkCfg_Int( wxT("/eMule/StatsAverageMinutes"), s_statsAverageMinutes, 5 )));
1143 NewCfgItem(IDC_SLIDER4, (MkCfg_Int( wxT("/eMule/VariousStatisticsMaxValue"), s_statsMax, 100 )));
1144 NewCfgItem(IDC_CLIENTVERSIONS, (MkCfg_Int( wxT("/Statistics/MaxClientVersions"), s_maxClientVersions, 0 )));
1147 * Security
1149 NewCfgItem(IDC_SEESHARES, (MkCfg_Int( wxT("/eMule/SeeShare"), s_iSeeShares, 2 )));
1150 NewCfgItem(IDC_SECIDENT, (new Cfg_Bool( wxT("/ExternalConnect/UseSecIdent"), s_SecIdent, true )));
1151 NewCfgItem(IDC_IPFCLIENTS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterClients"), s_IPFilterClients, true )));
1152 NewCfgItem(IDC_IPFSERVERS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterServers"), s_IPFilterServers, true )));
1153 NewCfgItem(IDC_FILTERLAN, (new Cfg_Bool( wxT("/eMule/FilterLanIPs"), s_filterLanIP, true )));
1154 NewCfgItem(IDC_PARANOID, (new Cfg_Bool( wxT("/eMule/ParanoidFiltering"), s_paranoidfilter, true )));
1155 NewCfgItem(IDC_AUTOIPFILTER, (new Cfg_Bool( wxT("/eMule/IPFilterAutoLoad"), s_IPFilterAutoLoad, true )));
1156 NewCfgItem(IDC_IPFILTERURL, (new Cfg_Str( wxT("/eMule/IPFilterURL"), s_IPFilterURL, wxEmptyString )));
1157 NewCfgItem(ID_IPFILTERLEVEL, (MkCfg_Int( wxT("/eMule/FilterLevel"), s_filterlevel, 127 )));
1158 NewCfgItem(IDC_IPFILTERSYS, (new Cfg_Bool( wxT("/eMule/IPFilterSystem"), s_IPFilterSys, false )));
1160 /**
1161 * Message Filter
1163 NewCfgItem(IDC_MSGFILTER, (new Cfg_Bool( wxT("/eMule/FilterMessages"), s_MustFilterMessages, true )));
1164 NewCfgItem(IDC_MSGFILTER_ALL, (new Cfg_Bool( wxT("/eMule/FilterAllMessages"), s_FilterAllMessages, false )));
1165 NewCfgItem(IDC_MSGFILTER_NONFRIENDS, (new Cfg_Bool( wxT("/eMule/MessagesFromFriendsOnly"), s_msgonlyfriends, false )));
1166 NewCfgItem(IDC_MSGFILTER_NONSECURE, (new Cfg_Bool( wxT("/eMule/MessageFromValidSourcesOnly"), s_msgsecure, true )));
1167 NewCfgItem(IDC_MSGFILTER_WORD, (new Cfg_Bool( wxT("/eMule/FilterWordMessages"), s_FilterSomeMessages, false )));
1168 NewCfgItem(IDC_MSGWORD, (new Cfg_Str( wxT("/eMule/MessageFilter"), s_MessageFilterString, wxEmptyString )));
1169 NewCfgItem(IDC_MSGLOG, (new Cfg_Bool( wxT("/eMule/ShowMessagesInLog"), s_ShowMessagesInLog, true )));
1170 //Todo NewCfgItem(IDC_MSGADVSPAM, (new Cfg_Bool( wxT("/eMule/AdvancedSpamFilter"), s_IsAdvancedSpamfilterEnabled, true )));
1171 //Todo NewCfgItem(IDC_MSGCAPTCHA, (new Cfg_Bool( wxT("/eMule/MessageUseCaptchas"), s_IsChatCaptchaEnabled, true )));
1172 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/AdvancedSpamFilter"), s_IsAdvancedSpamfilterEnabled, true ) );
1173 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/MessageUseCaptchas"), s_IsChatCaptchaEnabled, true ) );
1175 NewCfgItem(IDC_FILTERCOMMENTS, (new Cfg_Bool( wxT("/eMule/FilterComments"), s_FilterComments, false )));
1176 NewCfgItem(IDC_COMMENTWORD, (new Cfg_Str( wxT("/eMule/CommentFilter"), s_CommentFilterString, wxEmptyString )));
1179 * Hidden files sharing
1180 **/
1181 NewCfgItem(IDC_SHAREHIDDENFILES, (new Cfg_Bool( wxT("/eMule/ShareHiddenFiles"), s_ShareHiddenFiles, false )));
1184 * Auto-Sorting of downloads
1186 NewCfgItem(IDC_AUTOSORT, (new Cfg_Bool( wxT("/eMule/AutoSortDownloads"), s_AutoSortDownload, false )));
1189 * Version check
1191 NewCfgItem(IDC_NEWVERSION, (new Cfg_Bool( wxT("/eMule/NewVersionCheck"), s_NewVersionCheck, true )));
1194 * Obfuscation
1196 NewCfgItem( IDC_SUPPORT_PO, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerSupported"), s_IsClientCryptLayerSupported, true )));
1197 NewCfgItem( IDC_ENABLE_PO_OUTGOING, ( new Cfg_Bool( wxT("/Obfuscation/IsCryptLayerRequested"), s_bCryptLayerRequested, true )));
1198 NewCfgItem( IDC_ENFORCE_PO_INCOMING, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerRequired"), s_IsClientCryptLayerRequired, false )));
1199 #ifndef CLIENT_GUI
1200 // There is no need for GUI items for this two.
1201 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoPaddingLenght"), s_byCryptTCPPaddingLength, 254 ) );
1202 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoKadUDPKey"), s_dwKadUDPKey, GetRandomUint32() ) );
1203 #endif
1206 * The following doesn't have an associated widget or section
1208 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Language"), s_languageID ) );
1209 s_MiscList.push_back( new Cfg_Counter( wxT("/Statistics/TotalDownloadedBytes"), s_totalDownloadedBytes ) );
1210 s_MiscList.push_back( new Cfg_Counter( wxT("/Statistics/TotalUploadedBytes"), s_totalUploadedBytes ) );
1211 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SplitterbarPosition"), s_splitterbarPosition, 75 ) );
1212 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/YourHostname"), s_yourHostname, wxEmptyString ) );
1213 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/DateTimeFormat"), s_datetimeformat, wxT("%A, %x, %X") ) );
1215 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/AllcatType"), s_allcatType, 0 ) );
1216 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/ShowAllNotCats"), s_showAllNotCats, false ) );
1218 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SmartIdState"), s_smartidstate, 0 ) );
1220 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/DropSlowSources"), s_DropSlowSources, false ) );
1222 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/KadNodesUrl"), s_KadURL, wxT("http://download.tuxfamily.org/technosalad/utils/nodes.dat") ) );
1223 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Ed2kServersUrl"), s_Ed2kURL, wxT("http://gruk.org/server.met.gz") ) );
1224 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/ShowRatesOnTitle"), s_showRatesOnTitle, 0 ));
1226 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/GeoIPEnabled"), s_GeoIPEnabled, true ) );
1227 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/GeoLiteCountryUpdateUrl"), s_GeoIPUpdateUrl, wxT("http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz") ) );
1228 wxConfigBase::Get()->DeleteEntry(wxT("/eMule/GeoIPUpdateUrl")); // get rid of the old one for a while
1230 s_MiscList.push_back( new Cfg_Str( wxT("/WebServer/Path"), s_sWebPath, wxT("amuleweb") ) );
1232 #ifndef AMULE_DAEMON
1233 // Colors have been moved from global prefs to CStatisticsDlg
1234 for ( int i = 0; i < cntStatColors; i++ ) {
1235 wxString str = wxString::Format(wxT("/eMule/StatColor%i"),i);
1236 s_MiscList.push_back( new Cfg_Colour( str, CStatisticsDlg::acrStat[i] ) );
1238 #endif
1240 // User events
1241 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1242 // We can't use NewCfgItem here, because we need to find these items
1243 // later, which would be impossible in amuled with NewCfgItem.
1244 // The IDs we assign here are high enough to not cause any collision
1245 // even on the daemon.
1246 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);
1247 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);
1248 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);
1249 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);
1254 void CPreferences::EraseItemList()
1256 while ( s_CfgList.begin() != s_CfgList.end() ) {
1257 delete s_CfgList.begin()->second;
1258 s_CfgList.erase( s_CfgList.begin() );
1261 CFGList::iterator it = s_MiscList.begin();
1262 for ( ; it != s_MiscList.end(); ) {
1263 delete *it;
1264 it = s_MiscList.erase( it );
1269 void CPreferences::LoadAllItems(wxConfigBase* cfg)
1271 #ifndef CLIENT_GUI
1272 // Preserve values from old config. The global config object may not be set yet
1273 // when BuildItemList() is called, so we need to provide defaults later - here.
1274 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletion"))) {
1275 bool ExecOnCompletion;
1276 cfg->Read(wxT("/eMule/ExecOnCompletion"), &ExecOnCompletion, false);
1277 // Assign to core command, that's the most likely it was.
1278 static_cast<Cfg_Bool*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT + 1])->SetDefault(ExecOnCompletion);
1279 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletion"));
1281 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletionCommand"))) {
1282 wxString ExecOnCompletionCommand;
1283 cfg->Read(wxT("/eMule/ExecOnCompletionCommand"), &ExecOnCompletionCommand, wxEmptyString);
1284 static_cast<Cfg_Str*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT + 2])->SetDefault(ExecOnCompletionCommand);
1285 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletionCommand"));
1287 #endif
1288 CFGMap::iterator it_a = s_CfgList.begin();
1289 for ( ; it_a != s_CfgList.end(); ++it_a ) {
1290 it_a->second->LoadFromFile( cfg );
1293 CFGList::iterator it_b = s_MiscList.begin();
1294 for ( ; it_b != s_MiscList.end(); ++it_b ) {
1295 (*it_b)->LoadFromFile( cfg );
1298 // Preserve old value of UDPDisable
1299 if (cfg->HasEntry(wxT("/eMule/UDPDisable"))) {
1300 bool UDPDisable;
1301 cfg->Read(wxT("/eMule/UDPDisable"), &UDPDisable, false);
1302 SetUDPDisable(UDPDisable);
1303 cfg->DeleteEntry(wxT("/eMule/UDPDisable"));
1306 // Preserve old value of UseSkinFiles
1307 if (cfg->HasEntry(wxT("/SkinGUIOptions/UseSkinFiles"))) {
1308 bool UseSkinFiles;
1309 cfg->Read(wxT("/SkinGUIOptions/UseSkinFiles"), &UseSkinFiles, false);
1310 if (!UseSkinFiles) {
1311 s_Skin.Clear();
1313 cfg->DeleteEntry(wxT("/SkinGUIOptions/UseSkinFiles"));
1316 #ifdef __DEBUG__
1317 // Load debug-categories
1318 int count = theLogger.GetDebugCategoryCount();
1320 for ( int i = 0; i < count; i++ ) {
1321 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1323 bool enabled = false;
1324 cfg->Read( wxT("/Debug/Cat_") + cat.GetName(), &enabled );
1326 theLogger.SetEnabled( cat.GetType(), enabled );
1328 #endif
1330 // Now do some post-processing / sanity checking on the values we just loaded
1331 #ifndef CLIENT_GUI
1332 CheckUlDlRatio();
1333 SetPort(s_port);
1334 if (s_byCryptTCPPaddingLength > 254) {
1335 s_byCryptTCPPaddingLength = GetRandomUint8() % 254;
1337 SetSlotAllocation(s_slotallocation);
1338 #endif
1342 void CPreferences::SaveAllItems(wxConfigBase* cfg)
1344 // Save the Cfg values
1345 CFGMap::iterator it_a = s_CfgList.begin();
1346 for ( ; it_a != s_CfgList.end(); ++it_a )
1347 it_a->second->SaveToFile( cfg );
1349 CFGList::iterator it_b = s_MiscList.begin();
1350 for ( ; it_b != s_MiscList.end(); ++it_b )
1351 (*it_b)->SaveToFile( cfg );
1354 // Save debug-categories
1355 #ifdef __DEBUG__
1356 int count = theLogger.GetDebugCategoryCount();
1358 for ( int i = 0; i < count; i++ ) {
1359 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1361 cfg->Write( wxT("/Debug/Cat_") + cat.GetName(), cat.IsEnabled() );
1363 #endif
1366 void CPreferences::SetMaxUpload(uint16 in)
1368 if ( s_maxupload != in ) {
1369 s_maxupload = in;
1371 // Ensure that the ratio is upheld
1372 CheckUlDlRatio();
1377 void CPreferences::SetMaxDownload(uint16 in)
1379 if ( s_maxdownload != in ) {
1380 s_maxdownload = in;
1382 // Ensure that the ratio is upheld
1383 CheckUlDlRatio();
1388 void CPreferences::UnsetAutoServerStart()
1390 s_autoserverlist = false;
1394 // Here we slightly limit the users' ability to be a bad citizen: for very low upload rates
1395 // we force a low download rate, so as to discourage this type of leeching.
1396 // We're Open Source, and whoever wants it can do his own mod to get around this, but the
1397 // packaged product will try to enforce good behavior.
1399 // Kry note: of course, any leecher mod will be banned asap.
1400 void CPreferences::CheckUlDlRatio()
1402 // Backwards compatibility
1403 if ( s_maxupload == 0xFFFF )
1404 s_maxupload = UNLIMITED;
1406 // Backwards compatibility
1407 if ( s_maxdownload == 0xFFFF )
1408 s_maxdownload = UNLIMITED;
1410 if ( s_maxupload == UNLIMITED )
1411 return;
1413 // Enforce the limits
1414 if ( s_maxupload < 4 ) {
1415 if ( ( s_maxupload * 3 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1416 s_maxdownload = s_maxupload * 3 ;
1417 } else if ( s_maxupload < 10 ) {
1418 if ( ( s_maxupload * 4 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1419 s_maxdownload = s_maxupload * 4;
1424 void CPreferences::Save()
1426 wxString fullpath(theApp->ConfigDir + wxT("preferences.dat"));
1428 CFile preffile;
1429 if (!wxFileExists(fullpath)) {
1430 preffile.Create(fullpath);
1433 if (preffile.Open(fullpath, CFile::read_write)) {
1434 try {
1435 preffile.WriteUInt8(PREFFILE_VERSION);
1436 preffile.WriteHash(s_userhash);
1437 } catch (const CIOFailureException& e) {
1438 AddDebugLogLineM(true, logGeneral, wxT("IO failure while saving user-hash: ") + e.what());
1442 SavePreferences();
1444 #ifndef CLIENT_GUI
1445 CTextFile sdirfile;
1446 if (sdirfile.Open(theApp->ConfigDir + wxT("shareddir.dat"), CTextFile::write)) {
1447 for (size_t i = 0; i < shareddir_list.size(); ++i) {
1448 sdirfile.WriteLine(CPath::ToUniv(shareddir_list[i]), wxConvUTF8);
1452 #endif
1456 CPreferences::~CPreferences()
1458 DeleteContents(m_CatList);
1462 int32 CPreferences::GetRecommendedMaxConnections()
1464 #ifndef CLIENT_GUI
1465 int iRealMax = PlatformSpecific::GetMaxConnections();
1466 if(iRealMax == -1 || iRealMax > 520) {
1467 return 500;
1469 if(iRealMax < 20) {
1470 return iRealMax;
1472 if(iRealMax <= 256) {
1473 return iRealMax - 10;
1475 return iRealMax - 20;
1476 #else
1477 return 500;
1478 #endif
1482 void CPreferences::SavePreferences()
1484 wxConfigBase* cfg = wxConfigBase::Get();
1486 cfg->Write( wxT("/eMule/AppVersion"), wxT(VERSION) );
1488 // Save the options
1489 SaveAllItems( cfg );
1491 // Ensure that the changes are saved to disk.
1492 cfg->Flush();
1496 void CPreferences::SaveCats()
1498 if ( GetCatCount() ) {
1499 wxConfigBase* cfg = wxConfigBase::Get();
1501 // Save the main cat.
1502 cfg->Write( wxT("/eMule/AllcatType"), (int)s_allcatType);
1504 // The first category is the default one and should not be counted
1506 cfg->Write( wxT("/General/Count"), (long)(m_CatList.size() - 1) );
1508 for ( size_t i = 1; i < m_CatList.size(); i++ ) {
1509 cfg->SetPath( wxString::Format(wxT("/Cat#%i"), i) );
1511 cfg->Write( wxT("Title"), m_CatList[i]->title );
1512 cfg->Write( wxT("Incoming"), CPath::ToUniv(m_CatList[i]->path) );
1513 cfg->Write( wxT("Comment"), m_CatList[i]->comment );
1514 cfg->Write( wxT("Color"), wxString::Format(wxT("%u"), m_CatList[i]->color) );
1515 cfg->Write( wxT("Priority"), (int)m_CatList[i]->prio );
1518 cfg->Flush();
1523 void CPreferences::LoadPreferences()
1525 LoadCats();
1529 void CPreferences::LoadCats()
1531 // default cat ... Meow! =(^.^)=
1532 Category_Struct* defaultcat = new Category_Struct;
1533 defaultcat->prio = 0;
1534 defaultcat->color = 0;
1536 AddCat( defaultcat );
1538 wxConfigBase* cfg = wxConfigBase::Get();
1540 long max = cfg->Read( wxT("/General/Count"), 0l );
1542 for ( int i = 1; i <= max ; i++ ) {
1543 cfg->SetPath( wxString::Format(wxT("/Cat#%i"), i) );
1545 Category_Struct* newcat = new Category_Struct;
1547 newcat->title = cfg->Read( wxT("Title"), wxEmptyString );
1548 newcat->path = CPath::FromUniv(cfg->Read(wxT("Incoming"), wxEmptyString));
1550 // Some sainity checking
1551 if ( newcat->title.IsEmpty() || !newcat->path.IsOk() ) {
1552 AddLogLineN(_("Invalid category found, skipping"));
1554 delete newcat;
1555 continue;
1558 newcat->comment = cfg->Read( wxT("Comment"), wxEmptyString );
1559 newcat->prio = cfg->Read( wxT("Priority"), 0l );
1560 newcat->color = StrToULong(cfg->Read(wxT("Color"), wxT("0")));
1562 AddCat(newcat);
1564 if (!newcat->path.DirExists()) {
1565 CPath::MakeDir(newcat->path);
1571 uint16 CPreferences::GetDefaultMaxConperFive()
1573 return MAXCONPER5SEC;
1577 uint32 CPreferences::AddCat(Category_Struct* cat)
1579 m_CatList.push_back( cat );
1581 return m_CatList.size() - 1;
1585 void CPreferences::RemoveCat(size_t index)
1587 if ( index < m_CatList.size() ) {
1588 CatList::iterator it = m_CatList.begin() + index;
1590 delete *it;
1592 m_CatList.erase( it );
1597 uint32 CPreferences::GetCatCount()
1599 return m_CatList.size();
1603 Category_Struct* CPreferences::GetCategory(size_t index)
1605 wxASSERT( index < m_CatList.size() );
1607 return m_CatList[index];
1611 const CPath& CPreferences::GetCatPath(uint8 index)
1613 wxASSERT( index < m_CatList.size() );
1615 return m_CatList[index]->path;
1619 uint32 CPreferences::GetCatColor(size_t index)
1621 wxASSERT( index < m_CatList.size() );
1623 return m_CatList[index]->color;
1626 bool CPreferences::CreateCategory(
1627 Category_Struct *& category,
1628 const wxString& name,
1629 const CPath& path,
1630 const wxString& comment,
1631 uint32 color,
1632 uint8 prio)
1634 category = new Category_Struct();
1635 category->path = thePrefs::GetIncomingDir(); // set a default in case path is invalid
1636 uint32 cat = AddCat(category);
1637 return UpdateCategory(cat, name, path, comment, color, prio);
1640 bool CPreferences::UpdateCategory(
1641 uint8 cat,
1642 const wxString& name,
1643 const CPath& path,
1644 const wxString& comment,
1645 uint32 color,
1646 uint8 prio)
1648 Category_Struct *category = m_CatList[cat];
1650 // return true if path is ok, false if not
1651 bool ret = true;
1652 if (!path.IsOk() || (!path.DirExists() && !CPath::MakeDir(path))) {
1653 ret = false;
1654 // keep path as it was
1655 } else {
1656 category->path = path;
1658 category->title = name;
1659 category->comment = comment;
1660 category->color = color;
1661 category->prio = prio;
1663 SaveCats();
1664 return ret;
1668 wxString CPreferences::GetBrowser()
1670 wxString cmd(s_CustomBrowser);
1671 #ifndef __WXMSW__
1672 if( s_BrowserTab ) {
1673 // This is certainly not the best way to do it, but I'm lazy
1674 if ((wxT("mozilla") == cmd.Right(7)) || (wxT("firefox") == cmd.Right(7))
1675 || (wxT("MozillaFirebird") == cmd.Right(15))) {
1676 cmd += wxT(" -remote 'openURL(%s, new-tab)'");
1678 if ((wxT("galeon") == cmd.Right(6)) || (wxT("epiphany") == cmd.Right(8))) {
1679 cmd += wxT(" -n '%s'");
1681 if (wxT("opera") == cmd.Right(5)) {
1682 cmd += wxT(" --newpage '%s'");
1684 if (wxT("netscape") == cmd.Right(8)) {
1685 cmd += wxT(" -remote 'openURLs(%s,new-tab)'");
1688 #endif /* !__WXMSW__ */
1689 return cmd;
1693 #include "ClientList.h"
1694 #include "ServerList.h"
1695 void CPreferences::SetIPFilterLevel(uint8 level)
1697 if (level != s_filterlevel) {
1698 // We only need to recheck if the new level is more restrictive
1699 bool filter = level > s_filterlevel;
1701 // Set the new access-level
1702 s_filterlevel = level;
1704 if ( filter ) {
1705 theApp->clientlist->FilterQueues();
1706 theApp->serverlist->FilterServers();
1712 void CPreferences::SetPort(uint16 val)
1714 // Warning: Check for +3, because server UDP is TCP+3
1716 if (val +3 > 65535) {
1717 AddLogLineM(true, _("TCP port can't be higher than 65532 due to server UDP socket being TCP+3"));
1718 AddLogLineM(false, wxString::Format(_("Default port will be used (%d)"),DEFAULT_TCP_PORT));
1719 s_port = DEFAULT_TCP_PORT;
1720 } else {
1721 s_port = val;
1726 void CPreferences::ReloadSharedFolders()
1728 #ifndef CLIENT_GUI
1729 shareddir_list.clear();
1731 CTextFile file;
1732 if (file.Open(theApp->ConfigDir + wxT("shareddir.dat"), CTextFile::read)) {
1733 wxArrayString lines = file.ReadLines(txtReadDefault, wxConvUTF8);
1735 for (size_t i = 0; i < lines.size(); ++i) {
1736 CPath path = CPath::FromUniv(lines[i]);
1738 if (path.DirExists()) {
1739 shareddir_list.push_back(path);
1740 } else {
1741 AddLogLineN(CFormat(_("Dropping non-existing shared directory: %s")) % path.GetRaw());
1745 #endif
1749 bool CPreferences::IsMessageFiltered(const wxString& message)
1751 if (s_FilterAllMessages) {
1752 return true;
1753 } else {
1754 if (s_FilterSomeMessages) {
1755 if (s_MessageFilterString.IsSameAs(wxT("*"))){
1756 // Filter anything
1757 return true;
1758 } else {
1759 wxStringTokenizer tokenizer( s_MessageFilterString, wxT(",") );
1760 while (tokenizer.HasMoreTokens()) {
1761 if ( message.Lower().Trim(false).Trim(true).Contains(
1762 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1763 return true;
1766 return false;
1768 } else {
1769 return false;
1775 bool CPreferences::IsCommentFiltered(const wxString& comment)
1777 if (s_FilterComments) {
1778 wxStringTokenizer tokenizer( s_CommentFilterString, wxT(",") );
1779 while (tokenizer.HasMoreTokens()) {
1780 if ( comment.Lower().Trim(false).Trim(true).Contains(
1781 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1782 return true;
1786 return false;
1789 // File_checked_for_headers