← Back to team overview

kicad-developers team mailing list archive

Re: Config file relocation (patch 5)

 

Interesting! I don't have a .SchematicFrame file and haven't seen one, but looking at the code I see that eeschema tries to read hotkey configs from that file: ReadHotkeyConfig( wxT("SchematicFrame"), s_Eeschema_Hokeys_Descr );

Anyhow, the culprit is in a couple places in hotkeys_basic.cpp where it uses wxConfig instead of the new function GetNewConfig()

I fixed that now, and did a grep for other uses of wxConfig and could not find any more. So I think I've caught all of those now.

I also changed the message about the fp-lib-table in the home folder to "...in the kicad config folder..."

As for the "\n" separators, that is part of the hotkey setting format itself, and is the way it should be.

Moses

On 09/04/2014 12:45 AM, yann jautard wrote:
I just tested your patch on Ubuntu, works fine.

But I noticed one file is still stored on home dir : the hotkey config file
~/.SchematicFrame

I think it should be relocated too.

Regarding this file, I think there is a formatting error in it : it is composed
of one single line with plain text "\n" as item separators. I guess that these
should be real carriage return instead of writing them down.

I can propose a patch to correct this if needed.



Le 03/09/2014 22:40, Moses McKnight a écrit :
Ok, the previous patch actually put the files in
~/Library/Preferences/.config/kicad on OSX, so I added a check for __WXMAC__
so it does not add the .config directory on OSX. I also did a little cleanup
on the patch - mainly removed the check for OS/2 which I'm pretty sure is not
needed for kicad!

nullset on IRC who did some testing did say he thinks the
~/Library/Preferences/kicad location is fine for the config files.

Moses
=== modified file 'bitmap2component/bitmap2cmp_gui.cpp'
--- bitmap2component/bitmap2cmp_gui.cpp	2014-08-22 10:24:14 +0000
+++ bitmap2component/bitmap2cmp_gui.cpp	2014-09-03 21:06:12 +0000
@@ -65,19 +65,19 @@
 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 @@
     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-09-02 16:44:53 +0000
+++ common/bin_mod.cpp	2014-09-03 02:49:20 +0000
@@ -1,8 +1,7 @@
 
-
-#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 @@
 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-09-03 22:13:41 +0000
@@ -39,6 +39,9 @@
 #include <base_units.h>
 
 #include <wx/process.h>
+#include <wx/config.h>
+#include <wx/utils.h>
+#include <wx/stdpaths.h>
 
 
 /**
@@ -289,3 +292,29 @@
 #endif
 }
 
+wxConfigBase* GetNewConfig( const wxString& aProgName )
+{
+    wxConfigBase*   cfg = 0;
+    wxFileName      configname;
+    wxString        envstr;
+
+    // From the wxWidgets wxStandardPaths::GetUserConfigDir() help:
+    //      Unix: ~ (the home directory)
+    //      Windows: "C:\Documents and Settings\username\Application Data"
+    //      Mac: ~/Library/Preferences
+    configname.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
+    
+#if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
+    configname.AppendDir( wxT( ".config" ) );
+#endif
+
+    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() );
+    return cfg;
+}
+

=== modified file 'common/fp_lib_table.cpp'
--- common/fp_lib_table.cpp	2014-05-18 15:16:59 +0000
+++ common/fp_lib_table.cpp	2014-09-03 22:13:57 +0000
@@ -733,13 +733,16 @@
 {
     wxFileName fn;
 
-    // This is possibly problematic with an uncertain wxApp title, which is now
-    // the case.  We'll need a better technique soon.
+    // From the wxWidgets wxStandardPaths::GetUserConfigDir() help:
+    //      Unix: ~ (the home directory)
+    //      Windows: "C:\Documents and Settings\username\Application Data"
+    //      Mac: ~/Library/Preferences
     fn.SetPath( wxStandardPaths::Get().GetUserConfigDir() );
 
-#if defined( __WINDOWS__ )
+#if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
+    fn.AppendDir( wxT( ".config" ) );
+#endif
     fn.AppendDir( wxT( "kicad" ) );
-#endif
 
     fn.SetName( global_tbl_name );
 

=== modified file 'common/hotkeys_basic.cpp'
--- common/hotkeys_basic.cpp	2014-08-13 20:28:54 +0000
+++ common/hotkeys_basic.cpp	2014-09-04 13:11:02 +0000
@@ -533,8 +533,9 @@
     }
     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 @@
 
 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 );
 }

=== modified file 'common/pgm_base.cpp'
--- common/pgm_base.cpp	2014-09-02 16:44:53 +0000
+++ common/pgm_base.cpp	2014-09-03 02:48:32 +0000
@@ -405,7 +405,7 @@
     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
 

=== modified file 'include/common.h'
--- include/common.h	2014-09-02 16:44:53 +0000
+++ include/common.h	2014-09-02 19:43:42 +0000
@@ -612,5 +612,17 @@
 /// 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.
+ * @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 );
+
 
 #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-09-03 02:54:22 +0000
@@ -26,9 +26,9 @@
     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

=== 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] =

=== modified file 'pcbnew/pcbnew.cpp'
--- pcbnew/pcbnew.cpp	2014-08-24 07:05:07 +0000
+++ pcbnew/pcbnew.cpp	2014-09-04 13:39:18 +0000
@@ -336,7 +336,7 @@
                 "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 config "
                 "folder.  You must first configure the library "
                 "table to include all footprint libraries not "
                 "included with KiCad.  See the \"Footprint Library "


Follow ups

References