Update Wiki URL
[amule.git] / src / Preferences.cpp
blob1b27a1d3641bc0b0fc71c83fb1da358a74796a32
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 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.
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 #include "SharedFileList.h" // Needed for theApp->sharedfiles->Reload()
65 #endif
67 // Needed for IP filtering prefs
68 #include "ClientList.h"
69 #include "ServerList.h"
70 #include "GuiEvents.h"
72 #define DEFAULT_TCP_PORT 4662
73 #define DEFAULT_UDP_PORT 4672
75 // Static variables
76 unsigned long CPreferences::s_colors[cntStatColors];
77 unsigned long CPreferences::s_colors_ref[cntStatColors];
79 CPreferences::CFGMap CPreferences::s_CfgList;
80 CPreferences::CFGList CPreferences::s_MiscList;
83 /* Proxy */
84 CProxyData CPreferences::s_ProxyData;
86 /* The rest, organize it! */
87 wxString CPreferences::s_nick;
88 Cfg_Lang_Base * CPreferences::s_cfgLang;
89 uint16 CPreferences::s_maxupload;
90 uint16 CPreferences::s_maxdownload;
91 uint16 CPreferences::s_slotallocation;
92 wxString CPreferences::s_Addr;
93 uint16 CPreferences::s_port;
94 uint16 CPreferences::s_udpport;
95 bool CPreferences::s_UDPEnable;
96 uint16 CPreferences::s_maxconnections;
97 bool CPreferences::s_reconnect;
98 bool CPreferences::s_autoconnect;
99 bool CPreferences::s_autoconnectstaticonly;
100 bool CPreferences::s_UPnPEnabled;
101 bool CPreferences::s_UPnPECEnabled;
102 bool CPreferences::s_UPnPWebServerEnabled;
103 uint16 CPreferences::s_UPnPTCPPort;
104 bool CPreferences::s_autoserverlist;
105 bool CPreferences::s_deadserver;
106 CPath CPreferences::s_incomingdir;
107 CPath CPreferences::s_tempdir;
108 bool CPreferences::s_ICH;
109 uint8 CPreferences::s_depth3D;
110 bool CPreferences::s_scorsystem;
111 bool CPreferences::s_hideonclose;
112 bool CPreferences::s_mintotray;
113 bool CPreferences::s_trayiconenabled;
114 bool CPreferences::s_addnewfilespaused;
115 bool CPreferences::s_addserversfromserver;
116 bool CPreferences::s_addserversfromclient;
117 uint16 CPreferences::s_maxsourceperfile;
118 uint16 CPreferences::s_trafficOMeterInterval;
119 uint16 CPreferences::s_statsInterval;
120 uint32 CPreferences::s_maxGraphDownloadRate;
121 uint32 CPreferences::s_maxGraphUploadRate;
122 bool CPreferences::s_confirmExit;
123 bool CPreferences::s_filterLanIP;
124 bool CPreferences::s_paranoidfilter;
125 bool CPreferences::s_IPFilterSys;
126 bool CPreferences::s_onlineSig;
127 uint16 CPreferences::s_OSUpdate;
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_bVerboseLogfile;
147 bool CPreferences::s_bmanualhighprio;
148 bool CPreferences::s_bstartnextfile;
149 bool CPreferences::s_bstartnextfilesame;
150 bool CPreferences::s_bstartnextfilealpha;
151 bool CPreferences::s_bshowoverhead;
152 bool CPreferences::s_bDAP;
153 bool CPreferences::s_bUAP;
154 #ifndef __SVN__
155 bool CPreferences::s_showVersionOnTitle;
156 #endif
157 uint8_t CPreferences::s_showRatesOnTitle;
158 wxString CPreferences::s_VideoPlayer;
159 bool CPreferences::s_showAllNotCats;
160 bool CPreferences::s_msgonlyfriends;
161 bool CPreferences::s_msgsecure;
162 uint8 CPreferences::s_filterlevel;
163 uint8 CPreferences::s_iFileBufferSize;
164 uint8 CPreferences::s_iQueueSize;
165 wxString CPreferences::s_datetimeformat;
166 wxString CPreferences::s_sWebPath;
167 wxString CPreferences::s_sWebPassword;
168 wxString CPreferences::s_sWebLowPassword;
169 uint16 CPreferences::s_nWebPort;
170 uint16 CPreferences::s_nWebUPnPTCPPort;
171 bool CPreferences::s_bWebEnabled;
172 bool CPreferences::s_bWebUseGzip;
173 uint32 CPreferences::s_nWebPageRefresh;
174 bool CPreferences::s_bWebLowEnabled;
175 wxString CPreferences::s_WebTemplate;
176 bool CPreferences::s_showCatTabInfos;
177 AllCategoryFilter CPreferences::s_allcatFilter;
178 uint8 CPreferences::s_NoNeededSources;
179 bool CPreferences::s_DropFullQueueSources;
180 bool CPreferences::s_DropHighQueueRankingSources;
181 uint32 CPreferences::s_HighQueueRanking;
182 uint32 CPreferences::s_AutoDropTimer;
183 bool CPreferences::s_AcceptExternalConnections;
184 wxString CPreferences::s_ECAddr;
185 uint32 CPreferences::s_ECPort;
186 wxString CPreferences::s_ECPassword;
187 bool CPreferences::s_TransmitOnlyUploadingClients;
188 bool CPreferences::s_IPFilterClients;
189 bool CPreferences::s_IPFilterServers;
190 bool CPreferences::s_UseSrcSeeds;
191 bool CPreferences::s_ProgBar;
192 bool CPreferences::s_Percent;
193 bool CPreferences::s_SecIdent;
194 bool CPreferences::s_ExtractMetaData;
195 bool CPreferences::s_allocFullFile;
196 wxString CPreferences::s_CustomBrowser;
197 bool CPreferences::s_BrowserTab;
198 CPath CPreferences::s_OSDirectory;
199 wxString CPreferences::s_Skin;
200 bool CPreferences::s_FastED2KLinksHandler;
201 bool CPreferences::s_ToolbarOrientation;
202 bool CPreferences::s_AICHTrustEveryHash;
203 wxString CPreferences::s_CommentFilterString;
204 bool CPreferences::s_IPFilterAutoLoad;
205 wxString CPreferences::s_IPFilterURL;
206 CMD4Hash CPreferences::s_userhash;
207 bool CPreferences::s_MustFilterMessages;
208 wxString CPreferences::s_MessageFilterString;
209 bool CPreferences::s_FilterAllMessages;
210 bool CPreferences::s_FilterComments;
211 bool CPreferences::s_FilterSomeMessages;
212 bool CPreferences::s_ShowMessagesInLog;
213 bool CPreferences::s_IsAdvancedSpamfilterEnabled;
214 bool CPreferences::s_IsChatCaptchaEnabled;
215 bool CPreferences::s_ShareHiddenFiles;
216 bool CPreferences::s_AutoSortDownload;
217 bool CPreferences::s_NewVersionCheck;
218 bool CPreferences::s_ConnectToKad;
219 bool CPreferences::s_ConnectToED2K;
220 unsigned CPreferences::s_maxClientVersions;
221 bool CPreferences::s_DropSlowSources;
222 bool CPreferences::s_IsClientCryptLayerSupported;
223 bool CPreferences::s_bCryptLayerRequested;
224 bool CPreferences::s_IsClientCryptLayerRequired;
225 uint32 CPreferences::s_dwKadUDPKey;
226 uint8 CPreferences::s_byCryptTCPPaddingLength;
228 wxString CPreferences::s_Ed2kURL;
229 wxString CPreferences::s_KadURL;
230 bool CPreferences::s_GeoIPEnabled;
231 wxString CPreferences::s_GeoIPUpdateUrl;
232 bool CPreferences::s_preventSleepWhileDownloading;
233 wxString CPreferences::s_StatsServerName;
234 wxString CPreferences::s_StatsServerURL;
237 * Template Cfg class for connecting with widgets.
239 * This template provides the base functionionality needed to syncronize a
240 * variable with a widget. However, please note that wxGenericValidator only
241 * supports a few types (int, wxString, bool and wxArrayInt), so this template
242 * can't always be used directly.
244 * Cfg_Str and Cfg_Bool are able to use this template directly, whereas Cfg_Int
245 * makes use of serveral workaround to enable it to be used with integers other
246 * than int.
248 template <typename TYPE>
249 class Cfg_Tmpl : public Cfg_Base
251 public:
253 * Constructor.
255 * @param keyname
256 * @param value
257 * @param defaultVal
259 Cfg_Tmpl( const wxString& keyname, TYPE& value, const TYPE& defaultVal )
260 : Cfg_Base( keyname ),
261 m_value( value ),
262 m_default( defaultVal ),
263 m_widget( NULL )
266 #ifndef AMULE_DAEMON
268 * Connects the Cfg to a widget.
270 * @param id The ID of the widget to be connected.
271 * @param parent The parent of the widget. Use this to speed up searches.
273 * This function works by setting the wxValidator of the class. This however
274 * poses some restrictions on which variable types can be used for this
275 * template, as noted above. It also poses some limits on the widget types,
276 * refer to the wx documentation for those.
278 virtual bool ConnectToWidget( int id, wxWindow* parent = NULL )
280 if ( id ) {
281 m_widget = wxWindow::FindWindowById( id, parent );
283 if ( m_widget ) {
284 wxGenericValidator validator( &m_value );
286 m_widget->SetValidator( validator );
288 return true;
290 } else {
291 m_widget = NULL;
294 return false;
298 /** Updates the assosiated variable, returning true on success. */
299 virtual bool TransferFromWindow()
301 if ( m_widget ) {
302 wxValidator* validator = m_widget->GetValidator();
304 if ( validator ) {
305 TYPE temp = m_value;
307 if ( validator->TransferFromWindow() ) {
308 SetChanged( temp != m_value );
310 return true;
315 return false;
318 /** Updates the assosiated widget, returning true on success. */
319 virtual bool TransferToWindow()
321 if ( m_widget ) {
322 wxValidator* validator = m_widget->GetValidator();
324 if ( validator )
325 return validator->TransferToWindow();
328 return false;
331 #endif
333 /** Sets the default value. */
334 void SetDefault(const TYPE& defaultVal)
336 m_default = defaultVal;
339 protected:
340 //! Reference to the associated variable
341 TYPE& m_value;
343 //! Default variable value
344 TYPE m_default;
346 //! Pointer to the widget assigned to the Cfg instance
347 wxWindow* m_widget;
351 /** Cfg class for wxStrings. */
352 class Cfg_Str : public Cfg_Tmpl<wxString>
354 public:
355 /** Constructor. */
356 Cfg_Str( const wxString& keyname, wxString& value, const wxString& defaultVal = EmptyString )
357 : Cfg_Tmpl<wxString>( keyname, value, defaultVal )
360 /** Loads the string, using the specified default value. */
361 virtual void LoadFromFile(wxConfigBase* cfg)
363 cfg->Read( GetKey(), &m_value, m_default );
367 /** Saves the string to the specified wxConfig object. */
368 virtual void SaveToFile(wxConfigBase* cfg)
370 cfg->Write( GetKey(), m_value );
376 * Cfg-class for encrypting strings, for example for passwords.
378 class Cfg_Str_Encrypted : public Cfg_Str
380 public:
381 Cfg_Str_Encrypted( const wxString& keyname, wxString& value, const wxString& defaultVal = EmptyString )
382 : Cfg_Str( keyname, value, defaultVal )
385 #ifndef AMULE_DAEMON
386 virtual bool TransferFromWindow()
388 // Shakraw: when storing value, store it encrypted here (only if changed in prefs)
389 if ( Cfg_Str::TransferFromWindow() ) {
391 // Only recalucate the hash for new, non-empty passwords
392 if ( HasChanged() && !m_value.IsEmpty() ) {
393 m_value = MD5Sum( m_value ).GetHash();
396 return true;
400 return false;
402 #endif
406 /** Cfg class for CPath. */
407 class Cfg_Path : public Cfg_Str
409 public:
410 /** Constructor. */
411 Cfg_Path(const wxString& keyname, CPath& value, const wxString& defaultVal = EmptyString )
412 : Cfg_Str(keyname, m_temp_path, defaultVal)
413 , m_real_path(value)
416 /** @see Cfg_Str::LoadFromFile. */
417 virtual void LoadFromFile(wxConfigBase* cfg)
419 Cfg_Str::LoadFromFile(cfg);
421 m_real_path = CPath::FromUniv(m_temp_path);
425 /** @see Cfg_Str::SaveToFile. */
426 virtual void SaveToFile(wxConfigBase* cfg)
428 m_temp_path = CPath::ToUniv(m_real_path);
430 Cfg_Str::SaveToFile(cfg);
434 /** @see Cfg_Tmpl::TransferToWindow. */
435 virtual bool TransferToWindow()
437 m_temp_path = m_real_path.GetRaw();
439 return Cfg_Str::TransferToWindow();
442 /** @see Cfg_Tmpl::TransferFromWindow. */
443 virtual bool TransferFromWindow()
445 if (Cfg_Str::TransferFromWindow()) {
446 m_real_path = CPath(m_temp_path);
447 return true;
450 return false;
453 private:
454 wxString m_temp_path;
455 CPath& m_real_path;
460 * Cfg class that takes care of integer types.
462 * This template is needed since wxValidator only supports normals ints, and
463 * wxConfig for the matter only supports longs, thus some worksarounds are
464 * needed.
466 * There are two work-arounds:
467 * 1) wxValidator only supports int*, so we need a immediate variable to act
468 * as a storage. Thus we use Cfg_Tmpl<int> as base class. Thus this class
469 * contains a integer which we use to pass the value back and forth
470 * between the widgets.
472 * 2) wxConfig uses longs to save and read values, thus we need an immediate
473 * stage when loading and saving the value.
475 template <typename TYPE>
476 class Cfg_Int : public Cfg_Tmpl<int>
478 public:
479 Cfg_Int( const wxString& keyname, TYPE& value, int defaultVal = 0 )
480 : Cfg_Tmpl<int>( keyname, m_temp_value, defaultVal ),
481 m_real_value( value ),
482 m_temp_value( value )
486 virtual void LoadFromFile(wxConfigBase* cfg)
488 long tmp = 0;
489 cfg->Read( GetKey(), &tmp, m_default );
491 // Set the temp value
492 m_temp_value = (int)tmp;
493 // Set the actual value
494 m_real_value = (TYPE)tmp;
497 virtual void SaveToFile(wxConfigBase* cfg)
499 cfg->Write( GetKey(), (long)m_real_value );
503 #ifndef AMULE_DAEMON
504 virtual bool TransferFromWindow()
506 if ( Cfg_Tmpl<int>::TransferFromWindow() ) {
507 m_real_value = (TYPE)m_temp_value;
509 return true;
512 return false;
515 virtual bool TransferToWindow()
517 m_temp_value = (int)m_real_value;
519 if ( Cfg_Tmpl<int>::TransferToWindow() ) {
521 // In order to let us update labels on slider-changes, we trigger a event
522 wxSlider *slider = dynamic_cast<wxSlider *>(m_widget);
523 if (slider) {
524 int id = m_widget->GetId();
525 int pos = slider->GetValue();
526 wxScrollEvent evt( wxEVT_SCROLL_THUMBRELEASE, id, pos );
527 m_widget->GetEventHandler()->ProcessEvent( evt );
530 return true;
533 return false;
535 #endif
537 protected:
539 TYPE& m_real_value;
540 int m_temp_value;
545 * Helper function for creating new Cfg_Ints.
547 * @param keyname The cfg-key under which the item should be saved.
548 * @param value The variable to syncronize. The type of this variable defines the type used to create the Cfg_Int.
549 * @param defaultVal The default value if the key isn't found when loading the value.
550 * @return A pointer to the new Cfg_Int object. The caller is responsible for deleting it.
552 * This template-function returns a Cfg_Int of the appropriate type for the
553 * variable used as argument and should be used to avoid having to specify
554 * the integer type when adding a new Cfg_Int, since that's just increases
555 * the maintainence burden.
557 template <class TYPE>
558 Cfg_Base* MkCfg_Int( const wxString& keyname, TYPE& value, int defaultVal )
560 return new Cfg_Int<TYPE>( keyname, value, defaultVal );
565 * Cfg-class for bools.
567 class Cfg_Bool : public Cfg_Tmpl<bool>
569 public:
570 Cfg_Bool( const wxString& keyname, bool& value, bool defaultVal )
571 : Cfg_Tmpl<bool>( keyname, value, defaultVal )
575 virtual void LoadFromFile(wxConfigBase* cfg)
577 cfg->Read( GetKey(), &m_value, m_default );
580 virtual void SaveToFile(wxConfigBase* cfg)
582 cfg->Write( GetKey(), m_value );
587 #ifndef AMULE_DAEMON
589 class Cfg_Colour : public Cfg_Base
591 public:
592 Cfg_Colour(const wxString& key, wxColour& colour)
593 : Cfg_Base(key),
594 m_colour(colour),
595 m_default(CMuleColour(colour).GetULong())
598 virtual void LoadFromFile(wxConfigBase* cfg)
600 long int rgb;
601 cfg->Read(GetKey(), &rgb, m_default);
602 m_colour.Set(rgb);
605 virtual void SaveToFile(wxConfigBase* cfg)
607 cfg->Write(GetKey(), static_cast<long int>(CMuleColour(m_colour).GetULong()));
610 private:
611 wxColour& m_colour;
612 long int m_default;
616 typedef struct {
617 int id;
618 bool available;
619 wxString displayname;
620 wxString name;
621 } LangInfo;
625 * The languages aMule has translation for.
627 * Add new languages here.
628 * Then activate the test code in Cfg_Lang::UpdateChoice below!
630 static LangInfo aMuleLanguages[] = {
631 { wxLANGUAGE_DEFAULT, true, wxEmptyString, wxTRANSLATE("System default") },
632 { wxLANGUAGE_ALBANIAN, false, wxEmptyString, wxTRANSLATE("Albanian") },
633 { wxLANGUAGE_ARABIC, false, wxEmptyString, wxTRANSLATE("Arabic") },
634 { wxLANGUAGE_ASTURIAN, false, wxEmptyString, wxTRANSLATE("Asturian") },
635 { wxLANGUAGE_BASQUE, false, wxEmptyString, wxTRANSLATE("Basque") },
636 { wxLANGUAGE_BULGARIAN, false, wxEmptyString, wxTRANSLATE("Bulgarian") },
637 { wxLANGUAGE_CATALAN, false, wxEmptyString, wxTRANSLATE("Catalan") },
638 { wxLANGUAGE_CHINESE_SIMPLIFIED, false, wxEmptyString, wxTRANSLATE("Chinese (Simplified)") },
639 { wxLANGUAGE_CHINESE_TRADITIONAL, false, wxEmptyString, wxTRANSLATE("Chinese (Traditional)") },
640 { wxLANGUAGE_CROATIAN, false, wxEmptyString, wxTRANSLATE("Croatian") },
641 { wxLANGUAGE_CZECH, false, wxEmptyString, wxTRANSLATE("Czech") },
642 { wxLANGUAGE_DANISH, false, wxEmptyString, wxTRANSLATE("Danish") },
643 { wxLANGUAGE_DUTCH, false, wxEmptyString, wxTRANSLATE("Dutch") },
644 { wxLANGUAGE_ENGLISH, false, wxEmptyString, wxTRANSLATE("English (U.K.)") },
645 { wxLANGUAGE_ESTONIAN, false, wxEmptyString, wxTRANSLATE("Estonian") },
646 { wxLANGUAGE_FINNISH, false, wxEmptyString, wxTRANSLATE("Finnish") },
647 { wxLANGUAGE_FRENCH, false, wxEmptyString, wxTRANSLATE("French") },
648 { wxLANGUAGE_GALICIAN, false, wxEmptyString, wxTRANSLATE("Galician") },
649 { wxLANGUAGE_GERMAN, false, wxEmptyString, wxTRANSLATE("German") },
650 { wxLANGUAGE_GREEK, false, wxEmptyString, wxTRANSLATE("Greek") },
651 { wxLANGUAGE_HEBREW, false, wxEmptyString, wxTRANSLATE("Hebrew") },
652 { wxLANGUAGE_HUNGARIAN, false, wxEmptyString, wxTRANSLATE("Hungarian") },
653 { wxLANGUAGE_ITALIAN, false, wxEmptyString, wxTRANSLATE("Italian") },
654 { wxLANGUAGE_ITALIAN_SWISS, false, wxEmptyString, wxTRANSLATE("Italian (Swiss)") },
655 { wxLANGUAGE_JAPANESE, false, wxEmptyString, wxTRANSLATE("Japanese") },
656 { wxLANGUAGE_KOREAN, false, wxEmptyString, wxTRANSLATE("Korean") },
657 { wxLANGUAGE_LITHUANIAN, false, wxEmptyString, wxTRANSLATE("Lithuanian") },
658 { wxLANGUAGE_NORWEGIAN_NYNORSK, false, wxEmptyString, wxTRANSLATE("Norwegian (Nynorsk)") },
659 { wxLANGUAGE_POLISH, false, wxEmptyString, wxTRANSLATE("Polish") },
660 { wxLANGUAGE_PORTUGUESE, false, wxEmptyString, wxTRANSLATE("Portuguese") },
661 { wxLANGUAGE_PORTUGUESE_BRAZILIAN, false, wxEmptyString, wxTRANSLATE("Portuguese (Brazilian)") },
662 { wxLANGUAGE_RUSSIAN, false, wxEmptyString, wxTRANSLATE("Russian") },
663 { wxLANGUAGE_SLOVENIAN, false, wxEmptyString, wxTRANSLATE("Slovenian") },
664 { wxLANGUAGE_SPANISH, false, wxEmptyString, wxTRANSLATE("Spanish") },
665 { wxLANGUAGE_SWEDISH, false, wxEmptyString, wxTRANSLATE("Swedish") },
666 { wxLANGUAGE_TURKISH, false, wxEmptyString, wxTRANSLATE("Turkish") },
667 { wxLANGUAGE_UKRAINIAN, false, wxEmptyString, wxTRANSLATE("Ukrainian") },
671 typedef Cfg_Int<int> Cfg_PureInt;
673 class Cfg_Lang : public Cfg_PureInt, public Cfg_Lang_Base
675 public:
676 // cppcheck-suppress uninitMemberVar m_selection, m_langSelector
677 Cfg_Lang()
678 : Cfg_PureInt( wxEmptyString, m_selection, 0 )
680 m_languagesReady = false;
681 m_changePos = 0;
684 virtual void LoadFromFile(wxConfigBase* WXUNUSED(cfg)) {}
685 virtual void SaveToFile(wxConfigBase* WXUNUSED(cfg)) {}
688 virtual bool TransferFromWindow()
690 if (!m_languagesReady) {
691 return true; // nothing changed, no problem
694 if ( Cfg_PureInt::TransferFromWindow() ) {
695 // find wx ID of selected language
696 int i = 0;
697 while (m_selection > 0) {
698 i++;
699 if (aMuleLanguages[i].available) {
700 m_selection--;
703 int id = aMuleLanguages[i].id;
705 // save language selection
706 thePrefs::SetLanguageID(wxLang2Str(id));
708 return true;
711 return false;
715 virtual bool TransferToWindow()
717 m_langSelector = dynamic_cast<wxChoice*>(m_widget); // doesn't work in ctor!
718 if (m_languagesReady) {
719 FillChoice();
720 } else {
721 int wxId = StrLang2wx(thePrefs::GetLanguageID());
722 m_langSelector->Clear();
723 m_selection = 0;
724 for (uint32 i = 0; i < itemsof(aMuleLanguages); i++) {
725 if ( aMuleLanguages[i].id == wxId ) {
726 m_langSelector->Append(wxString(wxGetTranslation(aMuleLanguages[i].name)) + wxT(" [") + aMuleLanguages[i].name + wxT("]"));
727 break;
730 m_langSelector->Append(_("Change Language"));
731 m_changePos = m_langSelector->GetCount() - 1;
734 return Cfg_PureInt::TransferToWindow();
737 virtual void UpdateChoice(int pos)
739 if (!m_languagesReady && pos == m_changePos) {
740 // Find available languages and translate them.
741 // This is only done when the user selects "Change Language"
742 // Language is changed rarely, and the go-through-all locales takes a considerable
743 // time when the settings dialog is opened for the first time.
744 wxBusyCursor busyCursor;
745 aMuleLanguages[0].displayname = wxGetTranslation(aMuleLanguages[0].name);
747 // This supresses error-messages about invalid locales
748 for (unsigned int i = 1; i < itemsof(aMuleLanguages); ++i) {
749 if ((aMuleLanguages[i].id > wxLANGUAGE_USER_DEFINED) || wxLocale::IsAvailable(aMuleLanguages[i].id)) {
750 wxLogNull logTarget;
751 wxLocale locale_to_check;
752 InitLocale(locale_to_check, aMuleLanguages[i].id);
753 if (locale_to_check.IsOk() && locale_to_check.IsLoaded(wxT(PACKAGE))) {
754 aMuleLanguages[i].displayname = wxString(wxGetTranslation(aMuleLanguages[i].name)) + wxT(" [") + aMuleLanguages[i].name + wxT("]");
755 aMuleLanguages[i].available = true;
756 #if 0
757 // Check for language problems
758 // Activate this code temporarily after messing with the languages!
759 int wxid = StrLang2wx(wxLang2Str(aMuleLanguages[i].id));
760 if (wxid != aMuleLanguages[i].id) {
761 AddDebugLogLineN(logGeneral, CFormat(wxT("Language problem for %s : aMule id %d != wx id %d"))
762 % aMuleLanguages[i].name % aMuleLanguages[i].id % wxid);
764 #endif
768 // Restore original locale
769 wxLocale tmpLocale;
770 InitLocale(tmpLocale, theApp->m_locale.GetLanguage());
771 FillChoice();
772 if (m_langSelector->GetCount() == 1) {
773 wxMessageBox(_("There are no translations installed for aMule"), _("No languages available"), wxICON_INFORMATION | wxOK);
775 m_langSelector->SetSelection(m_selection);
776 m_languagesReady = true;
780 protected:
781 int m_selection;
783 private:
784 void FillChoice()
786 int wxId = StrLang2wx(thePrefs::GetLanguageID());
787 m_langSelector->Clear();
788 // Add all available languages and find the index of the selected language.
789 for ( unsigned int i = 0, j = 0; i < itemsof(aMuleLanguages); i++) {
790 if (aMuleLanguages[i].available) {
791 m_langSelector->Append(aMuleLanguages[i].displayname);
792 if ( aMuleLanguages[i].id == wxId ) {
793 m_selection = j;
795 j++;
800 bool m_languagesReady; // true: all translations calculated
801 int m_changePos;
802 wxChoice * m_langSelector;
805 #endif /* ! AMULE_DAEMON */
807 void Cfg_Lang_Base::UpdateChoice(int) {} // dummy
809 class Cfg_Skin : public Cfg_Str
811 public:
812 Cfg_Skin( const wxString& keyname, wxString& value, const wxString& defaultVal = EmptyString )
813 : Cfg_Str( keyname, value, defaultVal ),
814 m_is_skin(false)
817 #ifndef AMULE_DAEMON
818 virtual bool TransferFromWindow()
820 if ( Cfg_Str::TransferFromWindow() ) {
821 if (m_is_skin) {
822 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
823 // "- default -" is always the first
824 if (skinSelector->GetSelection() == 0) {
825 m_value.Clear();
828 return true;
831 return false;
835 virtual bool TransferToWindow()
838 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
839 skinSelector->Clear();
841 wxString folder;
842 int flags = wxDIR_DIRS;
843 wxString filespec;
844 wxString defaultSelection = _("- default -");
845 //#warning there has to be a better way...
846 if ( GetKey() == wxT("/SkinGUIOptions/Skin") ) {
847 folder = wxT("skins");
848 m_is_skin = true;
849 flags = wxDIR_FILES;
850 filespec = wxT("*.zip");
851 skinSelector->Append(defaultSelection);
852 } else {
853 folder = wxT("webserver");
855 wxString dirName(JoinPaths(GetConfigDir(theApp->m_configFile), folder));
856 wxString Filename;
857 wxDir d;
859 if (wxDir::Exists(dirName) &&
860 d.Open(dirName) &&
861 d.GetFirst(& Filename, filespec, flags)
866 if (m_is_skin) {
867 Filename = wxT("User:") + Filename;
869 skinSelector->Append(Filename);
871 while (d.GetNext(&Filename));
874 wxString dataDir;
875 if (m_is_skin) {
876 dataDir = wxStandardPaths::Get().GetDataDir();
877 } else {
878 dataDir = wxStandardPaths::Get().GetResourcesDir();
880 #if !defined(__WINDOWS__ ) && !defined(__WXMAC__)
881 dataDir = dataDir.BeforeLast(wxT('/')) + wxT("/amule");
882 #endif
883 wxString systemDir(JoinPaths(dataDir,folder));
885 if (wxDir::Exists(systemDir) &&
886 d.Open(systemDir) &&
887 d.GetFirst(& Filename, filespec, flags)
892 if (m_is_skin) {
893 Filename = wxT("System:") + Filename;
895 // avoid duplicates for webserver templates
896 if (skinSelector->FindString(Filename) == wxNOT_FOUND) {
897 skinSelector->Append(Filename);
900 while (d.GetNext(&Filename));
903 if ( skinSelector->GetCount() == 0 ) {
904 skinSelector->Append(_("no options available"));
907 int id = skinSelector->FindString(m_value);
908 if ( id == wxNOT_FOUND ) {
909 id = 0;
910 if (m_is_skin) {
911 m_value = defaultSelection;
914 skinSelector->SetSelection(id);
916 return Cfg_Str::TransferToWindow();
918 #endif /* ! AMULE_DAEMON */
920 protected:
921 bool m_is_skin;
925 /// new implementation
926 CPreferences::CPreferences()
928 srand( wxGetLocalTimeMillis().GetLo() ); // we need random numbers sometimes
930 // load preferences.dat or set standard values
931 wxString fullpath(theApp->ConfigDir + wxT("preferences.dat"));
932 CFile preffile;
933 if (wxFileExists(fullpath)) {
934 if (preffile.Open(fullpath, CFile::read)) {
935 try {
936 preffile.ReadUInt8(); // Version. Value is not used.
937 s_userhash = preffile.ReadHash();
938 } catch (const CSafeIOException& e) {
939 AddDebugLogLineC(logGeneral,
940 wxT("Error while reading userhash: ") + e.what());
945 if (s_userhash.IsEmpty()) {
946 for (int i = 0; i < 8; i++) {
947 RawPokeUInt16(s_userhash.GetHash() + (i * 2), rand());
950 Save();
953 // Mark hash as an eMule-type hash
954 // See also CUpDownClient::GetHashType
955 s_userhash[5] = 14;
956 s_userhash[14] = 111;
958 #ifndef CLIENT_GUI
959 LoadPreferences();
960 ReloadSharedFolders();
962 // serverlist adresses
963 CTextFile slistfile;
964 if (slistfile.Open(theApp->ConfigDir + wxT("addresses.dat"), CTextFile::read)) {
965 adresses_list = slistfile.ReadLines();
967 #endif
971 // Gets called at init time
973 void CPreferences::BuildItemList( const wxString& appdir )
975 #ifndef AMULE_DAEMON
976 #define NewCfgItem(ID, COMMAND) s_CfgList[ID] = COMMAND
977 #else
978 int current_id = 0;
979 #define NewCfgItem(ID, COMMAND) s_CfgList[++current_id] = COMMAND
980 #endif /* AMULE_DAEMON */
983 * User settings
985 NewCfgItem(IDC_NICK, (new Cfg_Str( wxT("/eMule/Nick"), s_nick, wxT("http://www.aMule.org") )));
986 #ifndef AMULE_DAEMON
987 Cfg_Lang * cfgLang = new Cfg_Lang();
988 s_cfgLang = cfgLang;
989 NewCfgItem(IDC_LANGUAGE, cfgLang);
990 #endif
993 * Browser options
995 #ifdef __WXMAC__
996 wxString customBrowser = wxT("/usr/bin/open");
997 #else
998 wxString customBrowser; // left empty
999 #endif
1001 NewCfgItem(IDC_BROWSERTABS, (new Cfg_Bool( wxT("/Browser/OpenPageInTab"), s_BrowserTab, true )));
1002 NewCfgItem(IDC_BROWSERSELF, (new Cfg_Str( wxT("/Browser/CustomBrowserString"), s_CustomBrowser, customBrowser )));
1006 * Misc
1008 NewCfgItem(IDC_QUEUESIZE, (MkCfg_Int( wxT("/eMule/QueueSizePref"), s_iQueueSize, 50 )));
1011 #ifdef __DEBUG__
1013 * Debugging
1015 NewCfgItem(ID_VERBOSEDEBUG, (new Cfg_Bool( wxT("/eMule/VerboseDebug"), s_bVerbose, false )));
1016 NewCfgItem(ID_VERBOSEDEBUGLOGFILE, (new Cfg_Bool( wxT("/eMule/VerboseDebugLogfile"), s_bVerboseLogfile, false )));
1017 #endif
1020 * Connection settings
1022 NewCfgItem(IDC_MAXUP, (MkCfg_Int( wxT("/eMule/MaxUpload"), s_maxupload, 0 )));
1023 NewCfgItem(IDC_MAXDOWN, (MkCfg_Int( wxT("/eMule/MaxDownload"), s_maxdownload, 0 )));
1024 NewCfgItem(IDC_SLOTALLOC, (MkCfg_Int( wxT("/eMule/SlotAllocation"), s_slotallocation, 2 )));
1025 NewCfgItem(IDC_PORT, (MkCfg_Int( wxT("/eMule/Port"), s_port, DEFAULT_TCP_PORT )));
1026 NewCfgItem(IDC_UDPPORT, (MkCfg_Int( wxT("/eMule/UDPPort"), s_udpport, DEFAULT_UDP_PORT )));
1027 NewCfgItem(IDC_UDPENABLE, (new Cfg_Bool( wxT("/eMule/UDPEnable"), s_UDPEnable, true )));
1028 NewCfgItem(IDC_ADDRESS, (new Cfg_Str( wxT("/eMule/Address"), s_Addr, wxEmptyString)));
1029 NewCfgItem(IDC_AUTOCONNECT, (new Cfg_Bool( wxT("/eMule/Autoconnect"), s_autoconnect, true )));
1030 NewCfgItem(IDC_MAXSOURCEPERFILE, (MkCfg_Int( wxT("/eMule/MaxSourcesPerFile"), s_maxsourceperfile, 300 )));
1031 NewCfgItem(IDC_MAXCON, (MkCfg_Int( wxT("/eMule/MaxConnections"), s_maxconnections, GetRecommendedMaxConnections() )));
1032 NewCfgItem(IDC_MAXCON5SEC, (MkCfg_Int( wxT("/eMule/MaxConnectionsPerFiveSeconds"), s_MaxConperFive, 20 )));
1035 * Proxy
1037 NewCfgItem(ID_PROXY_ENABLE_PROXY, (new Cfg_Bool( wxT("/Proxy/ProxyEnableProxy"), s_ProxyData.m_proxyEnable, false )));
1038 NewCfgItem(ID_PROXY_TYPE, (MkCfg_Int( wxT("/Proxy/ProxyType"), s_ProxyData.m_proxyType, 0 )));
1039 NewCfgItem(ID_PROXY_NAME, (new Cfg_Str( wxT("/Proxy/ProxyName"), s_ProxyData.m_proxyHostName, wxEmptyString )));
1040 NewCfgItem(ID_PROXY_PORT, (MkCfg_Int( wxT("/Proxy/ProxyPort"), s_ProxyData.m_proxyPort, 1080 )));
1041 NewCfgItem(ID_PROXY_ENABLE_PASSWORD, (new Cfg_Bool( wxT("/Proxy/ProxyEnablePassword"), s_ProxyData.m_enablePassword, false )));
1042 NewCfgItem(ID_PROXY_USER, (new Cfg_Str( wxT("/Proxy/ProxyUser"), s_ProxyData.m_userName, wxEmptyString )));
1043 NewCfgItem(ID_PROXY_PASSWORD, (new Cfg_Str( wxT("/Proxy/ProxyPassword"), s_ProxyData.m_password, wxEmptyString )));
1044 // These were copied from eMule config file, maybe someone with windows can complete this?
1045 // NewCfgItem(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, (new Cfg_Bool( wxT("/Proxy/Proxy????"), s_Proxy????, false )));
1048 * Servers
1050 NewCfgItem(IDC_REMOVEDEAD, (new Cfg_Bool( wxT("/eMule/RemoveDeadServer"), s_deadserver, 1 )));
1051 NewCfgItem(IDC_SERVERRETRIES, (MkCfg_Int( wxT("/eMule/DeadServerRetry"), s_deadserverretries, 3 )));
1052 NewCfgItem(IDC_SERVERKEEPALIVE, (MkCfg_Int( wxT("/eMule/ServerKeepAliveTimeout"), s_dwServerKeepAliveTimeoutMins, 0 )));
1053 NewCfgItem(IDC_RECONN, (new Cfg_Bool( wxT("/eMule/Reconnect"), s_reconnect, true )));
1054 NewCfgItem(IDC_SCORE, (new Cfg_Bool( wxT("/eMule/Scoresystem"), s_scorsystem, true )));
1055 NewCfgItem(IDC_AUTOSERVER, (new Cfg_Bool( wxT("/eMule/Serverlist"), s_autoserverlist, false )));
1056 NewCfgItem(IDC_UPDATESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/AddServerListFromServer"), s_addserversfromserver, false)));
1057 NewCfgItem(IDC_UPDATESERVERCLIENT, (new Cfg_Bool( wxT("/eMule/AddServerListFromClient"), s_addserversfromclient, false )));
1058 NewCfgItem(IDC_SAFESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/SafeServerConnect"), s_safeServerConnect, false )));
1059 NewCfgItem(IDC_AUTOCONNECTSTATICONLY, (new Cfg_Bool( wxT("/eMule/AutoConnectStaticOnly"), s_autoconnectstaticonly, false )));
1060 NewCfgItem(IDC_UPNP_ENABLED, (new Cfg_Bool( wxT("/eMule/UPnPEnabled"), s_UPnPEnabled, false )));
1061 NewCfgItem(IDC_UPNPTCPPORT, (MkCfg_Int( wxT("/eMule/UPnPTCPPort"), s_UPnPTCPPort, 50000 )));
1062 NewCfgItem(IDC_SMARTIDCHECK, (new Cfg_Bool( wxT("/eMule/SmartIdCheck"), s_smartidcheck, true )));
1063 // Enabled networks
1064 NewCfgItem( IDC_NETWORKKAD, (new Cfg_Bool( wxT("/eMule/ConnectToKad"), s_ConnectToKad, true )) );
1065 NewCfgItem( IDC_NETWORKED2K, ( new Cfg_Bool( wxT("/eMule/ConnectToED2K"), s_ConnectToED2K, true ) ));
1069 * Files
1071 NewCfgItem(IDC_TEMPFILES, (new Cfg_Path( wxT("/eMule/TempDir"), s_tempdir, appdir + wxT("Temp") )));
1073 #if defined(__WXMAC__) || defined(__WINDOWS__ )
1074 wxString incpath = wxStandardPaths::Get().GetDocumentsDir();
1075 if (incpath.IsEmpty()) {
1076 // There is a built-in possibility for this call to fail, though I can't imagine a reason for that.
1077 incpath = appdir + wxT("Incoming");
1078 } else {
1079 incpath = JoinPaths(incpath, wxT("aMule Downloads"));
1081 #else
1082 wxString incpath = appdir + wxT("Incoming");
1083 #endif
1084 NewCfgItem(IDC_INCFILES, (new Cfg_Path( wxT("/eMule/IncomingDir"), s_incomingdir, incpath )));
1086 NewCfgItem(IDC_ICH, (new Cfg_Bool( wxT("/eMule/ICH"), s_ICH, true )));
1087 NewCfgItem(IDC_AICHTRUST, (new Cfg_Bool( wxT("/eMule/AICHTrust"), s_AICHTrustEveryHash, false )));
1088 NewCfgItem(IDC_CHECKDISKSPACE, (new Cfg_Bool( wxT("/eMule/CheckDiskspace"), s_checkDiskspace, true )));
1089 NewCfgItem(IDC_MINDISKSPACE, (MkCfg_Int( wxT("/eMule/MinFreeDiskSpace"), s_uMinFreeDiskSpace, 1 )));
1090 NewCfgItem(IDC_ADDNEWFILESPAUSED, (new Cfg_Bool( wxT("/eMule/AddNewFilesPaused"), s_addnewfilespaused, false )));
1091 NewCfgItem(IDC_PREVIEWPRIO, (new Cfg_Bool( wxT("/eMule/PreviewPrio"), s_bpreviewprio, false )));
1092 NewCfgItem(IDC_MANUALSERVERHIGHPRIO, (new Cfg_Bool( wxT("/eMule/ManualHighPrio"), s_bmanualhighprio, false )));
1093 NewCfgItem(IDC_STARTNEXTFILE, (new Cfg_Bool( wxT("/eMule/StartNextFile"), s_bstartnextfile, false )));
1094 NewCfgItem(IDC_STARTNEXTFILE_SAME, (new Cfg_Bool( wxT("/eMule/StartNextFileSameCat"), s_bstartnextfilesame, false )));
1095 NewCfgItem(IDC_STARTNEXTFILE_ALPHA, (new Cfg_Bool( wxT("/eMule/StartNextFileAlpha"), s_bstartnextfilealpha, false )));
1096 NewCfgItem(IDC_SRCSEEDS, (new Cfg_Bool( wxT("/ExternalConnect/UseSrcSeeds"), s_UseSrcSeeds, false )));
1097 NewCfgItem(IDC_FILEBUFFERSIZE, (MkCfg_Int( wxT("/eMule/FileBufferSizePref"), s_iFileBufferSize, 16 )));
1098 NewCfgItem(IDC_DAP, (new Cfg_Bool( wxT("/eMule/DAPPref"), s_bDAP, true )));
1099 NewCfgItem(IDC_UAP, (new Cfg_Bool( wxT("/eMule/UAPPref"), s_bUAP, true )));
1100 NewCfgItem(IDC_ALLOCFULLFILE, (new Cfg_Bool( wxT("/eMule/AllocateFullFile"), s_allocFullFile, false )));
1103 * Web Server
1105 NewCfgItem(IDC_OSDIR, (new Cfg_Path( wxT("/eMule/OSDirectory"), s_OSDirectory, appdir )));
1106 NewCfgItem(IDC_ONLINESIG, (new Cfg_Bool( wxT("/eMule/OnlineSignature"), s_onlineSig, false )));
1107 NewCfgItem(IDC_OSUPDATE, (MkCfg_Int( wxT("/eMule/OnlineSignatureUpdate"), s_OSUpdate, 5 )));
1108 NewCfgItem(IDC_ENABLE_WEB, (new Cfg_Bool( wxT("/WebServer/Enabled"), s_bWebEnabled, false )));
1109 NewCfgItem(IDC_WEB_PASSWD, (new Cfg_Str_Encrypted( wxT("/WebServer/Password"), s_sWebPassword )));
1110 NewCfgItem(IDC_WEB_PASSWD_LOW, (new Cfg_Str_Encrypted( wxT("/WebServer/PasswordLow"), s_sWebLowPassword )));
1111 NewCfgItem(IDC_WEB_PORT, (MkCfg_Int( wxT("/WebServer/Port"), s_nWebPort, 4711 )));
1112 NewCfgItem(IDC_WEBUPNPTCPPORT, (MkCfg_Int( wxT("/WebServer/WebUPnPTCPPort"), s_nWebUPnPTCPPort, 50001 )));
1113 NewCfgItem(IDC_UPNP_WEBSERVER_ENABLED,
1114 (new Cfg_Bool( wxT("/WebServer/UPnPWebServerEnabled"), s_UPnPWebServerEnabled, false )));
1115 NewCfgItem(IDC_WEB_GZIP, (new Cfg_Bool( wxT("/WebServer/UseGzip"), s_bWebUseGzip, true )));
1116 NewCfgItem(IDC_ENABLE_WEB_LOW, (new Cfg_Bool( wxT("/WebServer/UseLowRightsUser"), s_bWebLowEnabled, false )));
1117 NewCfgItem(IDC_WEB_REFRESH_TIMEOUT, (MkCfg_Int( wxT("/WebServer/PageRefreshTime"), s_nWebPageRefresh, 120 )));
1118 NewCfgItem(IDC_WEBTEMPLATE, (new Cfg_Skin( wxT("/WebServer/Template"), s_WebTemplate, wxEmptyString )));
1121 * External Connections
1123 NewCfgItem(IDC_EXT_CONN_ACCEPT, (new Cfg_Bool( wxT("/ExternalConnect/AcceptExternalConnections"), s_AcceptExternalConnections, false )));
1124 NewCfgItem(IDC_EXT_CONN_IP, (new Cfg_Str( wxT("/ExternalConnect/ECAddress"), s_ECAddr, wxEmptyString )));
1125 NewCfgItem(IDC_EXT_CONN_TCP_PORT, (MkCfg_Int( wxT("/ExternalConnect/ECPort"), s_ECPort, 4712 )));
1126 NewCfgItem(IDC_EXT_CONN_PASSWD, (new Cfg_Str_Encrypted( wxT("/ExternalConnect/ECPassword"), s_ECPassword, wxEmptyString )));
1127 NewCfgItem(IDC_UPNP_EC_ENABLED, (new Cfg_Bool( wxT("/ExternalConnect/UPnPECEnabled"), s_UPnPECEnabled, false )));
1130 * GUI behavior
1132 NewCfgItem(IDC_MACHIDEONCLOSE, (new Cfg_Bool( wxT("/GUI/HideOnClose"), s_hideonclose, false )));
1133 NewCfgItem(IDC_ENABLETRAYICON, (new Cfg_Bool( wxT("/eMule/EnableTrayIcon"), s_trayiconenabled, false )));
1134 NewCfgItem(IDC_MINTRAY, (new Cfg_Bool( wxT("/eMule/MinToTray"), s_mintotray, false )));
1135 NewCfgItem(IDC_EXIT, (new Cfg_Bool( wxT("/eMule/ConfirmExit"), s_confirmExit, true )));
1136 NewCfgItem(IDC_STARTMIN, (new Cfg_Bool( wxT("/eMule/StartupMinimized"), s_startMinimized, false )));
1139 * GUI appearence
1141 NewCfgItem(IDC_3DDEPTH, (MkCfg_Int( wxT("/eMule/3DDepth"), s_depth3D, 10 )));
1142 NewCfgItem(IDC_TOOLTIPDELAY, (MkCfg_Int( wxT("/eMule/ToolTipDelay"), s_iToolDelayTime, 1 )));
1143 NewCfgItem(IDC_SHOWOVERHEAD, (new Cfg_Bool( wxT("/eMule/ShowOverhead"), s_bshowoverhead, false )));
1144 NewCfgItem(IDC_EXTCATINFO, (new Cfg_Bool( wxT("/eMule/ShowInfoOnCatTabs"), s_showCatTabInfos, true )));
1145 NewCfgItem(IDC_FED2KLH, (new Cfg_Bool( wxT("/Razor_Preferences/FastED2KLinksHandler"), s_FastED2KLinksHandler, true )));
1146 NewCfgItem(IDC_PROGBAR, (new Cfg_Bool( wxT("/ExternalConnect/ShowProgressBar"), s_ProgBar, true )));
1147 NewCfgItem(IDC_PERCENT, (new Cfg_Bool( wxT("/ExternalConnect/ShowPercent"), s_Percent, true )));
1148 NewCfgItem(IDC_SKIN, (new Cfg_Skin( wxT("/SkinGUIOptions/Skin"), s_Skin, wxEmptyString )));
1149 NewCfgItem(IDC_VERTTOOLBAR, (new Cfg_Bool( wxT("/eMule/VerticalToolbar"), s_ToolbarOrientation, false )));
1150 NewCfgItem(IDC_SHOW_COUNTRY_FLAGS, (new Cfg_Bool( wxT("/eMule/GeoIPEnabled"), s_GeoIPEnabled, true )));
1151 #ifndef __SVN__
1152 NewCfgItem(IDC_SHOWVERSIONONTITLE, (new Cfg_Bool( wxT("/eMule/ShowVersionOnTitle"), s_showVersionOnTitle, false )));
1153 #endif
1156 * External Apps
1158 NewCfgItem(IDC_VIDEOPLAYER, (new Cfg_Str( wxT("/eMule/VideoPlayer"), s_VideoPlayer, wxEmptyString )));
1161 * Statistics
1163 NewCfgItem(IDC_SLIDER, (MkCfg_Int( wxT("/eMule/StatGraphsInterval"), s_trafficOMeterInterval, 3 )));
1164 NewCfgItem(IDC_SLIDER2, (MkCfg_Int( wxT("/eMule/statsInterval"), s_statsInterval, 30 )));
1165 NewCfgItem(IDC_DOWNLOAD_CAP, (MkCfg_Int( wxT("/eMule/DownloadCapacity"), s_maxGraphDownloadRate, 300 )));
1166 NewCfgItem(IDC_UPLOAD_CAP, (MkCfg_Int( wxT("/eMule/UploadCapacity"), s_maxGraphUploadRate, 100 )));
1167 NewCfgItem(IDC_SLIDER3, (MkCfg_Int( wxT("/eMule/StatsAverageMinutes"), s_statsAverageMinutes, 5 )));
1168 NewCfgItem(IDC_SLIDER4, (MkCfg_Int( wxT("/eMule/VariousStatisticsMaxValue"), s_statsMax, 100 )));
1169 NewCfgItem(IDC_CLIENTVERSIONS, (MkCfg_Int( wxT("/Statistics/MaxClientVersions"), s_maxClientVersions, 0 )));
1172 * Security
1174 NewCfgItem(IDC_SEESHARES, (MkCfg_Int( wxT("/eMule/SeeShare"), s_iSeeShares, 2 )));
1175 NewCfgItem(IDC_SECIDENT, (new Cfg_Bool( wxT("/ExternalConnect/UseSecIdent"), s_SecIdent, true )));
1176 NewCfgItem(IDC_IPFCLIENTS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterClients"), s_IPFilterClients, true )));
1177 NewCfgItem(IDC_IPFSERVERS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterServers"), s_IPFilterServers, true )));
1178 NewCfgItem(IDC_FILTERLAN, (new Cfg_Bool( wxT("/eMule/FilterLanIPs"), s_filterLanIP, true )));
1179 NewCfgItem(IDC_PARANOID, (new Cfg_Bool( wxT("/eMule/ParanoidFiltering"), s_paranoidfilter, true )));
1180 NewCfgItem(IDC_AUTOIPFILTER, (new Cfg_Bool( wxT("/eMule/IPFilterAutoLoad"), s_IPFilterAutoLoad, true )));
1181 NewCfgItem(IDC_IPFILTERURL, (new Cfg_Str( wxT("/eMule/IPFilterURL"), s_IPFilterURL, wxEmptyString )));
1182 NewCfgItem(ID_IPFILTERLEVEL, (MkCfg_Int( wxT("/eMule/FilterLevel"), s_filterlevel, 127 )));
1183 NewCfgItem(IDC_IPFILTERSYS, (new Cfg_Bool( wxT("/eMule/IPFilterSystem"), s_IPFilterSys, false )));
1186 * Message Filter
1188 NewCfgItem(IDC_MSGFILTER, (new Cfg_Bool( wxT("/eMule/FilterMessages"), s_MustFilterMessages, true )));
1189 NewCfgItem(IDC_MSGFILTER_ALL, (new Cfg_Bool( wxT("/eMule/FilterAllMessages"), s_FilterAllMessages, false )));
1190 NewCfgItem(IDC_MSGFILTER_NONFRIENDS, (new Cfg_Bool( wxT("/eMule/MessagesFromFriendsOnly"), s_msgonlyfriends, false )));
1191 NewCfgItem(IDC_MSGFILTER_NONSECURE, (new Cfg_Bool( wxT("/eMule/MessageFromValidSourcesOnly"), s_msgsecure, true )));
1192 NewCfgItem(IDC_MSGFILTER_WORD, (new Cfg_Bool( wxT("/eMule/FilterWordMessages"), s_FilterSomeMessages, false )));
1193 NewCfgItem(IDC_MSGWORD, (new Cfg_Str( wxT("/eMule/MessageFilter"), s_MessageFilterString, wxEmptyString )));
1194 NewCfgItem(IDC_MSGLOG, (new Cfg_Bool( wxT("/eMule/ShowMessagesInLog"), s_ShowMessagesInLog, true )));
1195 //Todo NewCfgItem(IDC_MSGADVSPAM, (new Cfg_Bool( wxT("/eMule/AdvancedSpamFilter"), s_IsAdvancedSpamfilterEnabled, true )));
1196 //Todo NewCfgItem(IDC_MSGCAPTCHA, (new Cfg_Bool( wxT("/eMule/MessageUseCaptchas"), s_IsChatCaptchaEnabled, true )));
1197 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/AdvancedSpamFilter"), s_IsAdvancedSpamfilterEnabled, true ) );
1198 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/MessageUseCaptchas"), s_IsChatCaptchaEnabled, true ) );
1200 NewCfgItem(IDC_FILTERCOMMENTS, (new Cfg_Bool( wxT("/eMule/FilterComments"), s_FilterComments, false )));
1201 NewCfgItem(IDC_COMMENTWORD, (new Cfg_Str( wxT("/eMule/CommentFilter"), s_CommentFilterString, wxEmptyString )));
1204 * Hidden files sharing
1206 NewCfgItem(IDC_SHAREHIDDENFILES, (new Cfg_Bool( wxT("/eMule/ShareHiddenFiles"), s_ShareHiddenFiles, false )));
1209 * Auto-Sorting of downloads
1211 NewCfgItem(IDC_AUTOSORT, (new Cfg_Bool( wxT("/eMule/AutoSortDownloads"), s_AutoSortDownload, false )));
1214 * Version check
1216 NewCfgItem(IDC_NEWVERSION, (new Cfg_Bool( wxT("/eMule/NewVersionCheck"), s_NewVersionCheck, true )));
1219 * Obfuscation
1221 NewCfgItem( IDC_SUPPORT_PO, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerSupported"), s_IsClientCryptLayerSupported, true )));
1222 NewCfgItem( IDC_ENABLE_PO_OUTGOING, ( new Cfg_Bool( wxT("/Obfuscation/IsCryptLayerRequested"), s_bCryptLayerRequested, true )));
1223 NewCfgItem( IDC_ENFORCE_PO_INCOMING, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerRequired"), s_IsClientCryptLayerRequired, false )));
1224 #ifndef CLIENT_GUI
1225 // There is no need for GUI items for this two.
1226 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoPaddingLenght"), s_byCryptTCPPaddingLength, 254 ) );
1227 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoKadUDPKey"), s_dwKadUDPKey, GetRandomUint32() ) );
1228 #endif
1231 * Power management
1233 NewCfgItem( IDC_PREVENT_SLEEP, ( new Cfg_Bool( wxT("/PowerManagement/PreventSleepWhileDownloading"), s_preventSleepWhileDownloading, false )));
1236 * The following doesn't have an associated widget or section
1238 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Language"), s_languageID ) );
1239 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SplitterbarPosition"), s_splitterbarPosition, 75 ) );
1240 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/YourHostname"), s_yourHostname, wxEmptyString ) );
1241 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/DateTimeFormat"), s_datetimeformat, wxT("%A, %x, %X") ) );
1243 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/AllcatType"), s_allcatFilter, 0 ) );
1244 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/ShowAllNotCats"), s_showAllNotCats, false ) );
1246 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SmartIdState"), s_smartidstate, 0 ) );
1248 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/DropSlowSources"), s_DropSlowSources, false ) );
1250 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/KadNodesUrl"), s_KadURL, wxT("http://upd.emule-security.org/nodes.dat") ) );
1251 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Ed2kServersUrl"), s_Ed2kURL, wxT("http://upd.emule-security.org/server.met") ) );
1252 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/ShowRatesOnTitle"), s_showRatesOnTitle, 0 ));
1254 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/GeoLiteCountryUpdateUrl"), s_GeoIPUpdateUrl, wxT("http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz") ) );
1255 wxConfigBase::Get()->DeleteEntry(wxT("/eMule/GeoIPUpdateUrl")); // get rid of the old one for a while
1257 s_MiscList.push_back( new Cfg_Str( wxT("/WebServer/Path"), s_sWebPath, wxT("amuleweb") ) );
1259 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/StatsServerName"), s_StatsServerName, wxT("Shorty's ED2K stats") ) );
1260 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/StatsServerURL"), s_StatsServerURL, wxT("http://ed2k.shortypower.dyndns.org/?hash=") ) );
1262 s_MiscList.push_back( new Cfg_Bool( wxT("/ExternalConnect/TransmitOnlyUploadingClients"), s_TransmitOnlyUploadingClients, false ) );
1264 #ifndef AMULE_DAEMON
1265 // Colors have been moved from global prefs to CStatisticsDlg
1266 for ( int i = 0; i < cntStatColors; i++ ) {
1267 wxString str = CFormat(wxT("/eMule/StatColor%i")) % i;
1268 s_MiscList.push_back( new Cfg_Colour( str, CStatisticsDlg::acrStat[i] ) );
1270 #endif
1272 // User events
1273 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1274 // We can't use NewCfgItem here, because we need to find these items
1275 // later, which would be impossible in amuled with NewCfgItem.
1276 // The IDs we assign here are high enough to not cause any collision
1277 // even on the daemon.
1278 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);
1279 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);
1280 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);
1281 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);
1286 void CPreferences::EraseItemList()
1288 while ( s_CfgList.begin() != s_CfgList.end() ) {
1289 delete s_CfgList.begin()->second;
1290 s_CfgList.erase( s_CfgList.begin() );
1293 CFGList::iterator it = s_MiscList.begin();
1294 for ( ; it != s_MiscList.end(); ) {
1295 delete *it;
1296 it = s_MiscList.erase( it );
1301 void CPreferences::LoadAllItems(wxConfigBase* cfg)
1303 #ifndef CLIENT_GUI
1304 // Preserve values from old config. The global config object may not be set yet
1305 // when BuildItemList() is called, so we need to provide defaults later - here.
1306 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletion"))) {
1307 bool ExecOnCompletion;
1308 cfg->Read(wxT("/eMule/ExecOnCompletion"), &ExecOnCompletion, false);
1309 // Assign to core command, that's the most likely it was.
1310 static_cast<Cfg_Bool*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT + 1])->SetDefault(ExecOnCompletion);
1311 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletion"));
1313 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletionCommand"))) {
1314 wxString ExecOnCompletionCommand;
1315 cfg->Read(wxT("/eMule/ExecOnCompletionCommand"), &ExecOnCompletionCommand, wxEmptyString);
1316 static_cast<Cfg_Str*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT + 2])->SetDefault(ExecOnCompletionCommand);
1317 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletionCommand"));
1319 #endif
1320 CFGMap::iterator it_a = s_CfgList.begin();
1321 for ( ; it_a != s_CfgList.end(); ++it_a ) {
1322 it_a->second->LoadFromFile( cfg );
1325 CFGList::iterator it_b = s_MiscList.begin();
1326 for ( ; it_b != s_MiscList.end(); ++it_b ) {
1327 (*it_b)->LoadFromFile( cfg );
1330 // Preserve old value of UDPDisable
1331 if (cfg->HasEntry(wxT("/eMule/UDPDisable"))) {
1332 bool UDPDisable;
1333 cfg->Read(wxT("/eMule/UDPDisable"), &UDPDisable, false);
1334 SetUDPDisable(UDPDisable);
1335 cfg->DeleteEntry(wxT("/eMule/UDPDisable"));
1338 // Preserve old value of UseSkinFiles
1339 if (cfg->HasEntry(wxT("/SkinGUIOptions/UseSkinFiles"))) {
1340 bool UseSkinFiles;
1341 cfg->Read(wxT("/SkinGUIOptions/UseSkinFiles"), &UseSkinFiles, false);
1342 if (!UseSkinFiles) {
1343 s_Skin.Clear();
1345 cfg->DeleteEntry(wxT("/SkinGUIOptions/UseSkinFiles"));
1348 #ifdef __DEBUG__
1349 // Load debug-categories
1350 int count = theLogger.GetDebugCategoryCount();
1352 for ( int i = 0; i < count; i++ ) {
1353 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1355 bool enabled = false;
1356 cfg->Read( wxT("/Debug/Cat_") + cat.GetName(), &enabled );
1358 theLogger.SetEnabled( cat.GetType(), enabled );
1360 #endif
1362 // Now do some post-processing / sanity checking on the values we just loaded
1363 #ifndef CLIENT_GUI
1364 CheckUlDlRatio();
1365 SetPort(s_port);
1366 if (s_byCryptTCPPaddingLength > 254) {
1367 s_byCryptTCPPaddingLength = GetRandomUint8() % 254;
1369 SetSlotAllocation(s_slotallocation);
1370 #endif
1374 void CPreferences::SaveAllItems(wxConfigBase* cfg)
1376 // Save the Cfg values
1377 CFGMap::iterator it_a = s_CfgList.begin();
1378 for ( ; it_a != s_CfgList.end(); ++it_a )
1379 it_a->second->SaveToFile( cfg );
1381 CFGList::iterator it_b = s_MiscList.begin();
1382 for ( ; it_b != s_MiscList.end(); ++it_b )
1383 (*it_b)->SaveToFile( cfg );
1386 // Save debug-categories
1387 #ifdef __DEBUG__
1388 int count = theLogger.GetDebugCategoryCount();
1390 for ( int i = 0; i < count; i++ ) {
1391 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1393 cfg->Write( wxT("/Debug/Cat_") + cat.GetName(), cat.IsEnabled() );
1395 #endif
1398 void CPreferences::SetMaxUpload(uint16 in)
1400 if ( s_maxupload != in ) {
1401 s_maxupload = in;
1403 // Ensure that the ratio is upheld
1404 CheckUlDlRatio();
1409 void CPreferences::SetMaxDownload(uint16 in)
1411 if ( s_maxdownload != in ) {
1412 s_maxdownload = in;
1414 // Ensure that the ratio is upheld
1415 CheckUlDlRatio();
1420 void CPreferences::UnsetAutoServerStart()
1422 s_autoserverlist = false;
1426 // Here we slightly limit the users' ability to be a bad citizen: for very low upload rates
1427 // we force a low download rate, so as to discourage this type of leeching.
1428 // We're Open Source, and whoever wants it can do his own mod to get around this, but the
1429 // packaged product will try to enforce good behavior.
1431 // Kry note: of course, any leecher mod will be banned asap.
1432 void CPreferences::CheckUlDlRatio()
1434 // Backwards compatibility
1435 if ( s_maxupload == 0xFFFF )
1436 s_maxupload = UNLIMITED;
1438 // Backwards compatibility
1439 if ( s_maxdownload == 0xFFFF )
1440 s_maxdownload = UNLIMITED;
1442 if ( s_maxupload == UNLIMITED )
1443 return;
1445 // Enforce the limits
1446 if ( s_maxupload < 4 ) {
1447 if ( ( s_maxupload * 3 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1448 s_maxdownload = s_maxupload * 3 ;
1449 } else if ( s_maxupload < 10 ) {
1450 if ( ( s_maxupload * 4 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1451 s_maxdownload = s_maxupload * 4;
1456 void CPreferences::Save()
1458 wxString fullpath(theApp->ConfigDir + wxT("preferences.dat"));
1460 CFile preffile;
1461 if (!wxFileExists(fullpath)) {
1462 preffile.Create(fullpath);
1465 if (preffile.Open(fullpath, CFile::read_write)) {
1466 try {
1467 preffile.WriteUInt8(PREFFILE_VERSION);
1468 preffile.WriteHash(s_userhash);
1469 } catch (const CIOFailureException& e) {
1470 AddDebugLogLineC(logGeneral, wxT("IO failure while saving user-hash: ") + e.what());
1474 SavePreferences();
1476 #ifndef CLIENT_GUI
1477 CTextFile sdirfile;
1478 if (sdirfile.Open(theApp->ConfigDir + wxT("shareddir.dat"), CTextFile::write)) {
1479 for (size_t i = 0; i < shareddir_list.size(); ++i) {
1480 sdirfile.WriteLine(CPath::ToUniv(shareddir_list[i]), wxConvUTF8);
1484 #endif
1488 CPreferences::~CPreferences()
1490 DeleteContents(m_CatList);
1494 int32 CPreferences::GetRecommendedMaxConnections()
1496 #ifndef CLIENT_GUI
1497 int iRealMax = PlatformSpecific::GetMaxConnections();
1498 if(iRealMax == -1 || iRealMax > 520) {
1499 return 500;
1501 if(iRealMax < 20) {
1502 return iRealMax;
1504 if(iRealMax <= 256) {
1505 return iRealMax - 10;
1507 return iRealMax - 20;
1508 #else
1509 return 500;
1510 #endif
1514 void CPreferences::SavePreferences()
1516 wxConfigBase* cfg = wxConfigBase::Get();
1518 cfg->Write( wxT("/eMule/AppVersion"), wxT(VERSION) );
1520 // Save the options
1521 SaveAllItems( cfg );
1523 // Ensure that the changes are saved to disk.
1524 cfg->Flush();
1528 void CPreferences::SaveCats()
1530 if ( GetCatCount() ) {
1531 wxConfigBase* cfg = wxConfigBase::Get();
1533 // Save the main cat.
1534 cfg->Write( wxT("/eMule/AllcatType"), (int)s_allcatFilter);
1536 // The first category is the default one and should not be counted
1538 cfg->Write( wxT("/General/Count"), (long)(m_CatList.size() - 1) );
1540 uint32 maxcat = m_CatList.size();
1541 for (uint32 i = 1; i < maxcat; i++) {
1542 cfg->SetPath(CFormat(wxT("/Cat#%i")) % i);
1544 cfg->Write( wxT("Title"), m_CatList[i]->title );
1545 cfg->Write( wxT("Incoming"), CPath::ToUniv(m_CatList[i]->path) );
1546 cfg->Write( wxT("Comment"), m_CatList[i]->comment );
1547 cfg->Write( wxT("Color"), wxString(CFormat(wxT("%u")) % m_CatList[i]->color));
1548 cfg->Write( wxT("Priority"), (int)m_CatList[i]->prio );
1550 // remove deleted cats from config
1551 while (cfg->DeleteGroup(CFormat(wxT("/Cat#%i")) % maxcat++)) {}
1553 cfg->Flush();
1558 void CPreferences::LoadPreferences()
1560 LoadCats();
1564 void CPreferences::LoadCats()
1566 // default cat ... Meow! =(^.^)=
1567 Category_Struct* defaultcat = new Category_Struct;
1568 defaultcat->prio = 0;
1569 defaultcat->color = 0;
1571 AddCat( defaultcat );
1573 wxConfigBase* cfg = wxConfigBase::Get();
1575 long max = cfg->Read( wxT("/General/Count"), 0l );
1577 for ( int i = 1; i <= max ; i++ ) {
1578 cfg->SetPath(CFormat(wxT("/Cat#%i")) % i);
1580 Category_Struct* newcat = new Category_Struct;
1582 newcat->title = cfg->Read( wxT("Title"), wxEmptyString );
1583 newcat->path = CPath::FromUniv(cfg->Read(wxT("Incoming"), wxEmptyString));
1585 // Some sanity checking
1586 if ( newcat->title.IsEmpty() || !newcat->path.IsOk() ) {
1587 AddLogLineN(_("Invalid category found, skipping"));
1589 delete newcat;
1590 continue;
1593 newcat->comment = cfg->Read( wxT("Comment"), wxEmptyString );
1594 newcat->prio = cfg->Read( wxT("Priority"), 0l );
1595 newcat->color = StrToULong(cfg->Read(wxT("Color"), wxT("0")));
1597 AddCat(newcat);
1599 if (!newcat->path.DirExists()) {
1600 CPath::MakeDir(newcat->path);
1606 uint16 CPreferences::GetDefaultMaxConperFive()
1608 return MAXCONPER5SEC;
1612 uint32 CPreferences::AddCat(Category_Struct* cat)
1614 m_CatList.push_back( cat );
1616 return m_CatList.size() - 1;
1620 void CPreferences::RemoveCat(size_t index)
1622 if ( index < m_CatList.size() ) {
1623 CatList::iterator it = m_CatList.begin() + index;
1625 delete *it;
1627 m_CatList.erase( it );
1629 // remove cat directory from shares
1630 theApp->sharedfiles->Reload();
1635 uint32 CPreferences::GetCatCount()
1637 return m_CatList.size();
1641 Category_Struct* CPreferences::GetCategory(size_t index)
1643 wxASSERT( index < m_CatList.size() );
1645 return m_CatList[index];
1649 const CPath& CPreferences::GetCatPath(uint8 index)
1651 wxASSERT( index < m_CatList.size() );
1653 return m_CatList[index]->path;
1657 uint32 CPreferences::GetCatColor(size_t index)
1659 wxASSERT( index < m_CatList.size() );
1661 return m_CatList[index]->color;
1664 bool CPreferences::CreateCategory(
1665 Category_Struct *& category,
1666 const wxString& name,
1667 const CPath& path,
1668 const wxString& comment,
1669 uint32 color,
1670 uint8 prio)
1672 category = new Category_Struct();
1673 category->path = thePrefs::GetIncomingDir(); // set a default in case path is invalid
1674 uint32 cat = AddCat(category);
1675 return UpdateCategory(cat, name, path, comment, color, prio);
1678 bool CPreferences::UpdateCategory(
1679 uint8 cat,
1680 const wxString& name,
1681 const CPath& path,
1682 const wxString& comment,
1683 uint32 color,
1684 uint8 prio)
1686 Category_Struct *category = m_CatList[cat];
1688 // return true if path is ok, false if not
1689 bool ret = true;
1690 if (!path.IsOk() || (!path.DirExists() && !CPath::MakeDir(path))) {
1691 ret = false;
1692 // keep path as it was
1693 } else if (category->path != path) {
1694 // path changed: reload shared files, adding files in the new path and removing those from the old path
1695 category->path = path;
1696 theApp->sharedfiles->Reload();
1698 category->title = name;
1699 category->comment = comment;
1700 category->color = color;
1701 category->prio = prio;
1703 SaveCats();
1704 return ret;
1708 wxString CPreferences::GetBrowser()
1710 wxString cmd(s_CustomBrowser);
1711 #ifndef __WINDOWS__
1712 if( s_BrowserTab ) {
1713 // This is certainly not the best way to do it, but I'm lazy
1714 if ((wxT("mozilla") == cmd.Right(7)) || (wxT("firefox") == cmd.Right(7))
1715 || (wxT("MozillaFirebird") == cmd.Right(15))) {
1716 cmd += wxT(" -remote 'openURL(%s, new-tab)'");
1718 if ((wxT("galeon") == cmd.Right(6)) || (wxT("epiphany") == cmd.Right(8))) {
1719 cmd += wxT(" -n '%s'");
1721 if (wxT("opera") == cmd.Right(5)) {
1722 cmd += wxT(" --newpage '%s'");
1724 if (wxT("netscape") == cmd.Right(8)) {
1725 cmd += wxT(" -remote 'openURLs(%s,new-tab)'");
1728 #endif /* !__WINDOWS__ */
1729 return cmd;
1732 void CPreferences::SetFilteringClients(bool val)
1734 if (val != s_IPFilterClients) {
1735 s_IPFilterClients = val;
1736 if (val) {
1737 theApp->clientlist->FilterQueues();
1742 void CPreferences::SetFilteringServers(bool val)
1744 if (val != s_IPFilterServers) {
1745 s_IPFilterServers = val;
1746 if (val) {
1747 theApp->serverlist->FilterServers();
1752 void CPreferences::SetIPFilterLevel(uint8 level)
1754 if (level != s_filterlevel) {
1755 // Set the new access-level
1756 s_filterlevel = level;
1757 #ifndef CLIENT_GUI
1758 // and reload the filter
1759 NotifyAlways_IPFilter_Reload();
1760 #endif
1764 void CPreferences::SetPort(uint16 val)
1766 // Warning: Check for +3, because server UDP is TCP+3
1768 if (val +3 > 65535) {
1769 AddLogLineC(_("TCP port can't be higher than 65532 due to server UDP socket being TCP+3"));
1770 AddLogLineN(CFormat(_("Default port will be used (%d)")) % DEFAULT_TCP_PORT);
1771 s_port = DEFAULT_TCP_PORT;
1772 } else {
1773 s_port = val;
1778 void CPreferences::ReloadSharedFolders()
1780 #ifndef CLIENT_GUI
1781 shareddir_list.clear();
1783 CTextFile file;
1784 if (file.Open(theApp->ConfigDir + wxT("shareddir.dat"), CTextFile::read)) {
1785 wxArrayString lines = file.ReadLines(txtReadDefault, wxConvUTF8);
1787 for (size_t i = 0; i < lines.size(); ++i) {
1788 CPath path = CPath::FromUniv(lines[i]);
1790 if (path.DirExists()) {
1791 shareddir_list.push_back(path);
1792 } else {
1793 AddLogLineN(CFormat(_("Dropping non-existing shared directory: %s")) % path.GetRaw());
1797 #endif
1801 bool CPreferences::IsMessageFiltered(const wxString& message)
1803 if (s_FilterAllMessages) {
1804 return true;
1805 } else {
1806 if (s_FilterSomeMessages) {
1807 if (s_MessageFilterString.IsSameAs(wxT("*"))){
1808 // Filter anything
1809 return true;
1810 } else {
1811 wxStringTokenizer tokenizer( s_MessageFilterString, wxT(",") );
1812 while (tokenizer.HasMoreTokens()) {
1813 if ( message.Lower().Trim(false).Trim(true).Contains(
1814 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1815 return true;
1818 return false;
1820 } else {
1821 return false;
1827 bool CPreferences::IsCommentFiltered(const wxString& comment)
1829 if (s_FilterComments) {
1830 wxStringTokenizer tokenizer( s_CommentFilterString, wxT(",") );
1831 while (tokenizer.HasMoreTokens()) {
1832 if ( comment.Lower().Trim(false).Trim(true).Contains(
1833 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1834 return true;
1838 return false;
1841 wxString CPreferences::GetLastHTTPDownloadURL(uint8 t)
1843 wxConfigBase* cfg = wxConfigBase::Get();
1844 wxString key = CFormat(wxT("/HTTPDownload/URL_%d")) % t;
1845 return cfg->Read(key, wxEmptyString);
1848 void CPreferences::SetLastHTTPDownloadURL(uint8 t, const wxString& val)
1850 wxConfigBase* cfg = wxConfigBase::Get();
1851 wxString key = CFormat(wxT("/HTTPDownload/URL_%d")) % t;
1852 cfg->Write(key, val);
1855 // File_checked_for_headers