1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
from bzrlib.config import GlobalConfig
27
class PreferencesWindow(gtk.Dialog):
28
"""Displays global preferences windows."""
29
def __init__(self, config=None):
30
""" Initialize the Status window. """
31
super(PreferencesWindow, self).__init__(flags=gtk.DIALOG_MODAL)
32
self.set_title("Bazaar Preferences")
34
if self.config is None:
35
self.config = GlobalConfig()
38
def _create_mainpage(self):
39
table = gtk.Table(rows=4, columns=2)
40
table.set_row_spacings(6)
41
table.set_col_spacings(6)
43
align = gtk.Alignment(1.0, 0.5)
45
label.set_markup("<b>User Id:</b>")
47
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
49
align = gtk.Alignment(0.0, 0.5)
50
self.username = gtk.Entry()
51
align.add(self.username)
52
self.username.set_text(self.config.username())
53
table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
55
align = gtk.Alignment(1.0, 0.5)
57
label.set_markup("<b>GPG signing command:</b>")
59
table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
61
align = gtk.Alignment(0.0, 0.5)
62
self.email = gtk.Entry()
63
self.email.set_text(self.config.gpg_signing_command())
65
table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
67
align = gtk.Alignment(1.0, 0.5)
69
label.set_markup("<b>Check GPG Signatures:</b>")
71
table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
73
align = gtk.Alignment(0.0, 0.5)
75
self.check_sigs_if_possible = gtk.RadioButton(None,
77
sigvals.pack_start(self.check_sigs_if_possible)
78
self.check_sigs_always = gtk.RadioButton(self.check_sigs_if_possible,
80
sigvals.pack_start(self.check_sigs_always)
81
self.check_sigs_never = gtk.RadioButton(self.check_sigs_if_possible,
83
sigvals.pack_start(self.check_sigs_never)
86
table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
88
align = gtk.Alignment(1.0, 0.5)
90
label.set_markup("<b>Create GPG Signatures:</b>")
92
table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
94
align = gtk.Alignment(0.0, 0.5)
95
create_sigs = gtk.VBox()
96
self.create_sigs_when_required = gtk.RadioButton(None,
97
"Sign When _Required")
98
create_sigs.pack_start(self.create_sigs_when_required)
99
self.create_sigs_always = gtk.RadioButton(
100
self.create_sigs_when_required, "Sign _Always")
101
create_sigs.pack_start(self.create_sigs_always)
102
self.create_sigs_never = gtk.RadioButton(
103
self.create_sigs_when_required, "Sign _Never")
104
create_sigs.pack_start(self.create_sigs_never)
106
align.add(create_sigs)
107
table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
111
def _create_pluginpage(self):
112
vbox = gtk.VBox(False, 2)
113
vbox.set_border_width(6)
115
scrolledwindow = gtk.ScrolledWindow()
116
scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
117
model = gtk.ListStore(str, str)
118
treeview = gtk.TreeView()
119
scrolledwindow.add(treeview)
121
table = gtk.Table(columns=2)
122
table.set_row_spacings(6)
123
table.set_col_spacings(6)
126
def row_selected(tv, path, tvc):
127
p = bzrlib.plugin.all_plugins()[model[path][0]]
128
from inspect import getdoc
130
for w in table.get_children():
133
if getattr(p, '__author__', None) is not None:
134
align = gtk.Alignment(1.0, 0.5)
136
label.set_markup("<b>Author:</b>")
138
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
142
align = gtk.Alignment(0.0, 0.5)
144
author.set_text(p.__author__)
145
author.set_selectable(True)
147
table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
149
if getattr(p, '__version__', None) is not None:
150
align = gtk.Alignment(1.0, 0.5)
152
label.set_markup("<b>Version:</b>")
154
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
158
align = gtk.Alignment(0.0, 0.5)
160
author.set_text(p.__version__)
161
author.set_selectable(True)
163
table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
165
if getdoc(p) is not None:
166
align = gtk.Alignment(0.0, 0.5)
167
description = gtk.Label()
168
description.set_text(getdoc(p))
169
description.set_selectable(True)
170
align.add(description)
171
table.attach(align, 0, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
175
treeview.set_headers_visible(False)
176
treeview.set_model(model)
177
treeview.connect("row-activated", row_selected)
179
cell = gtk.CellRendererText()
180
column = gtk.TreeViewColumn()
181
column.pack_start(cell, expand=True)
182
column.add_attribute(cell, "text", 0)
183
treeview.append_column(column)
185
cell = gtk.CellRendererText()
186
column = gtk.TreeViewColumn()
187
column.pack_start(cell, expand=True)
188
column.add_attribute(cell, "text", 1)
189
treeview.append_column(column)
192
plugins = bzrlib.plugin.all_plugins()
193
plugin_names = plugins.keys()
195
for name in plugin_names:
196
model.append([name, getattr(plugins[name], '__file__', None)])
198
vbox.pack_start(scrolledwindow, expand=True, fill=True)
200
vbox.pack_start(table)
205
self.set_default_size(600, 600)
206
notebook = gtk.Notebook()
207
notebook.insert_page(self._create_mainpage(), gtk.Label("Main"))
208
notebook.insert_page(self._create_pluginpage(), gtk.Label("Plugins"))
209
self.vbox.pack_start(notebook, True, True)
213
self.window.show_all()
215
def close(self, widget=None):
216
self.window.destroy()
218
class BranchPreferencesWindow(gtk.Dialog):
219
"""Displays global preferences windows."""
220
def __init__(self, config=None):
221
super(BranchPreferencesWindow, self).__init__(config)