diff --git a/include/kiway.h b/include/kiway.h index 48161c544a..0dfb24a47a 100644 --- a/include/kiway.h +++ b/include/kiway.h @@ -401,7 +401,7 @@ public: * * Use after changing suite-wide options such as panning, autosave interval, etc. */ - virtual void CommonSettingsChanged( int aFlags ); + virtual void CommonSettingsChanged( int aFlags = 0 ); /** * Calls ProjectChanged() on all KIWAY_PLAYERs. diff --git a/kicad/pcm/dialogs/dialog_pcm.cpp b/kicad/pcm/dialogs/dialog_pcm.cpp index f982fbae01..a4d42bdcd6 100644 --- a/kicad/pcm/dialogs/dialog_pcm.cpp +++ b/kicad/pcm/dialogs/dialog_pcm.cpp @@ -25,6 +25,7 @@ #include "bitmaps.h" #include "dialog_manage_repositories.h" #include "dialog_pcm.h" +#include <eda_base_frame.h> #include "grid_tricks.h" #include "ki_exception.h" #include "pcm_task_manager.h" @@ -54,8 +55,9 @@ static std::vector<std::pair<PCM_PACKAGE_TYPE, wxString>> PACKAGE_TYPE_LIST = { }; -DIALOG_PCM::DIALOG_PCM( wxWindow* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ) : +DIALOG_PCM::DIALOG_PCM( EDA_BASE_FRAME* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ) : DIALOG_PCM_BASE( parent ), + m_parentFrame( parent ), m_pcm( pcm ) { // correct the min size from wxfb with fromdip diff --git a/kicad/pcm/dialogs/dialog_pcm.h b/kicad/pcm/dialogs/dialog_pcm.h index 6321ebb144..098ff6c739 100644 --- a/kicad/pcm/dialogs/dialog_pcm.h +++ b/kicad/pcm/dialogs/dialog_pcm.h @@ -30,15 +30,19 @@ #include <vector> +class EDA_BASE_FRAME; + /** Implementing pcm main dialog. */ class DIALOG_PCM : public DIALOG_PCM_BASE { public: /** Constructor */ - DIALOG_PCM( wxWindow* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ); + DIALOG_PCM( EDA_BASE_FRAME* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ); ~DIALOG_PCM(); + EDA_BASE_FRAME* ParentFrame() const { return m_parentFrame; } + ///< Closes the window, asks user confirmation if there are pending actions void OnCloseClicked( wxCommandEvent& event ) override; void OnCloseWindow( wxCloseEvent& aEvent ); @@ -102,6 +106,7 @@ private: ///< Discards specified pending action void discardAction( int aIndex ); + EDA_BASE_FRAME* m_parentFrame; std::shared_ptr<PLUGIN_CONTENT_MANAGER> m_pcm; ActionCallback m_actionCallback; PinCallback m_pinCallback; diff --git a/kicad/pcm/pcm.cpp b/kicad/pcm/pcm.cpp index 032d94cfb6..3abc699284 100644 --- a/kicad/pcm/pcm.cpp +++ b/kicad/pcm/pcm.cpp @@ -30,10 +30,14 @@ #include "build_version.h" #include "paths.h" #include "pcm.h" +#include <eda_base_frame.h> +#include "dialogs/dialog_pcm.h" #include "pgm_base.h" #include "picosha2.h" #include "settings/settings_manager.h" #include <wx_filename.h> +#include <settings/common_settings.h> +#include <kiway.h> #include <fstream> #include <iomanip> @@ -766,6 +770,21 @@ void PLUGIN_CONTENT_MANAGER::MarkInstalled( const PCM_PACKAGE& aPackage, const w entry.pinned = pinned; m_installed.emplace( aPackage.identifier, entry ); + + if( m_dialog + && ( aPackage.versions[0].runtime.value_or( PCM_PACKAGE_RUNTIME::PPR_SWIG ) + == PCM_PACKAGE_RUNTIME::PPR_IPC ) + && !Pgm().GetCommonSettings()->m_Api.enable_server ) + { + if( wxMessageBox( _( "This plugin requires the KiCad API, which is currently " + "disabled in preferences. Would you like to enable it?" ), + _( "Enable KiCad API" ), wxICON_QUESTION | wxYES_NO, m_dialog ) + == wxYES ) + { + Pgm().GetCommonSettings()->m_Api.enable_server = true; + m_dialog->ParentFrame()->Kiway().CommonSettingsChanged(); + } + } } diff --git a/kicad/pcm/pcm.h b/kicad/pcm/pcm.h index 50a29cfedd..d5bfa531ff 100644 --- a/kicad/pcm/pcm.h +++ b/kicad/pcm/pcm.h @@ -80,6 +80,7 @@ typedef std::vector<std::tuple<wxString, wxString, wxString>> STRING_TUPLE_LIST; struct BACKGROUND_JOB; +class DIALOG_PCM; /** @@ -326,7 +327,7 @@ public: * * @param aDialog parent dialog for progress window */ - void SetDialogWindow( wxWindow* aDialog ) { m_dialog = aDialog; }; + void SetDialogWindow( DIALOG_PCM* aDialog ) { m_dialog = aDialog; }; /** * @brief Runs a background update thread that checks for new package versions @@ -392,7 +393,7 @@ private: ///< Returns current UTC timestamp time_t getCurrentTimestamp() const; - wxWindow* m_dialog; + DIALOG_PCM* m_dialog; std::unique_ptr<JSON_SCHEMA_VALIDATOR> m_schema_validator; wxString m_3rdparty_path; wxString m_cache_path; diff --git a/kicad/pcm/pcm_data.cpp b/kicad/pcm/pcm_data.cpp index 07bd2dac47..9a55bf4365 100644 --- a/kicad/pcm/pcm_data.cpp +++ b/kicad/pcm/pcm_data.cpp @@ -54,6 +54,9 @@ void to_json( json& j, const PACKAGE_VERSION& v ) if( v.install_size ) j["install_size"] = *v.install_size; + if( v.runtime ) + j["runtime"] = *v.runtime; + if( v.platforms.size() > 0 ) nlohmann::to_json( j["platforms"], v.platforms ); @@ -77,6 +80,7 @@ void from_json( const json& j, PACKAGE_VERSION& v ) to_optional( j, "download_size", v.download_size ); to_optional( j, "install_size", v.install_size ); to_optional( j, "kicad_version_max", v.kicad_version_max ); + to_optional( j, "runtime", v.runtime ); if( j.contains( "platforms" ) ) j.at( "platforms" ).get_to( v.platforms ); diff --git a/kicad/pcm/pcm_data.h b/kicad/pcm/pcm_data.h index 1dab438256..1f1c738961 100644 --- a/kicad/pcm/pcm_data.h +++ b/kicad/pcm/pcm_data.h @@ -66,6 +66,13 @@ enum PCM_PACKAGE_VERSION_STATUS PVS_DEPRECATED }; +///< The runtime a plugin package uses +enum class PCM_PACKAGE_RUNTIME +{ + PPR_SWIG, + PPR_IPC +}; + ///< Describes a person's name and contact information struct PCM_CONTACT @@ -93,6 +100,7 @@ struct PACKAGE_VERSION wxString kicad_version; std::optional<wxString> kicad_version_max; std::vector<std::string> keep_on_update; + std::optional<PCM_PACKAGE_RUNTIME> runtime; // Not serialized fields std::tuple<int, int, int, int> parsed_version; // Full version tuple for sorting @@ -183,6 +191,12 @@ NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PACKAGE_VERSION_STATUS, { PVS_DEPRECATED, "deprecated" }, } ) +NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PACKAGE_RUNTIME, + { + { PCM_PACKAGE_RUNTIME::PPR_SWIG, "swig" }, + { PCM_PACKAGE_RUNTIME::PPR_IPC, "ipc" }, + } ) + // Following are templates and definitions for en/decoding above structs // to/from json diff --git a/kicad/pcm/schemas/pcm.v1.schema.json b/kicad/pcm/schemas/pcm.v1.schema.json index ab71029ff8..ec36b80cc0 100644 --- a/kicad/pcm/schemas/pcm.v1.schema.json +++ b/kicad/pcm/schemas/pcm.v1.schema.json @@ -191,6 +191,14 @@ "minItems": 1, "uniqueItems": true }, + "runtime": { + "type": "string", + "enum": [ + "swig", + "ipc" + ], + "description": "What runtime a plugin requires. Assumed to be swig if absent. Not used for non-plugin packages." + }, "kicad_version": { "type": "string", "description": "Minimum supported KiCad version", @@ -391,4 +399,4 @@ ] } } -} \ No newline at end of file +}