1 # -*- coding: utf-8 -*-
3 # config.py - configuration for QWeeChat
5 # Copyright (C) 2011-2021 Sébastien Helleu <flashcode@flashtux.org>
7 # This file is part of QWeeChat, a Qt remote GUI for WeeChat.
9 # QWeeChat is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # QWeeChat is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
23 """Configuration for QWeeChat."""
28 from pathlib
import Path
30 CONFIG_DIR
= '%s/.config/qweechat' % os
.getenv('HOME')
31 CONFIG_FILENAME
= '%s/qweechat.conf' % CONFIG_DIR
33 CONFIG_DEFAULT_RELAY_LINES
= 50
35 CONFIG_DEFAULT_SECTIONS
= ('relay', 'look', 'color')
36 CONFIG_DEFAULT_OPTIONS
= (('relay.server', ''),
39 ('relay.password', ''),
40 ('relay.autoconnect', 'off'),
41 ('relay.lines', str(CONFIG_DEFAULT_RELAY_LINES
)),
42 ('look.debug', 'off'),
43 ('look.statusbar', 'off'))
45 # Default colors for WeeChat color options (option name, #rgb value)
46 CONFIG_DEFAULT_COLOR_OPTIONS
= (
47 ('separator', '#000066'), # 0
48 ('chat', '#000000'), # 1
49 ('chat_time', '#999999'), # 2
50 ('chat_time_delimiters', '#000000'), # 3
51 ('chat_prefix_error', '#FF6633'), # 4
52 ('chat_prefix_network', '#990099'), # 5
53 ('chat_prefix_action', '#000000'), # 6
54 ('chat_prefix_join', '#00CC00'), # 7
55 ('chat_prefix_quit', '#CC0000'), # 8
56 ('chat_prefix_more', '#CC00FF'), # 9
57 ('chat_prefix_suffix', '#330099'), # 10
58 ('chat_buffer', '#000000'), # 11
59 ('chat_server', '#000000'), # 12
60 ('chat_channel', '#000000'), # 13
61 ('chat_nick', '#000000'), # 14
62 ('chat_nick_self', '*#000000'), # 15
63 ('chat_nick_other', '#000000'), # 16
64 ('', '#000000'), # 17 (nick1 -- obsolete)
65 ('', '#000000'), # 18 (nick2 -- obsolete)
66 ('', '#000000'), # 19 (nick3 -- obsolete)
67 ('', '#000000'), # 20 (nick4 -- obsolete)
68 ('', '#000000'), # 21 (nick5 -- obsolete)
69 ('', '#000000'), # 22 (nick6 -- obsolete)
70 ('', '#000000'), # 23 (nick7 -- obsolete)
71 ('', '#000000'), # 24 (nick8 -- obsolete)
72 ('', '#000000'), # 25 (nick9 -- obsolete)
73 ('', '#000000'), # 26 (nick10 -- obsolete)
74 ('chat_host', '#666666'), # 27
75 ('chat_delimiters', '#9999FF'), # 28
76 ('chat_highlight', '#3399CC'), # 29
77 ('chat_read_marker', '#000000'), # 30
78 ('chat_text_found', '#000000'), # 31
79 ('chat_value', '#000000'), # 32
80 ('chat_prefix_buffer', '#000000'), # 33
81 ('chat_tags', '#000000'), # 34
82 ('chat_inactive_window', '#000000'), # 35
83 ('chat_inactive_buffer', '#000000'), # 36
84 ('chat_prefix_buffer_inactive_buffer', '#000000'), # 37
85 ('chat_nick_offline', '#000000'), # 38
86 ('chat_nick_offline_highlight', '#000000'), # 39
87 ('chat_nick_prefix', '#000000'), # 40
88 ('chat_nick_suffix', '#000000'), # 41
89 ('emphasis', '#000000'), # 42
90 ('chat_day_change', '#000000'), # 43
92 config_color_options
= []
96 """Read config file."""
97 global config_color_options
98 config
= configparser
.RawConfigParser()
99 if os
.path
.isfile(CONFIG_FILENAME
):
100 config
.read(CONFIG_FILENAME
)
102 # add missing sections/options
103 for section
in CONFIG_DEFAULT_SECTIONS
:
104 if not config
.has_section(section
):
105 config
.add_section(section
)
106 for option
in reversed(CONFIG_DEFAULT_OPTIONS
):
107 section
, name
= option
[0].split('.', 1)
108 if not config
.has_option(section
, name
):
109 config
.set(section
, name
, option
[1])
111 for option
in reversed(CONFIG_DEFAULT_COLOR_OPTIONS
):
112 if option
[0] and not config
.has_option(section
, option
[0]):
113 config
.set(section
, option
[0], option
[1])
115 # build list of color options
116 config_color_options
= []
117 for option
in CONFIG_DEFAULT_COLOR_OPTIONS
:
119 config_color_options
.append(config
.get('color', option
[0]))
121 config_color_options
.append('#000000')
127 """Write config file."""
128 Path(CONFIG_DIR
).mkdir(mode
=0o0700, parents
=True, exist_ok
=True)
129 with open(CONFIG_FILENAME
, 'w') as cfg
:
134 """Return color options."""
135 global config_color_options
136 return config_color_options