#***************************************************************************** # # Copyright (c) 2002 Guillaume Cottenceau (gc at mandrakesoft dot com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # #***************************************************************************** # # $Id$ use lib qw(/usr/lib/libDrakX); use standalone; #- warning, standalone must be loaded very first, for 'explanations' use MDK::Common; use urpm; use URPM; use URPM::Resolve; use packdrake; use strict; use vars qw($configfile %config $mandrakeupdate_wanted_categories $already_splashed $max_info_in_descr $typical_width); use log; use c; use curl_download; eval { require ugtk2; ugtk2->import(qw(:all)) }; if ($@) { print "This program cannot be run in console mode.\n"; c::_exit(0); #- skip ugtk2::END } ugtk2::add_icon_path('/usr/share/rpmdrake/icons'); c::bind_textdomain_codeset('rpmdrake', 'UTF8'); sub translate { my ($s) = @_; my $r = $s ? c::dgettext('rpmdrake', $s) : ''; c::set_tagged_utf8($r); $r; } sub sprintf_fixutf8 { my $need_upgrade; $need_upgrade |= to_bool(c::is_tagged_utf8($_)) + 1 foreach @_; if ($need_upgrade == 3) { c::upgrade_utf8($_) foreach @_ }; sprintf shift, @_; } sub N { my $s = shift @_; my $t = translate($s); sprintf_fixutf8 $t, @_; } sub myexit { ugtk2::exit(undef, @_) } $ENV{HOME} ||= '/root'; sub readconf { $configfile = "$ENV{HOME}/.rpmdrake"; %config = (mandrakeupdate_wanted_categories => { var => \$mandrakeupdate_wanted_categories, default => [ qw(security) ] }, already_splashed => { var => \$already_splashed, default => [] }, max_info_in_descr => { var => \$max_info_in_descr, default => [] }, ); ${$config{$_}{var}} = $config{$_}{default} foreach keys %config; foreach my $l (cat_($configfile)) { $l =~ /^\Q$_\E (.*)/ and ${$config{$_}{var}} = [ split ' ', $1 ] foreach keys %config; } } sub writeconf { output $configfile, map { "$_ " . join(' ', @${$config{$_}{var}}) . "\n" } keys %config; } sub interactive_msg { my ($title, $contents, %options) = @_; my $d = ugtk2->new($title, grab => 1, if_(exists $options{transient}, transient => $options{transient})); gtkadd($d->{window}, gtkpack_(Gtk2::VBox->new(0,5), 1, $options{scroll} ? gtkadd(gtkset_shadow_type(Gtk2::Frame->new, 'in'), gtkset_size_request(create_scrolled_window(gtktext_insert(Gtk2::TextView->new, $contents)), $typical_width*2, 300)) : Gtk2::Label->new($contents), 0, gtkpack(create_hbox(), ref($options{yesno}) eq 'ARRAY' ? map { my $label = $_; gtksignal_connect(Gtk2::Button->new($label), clicked => sub { $d->{retval} = $label; Gtk2->main_quit }) } @{$options{yesno}} : $options{yesno} ? (gtksignal_connect(Gtk2::Button->new($options{text}{yes} || N("Yes")), clicked => sub { $d->{retval} = 1; Gtk2->main_quit }), gtksignal_connect(Gtk2::Button->new($options{text}{no} || N("No")), clicked => sub { $d->{retval} = 0; Gtk2->main_quit })) : gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub { Gtk2->main_quit }) ))); $d->main; } sub interactive_packtable { my ($title, $parent_window, $top_label, $lines, $action_buttons) = @_; my $w = ugtk2->new($title, grab => 1, transient => $parent_window); my $packtable = create_packtable({}, @$lines); gtkadd($w->{window}, gtkpack_(Gtk2::VBox->new(0, 5), if_($top_label, 0, Gtk2::Label->new($top_label)), 1, create_scrolled_window($packtable), 0, gtkpack__(create_hbox(), @$action_buttons))); my ($xpreq, $ypreq) = $packtable->size_request->values; my ($xwreq, $ywreq) = $w->{rwindow}->size_request->values; $w->{rwindow}->set_default_size(max($typical_width, min($typical_width*2.5, $xpreq+$xwreq)), max(200, min(450, $ypreq+$ywreq))); $w->main; } sub interactive_list { my ($title, $contents, $list, $callback, %options) = @_; my $d = ugtk2->new($title, grab => 1, if_(exists $options{transient}, transient => $options{transient})); my @radios = gtkradio('', @$list); my $vbradios = $callback ? create_packtable({}, mapn { my $n = $_[1]; [ $_[0], gtksignal_connect(Gtk2::Button->new(but(N("Info..."))), clicked => sub { $callback->($n) }) ] } \@radios, $list) : gtkpack__(Gtk2::VBox->new(0, 0), @radios); my $choice; gtkadd($d->{window}, gtkpack__(Gtk2::VBox->new(0,5), Gtk2::Label->new($contents), int(@$list) > 8 ? gtkset_size_request(create_scrolled_window($vbradios), 250, 320) : $vbradios, gtkpack__(create_hbox(), gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub { each_index { $_->get_active and $choice = $::i } @radios; Gtk2->main_quit })))); $d->main; $choice; } sub fatal_msg { interactive_msg @_; myexit -1; } sub wait_msg { my ($msg, %options) = @_; my $mainw = ugtk2->new('rpmdrake', grab => 1, if_(exists $options{transient}, transient => $options{transient})); my $label = ref($msg) =~ /^Gtk/ ? $msg : Gtk2::Label->new($msg); gtkadd($mainw->{window}, gtkpack(gtkadd(create_vbox(), $label, if_(exists $options{widgets}, @{$options{widgets}})))); $label->signal_connect(expose_event => sub { $mainw->{displayed} = 1; 0 }); $mainw->sync until $mainw->{displayed}; gtkset_mousecursor_wait($mainw->{rwindow}->window); $mainw->flush; $mainw; } sub remove_wait_msg { $_[0]->destroy } sub but { " $_[0] " } sub but_ { " $_[0] " } sub slow_func($&) { my ($param, $func) = @_; if (ref($param) =~ /^Gtk/) { gtkset_mousecursor_wait($param); ugtk2::flush(); $func->(); gtkset_mousecursor_normal($param); } else { my $w = wait_msg($param); $func->(); remove_wait_msg($w); } } my %u2l = ( at => N("Austria"), au => N("Australia"), be => N("Belgium"), br => N("Brazil"), ca => N("Canada"), cr => N("Costa Rica"), cz => N("Czech Republic"), de => NGenerated by cvs2cl the 27_Aug