1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2018 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 gi
.repository
import Gtk
25 from gpodder
.gtkui
.config
import ConfigModel
26 from gpodder
.gtkui
.interface
.common
import BuilderWidget
31 class gPodderConfigEditor(BuilderWidget
):
33 self
.gPodderConfigEditor
.set_transient_for(self
.parent_widget
)
34 name_column
= Gtk
.TreeViewColumn(_('Setting'))
35 name_renderer
= Gtk
.CellRendererText()
36 name_column
.pack_start(name_renderer
, True)
37 name_column
.add_attribute(name_renderer
, 'text', 0)
38 name_column
.add_attribute(name_renderer
, 'style', 5)
39 name_column
.set_expand(True)
40 self
.configeditor
.append_column(name_column
)
42 value_column
= Gtk
.TreeViewColumn(_('Set to'))
43 value_check_renderer
= Gtk
.CellRendererToggle()
44 # align left otherwise the checkbox is very far away and not visible
45 value_check_renderer
.set_alignment(0, 0.5)
46 value_column
.pack_start(value_check_renderer
, 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
, True)
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 value_column
.set_expand(False)
60 self
.configeditor
.append_column(value_column
)
62 self
.model
= ConfigModel(self
._config
)
63 self
.filter = self
.model
.filter_new()
64 self
.filter.set_visible_func(self
.visible_func
)
66 self
.configeditor
.set_model(self
.filter)
67 self
.configeditor
.set_rules_hint(True)
69 self
._config
.connect_gtk_window(self
.main_window
, 'config_editor', True)
71 def visible_func(self
, model
, iterator
, user_data
=None):
72 text
= self
.entryFilter
.get_text().lower()
76 # either the variable name or its value
77 return (text
in model
.get_value(iterator
, 0).lower()
78 or text
in model
.get_value(iterator
, 2).lower())
80 def value_edited(self
, renderer
, path
, new_text
):
81 model
= self
.configeditor
.get_model()
82 iterator
= model
.get_iter(path
)
83 name
= model
.get_value(iterator
, 0)
84 type_cute
= model
.get_value(iterator
, 1)
86 if not self
._config
.update_field(name
, new_text
):
87 message
= _('Cannot set %(field)s to %(value)s. Needed data type: %(datatype)s')
88 d
= {'field': html
.escape(name
),
89 'value': html
.escape(new_text
),
90 'datatype': html
.escape(type_cute
)}
91 self
.notification(message
% d
, _('Error setting option'))
93 def value_toggled(self
, renderer
, path
):
94 model
= self
.configeditor
.get_model()
95 iterator
= model
.get_iter(path
)
96 field_name
= model
.get_value(iterator
, 0)
97 field_type
= model
.get_value(iterator
, 3)
99 # Flip the boolean config flag
100 if field_type
== bool:
101 self
._config
.toggle_flag(field_name
)
103 def on_entryFilter_changed(self
, widget
):
104 self
.filter.refilter()
106 def on_btnShowAll_clicked(self
, widget
):
107 self
.entryFilter
.set_text('')
108 self
.entryFilter
.grab_focus()
110 def on_btnClose_clicked(self
, widget
):
111 self
.gPodderConfigEditor
.destroy()
113 def on_gPodderConfigEditor_destroy(self
, widget
):
114 self
.model
.stop_observing()