-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathconfig.cpp
More file actions
95 lines (81 loc) · 3.73 KB
/
config.cpp
File metadata and controls
95 lines (81 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
gebaar
Copyright (C) 2019 coffee2code
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <zconf.h>
#include "config.h"
/**
* Check if config file exists at current path
*/
bool gebaar::config::Config::config_file_exists()
{
auto true_path = std::filesystem::path(config_file_path);
return std::filesystem::exists(true_path);
}
/**
* Load Configuration from TOML file
*/
void gebaar::config::Config::load_config()
{
if (find_config_file()) {
if (config_file_exists()) {
config = cpptoml::parse_file(std::filesystem::path(config_file_path));
swipe_three_commands[1] = *config->get_qualified_as<std::string>("commands.swipe.three.left_up");
swipe_three_commands[2] = *config->get_qualified_as<std::string>("commands.swipe.three.up");
swipe_three_commands[3] = *config->get_qualified_as<std::string>("commands.swipe.three.right_up");
swipe_three_commands[4] = *config->get_qualified_as<std::string>("commands.swipe.three.left");
swipe_three_commands[6] = *config->get_qualified_as<std::string>("commands.swipe.three.right");
swipe_three_commands[7] = *config->get_qualified_as<std::string>("commands.swipe.three.left_down");
swipe_three_commands[8] = *config->get_qualified_as<std::string>("commands.swipe.three.down");
swipe_three_commands[9] = *config->get_qualified_as<std::string>("commands.swipe.three.right_down");
swipe_four_commands[1] = *config->get_qualified_as<std::string>("commands.swipe.four.left_up");
swipe_four_commands[2] = *config->get_qualified_as<std::string>("commands.swipe.four.up");
swipe_four_commands[3] = *config->get_qualified_as<std::string>("commands.swipe.four.right_up");
swipe_four_commands[4] = *config->get_qualified_as<std::string>("commands.swipe.four.left");
swipe_four_commands[6] = *config->get_qualified_as<std::string>("commands.swipe.four.right");
swipe_four_commands[7] = *config->get_qualified_as<std::string>("commands.swipe.four.left_down");
swipe_four_commands[8] = *config->get_qualified_as<std::string>("commands.swipe.four.down");
swipe_four_commands[9] = *config->get_qualified_as<std::string>("commands.swipe.four.right_down");
pinch_in_command = *config->get_qualified_as<std::string>("commands.pinch.in");
pinch_out_command = *config->get_qualified_as<std::string>("commands.pinch.out");
loaded = true;
}
}
}
/**
* Find the configuration file according to XDG spec
* @return bool
*/
bool gebaar::config::Config::find_config_file()
{
const char* temp_path;
temp_path = getenv("XDG_CONFIG_HOME");
if (temp_path==nullptr) {
temp_path = getenv("HOME");
if (temp_path==nullptr) {
temp_path = getpwuid(getuid())->pw_dir;
}
}
if (temp_path!=nullptr) {
config_file_path = temp_path;
config_file_path.append("/.config/gebaar/gebaard.toml");
return true;
}
return false;
}
gebaar::config::Config::Config()
{
if (!loaded) {
load_config();
}
}