KiCad PCB EDA Suite
bin_mod.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014 CERN
5  * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <bin_mod.h>
26 #include <common.h>
27 #include <pgm_base.h>
28 
29 
30 BIN_MOD::BIN_MOD( const char* aName ) :
31  m_name( aName ),
32  m_config( 0 ),
33  m_history( 0 )
34 {
35 }
36 
37 
39 {
40  // do an OS specific wxConfig instantiation, using the bin_mod (EXE/DLL/DSO) name.
41  m_config = GetNewConfig( wxString::FromUTF8( m_name ) );
42 
43  // wxWidgets' implementation of this is *very* expensive, and we don't use them anyway.
44  m_config->SetExpandEnvVars( false );
45 
46  // get file history size from common settings
47  int fileHistorySize;
48  Pgm().CommonSettings()->Read( FILE_HISTORY_SIZE_KEY, &fileHistorySize, DEFAULT_FILE_HISTORY_SIZE );
49 
50  m_history = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ), ID_FILE1 );
51  m_history->Load( *m_config );
52 
53  // Prepare On Line Help. Use only lower case for help file names, in order to
54  // avoid problems with upper/lower case file names under windows and unix.
55  // Help files are now using html format.
56  // Old help files used pdf format.
57  // so when searching a help file, the .html file will be searched,
58  // and if not found, the .pdf file will be searched.
59  m_help_file = wxString::FromUTF8( m_name ); // no ext given. can be .html or .pdf
60 }
61 
62 
64 {
65  if( m_config )
66  {
67  m_history->Save( *m_config );
68 
69  delete m_history;
70 
71  // Deleting a wxConfigBase writes its contents to disk if changed.
72  // Might be NULL if called twice, in which case nothing happens.
73  delete m_config;
74  m_config = 0;
75  }
76 }
77 
78 
80 {
81  End();
82 }
83 
void Init()
Definition: bin_mod.cpp:38
wxConfigBase * GetNewConfig(const wxString &aProgName)
Create a new wxConfig so we can put configuration files in a more proper place for each platform...
Definition: common.cpp:251
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
#define DEFAULT_FILE_HISTORY_SIZE
The default file history size is 9.
Definition: pgm_base.h:58
#define FILE_HISTORY_SIZE_KEY
Definition: pgm_base.h:51
~BIN_MOD()
Definition: bin_mod.cpp:79
FILE_HISTORY * m_history
Definition: bin_mod.h:59
wxString m_help_file
Definition: bin_mod.h:60
see class PGM_BASE
#define max(a, b)
Definition: auxiliary.h:86
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
The common library.
BIN_MOD(const char *aName)
Definition: bin_mod.cpp:30
wxConfigBase * m_config
maybe from $HOME/.${m_name}
Definition: bin_mod.h:58
const char * m_name
name of this binary module, static C string.
Definition: bin_mod.h:56
void End()
Definition: bin_mod.cpp:63