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

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
...@@ -77,7 +77,7 @@ private: ...@@ -77,7 +77,7 @@ private:
wxString m_ConvertedFileName; wxString m_ConvertedFileName;
wxSize m_frameSize; wxSize m_frameSize;
wxPoint m_framePos; wxPoint m_framePos;
wxConfig* m_config; wxConfigBase* m_config;
public: public:
BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent ); BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent );
...@@ -147,7 +147,7 @@ BM2CMP_FRAME::BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent ) : ...@@ -147,7 +147,7 @@ BM2CMP_FRAME::BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
SetKiway( this, aKiway ); SetKiway( this, aKiway );
int tmp; 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_POSX, & m_framePos.x, -1 );
m_config->Read( KEYWORD_FRAME_POSY, & m_framePos.y, -1 ); m_config->Read( KEYWORD_FRAME_POSY, & m_framePos.y, -1 );
m_config->Read( KEYWORD_FRAME_SIZEX, & m_frameSize.x, -1 ); m_config->Read( KEYWORD_FRAME_SIZEX, & m_frameSize.x, -1 );
......
#include <wx/config.h>
#include <bin_mod.h> #include <bin_mod.h>
#include <online_help.h> #include <online_help.h>
#include <common.h>
BIN_MOD::BIN_MOD( const char* aName ) : BIN_MOD::BIN_MOD( const char* aName ) :
...@@ -15,7 +14,7 @@ BIN_MOD::BIN_MOD( const char* aName ) : ...@@ -15,7 +14,7 @@ BIN_MOD::BIN_MOD( const char* aName ) :
void BIN_MOD::Init() void BIN_MOD::Init()
{ {
// do an OS specific wxConfig instantiation, using the bin_mod (EXE/DLL/DSO) name. // 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 ); m_history.Load( *m_config );
......
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
#include <base_units.h> #include <base_units.h>
#include <wx/process.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 ) ...@@ -280,8 +283,8 @@ double RoundTo0( double x, double precision )
wxString FormatDateLong( const wxDateTime &aDate ) wxString FormatDateLong( const wxDateTime &aDate )
{ {
/* GetInfo was introduced only on wx 2.9; for portability reason an // GetInfo was introduced only on wx 2.9; for portability reason an
* hardcoded format is used on wx 2.8 */ // hardcoded format is used on wx 2.8
#if wxCHECK_VERSION( 2, 9, 0 ) #if wxCHECK_VERSION( 2, 9, 0 )
return aDate.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) ); return aDate.Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) );
#else #else
...@@ -289,3 +292,54 @@ wxString FormatDateLong( const wxDateTime &aDate ) ...@@ -289,3 +292,54 @@ wxString FormatDateLong( const wxDateTime &aDate )
#endif #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();
}
...@@ -733,14 +733,7 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName() ...@@ -733,14 +733,7 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()
{ {
wxFileName fn; wxFileName fn;
// This is possibly problematic with an uncertain wxApp title, which is now fn.SetPath( GetKicadConfigPath() );
// the case. We'll need a better technique soon.
fn.SetPath( wxStandardPaths::Get().GetUserConfigDir() );
#if defined( __WINDOWS__ )
fn.AppendDir( wxT( "kicad" ) );
#endif
fn.SetName( global_tbl_name ); fn.SetName( global_tbl_name );
return fn.GetFullPath(); return fn.GetFullPath();
......
...@@ -533,8 +533,9 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, ...@@ -533,8 +533,9 @@ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList,
} }
else else
{ {
wxConfig config( m_FrameName ); wxConfigBase* config = GetNewConfig( m_FrameName );
config.Write( HOTKEYS_CONFIG_KEY, msg ); config->Write( HOTKEYS_CONFIG_KEY, msg );
delete config;
} }
return 1; return 1;
...@@ -575,16 +576,17 @@ int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename, ...@@ -575,16 +576,17 @@ int EDA_BASE_FRAME::ReadHotkeyConfigFile( const wxString& aFilename,
void ReadHotkeyConfig( const wxString& Appname, struct EDA_HOTKEY_CONFIG* aDescList ) 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 // assume defaults are ok
return; return;
} }
wxString data; wxString data;
config.Read( HOTKEYS_CONFIG_KEY, &data ); config->Read( HOTKEYS_CONFIG_KEY, &data );
delete config;
ParseHotkeyConfig( data, aDescList ); ParseHotkeyConfig( data, aDescList );
} }
......
...@@ -405,7 +405,7 @@ bool PGM_BASE::initPgm() ...@@ -405,7 +405,7 @@ bool PGM_BASE::initPgm()
SetLanguagePath(); SetLanguagePath();
// OS specific instantiation of wxConfigBase derivative: // OS specific instantiation of wxConfigBase derivative:
m_common_settings = new wxConfig( KICAD_COMMON ); m_common_settings = GetNewConfig( KICAD_COMMON );
ReadPdfBrowserInfos(); // needs m_common_settings ReadPdfBrowserInfos(); // needs m_common_settings
......
...@@ -612,5 +612,27 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxStrin ...@@ -612,5 +612,27 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxStrin
/// Put aPriorityPath in front of all paths in the value of aEnvVar. /// Put aPriorityPath in front of all paths in the value of aEnvVar.
const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath ); const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath );
/**
* Function GetNewConfig
*
* Use this function instead of creating a new wxConfig so we can put config files in
* a more proper place for each platform. This is generally $HOME/.config/kicad/ in Linux
* according to the FreeDesktop specification at
* http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
* The config object created here should be destroyed by the caller.
*
* @param aProgName is the name of the program calling this function - can be obtained by
* calling Pgm().App().GetAppName(). This will be the actual file name of the config file.
* @return A pointer to a new wxConfigBase derived object is returned. The caller is in charge
* of deleting it.
*/
wxConfigBase* GetNewConfig( const wxString& aProgName );
/**
* Function GetKicadConfigPath
* @return A wxString containing the config path for Kicad
*/
wxString GetKicadConfigPath();
#endif // INCLUDE__COMMON_H_ #endif // INCLUDE__COMMON_H_
...@@ -28,7 +28,7 @@ private: ...@@ -28,7 +28,7 @@ private:
// must be rewritten // must be rewritten
wxSize m_FrameSize; wxSize m_FrameSize;
wxPoint m_FramePos; wxPoint m_FramePos;
wxConfig * m_Config; wxConfigBase* m_Config;
enum TRANSLINE_TYPE_ID m_currTransLineType; enum TRANSLINE_TYPE_ID m_currTransLineType;
TRANSLINE * m_currTransLine; // a pointer to the active transline TRANSLINE * m_currTransLine; // a pointer to the active transline
// List of translines: ordered like in dialog menu list // List of translines: ordered like in dialog menu list
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/config.h> #include <wx/config.h>
#include <pgm_base.h>
#include <pcb_calculator.h> #include <pcb_calculator.h>
#include <UnitSelector.h> #include <UnitSelector.h>
#include <bitmaps.h> #include <bitmaps.h>
...@@ -61,7 +62,7 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : ...@@ -61,7 +62,7 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_currTransLineType = DEFAULT_TYPE; m_currTransLineType = DEFAULT_TYPE;
m_currAttenuator = NULL; m_currAttenuator = NULL;
m_RegulatorListChanged = false; m_RegulatorListChanged = false;
m_Config = new wxConfig(); m_Config = GetNewConfig( Pgm().App().GetAppName() );
// Populate transline list ordered like in dialog menu list // Populate transline list ordered like in dialog menu list
const static TRANSLINE_TYPE_ID tltype_list[8] = const static TRANSLINE_TYPE_ID tltype_list[8] =
......
...@@ -256,7 +256,7 @@ static bool scriptingSetup() ...@@ -256,7 +256,7 @@ static bool scriptingSetup()
// (and remove the fixed paths from <src>/scripting/kicadplugins.i) // (and remove the fixed paths from <src>/scripting/kicadplugins.i)
// wizard plugins are stored in kicad/bin/plugins. // wizard plugins are stored in kicad/bin/plugins.
// so add this path to python scripting defualt search paths // so add this path to python scripting default search paths
// which are ( [KICAD_PATH] is an environment variable to define) // which are ( [KICAD_PATH] is an environment variable to define)
// [KICAD_PATH]/scripting/plugins // [KICAD_PATH]/scripting/plugins
// Add this default search path: // Add this default search path:
...@@ -336,11 +336,11 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) ...@@ -336,11 +336,11 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
"You have run Pcbnew for the first time using the " "You have run Pcbnew for the first time using the "
"new footprint library table method for finding " "new footprint library table method for finding "
"footprints. Pcbnew has either copied the default " "footprints. Pcbnew has either copied the default "
"table or created an empty table in your home " "table or created an empty table in the kicad configuration "
"folder. You must first configure the library " "folder. You must first configure the library "
"table to include all footprint libraries not " "table to include all footprint libraries not "
"included with KiCad. See the \"Footprint Library " "included with KiCad. See the \"Footprint Library "
"Table\" section of the CvPcb documentation for " "Table\" section of the CvPcb or Pcbnew documentation for "
"more information." ) ); "more information." ) );
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment