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