1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2010 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 from xml
.sax
import saxutils
28 from gpodder
.gtkui
.config
import ConfigModel
30 from gpodder
.gtkui
.interface
.common
import BuilderWidget
33 class gPodderConfigEditor(BuilderWidget
):
34 finger_friendly_widgets
= ['btnShowAll', 'btnClose', 'configeditor']
37 name_column
= gtk
.TreeViewColumn(_('Setting'))
38 name_renderer
= gtk
.CellRendererText()
39 name_column
.pack_start(name_renderer
)
40 name_column
.add_attribute(name_renderer
, 'text', 0)
41 name_column
.add_attribute(name_renderer
, 'style', 5)
42 self
.configeditor
.append_column(name_column
)
44 value_column
= gtk
.TreeViewColumn(_('Set to'))
45 value_check_renderer
= gtk
.CellRendererToggle()
46 value_column
.pack_start(value_check_renderer
, expand
=False)
47 value_column
.add_attribute(value_check_renderer
, 'active', 7)
48 value_column
.add_attribute(value_check_renderer
, 'visible', 6)
49 value_column
.add_attribute(value_check_renderer
, 'activatable', 6)
50 value_check_renderer
.connect('toggled', self
.value_toggled
)
52 value_renderer
= gtk
.CellRendererText()
53 value_column
.pack_start(value_renderer
)
54 value_column
.add_attribute(value_renderer
, 'text', 2)
55 value_column
.add_attribute(value_renderer
, 'visible', 4)
56 value_column
.add_attribute(value_renderer
, 'editable', 4)
57 value_column
.add_attribute(value_renderer
, 'style', 5)
58 value_renderer
.connect('edited', self
.value_edited
)
59 self
.configeditor
.append_column(value_column
)
61 self
.model
= ConfigModel(self
._config
)
62 self
.filter = self
.model
.filter_new()
63 self
.filter.set_visible_func(self
.visible_func
)
65 self
.configeditor
.set_model(self
.filter)
66 self
.configeditor
.set_rules_hint(True)
67 self
.configeditor
.get_selection().connect( 'changed',
68 self
.on_configeditor_row_changed
)
70 def visible_func(self
, model
, iter, user_data
=None):
71 text
= self
.entryFilter
.get_text().lower()
75 # either the variable name or its value
76 return (text
in model
.get_value(iter, 0).lower() or
77 text
in model
.get_value(iter, 2).lower())
79 def value_edited(self
, renderer
, path
, new_text
):
80 model
= self
.configeditor
.get_model()
81 iter = model
.get_iter(path
)
82 name
= model
.get_value(iter, 0)
83 type_cute
= model
.get_value(iter, 1)
85 if not self
._config
.update_field(name
, new_text
):
86 self
.notification(_('Cannot set value of <b>%s</b> to <i>%s</i>.\n\nNeeded data type: %s') % (saxutils
.escape(name
), saxutils
.escape(new_text
), saxutils
.escape(type_cute
)), _('Error updating %s') % saxutils
.escape(name
))
88 def value_toggled(self
, renderer
, path
):
89 model
= self
.configeditor
.get_model()
90 iter = model
.get_iter(path
)
91 field_name
= model
.get_value(iter, 0)
92 field_type
= model
.get_value(iter, 3)
94 # Flip the boolean config flag
95 if field_type
== bool:
96 self
._config
.toggle_flag(field_name
)
98 def on_entryFilter_changed(self
, widget
):
99 self
.filter.refilter()
101 def on_btnShowAll_clicked(self
, widget
):
102 self
.entryFilter
.set_text('')
103 self
.entryFilter
.grab_focus()
105 def on_btnClose_clicked(self
, widget
):
106 self
.gPodderConfigEditor
.destroy()
108 def on_gPodderConfigEditor_destroy(self
, widget
):
109 self
.model
.stop_observing()
111 def on_configeditor_row_changed(self
, treeselection
):
112 model
, iter = treeselection
.get_selected()
114 option_name
= self
._config
.get_description( model
.get(iter, 0)[0] )
115 self
.config_option_description_label
.set_text(option_name
)