summaryrefslogtreecommitdiffstats
path: root/perl-install/interactive_gtk.pm
blob: 34e08d62f9b4ec9713c25448498171dbffd11aa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package interactive_gtk;

use diagnostics;
use strict;
use vars qw(@ISA);

@ISA = qw(interactive);

use interactive;
use common qw(:common :functional);
use my_gtk qw(:helpers :wrappers);

1;

#-#- redefine ask_warn
#-sub ask_warn {
#-    my $o = shift;
#-    local $my_gtk::grab = 1;
#-    $o->SUPER::ask_warn(@_);
#-}

sub ask_from_listW {
    my ($o, $title, $messages, $l, $def) = @_;

    my $w = my_gtk->new(first(deref($title)), %$o);
    $w->{retval} = $def || $l->[0]; #- nearly especially for the X test case (see timeout in Xconfigurator.pm)
    if (@$l < 5) { #- really ? : && sum(map { length $_ } @$l) < 90) {
	my $defW;
	my $f = sub { $w->{retval} = $_[1]; Gtk->main_quit };
	my $box = (@$l <= 2 && (map { split "\n" } @$messages) > 6) ?
	  gtkpack(new Gtk::VBox(0,0),
		  gtkset_usize(createScrolledWindow(gtktext_insert(new Gtk::Text, join "\n", @$messages)), 400, 250)) :
	  create_box_with_title($w, @$messages);
	gtkadd($w->{window},
	       gtkpack($box,
		       gtkadd((@$l < 3 ? create_hbox() : create_vbox()),
			      map {
				  my $b = new Gtk::Button($_);
				  $b->signal_connect(clicked => [ $f, $_ ]);
				  $_ eq $def and $defW = $b;
				  $b;
			      } @$l),
		       ),
	       );
	$defW->grab_focus if $defW;
	$w->main;
    } else {
	$w->_ask_from_list($title, $messages, $l, $def);
	$w->main;
    }
}

sub ask_many_from_list_refW($$$$$) {
    my ($o, $title, $messages, $list, $val) = @_;
    my $w = my_gtk->new('', %$o);
    my $box = gtkpack(new Gtk::VBox(0,0),
	map_index {
	    my $i = $::i;
	    my $o = Gtk::CheckButton->new($_);
	    $o->set_active(${$val->[$i]});
	    $o->signal_connect(clicked => sub { invbool \${$val->[$i]} });
	    $o;
	} @$list);
    gtkadd($w->{window},
	   gtkpack_(create_box_with_title($w, @$messages),
		   1, @$list > 11 ? gtkset_usize(createScrolledWindow($box), 0, 250) : $box,
		   0, $w->create_okcancel,
		  )
	  );
    $w->{ok}->grab_focus;
    $w->main && $val;
}


sub ask_from_entries_refW {
    my ($o, $title, $messages, $l, $val, %hcallback) = @_;
    my ($title_, @okcancel) = ref $title ? @$title : $title;
    my $num_fields = @{$l};
    my $ignore = 0; #-to handle recursivity

    my $w = my_gtk->new($title_, %$o);
    #-the widgets
    my @widgets = map {
	if ($_->{type} eq "list") {
	    my $w = new Gtk::Combo;
	    $w->set_use_arrows_always(1);
	    $w->entry->set_editable(!$_->{not_edit});
	    $w->set_popdown_strings(@{$_->{list}});
	    $w->disable_activate;
	    $_->{val} ||= $_->{list}[0];
	    $w;
	} elsif ($_->{type} eq "bool") {
	    my $w = Gtk::CheckButton->new($_->{text});
	    $w->set_active(${$_->{val}});
	    my $i = $_; $w->signal_connect(clicked => sub { $ignore or invbool \${$i->{val}} });
	    $w;
	} else {
	    new Gtk::Entry;
	}
    } @{$val};
    my $ok = $w->create_okcancel(@okcancel);

    sub widget {
	my ($w, $ref) = @_;
	($ref->{type} eq "list" && @{$ref->{list}}) ? $w->entry : $w
    }
    my @updates = mapn {
	my ($w, $ref) = @_;
	sub {
	    $ref->{type} eq "bool" and return;
	    ${$ref->{val}} = widget($w, $ref)->get_text;
	};
    } \@widgets, $val;

    my @updates_inv = mapn {
	my ($w, $ref) = @_;
	sub { 
	    $ref->{type} eq "bool" ? 
	      $w->set_active(${$ref->{val}}) :
	      widget($w, $ref)->set_text(${$ref->{val}})
	};
    } \@widgets, $val;


    for (my $i = 0; $i < $num_fields; $i++) {
	my $ind = $i; #-cos lexical bindings pb !!
	my $widget = widget($widgets[$i], $val->[$i]);
	my $changed_callback = sub {
	    return if $ignore; #-handle recursive deadlock
	    &{$updates[$ind]};
	    if ($hcallback{changed}) {
		&{$hcallback{changed}}($ind);
		#update all the value
		$ignore = 1;
		&$_ foreach @updates_inv;
		$ignore = 0;
	    };
	};
	if ($hcallback{focus_out}) {
	    my $focusout_callback = sub {
		return if $ignore;
		&{$hcallback{focus_out}}($ind);
		#update all the value
		$ignore = 1;
		&$_ foreach @updates_inv;
		$ignore = 0;
	    };
	    $widget->signal_connect(focus_out_event => $focusout_callback);
	}
	if (ref $widget eq "Gtk::Entry") {
	    $widget->signal_connect(changed => $changed_callback);
	    my $go_to_next = sub {
		if ($ind == ($num_fields -1)) {
		    $w->{ok}->grab_focus();
		} else {
		    widget($widgets[$ind+1],$val->[$ind+1])->grab_focus();
		}
	    };
	    $widget->signal_connect(activate => $go_to_next);
	    $widget->signal_connect(key_press_event => sub {
		my ($w, $e) = @_;
		#-don't know why it works, i believe that
		#-i must say before &$go_to_next, but with it doen't work HACK!
		$w->signal_emit_stop("key_press_event") if chr($e->{keyval}) eq "\x8d";
	    });
	    $widget->set_text(${$val->[$i]{val}})  if ${$val->[$i]{val}};
	    $widget->set_visibility(0) if $val->[$i]{hidden};
	}
	&{$updates[$i]};
    }

    my @entry_list = mapn { [($_[0], $_[1])]} $l, \@widgets;

    gtkadd($w->{window},
	   gtkpack(
		   create_box_with_title($w, @$messages),
		   create_packtable({}, @entry_list),
		   $ok
		   ));
    widget($widgets[0],$val->[0])->grab_focus();
    if ($hcallback{complete}) {
	my $callback = sub {
	    my ($error, $focus) = &{$hcallback{complete}};
	    #-update all the value
	    $ignore = 1;
	    foreach (@updates_inv) { &{$_};}
	    $ignore = 0;
	    if ($error) {
		$focus ||= 0;
		widget($widgets[$focus], $val->[$focus])->grab_focus();
	    } else {
		return 1;
	    }
	};
	#$w->{ok}->signal_connect(clicked => $callback)
	$w->main($callback);
    } else {
	$w->main();
    }
}


sub wait_messageW($$$) {
    my ($o, $title, $message) = @_;

    my $w = my_gtk->new($title, %$o, grab => 1);
    my $W = pop @$message;
    gtkadd($w->{window},
	   gtkpack(new Gtk::VBox(0,0),
		   @$message,
		   $w->{wait_messageW} = new Gtk::Label($W)));
    $w->sync;
    $w;
}
sub wait_message_nextW {
    my ($o, $message, $w) = @_;
    $w->{wait_messageW}->set($message);
    $w->sync;
}
sub wait_message_endW {
    my ($o, $w) = @_;
    $w->destroy;
}

sub kill {
    my ($o) = @_;
    $o->{before_killing} ||= 0;
    while (@interactive::objects > $o->{before_killing}) {
	my $w = pop @interactive::objects;
	$w->destroy;
    }
    @my_gtk::grabbed = ();
    $o->{before_killing} = @interactive::objects;
}
es{'default'} || 'default')); $combo{'boot'}->entry->set_text(member($thm_txt, @boot_thms) ? $thm_txt : ($themes{'default'} || 'default')); }); $combo{'lilo'}->entry->signal_connect(changed => sub { my $new_file = $themes{'path'} . $combo{'lilo'}->entry->get_text() . $themes{'lilo'}{'thumb'}; $lilo_pic->set(gtkcreate_png(-r $new_file ? $new_file : $themes{'def_thmb'})); }); $combo{'boot'}->entry->signal_connect( changed => sub { my $new_file = $themes{'path'}.$combo{'boot'}->entry->get_text().$themes{'boot'}{'thumb'}; if (! -f $new_file && -f $themes{'path'}.$combo{'boot'}->entry->get_text().$themes{'boot'}{'path'}."bootsplash-$cur_res.jpg"){ system("convert -scale 159x119 ".$themes{'path'}.$combo{'boot'}->entry->get_text().$themes{'boot'}{'path'}."bootsplash-$cur_res.jpg $new_file") and $in->ask_warn(_("Error"),_("Can't create Bootsplash preview")); } $boot_pic->set(gtkcreate_png(-r $new_file ? $new_file : $themes{'def_thmb'})); }); $combo{'thms'}->entry->set_text($themes{'default'}); $thm_button->signal_connect('clicked', sub { my $error = 0; my $boot_conf_file = '/etc/sysconfig/bootsplash'; my $lilomsg = '/boot/lilo-graphic/message'; #lilo installation if (-f $themes{'path'}.$combo{'lilo'}->entry->get_text() . $themes{'lilo'}{'file'}) { use File::Copy; ( copy($lilomsg,"/boot/lilo-graphic/message.old") and standalone::explanations(_("Backup %s to %s.old",$lilomsg,$lilomsg)) ) or $in->ask_warn(_("Error"), _("unable to backup lilo message")); ( copy($themes{'path'} . $combo{'lilo'}->entry->get_text() . $themes{'lilo'}{'file'}, $lilomsg) and standalone::explanations(_("Copy %s to %s",$themes{'path'} . $combo{'lilo'}->entry->get_text() . $themes{'lilo'}{'file'},$lilomsg)) ) or $in->ask_warn(_("Error"), _("can't change lilo message")); } else { $error = 1; $in->ask_warn(_("Error"), _("Lilo message not found")); } #bootsplash install if ( -f $themes{'path'} . $combo{'boot'}->entry->get_text() . $themes{'boot'}{'path'} . "bootsplash-$cur_res.jpg") { $bootsplash_cont = "# -*- Mode: shell-script -*- # Specify here if you want add the splash logo to initrd when # generating an initrd. You can specify : # # SPLASH=no to don't have a splash screen # # SPLASH=auto to make autodetect the splash screen # # SPLASH=INT When Integer could be 800x600 1024x768 1280x1024 # SPLASH=$cur_res # Choose the themes. The should be based in # /usr/share/bootsplash/themes/ THEME=" . $combo{'boot'}->entry->get_text() . " # Say yes here if you want to leave the logo on the console. # Three options : # # LOGO_CONSOLE=no don't display logo under console. # # LOGO_CONSOLE=yes display logo under console. # # LOGO_CONSOLE=theme leave the theme to decide. # LOGO_CONSOLE=" . ($keep_logo ? 'yes' : 'no') . "\n"; if (-f $boot_conf_file) { eval { output($boot_conf_file, $bootsplash_cont) }; $@ and $in->ask_warn(_("Error"), _("Can't write /etc/sysconfig/bootsplash.")) or standalone::explanations(_("Write %s",$boot_conf_file)); } else { $in->ask_warn(_("Error"), _("Can't write /etc/sysconfig/bootsplash\nFile not found.")); $error = 1; } } else { $in->ask_warn("Error","BootSplash screen not found"); } #here is mkinitrd time if (!$error) { foreach (map { if_(m|^initrd-(.*)\.img|, $1) } all('/boot')){ if ( system("mkinitrd -f /boot/initrd-$_.img $_" ) ) { $in->ask_warn(_("Error"), _("Can't launch mkinitrd -f /boot/initrd-%s.img %s.", $_,$_)); $error = 1; } else { standalone::explanations(_("Make initrd 'mkinitrd -f /boot/initrd-%s.img %s'.", $_,$_)); } } } if (system('lilo')) { $in->ask_warn(_("Error"), _("Can't relaunch LiLo! Launch \"lilo\" as root in command line to complete LiLo theme installation.")); $error = 1; } else { standalone::explanations(_("Relaunch 'lilo'")); } $in->ask_warn(_(($error)?"Error":"Notice"), _($error?"Theme installation failed!":"LiLo and Bootsplash themes installation successfull")); } ); gtkadd($window, gtkpack__ (my $global_vbox = new Gtk::VBox(0,0), gtkadd (new Gtk::Frame ("$disp_mode"), # gtkpack__(new Gtk::VBox(0,0), (gtkpack_(gtkset_border_width(new Gtk::HBox(0, 0),5), 1,_("You are currently using %s as your boot manager. Click on Configure to launch the setup wizard.", $lilogrub), 0,gtksignal_connect(new Gtk::Button (_("Configure")), clicked => $::lilo_choice), )), # "" #we need some place under the button -- replaced by gtkset_border_width( for the moment # ) ), #Splash Selector gtkadd(my $thm_frame = new Gtk::Frame( _("Splash selection") ), gtkpack__(gtkset_border_width(new Gtk::HBox(0,5),5), gtkpack__(new Gtk::VBox(0,5), _("Themes"), $combo{'thms'}, _("\nSelect a theme for\nlilo and bootsplash,\nyou can choose\nthem separatly"), $logo_thm), gtkpack__(new Gtk::VBox(0,5), _("Lilo screen"), $combo{'lilo'}, $lilo_pic, $B_create), gtkpack__(new Gtk::VBox(0,5), _("Bootsplash"), $combo{'boot'}, $boot_pic, $thm_button)) ), # aurora # gtkadd (new Gtk::Frame (_("Boot mode")), # gtkpack__ (new Gtk::HBox(0,0), # gtkpack__ (new Gtk::VBox(0, 5), # gtksignal_connect ($a_button, clicked => sub { # if ($inmain) { # $a_box->set_sensitive(!$a_mode); # $a_mode = !$a_mode; # if ($a_mode) { # $pixmap->set($c_pixmap, $c_mask) if $a_c_button->get_active(); # $pixmap->set($h_pixmap, $h_mask) if $a_h_button->get_active(); # $pixmap->set($v_pixmap, $v_mask) if $a_v_button->get_active(); # $pixmap->set($g_pixmap, $g_mask) if $a_g_button->get_active(); # } else { # $pixmap->set($t_pixmap, $t_mask); # } # } # }), # gtkpack__ (gtkset_sensitive ($a_box, $a_mode), # gtksignal_connect ($a_c_button,clicked => sub{$pixmap->set($c_pixmap, $c_mask)}), # gtksignal_connect ($a_h_button,clicked => sub{$pixmap->set($h_pixmap, $h_mask)}), # gtksignal_connect ($a_v_button,clicked => sub{$pixmap->set($v_pixmap, $v_mask)}), # gtksignal_connect ($a_g_button,clicked => sub{$pixmap->set($g_pixmap, $g_mask)}) # ) # ), # gtkpack__ (new Gtk::HBox(0,0), $pixmap) # ) # ), # X gtkadd (new Gtk::Frame (_("System mode")), gtkpack__ (new Gtk::VBox(0, 5), gtksignal_connect(gtkset_active(new Gtk::CheckButton (_("Launch the graphical environment when your system starts")), $x_mode), clicked => sub { $x_box->set_sensitive(!$x_mode); $x_mode = !$x_mode; }), gtkpack__ (gtkset_sensitive ($x_box, $x_mode), gtkset_active($x_no_button = new Gtk::RadioButton (_("No, I don't want autologin")), !$l_mode), gtkpack__ (new Gtk::HBox(0, 10), gtkset_active($x_yes_button = new Gtk::RadioButton((_("Yes, I want autologin with this (user, desktop)")), $x_no_button), $l_mode), gtkpack__ (new Gtk::VBox(0, 10), $user_combo, $desktop_combo ) ) ) ) ), gtkadd (gtkset_layout(new Gtk::HButtonBox,-end), gtksignal_connect(new Gtk::Button(_("OK")), clicked => sub{ updateInit(); updateAutologin(); updateAurora(); $::isEmbedded ? kill('USR1',$::CCPID) : Gtk->exit(0) }), gtksignal_connect(new Gtk::Button(_("Cancel")), clicked => sub { $::isEmbedded ? kill('USR1', $::CCPID) : Gtk->exit(0) }) ) ) ); $a_button->set_active($a_mode); # up == false == "0" if ($a_mode) { my $a = readlink "/etc/aurora/Monitor"; $a =~ s#/lib/aurora/Monitors/##; if ($a eq "NewStyle-Categorizing-WsLib") { $a_c_button->set_active(1); $pixmap->set($c_pixmap, $c_mask) } if ($a eq "NewStyle-WsLib") { $a_h_button->set_active(1); $pixmap->set($h_pixmap, $h_mask) } if ($a eq "Traditional-WsLib") { $a_v_button->set_active(1); $pixmap->set($v_pixmap, $v_mask) } if ($a eq "Traditional-Gtk+") { $a_g_button->set_active(1); $pixmap->set($g_pixmap, $g_mask) } } else { $pixmap->set($t_pixmap, $t_mask); } $window->show_all(); $no_bootsplash and $thm_frame->hide(); Gtk->main_iteration while Gtk->events_pending; $::isEmbedded and kill 'USR2', $::CCPID; $inmain=1; Gtk->main; Gtk->exit(0); #------------------------------------------------------------- # get user names to put in combo #------------------------------------------------------------- sub parse_etc_passwd { my ($uname, $uid); setpwent(); do { @user_info = getpwent(); ($uname, $uid) = @user_info[0,2];