/[soft]/rpm/urpmi/branches/2/gurpmi
ViewVC logotype

Contents of /rpm/urpmi/branches/2/gurpmi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4897 - (show annotations) (download)
Fri Jun 8 21:07:33 2012 UTC (11 years, 10 months ago) by tv
File size: 3717 byte(s)
branch

1 #!/usr/bin/perl
2
3 #- Copyright (C) 2005 MandrakeSoft SA
4 #- Copyright (C) 2005-2010 Mandriva SA
5
6 use strict;
7
8 BEGIN { #- set up a safe path and environment
9 $ENV{PATH} = "/bin:/usr/bin:/usr/X11R6/bin";
10 delete @ENV{qw(ENV BASH_ENV IFS CDPATH)};
11 }
12
13 use Gtk2;
14 use gurpmi;
15 use urpm::util;
16
17 sub usage() { gurpmi::usage() }
18
19 #- globals
20 my ($srpms, $rpms) = ([], []);
21 my ($mainw, $mainbox);
22 my @all_rpms = gurpmi::parse_command_line();
23
24 #- Now, the graphical stuff.
25
26 Gtk2->init;
27
28 #- Create main window
29
30 $mainw = Gtk2::Window->new('toplevel');
31 $mainw->set_border_width(3);
32 $mainw->set_title(N("RPM installation"));
33 $mainw->signal_connect(destroy => \&cancel_n_quit);
34 $mainw->set_position('center');
35 $mainw->set_modal(0);
36 $mainbox = Gtk2::VBox->new(0, 5);
37 $mainw->add($mainbox);
38
39 sub all_descriptions {
40 my (@rpms) = @_;
41 join '', `rpm -qp --qf '%{name}-%{version}-%{release}: %{summary}\\n' @rpms`;
42 }
43
44 foreach (@all_rpms) {
45 unless (-e $_) {
46 $mainbox->pack_start(new_label(N("Error: unable to find file %s, will cancel operation", $_)), 1, 1, 0);
47 my $abort_button = Gtk2::Button->new(but(N("_Ok")));
48 $abort_button->signal_connect(clicked => sub { cancel_n_quit(); exit 1 });
49 add_button_box($mainbox, $abort_button);
50 $mainw->show_all;
51 Gtk2->main;
52 }
53 /\.src\.rpm$/ ? push(@$srpms, $_) : push(@$rpms, $_);
54 }
55
56 sub proceed() {
57 #- we need to switch to root if we're not already (via consolehelper)
58 #- yes. hardcoded paths. safe.
59 exec $> ? '/usr/bin/gurpmi2' : '/usr/sbin/gurpmi2', @ARGV;
60 }
61
62 #- Ask question: save or install ?
63 #- change depending on the number of rpms, and on the presence of srpms
64 if (!$gurpmi::options{auto} && @all_rpms + @gurpmi::names) {
65 my $msg = (
66 @$srpms > 0
67 ? N("You have selected a source package:
68
69 %s
70
71 You probably didn't want to install it on your computer (installing it would allow you to make modifications to its sourcecode then compile it).
72
73 What would you like to do?", basename($srpms->[0]))
74 : @all_rpms == 0
75 ? N("You are about to install the following software packages on your computer:
76
77 %s
78
79 Proceed?", join("\n", map { "- $_" } @gurpmi::names))
80 : @all_rpms == 1
81 ? N("You are about to install the following software package on your computer:
82
83 %s
84
85 You may prefer to just save it. What is your choice?", all_descriptions($rpms->[0]))
86 : N("You are about to install the following software packages on your computer:
87
88 %s
89
90 Proceed?", all_descriptions(@all_rpms))
91 );
92 $mainbox->pack_start(new_label($msg), 1, 1, 0);
93 } else {
94 #- we're doing an --auto-select, proceed without asking
95 proceed();
96 }
97
98 { #- buttons
99 my $inst_button = Gtk2::Button->new(but(N("_Install")));
100 my $save_button = @all_rpms == 1 ? Gtk2::Button->new(but(N("_Save"))) : undef;
101 my $ccel_button = Gtk2::Button->new(but(N("_Cancel")));
102
103 $inst_button->signal_connect(clicked => sub {
104 #- performs installation.
105 quit();
106 proceed();
107 });
108 $save_button and $save_button->signal_connect(clicked => sub {
109 my $file_dialog = Gtk2::FileSelection->new(N("Choose location to save file"));
110 $file_dialog->set_modal(1);
111 $file_dialog->set_position('center');
112 my $filename = @$srpms > 0 ? $srpms->[0] : $rpms->[0];
113 $file_dialog->set_filename($filename);
114 $file_dialog->hide_fileop_buttons;
115 $file_dialog->ok_button->signal_connect(clicked => sub {
116 my $location = $file_dialog->get_filename;
117 quit();
118 $location and exec '/bin/mv', '-f', $filename, $location;
119 });
120 $file_dialog->cancel_button->signal_connect(clicked => \&quit);
121 $file_dialog->show;
122 });
123 $ccel_button->signal_connect(clicked => \&cancel_n_quit);
124 add_button_box($mainbox, grep { defined $_ } $inst_button, $save_button, $ccel_button);
125 }
126
127 $mainw->show_all;
128 Gtk2->main;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.30