summaryrefslogtreecommitdiffstats
path: root/perl-install/install_interactive.pm
blob: a486a13ecc6faa33cb6612f07c6ae751baaea2be (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
235
236
237
238
239
240
241
242
243
package install_interactive; # $Id$

use diagnostics;
use strict;

use vars;

use common qw(:common :functional);
use partition_table qw(:types);
use partition_table_raw;
use detect_devices;
use install_steps;
use devices;
use fsedit;
use log;
use fs;


sub tellAboutProprietaryModules {
    my ($o) = @_;
    my @l = grep {$_} map { $_->{driver} =~ /^Bad:(.*)/ && $1 } detect_devices::probeall();
    $o->ask_warn('', 
_("Some hardware on your computer needs ``proprietary'' drivers to work.
You can find some information about them at: %s", join(", ", @l))) if @l;
}

sub partition_with_diskdrake {
    my ($o, $hds, $nowizard) = @_;
    my $ok; 

    $o->set_help('partition_with_diskdrake');
    do {
	$ok = 1;
	require diskdrake;
	diskdrake::main($hds, $o->{lvms}, $o->{raid}, interactive_gtk->new, $nowizard);
	delete $o->{wizard} and return partitionWizard($o, 'nodiskdrake');
	my @fstab = fsedit::get_fstab(@$hds, @{$o->{lvms}}, $o->{raid});
	
	unless (fsedit::get_root_(\@fstab)) {
	    $ok = 0;
	    $o->ask_okcancel('', _("You must have a root partition.
For this, create a partition (or click on an existing one).
Then choose action ``Mount point'' and set it to `/'"), 1) or return;
	}
	if (!grep { isSwap($_) } @fstab) {
	    $o->ask_warn('', _("You must have a swap partition")), $ok=0 if !$::expert;
	    $ok &&= $::expert || $o->ask_okcancel('', _("You don't have a swap partition\n\nContinue anyway?"));
	}
    } until $ok;
    1;
}

sub partitionWizardSolutions {
    my ($o, $hds, $fstab, $readonly) = @_;
    my @wizlog;
    my (@solutions, %solutions);

    my $min_linux = 400 << 11;
    my $max_linux = 3000 << 11;
    my $min_swap = 50 << 11;
    my $max_swap = 300 << 11;
    my $min_freewin = 100 << 11;

    # each solution is a [ score, text, function ], where the function retunrs true if succeeded

    my @good_hds = grep { partition_table::can_raw_add($_) } @$hds;
    if (fsedit::free_space(@good_hds) > $min_linux and !$readonly) {
	$solutions{free_space} = [ 20, _("Use free space"), sub { fsedit::auto_allocate($hds); 1 } ]
    } else { 
	push @wizlog, _("Not enough free space to allocate new partitions") . ": " .
	  (@good_hds ? 
	   fsedit::free_space(@good_hds) . " < $min_linux" :
	   "no harddrive on which partitions can be added") if !$readonly;
    }

    if (my @truefs = grep { isTrueFS($_) } @$fstab) {
	#- value twice the ext2 partitions
	$solutions{existing_part} = [ 6 + @truefs + @$fstab, _("Use existing partition"), sub { $o->ask_mntpoint_s($fstab) } ]
    } else {
	push @wizlog, _("There is no existing partition to use");
    }

    my @fats = grep { isFat($_) } @$fstab;
    fs::df($_) foreach @fats;
    if (my @ok_forloopback = sort { $b->{free} <=> $a->{free} } grep { $_->{free} > $min_linux + $min_swap + $min_freewin } @fats) {
	$solutions{loopback} = 
	  [ -10 - @fats, _("Use the Windows partition for loopback"), 
	    sub { 
		my ($s_root, $s_swap);
		my $part = $o->ask_from_listf('', _("Which partition do you want to use for Linux4Win?"), \&partition_table_raw::description, \@ok_forloopback) or return;
		$max_swap = $min_swap + 1 if $part->{free} - $max_swap < $min_linux;
		$o->ask_from_entries_refH('', _("Choose the sizes"), [ 
		   { label => _("Root partition size in MB: "), val => \$s_root, min => $min_linux >> 11, max => min($part->{free} - $max_swap, $max_linux) >> 11, type => 'range' },
		   { label => _("Swap partition size in MB: "), val => \$s_swap, min => $min_swap >> 11,  max => $max_swap >> 11, type => 'range' },
		]) or return;
		push @{$part->{loopback}}, 
		  { type => 0x83, loopback_file => '/lnx4win/linuxsys.img', mntpoint => '/',    size => $s_root << 11, device => $part, notFormatted => 1 },
		  { type => 0x82, loopback_file => '/lnx4win/swapfile',     mntpoint => 'swap', size => $s_swap << 11, device => $part, notFormatted => 1 };
		1;
	    } ];
	$solutions{resize_fat} = 
	  [ 6 - @fats, _("Use the free space on the Windows partition"),
	    sub {
		$o->set_help('resizeFATChoose');
		my $part = $o->ask_from_listf('', _("Which partition do you want to resize?"), \&partition_table_raw::description, \@ok_forloopback) or return;
		$o->set_help('resizeFATWait');
		my $w = $o->wait_message(_("Resizing"), _("Computing Windows filesystem bounds"));
		require resize_fat::main;
		my $resize_fat = eval { resize_fat::main->new($part->{device}, devices::make($part->{device})) };
		$@ and die _("The FAT resizer is unable to handle your partition, 
the following error occured: %s", $@);
		my $min_win = $resize_fat->min_size;
		$part->{size} > $min_linux + $min_swap + $min_freewin + $min_win or die _("Your Windows partition is too fragmented, please run ``defrag'' first");
		$o->ask_okcancel('', _("WARNING!

DrakX will now resize your Windows partition. Be careful: this operation is
dangerous. If you have not already done so, you should first exit the
installation, run scandisk under Windows (and optionally run defrag), then
restart the installation. You should also backup your data.
When sure, press Ok.")) or return;

		my $size = $part->{size};
		$o->ask_from_entries_refH('', _("Which size do you want to keep for windows on"), [
                   { label => _("partition %s", partition_table_raw::description($part)), val => \$size, min => $min_win >> 11, max => ($part->{size} - $min_linux - $min_swap) >> 11, type => 'range' },
                ]) or return;
		$size <<= 11;

		local *log::l = sub { $w->set(join(' ', @_)) };
		eval { $resize_fat->resize($size) };
		$@ and die _("FAT resizing failed: %s", $@);

		$part->{size} = $size;
		$part->{isFormatted} = 1;
		
		my ($hd) = grep { $_->{device} eq $part->{rootDevice} } @$hds;
		$hd->{isDirty} = $hd->{needKernelReread} = 1;
		$hd->adjustEnd($part);
		partition_table::adjust_local_extended($hd, $part);
		partition_table::adjust_main_extended($hd);

		fsedit::auto_allocate($hds);
		1;
	    } ] if !$readonly;
    } else {
	push @wizlog, _("There is no FAT partitions to resize or to use as loopback (or not enough space left)") .
	  @fats ? "\nFAT partitions:" . join('', map { "\n  $_->{device} $_->{free} (" . ($min_linux + $min_swap + $min_freewin) . ")" } @fats) : '';
    }

    if (@$fstab && !$readonly) {
	$solutions{wipe_drive} =
	  [ 10, fsedit::is_one_big_fat($hds) ? _("Remove Windows(TM)") : _("Erase entire disk"), 
	    sub {
		$o->set_help('takeOverHdChoose');
		my $hd = $o->ask_from_listf('', _("You have more than one hard drive, which one do you install linux on?"),
					    \&partition_table_raw::description, $hds) or return;
		$o->set_help('takeOverHdConfirm');
		$o->ask_okcancel('', _("ALL existing partitions and their data will be lost on drive %s", partition_table_raw::description($hd))) or return;
		partition_table_raw::zero_MBR($hd);
		fsedit::auto_allocate($hds);
		1;
	    } ];
    }

    if (!$readonly && ref($o) =~ /gtk/) { #- diskdrake only available in gtk for now
	$solutions{diskdrake} = [ 0, _("Custom disk partitioning"), sub { partition_with_diskdrake($o, $hds, 'nowizard') } ];
    }

    $solutions{fdisk} =
      [ -10, _("Use fdisk"), sub { 
	    $o->enter_console;
	    foreach (@$hds) {
		print "\n" x 10, _("You can now partition %s.
When you are done, don't forget to save using `w'", partition_table_raw::description($_));
		print "\n\n";
		my $pid = 0;
		if (arch() =~ /ppc/) {
			$pid = fork or exec "pdisk", devices::make($_->{device});
		} else {
			$pid = fork or exec "fdisk", devices::make($_->{device});
		}			
		waitpid($pid, 0);
	    }
	    $o->leave_console;
	    0;
	} ] if $o->{partitioning}{fdisk};

    log::l("partitioning wizard log:\n", (map { ">>wizlog>>$_\n" } @wizlog));
    %solutions;
}

sub partitionWizard {
    my ($o, $nodiskdrake) = @_;

    $o->set_help('doPartitionDisks');

    my %solutions = partitionWizardSolutions($o, $o->{hds}, $o->{fstab}, $o->{partitioning}{readonly});
    if ($o->{lnx4win}) {
	if ($solutions{loopback}) {
	    %solutions = (loopback => $solutions{loopback});
	} else {
	    $o->ask_warn('', _("You don't have enough free space on your Windows partition")) if grep { isFat($_) } @{$o->{fstab}}
	}
    }

    delete $solutions{diskdrake} if $nodiskdrake;

    my @solutions = sort { $b->[0] <=> $a->[0] } values %solutions;

    my $level = $::expert ? -9999 : 0;
    my @sol = grep { $_->[0] >= $level } @solutions;

    log::l(      "solutions found: " . join('', map {$_->[1]} @sol) . 
	   " (all solutions found: " . join('', map {$_->[1]} @solutions) . ")");

    @solutions = @sol if @sol > 1;
    log::l("solutions: ", int @solutions);
    @solutions or $o->ask_warn('', _("I can't find any room for installing")), die 'already displayed';

    my $ok; while (!$ok) {
	log::l('HERE: ', join(',', map { $_->[1] } @solutions));
	my $sol = $o->ask_from_listf('', _("The DrakX Partitioning wizard found the following solutions:"), sub { $_[0][1] }, \@solutions) or redo;
	log::l("partitionWizard calling solution $sol->[1]");
	eval { $ok = $sol->[2]->() };
	die if $@ =~ /setstep/;
	$ok &&= !$@;
	$@ and $o->ask_warn('', _("Partitioning failed: %s", $@));
    }
}

sub upNetwork {
    my ($o, $pppAvoided) = @_;
    my $w = $o->wait_message('', _("Bringing up the network"));
    install_steps::upNetwork($o, $pppAvoided);
}
sub downNetwork {
    my ($o, $pppOnly) = @_;
    my $w = $o->wait_message('', _("Bringing down the network"));
    install_steps::downNetwork($o, $pppOnly);
}



1;
>@_); } sub gtkpack2__($@) { my $box = shift; gtkpack2_($box, map {; 0, $_ } @_); } sub gtkpack3 { my $a = shift; $a && goto \&gtkpack2__; goto \&gtkpack2; } sub gtkpack2_($@) { my $box = shift; for (my $i = 0; $i < @_; $i += 2) { my $l = $_[$i + 1]; ref $l or $l = new Gtk::Label($l); $box->pack_start($l, $_[$i], 0, 0); $l->show; } $box } sub gtksetstyle { my ($w, $s) = @_; $w->set_style($s); $w; } sub gtkset_tip { my ($tips, $w, $tip) = @_; $tips->set_tip($w, $tip) if $tip; } sub gtkappenditems { my $w = shift; map {gtkshow($_) } @_; $w->append_items(@_); $w } sub gtkappend($@) { my $w = shift; foreach (@_) { my $l = $_; ref $l or $l = new Gtk::Label($l); $w->append($l); $l->show; } $w } sub gtkset_shadow_type { $_[0]->set_shadow_type($_[1]); $_[0]; } sub gtkset_layout { $_[0]->set_layout($_[1]); $_[0]; } sub gtkadd($@) { my $w = shift; foreach (@_) { my $l = $_; ref $l or $l = new Gtk::Label($l); $w->add($l); $l->show; } $w } sub gtkput { my ($w, $w2, $x, $y) = @_; $w->put($w2, $x, $y); $w2->show; $w } sub gtktext_insert { my ($w, $t) = @_; $w->freeze; $w->backward_delete($w->get_length); $w->insert(undef, undef, undef, $t); #- DEPRECATED? needs \n otherwise in case of one line text the beginning is not shown (even with the vadj->set_value) $w->set_word_wrap(1); #- $w->vadj->set_value(0); $w->thaw; $w; } sub gtkroot { Gtk->init; Gtk->set_locale; Gtk::Gdk::Window->new_foreign(Gtk::Gdk->ROOT_WINDOW); } sub gtkcolor($$$) { my ($r, $g, $b) = @_; my $color = bless { red => $r, green => $g, blue => $b }, 'Gtk::Gdk::Color'; gtkroot()->get_colormap->color_alloc($color); } sub gtkset_mousecursor { my ($type, $w) = @_; ($w || gtkroot())->set_cursor(Gtk::Gdk::Cursor->new($type)); } sub gtkset_mousecursor_normal { gtkset_mousecursor(68, @_) } sub gtkset_mousecursor_wait { gtkset_mousecursor(150, @_) } sub gtkset_background { my ($r, $g, $b) = @_; my $root = gtkroot(); my $gc = Gtk::Gdk::GC->new($root); my $color = gtkcolor($r, $g, $b); $gc->set_foreground($color); $root->set_background($color); my ($h, $w) = $root->get_size; $root->draw_rectangle($gc, 1, 0, 0, $w, $h); } sub gtkset_default_fontset { my ($fontset) = @_; my $style = Gtk::Widget->get_default_style; my $f = Gtk::Gdk::Font->fontset_load($fontset) or die ''; $style->font($f); Gtk::Widget->set_default_style($style); } sub gtkctree_children { my ($node) = @_; my @l; $node or return; for (my $p = $node->row->children; $p; $p = $p->row->sibling) { push @l, $p; } @l; } sub gtkcreate_xpm { my ($w, $f) = @_; my @l = Gtk::Gdk::Pixmap->create_from_xpm($w->window, $w->style->bg('normal'), $f) or die "gtkcreate_xpm: missing pixmap file $f"; @l; } sub gtkcreate_png { my ($f) = @_; $f =~ m|.png$| or $f="$f.png"; if ( $f !~ /\//) { -e "$_/$f" and $f="$_/$f", last foreach $ENV{SHARE_PATH}, "$ENV{SHARE_PATH}/libDrakX/pixmaps", "pixmaps" } my $im = Gtk::Gdk::ImlibImage->load_image($f) or die "gtkcreate_png: missing png file $f"; $im->render($im->rgb_width, $im->rgb_height); ($im->move_image(), $im->move_mask); } sub xpm_d { my $w = shift; Gtk::Gdk::Pixmap->create_from_xpm_d($w->window, undef, @_) } sub gtkxpm { new Gtk::Pixmap(gtkcreate_xpm(@_)) } sub gtkpng { new Gtk::Pixmap(gtkcreate_png(@_)) } #-############################################################################### #- createXXX functions #- these functions return a widget #-############################################################################### sub create_okcancel { my ($w, $ok, $cancel, $spread, @other) = @_; my $one = ($ok xor $cancel); $spread ||= $::isWizard ? "end" : "spread"; $ok ||= $::isWizard ? ($::Wizard_finished ? _("Finish") : _("Next ->")) : _("Ok"); $cancel ||= $::isWizard ? _("<- Previous") : _("Cancel"); my $b1 = gtksignal_connect($w->{ok} = new Gtk::Button($ok), clicked => $w->{ok_clicked} || sub { $w->{retval} = 1; Gtk->main_quit }); my $b2 = !$one && gtksignal_connect($w->{cancel} = new Gtk::Button($cancel), clicked => $w->{cancel_clicked} || sub { log::l("default cancel_clicked"); undef $w->{retval}; Gtk->main_quit }); $::isWizard and gtksignal_connect($w->{wizcancel} = new Gtk::Button(_("Cancel")), clicked => sub { die 'wizcancel' }); my @l = grep { $_ } $::isWizard ? ($w->{wizcancel}, $::Wizard_no_previous ? () : $b2, $b1): ($b1, $b2); push @l, map { gtksignal_connect(new Gtk::Button($_->[0]), clicked => $_->[1]) } @other; $_->can_default($::isWizard) foreach @l; gtkadd(create_hbox($spread), @l); } sub create_box_with_title($@) { my $o = shift; $o->{box_size} = sum(map { round(length($_) / 60 + 0.5) } map { split "\n" } @_); $o->{box} = new Gtk::VBox(0,0); $o->{icon} and eval { gtkpack__($o->{box}, gtkset_border_width(gtkpack_(new Gtk::HBox(0,0), 1, gtkpng($o->{icon})),5)); }; if (@_ <= 2 && $o->{box_size} > 4) { my $font = $o->{box}->style->font; my $wanted = $o->{box_size} * ($font->ascent + $font->descent) + 7; my $height = min(250, $wanted); my $has_scroll = $height < $wanted; my $wtext = new Gtk::Text; $wtext->can_focus($has_scroll); chomp(my $text = join("\n", @_)); my $scroll = createScrolledWindow(gtktext_insert($wtext, $text)); $scroll->set_usize(400, $height); gtkpack__($o->{box}, $scroll); } else { my $a = !$::no_separator; undef $::no_separator; gtkpack__($o->{box}, (map { my $w = ref $_ ? $_ : new Gtk::Label($_); $w->set_name("Title"); $w; } map { ref $_ ? $_ : warp_text($_) } @_), if_($a, new Gtk::HSeparator) ); } } sub createScrolledWindow { my ($W) = @_; my $w = new Gtk::ScrolledWindow(undef, undef); $w->set_policy('automatic', 'automatic'); member(ref $W, qw(Gtk::CList Gtk::CTree Gtk::Text)) ? $w->add($W) : $w->add_with_viewport($W); $W->can("set_focus_vadjustment") and $W->set_focus_vadjustment($w->get_vadjustment); $W->show; $w } sub create_menu($@) { my $title = shift; my $w = new Gtk::MenuItem($title); $w->set_submenu(gtkshow(gtkappend(new Gtk::Menu, @_))); $w } sub add2notebook { my ($n, $title, $book) = @_; my ($w1, $w2) = map { new Gtk::Label($_) } $title, $title; $book->{widget_title} = $w1; $n->append_page_menu($book, $w1, $w2); $book->show; $w1->show; $w2->show; } sub create_notebook(@) { my $n = new Gtk::Notebook; add2notebook($n, splice(@_, 0, 2)) while @_; $n } sub create_adjustment($$$) { my ($val, $min, $max) = @_; new Gtk::Adjustment($val, $min, $max + 1, 1, ($max - $min + 1) / 10, 1); } sub create_packtable($@) { my ($options, @l) = @_; my $w = new Gtk::Table(0, 0, $options->{homogeneous} || 0); map_index { my ($i, $l) = ($_[0], $_); map_index { my ($j) = @_; if ($_) { ref $_ or $_ = new Gtk::Label($_); $j != $#$l ? $w->attach($_, $j, $j + 1, $i, $i + 1, 'fill', 'fill', 5, 0) : $w->attach($_, $j, $j + 1, $i, $i + 1, 1|4, ref($_) eq 'Gtk::ScrolledWindow' ? 1|4 : 0, 0, 0); $_->show; } } @$l; } @l; $w->set_col_spacings($options->{col_spacings} || 0); $w->set_row_spacings($options->{row_spacings} || 0); $w } sub create_hbox { my $w = new Gtk::HButtonBox; $w->set_layout($_[0] || "spread"); $w; } sub create_vbox { my $w = new Gtk::VButtonBox; $w->set_layout(-spread); $w; } sub _create_window($$) { my ($o, $title) = @_; my $w = new Gtk::Window; my $f = new Gtk::Frame(undef); $w->set_name("Title"); gtkadd($w, $f); $w->set_title($title); $w->signal_connect(expose_event => sub { eval { $interactive::objects[-1]{rwindow} == $w and $w->window->XSetInputFocus } }) if $my_gtk::force_focus || $o->{force_focus}; $w->signal_connect(delete_event => sub { $w->destroy; die 'wizcancel' }); $w->set_uposition(@{$my_gtk::force_position || $o->{force_position}}) if $my_gtk::force_position || $o->{force_position}; $w->signal_connect(focus => sub { Gtk->idle_add(sub { $w->ensure_focus($_[0]); 0 }, $_[1]) }) if $w->can('ensure_focus'); if ($::o->{mouse}{unsafe}) { $w->set_events("pointer_motion_mask"); my $signal; $signal = $w->signal_connect(motion_notify_event => sub { delete $::o->{mouse}{unsafe}; log::l("unsetting unsafe mouse"); $w->signal_disconnect($signal); }); } $w->signal_connect(key_press_event => sub { my $d = ${{ 65470 => 'help', 65481 => 'next', 65480 => 'previous' }}{$_[1]{keyval}}; if ($d eq "help") { require install_gtk; install_gtk::create_big_help($::o); } elsif (chr($_[1]{keyval}) eq 'e' && $_[1]{state} & 8) { log::l("Switching to " . ($::expert ? "beginner" : "expert")); $::expert = !$::expert; } elsif ($d) { #- previous field is created here :( my $s; foreach (reverse @{$::o->{orderedSteps}}) { $s->{previous} = $_ if $s; $s = $::o->{steps}{$_}; } $s = $::o->{step}; do { $s = $::o->{steps}{$s}{$d} } until !$s || $::o->{steps}{$s}{reachable}; $::setstep && $s and die "setstep $s\n"; } });# if $::isInstall; $w->signal_connect(size_allocate => sub { my ($wi, $he) = @{$_[1]}[2,3]; my ($X, $Y, $Wi, $He) = @{$my_gtk::force_center || $o->{force_center}}; $w->set_uposition(max(0, $X + ($Wi - $wi) / 2), max(0, $Y + ($He - $he) / 2)); }) if ($my_gtk::force_center || $o->{force_center}) && !($my_gtk::force_position || $o->{force_position}) ; $o->{window} = $f; $o->{rwindow} = $w; } my ($next_child, $left, $right, $up, $down); { my $next_child = sub { my ($c, $dir) = @_; my @childs = $c->parent->children; my $i; for ($i = 0; $i < @childs; $i++) { last if $childs[$i] == $c || $childs[$i]->subtree == $c; } $i += $dir; 0 <= $i && $i < @childs ? $childs[$i] : undef; }; $left = sub { &$next_child($_[0]->parent, 0); }; $right = sub { my ($c) = @_; if ($c->subtree) { $c->expand; ($c->subtree->children)[0]; } else { $c; } }; $down = sub { my ($c) = @_; return &$right($c) if ref $c eq "Gtk::TreeItem" && $c->subtree && $c->expanded; if (my $n = &$next_child($c, 1)) { $n; } else { return if ref $c->parent ne 'Gtk::Tree'; &$down($c->parent); } }; $up = sub { my ($c) = @_; if (my $n = &$next_child($c, -1)) { $n = ($n->subtree->children)[-1] while ref $n eq "Gtk::TreeItem" && $n->subtree && $n->expanded; $n; } else { return if ref $c->parent ne 'Gtk::Tree'; &$left($c); } }; } sub create_treeitem($) { my ($name) = @_; my $w = new Gtk::TreeItem($name); $w->signal_connect(key_press_event => sub { my (undef, $e) = @_; local $_ = chr ($e->{keyval}); if ($e->{keyval} > 0x100) { my $n; $n = &$left($w) if /[Q´\x96]/; $n = &$right($w) if /[S¶\x98]/; $n = &$up($w) if /[R¸\x97]/; $n = &$down($w) if /[T²\x99]/; if ($n) { $n->focus('up'); $w->signal_emit_stop("key_press_event"); } $w->expand if /[+«]/; $w->collapse if /[-\xad]/; do { $w->expanded ? $w->collapse : $w->expand; $w->signal_emit_stop("key_press_event"); } if /[\r\x8d]/; } 1; }); $w; } #-############################################################################### #- ask_XXX #- just give a title and some args, and it will return the value given by the user #-############################################################################### sub ask_warn { my $w = my_gtk->new(shift @_); $w->_ask_warn(@_); main($w); } sub ask_yesorno { my $w = my_gtk->new(shift @_); $w->_ask_okcancel(@_, _("Yes"), _("No")); main($w); } sub ask_okcancel { my $w = my_gtk->new(shift @_); $w->_ask_okcancel(@_, _("Is this correct?"), _("Ok"), _("Cancel")); main($w); } sub ask_from_entry { my $w = my_gtk->new(shift @_); $w->_ask_from_entry(@_); main($w); } sub ask_file { my $w = my_gtk->new(''); $w->_ask_file(@_); main($w); } sub _ask_from_entry($$@) { my ($o, @msgs) = @_; my $entry = new Gtk::Entry; my $f = sub { $o->{retval} = $entry->get_text; Gtk->main_quit }; $o->{ok_clicked} = $f; $o->{cancel_clicked} = sub { undef $o->{retval}; Gtk->main_quit }; gtkadd($o->{window}, gtkpack($o->create_box_with_title(@msgs), gtksignal_connect($entry, 'activate' => $f), ($o->{hide_buttons} ? () : create_okcancel($o))), ); $entry->grab_focus; } sub _ask_warn($@) { my ($o, @msgs) = @_; gtkadd($o->{window}, gtkpack($o->create_box_with_title(@msgs), gtksignal_connect(my $w = new Gtk::Button(_("Ok")), "clicked" => sub { Gtk->main_quit }), ), ); $w->grab_focus; } sub _ask_okcancel($@) { my ($o, @msgs) = @_; my ($ok, $cancel) = splice @msgs, -2; gtkadd($o->{window}, gtkpack(create_box_with_title($o, @msgs), create_okcancel($o, $ok, $cancel), ) ); $o->{ok}->grab_focus; } sub _ask_file { my ($o, $title, $path) = @_; my $f = $o->{rwindow} = new Gtk::FileSelection $title; $f->set_filename($path); $f->ok_button->signal_connect(clicked => sub { $o->{retval} = $f->get_filename ; Gtk->main_quit }); $f->cancel_button->signal_connect(clicked => sub { Gtk->main_quit }); $f->hide_fileop_buttons; } #-############################################################################### #- rubbish #-############################################################################### #-sub label_align($$) { #- my $w = shift; #- local $_ = shift; #- $w->set_alignment(!/W/i, !/N/i); #- $w #-}