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