← Back to team overview

kicad-developers team mailing list archive

Config file relocation

 

Hi,

I would like to move the kicad config files in linux to a more "proper" location as defined by the FreeDesktop specification here:
http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html

Specifically this would put the files in $HOME/.config/kicad.

At first I thought I could just change bin_mod.cpp, but figured out that there were three other places that would need changing as well to catch everything. So I made a new function in common.h/.cpp called GetNewConfig(...) and changed the four other files to call that instead of creating a wxConfig() object.

I've attached a patch against BZR rev 5106 which works on linux as far as I've tested it, and *should* still work as before for windows etc.

It will surprise me very little if this patch has problems or causes other issues I haven't thought of, but it should at least be a starting point for further discussion. For starters, common.h/.cpp may not be the best place for such a function - I don't know.

Thanks,
Moses
=== modified file 'bitmap2component/bitmap2cmp_gui.cpp'
--- bitmap2component/bitmap2cmp_gui.cpp	2014-08-22 10:24:14 +0000
+++ bitmap2component/bitmap2cmp_gui.cpp	2014-08-31 00:15:30 +0000
@@ -77,7 +77,7 @@
     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 @@
     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 );

=== modified file 'common/bin_mod.cpp'
--- common/bin_mod.cpp	2014-04-02 13:38:59 +0000
+++ common/bin_mod.cpp	2014-08-31 00:08:50 +0000
@@ -1,8 +1,9 @@
 
 
-#include <wx/config.h>
+//#include <wx/config.h>
 #include <bin_mod.h>
 #include <online_help.h>
+#include <common.h>
 
 
 BIN_MOD::BIN_MOD( const char* aName ) :
@@ -15,7 +16,7 @@
 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 );
 

=== modified file 'common/common.cpp'
--- common/common.cpp	2014-08-05 09:39:42 +0000
+++ common/common.cpp	2014-08-31 00:50:40 +0000
@@ -39,6 +39,8 @@
 #include <base_units.h>
 
 #include <wx/process.h>
+#include <wx/config.h>
+#include <wx/utils.h>
 
 
 /**
@@ -289,3 +291,35 @@
 #endif
 }
 
+wxConfigBase* GetNewConfig( const wxString& aProgName )
+{
+    wxConfigBase* cfg = 0;
+    // under Windows we prefer to use the native implementation but can be forced
+    // to use the file-based one
+#if (defined(__WINDOWS__) || defined(__WXOS2__)) && wxUSE_CONFIG_NATIVE
+    cfg = new wxConfig( aProgName );
+#else // either we're under Unix or wish to always use config files
+    wxFileName configname;
+    wxString envstr;
+    bool env_good = wxGetEnv( "XDG_CONFIG_HOME", &envstr );
+    if ( (false == env_good) || envstr.IsEmpty() )
+    {
+        configname.AssignDir( wxFileName::GetHomeDir() );
+        configname.AppendDir( wxT( ".config" ) );
+    }
+    else
+    {
+        configname.AssignDir( envstr );
+        //wxPrintf("%s", envstr);
+    }
+    configname.AppendDir( wxT( "kicad" ) );
+    configname.SetFullName( aProgName );
+    if ( !configname.DirExists() )
+    {
+        configname.Mkdir( configname.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
+    }
+    cfg = new wxFileConfig( wxT(""), wxT(""), configname.GetFullPath() );
+#endif
+    return cfg;
+}
+

=== modified file 'common/pgm_base.cpp'
--- common/pgm_base.cpp	2014-08-26 10:54:22 +0000
+++ common/pgm_base.cpp	2014-08-31 00:09:18 +0000
@@ -416,7 +416,8 @@
     SetLanguagePath();
 
     // OS specific instantiation of wxConfigBase derivative:
-    m_common_settings = new wxConfig( KICAD_COMMON );
+    //m_common_settings = new wxConfig( KICAD_COMMON );
+    m_common_settings = GetNewConfig( KICAD_COMMON );
 
     ReadPdfBrowserInfos();      // needs m_common_settings
 

=== modified file 'include/common.h'
--- include/common.h	2014-06-20 11:13:04 +0000
+++ include/common.h	2014-08-30 23:51:39 +0000
@@ -609,5 +609,13 @@
 /// Put aPriorityPath in front of all paths in the value of aEnvVar.
 const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPath );
 
+/**
+ * Use this function instead of creating a new wxConfig so we can put config files in
+ * the proper place (/$HOME/.config/kicad/) according to the FreeDesktop specification
+ * at http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
+ * The config object created here should be detroyed by the caller.
+ */
+wxConfigBase* GetNewConfig( const wxString& aProgName );
+
 
 #endif  // INCLUDE__COMMON_H_

=== modified file 'pcb_calculator/pcb_calculator.h'
--- pcb_calculator/pcb_calculator.h	2014-04-02 13:38:59 +0000
+++ pcb_calculator/pcb_calculator.h	2014-08-31 00:16:47 +0000
@@ -28,7 +28,7 @@
                                         // must be rewritten
     wxSize m_FrameSize;
     wxPoint m_FramePos;
-    wxConfig * m_Config;
+    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

=== modified file 'pcb_calculator/pcb_calculator_frame.cpp'
--- pcb_calculator/pcb_calculator_frame.cpp	2014-05-18 15:16:59 +0000
+++ pcb_calculator/pcb_calculator_frame.cpp	2014-08-31 00:15:20 +0000
@@ -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 @@
     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] =


Follow ups