You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
  5. * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "settings/kicad_settings.h"
  21. #include <nlohmann/json.hpp>
  22. #include <settings/parameters.h>
  23. ///! Update the schema version whenever a migration is required
  24. const int kicadSchemaVersion = 0;
  25. const nlohmann::json PCM_DEFAULT_REPOSITORIES = nlohmann::json::array( {
  26. nlohmann::json( {
  27. { "name", "KiCad official repository" },
  28. { "url", PCM_DEFAULT_REPOSITORY_URL },
  29. } )
  30. } );
  31. KICAD_SETTINGS::KICAD_SETTINGS() :
  32. APP_SETTINGS_BASE( "kicad", kicadSchemaVersion ), m_LeftWinWidth( 200 )
  33. {
  34. m_params.emplace_back( new PARAM<int>( "appearance.left_frame_width", &m_LeftWinWidth, 200 ) );
  35. m_params.emplace_back(
  36. new PARAM_LIST<wxString>( "system.open_projects", &m_OpenProjects, {} ) );
  37. m_params.emplace_back( new PARAM<int>( "system.check_for_updates", &m_updateCheck, 0 ) );
  38. m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
  39. "pcm.repositories",
  40. [&]() -> nlohmann::json
  41. {
  42. nlohmann::json js = nlohmann::json::array();
  43. for( const auto& pair : m_PcmRepositories )
  44. {
  45. js.push_back( nlohmann::json( { { "name", pair.first.ToUTF8() },
  46. { "url", pair.second.ToUTF8() } } ) );
  47. }
  48. return js;
  49. },
  50. [&]( const nlohmann::json aObj )
  51. {
  52. m_PcmRepositories.clear();
  53. if( !aObj.is_array() )
  54. return;
  55. for( const auto& entry : aObj )
  56. {
  57. if( entry.empty() || !entry.is_object() )
  58. continue;
  59. m_PcmRepositories.emplace_back(
  60. std::make_pair( wxString( entry["name"].get<std::string>() ),
  61. wxString( entry["url"].get<std::string>() ) ) );
  62. }
  63. },
  64. PCM_DEFAULT_REPOSITORIES ) );
  65. m_params.emplace_back(
  66. new PARAM<wxString>( "pcm.last_download_dir", &m_PcmLastDownloadDir, "" ) );
  67. m_params.emplace_back( new PARAM<bool>( "pcm.check_for_updates", &m_PcmUpdateCheck, true ) );
  68. m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_add", &m_PcmLibAutoAdd, true ) );
  69. m_params.emplace_back( new PARAM<bool>( "pcm.lib_auto_remove", &m_PcmLibAutoRemove, true ) );
  70. m_params.emplace_back( new PARAM<wxString>( "pcm.lib_prefix", &m_PcmLibPrefix, "PCM_" ) );
  71. }
  72. bool KICAD_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
  73. {
  74. bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
  75. ret &= fromLegacy<int>( aCfg, "LeftWinWidth", "appearance.left_frame_width" );
  76. // Override the size parameters to ensure the new PCM button is always shown.
  77. // This will make the window take the default size instead of the migrated one.
  78. Set( "window.size_x", 0 );
  79. Set( "window.size_y", 0 );
  80. return ret;
  81. }