summaryrefslogtreecommitdiffstats
path: root/perl-install/interactive/gtk.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2007-04-25 12:26:16 +0000
committerPascal Rigaux <pixel@mandriva.com>2007-04-25 12:26:16 +0000
commit126777bc019a54afb4ec51299f2cf9d2841698aa (patch)
tree97f76e571902ead55ba138f1156a4b4f00b9b779 /perl-install/interactive/gtk.pm
parentf1f67448efc714873378dfeb8279fae68054a90a (diff)
downloaddrakx-126777bc019a54afb4ec51299f2cf9d2841698aa.tar
drakx-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.gz
drakx-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.bz2
drakx-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.xz
drakx-126777bc019a54afb4ec51299f2cf9d2841698aa.zip
re-sync after the big svn loss
Diffstat (limited to 'perl-install/interactive/gtk.pm')
-rw-r--r--perl-install/interactive/gtk.pm830
1 files changed, 450 insertions, 380 deletions
diff --git a/perl-install/interactive/gtk.pm b/perl-install/interactive/gtk.pm
index e024fc54f..335bdda41 100644
--- a/perl-install/interactive/gtk.pm
+++ b/perl-install/interactive/gtk.pm
@@ -15,11 +15,16 @@ use Gtk2::Gdk::Keysyms;
my $forgetTime = 1000; #- in milli-seconds
sub new {
- ($::windowwidth, $::windowheight) = gtkroot()->get_size if !$::isInstall;
- goto &interactive::new;
+ my $w = &interactive::new;
+ ($w->{windowwidth}, $w->{windowheight}) = gtkroot()->get_size if !$::isInstall;
+ $w;
}
sub enter_console { my ($o) = @_; $o->{suspended} = common::setVirtual(1) }
sub leave_console { my ($o) = @_; common::setVirtual(delete $o->{suspended}) }
+sub adapt_markup {
+ #- nothing needed, the default markup is gtk2's
+ my ($_o, $s) = @_; return $s;
+}
sub exit { ugtk2::exit(@_) }
@@ -38,7 +43,7 @@ sub ask_fileW {
}
sub create_boxradio {
- my ($e, $may_go_to_next, $changed, $double_click) = @_;
+ my ($e, $onchange_f, $double_click) = @_;
my $boxradio = gtkpack2__(Gtk2::VBox->new(0, 0),
my @radios = gtkradio('', @{$e->{formatted_list}}));
@@ -47,13 +52,11 @@ sub create_boxradio {
my ($txt, $w) = @_;
$w->signal_connect(button_press_event => $double_click) if $double_click;
- $w->signal_connect(key_press_event => sub {
- &$may_go_to_next;
+ $w->signal_connect(key_press_event => $e->{may_go_to_next});
+ $w->signal_connect(clicked => sub {
+ ${$e->{val}} ne $txt or return;
+ $onchange_f->(sub { $txt });
});
- $w->signal_connect(clicked => sub {
- ${$e->{val}} = $txt;
- &$changed;
- });
if ($e->{help}) {
gtkset_tip($tips, $w,
ref($e->{help}) eq 'HASH' ? $e->{help}{$txt} :
@@ -71,7 +74,7 @@ sub create_boxradio {
}
sub create_treeview_list {
- my ($e, $may_go_to_next, $changed, $double_click) = @_;
+ my ($e, $onchange_f, $double_click) = @_;
my $curr;
my $list = Gtk2::ListStore->new("Glib::String");
@@ -97,7 +100,7 @@ sub create_treeview_list {
Glib::Source->remove($timeout) if $timeout; $timeout = '';
if ($event->keyval >= 0x100) {
- &$may_go_to_next if member($event->keyval, ($Gtk2::Gdk::Keysyms{Return}, $Gtk2::Gdk::Keysyms{KP_Enter}));
+ $e->{may_go_to_next}(), return 1 if member($event->keyval, ($Gtk2::Gdk::Keysyms{Return}, $Gtk2::Gdk::Keysyms{KP_Enter}));
$starting_word = '' if !member($event->keyval, ($Gtk2::Gdk::Keysyms{Control_L}, $Gtk2::Gdk::Keysyms{Control_R}));
} else {
if (member('control-mask', @{$event->state})) {
@@ -105,7 +108,7 @@ sub create_treeview_list {
$start_reg and $start_reg = '', return 1;
$curr++;
} else {
- &$may_go_to_next if $c eq ' ';
+ $e->{may_go_to_next}(), return 1 if $c eq ' ';
$curr++ if $starting_word eq '' || $starting_word eq $c;
$starting_word .= $c unless $starting_word eq $c;
@@ -132,9 +135,10 @@ sub create_treeview_list {
$list_tv->get_selection->signal_connect(changed => sub {
my ($model, $iter) = $_[0]->get_selected;
$model && $iter or return;
- my $row = $model->get_path_str($iter);
- ${$e->{val}} = $e->{list}[$curr = $row];
- &$changed;
+ $onchange_f->(sub {
+ my $row = $model->get_path_str($iter);
+ $e->{list}[$curr = $row];
+ });
});
$list_tv->signal_connect(button_press_event => $double_click) if $double_click;
@@ -193,7 +197,7 @@ sub __create_tree_model {
}
sub create_treeview_tree {
- my ($e, $may_go_to_next, $changed, $double_click, $tree_expanded) = @_;
+ my ($e, $onchange_f, $double_click) = @_;
my $tree_model = __create_tree_model($e);
my $tree = Gtk2::TreeView->new_with_model($tree_model);
@@ -220,7 +224,7 @@ sub create_treeview_tree {
};
my $curr = $tree_model->get_iter_first; #- default value
- $tree->expand_all if $tree_expanded;
+ $tree->expand_all if $e->{tree_expanded};
my $selected_via_click;
@@ -230,10 +234,11 @@ sub create_treeview_tree {
undef $curr if ref $curr;
my $path = $tree_model->get_path($curr = $iter);
if (!$tree_model->iter_has_child($iter)) {
- my $path_str = $path->to_string;
- my $i = find_index { $path_str eq $_ } @{$tree_model->{path_str_list}};
- ${$e->{val}} = $e->{list}[$i];
- &$changed;
+ $onchange_f->(sub {
+ my $path_str = $path->to_string;
+ my $i = find_index { $path_str eq $_ } @{$tree_model->{path_str_list}};
+ $e->{list}[$i];
+ });
} else {
$tree->expand_row($path, 0) if $selected_via_click;
}
@@ -246,7 +251,7 @@ sub create_treeview_tree {
$tree->toggle_expansion($tree_model->get_path($curr), 0);
} else {
- &$may_go_to_next;
+ &{$e->{may_go_to_next}};
}
};
@@ -259,7 +264,7 @@ sub create_treeview_tree {
Glib::Source->remove($timeout) if $timeout; $timeout = '';
if ($event->keyval >= 0x100) {
- &$toggle if member($event->keyval, ($Gtk2::Gdk::Keysyms{Return}, $Gtk2::Gdk::Keysyms{KP_Enter}));
+ &$toggle and return 1 if member($event->keyval, ($Gtk2::Gdk::Keysyms{Return}, $Gtk2::Gdk::Keysyms{KP_Enter}));
$starting_word = '' if !member($event->keyval, ($Gtk2::Gdk::Keysyms{Control_L}, $Gtk2::Gdk::Keysyms{Control_R}));
} else {
my $next;
@@ -268,7 +273,7 @@ sub create_treeview_tree {
$start_reg and $start_reg = '', return 0;
$next = 1;
} else {
- &$toggle if $c eq ' ';
+ &$toggle and return 1 if $c eq ' ';
$next = 1 if $starting_word eq '' || $starting_word eq $c;
$starting_word .= $c unless $starting_word eq $c;
}
@@ -322,50 +327,6 @@ sub create_treeview_tree {
};
}
-sub create_list {
- my ($e, $may_go_to_next, $changed, $double_click) = @_;
- my $l = $e->{list};
- my $list = Gtk2::List->new;
- $list->set_selection_mode('browse');
-
- my $select = sub {
- $list->select_item($_[0]);
- };
-
- my $tips = Gtk2::Tooltips->new;
- each_index {
- my $item = Gtk2::ListItem->new(may_apply($e->{format}, $_));
- $item->signal_connect(key_press_event => sub {
- my ($_w, $event) = @_;
- my $c = chr($event->keyval & 0xff);
- &$may_go_to_next if $event->keyval < 0x100 ? $c eq ' ' : $c eq "\r" || $c eq "\x8d";
- 0;
- });
- $list->append_items(gtkshow($item));
- if ($e->{help}) {
- gtkset_tip($tips, $item,
- ref($e->{help}) eq 'HASH' ? $e->{help}{$_} :
- ref($e->{help}) eq 'CODE' ? $e->{help}($_) : $e->{help});
- }
- $item->grab_focus if ${$e->{val}} && $_ eq ${$e->{val}};
- } @$l;
-
- #- signal_connect'ed after append_items otherwise it is called and destroys the default value
- $list->signal_connect(select_child => sub {
- my ($_w, $row) = @_;
- ${$e->{val}} = $l->[$list->child_position($row)];
- &$changed;
- });
- $list->signal_connect(button_press_event => $double_click) if $double_click;
-
- $list, sub {
- my ($v) = @_;
- eval {
- $select->(find_index { $_ eq $v } @$l);
- };
- };
-}
-
#- $actions is a ref list of $action
#- $action is a { kind => $kind, action => sub { ... }, button => Gtk2::Button->new(...) }
#- where $kind is one of '', 'modify', 'remove', 'add'
@@ -389,365 +350,447 @@ sub add_modify_remove_action {
1;
}
-sub add_modify_remove_sensitive {
- my ($buttons, $e) = @_;
- $_->{button}->set_sensitive(@{$e->{list}} != ()) foreach
- grep { member($_->{kind}, 'modify', 'remove') } @$buttons;
+sub create_widget {
+ my ($o, $e, $onchange_f, $update, $ignore_ref) = @_;
+
+ my $onchange = sub {
+ my ($f) = @_;
+ sub { $onchange_f->($f, @_) };
+ };
+
+ my ($w, $real_w, $focus_w, $set);
+ if ($e->{type} eq 'iconlist') {
+ $w = Gtk2::Button->new;
+ $set = sub {
+ gtkdestroy($e->{icon});
+ my $f = $e->{icon2f}->($_[0]);
+ $e->{icon} = -e $f ?
+ gtkcreate_img($f) :
+ Gtk2::WrappedLabel->new(may_apply($e->{format}, $_[0]));
+ $w->add(gtkshow($e->{icon}));
+ };
+ $w->signal_connect(clicked => sub {
+ $onchange_f->(sub { next_val_in_array(${$e->{val}}, $e->{list}) });
+ $set->(${$e->{val}});
+ });
+ $real_w = gtkpack_(Gtk2::HBox->new(0,10), 1, Gtk2::HBox->new(0,0), 0, $w, 1, Gtk2::HBox->new(0,0));
+ } elsif ($e->{type} eq 'bool') {
+ if ($e->{image}) {
+ $w = ugtk2::gtkadd(Gtk2::CheckButton->new, gtkshow(gtkcreate_img($e->{image})));
+ } else {
+ #- warn "\"text\" member should have been used instead of \"label\" one at:\n", common::backtrace(), "\n" if $e->{label} && !$e->{text};
+ $w = Gtk2::CheckButton->new_with_label($e->{text});
+ }
+ $w->signal_connect(clicked => $onchange->(sub { $w->get_active }));
+ $set = sub { $w->set_active($_[0]) };
+ } elsif ($e->{type} eq 'only_label') {
+ $w = $e->{title} ?
+ gtknew('Title2', label => escape_text_for_TextView_markup_format(${$e->{val}})) :
+ gtknew('Label_Left', line_wrap => 1, text_markup => ${$e->{val}});
+ } elsif ($e->{type} eq 'label') {
+ $w = gtknew('WrappedLabel', text_markup => ${$e->{val}});
+ $set = sub { $w->set($_[0]) };
+ } elsif ($e->{type} eq 'empty') {
+ $w = gtknew('HBox', height => $e->{height});
+ } elsif ($e->{type} eq 'button') {
+ $w = Gtk2::Button->new_with_label('');
+ $w->signal_connect(clicked => $e->{clicked_may_quit_cooked});
+ $set = sub { $w->child->set_label(may_apply($e->{format}, $_[0])) };
+ } elsif ($e->{type} eq 'range') {
+ my $adj = Gtk2::Adjustment->new(${$e->{val}}, $e->{min}, $e->{max} + ($e->{SpinButton} ? 0 : 1), 1, ($e->{max} - $e->{min}) / 10, 1);
+ $w = $e->{SpinButton} ? Gtk2::SpinButton->new($adj, 10, 0) : Gtk2::HScale->new($adj);
+ $w->set_size_request($e->{SpinButton} ? 100 : 200, -1);
+ $w->set_digits(0);
+ $adj->signal_connect(value_changed => $onchange->(sub { $adj->get_value }));
+ $w->signal_connect(key_press_event => $e->{may_go_to_next});
+ $set = sub { $adj->set_value($_[0]) };
+ } elsif ($e->{type} eq 'expander') {
+ $e->{grow} = 'fill';
+ my $children = [ if_($e->{message}, { type => 'only_label', no_indent => 1, val => \$e->{message} }), @{$e->{children}} ];
+ my $box = create_widgets_block($o, $children, $update, $ignore_ref);
+ $w = gtknew('Expander', text => $e->{text}, child => $box);
+ } elsif ($e->{type} =~ /list/) {
+
+ $e->{formatted_list} = [ map { may_apply($e->{format}, $_) } @{$e->{list}} ];
+
+ if (my $actions = $e->{add_modify_remove}) {
+ my @buttons = map {
+ { kind => lc $_, action => $actions->{$_}, button => Gtk2::Button->new(translate($_)) };
+ } N_("Add"), N_("Modify"), N_("Remove");
+ my $modify = find { $_->{kind} eq 'modify' } @buttons;
+
+ my $do_action = sub {
+ my ($button) = @_;
+ add_modify_remove_action($button, \@buttons, $e, $w) and $update->();
+ };
+
+ ($w, $set, $focus_w) = create_treeview_list($e, $onchange_f,
+ sub { $do_action->($modify) if $_[1]->type =~ /^2/ });
+
+ foreach my $button (@buttons) {
+ $button->{button}->signal_connect(clicked => sub { $do_action->($button) });
+ }
+ add_modify_remove_sensitive(\@buttons, $e);
+
+ $real_w = gtkpack_(Gtk2::HBox->new(0,0),
+ 1, create_scrolled_window($w),
+ 0, gtkpack__(Gtk2::VBox->new(0,0), map { $_->{button} } @buttons));
+ $e->{grow} = 'expand';
+ } else {
+ my $use_boxradio = exists $e->{gtk}{use_boxradio} ? $e->{gtk}{use_boxradio} : @{$e->{list}} <= 8;
+
+ if ($e->{help} || $use_boxradio && $e->{type} ne 'treelist') {
+ #- used only when needed, as key bindings are dropped by List (ListStore does not seems to accepts Tooltips).
+ ($w, $set, $focus_w) = create_boxradio($e, $onchange_f, $e->{quit_if_double_click_cooked});
+ } elsif ($e->{type} eq 'treelist') {
+ ($w, $set) = create_treeview_tree($e, $onchange_f, $e->{quit_if_double_click_cooked});
+ } else {
+ ($w, $set, $focus_w) = create_treeview_list($e, $onchange_f, $e->{quit_if_double_click_cooked});
+ }
+ if (@{$e->{list}} > 10 || $e->{gtk}{use_scrolling}) {
+ $real_w = create_scrolled_window($w);
+ $e->{grow} = 'expand';
+ }
+ }
+ } else {
+ if ($e->{type} eq "combo") {
+ my $model;
+
+ my @formatted_list = map { may_apply($e->{format}, $_) } @{$e->{list}};
+ $e->{formatted_list} = \@formatted_list;
+
+ my @l = sort { $b <=> $a } map { length } @formatted_list;
+ my $width = $l[@l / 16]; # take the third octile (think quartile)
+
+ if (!$e->{separator}) {
+ if ($e->{not_edit} && $width < 160) { #- ComboBoxes do not have an horizontal scroll-bar. This can cause havoc for long strings (eg: diskdrake Create dialog box in expert mode)
+ $w = Gtk2::ComboBox->new_text;
+ $w->set_wrap_width($e->{gtk}{wrap_width}) if exists $e->{gtk}{wrap_width};
+ } else {
+ $w = Gtk2::Combo->new;
+ $w->set_use_arrows_always(1);
+ $w->entry->set_editable(!$e->{not_edit});
+ $w->disable_activate;
+ }
+ $w->set_popdown_strings(@formatted_list);
+ $w->set_text(ref($e->{val}) ? may_apply($e->{format}, ${$e->{val}}) : $formatted_list[0]) if $w->isa('Gtk2::ComboBox');
+ } else {
+ $model = __create_tree_model($e);
+ $w = Gtk2::ComboBox->new_with_model($model);
+
+ $w->pack_start(my $texrender = Gtk2::CellRendererText->new, 0);
+ $w->add_attribute($texrender, text => 0);
+ if ($e->{image2f}) {
+ $w->pack_start(my $pixrender = Gtk2::CellRendererPixbuf->new, 0);
+ $w->add_attribute($pixrender, pixbuf => 1);
+ }
+ }
+ ($real_w, $w) = ($w, $w->entry);
+
+ my $get = sub {
+ my $i = $model ? do {
+ my $s = $model->get_string_from_iter($w->get_active_iter);
+ eval { find_index { $s eq $_ } @{$model->{path_str_list}} };
+ } : do {
+ my $s = $w->get_text;
+ eval { find_index { $s eq $_ } @formatted_list };
+ };
+ defined $i ? $e->{list}[$i] : $w->get_text;
+ };
+ if ($real_w->isa('Gtk2::Combo')) {
+ #- FIXME workaround gtk suckiness (set_text generates two 'change' signals, one when removing the whole, one for inserting the replacement..)
+ my $idle;
+ $w->signal_connect(changed => sub {
+ return if $$ignore_ref;
+ $idle ||= Glib::Idle->add(sub { undef $idle; $onchange_f->($get); 0 });
+ });
+ } else {
+ $w->signal_connect(changed => $onchange->($get));
+ }
+
+ $set = sub {
+ my $s = may_apply($e->{format}, $_[0]);
+ if ($model) {
+ eval {
+ my $i = find_index { $s eq $_ } @{$e->{formatted_list}};
+ my $path_str = $model->{path_str_list}[$i];
+ $w->set_active_iter($model->get_iter_from_string($path_str));
+ };
+ } else {
+ $w->set_text($s) if $s ne $w->get_text && $_[0] ne $w->get_text;
+ }
+ };
+ } else {
+ $w = Gtk2::Entry->new;
+ $w->signal_connect(changed => $onchange->(sub { $w->get_text }));
+ $w->signal_connect(focus_in_event => sub { $w->select_region(0, -1) });
+ $w->signal_connect(focus_out_event => sub { $w->select_region(0, 0) });
+ $set = sub { $w->set_text($_[0]) if $_[0] ne $w->get_text };
+ if ($e->{type} eq 'file') {
+ my $button = gtksignal_connect(Gtk2::Button->new_from_stock('gtk-open'), clicked => sub {
+ my $file = $o->ask_filename({ title => $e->{label} });
+ $set->($file) if $file;
+ });
+ $real_w = gtkpack_(Gtk2::HBox->new(0,0), 1, $w, 0, $button);
+ }
+ }
+ $w->signal_connect(key_press_event => $e->{may_go_to_next});
+ $w->set_visibility(0) if $e->{hidden};
+ }
+
+ if (my $focus_out = $e->{focus_out}) {
+ $w->signal_connect(focus_out_event => sub { $update->($focus_out) });
+ }
+ $real_w ||= $w;
+
+ $e->{w} = $w;
+ $e->{real_w} = $real_w;
+ $e->{focus_w} = $focus_w || $w if $e->{type} ne 'empty';
+ $e->{set} = $set || sub {};
}
-sub ask_fromW {
- my ($o, $common, $l, $l2) = @_;
- my $ignore = 0; #-to handle recursivity
+sub all_entries {
+ my ($l) = @_;
+ map { $_, if_($_->{children}, @{$_->{children}}) } @$l;
+}
- my $mainw = ugtk2->new($common->{title}, %$o, modal => 1, if__($::main_window, transient => $::main_window), if_($common->{icon}, icon => $common->{icon}));
-
- #-the widgets
- my (@widgets, @widgets_always, @widgets_advanced, $advanced);
- my $tooltips = Gtk2::Tooltips->new;
- my $ok_clicked = sub {
- !$mainw->{ok} || $mainw->{ok}->get_property('sensitive') or return;
- $mainw->{retval} = 1;
- Gtk2->main_quit;
- };
+sub all_focusable_entries {
+ my ($l) = @_;
+ map { $_->{type} eq 'expander'
+ ? ($_->{w}->get_expanded ? all_focusable_entries($_->{children}) : ())
+ : $_;
+ } grep { $_->{focus_w} } @$l;
+}
+
+sub create_widgets_block {
+ my ($o, $l, $update, $ignore_ref) = @_;
+
+ my $label_sizegrp = Gtk2::SizeGroup->new('horizontal');
+
+ @$l = map_index {
+ if ($::i && ($_->{type} eq 'expander' || $_->{title})) {
+ ({ type => 'empty', height => 4 }, $_);
+ } else {
+ $_;
+ }
+ } @$l;
+
+ foreach my $e (@$l) {
+ my $onchange_f = sub {
+ my ($f, @para) = @_;
+ return if $$ignore_ref;
+ ${$e->{val}} = $f->(@para);
+ $update->($e->{changed});
+ };
+
+ create_widget($o, $e, $onchange_f, $update, $ignore_ref);
+
+ my $label_w;
+ if ($e->{label} || !$e->{no_indent}) {
+ $label_w = gtknew('Label_Left', text_markup => $e->{label} || '',
+ size_group => $label_sizegrp, alignment => [ 0, 0.5 ]);
+ }
+
+ $e->{real_w} = gtkpack_(Gtk2::HBox->new,
+ if_($e->{icon}, 0, eval { gtkcreate_img($e->{icon}) }),
+ if_($label_w, 0, $label_w),
+ (1, $e->{real_w}),
+ );
+ }
+ gtknew('VBox', children => [ map { $_->{grow} || 0, $_->{real_w} } @$l ]);
+}
+
+sub create_widgets {
+ my ($o, $common, $mainw, $l) = @_;
+
+ my $ignore = 0; #-to handle recursivity
my $set_all = sub {
$ignore = 1;
- $_->{set}->(${$_->{e}{val}}, $_) foreach @widgets_always, @widgets_advanced;
- $_->{real_w}->set_sensitive(!$_->{e}{disabled}()) foreach @widgets_always, @widgets_advanced;
- $mainw->{ok}->set_sensitive(!$common->{callbacks}{ok_disabled}()) if $common->{callbacks}{ok_disabled};
+ my @all = all_entries($l);
+ $_->{set}->(${$_->{val}}, $_) foreach @all; #- nb: the parameter "$_" is needed for create_boxradio
+ $_->{disabled} and $_->{real_w}->set_sensitive(!$_->{disabled}()) foreach @all;
+ $mainw->{ok}->set_sensitive(!$common->{ok_disabled}()) if $common->{ok_disabled};
$ignore = 0;
};
- my $get_all = sub {
- ${$_->{e}{val}} = $_->{get}->() foreach @widgets_always, @widgets_advanced;
- };
my $update = sub {
my ($f) = @_;
return if $ignore;
- $get_all->();
- $f->();
+ $f->() if $f;
$set_all->();
};
- my @label_sizegrp = map { Gtk2::SizeGroup->new('horizontal') } 0 .. 1;
- my @realw_sizegrp = map { Gtk2::SizeGroup->new('horizontal') } 0 .. 1;
+ my $ok_clicked = sub {
+ !$mainw->{ok} || $mainw->{ok}->get_property('sensitive') or return;
+ $mainw->{retval} = 1;
+ Gtk2->main_quit;
+ };
- my $create_widget = sub {
- my ($e, $ind) = @_;
+ my @all = all_entries($l);
+ foreach (@all) {
+ my $e = $_; #- for closures
- my $may_go_to_next = sub {
- my (undef, $event) = @_;
- if (!$event || ($event->keyval & 0x7f) == 0xd) {
- if ($ind == $#widgets) {
- @widgets == 1 ? $ok_clicked->() : $mainw->{ok}->grab_focus;
- } else {
- $widgets[$ind+1]{focus_w}->grab_focus;
- }
- return 1; #- prevent an action on the just grabbed focus
- }
- };
- my $changed = sub { $update->(sub { $common->{callbacks}{changed}($ind) }) };
+ if (@all == 1 || $e->{quit_if_double_click}) {
+ #- i'm the only one, double click means accepting
+ $e->{quit_if_double_click_cooked} = sub { $_[1]->type =~ /^2/ && $ok_clicked->() };
+ }
- my ($w, $real_w, $focus_w, $set, $get, $grow);
- if ($e->{type} eq 'iconlist') {
- $w = Gtk2::Button->new;
- $set = sub {
- gtkdestroy($e->{icon});
- my $f = $e->{icon2f}->($_[0]);
- $e->{icon} = -e $f ?
- gtkcreate_img($f) :
- Gtk2::WrappedLabel->new(may_apply($e->{format}, $_[0]));
- $w->add(gtkshow($e->{icon}));
- };
- $w->signal_connect(clicked => sub {
- $set->(${$e->{val}} = next_val_in_array(${$e->{val}}, $e->{list}));
- $changed->();
- });
- $real_w = gtkpack_(Gtk2::HBox->new(0,10), 1, Gtk2::HBox->new(0,0), 0, $w, 1, Gtk2::HBox->new(0,0));
- } elsif ($e->{type} eq 'bool') {
- if ($e->{image}) {
- $w = ugtk2::gtkadd(Gtk2::CheckButton->new, gtkshow(gtkcreate_img($e->{image})));
- } else {
-#- warn "\"text\" member should have been used instead of \"label\" one at:\n", common::backtrace(), "\n" if $e->{label} && !$e->{text};
- $w = Gtk2::CheckButton->new_with_label($e->{text});
- }
- $w->signal_connect(clicked => $changed);
- $set = sub { $w->set_active($_[0]) };
- $get = sub { $w->get_active };
- } elsif ($e->{type} eq 'label') {
- $w = Gtk2::WrappedLabel->new(${$e->{val}});
- $set = sub { $w->set($_[0]) };
- } elsif ($e->{type} eq 'button') {
- $w = Gtk2::Button->new_with_label('');
- $w->signal_connect(clicked => sub {
- $get_all->();
+ if ($e->{clicked_may_quit}) {
+ $e->{clicked_may_quit_cooked} = sub {
$mainw->{rwindow}->hide;
if (my $v = $e->{clicked_may_quit}()) {
$mainw->{retval} = $v;
Gtk2->main_quit;
}
$mainw->{rwindow}->show;
- $set_all->();
- });
- $set = sub { $w->child->set_label(may_apply($e->{format}, $_[0])) };
- } elsif ($e->{type} eq 'range') {
- my $want_scale = !$::expert;
- my $adj = Gtk2::Adjustment->new(${$e->{val}}, $e->{min}, $e->{max} + ($want_scale ? 1 : 0), 1, ($e->{max} - $e->{min}) / 10, 1);
- $adj->signal_connect(value_changed => $changed);
- $w = $want_scale ? Gtk2::HScale->new($adj) : Gtk2::SpinButton->new($adj, 10, 0);
- $w->set_size_request($want_scale ? 200 : 100, -1);
- $w->set_digits(0);
- $w->signal_connect(key_press_event => $may_go_to_next);
- $set = sub { $adj->set_value($_[0]) };
- $get = sub { $adj->get_value };
- } elsif ($e->{type} =~ /list/) {
-
- $e->{formatted_list} = [ map { may_apply($e->{format}, $_) } @{$e->{list}} ];
-
- if (my $actions = $e->{add_modify_remove}) {
- my @buttons = map {
- { kind => lc $_, action => $actions->{$_}, button => Gtk2::Button->new(translate($_)) };
- } N_("Add"), N_("Modify"), N_("Remove");
- my $modify = find { $_->{kind} eq 'modify' } @buttons;
-
- my $do_action = sub {
- my ($button) = @_;
- add_modify_remove_action($button, \@buttons, $e, $w) and $changed->();
- };
-
- ($w, $set, $focus_w) = create_treeview_list($e, $may_go_to_next, $changed,
- sub { $do_action->($modify) if $_[1]->type =~ /^2/ });
- $e->{saved_default_val} = ${$e->{val}};
+ $update->();
+ };
+ }
- foreach my $button (@buttons) {
- $button->{button}->signal_connect(clicked => sub { $do_action->($button) });
+ $e->{may_go_to_next} = sub {
+ my (undef, $event) = @_;
+ if (!$event || ($event->keyval & 0x7f) == 0xd) {
+ my @current_all = all_focusable_entries($l);
+ my $ind = eval { find_index { $_ == $e } @current_all };
+ if (my $e_ = $current_all[$ind+1]) {
+ $e_->{focus_w}->grab_focus;
+ } else {
+ @current_all == 1 ? $ok_clicked->() : $mainw->{ok}->grab_focus;
}
- add_modify_remove_sensitive(\@buttons, $e);
-
- $real_w = gtkpack_(Gtk2::HBox->new(0,0),
- 1, create_scrolled_window($w),
- 0, gtkpack__(Gtk2::VBox->new(0,0), map { $_->{button} } @buttons));
- $grow = 1;
+ 1; #- prevent an action on the just grabbed focus
} else {
+ 0;
+ }
+ };
+ }
- my $quit_if_double_click =
- #- i'm the only one, double click means accepting
- @$l == 1 || $e->{quit_if_double_click} ?
- sub { $_[1]->type =~ /^2/ && $ok_clicked->() } : '';
+ my $box = create_widgets_block($o, $l, $update, \$ignore);
- my @para = ($e, $may_go_to_next, $changed, $quit_if_double_click);
- my $use_boxradio = exists $e->{gtk}{use_boxradio} ? $e->{gtk}{use_boxradio} : @{$e->{list}} <= 8;
+ my $tooltips = Gtk2::Tooltips->new;
+ foreach my $e (@all) {
+ $tooltips->set_tip($e->{w}, $e->{help}) if $e->{help} && !ref($e->{help});
+ }
- if ($e->{help}) {
- #- used only when needed, as key bindings are dropped by List (ListStore does not seems to accepts Tooltips).
- ($w, $set, $focus_w) = $use_boxradio ? create_boxradio(@para) : create_list(@para);
- } elsif ($e->{type} eq 'treelist') {
- ($w, $set) = create_treeview_tree(@para, $e->{tree_expanded});
- $e->{saved_default_val} = ${$e->{val}}; #- during realization, signals will mess up the default val :(
- } else {
- if ($use_boxradio) {
- ($w, $set, $focus_w) = create_boxradio(@para);
- } else {
- ($w, $set, $focus_w) = create_treeview_list(@para);
- $e->{saved_default_val} = ${$e->{val}};
- }
- }
- if (@{$e->{list}} > 10) {
- $real_w = create_scrolled_window($w);
- $grow = 1;
- }
- }
- } else {
- if ($e->{type} eq "combo") {
- my $model;
+ $box, $set_all;
+}
- my @formatted_list = map { may_apply($e->{format}, $_) } @{$e->{list}};
- $e->{formatted_list} = \@formatted_list;
+sub add_modify_remove_sensitive {
+ my ($buttons, $e) = @_;
+ $_->{button}->set_sensitive(@{$e->{list}} != ()) foreach
+ grep { member($_->{kind}, 'modify', 'remove') } @$buttons;
+}
- my @l = sort { $b <=> $a } map { length } @formatted_list;
- my $width = $l[@l / 16]; # take the third octile (think quartile)
+sub filter_widgets {
+ my ($l) = @_;
- if (!$e->{separator}) {
- if ($e->{not_edit} && $width < 160) { #- ComboBoxes do not have an horizontal scroll-bar. This can cause havoc for long strings (eg: diskdrake Create dialog box in expert mode)
- $w = Gtk2::ComboBox->new_text;
- } else {
- $w = Gtk2::Combo->new;
- $w->set_use_arrows_always(1);
- $w->entry->set_editable(!$e->{not_edit});
- $w->disable_activate;
- }
- $w->set_popdown_strings(@formatted_list);
- $w->set_text(ref($e->{val}) ? may_apply($e->{format}, ${$e->{val}}) : $formatted_list[0]) if $w->isa('Gtk2::ComboBox');
- } else {
- $model = __create_tree_model($e);
- $w = Gtk2::ComboBox->new_with_model($model);
-
- $w->pack_start(my $texrender = Gtk2::CellRendererText->new, 0);
- $w->add_attribute($texrender, text => 0);
- if ($e->{image2f}) {
- $w->pack_start(my $pixrender = Gtk2::CellRendererPixbuf->new, 0);
- $w->add_attribute($pixrender, pixbuf => 1);
- }
- }
- ($real_w, $w) = ($w, $w->entry);
+ foreach my $e (all_entries($l)) {
+ $e->{no_indent} = 1 if member($e->{type}, 'list', 'treelist', 'expander', 'bool', 'only_label');
+ }
+}
- #- FIXME workaround gtk suckiness (set_text generates two 'change' signals, one when removing the whole, one for inserting the replacement..)
- my $idle;
- $w->signal_connect(changed => sub {
- $idle ||= Glib::Idle->add(sub { undef $idle; $changed->(); 0 });
- });
-
- $set = sub {
- my $s = may_apply($e->{format}, $_[0]);
- if ($model) {
- eval {
- my $i = find_index { $s eq $_ } @{$e->{formatted_list}};
- my $path_str = $model->{path_str_list}[$i];
- $w->set_active_iter($model->get_iter_from_string($path_str));
- };
- } else {
- $w->set_text($s) if $s ne $w->get_text && $_[0] ne $w->get_text;
- }
- };
- $get = sub {
- my $i = $model ? do {
- my $s = $model->get_string_from_iter($w->get_active_iter);
- eval { find_index { $s eq $_ } @{$model->{path_str_list}} };
- } : do {
- my $s = $w->get_text;
- eval { find_index { $s eq $_ } @formatted_list };
- };
- defined $i ? $e->{list}[$i] : $w->get_text;
- };
- } else {
- $w = Gtk2::Entry->new;
- $w->signal_connect(changed => $changed);
- $w->signal_connect(focus_in_event => sub { $w->select_region(0, -1) });
- $w->signal_connect(focus_out_event => sub { $w->select_region(0, 0) });
- $set = sub { $w->set_text($_[0]) if $_[0] ne $w->get_text };
- $get = sub { $w->get_text };
- }
- $w->signal_connect(key_press_event => $may_go_to_next);
- $w->set_visibility(0) if $e->{hidden};
- }
- $w->signal_connect(focus_out_event => sub {
- $update->(sub { $common->{callbacks}{focus_out}($ind) });
- });
- $tooltips->set_tip($w, $e->{help}) if $e->{help} && !ref($e->{help});
+my $help_path = "/usr/share/doc/installer-help";
- $real_w ||= $w;
- $real_w = gtkpack_(Gtk2::HBox->new,
- if_($e->{icon}, 0, eval { gtkcreate_img($e->{icon}) }),
- 0, gtkadd_widget($label_sizegrp[$e->{advanced} ? 1 : 0], $e->{label}),
- 1, gtkadd_widget($realw_sizegrp[$e->{advanced} ? 1 : 0], $real_w),
- ) if !$real_w->isa("Gtk2::CheckButton") || $e->{icon} || $e->{label};
+sub load_from_uri {
+ my ($document, $url) = @_;
+ $url = "$help_path/$url" if $url !~ m!^/!;
+ my $str = scalar(cat_($url));
+ c::set_tagged_utf8($str);
+ $document->clear;
+ $document->open_stream("text/html");
+ $document->write_stream($str);
+}
- { e => $e, w => $w, real_w => $real_w, focus_w => $focus_w || $w,
- get => $get || sub { ${$e->{val}} }, set => $set || sub {}, grow => $grow };
- };
- @widgets_always = map_index { $create_widget->($_, $::i) } @$l;
- @widgets_advanced = map_index { $create_widget->($_, $::i + @$l) } @$l2;
+sub ask_fromW {
+ my ($o, $common, $l) = @_;
+
+ filter_widgets($l);
+
+ my $mainw = ugtk2->new($common->{title}, %$o, modal => 1, if__($::main_window, transient => $::main_window, modal => 1),
+ if_($common->{icon}, icon => $common->{icon}), banner_title => $common->{banner_title},
+ );
+
+ my ($box, $set_all) = create_widgets($o, $common, $mainw, $l);
$mainw->{box_allow_grow} = 1;
my $pack = create_box_with_title($mainw, @{$common->{messages}});
- mygtk2::set_main_window_size($mainw->{rwindow}) if $mainw->{pop_it} && (@$l || $mainw->{box_size} == 200);
-
- my @before_widgets_advanced = (
- (map { { grow => 0, real_w => Gtk2::WrappedLabel->new($_) } } @{$common->{advanced_messages}}),
- { grow => 0, real_w => Gtk2::HSeparator->new },
- );
-
- my $first_time = 1;
- my $set_advanced = sub {
- ($advanced) = @_;
- $update->($common->{callbacks}{advanced}) if $advanced && !$first_time;
- foreach (@before_widgets_advanced, @widgets_advanced) {
- my $w = $_->{embed_scroll} || $_->{real_w};
- $advanced ? $w->show : $w->hide;
- }
- @widgets = (@widgets_always, if_($advanced, @widgets_advanced));
- $first_time = 0;
- $set_all->(); #- must be done when showing advanced lists (to center selected value)
- };
- if ($::expert && @$l2) {
- $common->{advanced_state} = 1;
- }
- my $advanced_button = [ $common->{advanced_state} ? $common->{advanced_label_close} : $common->{advanced_label},
- sub {
- my ($w) = @_;
- $set_advanced->(!$advanced);
- $w->child->set_label($advanced ? $common->{advanced_label_close} : $common->{advanced_label});
- } ];
+ mygtk2::set_main_window_size($mainw->{rwindow}) if $mainw->{pop_it} && !$common->{auto_window_size} && (@$l || $mainw->{box_size} == 200);
my @more_buttons = (
if_($common->{interactive_help},
[ N("Help"), sub {
+ if (my $file = find { -e $_ } map { "$help_path/${_}.html" }
+ map {
+ my $id = $_;
+ require lang;
+ map { "$_/$id" } (split ':', lang::getLANGUAGE($o->{locale}{lang}));
+ } $common->{interactive_help_id}
+ ) {
+ require Gtk2::Html2;
+ my $view = Gtk2::Html2::View->new;
+ my $document = Gtk2::Html2::Document->new;
+ $document->signal_connect(request_url => sub {
+ my ($_document, $url, $stream) = @_;
+ $stream->write(join('', cat_("$help_path/$url")));
+ $stream->close;
+ });
+ $document->signal_connect('link-clicked' => \&load_from_uri);
+ $view->set_document($document);
+
+ load_from_uri($document, $file);
+
+ my $w = ugtk2->new(N("Help"), transient => $mainw->{real_window}, modal => 1);
+ gtkadd($w->{rwindow},
+ gtkpack_(Gtk2::VBox->new,
+ 1, create_scrolled_window(gtkset_border_width($view, 5),
+ [ 'never', 'automatic' ],
+ ),
+ 0, gtkpack(create_hbox('edge'),
+ gtknew('Button', text => N("Close"), clicked => sub { Gtk2->main_quit })
+ ),
+ ),
+ );
+ # make parent visible still visible:
+ local ($::real_windowwidth, $::real_windowheight) = ($::real_windowwidth - 50, $::real_windowheight - 50);
+ mygtk2::set_main_window_size($w->{rwindow});
+ $w->{real_window}->grab_focus;
+ $w->{real_window}->show_all;
+ $w->main;
+ return;
+ }
my $message = $common->{interactive_help}->() or return;
$o->ask_warn(N("Help"), $message);
}, 1 ]),
if_($common->{more_buttons}, @{$common->{more_buttons}}),
);
- my $buttons_pack = ($common->{ok} || !exists $common->{ok}) && $mainw->create_okcancel($common->{ok}, $common->{cancel}, '', @more_buttons, if_(@$l2, $advanced_button));
-
- my @widgets_to_pack;
- foreach my $l (\@widgets_always, if_(@widgets_advanced, [ @before_widgets_advanced, @widgets_advanced ])) {
- my @grouped;
- my $add_grouped = sub {
- if (@grouped == 0) {
- } elsif (@grouped == 1) {
- push @widgets_to_pack, 0 => $grouped[0]{real_w};
- } else {
- my $scroll = create_scrolled_window(gtkpack__(Gtk2::VBox->new(0,0), map { $_->{real_w} } @grouped),
- [ 'automatic', 'automatic' ], 'none');
- $_->{embed_scroll} = $scroll foreach @grouped;
- push @widgets_to_pack, 1 => $scroll;
- }
- @grouped = ();
- };
- foreach (@$l) {
- if ($_->{grow}) {
- $add_grouped->();
- push @widgets_to_pack, 1 => $_->{real_w};
- } else {
- push @grouped, $_;
- }
- }
- $add_grouped->();
- }
+ my $buttons_pack = ($common->{ok} || !exists $common->{ok}) && $mainw->create_okcancel($common->{ok}, $common->{cancel}, '', @more_buttons);
- gtkpack_($pack, @widgets_to_pack);
+ gtkpack_($pack, 1, gtknew('ScrolledWindow', shadow_type => 'none', child => $box)) if @$l;
if ($buttons_pack) {
$pack->pack_end(gtkshow($buttons_pack), 0, 0, 0);
}
ugtk2::gtkadd($mainw->{window}, $pack);
- $set_advanced->($common->{advanced_state});
-
- my $widget_to_focus =
- $common->{focus_cancel} ? $mainw->{cancel} :
- @widgets && ($common->{focus_first} || !$mainw->{ok} || @widgets == 1 && member(ref($widgets[0]{focus_w}), "Gtk2::TreeView", "Gtk2::RadioButton")) ?
- $widgets[0]{focus_w} :
- $mainw->{ok};
+ $set_all->();
+
+ my $entry_to_focus = find { $_->{focus} && $_->{focus}() } @$l;
+ my $widget_to_focus = $entry_to_focus ? $entry_to_focus->{focus_w} :
+ $common->{focus_cancel} ? $mainw->{cancel} :
+ @$l && (!$mainw->{ok} || @$l == 1 && member(ref($l->[0]{focus_w}), "Gtk2::TreeView", "Gtk2::RadioButton")) ?
+ $l->[0]{focus_w} :
+ $mainw->{ok};
$widget_to_focus->grab_focus if $widget_to_focus;
- my $check = sub {
- my ($f) = @_;
- sub {
- $get_all->();
- my ($error, $focus) = $f->();
-
- if ($error) {
- $set_all->();
- if (my $to_focus = $widgets[$focus || 0]) {
- $to_focus->{focus_w}->grab_focus;
- } else {
- log::l("ERROR: bad entry number given to focus " . backtrace());
- }
- }
- !$error;
- };
+ my $validate = sub {
+ my @all = all_entries($l);
+ my $e = find { $_->{validate} && !$_->{validate}->() } @all;
+ $e ||= $common->{validate} && !$common->{validate}() && $all[0];
+ if ($e) {
+ $set_all->();
+ $e->{focus_w}->grab_focus;
+ }
+ !$e;
};
- $_->{set}->($_->{e}{saved_default_val} || next) foreach @widgets_always, @widgets_advanced;
- $mainw->main(map { $check->($common->{callbacks}{$_}) } 'complete', 'canceled');
+ $mainw->main($validate);
}
@@ -770,18 +813,21 @@ sub ask_from__add_modify_removeW {
}
sub wait_messageW {
- my ($_o, $title, $messages) = @_;
+ my ($o, $title, $message, $message_modifiable) = @_;
- my $to_modify;
- my @l = map { ref $_ ? (0, $_) : (1, $to_modify = Gtk2::Label->new(scalar warp_text($_))) } @$messages;
- $l[0] = 0; #- force first one
+ my $to_modify = Gtk2::Label->new(scalar warp_text(ref $message_modifiable ? '' : $message_modifiable));
my $Window = gtknew('MagicWindow',
title => $title,
pop_it => !$::isInstall,
modal => 1,
+ no_Window_Manager => exists $o->{no_Window_Manager} ? $o->{no_Window_Manager} : !$::isStandalone,
if__($::main_window, transient_for => $::main_window),
- child => gtknew('VBox', padding => 4, border_width => 10, children => \@l),
+ child => gtknew('VBox', padding => 4, border_width => 10, children => [
+ 0, Gtk2::Label->new(scalar warp_text($message)),
+ 1, $to_modify,
+ if_(ref($message_modifiable), 0, $message_modifiable),
+ ]),
);
$Window->signal_connect(expose_event => sub { $Window->{displayed} = 1; 0 });
$Window->{wait_messageW} = $to_modify;
@@ -789,11 +835,10 @@ sub wait_messageW {
$Window;
}
sub wait_message_nextW {
- my ($_o, $messages, $Window) = @_;
- my $msg = warp_text(join "\n", @$messages);
- return if $msg eq $Window->{wait_messageW}->get_text; #- needed otherwise no expose_event :(
+ my ($_o, $message, $Window) = @_;
+ return if $message eq $Window->{wait_messageW}->get_text; #- needed otherwise no expose_event :(
$Window->{displayed} = 0;
- $Window->{wait_messageW}->set($msg);
+ $Window->{wait_messageW}->set($message);
mygtk2::sync($Window) while !$Window->{displayed};
}
sub wait_message_endW {
@@ -802,6 +847,31 @@ sub wait_message_endW {
mygtk2::flush();
}
+sub wait_message_with_progress_bar {
+ my ($in, $o_title) = @_;
+
+ my $progress = Gtk2::ProgressBar->new;
+ my $w = $in->wait_message($o_title, $progress);
+ my $displayed;
+ $progress->signal_connect(expose_event => sub { $displayed = 1; 0 });
+ $w, sub {
+ my ($msg, $current, $total) = @_;
+ if ($msg) {
+ $w->set($msg);
+ }
+
+ if ($total) {
+ $progress or internal_error('You must first give some text to display');
+ $progress->set_fraction($current / $total);
+ $progress->show;
+ $displayed = 0;
+ mygtk2::flush() while !$displayed;
+ } else {
+ $progress->hide if !$total;
+ }
+ };
+}
+
sub kill {
my ($_o) = @_;
$_->destroy foreach $::WizardTable ? $::WizardTable->get_children : (), @tempory::objects;