diff options
Diffstat (limited to 'perl-install/mygtk2.pm')
-rw-r--r-- | perl-install/mygtk2.pm | 218 |
1 files changed, 146 insertions, 72 deletions
diff --git a/perl-install/mygtk2.pm b/perl-install/mygtk2.pm index 3ff3f0f72..6633decf3 100644 --- a/perl-install/mygtk2.pm +++ b/perl-install/mygtk2.pm @@ -19,13 +19,13 @@ sub init() { Gtk2->init; Locale::gettext::bind_textdomain_codeset($_, 'UTF8') foreach 'libDrakX', if_(!$::isInstall, 'libDrakX-standalone'), - if_($::isInstall, 'draksnapshot'), + if_($::isRestore, 'draksnapshot'), if_($::isInstall, 'urpmi'), 'drakx-net', 'drakx-kbd-mouse-x11', # shared translation @::textdomains; - Gtk2->croak_execeptions; + Glib->enable_exceptions2; } -init() unless ($::no_ugtk_init); -Gtk2->croak_execeptions if $::isInstall; +init() unless $::no_ugtk_init; +Glib->enable_exceptions2 if $::isInstall; @@ -146,7 +146,7 @@ sub _gtk { } sub _gtk__Install_Button { - my ($w, $opts, $class) = @_; + my ($w, $opts, $_class) = @_; $opts->{child} = gtknew('HBox', spacing => 5, children_tight => [ # FIXME: not RTL compliant (lang::text_direction_rtl() ? ...) @@ -253,12 +253,22 @@ sub _gtk__HScale { if (!$w) { $opts->{adjustment} ||= do { - add2hash_($opts, { step_increment => 1, page_increment => 5, page_size => 1, value => delete $opts->{lower} }); + add2hash_($opts, { step_increment => 1, page_increment => 5, page_size => 1 }); + add2hash_($opts, { value => $opts->{lower} }) if !exists $opts->{value}; Gtk2::Adjustment->new(delete $opts->{value}, delete $opts->{lower}, (delete $opts->{upper}) + 1, delete $opts->{step_increment}, delete $opts->{page_increment}, delete $opts->{page_size}); }; $w = Gtk2::HScale->new(delete $opts->{adjustment}); } + $w->set_digits(delete $opts->{digits}) if exists $opts->{digits}; + if (my $value_ref = delete $opts->{value_ref}) { + my $set = sub { $w->set_value($$value_ref) }; + gtkval_register($w, $value_ref, $set); + $set->(); + $w->signal_connect(value_changed => sub { + gtkval_modify($value_ref, $w->get_value, $set); + }); + } $w->signal_connect(value_changed => delete $opts->{value_changed}) if exists $opts->{value_changed}; $w; } @@ -286,7 +296,7 @@ sub _gtk__HSeparator { &_gtk_any_simple } sub _gtk__Calendar { &_gtk_any_simple } sub _gtk__DrawingArea { - my ($w, $opts) = @_; + my ($w, $_opts) = @_; if (!$w) { $w = Gtk2::DrawingArea->new; @@ -299,7 +309,7 @@ sub _gtk__Pixbuf { if (!$w) { my $name = delete $opts->{file} or internal_error("missing file"); - my $file = _find_imgfile($name) or internal_error("can not find image $name"); + my $file = _find_imgfile($name) or internal_error("cannot find image $name"); if (my $size = delete $opts->{size}) { $w = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($file, $size, $size, 1); } else { @@ -320,6 +330,8 @@ sub _gtk__Image { if (!$w) { $w = Gtk2::Image->new; $w->{format} = delete $opts->{format} if exists $opts->{format}; + + $w->set_from_stock(delete $opts->{stock}, 'button') if exists $opts->{stock}; $w->{options} = { flip => delete $opts->{flip} }; @@ -333,7 +345,6 @@ sub _gtk__Image { my ($width, $height) = ($pixbuf->get_width, $pixbuf->get_height); $w->set_size_request($width, $height); $w->{pixbuf} = $pixbuf; - my $not_my_first_event; $w->signal_connect(expose_event => sub { my (undef, $event) = @_; if (!$w->{x}) { @@ -341,17 +352,17 @@ sub _gtk__Image { $w->{x} = $alloc->x; $w->{y} = $alloc->y; } - foreach my $rect($event->region->get_rectangles) { + # workaround Gtk+ bug: in installer, first event is not complete and rectables are bogus: + if ($::isInstall) { + $pixbuf->render_to_drawable($w->window, $w->style->fg_gc('normal'), + 0, 0, $w->{x}, $w->{y}, $width, $height, 'max', 0, 0); + return; + } + foreach my $rect ($event->region->get_rectangles) { my @values = $rect->values; $pixbuf->render_to_drawable($w->window, $w->style->fg_gc('normal'), @values[0..1], $w->{x}+$values[0], $w->{y}+$values[1], @values[2..3], 'max', 0, 0); } - # workaround Gtk+ bug: in installer, first event is not complete: - if ($::isInstall && !$not_my_first_event) { - $not_my_first_event = 1; - $pixbuf->render_to_drawable($w->window, $w->style->fg_gc('normal'), - 0, 0, $w->{x}, $w->{y}, $width, $height, 'max', 0, 0); - } }); } : sub { my ($w, $file, $o_size) = @_; @@ -361,11 +372,11 @@ sub _gtk__Image { } if (my $name = delete $opts->{file}) { - my $file = _find_imgfile(may_apply($w->{format}, $name)) or internal_error("can not find image $name"); + my $file = _find_imgfile(may_apply($w->{format}, $name)) or internal_error("cannot find image $name"); $w->{set_from_file}->($w, $file, delete $opts->{size}); } elsif (my $file_ref = delete $opts->{file_ref}) { my $set = sub { - my $file = _find_imgfile(may_apply($w->{format}, $$file_ref)) or internal_error("can not find image $$file_ref"); + my $file = _find_imgfile(may_apply($w->{format}, $$file_ref)) or internal_error("cannot find image $$file_ref"); $w->{set_from_file}->($w, $file, delete $opts->{size}); }; gtkval_register($w, $file_ref, $set); @@ -377,7 +388,7 @@ sub _gtk__Image { sub _gtk__WrappedLabel { my ($w, $opts) = @_; - $opts->{line_wrap} = 1 if not defined $opts->{line_wrap}; + $opts->{line_wrap} = 1 if !defined $opts->{line_wrap}; _gtk__Label($w, $opts); } @@ -404,6 +415,7 @@ sub _gtk__Label { $w->set_text(delete $opts->{text}) if exists $opts->{text}; } else { $w = exists $opts->{text} ? Gtk2::Label->new(delete $opts->{text}) : Gtk2::Label->new; + $w->set_selectable(delete $opts->{selectable}) if exists $opts->{selectable}; $w->set_ellipsize(delete $opts->{ellipsize}) if exists $opts->{ellipsize}; $w->set_justify(delete $opts->{justify}) if exists $opts->{justify}; $w->set_line_wrap(delete $opts->{line_wrap}) if exists $opts->{line_wrap}; @@ -429,7 +441,7 @@ sub _gtk__Label { sub _gtk__Alignment { - my ($w, $opts) = @_; + my ($w, $_opts) = @_; if (!$w) { $w = Gtk2::Alignment->new(0, 0, 0, 0); @@ -513,6 +525,18 @@ sub _gtk__Entry { $w->set_editable(delete $opts->{editable}) if exists $opts->{editable}; } + if (my $icon = delete $opts->{primary_icon}) { + $w->set_icon_from_stock('primary', $icon); + #$w->set_icon_highlight('primary', $icon); + } + if (my $icon = delete $opts->{secondary_icon}) { + $w->set_icon_from_stock('secondary', $icon); + #$w->set_icon_highlight('secondary', $icon); + } + + $w->signal_connect('icon-release' => delete $opts->{'icon-release'}) if exists $opts->{'icon-release'}; + $w->signal_connect('icon-press' => delete $opts->{'icon-press'}) if exists $opts->{'icon-press'}; + $w->set_text(delete $opts->{text}) if exists $opts->{text}; $w->signal_connect(key_press_event => delete $opts->{key_press_event}) if exists $opts->{key_press_event}; @@ -528,6 +552,23 @@ sub _gtk__Entry { $w; } +sub _gtk__WeaknessCheckEntry { + my ($w, $opts) = @_; + + if (!$w) { + $w = _gtk__Entry($w, $opts); + } + + $w->signal_connect('changed' => sub { + require authentication; + my $password_weakness = authentication::compute_password_weakness($w->get_text); + $w->set_icon_from_pixbuf('GTK_ENTRY_ICON_SECONDARY', _get_weakness_icon($password_weakness)); + $w->set_icon_tooltip_text('GTK_ENTRY_ICON_SECONDARY', _get_weakness_tooltip($password_weakness)); + }); + + $w; +} + sub _gtk__TextView { my ($w, $opts, $_class, $action) = @_; @@ -543,7 +584,7 @@ sub _gtk__TextView { } sub _gtk__WebKit_View { - my ($w, $opts, $_class, $action) = @_; + my ($w, $opts, $_class, $_action) = @_; if (!$w) { $w = Gtk2::WebKit::WebView->new; } @@ -625,7 +666,7 @@ sub _gtk__ScrolledWindow { $w->add_with_viewport($child); } $child->set_focus_vadjustment($w->get_vadjustment) if $child->can('set_focus_vadjustment'); - $child->set_left_margin(6) if ref($child) =~ /Gtk2::TextView/ && $child->get_left_margin() <= 6; + $child->set_left_margin(6) if ref($child) =~ /Gtk2::TextView/ && $child->get_left_margin <= 6; $child->show; $w->child->set_shadow_type(delete $opts->{shadow_type}) if exists $opts->{shadow_type}; @@ -680,14 +721,14 @@ sub _gtk__Expander { sub _gtk__MDV_Notebook { - my ($w, $opts, $_class, $action) = @_; + my ($w, $opts, $_class, $_action) = @_; if (!$w) { import_style_ressources(); my ($layout, $selection_arrow, $selection_bar); my $parent_window = delete $opts->{parent_window} || root_window(); - my $root_height = first($parent_window->get_size()); - my $suffix = $root_height eq 800 && !$::isStandalone ? '_600' : '_768'; + my $root_height = first($parent_window->get_size); + my $suffix = $root_height == 800 && !$::isStandalone ? '_600' : '_768'; # the white square is a little bit above the actual left sidepanel: my $offset = 20; my $is_flip_needed = text_direction_rtl(); @@ -698,11 +739,11 @@ sub _gtk__MDV_Notebook { my @right_background = $::isInstall ? gtknew('Image', file => "right-white-background_left_part$suffix", flip => $is_flip_needed) : map { - gtknew('Image', file => "right-white-background_left_part-$_", flip => $is_flip_needed) + gtknew('Image', file => "right-white-background_left_part-$_", flip => $is_flip_needed); } 1, 2, 2, 3; my $width1 = $left_background->{pixbuf}->get_width; my $total_width = $width1 + $right_background[0]->get_pixbuf->get_width; - my $arrow_x = text_direction_rtl() ? $offset/2 -4 : $width1 - $offset -3; + my $arrow_x = text_direction_rtl() ? $offset/2 - 4 : $width1 - $offset - 3; $w = gtknew('HBox', spacing => 0, children => [ 0, $layout = gtknew('Layout', width => $total_width - $offset, children => [ #Layout Fixed # stacking order is important for "Z-buffer": @@ -748,7 +789,7 @@ sub _gtk__MDV_Notebook { sub _gtk__Fixed { - my ($w, $opts, $_class, $action) = @_; + my ($w, $opts, $_class, $_action) = @_; if (!$w) { $w = Gtk2::Fixed->new; @@ -778,7 +819,7 @@ sub _gtknew_handle_layout_children { delete $opts->{children}; if ($opts->{pixbuf_file}) { - my $pixbuf = gtknew('Pixbuf', file => delete $opts->{pixbuf_file}) if $opts->{pixbuf_file}; + my $pixbuf = if_($opts->{pixbuf_file}, gtknew('Pixbuf', file => delete $opts->{pixbuf_file})); $w->signal_connect( realize => sub { ugtk2::set_back_pixbuf($w, $pixbuf); @@ -797,7 +838,7 @@ sub _gtk_any_Window { if ($class eq 'Window') { $w = "Gtk2::$class"->new(delete $opts->{type} || 'toplevel'); } elsif ($class eq 'Plug') { - $opts->{socket_id} or internal_error("can not create a Plug without a socket_id"); + $opts->{socket_id} or internal_error("cannot create a Plug without a socket_id"); $w = "Gtk2::$class"->new(delete $opts->{socket_id}); } elsif ($class eq 'FileChooserDialog') { my $action = delete $opts->{action} || internal_error("missing action for FileChooser"); @@ -825,7 +866,7 @@ sub _gtk_any_Window { if (my $f = _find_imgfile($name)) { $w->set_icon(gtknew('Pixbuf', file => $f)); } elsif (!$icon_no_error) { - internal_error("can not find $name"); + internal_error("cannot find $name"); } } } @@ -1136,7 +1177,7 @@ sub _gtknew_handle_children { foreach (@child) { my ($fill, $child) = @$_; - $fill eq '0' || $fill eq '1' || $fill eq 'fill' || $fill eq 'expand' or internal_error("odd {children} parameter must be 0 or 1 (got $fill)"); + member($fill, qw(0 1 fill expand)) or internal_error("odd {children} parameter must be 0 or 1 (got $fill)"); ref $child or $child = Gtk2::WrappedLabel->new($child); my $expand = $fill && $fill ne 'fill' ? 1 : 0; $w->pack_start($child, $expand, $fill, $padding || 0); @@ -1157,7 +1198,7 @@ sub mygtk2::MagicWindow::AUTOLOAD { my ($s1, @s2) = $meth eq 'show' ? ('real_window', 'banner', 'child') : - $meth eq 'destroy' || $meth eq 'hide' ? + member($meth, qw(destroy hide)) ? ($w->{pop_it} ? 'real_window' : ('child', 'banner')) : $meth eq 'get' && $args[0] eq 'window-position' || $for_real_window{$meth} || @@ -1171,6 +1212,43 @@ sub mygtk2::MagicWindow::AUTOLOAD { $w->{$s1}->$meth(@args); } +my $enable_quit_popup; +sub enable_quit_popup { + my ($bool) = @_; + $enable_quit_popup = $bool; +} + +state $in_callback; +sub quit_popup() { + return if !$enable_quit_popup; + if (!$in_callback) { + $in_callback = 1; + my $_guard = before_leaving { undef $in_callback }; + require ugtk2; + my $w = ugtk2->new(N("Confirmation"), grab => 1); + ugtk2::_ask_okcancel($w, N("Are you sure you want to quit?"), N("Quit"), N("Cancel")); + my $ret = ugtk2::main($w); + return 1 if !$ret; + } +} + +sub quit_callback { + my ($w) = @_; + + return 1 if quit_popup(); + if ($::isWizard) { + $w->destroy; + die 'wizcancel'; + } else { + if (Gtk2->main_level) { + Gtk2->main_quit; + } else { + # block window deletion if not in main loop (eg: while starting the GUI) + return 1; + } + } +} + sub _create_Window { my ($opts, $special_center) = @_; @@ -1191,23 +1269,7 @@ sub _create_Window { my $w = _gtk(undef, 'Window', 'gtknew', $opts); #- when the window is closed using the window manager "X" button (or alt-f4) - $w->signal_connect(delete_event => sub { - if ($::isWizard) { - $w->destroy; - die 'wizcancel'; - } else { - if (Gtk2->main_level) { - Gtk2->main_quit; - } else { - # block window deletion if not in main loop (eg: while starting the GUI) - return 1; - } - } - }); - - if ($no_Window_Manager) { - _force_keyboard_focus($w); - } + $w->signal_connect(delete_event => \&quit_callback); if ($::isInstall && !$::isStandalone) { require install::gtk; #- for perl_checker @@ -1232,26 +1294,9 @@ sub _create_Window { }) if $special_center; } - $w; -} - -my $current_window; -sub _force_keyboard_focus { - my ($w) = @_; + $w->present if $no_Window_Manager; - sub _XSetInputFocus { - my ($w) = @_; - if ($current_window == $w) { - $w->window->XSetInputFocus; - } - 0; - } - - #- force keyboard focus instead of mouse focus - my $previous_current_window = $current_window; - $current_window = $w; - $w->signal_connect(expose_event => \&_XSetInputFocus); - $w->signal_connect(destroy => sub { $current_window = $previous_current_window }); + $w; } sub _find_imgfile { @@ -1375,12 +1420,12 @@ sub asteriskize { } sub get_main_window_size() { - my ($width, $height) = $::real_windowwidth ? ($::real_windowwidth, $::real_windowheight) : $::isWizard ? (540, 360) : (600, 400); + $::real_windowwidth ? ($::real_windowwidth, $::real_windowheight) : $::isWizard ? (540, 360) : (600, 400); } # in order to workaround infamous 6 years old gnome bug #101968: sub get_label_width() { - first(mygtk2::get_main_window_size()) - 50 - $left_padding; + first(mygtk2::get_main_window_size()) - 55 - $left_padding; } sub set_main_window_size { @@ -1428,6 +1473,11 @@ sub sync_flush { } +sub register_main_window { + my ($w) = @_; + push @::main_windows, $::main_window = $w; +} + sub may_destroy { my ($w) = @_; return if !$w; @@ -1499,7 +1549,31 @@ sub import_style_ressources() { } sub text_direction_rtl() { - Gtk2::Widget->get_default_direction() eq 'rtl'; + Gtk2::Widget->get_default_direction eq 'rtl'; +} + +sub _get_weakness_icon { + my ($password_weakness) = @_; + my %weakness_icon = ( + 1 => gtknew('Pixbuf', file => 'security-low'), + 2 => gtknew('Pixbuf', file => 'security-low'), + 3 => gtknew('Pixbuf', file => 'security-medium'), + 4 => gtknew('Pixbuf', file => 'security-strong'), + 5 => gtknew('Pixbuf', file => 'security-strong')); + my $weakness_icon = $weakness_icon{$password_weakness} || return undef; + $weakness_icon; +} + +sub _get_weakness_tooltip { + my ($password_weakness) = @_; + my %weakness_tooltip = ( + 1 => N("Password is trivial to guess"), + 2 => N("Password is trivial to guess"), + 3 => N("Password should be resistant to basic attacks"), + 4 => N("Password seems secure"), + 5 => N("Password seems secure")); + my $weakness_tooltip = $weakness_tooltip{$password_weakness} || return undef; + return $weakness_tooltip; } package Gtk2::MDV_Notebook; # helper functions for installer & mcc |