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_history( 0 )
33 {
34 }
35 
36 
38 {
39  // do an OS specific wxConfig instantiation, using the bin_mod (EXE/DLL/DSO) name.
40  m_config = GetNewConfig( wxString::FromUTF8( m_name ) );
41 
42  // wxWidgets' implementation of this is *very* expensive, and we don't use them anyway.
43  m_config->SetExpandEnvVars( false );
44 
45  // get file history size from common settings
46  int fileHistorySize;
47  Pgm().CommonSettings()->Read( FILE_HISTORY_SIZE_KEY, &fileHistorySize, DEFAULT_FILE_HISTORY_SIZE );
48 
49  m_history = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ), ID_FILE1 );
50  m_history->Load( *m_config.get() );
51 
52  // Prepare On Line Help. Use only lower case for help file names, in order to
53  // avoid problems with upper/lower case file names under windows and unix.
54  // Help files are now using html format.
55  // Old help files used pdf format.
56  // so when searching a help file, the .html file will be searched,
57  // and if not found, the .pdf file will be searched.
58  m_help_file = wxString::FromUTF8( m_name ); // no ext given. can be .html or .pdf
59 }
60 
61 
63 {
64  if( m_config )
65  {
66  m_history->Save( *m_config.get() );
67  delete m_history;
68 
69  // Deleting a wxConfigBase writes its contents to disk if changed.
70  m_config.reset();
71  }
72 }
73 
74 
76 {
77  End();
78 }
79 
void Init()
Definition: bin_mod.cpp:37
std::unique_ptr< 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:255
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:60
#define FILE_HISTORY_SIZE_KEY
Definition: pgm_base.h:52
~BIN_MOD()
Definition: bin_mod.cpp:75
FILE_HISTORY * m_history
Definition: bin_mod.h:60
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:189
wxString m_help_file
Definition: bin_mod.h:61
see class PGM_BASE
#define max(a, b)
Definition: auxiliary.h:86
The common library.
BIN_MOD(const char *aName)
Definition: bin_mod.cpp:30
const char * m_name
name of this binary module, static C string.
Definition: bin_mod.h:57
std::unique_ptr< wxConfigBase > m_config
maybe from $HOME/.${m_name}
Definition: bin_mod.h:59
void End()
Definition: bin_mod.cpp:62