Commit 6da5e2cd authored by Moses McKnight's avatar Moses McKnight Committed by Wayne Stambaugh
Browse files

Configuration file consolidation patch from Moses McKnight.

* Create GetNewConfig() and GetKicadConfigPath() to unify configuration file
  creation and location.
* Move Windows configuration out of the registry into configuration files.
* Move Linux configuration files from $HOME to $HOME/.config/kicad to eliminate
  configuration file pollution in the users $HOME folder.
* Fix a bug in the configuration file where the Eeschema hot keys are saved.
parent 5c954998
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ private:
    wxString        m_ConvertedFileName;
    wxSize          m_frameSize;
    wxPoint         m_framePos;
    wxConfig*   m_config;
    wxConfigBase*   m_config;

public:
    BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent );
@@ -147,7 +147,7 @@ BM2CMP_FRAME::BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
    SetKiway( this, aKiway );

    int tmp;
    m_config = new wxConfig();
    m_config = GetNewConfig( Pgm().App().GetAppName() );
    m_config->Read( KEYWORD_FRAME_POSX, & m_framePos.x, -1 );
    m_config->Read( KEYWORD_FRAME_POSY, & m_framePos.y, -1 );
    m_config->Read( KEYWORD_FRAME_SIZEX, & m_frameSize.x, -1 );
+2 −3
Original line number Diff line number Diff line


#include <wx/config.h>
#include <bin_mod.h>
#include <online_help.h>
#include <common.h>


BIN_MOD::BIN_MOD( const char* aName ) :
@@ -15,7 +14,7 @@ BIN_MOD::BIN_MOD( const char* aName ) :
void BIN_MOD::Init()
{
    // do an OS specific wxConfig instantiation, using the bin_mod (EXE/DLL/DSO) name.
    m_config = new wxConfig( wxString::FromUTF8( m_name ) );
    m_config = GetNewConfig( wxString::FromUTF8( m_name ) );

    m_history.Load( *m_config );

+56 −2
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@
#include <base_units.h>

#include <wx/process.h>
#include <wx/config.h>
#include <wx/utils.h>
#include <wx/stdpaths.h>


/**
@@ -280,8 +283,8 @@ double RoundTo0( double x, double precision )

wxString FormatDateLong( const wxDateTime &aDate )
{
    /* GetInfo was introduced only on wx 2.9; for portability reason an
     * hardcoded format is used on wx 2.8 */
    // GetInfo was introduced only on wx 2.9; for portability reason an
    // hardcoded format is used on wx 2.8
#if wxCHECK_VERSION( 2, 9, 0 )
    return aDate.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
#else
@@ -289,3 +292,54 @@ wxString FormatDateLong( const wxDateTime &aDate )
#endif
}


wxConfigBase* GetNewConfig( const wxString& aProgName )
{
    wxConfigBase* cfg = 0;
    wxFileName configname;
    configname.AssignDir( GetKicadConfigPath() );
    configname.SetFullName( aProgName );

    cfg = new wxFileConfig( wxT( "" ), wxT( "" ), configname.GetFullPath() );
    return cfg;
}


wxString GetKicadConfigPath()
{
    wxFileName cfgpath;

    // From the wxWidgets wxStandardPaths::GetUserConfigDir() help:
    //      Unix: ~ (the home directory)
    //      Windows: "C:\Documents and Settings\username\Application Data"
    //      Mac: ~/Library/Preferences
    cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );

#if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
    wxString envstr;

    if( !wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) || envstr.IsEmpty() )
    {
        // XDG_CONFIG_HOME is not set, so use the fallback
        cfgpath.AppendDir( wxT( ".config" ) );
    }
    else
    {
        // Override the assignment above with XDG_CONFIG_HOME
        cfgpath.AssignDir( envstr );
    }
#endif

    cfgpath.AppendDir( wxT( "kicad" ) );

#if !wxCHECK_VERSION( 2, 9, 0 )
    #define wxS_DIR_DEFAULT  0777
#endif

    if( !cfgpath.DirExists() )
    {
        cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
    }

    return cfgpath.GetPath();
}
+1 −8
Original line number Diff line number Diff line
@@ -733,14 +733,7 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()
{
    wxFileName fn;

    // This is possibly problematic with an uncertain wxApp title, which is now
    // the case.  We'll need a better technique soon.
    fn.SetPath( wxStandardPaths::Get().GetUserConfigDir() );

#if defined( __WINDOWS__ )
    fn.AppendDir( wxT( "kicad" ) );
#endif

    fn.SetPath( GetKicadConfigPath() );
    fn.SetName( global_tbl_name );

    return fn.GetFullPath();
+7 −5
Original line number Diff line number Diff line
@@ -533,8 +533,9 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList,
    }
    else
    {
        wxConfig config( m_FrameName );
        config.Write( HOTKEYS_CONFIG_KEY, msg );
        wxConfigBase* config = GetNewConfig( m_FrameName );
        config->Write( HOTKEYS_CONFIG_KEY, msg );
        delete config;
    }

    return 1;
@@ -575,16 +576,17 @@ int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename,

void ReadHotkeyConfig( const wxString& Appname, struct EDA_HOTKEY_CONFIG* aDescList )
{
    wxConfig config( Appname );
    wxConfigBase* config = GetNewConfig( Appname );

    if( !config.HasEntry( HOTKEYS_CONFIG_KEY ) )
    if( !config->HasEntry( HOTKEYS_CONFIG_KEY ) )
    {
        // assume defaults are ok
        return;
    }

    wxString data;
    config.Read( HOTKEYS_CONFIG_KEY, &data );
    config->Read( HOTKEYS_CONFIG_KEY, &data );
    delete config;

    ParseHotkeyConfig( data, aDescList );
}
Loading