1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2
3 #include "smconfig.hh"
4 #include "smmicroconf.hh"
5
6 using namespace SpectMorph;
7
8 using std::string;
9 using std::vector;
10
11 string
get_config_filename()12 Config::get_config_filename()
13 {
14 return sm_get_user_dir (USER_DIR_DATA) + "/config";
15 }
16
Config()17 Config::Config()
18 {
19 MicroConf cfg_parser (get_config_filename());
20
21 if (!cfg_parser.open_ok())
22 return;
23
24 while (cfg_parser.next())
25 {
26 int i;
27 std::string s;
28
29 if (cfg_parser.command ("zoom", i))
30 {
31 m_zoom = i;
32 }
33 else if (cfg_parser.command ("debug", s))
34 {
35 m_debug.push_back (s);
36 }
37 else if (cfg_parser.command ("font", s))
38 {
39 m_font = s;
40 }
41 else if (cfg_parser.command ("font_bold", s))
42 {
43 m_font_bold = s;
44 }
45 else
46 {
47 //cfg.die_if_unknown();
48 }
49 }
50 }
51
52 int
zoom() const53 Config::zoom() const
54 {
55 return m_zoom;
56 }
57
58 void
set_zoom(int z)59 Config::set_zoom (int z)
60 {
61 m_zoom = z;
62 }
63
64 vector<string>
debug()65 Config::debug()
66 {
67 return m_debug;
68 }
69
70 string
font() const71 Config::font() const
72 {
73 return m_font;
74 }
75
76 string
font_bold() const77 Config::font_bold() const
78 {
79 return m_font_bold;
80 }
81
82 void
store()83 Config::store()
84 {
85 FILE *file = fopen (get_config_filename().c_str(), "w");
86
87 if (!file)
88 return;
89
90 fprintf (file, "# this file is automatically updated by SpectMorph\n");
91 fprintf (file, "# it can be manually edited, however, if you do that, be careful\n");
92 fprintf (file, "zoom %d\n", m_zoom);
93
94 for (auto area : m_debug)
95 fprintf (file, "debug %s\n", area.c_str());
96
97 if (m_font != "")
98 fprintf (file, "font \"%s\"", m_font.c_str());
99
100 if (m_font_bold != "")
101 fprintf (file, "font_bold \"%s\"", m_font_bold.c_str());
102
103 fclose (file);
104 }
105