bzr branch
http://gegoxaren.bato24.eu/bzr/loggerouter/trunk
1
by Gustav Hartvigsson
* Inital release |
1 |
/*
|
2 |
This file is part of LoggerOuter.
|
|
3 |
||
4 |
LoggerOuter is free software: you can redistribute it and/or modify it under the
|
|
5 |
terms of the GNU Lesser General Public License as published by the Free Software
|
|
6 |
Foundation, either version 3 of the License, or (at your option) any later
|
|
7 |
version.
|
|
8 |
||
9 |
LoggerOuter is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
12 |
License for more details.
|
|
13 |
||
14 |
You should have received a copy of the GNU Lessel General Public License
|
|
15 |
along with LoggerOuter. If not, see <https://www.gnu.org/licenses/>.
|
|
16 |
*/
|
|
17 |
||
18 |
public struct LO.Settings { |
|
19 |
||
20 |
const string CONFIG_INI_NAMESPACE_MAIN = "Main"; |
|
21 |
||
22 |
string? config_path; |
|
23 |
GLib.KeyFile? key_file; |
|
24 |
||
25 |
private static GLib.Once<LO.Settings?> instance; |
|
26 |
||
27 |
public bool? dark_theme; |
|
28 |
||
29 |
public static unowned LO.Settings? get_instance () { |
|
30 |
return instance.once (() => { |
|
31 |
return LO.Settings (); |
|
32 |
}); |
|
33 |
} |
|
34 |
||
35 |
private Settings () {} |
|
36 |
||
37 |
public void load_settings (string config_path) { |
|
38 |
key_file = new GLib.KeyFile (); |
|
39 |
this.config_path = config_path; |
|
40 |
parse_key_file (); |
|
41 |
} |
|
42 |
||
43 |
public void load_setting_from_xdg () { |
|
44 |
key_file = new GLib.KeyFile (); |
|
45 |
this.config_path = LO_XDG_CONFIG_PATH; |
|
46 |
} |
|
47 |
||
48 |
private void parse_key_file () |
|
49 |
requires (key_file != null) { |
|
50 |
try { |
|
51 |
key_file.load_from_file (this.config_path, GLib.KeyFileFlags.NONE); |
|
52 |
} catch (GLib.FileError e) { |
|
53 |
string message = @"ERROR: $(e.message)\n"; |
|
54 |
stderr.printf (message); |
|
55 |
} catch (GLib.KeyFileError e) { |
|
56 |
string message = @"ERROR: $(e.message)\n"; |
|
57 |
stderr.printf (message); |
|
58 |
} |
|
59 |
||
60 |
try { |
|
61 |
if( key_file.has_key (CONFIG_INI_NAMESPACE_MAIN, "DarkTheme") ) { |
|
62 |
this.dark_theme = key_file.get_boolean (CONFIG_INI_NAMESPACE_MAIN, "DarkTheme"); |
|
63 |
} |
|
64 |
} catch (GLib.KeyFileError e) { |
|
65 |
string message = @"ERROR: $(e.message)\n"; |
|
66 |
stderr.printf (message); |
|
67 |
} |
|
68 |
} |
|
69 |
}
|