From 4937cd537bc4c5196d84f5af118521e5bcd9fa1b Mon Sep 17 00:00:00 2001 From: qu1ck Date: Fri, 2 Apr 2021 20:18:56 -0700 Subject: [PATCH] Add PCM settings --- kicad/kicad_settings.cpp | 52 ++++++++++++++++++++++++++++++++++++---- kicad/kicad_settings.h | 5 ++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/kicad/kicad_settings.cpp b/kicad/kicad_settings.cpp index 6db07324d7..5196aa3947 100644 --- a/kicad/kicad_settings.cpp +++ b/kicad/kicad_settings.cpp @@ -18,8 +18,9 @@ * with this program. If not, see . */ -#include #include "kicad_settings.h" +#include "nlohmann/json.hpp" +#include ///! Update the schema version whenever a migration is required @@ -27,13 +28,54 @@ const int kicadSchemaVersion = 0; KICAD_SETTINGS::KICAD_SETTINGS() : - APP_SETTINGS_BASE( "kicad", kicadSchemaVersion ), - m_LeftWinWidth( 200 ) + APP_SETTINGS_BASE( "kicad", kicadSchemaVersion ), m_LeftWinWidth( 200 ) { m_params.emplace_back( new PARAM( "appearance.left_frame_width", &m_LeftWinWidth, 200 ) ); - m_params.emplace_back( new PARAM_LIST( "system.open_projects", - &m_OpenProjects, {} ) ); + m_params.emplace_back( + new PARAM_LIST( "system.open_projects", &m_OpenProjects, {} ) ); + +#ifdef PCM + m_params.emplace_back( new PARAM_LAMBDA( + "pcm.repositories", + [&]() -> nlohmann::json + { + nlohmann::json js = nlohmann::json::array(); + + for( const auto& pair : m_PcmRepositories ) + { + js.push_back( nlohmann::json( { { "name", pair.first.ToUTF8() }, + { "url", pair.second.ToUTF8() } } ) ); + + return js; + }, + [&]( const nlohmann::json aObj ) + { + m_PcmRepositories.clear(); + + if( !aObj.is_array() ) + return; + + for( const auto& entry : aObj ) + { + if( entry.empty() || !entry.is_object() ) + continue; + + m_PcmRepositories.emplace_back( + std::make_pair( wxString( entry["name"].get() ), + wxString( entry["url"].get() ) ) ); + } + }, + R"([ + { + "name": "KiCad official repository", + "url": "https://repository.kicad.org/repository.json" + } + ])"_json ) ); + + m_params.emplace_back( + new PARAM( "pcm.last_download_dir", &m_PcmLastDownloadDir, "" ) ); +#endif } diff --git a/kicad/kicad_settings.h b/kicad/kicad_settings.h index c0f0b2cd3d..1b50515074 100644 --- a/kicad/kicad_settings.h +++ b/kicad/kicad_settings.h @@ -38,6 +38,11 @@ public: std::vector m_OpenProjects; +#ifdef PCM + std::vector> m_PcmRepositories; + wxString m_PcmLastDownloadDir; +#endif + protected: virtual std::string getLegacyFrameName() const override { return "KicadFrame"; }