aboutsummaryrefslogtreecommitdiff
path: root/src/settings.h.in
blob: 88fbcf5968f0e2fe266136065565fe2ed55af328 (plain)
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
#pragma once

#include <QStandardPaths>
#include <configuration.h>
#include <fstream>

inline const std::string init_conf(const std::string &path)
{
    auto value_map = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({
        @__DEFAULT_CFG__
    });

    const std::string cfgpath = [&]() {
        if(path.empty())
            return value_map->value<std::string>("poi.cfg.path").value();

        auto p = path;
        if(p.front() == '~')
            p.replace(0, 1, QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString());
        return p;
    }();

    std::fstream fs;
    fs.open(cfgpath, std::fstream::in);
    if(fs.is_open()) {
        value_map->read(fs);
        fs.close();
    }

    Configuration::move_global(std::move(value_map));
    return cfgpath;
}