Add support for enum based policies
This commit is contained in:
parent
8d2c744349
commit
b0fa2561b6
|
@ -47,9 +47,9 @@ bool PANEL_DATA_COLLECTION::TransferDataToWindow()
|
|||
{
|
||||
applySettingsToPanel();
|
||||
|
||||
KIPLATFORM::POLICY::STATE policyState =
|
||||
KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_DATACOLLECTION );
|
||||
if( policyState != KIPLATFORM::POLICY::STATE::NOT_CONFIGURED )
|
||||
KIPLATFORM::POLICY::PBOOL policyState =
|
||||
KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_DATACOLLECTION );
|
||||
if( policyState != KIPLATFORM::POLICY::PBOOL::NOT_CONFIGURED )
|
||||
{
|
||||
Disable();
|
||||
}
|
||||
|
|
|
@ -243,11 +243,11 @@ const wxString PGM_BASE::AskUserForPreferredEditor( const wxString& aDefaultEdit
|
|||
#ifdef KICAD_USE_SENTRY
|
||||
bool PGM_BASE::IsSentryOptedIn()
|
||||
{
|
||||
KIPLATFORM::POLICY::STATE policyState =
|
||||
KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_DATACOLLECTION );
|
||||
if( policyState != KIPLATFORM::POLICY::STATE::NOT_CONFIGURED )
|
||||
KIPLATFORM::POLICY::PBOOL policyState =
|
||||
KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_DATACOLLECTION );
|
||||
if( policyState != KIPLATFORM::POLICY::PBOOL::NOT_CONFIGURED )
|
||||
{
|
||||
return policyState == KIPLATFORM::POLICY::STATE::ENABLED;
|
||||
return policyState == KIPLATFORM::POLICY::PBOOL::ENABLED;
|
||||
}
|
||||
|
||||
return m_sentry_optin_fn.Exists();
|
||||
|
@ -354,10 +354,10 @@ void PGM_BASE::sentryPrompt()
|
|||
if( !IsGUI() )
|
||||
return;
|
||||
|
||||
KIPLATFORM::POLICY::STATE policyState =
|
||||
KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_DATACOLLECTION );
|
||||
KIPLATFORM::POLICY::PBOOL policyState =
|
||||
KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_DATACOLLECTION );
|
||||
|
||||
if( policyState == KIPLATFORM::POLICY::STATE::NOT_CONFIGURED
|
||||
if( policyState == KIPLATFORM::POLICY::PBOOL::NOT_CONFIGURED
|
||||
&& !m_settings_manager->GetCommonSettings()->m_DoNotShowAgain.data_collection_prompt )
|
||||
{
|
||||
wxMessageDialog optIn = wxMessageDialog(
|
||||
|
|
|
@ -162,8 +162,8 @@ void PANEL_KICAD_LAUNCHER::CreateLaunchers()
|
|||
addLauncher( KICAD_MANAGER_ACTIONS::showPluginManager,
|
||||
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 ) );
|
||||
( KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_PCM )
|
||||
!= KIPLATFORM::POLICY::PBOOL::DISABLED ) );
|
||||
|
||||
m_frame->SetPcmButton( bb );
|
||||
|
||||
|
|
|
@ -917,7 +917,7 @@ void KICAD_MANAGER_FRAME::OnIdle( wxIdleEvent& aEvent )
|
|||
}
|
||||
}
|
||||
|
||||
if( KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_PCM ) != KIPLATFORM::POLICY::STATE::DISABLED
|
||||
if( KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_PCM ) != KIPLATFORM::POLICY::PBOOL::DISABLED
|
||||
&& settings->m_PcmUpdateCheck )
|
||||
{
|
||||
m_pcm->RunBackgroundUpdate();
|
||||
|
|
|
@ -177,8 +177,8 @@ void KICAD_MANAGER_FRAME::doReCreateMenuBar()
|
|||
|
||||
wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
|
||||
|
||||
if( KIPLATFORM::POLICY::GetPolicyState( POLICY_KEY_PCM )
|
||||
== KIPLATFORM::POLICY::STATE::DISABLED )
|
||||
if( KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_PCM )
|
||||
== KIPLATFORM::POLICY::PBOOL::DISABLED )
|
||||
{
|
||||
pcmMenuItem->Enable( false );
|
||||
}
|
||||
|
|
|
@ -883,8 +883,8 @@ 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 )
|
||||
if( KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_PCM )
|
||||
== KIPLATFORM::POLICY::PBOOL::DISABLED )
|
||||
{
|
||||
// policy disables the plugin manager
|
||||
return 0;
|
||||
|
|
|
@ -22,7 +22,14 @@
|
|||
|
||||
#include <wx/string.h>
|
||||
|
||||
KIPLATFORM::POLICY::STATE KIPLATFORM::POLICY::GetPolicyState( const wxString& aKey )
|
||||
|
||||
KIPLATFORM::POLICY::PBOOL KIPLATFORM::POLICY::GetPolicyBool( const wxString& aKey )
|
||||
{
|
||||
return STATE::NOT_CONFIGURED;
|
||||
return PBOOL::NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
|
||||
std::uint32_t KIPLATFORM::POLICY::GetPolicyEnumUInt( const wxString& aKey )
|
||||
{
|
||||
return 0;
|
||||
}
|
|
@ -22,20 +22,29 @@
|
|||
#ifndef KIPLATFORM_POLICY_H_
|
||||
#define KIPLATFORM_POLICY_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class wxString;
|
||||
|
||||
namespace KIPLATFORM
|
||||
{
|
||||
namespace POLICY
|
||||
{
|
||||
enum class STATE
|
||||
enum class PBOOL
|
||||
{
|
||||
ENABLED,
|
||||
DISABLED,
|
||||
NOT_CONFIGURED
|
||||
};
|
||||
|
||||
STATE GetPolicyState( const wxString& aKey );
|
||||
PBOOL GetPolicyBool( const wxString& aKey );
|
||||
std::uint32_t GetPolicyEnumUInt( const wxString& aKey );
|
||||
|
||||
template <typename T>
|
||||
T GetPolicyEnum( const wxString& aKey )
|
||||
{
|
||||
return static_cast<T>( GetPolicyEnumUInt( aKey ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,41 +21,91 @@
|
|||
#include <kiplatform/policy.h>
|
||||
|
||||
#include <wx/string.h>
|
||||
#include <wx/tokenzr.h>
|
||||
#include <wx/msw/registry.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#define POLICY_KEY_ROOT "Software\\Policies\\KiCad\\KiCad"
|
||||
|
||||
|
||||
KIPLATFORM::POLICY::STATE KIPLATFORM::POLICY::GetPolicyState( const wxString& aKey )
|
||||
static wxRegKey* GetPolicyRegKey( wxString& aKey )
|
||||
{
|
||||
wxString key = aKey;
|
||||
wxRegKey* keyToUse = nullptr;
|
||||
wxRegKey userKey( wxRegKey::HKCU, POLICY_KEY_ROOT );
|
||||
wxRegKey compKey( wxRegKey::HKLM, POLICY_KEY_ROOT );
|
||||
|
||||
wxString keyPath = POLICY_KEY_ROOT;
|
||||
|
||||
wxStringTokenizer tokenizer( aKey, "\\" );
|
||||
while( tokenizer.HasMoreTokens() )
|
||||
{
|
||||
wxString token = tokenizer.GetNextToken();
|
||||
|
||||
if( tokenizer.HasMoreTokens() )
|
||||
{
|
||||
keyPath.Append( "\\" );
|
||||
keyPath.Append( token );
|
||||
}
|
||||
else
|
||||
key = token;
|
||||
}
|
||||
|
||||
std::unique_ptr<wxRegKey> userKey = std::make_unique<wxRegKey>( wxRegKey::HKCU, keyPath );
|
||||
|
||||
// we have user level policies take precedence over computer level policies
|
||||
if( userKey.Exists() && userKey.HasValue( aKey ) )
|
||||
if( userKey->Exists() && userKey->HasValue( key ) )
|
||||
{
|
||||
keyToUse = &userKey;
|
||||
keyToUse = userKey.release();
|
||||
}
|
||||
else
|
||||
{
|
||||
if( compKey.Exists() && compKey.HasValue( aKey ) )
|
||||
std::unique_ptr<wxRegKey> compKey = std::make_unique<wxRegKey>( wxRegKey::HKLM, keyPath );
|
||||
|
||||
if( compKey->Exists() && compKey->HasValue( key ) )
|
||||
{
|
||||
keyToUse = &compKey;
|
||||
keyToUse = compKey.release();
|
||||
}
|
||||
}
|
||||
|
||||
aKey = key;
|
||||
return keyToUse;
|
||||
}
|
||||
|
||||
|
||||
KIPLATFORM::POLICY::PBOOL KIPLATFORM::POLICY::GetPolicyBool( const wxString& aKey )
|
||||
{
|
||||
wxString key = aKey;
|
||||
std::unique_ptr<wxRegKey> keyToUse( GetPolicyRegKey( key ) );
|
||||
|
||||
if( keyToUse != nullptr )
|
||||
{
|
||||
long value;
|
||||
if( keyToUse->QueryValue( aKey, &value ) )
|
||||
if( keyToUse->QueryValue( key, &value ) )
|
||||
{
|
||||
if( value == 1 )
|
||||
return POLICY::STATE::ENABLED;
|
||||
return POLICY::PBOOL::ENABLED;
|
||||
else
|
||||
return POLICY::STATE::DISABLED;
|
||||
return POLICY::PBOOL::DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
return STATE::NOT_CONFIGURED;
|
||||
return PBOOL::NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
|
||||
std::uint32_t KIPLATFORM::POLICY::GetPolicyEnumUInt( const wxString& aKey )
|
||||
{
|
||||
wxString key = aKey;
|
||||
std::unique_ptr<wxRegKey> keyToUse( GetPolicyRegKey( key ) );
|
||||
|
||||
if( keyToUse != nullptr )
|
||||
{
|
||||
long value;
|
||||
if( keyToUse->QueryValue( key, &value ) )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -22,7 +22,14 @@
|
|||
|
||||
#include <wx/string.h>
|
||||
|
||||
KIPLATFORM::POLICY::STATE KIPLATFORM::POLICY::GetPolicyState( const wxString& aKey )
|
||||
|
||||
KIPLATFORM::POLICY::PBOOL KIPLATFORM::POLICY::GetPolicyBool( const wxString& aKey )
|
||||
{
|
||||
return STATE::NOT_CONFIGURED;
|
||||
return PBOOL::NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
|
||||
std::uint32_t KIPLATFORM::POLICY::GetPolicyEnumUInt( const wxString& aKey )
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue