diff options
Diffstat (limited to 'perl-install/mygtk2.pm')
| -rw-r--r-- | perl-install/mygtk2.pm | 127 | 
1 files changed, 78 insertions, 49 deletions
| diff --git a/perl-install/mygtk2.pm b/perl-install/mygtk2.pm index 795ad69fa..6633decf3 100644 --- a/perl-install/mygtk2.pm +++ b/perl-install/mygtk2.pm @@ -22,10 +22,10 @@ sub init() {          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() ? ...) @@ -296,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; @@ -309,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 { @@ -345,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}) { @@ -353,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) = @_; @@ -373,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); @@ -389,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);  } @@ -442,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); @@ -585,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;      } @@ -667,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}; @@ -722,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(); @@ -740,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": @@ -790,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; @@ -820,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); @@ -839,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"); @@ -867,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");  	    }  	}      } @@ -1178,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); @@ -1199,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} || @@ -1213,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) = @_; @@ -1233,19 +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; -	    } -	}  -    }); +    $w->signal_connect(delete_event => \&quit_callback);      if ($::isInstall && !$::isStandalone) {  	require install::gtk; #- for perl_checker @@ -1270,7 +1294,7 @@ sub _create_Window {  	}) if $special_center;      } -    $w->present() if $no_Window_Manager; +    $w->present if $no_Window_Manager;      $w;  } @@ -1396,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 { @@ -1449,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; @@ -1520,7 +1549,7 @@ 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 { @@ -1540,7 +1569,7 @@ sub _get_weakness_tooltip {      my %weakness_tooltip = (          1 => N("Password is trivial to guess"),          2 => N("Password is trivial to guess"), -        3 => N("Password should resist to basic attacks"), +        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; | 
