1 #ifndef SPRINGLOBBY_HEADERGUARD_SETTINGS_H 2 #define SPRINGLOBBY_HEADERGUARD_SETTINGS_H 3 4 #include <wx/string.h> 5 #include <vector> 6 #include <set> 7 #include "utils/mixins.hh" 8 #include "utils/pathlistfactory.h" 9 #include "useractions.h" 10 #include "helper/sortutil.h" 11 #include "helper/slconfig.h" 12 13 14 const long CACHE_VERSION = 12; 15 const long SETTINGS_VERSION = 26; 16 17 18 const wxString DEFSETT_DEFAULT_SERVER_NAME= _T("Official server"); 19 const wxString DEFSETT_DEFAULT_SERVER_HOST = _T("lobby.springrts.com"); 20 const wxString BattlePostfix = _T("_battle"); 21 const int DEFSETT_DEFAULT_SERVER_PORT = 8200; 22 const bool DEFSETT_SAVE_PASSWORD = false; 23 const unsigned int DEFSETT_SPRING_PORT = 8452; 24 25 const long SET_MODE_EXPERT = 5000; 26 const long SET_MODE_SIMPLE = 5001; 27 const unsigned int DEFSETT_SW_WIDTH = 770; 28 const unsigned int DEFSETT_SW_HEIGHT = 580; 29 const unsigned int DEFSETT_SW_TOP = 50; 30 const unsigned int DEFSETT_SW_LEFT = 50; 31 32 const unsigned int SPRING_MAX_USERS = 64; 33 const unsigned int SPRING_MAX_TEAMS = 16; 34 const unsigned int SPRING_MAX_ALLIES = 16; 35 36 /** Default value for config path /General/WebBrowserUseDefault. 37 */ 38 const bool DEFSETT_WEB_BROWSER_USE_DEFAULT = true; 39 40 class wxWindow; 41 class wxConfigBase; 42 class wxFileConfig; 43 class wxFont; 44 struct PlaybackListFilterValues; 45 class wxFileInputStream; 46 class wxFileName; 47 class wxColour; 48 class wxColour; 49 class wxColourData; 50 class wxSize; 51 class wxPoint; 52 class wxPathList; 53 class wxTranslationHelper; 54 55 typedef std::map<unsigned int,unsigned int> ColumnMap; 56 57 struct ChannelJoinInfo 58 { 59 wxString name; 60 wxString password; 61 }; 62 63 namespace LSL{ 64 class SpringBundle; 65 }; 66 67 //!convenience class for saving and displaying a choice of discrete screen pos 68 class ScreenPosition : public wxArrayString 69 { 70 public: ScreenPosition()71 ScreenPosition(){ Add(_("Bottom right"));Add(_("Bottom left"));Add(_("Top right"));Add(_("Top left"));} 72 static const size_t bottom_right = 0; 73 static const size_t bottom_left = 1; 74 static const size_t top_right = 2; 75 static const size_t top_left = 3; 76 }; 77 78 //! @brief Class used to store and restore application settings. 79 class Settings : public SL::NonCopyable 80 { 81 public: 82 83 /** Default constructor. 84 */ 85 Settings(); 86 ~Settings(); 87 88 void Setup(wxTranslationHelper* translationhelper); 89 void ConvertSettings(wxTranslationHelper* translationhelper, long settversion); 90 91 /** Initialize all settings to default. 92 */ 93 void SetDefaultServerSettings(); 94 void SaveSettings(); 95 96 bool IsFirstRun(); 97 98 wxString GetLobbyWriteDir(); 99 100 wxString GetTempStorage(); 101 102 /* ================================================================ */ 103 /** @name Network 104 * @{ 105 */ 106 bool GetNoUDP(); 107 void SetNoUDP(bool value); 108 109 int GetClientPort();/// use zero to pick port automatically, nonzero to override. This allows to play if you have broken router, by setting SourcePort to some forwarded port. 110 void SetClientPort(int value); 111 112 bool GetShowIPAddresses(); 113 void SetShowIPAddresses(bool value); 114 115 int GetHTTPMaxParallelDownloads(); 116 void SetHTTPMaxParallelDownloads(int value); 117 /**@}*/ 118 119 /* ================================================================ */ 120 /** @name Web Browser 121 * 122 * Web browser preferences. 123 * 124 *@{ 125 */ 126 127 /** Fetch the "Use Default" setting for the web browser. 128 * 129 * @returns the current setting. 130 */ 131 bool GetWebBrowserUseDefault(); 132 133 134 /** Set the "Use Default" setting for the web browser. If @c true, we use 135 * wxLaunchDefaultBrowser when we want to open a web browser. 136 * 137 * @param useDefault Whether or not to use the system-default browser. 138 * 139 * @sa Ui::OpenWebBrowser 140 */ 141 void SetWebBrowserUseDefault(bool useDefault); 142 143 /** Get the path to the user-configured browser. 144 * 145 * @returns The user-defined browser path, if set, otherwise an empty string 146 * (wxEmptyString). 147 */ 148 wxString GetWebBrowserPath(); 149 150 /** Set the path to the user-configured browser. 151 * 152 * @param path A path to a web browser 153 */ 154 void SetWebBrowserPath( const wxString& path ); 155 156 /**@}*/ 157 158 /* ================================================================ */ 159 /** @name Cache 160 * 161 * Information about the directory tree used to cache infomation about maps 162 * and mods. 163 * 164 * @{ 165 */ 166 wxString GetCachePath(); 167 168 /**@}*/ 169 170 /* ================================================================ */ 171 /** @name Servers 172 * @{ 173 */ 174 wxString GetDefaultServer(); 175 void SetDefaultServer( const wxString& server_name ); 176 177 wxString GetServerHost( const wxString& server_name ); 178 int GetServerPort( const wxString& server_name ); 179 180 wxArrayString GetServers(); 181 bool ServerExists( const wxString& server_name ); 182 void SetServer( const wxString& server_name, const wxString& url, int port ); 183 void DeleteServer( const wxString& server_name ); 184 185 bool ShouldAddDefaultServerSettings(); 186 /**@}*/ 187 188 /* ================================================================ */ 189 /** @name Accounts 190 * @{ 191 */ 192 wxString GetServerAccountNick( const wxString& server_name ); 193 void SetServerAccountNick( const wxString& server_name, const wxString& value ); 194 195 wxString GetServerAccountPass( const wxString& server_name ); 196 void SetServerAccountPass( const wxString& server_name, const wxString& value ); 197 198 bool GetServerAccountSavePass( const wxString& server_name ); 199 void SetServerAccountSavePass( const wxString& server_name, const bool value ); 200 /**@}*/ 201 202 /* ================================================================ */ 203 /** @name Automatic channel join list 204 * 205 * These functions are used to manipulate the list of channels that 206 * SpringLobby should join upon connecting to a server. 207 * 208 * @{ 209 */ 210 211 /** Fetch the number of channels in the autojoin list. 212 */ 213 int GetNumChannelsJoin(); 214 215 216 /** Add a channel to the autojoin list. 217 */ 218 void AddChannelJoin( const wxString& channel , const wxString& key ); 219 220 /** Remove a channel from the autojoin list. 221 * 222 * @param channel The name of the channel to remove 223 */ 224 void RemoveChannelJoin( const wxString& channel ); 225 226 227 /** Returns the list of channels to autojoin 228 * 229 * @returns std::vector of ChannelJoinInfo struct, don't break ordering index! 230 */ 231 std::vector<ChannelJoinInfo> GetChannelsJoin(); 232 233 234 /** Deletes all autojoined channels 235 * 236 */ 237 void RemoveAllChannelsJoin(); 238 239 /** Returns the join order of a channel 240 * 241 * @returns the order of the channel during autojoin or -1 if not found 242 */ 243 int GetChannelJoinIndex( const wxString& name ); 244 245 bool ShouldAddDefaultChannelSettings(); 246 /**@}*/ 247 248 /* ================================================================ */ 249 /** @name UI 250 * @{ 251 */ 252 253 void SaveCustomColors( const wxColourData& cdata, const wxString& paletteName = _T("Default") ); 254 wxColourData GetCustomColors( const wxString& paletteName = _T("Default") ); 255 256 257 bool UseOldSpringLaunchMethod(); 258 void SetOldSpringLaunchMethod( bool value ); 259 260 void SetShowTooltips( bool show); 261 bool GetShowTooltips(); 262 263 ColumnMap GetColumnMap( const wxString& name ); 264 void GetColumnMap( const wxString& name, const ColumnMap& map ); 265 266 SortOrder GetSortOrder( const wxString& list_name ); 267 void SetSortOrder( const wxString& list_name, const SortOrder& order ); 268 269 void SetColumnWidth( const wxString& list_name, const int column_ind, const int column_width ); 270 int GetColumnWidth( const wxString& list_name, const int column ); 271 //! used to signal unset column width in Get... 272 static const int columnWidthUnset = -3; 273 static const int columnWidthMinimum = 5; 274 275 int GetSashPosition( const wxString& window_name ); 276 void SetSashPosition( const wxString& window_name, const int pos ); 277 278 bool GetSplitBRoomHorizontally(); 279 void SetSplitBRoomHorizontally( const bool vertical ); 280 281 bool GetShowXallTabs(); 282 void SetShowXallTabs( bool show ); 283 284 285 wxString GetEditorPath(); 286 void SetEditorPath( const wxString& path ); 287 288 void SetAutoloadedChatlogLinesCount( const int count ); 289 int GetAutoloadedChatlogLinesCount(); 290 291 void SetUseNotificationPopups( const bool use ); 292 bool GetUseNotificationPopups(); 293 void SetNotificationPopupPosition( const size_t index ); 294 size_t GetNotificationPopupPosition(); 295 void SetNotificationPopupDisplayTime( const unsigned int seconds ); 296 unsigned int GetNotificationPopupDisplayTime( ); 297 /*@}*/ 298 299 300 /* ================================================================ */ 301 /** @name Spring locations 302 * @{ 303 */ 304 305 void RefreshSpringVersionList(bool autosearch=true, const LSL::SpringBundle* additionalbundle = NULL); 306 std::map<wxString, LSL::SpringBundle> GetSpringVersionList() const; /// index -> version 307 wxString GetCurrentUsedSpringIndex(); 308 void SetUsedSpringIndex(const wxString &index ); 309 void DeleteSpringVersionbyIndex( const wxString& index ); 310 311 /// convenience wrappers to get current used version paths 312 wxString GetCurrentUsedDataDir(); 313 wxString GetCurrentUsedUnitSync(); 314 wxString GetCurrentUsedSpringBinary(); 315 //!@brief returns config file path unitsync uses, returns empty if unitsync isn't loaded 316 wxString GetCurrentUsedSpringConfigFilePath(); 317 318 wxString GetUnitSync( const wxString& index ); 319 wxString GetSpringBinary( const wxString& index ); 320 321 void SetUnitSync( const wxString& index, const wxString& path ); 322 void SetSpringBinary( const wxString& index, const wxString& path ); 323 //!@brief meaningful only on mac 324 void SetBundle( const wxString& index, const wxString& path ); 325 326 wxString AutoFindSpringBin(); 327 wxString AutoFindUnitSync( wxPathList pl = PathlistFactory::ConfigFileSearchPaths() ) const; 328 329 /*@}*/ 330 331 /* ================================================================ */ 332 /** @name Chat 333 * @{ 334 */ 335 bool GetChatLogEnable(); 336 void SetChatLogEnable( const bool value ); 337 wxString GetChatLogLoc(); 338 void SetChatLogLoc( const wxString& loc ); 339 340 //!@brief sets how many lines can stay in a chat panel before the old will start getting erased, 0 to disable 341 void SetChatHistoryLenght( int historylines ); 342 int GetChatHistoryLenght(); 343 344 void SetChatPMSoundNotificationEnabled( bool enabled ); 345 bool GetChatPMSoundNotificationEnabled(); 346 347 wxColour GetChatColorNormal(); 348 void SetChatColorNormal( wxColour value ); 349 wxColour GetChatColorBackground(); 350 void SetChatColorBackground( wxColour value ); 351 wxColour GetChatColorHighlight(); 352 void SetChatColorHighlight( wxColour value ); 353 wxColour GetChatColorMine(); 354 void SetChatColorMine( wxColour value ); 355 wxColour GetChatColorNotification(); 356 void SetChatColorNotification( wxColour value ); 357 wxColour GetChatColorAction(); 358 void SetChatColorAction( wxColour value ); 359 wxColour GetChatColorServer(); 360 void SetChatColorServer( wxColour value ); 361 wxColour GetChatColorClient(); 362 void SetChatColorClient( wxColour value ); 363 wxColour GetChatColorJoinPart(); 364 void SetChatColorJoinPart( wxColour value ); 365 wxColour GetChatColorError(); 366 void SetChatColorError( wxColour value ); 367 wxColour GetChatColorTime(); 368 void SetChatColorTime( wxColour value ); 369 wxFont GetChatFont(); 370 void SetChatFont( wxFont value ); 371 372 void SetDisplayJoinLeave( bool display, const wxString& channel ); 373 bool GetDisplayJoinLeave( const wxString& channel ); 374 375 void SetHighlightedWords( const wxArrayString& words ); 376 wxArrayString GetHighlightedWords( ); 377 378 //!\brief controls if user attention is requested when highlighting a line 379 void SetRequestAttOnHighlight( const bool req ); 380 bool GetRequestAttOnHighlight( ); 381 /**@}*/ 382 383 /* Do these go in Chat? */ 384 bool GetSmartScrollEnabled(); 385 void SetSmartScrollEnabled(bool value); 386 bool GetAlwaysAutoScrollOnFocusLost(); 387 void SetAlwaysAutoScrollOnFocusLost(bool value); 388 389 void SetUseIrcColors( bool value ); 390 bool GetUseIrcColors(); 391 392 /* ================================================================ */ 393 /** @name Hosting 394 * 395 * %Settings to use when hosting games. Includes "sticky" settings from the 396 * last time a game was hosted. 397 * 398 * @{ 399 */ 400 wxString GetLastHostDescription(); 401 wxString GetLastHostMod(); 402 wxString GetLastHostPassword(); 403 int GetLastHostPort(); 404 int GetLastHostPlayerNum(); 405 int GetLastHostNATSetting(); 406 wxString GetLastHostMap(); 407 wxString GetDefaultNick(); 408 int GetLastRankLimit(); 409 bool GetTestHostPort(); 410 bool GetLastAutolockStatus(); 411 bool GetLastHostRelayedMode(); 412 413 void SetLastHostDescription( const wxString& value ); 414 void SetLastHostMod( const wxString& value ); 415 void SetLastHostPassword( const wxString& value ); 416 void SetLastHostPort( int value ); 417 void SetLastHostPlayerNum( int value ); 418 void SetLastHostNATSetting( int value ); 419 void SetLastHostMap( const wxString& value ); 420 void SetLastRankLimit( int rank ); 421 void SetTestHostPort( bool value ); 422 void SetLastAutolockStatus( bool value ); 423 void SetLastHostRelayedMode( bool value ); 424 425 void SetHostingPreset( const wxString& name, int optiontype, std::map<wxString,wxString> options ); 426 std::map<wxString,wxString> GetHostingPreset( const wxString& name, int optiontype ); 427 wxArrayString GetPresetList(); 428 void DeletePreset( const wxString& name ); 429 430 wxString GetModDefaultPresetName( const wxString& modname ); 431 void SetModDefaultPresetName( const wxString& modname, const wxString& presetname ); 432 433 /**@}*/ 434 435 436 /* ================================================================ */ 437 wxColour GetBattleLastColour(); 438 void SetBattleLastColour( const wxColour& col ); 439 440 void SetLastBattleId( int battleId ); 441 int GetLastBattleId(); 442 443 void SetLastScriptPassword( const wxString& scriptPassword ); 444 wxString GetLastScriptPassword(); 445 446 void SetLastAI( const wxString& ai ); 447 wxString GetLastAI(); 448 449 void SetBalanceMethod(int value); 450 int GetBalanceMethod(); 451 452 void SetBalanceClans(bool value); 453 bool GetBalanceClans(); 454 455 void SetBalanceStrongClans(bool value); 456 bool GetBalanceStrongClans(); 457 458 void SetBalanceGrouping( int value ); 459 int GetBalanceGrouping(); 460 461 void SetFixIDMethod(int value); 462 int GetFixIDMethod(); 463 464 void SetFixIDClans(bool value); 465 bool GetFixIDClans(); 466 467 void SetFixIDStrongClans(bool value); 468 bool GetFixIDStrongClans(); 469 470 void SetFixIDGrouping( int value ); 471 int GetFixIDGrouping(); 472 473 /** @name Battle filters 474 * @{ 475 */ 476 477 bool GetBattleLastAutoStartState(); 478 void SetBattleLastAutoStartState( bool value ); 479 480 bool GetBattleLastAutoControlState(); 481 void SetBattleLastAutoControlState( bool value ); 482 483 int GetBattleLastAutoSpectTime(); 484 void SetBattleLastAutoSpectTime( int value ); 485 486 bool GetBattleLastAutoAnnounceDescription(); 487 void SetBattleLastAutoAnnounceDescription( bool value ); 488 489 void SetBattleLastSideSel( const wxString& modname, int sidenum ); 490 int GetBattleLastSideSel( const wxString& modname ); 491 492 struct SettStartBox 493 { 494 int ally; 495 int topx; 496 int topy; 497 int bottomx; 498 int bottomy; 499 }; 500 501 void SetMapLastStartPosType( const wxString& mapname, const wxString& startpostype ); 502 void SetMapLastRectPreset( const wxString& mapname, std::vector<Settings::SettStartBox> rects ); 503 504 wxString GetMapLastStartPosType( const wxString& mapname ); 505 std::vector<Settings::SettStartBox> GetMapLastRectPreset( const wxString& mapname ); 506 /**@}*/ 507 508 /** @name Replay filters 509 * @{ 510 */ 511 PlaybackListFilterValues GetReplayFilterValues(const wxString& profile_name = (_T("default"))); 512 void SetReplayFilterValues(const PlaybackListFilterValues& blfValues, const wxString& profile_name = _T("default")); 513 wxString GetLastReplayFilterProfileName(); 514 void SetReplayFilterActivState( const bool state ); 515 bool GetReplayFilterActivState( ) const; 516 /**@}*/ 517 518 bool GetDisableSpringVersionCheck(); 519 void SetDisableSpringVersionCheck(bool disable); 520 521 /** @name Aui 522 * 523 * Functions used to store and retrieve the current SpringLobby 524 * interface layout. 525 * 526 * @{ 527 */ 528 void SaveLayout( wxString& layout_name, wxString& layout_string ); 529 wxString GetLayout( wxString& layout_name ); 530 531 void SavePerspective( const wxString& notebook_name, const wxString& perspective_name, const wxString& layout_string ); 532 wxString LoadPerspective( const wxString& notebook_name, const wxString& perspective_name ); 533 wxString GetLastPerspectiveName( ); 534 void SetLastPerspectiveName( const wxString& name ); 535 void SetAutosavePerspective( bool autosave ); 536 bool GetAutosavePerspective( ); 537 wxArrayString GetPerspectives(); 538 bool PerspectiveExists( const wxString& perspective_name ); 539 540 void RemoveLayouts(); 541 542 /**@}*/ 543 544 enum CompletionMethod { 545 MatchNearest = 1, 546 MatchExact = 2 547 }; 548 549 void SetCompletionMethod( CompletionMethod method ); 550 CompletionMethod GetCompletionMethod( ) const; 551 552 /** @name SpringSettings 553 * @{ 554 */ 555 long getMode(); 556 void setMode( long ); 557 bool getDisableWarning(); 558 void setDisableWarning( bool ); 559 wxString getSimpleRes(); 560 void setSimpleRes( wxString ); 561 wxString getSimpleQuality(); 562 void setSimpleQuality( wxString ); 563 wxString getSimpleDetail(); 564 void setSimpleDetail( wxString ); 565 566 /**@}*/ 567 568 /* ================================================================ */ 569 /** @name Map selection dialog 570 * @{ 571 */ 572 unsigned int GetVerticalSortkeyIndex( ); 573 void SetVerticalSortkeyIndex( const unsigned int idx ); 574 575 unsigned int GetHorizontalSortkeyIndex( ); 576 void SetHorizontalSortkeyIndex( const unsigned int idx ); 577 578 /** \return true for "<" false for ">" */ 579 bool GetHorizontalSortorder(); 580 void SetHorizontalSortorder( const bool order ); 581 582 /** \return true for "ᴧ", false for "ᴠ" */ 583 bool GetVerticalSortorder(); 584 void SetVerticalSortorder( const bool order ); 585 586 void SetMapSelectorFollowsMouse( bool value ); 587 bool GetMapSelectorFollowsMouse(); 588 589 /** \return m_filter_all_sett = 0; (default) 590 m_filter_recent_sett = 1; 591 m_filter_popular_sett = 2; */ 592 unsigned int GetMapSelectorFilterRadio(); 593 void SetMapSelectorFilterRadio( const unsigned int val ); 594 /**@}*/ 595 /* ============================================================== */ 596 /** @name Relay Hosts 597 * @{ 598 */ 599 600 wxString GetLastRelayedHost(void); 601 void SetLastRelayedHost(wxString relhost); 602 603 /**@}*/ 604 605 //! you are absolutely forbidden to use this 606 template < class T > Get(wxString setting,const T def)607 T Get( wxString setting, const T def ) 608 { 609 return m_config->Read( setting, def ); 610 } 611 template < class T > Set(wxString setting,const T val)612 bool Set( wxString setting, const T val ) 613 { 614 return m_config->Write( setting, val ); 615 } 616 617 wxString FinalConfigPath() const; 618 619 //! move weirdly saved lists to sane form 620 void ConvertLists(); 621 622 private: 623 bool IsSpringBin( const wxString& path ); 624 625 slConfig* m_config; //!< wxConfig object to store and restore all settings in. 626 627 std::map<wxString, LSL::SpringBundle> m_spring_versions; 628 629 630 void setFromList(const wxArrayString& list, const wxString& path); 631 wxArrayString getFromList(const wxString& path); 632 }; 633 634 Settings& sett(); 635 636 #endif // SPRINGLOBBY_HEADERGUARD_SETTINGS_H 637 638 /** 639 This file is part of SpringLobby, 640 Copyright (C) 2007-2011 641 642 SpringLobby is free software: you can redistribute it and/or modify 643 it under the terms of the GNU General Public License version 2 as published by 644 the Free Software Foundation. 645 646 SpringLobby is distributed in the hope that it will be useful, 647 but WITHOUT ANY WARRANTY; without even the implied warranty of 648 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 649 GNU General Public License for more details. 650 651 You should have received a copy of the GNU General Public License 652 along with SpringLobby. If not, see <http://www.gnu.org/licenses/>. 653 **/ 654 655