]> jfr.im git - irc/weechat/qweechat.git/blame - qweechat/config.py
Add contributor
[irc/weechat/qweechat.git] / qweechat / config.py
CommitLineData
77df9d06
SH
1# -*- coding: utf-8 -*-
2#
3# config.py - configuration for QWeeChat (~/.qweechat/qweechat.conf)
4#
8335009d 5# Copyright (C) 2011-2021 Sébastien Helleu <flashcode@flashtux.org>
77df9d06
SH
6#
7# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
8#
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.
13#
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.
18#
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/>.
21#
22
1fe88536
SH
23"""Configuration for QWeeChat."""
24
1f27a20e 25import configparser
77df9d06
SH
26import os
27
28CONFIG_DIR = '%s/.qweechat' % os.getenv('HOME')
29CONFIG_FILENAME = '%s/qweechat.conf' % CONFIG_DIR
30
31CONFIG_DEFAULT_RELAY_LINES = 50
32
33CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color')
34CONFIG_DEFAULT_OPTIONS = (('relay.server', ''),
35 ('relay.port', ''),
36 ('relay.ssl', 'off'),
37 ('relay.password', ''),
38 ('relay.autoconnect', 'off'),
39 ('relay.lines', str(CONFIG_DEFAULT_RELAY_LINES)),
40 ('look.debug', 'off'),
41 ('look.statusbar', 'off'))
42
43# Default colors for WeeChat color options (option name, #rgb value)
44CONFIG_DEFAULT_COLOR_OPTIONS = (
45 ('separator', '#000066'), # 0
46 ('chat', '#000000'), # 1
47 ('chat_time', '#999999'), # 2
48 ('chat_time_delimiters', '#000000'), # 3
49 ('chat_prefix_error', '#FF6633'), # 4
50 ('chat_prefix_network', '#990099'), # 5
51 ('chat_prefix_action', '#000000'), # 6
52 ('chat_prefix_join', '#00CC00'), # 7
53 ('chat_prefix_quit', '#CC0000'), # 8
54 ('chat_prefix_more', '#CC00FF'), # 9
55 ('chat_prefix_suffix', '#330099'), # 10
56 ('chat_buffer', '#000000'), # 11
57 ('chat_server', '#000000'), # 12
58 ('chat_channel', '#000000'), # 13
59 ('chat_nick', '#000000'), # 14
60 ('chat_nick_self', '*#000000'), # 15
61 ('chat_nick_other', '#000000'), # 16
62 ('', '#000000'), # 17 (nick1 -- obsolete)
63 ('', '#000000'), # 18 (nick2 -- obsolete)
64 ('', '#000000'), # 19 (nick3 -- obsolete)
65 ('', '#000000'), # 20 (nick4 -- obsolete)
66 ('', '#000000'), # 21 (nick5 -- obsolete)
67 ('', '#000000'), # 22 (nick6 -- obsolete)
68 ('', '#000000'), # 23 (nick7 -- obsolete)
69 ('', '#000000'), # 24 (nick8 -- obsolete)
70 ('', '#000000'), # 25 (nick9 -- obsolete)
71 ('', '#000000'), # 26 (nick10 -- obsolete)
72 ('chat_host', '#666666'), # 27
73 ('chat_delimiters', '#9999FF'), # 28
74 ('chat_highlight', '#3399CC'), # 29
75 ('chat_read_marker', '#000000'), # 30
76 ('chat_text_found', '#000000'), # 31
77 ('chat_value', '#000000'), # 32
78 ('chat_prefix_buffer', '#000000'), # 33
79 ('chat_tags', '#000000'), # 34
80 ('chat_inactive_window', '#000000'), # 35
81 ('chat_inactive_buffer', '#000000'), # 36
82 ('chat_prefix_buffer_inactive_buffer', '#000000'), # 37
83 ('chat_nick_offline', '#000000'), # 38
84 ('chat_nick_offline_highlight', '#000000'), # 39
85 ('chat_nick_prefix', '#000000'), # 40
86 ('chat_nick_suffix', '#000000'), # 41
87 ('emphasis', '#000000'), # 42
88 ('chat_day_change', '#000000'), # 43
89)
90config_color_options = []
91
92
93def read():
94 """Read config file."""
95 global config_color_options
1f27a20e 96 config = configparser.RawConfigParser()
77df9d06
SH
97 if os.path.isfile(CONFIG_FILENAME):
98 config.read(CONFIG_FILENAME)
99
100 # add missing sections/options
101 for section in CONFIG_DEFAULT_SECTIONS:
102 if not config.has_section(section):
103 config.add_section(section)
104 for option in reversed(CONFIG_DEFAULT_OPTIONS):
105 section, name = option[0].split('.', 1)
106 if not config.has_option(section, name):
107 config.set(section, name, option[1])
108 section = 'color'
109 for option in reversed(CONFIG_DEFAULT_COLOR_OPTIONS):
110 if option[0] and not config.has_option(section, option[0]):
111 config.set(section, option[0], option[1])
112
113 # build list of color options
114 config_color_options = []
115 for option in CONFIG_DEFAULT_COLOR_OPTIONS:
116 if option[0]:
117 config_color_options.append(config.get('color', option[0]))
118 else:
119 config_color_options.append('#000000')
120
121 return config
122
123
124def write(config):
125 """Write config file."""
126 if not os.path.exists(CONFIG_DIR):
127 os.mkdir(CONFIG_DIR, 0o0755)
1f27a20e 128 with open(CONFIG_FILENAME, 'w') as cfg:
77df9d06
SH
129 config.write(cfg)
130
131
132def color_options():
ac53e98c 133 """Return color options."""
77df9d06
SH
134 global config_color_options
135 return config_color_options