-
Notifications
You must be signed in to change notification settings - Fork 50
/
uiconfig.cpp
103 lines (90 loc) · 2.76 KB
/
uiconfig.cpp
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
96
97
98
99
100
101
102
103
// uiconfig.cpp
//
// Copyright (c) 2019-2024 Kristofer Berggren
// All rights reserved.
//
// nchat is distributed under the MIT license, see LICENSE for details.
#include "uiconfig.h"
#include <map>
#include "fileutil.h"
#include "strutil.h"
Config UiConfig::m_Config;
void UiConfig::Init()
{
const std::map<std::string, std::string> defaultConfig =
{
{ "attachment_indicator", "\xF0\x9F\x93\x8E" },
{ "attachment_open_command", "" },
{ "away_status_indication", "0" },
{ "call_command", "" },
{ "chat_picker_sorted_alphabetically", "0" },
{ "confirm_deletion", "1" },
{ "desktop_notify_active", "0" },
{ "desktop_notify_inactive", "0" },
{ "desktop_notify_command", "" },
{ "downloadable_indicator", "+" },
{ "emoji_enabled", "1" },
{ "entry_height", "4" },
{ "failed_indicator", "\xe2\x9c\x97" },
{ "file_picker_command", "" },
{ "file_picker_persist_dir", "1" },
{ "help_enabled", "1" },
{ "home_fetch_all", "0" },
{ "linefeed_on_enter", "1" },
{ "link_open_command", "" },
{ "list_enabled", "1" },
{ "list_width", "14" },
{ "listdialog_show_filter", "1" },
{ "mark_read_on_view", "1" },
{ "mark_read_when_inactive", "0" },
{ "message_edit_command", "" },
{ "message_open_command", "" },
{ "muted_indicate_unread", "1" },
{ "muted_notify_unread", "0" },
{ "muted_position_by_timestamp", "1" },
{ "online_status_share", "1" },
{ "online_status_dynamic", "1" },
{ "phone_number_indicator", "" },
{ "proxy_indicator", "\xF0\x9F\x94\x92" },
{ "read_indicator", "\xe2\x9c\x93" },
{ "reactions_enabled", "1" },
{ "spell_check_command", "" },
{ "status_broadcast", "1" },
{ "syncing_indicator", "\xe2\x87\x84" },
{ "terminal_bell_active", "0" },
{ "terminal_bell_inactive", "1" },
{ "terminal_title", "" },
{ "top_enabled", "1" },
{ "top_show_version", "0" },
{ "transfer_send_caption", "1" },
{ "typing_status_share", "1" },
};
const std::string configPath(FileUtil::GetApplicationDir() + std::string("/ui.conf"));
m_Config = Config(configPath, defaultConfig);
}
void UiConfig::Cleanup()
{
m_Config.Save();
}
bool UiConfig::GetBool(const std::string& p_Param)
{
return m_Config.Get(p_Param) == "1";
}
void UiConfig::SetBool(const std::string& p_Param, const bool& p_Value)
{
m_Config.Set(p_Param, p_Value ? "1" : "0");
}
std::string UiConfig::GetStr(const std::string& p_Param)
{
return m_Config.Get(p_Param);
}
int UiConfig::GetNum(const std::string& p_Param)
{
const std::string value = m_Config.Get(p_Param);
if (!StrUtil::IsInteger(value)) return 0;
return StrUtil::ToInteger(value);
}
void UiConfig::SetNum(const std::string& p_Param, const int& p_Value)
{
m_Config.Set(p_Param, std::to_string(p_Value));
}