/[soft]/rpmdrake/trunk/MageiaUpdate
ViewVC logotype

Contents of /rpmdrake/trunk/MageiaUpdate

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6096 - (show annotations) (download)
Thu Sep 27 17:18:52 2012 UTC (11 years, 6 months ago) by tv
File size: 10522 byte(s)
do not store {selected} in memory if not needed
1 #!/usr/bin/perl
2 #*****************************************************************************
3 #
4 # Copyright (c) 2002 Guillaume Cottenceau
5 # Copyright (c) 2002-2007 Thierry Vignaud <tvignaud@mandriva.com>
6 # Copyright (c) 2003, 2004, 2005 MandrakeSoft SA
7 # Copyright (c) 2005-2007 Mandriva SA
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2, as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #
22 #*****************************************************************************
23 #
24 # $Id: MageiaUpdate 261845 2009-10-13 12:33:58Z tv $
25
26 use strict;
27 use MDK::Common::Func 'any';
28 use lib qw(/usr/lib/libDrakX);
29 use common;
30
31 use Rpmdrake::init;
32 use standalone; #- standalone must be loaded very first, for 'explanations', but after rpmdrake::init
33 use rpmdrake;
34 use Rpmdrake::gui;
35 use Rpmdrake::rpmnew;
36 use Rpmdrake::formatting;
37 use Rpmdrake::pkg;
38 use Rpmdrake::widgets;
39
40 use mygtk2 qw(gtknew); #- do not import anything else, especially gtkadd() which conflicts with ugtk2 one
41 use ugtk2 qw(:all);
42 use Gtk2::SimpleList;
43
44 # make Rpmdrake::gui aware MageiaUpdate do not use the same columns ids as rpmdrake:
45 %pkg_columns = (
46 image => 0,
47 selected => 1,
48 text => 2,
49 short_name => 3,
50 version => 4,
51 release => 5,
52 'arch' => 6,
53 importance => 7,
54 );
55
56 $ugtk2::wm_icon = get_icon('MageiaUpdate', "title-$MODE");
57
58 our $w;
59 our $statusbar;
60
61 warn_about_user_mode();
62
63 my (%data, $initialized);
64
65 my %update_icons = (
66 security => 'security-update',
67 bugfix => 'bugfix-update',
68 normal => 'general-update',
69 );
70
71 my %icons_cache;
72
73 sub refresh_packages_list {
74 my ($list, $info, $button) = @_;
75 # select packages to update:
76 my @requested = sort grep { $pkgs->{$_}{pkg} } @filtered_pkgs;
77
78 # don't select packages in skip list:
79 if (!$initialized) {
80 undef $pkgs->{$_}{selected} foreach @requested;
81 my @selectable = grep { !$pkgs->{$_}{pkg}->flag_skip } @requested;
82 toggle($list, @selectable) if @selectable;
83 $initialized = 1;
84 }
85
86 my $i;
87 @{$list->{data}} = map {
88 $data{$_} = $i++;
89 my $summary = get_summary($_);
90 my ($name, $version, $release, $arch) = split_fullname($_);
91 my $pkg = $pkgs->{$_};
92 my $raw_medium = pkg2medium($pkg->{pkg}, $urpm);
93 my $medium = !$raw_medium->{fake} ? $raw_medium->{name} : undef;
94 my $icon;
95 my $importance = $medium && $descriptions->{$medium}{$name}{importance};
96 if ($importance) {
97 $icon = $icons_cache{$importance} ||= gtknew('Pixbuf', file => $update_icons{$importance});
98 }
99 [ $icon, $pkgs->{$_}{selected}, $_, format_name_n_summary($name, $summary), $version, $release, $arch, $importance ];
100 } @requested;
101 gtktext_insert($info,
102 formatAlaTeX(N("The list of updates is empty. This means that either there is
103 no available update for the packages installed on your computer,
104 or you already installed all of them."))) if !@{$list->{data}};
105 $button->set_sensitive(scalar(@{$list->{data}}));
106 }
107
108 sub toggle {
109 my ($list, @names) = @_;
110 my $name = $names[0];
111 my $val = $pkgs->{$name}{selected};
112 my $old_status = $val ? 'to_install' : 'to_update';
113 my $done;
114 my $pkg = $pkgs->{$name}{pkg};
115 return if !$pkg;
116 $pkg->set_flag_skip(0);
117 toggle_nodes($w->{real_window}->window, $list->get_model, sub {
118 my ($leaf, $_state, $_model) = @_;
119 $done = 1;
120 $list->{data}[$data{$leaf}][$pkg_columns{selected}] = $pkgs->{$name}{selected};
121 },
122 $old_status, @names);
123 # handle canceling:
124 $list->{data}[$data{$name}][$pkg_columns{selected}] = !$list->{data}[$data{$name}][$pkg_columns{selected}] if !$done;
125 }
126
127 $w = ugtk2->new(N("Software Management"));
128 $w->{rwindow}->show_all if $::isEmbedded;
129 $::main_window = $w->{real_window};
130
131 sub quit() {
132 ($mandrivaupdate_width->[0], $mandrivaupdate_height->[0]) = $::w->{real_window}->get_size;
133 real_quit();
134 }
135
136 sub run_treeview_dialog {
137 my ($callback_action) = @_;
138
139 my ($list, $info, $update_button);
140
141 my $rootwin_height = second(gtkroot()->get_size);
142 my $is_small_screen = $rootwin_height <= 480;
143
144 compute_main_window_size($w);
145
146 gtkadd(
147 $w->{window},
148 gtkpack_(
149 gtknew('VBox', spacing => 3),
150 if_(!$is_small_screen, 0, getbanner()),
151 0, gtknew('Title2', label => N("Here is the list of software package updates"), width => 600),
152 1, create_vpaned(
153 gtknew('ScrolledWindow', width => $typical_width*0.9, height => $is_small_screen ? 150 : 200,
154 child => $list = Gtk2::SimpleList->new(
155 " " => 'pixbuf',
156 " " . " " . " " => 'bool', #N("Selected")
157 '' => 'hidden',
158 " " . N("Name") . " " => 'markup', #N("Name")
159 " " . N("Version") . " " => 'text',
160 " " . N("Release") . " " => 'text',
161 " " . N("Arch") . " " => 'text',
162 '' => 'hidden',
163 ),
164 ),
165
166 gtknew('ScrolledWindow', width => $typical_width*0.9,
167 child => $info = Gtk2::Mdv::TextView->new, height => $is_small_screen ? 150 : 190,
168 ),
169 resize1 => 1,
170 ),
171 0, gtkset_size_request(Gtk2::HSeparator->new, -1, 5),
172 0, gtkpack_(
173 gtknew('HBox', spacing => 20),
174 0, gtksignal_connect(
175 Gtk2::Button->new(but_(N("Help"))),
176 clicked => sub { rpmdrake::open_help($MODE) },
177 ),
178 0, gtksignal_connect(
179 Gtk2::Button->new(but_(N("Select all"))),
180 clicked => sub {
181 toggle_all({
182 widgets => {
183 detail_list => $list,
184 detail_list_model => $list->get_model
185 },
186 }, 1);
187 refresh_packages_list($list, $info, $update_button);
188 },
189 ),
190 1, gtknew('Label'),
191 0, my $action_button = gtksignal_connect(
192 $update_button = Gtk2::Button->new(but_(N("Update"))),
193 clicked => sub {
194 my $res = do_action({ tree_mode => 'all_updates' }, $callback_action);
195 $initialized = 0 if !$res;
196 refresh_packages_list($list, $info, $update_button);
197 },
198 ),
199 0, gtksignal_connect(
200 Gtk2::Button->new(but_(N("Quit"))),
201 clicked => \&quit,
202 ),
203 ),
204 #0, $statusbar = Gtk2::Statusbar->new,
205 ),
206 );
207 $statusbar = Gtk2::Statusbar->new;
208
209 $list->get_model->set_sort_func($pkg_columns{image} + 1, sub {
210 my ($store, $treeiter1, $treeiter2) = @_;
211 $store->get_value($treeiter1, $pkg_columns{importance}) cmp
212 $store->get_value($treeiter2, $pkg_columns{importance});
213 });
214
215
216 $list->set_rules_hint(1);
217 my $pix_col = $list->get_column($pkg_columns{image});
218 $pix_col->set_fixed_width(32);
219 my $bool_col = $list->get_column($pkg_columns{selected});
220 $bool_col->set_fixed_width(24);
221 $bool_col->set_sizing('fixed');
222 $bool_col->set_sort_column_id($pkg_columns{selected});
223
224 # -1 because actual widget count differs from TreeModel one due to the hidden column:
225 foreach (@pkg_columns{qw(short_name version release arch)}) {
226 my $col = $list->get_column($_-1);
227 ($col->get_cell_renderers)[0]->set_property('xpad', '6');
228 $col->set_sizing('autosize');
229 $col->set_sort_column_id($_);
230 }
231
232 my $pretty_column = $list->get_column($pkg_columns{short_name}-1);
233 $pretty_column->set_resizable(1);
234 ($pretty_column->get_cell_renderers)[0]->set_property('ellipsize', 'end');
235 $pretty_column->set_property('expand', '1');
236
237 $list->get_selection->signal_connect(changed => sub {
238 my ($model, $iter) = $_[0]->get_selected;
239 $model && $iter or return;
240 gtktext_insert($info, get_info($model->get($iter, $pkg_columns{text}), $w->{real_window}->window));
241 $info->scroll_to_iter($info->get_buffer->get_start_iter, 0, 0, 0, 0);
242 });
243
244 $w->{rwindow}->set_default_size(-1, 500) if !$::isEmbedded;
245
246 if ($mandrivaupdate_width->[0] && $mandrivaupdate_height->[0]) {
247 # so that we can shrink back:
248 $w->{real_window}->set_default_size($mandrivaupdate_width->[0], $mandrivaupdate_height->[0]);
249 }
250 $w->{rwindow}->show_all;
251 $w->{rwindow}->set_sensitive(0);
252
253 # ensure treeview get realized so that ->get_selection returns something
254 $list->realize;
255 gtkflush();
256
257 $filter->[0] = 'all'; # default filter: availlable updates
258 $Rpmdrake::pkg::probe_only_for_updates = 1; # faster startup
259 pkgs_provider('all_updates', pure_updates => 1); # default mode
260
261 refresh_packages_list($list, $info, $update_button);
262
263 my $cell = ($bool_col->get_cell_renderers)[0];
264 $cell->signal_connect(toggled => sub {
265 my ($_cell, $text_path) = @_;
266 my $name = $list->{data}[$text_path][$pkg_columns{text}];
267 gtkset_mousecursor_wait($w->{real_window}->window);
268 my $_guard = before_leaving(sub { gtkset_mousecursor_normal($w->{real_window}->window) });
269 toggle($list, $name);
270 });
271 $action_button->set_sensitive(0) if $>;
272
273 $w->{rwindow}->set_sensitive(1);
274
275 $w->main;
276 }
277
278
279 # -=-=-=---=-=-=---=-=-=-- main -=-=-=---=-=-=---=-=-=-
280
281 do_merge_if_needed();
282
283 readconf();
284
285 init();
286 run_treeview_dialog(\&perform_installation);
287
288 writeconf();
289
290 myexit(0);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.30