]> git.proxmox.com Git - pve-installer.git/blobdiff - proxinstall
stop main loop when closing the main window
[pve-installer.git] / proxinstall
index 7a156340f88fa38ef02e4d3b26b323f49b9708f9..21c7201eb388430cf957cc99b99346a8fad4c04e 100755 (executable)
@@ -235,10 +235,21 @@ compatibility_level = 2
 _EOD
 
 
-sub detect_country {
+sub app_quit {
+    my ($exit_code) = @_;
+
+    Gtk3->main_quit() if Gtk3->main_level() > 0;
+
+    # reap left over zombie processes
+    while ((my $child = waitpid(-1, POSIX::WNOHANG)) > 0) {
+       print "reaped child $child\n";
+    }
+    exit($exit_code);
+}
 
+sub detect_country {
     print "trying to detect country...\n";
-    my $cpid = open2(\*TMP, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
+    my $cpid = open2(my $TRACEROUTE_FH, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
     return undef if !$cpid;
 
     my $country;
@@ -247,7 +258,7 @@ sub detect_country {
     eval  {
        local $SIG{ALRM} = sub { die "timed out!\n" };
        my $line;
-       while (defined ($line = <TMP>)) {
+       while (defined ($line = <$TRACEROUTE_FH>)) {
            log_debug("DC TRACEROUTE: $line");
            if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
                my $geoip = `geoiplookup $1`;
@@ -260,12 +271,10 @@ sub detect_country {
            }
        }
     };
-
     my $err = $@;
-
     alarm ($previous_alarm);
 
-    close (TMP);
+    close($TRACEROUTE_FH);
 
     if ($err) {
        print "unable to detect country - $err\n";
@@ -494,7 +503,7 @@ sub ask_existing_vg_rename_or_abort {
                die "could not rename VG from '$vg->{pvs}' ($vg_uuid) to '$new_vgname'!\n";
        }
     } else {
-       set_next("_Reboot", sub { exit (0); } );
+       set_next("_Reboot", sub { app_quit(0); } );
        display_html("fail.htm");
        die "Cancled installation by user, due to already existing volume group '$vgname'\n";
     }
@@ -1489,11 +1498,12 @@ sub create_main_window {
 
     $window = Gtk3::Window->new();
     $window->set_default_size(1024, 768);
-    $window->set_has_resize_grip(0);
+    $window->signal_connect(map => sub { $window->set_resizable(0); });
     $window->fullscreen() if !is_test_mode();
     $window->set_decorated(0) if !is_test_mode();
+    $window->signal_connect(destroy => sub { Gtk3->main_quit(); });
 
-    my $vbox = Gtk3::VBox->new(0, 0);
+    my $vbox = Gtk3::Box->new('vertical', 0);
 
     my $logofn = "$env->{product}-banner.png";
     my $image = Gtk3::Image->new_from_file("${proxmox_libdir}/$logofn");
@@ -1506,17 +1516,17 @@ sub create_main_window {
 
     $vbox->pack_start($image, 0, 0, 0);
 
-    my $hbox = Gtk3::HBox->new(0, 0);
+    my $hbox = Gtk3::Box->new('horizontal', 0);
     $vbox->pack_start($hbox, 1, 1, 0);
 
  #  my $f1 = Gtk3::Frame->new ('test');
  #  $f1->set_shadow_type ('none');
  #  $hbox->pack_start ($f1, 1, 1, 0);
 
-    my $sep1 = Gtk3::HSeparator->new();
+    my $sep1 = Gtk3::Separator->new('horizontal');
     $vbox->pack_start($sep1, 0, 0, 0);
 
-    $cmdbox = Gtk3::HBox->new();
+    $cmdbox = Gtk3::Box->new('horizontal', 0);
     $vbox->pack_start($cmdbox, 0, 0, 10);
 
     $next = Gtk3::Button->new('_Next');
@@ -1532,33 +1542,34 @@ sub create_main_window {
     my $abort = Gtk3::Button->new('_Abort');
     $abort->set_can_focus(0);
     $cmdbox->pack_start($abort, 0, 0, 10);
-    $abort->signal_connect(clicked => sub { exit (-1); });
+    $abort->signal_connect(clicked => sub { app_quit(-1); });
 
-    my $vbox2 = Gtk3::VBox->new(0, 0);
+    my $vbox2 = Gtk3::Box->new('vertical', 0);
     $hbox->add($vbox2);
 
     $htmlview = Gtk3::WebKit2::WebView->new();
+    $htmlview->set_hexpand(1);
     my $scrolls = Gtk3::ScrolledWindow->new();
     $scrolls->add($htmlview);
 
-    my $hbox2 = Gtk3::HBox->new(0, 0);
+    my $hbox2 = Gtk3::Box->new('horizontal', 0);
     $hbox2->pack_start($scrolls, 1, 1, 0);
 
     $vbox2->pack_start($hbox2, 1, 1, 0);
 
-    my $vbox3 = Gtk3::VBox->new(0, 0);
+    my $vbox3 = Gtk3::Box->new('vertical', 0);
     $vbox2->pack_start($vbox3, 0, 0, 0);
 
-    my $sep2 = Gtk3::HSeparator->new;
+    my $sep2 = Gtk3::Separator->new('horizontal');
     $vbox3->pack_start($sep2, 0, 0, 0);
 
-    $inbox = Gtk3::HBox->new(0, 0);
+    $inbox = Gtk3::Box->new('horizontal', 0);
     $vbox3->pack_start($inbox, 0, 0, 0);
 
     $window->add($vbox);
 
     $window->show_all;
-    $window->realize();
+    $window->present();
 }
 
 sub cleanup_view {
@@ -1612,7 +1623,7 @@ sub create_text_input {
 
     my $label = Gtk3::Label->new($text);
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox->pack_start($label, 0, 0, 10);
     my $e1 = Gtk3::Entry->new();
     $e1->set_width_chars(35);
@@ -1628,7 +1639,7 @@ sub create_cidr_inputs {
 
     my $label = Gtk3::Label->new('IP Address (CIDR)');
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox->pack_start($label, 0, 0, 10);
 
     my $ip_el = Gtk3::Entry->new();
@@ -1638,7 +1649,6 @@ sub create_cidr_inputs {
 
     $label = Gtk3::Label->new('/');
     $label->set_size_request(10, -1);
-    $label->set_alignment(0.5, 0.5);
     $hbox->pack_start($label, 0, 0, 2);
 
     my $cidr_el = Gtk3::Entry->new();
@@ -1742,10 +1752,10 @@ sub create_ipconf_view {
        $device_cb->set_active(0);
     }
 
-    my $devicebox = Gtk3::HBox->new(0, 0);
+    my $devicebox = Gtk3::Box->new('horizontal', 0);
     my $label = Gtk3::Label->new("Management Interface:");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $devicebox->pack_start($label, 0, 0, 10);
     $devicebox->pack_start($device_cb, 0, 0, 0);
 
@@ -1862,7 +1872,7 @@ sub create_ack_view {
 
     cleanup_view();
 
-    my $vbox =  Gtk3::VBox->new(0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
     $inbox->pack_start($vbox, 1, 0, 0);
 
     my $reboot_checkbox = Gtk3::CheckButton->new('Automatically reboot after successful installation');
@@ -2001,15 +2011,15 @@ sub create_password_view {
 
     cleanup_view();
 
-    my $vbox2 =  Gtk3::VBox->new(0, 0);
+    my $vbox2 =  Gtk3::Box->new('vertical', 0);
     $inbox->pack_start($vbox2, 1, 0, 0);
-    my $vbox =  Gtk3::VBox->new(0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
     $vbox2->pack_start($vbox, 0, 0, 10);
 
-    my $hbox1 = Gtk3::HBox->new(0, 0);
+    my $hbox1 = Gtk3::Box->new('horizontal', 0);
     my $label = Gtk3::Label->new("Password");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox1->pack_start($label, 0, 0, 10);
     my $pwe1 = Gtk3::Entry->new();
     $pwe1->set_visibility(0);
@@ -2017,10 +2027,10 @@ sub create_password_view {
     $pwe1->set_size_request(200, -1);
     $hbox1->pack_start($pwe1, 0, 0, 0);
 
-    my $hbox2 = Gtk3::HBox->new(0, 0);
+    my $hbox2 = Gtk3::Box->new('horizontal', 0);
     $label = Gtk3::Label->new("Confirm");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox2->pack_start($label, 0, 0, 10);
     my $pwe2 = Gtk3::Entry->new();
     $pwe2->set_visibility(0);
@@ -2028,10 +2038,10 @@ sub create_password_view {
     $pwe2->set_size_request(200, -1);
     $hbox2->pack_start($pwe2, 0, 0, 0);
 
-    my $hbox3 = Gtk3::HBox->new(0, 0);
+    my $hbox3 = Gtk3::Box->new('horizontal', 0);
     $label = Gtk3::Label->new("Email");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox3->pack_start($label, 0, 0, 10);
     my $eme = Gtk3::Entry->new();
     $eme->set_size_request(200, -1);
@@ -2096,9 +2106,9 @@ sub create_country_view {
 
     my $locales = $env->{locales};
 
-    my $vbox2 =  Gtk3::VBox->new(0, 0);
+    my $vbox2 =  Gtk3::Box->new('vertical', 0);
     $inbox->pack_start($vbox2, 1, 0, 0);
-    my $vbox =  Gtk3::VBox->new(0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
     $vbox2->pack_start($vbox, 0, 0, 10);
 
     my $w = Gtk3::Entry->new();
@@ -2110,17 +2120,17 @@ sub create_country_view {
     $c->set_popup_set_width(1);
     $c->set_inline_completion(1);
 
-    my $hbox2 = Gtk3::HBox->new(0, 0);
+    my $hbox2 = Gtk3::Box->new('horizontal', 0);
     my $label = Gtk3::Label->new("Time zone");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox2->pack_start($label, 0, 0, 10);
     update_zonelist ($hbox2);
 
-    my $hbox3 = Gtk3::HBox->new(0, 0);
+    my $hbox3 = Gtk3::Box->new('horizontal', 0);
     $label = Gtk3::Label->new("Keyboard Layout");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox3->pack_start($label, 0, 0, 10);
 
     my $kmapcb = Gtk3::ComboBoxText->new();
@@ -2228,10 +2238,10 @@ sub create_country_view {
 
     $w->set_completion ($c);
 
-    my $hbox =  Gtk3::HBox->new(0, 0);
+    my $hbox =  Gtk3::Box->new('horizontal', 0);
 
     $label = Gtk3::Label->new("Country");
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $label->set_size_request(150, -1);
     $hbox->pack_start($label, 0, 0, 10);
     $hbox->pack_start($w, 0, 0, 0);
@@ -2295,7 +2305,7 @@ my $create_label_widget_grid = sub {
        my $widget = @$labeled_widgets[$i+1];
        my $label = Gtk3::Label->new(@$labeled_widgets[$i]);
        $label->set_visible(1);
-       $label->set_alignment (1, 0.5);
+       $label->set_xalign(1.0);
        $grid->attach($label, 0, $row, 1, 1);
        $widget->set_visible(1);
        $grid->attach($widget, 1, $row, 1, 1);
@@ -2523,7 +2533,7 @@ sub create_hdoption_view {
 
     # Filesystem type
     my $label0 = Gtk3::Label->new("Filesystem");
-    $label0->set_alignment (1, 0.5);
+    $label0->set_xalign(1.0);
     $grid->attach($label0, 0, $row, 1, 1);
 
     my $fstypecb = Gtk3::ComboBoxText->new();
@@ -2553,7 +2563,7 @@ sub create_hdoption_view {
 
     $row++;
 
-    my $sep = Gtk3::HSeparator->new();
+    my $sep = Gtk3::Separator->new('horizontal');
     $sep->set_visible(1);
     $grid->attach($sep, 0, $row, 2, 1);
     $row++;
@@ -2674,7 +2684,7 @@ sub create_hdoption_view {
        &$switch_view();
     });
 
-    my $sep2 = Gtk3::HSeparator->new();
+    my $sep2 = Gtk3::Separator->new('horizontal');
     $sep2->set_visible(1);
     $contarea->pack_end($sep2, 1, 1, 10);
 
@@ -2856,9 +2866,9 @@ sub create_hdsel_view {
 
     cleanup_view();
 
-    my $vbox =  Gtk3::VBox->new(0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
     $inbox->pack_start($vbox, 1, 0, 0);
-    my $hbox =  Gtk3::HBox->new(0, 0);
+    my $hbox =  Gtk3::Box->new('horizontal', 0);
     $vbox->pack_start($hbox, 0, 0, 10);
 
     my $cached_disks = get_cached_disks();
@@ -2943,12 +2953,12 @@ sub create_extract_view {
     $prev_btn->set_sensitive(0);
     $prev_btn->hide();
 
-    my $vbox =  Gtk3::VBox->new(0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
     $inbox->pack_start ($vbox, 1, 0, 0);
-    my $hbox =  Gtk3::HBox->new(0, 0);
+    my $hbox =  Gtk3::Box->new('horizontal', 0);
     $vbox->pack_start ($hbox, 0, 0, 10);
 
-    my $vbox2 =  Gtk3::VBox->new(0, 0);
+    my $vbox2 =  Gtk3::Box->new('vertical', 0);
     $hbox->pack_start ($vbox2, 0, 0, 0);
 
     $progress_status = Gtk3::Label->new('');
@@ -2971,7 +2981,7 @@ sub create_extract_view {
 
     $next->set_sensitive(1);
 
-    set_next("_Reboot", sub { exit (0); } );
+    set_next("_Reboot", sub { app_quit(0); } );
 
     if ($err) {
        display_html("fail.htm");
@@ -2986,7 +2996,7 @@ sub create_extract_view {
                    $autoreboot_seconds--;
                    display_html("success.htm");
                } else {
-                   exit(0);
+                   app_quit(0);
                }
            });
        }
@@ -3041,7 +3051,7 @@ my $initial_error = 0;
        print "no harddisks found\n";
        $initial_error = 1;
        display_html("nohds.htm");
-       set_next("Reboot", sub { exit(0); } );
+       set_next("Reboot", sub { app_quit(0); } );
     } else {
        foreach my $hd (@$cached_disks) {
            my ($disk, $devname) = @$hd;
@@ -3055,16 +3065,11 @@ if (!$initial_error && (scalar keys %{ $ipconf->{ifaces} } == 0)) {
     print "no network interfaces found\n";
     $initial_error = 1;
     display_html("nonics.htm");
-    set_next("Reboot", sub { exit(0); } );
+    set_next("Reboot", sub { app_quit(0); } );
 }
 
 create_intro_view () if !$initial_error;
 
 Gtk3->main;
 
-# reap left over zombie processes
-while ((my $child = waitpid(-1, POSIX::WNOHANG)) > 0) {
-    print "reaped child $child\n";
-}
-
-exit 0;
+app_quit(0);