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
......@@ -65,19 +65,19 @@ extern int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile,
class BM2CMP_FRAME : public BM2CMP_FRAME_BASE
{
private:
wxImage m_Pict_Image;
wxBitmap m_Pict_Bitmap;
wxImage m_Greyscale_Image;
wxBitmap m_Greyscale_Bitmap;
wxImage m_NB_Image;
wxBitmap m_BN_Bitmap;
wxSize m_imageDPI; // The initial image resolution. When unknown,
wxImage m_Pict_Image;
wxBitmap m_Pict_Bitmap;
wxImage m_Greyscale_Image;
wxBitmap m_Greyscale_Bitmap;
wxImage m_NB_Image;
wxBitmap m_BN_Bitmap;
wxSize m_imageDPI; // The initial image resolution. When unknown,
// set to DEFAULT_DPI x DEFAULT_DPI per Inch
wxString m_BitmapFileName;
wxString m_ConvertedFileName;
wxSize m_frameSize;
wxPoint m_framePos;
wxConfig* m_config;
wxString m_BitmapFileName;
wxString m_ConvertedFileName;
wxSize m_frameSize;
wxPoint m_framePos;
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 );
......
#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 );
......
......@@ -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();
}
......@@ -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();
......
......@@ -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 );
}
......
......@@ -405,7 +405,7 @@ bool PGM_BASE::initPgm()
SetLanguagePath();
// OS specific instantiation of wxConfigBase derivative:
m_common_settings = new wxConfig( KICAD_COMMON );
m_common_settings = GetNewConfig( KICAD_COMMON );
ReadPdfBrowserInfos(); // needs m_common_settings
......
......@@ -612,5 +612,27 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxStrin
/// Put aPriorityPath in front of all paths in the value of aEnvVar.
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_
......@@ -26,9 +26,9 @@ private:
bool m_RegulatorListChanged; // set to true when m_RegulatorList
// was modified, and the corresponging file
// must be rewritten
wxSize m_FrameSize;
wxPoint m_FramePos;
wxConfig * m_Config;
wxSize m_FrameSize;
wxPoint m_FramePos;
wxConfigBase* m_Config;
enum TRANSLINE_TYPE_ID m_currTransLineType;
TRANSLINE * m_currTransLine; // a pointer to the active transline
// List of translines: ordered like in dialog menu list
......
......@@ -24,6 +24,7 @@
#include <wx/wx.h>
#include <wx/config.h>
#include <pgm_base.h>
#include <pcb_calculator.h>
#include <UnitSelector.h>
#include <bitmaps.h>
......@@ -61,7 +62,7 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_currTransLineType = DEFAULT_TYPE;
m_currAttenuator = NULL;
m_RegulatorListChanged = false;
m_Config = new wxConfig();
m_Config = GetNewConfig( Pgm().App().GetAppName() );
// Populate transline list ordered like in dialog menu list
const static TRANSLINE_TYPE_ID tltype_list[8] =
......
......@@ -256,7 +256,7 @@ static bool scriptingSetup()
// (and remove the fixed paths from <src>/scripting/kicadplugins.i)
// 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)
// [KICAD_PATH]/scripting/plugins
// Add this default search path:
......@@ -336,11 +336,11 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
"You have run Pcbnew for the first time using the "
"new footprint library table method for finding "
"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 "
"table to include all footprint libraries not "
"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." ) );
}
}
......
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