| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
Debconf::FrontEnd::Gnome - GUI Gnome frontend |
| 6 |
|
| 7 |
=cut |
| 8 |
|
| 9 |
package Debconf::FrontEnd::Gnome; |
| 10 |
use warnings; |
| 11 |
use strict; |
| 12 |
use utf8; |
| 13 |
use Debconf::Gettext; |
| 14 |
use Debconf::Config; |
| 15 |
use Debconf::Encoding qw(to_Unicode); |
| 16 |
use base qw{Debconf::FrontEnd}; |
| 17 |
|
| 18 |
=head1 DESCRIPTION |
| 19 |
|
| 20 |
This FrontEnd is a Gnome UI for Debconf. |
| 21 |
|
| 22 |
=head1 METHODS |
| 23 |
|
| 24 |
=over 4 |
| 25 |
|
| 26 |
=item init |
| 27 |
|
| 28 |
Set up most of the GUI. |
| 29 |
|
| 30 |
=cut |
| 31 |
|
| 32 |
our @ARGV_for_gnome=('--sm-disable'); |
| 33 |
|
| 34 |
sub create_assistant_page { |
| 35 |
my $this=shift; |
| 36 |
|
| 37 |
$this->assistant_page(Gtk3::VBox->new); |
| 38 |
$this->assistant->append_page($this->assistant_page); |
| 39 |
|
| 40 |
if ($this->logo) { |
| 41 |
$this->assistant->set_page_header_image($this->assistant_page, $this->logo); |
| 42 |
} |
| 43 |
|
| 44 |
$this->configure_assistant_page; |
| 45 |
$this->assistant_page->show_all; |
| 46 |
} |
| 47 |
|
| 48 |
sub configure_assistant_page { |
| 49 |
my $this=shift; |
| 50 |
|
| 51 |
$this->assistant->set_page_title($this->assistant_page, to_Unicode($this->title)); |
| 52 |
$this->assistant->set_page_type($this->assistant_page, 'custom'); |
| 53 |
$this->forward_button->grab_default; |
| 54 |
$this->forward_button->show; |
| 55 |
if ($this->capb_backup) { |
| 56 |
$this->back_button->show; |
| 57 |
} else { |
| 58 |
$this->back_button->hide; |
| 59 |
} |
| 60 |
$this->assistant->set_page_complete($this->assistant_page, 1); |
| 61 |
} |
| 62 |
|
| 63 |
sub reset_assistant_page { |
| 64 |
my $this=shift; |
| 65 |
|
| 66 |
$this->assistant_page($this->assistant->get_nth_page($this->assistant->get_current_page)); |
| 67 |
foreach my $element ($this->assistant_page->get_children) { |
| 68 |
$this->assistant_page->remove($element); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
my $prev_page = 0; |
| 73 |
|
| 74 |
# this gets called on clicking next/previous buttons |
| 75 |
sub prepare_callback { |
| 76 |
my ($assistant, $page, $this) = @_; |
| 77 |
my $current_page = $assistant->get_current_page; |
| 78 |
|
| 79 |
if ($prev_page < $current_page) { |
| 80 |
$this->goback(0); |
| 81 |
if (Gtk3::main_level()) { |
| 82 |
Gtk3::main_quit(); |
| 83 |
} |
| 84 |
} elsif ($prev_page > $current_page) { |
| 85 |
$this->goback(1); |
| 86 |
if (Gtk3::main_level()) { |
| 87 |
Gtk3::main_quit(); |
| 88 |
} |
| 89 |
} |
| 90 |
$prev_page = $current_page; |
| 91 |
} |
| 92 |
|
| 93 |
sub close_callback { |
| 94 |
my ($assistant) = @_; |
| 95 |
|
| 96 |
my $title = gettext("Really quit configuration?"); |
| 97 |
my $text = gettext("If you quit this configuration dialog, then the package being configured will probably fail to install, and you may have to fix it manually. This may be especially difficult if you are in the middle of a large upgrade.")."\n\n".gettext("You may need to quit anyway if you are stuck in a configuration loop due to a buggy package.")."\n"; |
| 98 |
my $quit = gettext("_Quit"); |
| 99 |
my $continue = gettext("Continue"); |
| 100 |
|
| 101 |
my $dialog = Gtk3::Dialog->new_with_buttons(to_Unicode($title), |
| 102 |
$assistant, "modal", |
| 103 |
to_Unicode($quit), "yes", |
| 104 |
to_Unicode($continue), |
| 105 |
"no"); |
| 106 |
$dialog->set_default_response("no"); |
| 107 |
$dialog->set_border_width(3); |
| 108 |
|
| 109 |
my $grid = Gtk3::Grid->new(); |
| 110 |
$grid->set_orientation("horizontal"); |
| 111 |
$grid->set_column_homogeneous(0); |
| 112 |
$dialog->get_content_area->pack_start($grid, 1, 1, 5); |
| 113 |
$grid->show; |
| 114 |
|
| 115 |
my $alignment = Gtk3::Alignment->new(0.5, 0.0, 1.0, 0.0); |
| 116 |
$grid->add($alignment); |
| 117 |
$alignment->show; |
| 118 |
|
| 119 |
my $image = Gtk3::Image->new_from_icon_name("dialog-information", "dialog"); |
| 120 |
$alignment->add($image); |
| 121 |
$image->show; |
| 122 |
|
| 123 |
my $label = Gtk3::Label->new(to_Unicode($text)); |
| 124 |
$label->set_line_wrap(1); |
| 125 |
$grid->add($label); |
| 126 |
$label->show; |
| 127 |
|
| 128 |
my $response = $dialog->run; |
| 129 |
$dialog->destroy; |
| 130 |
|
| 131 |
exit 1 if $response eq "yes"; |
| 132 |
} |
| 133 |
|
| 134 |
sub delete_event_callback { |
| 135 |
my ($assistant, $event) = @_; |
| 136 |
|
| 137 |
close_callback($assistant); |
| 138 |
} |
| 139 |
|
| 140 |
sub forward_page_func { |
| 141 |
my ($current_page, $assistant) = @_; |
| 142 |
|
| 143 |
return $current_page + 1; |
| 144 |
} |
| 145 |
|
| 146 |
sub on_forward { |
| 147 |
my ($button) = @_; |
| 148 |
|
| 149 |
my $assistant = $button->get_ancestor("Gtk3::Assistant"); |
| 150 |
$assistant->next_page; |
| 151 |
} |
| 152 |
|
| 153 |
sub on_back { |
| 154 |
my ($button) = @_; |
| 155 |
|
| 156 |
my $assistant = $button->get_ancestor("Gtk3::Assistant"); |
| 157 |
$assistant->previous_page; |
| 158 |
} |
| 159 |
|
| 160 |
sub init { |
| 161 |
my $this=shift; |
| 162 |
|
| 163 |
# Ya know, this really sucks. The authors of GTK seemed to just not |
| 164 |
# conceive of a program that can, *gasp*, work even if GTK doesn't |
| 165 |
# load. So this thing throws a fatal, essentially untrappable |
| 166 |
# error. Yeesh. Look how far I must go out of my way to make sure |
| 167 |
# it's not going to destroy debconf.. |
| 168 |
if (fork) { |
| 169 |
wait(); # for child |
| 170 |
if ($? != 0) { |
| 171 |
die "DISPLAY problem?\n"; |
| 172 |
} |
| 173 |
} |
| 174 |
else { |
| 175 |
# Catch scenario where the libraries we need are not installed. |
| 176 |
use Gtk3; |
| 177 |
|
| 178 |
@ARGV=@ARGV_for_gnome; # temporary change at first |
| 179 |
Gtk3->init; |
| 180 |
|
| 181 |
# Create a window, but don't show it. |
| 182 |
# |
| 183 |
# This has the effect of exercising gtk a bit in an |
| 184 |
# attempt to force an error either in the gtk bindings |
| 185 |
# themselves, but hopefully also in |
| 186 |
# gtk/glib/gsettings/etc. There is no guarantee that |
| 187 |
# this alone will provoke an error, but it's a |
| 188 |
# relatively safe and reasonable operation to perform |
| 189 |
# and further reduces the chance of the parent debconf |
| 190 |
# process ending up in an unrecoverable state. |
| 191 |
my $window = Gtk3::Window->new('toplevel'); |
| 192 |
|
| 193 |
exit(0); # success |
| 194 |
} |
| 195 |
|
| 196 |
# Only load Gtk after the child has successfully proved it can do |
| 197 |
# the same. This avoids the problem where a module calls into a |
| 198 |
# native library and causes the perl interpreter to crash. When |
| 199 |
# we get to here, we know that the child didn't crash, so it |
| 200 |
# should be safe for us to attempt it. |
| 201 |
eval q{use Gtk3;}; |
| 202 |
die "Unable to load Gtk -- is libgtk3-perl installed?\n" if $@; |
| 203 |
|
| 204 |
my @gnome_sucks=@ARGV; |
| 205 |
@ARGV=@ARGV_for_gnome; |
| 206 |
Gtk3->init; |
| 207 |
@ARGV=@gnome_sucks; |
| 208 |
|
| 209 |
$this->SUPER::init(@_); |
| 210 |
$this->interactive(1); |
| 211 |
$this->capb('backup'); |
| 212 |
$this->need_tty(0); |
| 213 |
|
| 214 |
$this->assistant(Gtk3::Assistant->new); |
| 215 |
$this->assistant->set_position("center"); |
| 216 |
$this->assistant->set_default_size(600, 400); |
| 217 |
my $hostname = `hostname`; |
| 218 |
chomp $hostname; |
| 219 |
$this->assistant->set_title(to_Unicode(sprintf(gettext("Debconf on %s"), $hostname))); |
| 220 |
$this->assistant->signal_connect("delete_event", \&delete_event_callback); |
| 221 |
|
| 222 |
my $distribution=''; |
| 223 |
if (system('type lsb_release >/dev/null 2>&1') == 0) { |
| 224 |
$distribution=lc(`lsb_release -is`); |
| 225 |
chomp $distribution; |
| 226 |
} elsif (-e '/etc/debian_version') { |
| 227 |
$distribution='debian'; |
| 228 |
} |
| 229 |
|
| 230 |
my $logo="/usr/share/pixmaps/$distribution-logo.png"; |
| 231 |
if (-e $logo) { |
| 232 |
$this->logo(Gtk3::Gdk::Pixbuf->new_from_file($logo)); |
| 233 |
} |
| 234 |
|
| 235 |
$this->assistant->signal_connect("close", \&close_callback); |
| 236 |
$this->assistant->signal_connect("prepare", \&prepare_callback, $this); |
| 237 |
$this->assistant->set_forward_page_func(\&forward_page_func, $this->assistant); |
| 238 |
|
| 239 |
$this->forward_button(Gtk3::Button->new_with_mnemonic(to_Unicode(gettext("_Next")))); |
| 240 |
$this->forward_button->set_can_focus(1); |
| 241 |
$this->forward_button->set_can_default(1); |
| 242 |
$this->forward_button->set_receives_default(1); |
| 243 |
$this->forward_button->signal_connect("clicked", \&on_forward); |
| 244 |
$this->assistant->add_action_widget($this->forward_button); |
| 245 |
|
| 246 |
$this->back_button(Gtk3::Button->new_with_mnemonic(to_Unicode(gettext("_Back")))); |
| 247 |
$this->back_button->set_can_focus(1); |
| 248 |
$this->back_button->set_receives_default(1); |
| 249 |
$this->back_button->signal_connect("clicked", \&on_back); |
| 250 |
$this->assistant->add_action_widget($this->back_button); |
| 251 |
|
| 252 |
$this->create_assistant_page(); |
| 253 |
|
| 254 |
$this->assistant->show; |
| 255 |
} |
| 256 |
|
| 257 |
=item go |
| 258 |
|
| 259 |
Creates and lays out all the necessary widgets, then runs them to get |
| 260 |
input. |
| 261 |
|
| 262 |
=cut |
| 263 |
|
| 264 |
sub go { |
| 265 |
my $this=shift; |
| 266 |
my @elements=@{$this->elements}; |
| 267 |
|
| 268 |
$this->reset_assistant_page; |
| 269 |
|
| 270 |
my $interactive=''; |
| 271 |
foreach my $element (@elements) { |
| 272 |
# Noninteractive elements have no hboxes. |
| 273 |
next unless $element->hbox; |
| 274 |
|
| 275 |
$interactive=1; |
| 276 |
$this->assistant_page->pack_start($element->hbox, $element->fill, $element->expand, 0); |
| 277 |
} |
| 278 |
|
| 279 |
if ($interactive) { |
| 280 |
$this->configure_assistant_page; |
| 281 |
if ($this->assistant->get_current_page == $this->assistant->get_n_pages - 1) { |
| 282 |
# Create the next page so that GtkAssistant doesn't |
| 283 |
# hide the Forward button. |
| 284 |
$this->create_assistant_page(); |
| 285 |
} |
| 286 |
Gtk3::main(); |
| 287 |
} |
| 288 |
|
| 289 |
# Display all elements. This does nothing for gnome |
| 290 |
# elements, but it causes noninteractive elements to do |
| 291 |
# their thing. |
| 292 |
foreach my $element (@elements) { |
| 293 |
$element->show; |
| 294 |
} |
| 295 |
|
| 296 |
return '' if $this->goback; |
| 297 |
return 1; |
| 298 |
} |
| 299 |
|
| 300 |
sub progress_start { |
| 301 |
my $this=shift; |
| 302 |
$this->SUPER::progress_start(@_); |
| 303 |
|
| 304 |
$this->reset_assistant_page; |
| 305 |
|
| 306 |
my $element=$this->progress_bar; |
| 307 |
$this->assistant_page->pack_start($element->hbox, $element->fill, $element->expand, 0); |
| 308 |
# TODO: no backup support yet |
| 309 |
$this->configure_assistant_page; |
| 310 |
if ($this->assistant->get_current_page == $this->assistant->get_n_pages - 1) { |
| 311 |
$this->create_assistant_page(); |
| 312 |
} |
| 313 |
$this->assistant->set_page_complete($this->assistant_page, 0); |
| 314 |
$this->assistant->show_all; |
| 315 |
|
| 316 |
while (Gtk3::events_pending()) { |
| 317 |
Gtk3::main_iteration(); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
sub progress_set { |
| 322 |
my $this=shift; |
| 323 |
|
| 324 |
my $ret=$this->SUPER::progress_set(@_); |
| 325 |
|
| 326 |
while (Gtk3::events_pending()) { |
| 327 |
Gtk3::main_iteration(); |
| 328 |
} |
| 329 |
|
| 330 |
return $ret; |
| 331 |
} |
| 332 |
|
| 333 |
sub progress_info { |
| 334 |
my $this=shift; |
| 335 |
my $ret=$this->SUPER::progress_info(@_); |
| 336 |
|
| 337 |
while (Gtk3::events_pending()) { |
| 338 |
Gtk3::main_iteration(); |
| 339 |
} |
| 340 |
|
| 341 |
return $ret; |
| 342 |
} |
| 343 |
|
| 344 |
sub progress_stop { |
| 345 |
my $this=shift; |
| 346 |
$this->SUPER::progress_stop(@_); |
| 347 |
|
| 348 |
while (Gtk3::events_pending) { |
| 349 |
Gtk3::main_iteration; |
| 350 |
} |
| 351 |
|
| 352 |
if ($this->assistant->get_current_page == $this->assistant->get_n_pages - 1) { |
| 353 |
$this->create_assistant_page(); |
| 354 |
} |
| 355 |
# automatically go to the next page now |
| 356 |
$this->assistant->set_current_page($prev_page + 1); |
| 357 |
} |
| 358 |
|
| 359 |
=back |
| 360 |
|
| 361 |
=head1 AUTHOR |
| 362 |
|
| 363 |
Eric Gillespie <[email protected]> |
| 364 |
Gustavo Noronha Silva <[email protected]> |
| 365 |
|
| 366 |
=cut |
| 367 |
|
| 368 |
1 |