1
# -*- coding: utf-8; Mode: Python; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2006, 2007, 2008 Canonical Ltd.
4
# Written by Colin Watson <cjwatson@ubuntu.com>.
6
# This program 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 2 of the License, or
9
# (at your option) any later version.
11
# This program 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, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
from ubiquity.plugin import *
27
from ubiquity.misc import *
28
from ubiquity.casper import get_casper
30
from ubiquity import validation
35
# Not useful in oem-config.
38
class PageBase(PluginUI):
41
self.summary_device = None
43
self.http_proxy_host = None
44
self.http_proxy_port = 8080
46
def set_summary_text(self):
49
class PageGtk(PageBase):
50
plugin_is_install = True
51
plugin_widgets = 'stepReady'
53
def __init__(self, controller, *args, **kwargs):
54
PageBase.__init__(self)
55
self.controller = controller
58
builder = gtk.Builder()
59
controller.add_builder(builder)
60
builder.add_from_file(os.path.join(os.environ['UBIQUITY_GLADE'], 'stepReady.ui'))
61
builder.connect_signals(self)
62
self.page = builder.get_object('stepReady')
63
self.ready_text = builder.get_object('ready_text')
64
self.grub_device_entry = builder.get_object('grub_device_entry')
65
self.advanced_okbutton = builder.get_object('advanced_okbutton')
66
self.bootloader_vbox = builder.get_object('bootloader_vbox')
67
self.grub_enable = builder.get_object('grub_enable')
68
self.grub_device_label = builder.get_object('grub_device_label')
69
self.grub_device_entry = builder.get_object('grub_device_entry')
70
self.popcon_vbox = builder.get_object('popcon_vbox')
71
self.popcon_checkbutton = builder.get_object('popcon_checkbutton')
72
self.proxy_host_entry = builder.get_object('proxy_host_entry')
73
self.proxy_port_spinbutton = builder.get_object('proxy_port_spinbutton')
74
self.advanced_dialog = builder.get_object('advanced_dialog')
75
self.plugin_widgets = self.page
77
self.grub_device_entry.connect('changed', self.grub_verify_loop,
78
self.advanced_okbutton)
80
# The default instantiation of GtkComboBoxEntry creates a
81
# GtkCellRenderer, so reuse it.
82
self.grub_device_entry.set_model(self.controller.grub_options)
83
self.grub_device_entry.set_text_column(0)
84
renderer = gtk.CellRendererText()
85
self.grub_device_entry.pack_start(renderer, True)
86
self.grub_device_entry.add_attribute(renderer, 'text', 1)
88
def set_summary_text(self, text):
90
for child in self.ready_text.get_children():
91
self.ready_text.remove(child)
93
ready_buffer = gtk.TextBuffer()
94
ready_buffer.set_text(text)
95
self.ready_text.set_buffer(ready_buffer)
97
def grub_verify_loop(self, widget, okbutton):
98
if widget is not None and widget.get_property('visible'):
99
if validation.check_grub_device(widget.child.get_text()):
100
okbutton.set_sensitive(True)
102
okbutton.set_sensitive(False)
104
def on_advanced_button_clicked(self, unused_button):
107
grub_en = self.controller.get_grub()
108
summary_device = self.controller.get_summary_device()
110
if grub_en is not None:
112
self.bootloader_vbox.show()
113
self.grub_enable.set_active(grub_en)
115
self.bootloader_vbox.hide()
116
summary_device = None
118
if summary_device is not None:
120
self.grub_device_label.show()
121
self.grub_device_entry.show()
122
self.grub_device_entry.child.set_text(summary_device)
123
self.grub_device_entry.set_sensitive(grub_en)
124
self.grub_device_label.set_sensitive(grub_en)
126
self.grub_device_label.hide()
127
self.grub_device_entry.hide()
129
if self.popcon is not None:
131
self.popcon_vbox.show()
132
self.popcon_checkbutton.set_active(self.popcon)
134
self.popcon_vbox.hide()
137
if self.http_proxy_host:
138
self.proxy_host_entry.set_text(self.http_proxy_host)
139
self.proxy_port_spinbutton.set_sensitive(True)
141
self.proxy_port_spinbutton.set_sensitive(False)
142
self.proxy_port_spinbutton.set_value(self.http_proxy_port)
144
# never happens at the moment because the HTTP proxy question is
149
response = self.advanced_dialog.run()
150
self.advanced_dialog.hide()
151
if response == gtk.RESPONSE_OK:
152
if summary_device is not None:
153
self.controller.set_summary_device(self.grub_device_entry.child.get_text())
154
self.controller.set_popcon(self.popcon_checkbutton.get_active())
155
self.controller.set_grub(self.grub_enable.get_active())
156
self.controller.set_proxy_host(self.proxy_host_entry.get_text())
157
self.controller.set_proxy_port(self.proxy_port_spinbutton.get_value_as_int())
160
def toggle_grub(self, widget):
161
if (widget is not None and widget.get_name() == 'grub_enable'):
162
self.grub_device_entry.set_sensitive(widget.get_active())
163
self.grub_device_label.set_sensitive(widget.get_active())
165
def on_proxy_host_changed(self, widget):
166
if widget is not None and widget.get_name() == 'proxy_host_entry':
167
text = self.proxy_host_entry.get_text()
168
self.proxy_port_spinbutton.set_sensitive(text != '')
171
class PageKde(PageBase):
172
plugin_is_install = True
173
plugin_breadcrumb = 'ubiquity/text/breadcrumb_summary'
175
def __init__(self, controller, *args, **kwargs):
176
PageBase.__init__(self)
178
self.controller = controller
180
from PyQt4 import uic
181
from PyQt4.QtGui import QDialog
183
self.plugin_widgets = uic.loadUi('/usr/share/ubiquity/qt/stepSummary.ui')
184
self.advanceddialog = QDialog(self.plugin_widgets)
185
uic.loadUi("/usr/share/ubiquity/qt/advanceddialog.ui", self.advanceddialog)
187
self.advanceddialog.grub_enable.stateChanged.connect(self.toggle_grub)
188
self.advanceddialog.proxy_host_entry.textChanged.connect(self.enable_proxy_spinbutton)
190
self.plugin_widgets.advanced_button.clicked.connect(self.on_advanced_button_clicked)
191
self.w = self.plugin_widgets
193
def set_summary_text (self, text):
194
text = text.replace("\n", "<br>")
195
self.plugin_widgets.ready_text.setText(text)
197
def set_grub_combo(self, options):
198
''' options gives us a possible list of install locations for the boot loader '''
199
self.advanceddialog.grub_device_entry.clear()
200
''' options is from summary.py grub_options() '''
202
self.advanceddialog.grub_device_entry.addItem(opt[0])
204
def enable_proxy_spinbutton(self):
205
self.advanceddialog.proxy_port_spinbutton.setEnabled(self.advanceddialog.proxy_host_entry.text() != '')
207
def toggle_grub(self):
208
grub_en = self.advanceddialog.grub_enable.isChecked()
209
self.advanceddialog.grub_device_entry.setEnabled(grub_en)
210
self.advanceddialog.grub_device_label.setEnabled(grub_en)
212
def on_advanced_button_clicked(self):
215
grub_en = self.controller.get_grub()
216
summary_device = self.controller.get_summary_device()
217
self.advanceddialog.grub_device_entry.clear()
220
self.advanceddialog.grub_enable.show()
221
self.advanceddialog.grub_enable.setChecked(grub_en)
223
self.advanceddialog.grub_enable.hide()
224
summary_device = None
228
self.advanceddialog.bootloader_group_label.show()
229
self.advanceddialog.grub_device_label.show()
230
self.advanceddialog.grub_device_entry.show()
232
# if the combo box does not yet have the target install device, add it
233
# select current device
234
summary_device = self.controller.get_summary_device()
236
# by default select the summary device
237
self.advanceddialog.grub_device_entry.addItem(summary_device)
238
index = self.advanceddialog.grub_device_entry.count() - 1
239
self.advanceddialog.grub_device_entry.setCurrentIndex(index)
241
self.advanceddialog.grub_device_entry.setEnabled(grub_en)
242
self.advanceddialog.grub_device_label.setEnabled(grub_en)
244
for o in grub_options():
245
if o[0] == summary_device:
247
self.advanceddialog.grub_device_entry.addItem(o[0])
249
self.advanceddialog.bootloader_group_label.hide()
250
self.advanceddialog.grub_device_label.hide()
251
self.advanceddialog.grub_device_entry.hide()
255
self.advanceddialog.popcon_group_label.show()
256
self.advanceddialog.popcon_checkbutton.show()
257
self.advanceddialog.popcon_checkbutton.setChecked(self.popcon)
259
self.advanceddialog.popcon_group_label.hide()
260
self.advanceddialog.popcon_checkbutton.hide()
263
if self.http_proxy_host:
264
self.advanceddialog.proxy_port_spinbutton.setEnabled(True)
265
self.advanceddialog.proxy_host_entry.setText(unicode(self.http_proxy_host))
267
self.advanceddialog.proxy_port_spinbutton.setEnabled(False)
268
self.advanceddialog.proxy_port_spinbutton.setValue(self.http_proxy_port)
273
response = self.advanceddialog.exec_()
274
from PyQt4.QtGui import QDialog
275
if response == QDialog.Accepted:
276
if summary_device is not None:
277
self.controller.set_summary_device(
278
unicode(self.advanceddialog.grub_device_entry.currentText()))
279
self.controller.set_popcon(self.advanceddialog.popcon_checkbutton.isChecked())
280
self.controller.set_grub(self.advanceddialog.grub_enable.isChecked())
281
self.controller.set_proxy_host(unicode(self.advanceddialog.proxy_host_entry.text()))
282
self.controller.set_proxy_port(self.advanceddialog.proxy_port_spinbutton.value())
284
def will_be_installed(pkg):
286
casper_path = os.path.join(
287
'/cdrom', get_casper('LIVE_MEDIA_PATH', 'casper').lstrip('/'))
288
manifest = open(os.path.join(casper_path,
289
'filesystem.manifest-desktop'))
291
for line in manifest:
292
if line.strip() == '' or line.startswith('#'):
294
if line.split()[0] == pkg:
303
return ('/usr/share/ubiquity/summary', ['^ubiquity/summary.*'])
305
def run(self, priority, question):
306
if question.endswith('/summary'):
308
wrapper = textwrap.TextWrapper(width=76)
309
for line in self.extended_description(question).split("\n"):
310
text += wrapper.fill(line) + "\n"
312
self.ui.set_summary_text(text)
315
install_bootloader = self.db.get('ubiquity/install_bootloader')
316
self.frontend.set_grub(install_bootloader == 'true')
317
except debconf.DebconfError:
318
self.frontend.set_grub(None)
320
if os.access('/usr/share/grub-installer/grub-installer', os.X_OK):
321
self.frontend.set_summary_device(grub_default())
323
self.frontend.set_summary_device(None)
325
if will_be_installed('popularity-contest'):
327
participate = self.db.get('popularity-contest/participate')
328
self.frontend.set_popcon(participate == 'true')
329
except debconf.DebconfError:
330
self.frontend.set_popcon(None)
332
self.frontend.set_popcon(None)
334
# This component exists only to gather some information and then
335
# get out of the way.
337
return Plugin.run(self, priority, question)