From 392ed5fecd07d29a16804c8f3ecbe6b1d98086e9 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Tue, 12 Apr 2022 00:11:16 -0400 Subject: [PATCH] Add policy to enable/disable pcm --- common/dialogs/panel_data_collection.cpp | 5 ++-- common/pgm_base.cpp | 8 +++--- include/policy_keys.h | 31 ++++++++++++++++++++++++ kicad/dialogs/panel_kicad_launcher.cpp | 19 ++++++++++++--- kicad/menubar.cpp | 11 ++++++++- kicad/tools/kicad_manager_control.cpp | 9 +++++++ libs/kiplatform/msw/policy.cpp | 2 +- 7 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 include/policy_keys.h diff --git a/common/dialogs/panel_data_collection.cpp b/common/dialogs/panel_data_collection.cpp index d5605139a7..51c622e9a5 100644 --- a/common/dialogs/panel_data_collection.cpp +++ b/common/dialogs/panel_data_collection.cpp @@ -28,13 +28,14 @@ #include #include #include +#include #include #include +#include #include #include #include -#include PANEL_DATA_COLLECTION::PANEL_DATA_COLLECTION( PAGED_DIALOG* aDialog, wxWindow* aParent ) : PANEL_DATA_COLLECTION_BASE( aParent ), m_dialog( aDialog ) @@ -47,7 +48,7 @@ bool PANEL_DATA_COLLECTION::TransferDataToWindow() applySettingsToPanel(); KIPLATFORM::POLICY::STATE policyState = - KIPLATFORM::POLICY::GetPolicyState( "DataCollection" ); + KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_DATACOLLECTION ); if( policyState != KIPLATFORM::POLICY::STATE::NOT_CONFIGURED ) { Disable(); diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index 3e75ae01d4..111b64df2e 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -59,8 +60,7 @@ #include #include #include - -#include +#include #ifdef KICAD_USE_SENTRY #include @@ -221,7 +221,7 @@ const wxString PGM_BASE::AskUserForPreferredEditor( const wxString& aDefaultEdit bool PGM_BASE::IsSentryOptedIn() { KIPLATFORM::POLICY::STATE policyState = - KIPLATFORM::POLICY::GetPolicyState( wxT( "DataCollection" ) ); + KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_DATACOLLECTION ); if( policyState != KIPLATFORM::POLICY::STATE::NOT_CONFIGURED ) { return policyState == KIPLATFORM::POLICY::STATE::ENABLED; @@ -329,7 +329,7 @@ void PGM_BASE::sentryInit() void PGM_BASE::sentryPrompt() { KIPLATFORM::POLICY::STATE policyState = - KIPLATFORM::POLICY::GetPolicyState( wxT( "DataCollection" ) ); + KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_DATACOLLECTION ); if( policyState == KIPLATFORM::POLICY::STATE::NOT_CONFIGURED && !m_settings_manager->GetCommonSettings()->m_DoNotShowAgain.data_collection_prompt ) diff --git a/include/policy_keys.h b/include/policy_keys.h new file mode 100644 index 0000000000..91dc16923d --- /dev/null +++ b/include/policy_keys.h @@ -0,0 +1,31 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +#ifndef POLICY_KEYS_H_ +#define POLICY_KEYS_H_ + +#define POLICY_KEY_DATACOLLECTION wxT( "DataCollection" ) +#define POLICY_KEY_PCM wxT( "PluginAndContentManager" ) + +#endif // POLICY_KEYS_H_ \ No newline at end of file diff --git a/kicad/dialogs/panel_kicad_launcher.cpp b/kicad/dialogs/panel_kicad_launcher.cpp index cb0217f779..8a9dbc4eee 100644 --- a/kicad/dialogs/panel_kicad_launcher.cpp +++ b/kicad/dialogs/panel_kicad_launcher.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -58,10 +60,11 @@ void PANEL_KICAD_LAUNCHER::CreateLaunchers() helpFont.SetStyle( wxFONTSTYLE_ITALIC ); auto addLauncher = - [&]( const TOOL_ACTION& aAction, const wxBitmap& aBitmap, const wxString& aHelpText ) + [&]( const TOOL_ACTION& aAction, const wxBitmap& aBitmap, const wxString& aHelpText, bool enabled = true ) { BITMAP_BUTTON* btn = new BITMAP_BUTTON( this, wxID_ANY ); btn->SetBitmap( aBitmap ); + btn->SetDisabledBitmap( wxBitmap( aBitmap.ConvertToImage().ConvertToGreyscale() ) ); btn->SetPadding( 5 ); btn->SetToolTip( aAction.GetDescription() ); @@ -109,7 +112,14 @@ void PANEL_KICAD_LAUNCHER::CreateLaunchers() m_toolsSizer->Add( help, wxGBPosition( row + 1, 1 ), wxGBSpan( 1, 1 ), wxALIGN_TOP | wxTOP, 1 ); - }; + + btn->Enable( enabled ); + if( !enabled ) + { + help->Disable(); + label->Disable(); + } + }; addLauncher( KICAD_MANAGER_ACTIONS::editSchematic, KiScaledBitmap( BITMAPS::icon_eeschema, this, 48, true ), @@ -145,8 +155,9 @@ void PANEL_KICAD_LAUNCHER::CreateLaunchers() "designs" ) ); addLauncher( KICAD_MANAGER_ACTIONS::showPluginManager, - KiScaledBitmap( BITMAPS::icon_pcm, this, 48, true ), - _( "Manage downloadable packages from KiCad and 3rd party repositories" ) ); + KiScaledBitmap( BITMAPS::icon_pcm, this, 48, true ), + _( "Manage downloadable packages from KiCad and 3rd party repositories" ), + ( KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_PCM ) != KIPLATFORM::POLICY::STATE::DISABLED ) ); Layout(); } diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp index a74615170f..d2338828e1 100644 --- a/kicad/menubar.cpp +++ b/kicad/menubar.cpp @@ -26,8 +26,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -159,7 +161,14 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() toolsMenu->Add( KICAD_MANAGER_ACTIONS::convertImage ); toolsMenu->Add( KICAD_MANAGER_ACTIONS::showCalculator ); toolsMenu->Add( KICAD_MANAGER_ACTIONS::editDrawingSheet ); - toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager ); + + wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager ); + + if( KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_PCM ) + == KIPLATFORM::POLICY::STATE::DISABLED ) + { + pcmMenuItem->Enable( false ); + } toolsMenu->AppendSeparator(); toolsMenu->Add( _( "Edit Local File..." ), diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp index 9bc58a6354..6dc39be635 100644 --- a/kicad/tools/kicad_manager_control.cpp +++ b/kicad/tools/kicad_manager_control.cpp @@ -21,8 +21,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -813,6 +815,13 @@ int KICAD_MANAGER_CONTROL::Execute( const TOOL_EVENT& aEvent ) int KICAD_MANAGER_CONTROL::ShowPluginManager( const TOOL_EVENT& aEvent ) { + if( KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_PCM ) + == KIPLATFORM::POLICY::STATE::DISABLED ) + { + // policy disables the plugin manager + return 0; + } + // For some reason, after a click or a double click the bitmap button calling // PCM keeps the focus althougt the focus was not set to this button. // This hack force removing the focus from this button diff --git a/libs/kiplatform/msw/policy.cpp b/libs/kiplatform/msw/policy.cpp index 9496ce6811..e60a8c319a 100644 --- a/libs/kiplatform/msw/policy.cpp +++ b/libs/kiplatform/msw/policy.cpp @@ -32,7 +32,7 @@ KIPLATFORM::POLICY::STATE KIPLATFORM::POLICY::GetPolicyState( const wxString& aK if( key.Exists() ) { long value; - if( key.QueryValue( aKey, &value ) ) + if( key.HasValue( aKey ) && key.QueryValue( aKey, &value ) ) { if( value == 1 ) return POLICY::STATE::ENABLED;