aboutsummaryrefslogtreecommitdiffstats
path: root/modules/rpmdragora/dragoraUpdate
blob: b9894c075bb06736ff3a2504196681c8f2b73512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/usr/bin/perl
#*****************************************************************************
#
#  Copyright (c) 2002 Guillaume Cottenceau
#  Copyright (c) 2002-2007 Thierry Vignaud <tvignaud@mandriva.com>
#  Copyright (c) 2003, 2004, 2005 MandrakeSoft SA
#  Copyright (c) 2005-2007 Mandriva SA
#
#  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: MageiaUpdate 261845 2009-10-13 12:33:58Z tv $

use strict;
use MDK::Common::Func 'any';
# use lib qw(/usr/lib/libDrakX);
# use common;
use File::ShareDir ':ALL';

use AdminPanel::Rpmdragora::init;

use AdminPanel::rpmdragora;
use AdminPanel::Rpmdragora::gui;
use AdminPanel::Rpmdragora::rpmnew;
use AdminPanel::Rpmdragora::formatting;
use AdminPanel::Rpmdragora::pkg;
use AdminPanel::Shared::Locales;

use yui;

#use mygtk2 qw(gtknew);  #- do not import anything else, especially gtkadd() which conflicts with ugtk2 one
#use ugtk2 qw(:all);
# use Gtk2::SimpleList;



# make Rpmdrake::gui aware MageiaUpdate do not use the same columns ids as rpmdrake:
%pkg_columns = (
    image => 0,
    selected => 1,
    text => 2,
    short_name => 3,
    version => 4,
    release => 5,
    'arch' => 6,
    importance => 7,
);


our $w;
# TODO try to see if we can Moosify all!
our $statusbar;
my $loc = AdminPanel::rpmdragora::locale();

warn_about_user_mode();

my (%data, $initialized);

my %update_icons = (
    security => { icon => 'images/rpmdragora/security-update.png', text => $loc->N("Security") },
    bugfix   => { icon => 'images/rpmdragora/bugfix-update.png',   text => $loc->N("Bug fixing") },
    normal   => { icon => 'images/rpmdragora/general-update.png',  text => '' },
    title    => { icon => 'images/rpmdragora/title-update.png',    text => $loc->N("Here is the list of software package updates") },
);

my %icons_cache;


sub _refresh_packages_list {
    my ($dialog, $packageTbl) = @_;

    my $item = $packageTbl->selectedItem();
    my $packageName = $item ? $data{$item->index()}{name} : undef;

    # select packages to update:
    my @requested = sort grep { $pkgs->{$_}{pkg} } @filtered_pkgs;

    # don't select packages in skip list:
    if (!$initialized) {
        undef $pkgs->{$_}{selected} foreach @requested;
        my @selectable = grep { !$pkgs->{$_}{pkg}->flag_skip } @requested;
        toggle($packageTbl, @selectable) if @selectable;
        $initialized = 1;
    }

    $dialog->startMultipleChanges();
    $packageTbl->deleteAllItems();

    if (!scalar(@requested)) {
        AdminPanel::rpmdragora::interactive_msg($loc->N("rpmdragora update"),
                        $loc->N("The list of updates is empty. This means that either there is no available update for the packages installed on your computer, or you already installed all of them."),
                        scroll => 1
        );
    }
    else {
        my $itemCollection = new yui::YItemCollection;
        my $i = 0;
        foreach (@requested) {
            my $summary = get_summary($_);
            my ($name, $version, $release, $arch) = split_fullname($_);
            # TODO check if %data is needed
            $data{$i} = { name => $name, fullname => $_ }; $i++;
            my $pkg = $pkgs->{$_};
            my $raw_medium = pkg2medium($pkg->{pkg}, $urpm);
            my $medium = !$raw_medium->{fake} ? $raw_medium->{name} : undef;
            my $icon = "";

            $item = new yui::YCBTableItem("", $name , $summary, $version, $release, $arch);

            my $importance = $medium && $descriptions->{$medium}{$name}{importance};
            if ($importance) {
                my $update_label = "";
                if (yui::YUI::app()->hasImageSupport()) {
                    $icon = File::ShareDir::dist_file(AdminPanel::Shared::distName(), $update_icons{$importance}->{icon});
                }
                else {
                    # For ncurses set a label
                    $update_label = $update_icons{$importance}->{name};
                }
                my $cell = new yui::YTableCell($item, 1, $update_label, $icon);
            }

            $item->check($pkgs->{$_}{selected});
            $item->setLabel($name);
            $item->setSelected(1) if ($packageName && $name eq $packageName);
            $itemCollection->push($item);
            $item->DISOWN();
        }
        $packageTbl->addItems($itemCollection);

    }
    $dialog->doneMultipleChanges();

    # return number of packages to be updated
    return scalar(@requested);
}

sub toggle {
    my ($packageTbl, @names) = @_;
    my $name = $names[0];
    my $val = $pkgs->{$name}{selected};
    my $old_status = $val ? 'to_install' : 'to_update';
    my $done;
    my $pkg = $pkgs->{$name}{pkg};
    return if !$pkg;
    $pkg->set_flag_skip(0);
  #  toggle_nodes($packageTbl, $packageTbl, \&set_leaf_state, node_state($p[0][0]), @{$p[0]});

    toggle_nodes($packageTbl, $packageTbl, sub {
#                      my ($leaf, $_state, $_model) = @_;
#                      $done = 1;
#                      $list->{data}[$data{$leaf}][$pkg_columns{selected}] = $pkgs->{$name}{selected};
                 },
                 $old_status, @names);
#     # handle canceling:
#     $list->{data}[$data{$name}][$pkg_columns{selected}] = !$list->{data}[$data{$name}][$pkg_columns{selected}] if !$done;
}


sub quit() {
#     ($mandrivaupdate_width->[0], $mandrivaupdate_height->[0]) = $::w->{real_window}->get_size;
    real_quit();
}

sub run_treeview_dialog {
    my ($callback_action) = @_;

    my ($list, $info, $update_button);

    my $appTitle = yui::YUI::app()->applicationTitle();

    ## set new title to get it in dialog
    yui::YUI::app()->setApplicationTitle($loc->N("Software Management"));
    ## set icon if not already set by external launcher
    yui::YUI::app()->setApplicationIcon("/usr/share/mcc/themes/default/MageiaUpdate.png");

    my $mageiaPlugin = "mga";
    my $factory      = yui::YUI::widgetFactory;
    my $mgaFactory   = yui::YExternalWidgets::externalWidgetFactory($mageiaPlugin);
    $mgaFactory      = yui::YMGAWidgetFactory::getYMGAWidgetFactory($mgaFactory);

    my $dialog  = $factory->createMainDialog;

    $::main_window = $dialog; # rpmdrake way of working :(

    my $vbox    = $factory->createVBox( $dialog );

    #Line for logo and title
    my $hbox_iconbar  = $factory->createHBox($vbox);
    my $head_align_left  = $factory->createLeft($hbox_iconbar);
    $hbox_iconbar     = $factory->createHBox($head_align_left);
    my $wm_icon = File::ShareDir::dist_file(AdminPanel::Shared::distName(), $update_icons{'title'}->{icon});
    $factory->createImage($hbox_iconbar, $wm_icon);

    $factory->createHeading($hbox_iconbar, $update_icons{'title'}->{text});


    my $yTableHeader = new yui::YTableHeader();
    # checkbox
    $yTableHeader->addColumn("", $yui::YAlignCenter);
    # icon
    $yTableHeader->addColumn("", $yui::YAlignCenter);
    $yTableHeader->addColumn($loc->N("Name"), $yui::YAlignBegin);
    $yTableHeader->addColumn($loc->N("Summary"), $yui::YAlignBegin);
    $yTableHeader->addColumn($loc->N("Version"),  $yui::YAlignCenter);
    $yTableHeader->addColumn($loc->N("Release"), $yui::YAlignBegin);
    $yTableHeader->addColumn($loc->N("Arch"), $yui::YAlignBegin);

    ## service list (serviceBox)
    my $packageTbl = $mgaFactory->createCBTable($vbox, $yTableHeader, $yui::YCBTableCheckBoxOnFirstColumn);
                     $factory->createVSpacing($vbox, 1);
    my $infoBox    = $factory->createRichText($vbox, "", 0);
    $AdminPanel::Rpmdragora::pkg::probe_only_for_updates = 1; # faster startup

    pkgs_provider('all_updates', pure_updates => 1); # default mode

    my $num_pkgs = _refresh_packages_list($dialog, $packageTbl);
    if ($num_pkgs) {

        $packageTbl->setImmediateMode(1);
        $packageTbl->setWeight(0, 50);
        my $item = $packageTbl->selectedItem();
        if ($item) {
            my $pkg = $data{$item->index()}{fullname};
            AdminPanel::Rpmdragora::gui::setInfoOnWidget($pkg, $infoBox);
        }

        # dialog buttons
        $factory->createVSpacing($vbox, 1.0);
        ## Window push buttons
        my $hbox  = $factory->createHBox( $vbox );
        my $align = $factory->createLeft($hbox);
        $hbox     = $factory->createHBox($align);

        my $helpButton  = $factory->createPushButton($hbox, $loc->N("Help"));
        my $aboutButton = $factory->createPushButton($hbox, $loc->N("About") );
        $align = $factory->createRight($hbox);
        $hbox  = $factory->createHBox($align);

        ### Service Refresh button ($refreshButton)
        my $selectButton = $factory->createPushButton($hbox, $loc->N("Select all"));
        my $updateButton = $factory->createPushButton($hbox, $loc->N("Update"));
        my $closeButton  = $factory->createPushButton($hbox, $loc->N("Quit") );
        $statusbar       = $factory->createBusyIndicator($vbox, "" );

        my $info_options = {};

        while(1) {
            my $event     = $dialog->waitForEvent();
            my $eventType = $event->eventType();

            #event type checking
            if ($eventType == $yui::YEvent::CancelEvent) {
                last if quit();
            }
            elsif ($eventType == $yui::YEvent::MenuEvent) {
                my $item = $event->item();
                if (!$item) {
                    #URL emitted or at least a ref into RichText widget
                    my $url = yui::toYMenuEvent($event)->id ();
                    if (AdminPanel::Rpmdragora::gui::info_details($url, $info_options) )  {
                        $item = $packageTbl->selectedItem();
                        my $pkg = $data{$item->index()}{fullname};
                        AdminPanel::Rpmdragora::gui::setInfoOnWidget($pkg, $infoBox, $info_options);
                    }
                    else {
                        # default it's really a URL
                        AdminPanel::Rpmdragora::gui::run_browser($url);
                    }
                }
            }
            elsif ($eventType == $yui::YEvent::WidgetEvent) {
                # widget selected
                my $widget = $event->widget();

                if ($widget == $closeButton) {
                    last if quit();
                }
                elsif ($widget == $aboutButton) {
    #                 my $translators = $loc->N("_: Translator(s) name(s) & email(s)\n");
    #                 $translators =~ s/\</\&lt\;/g;
    #                 $translators =~ s/\>/\&gt\;/g;
    #                 $self->sh_gui->AboutDialog({ name => $self->name,
    #                                              version => $self->VERSION,
    #                          credits => $loc->N("Copyright (C) %s Mageia community", '2013-2014'),
    #                          license => $loc->N("GPLv2"),
    #                          description => $loc->N("dragoraUpdate is the Mageia update tool\n
    #                                                        (from the original idea of Mandriva MandrivaUpdate)."),
    #                          authors => $loc->N("<h3>Developers</h3>
    #                                                     <ul><li>%s</li>
    #                                                            <li>%s</li>
    #                                                        </ul>
    #                                                        <h3>Translators</h3>
    #                                                        <ul><li>%s</li></ul>",
    #                                                       "Angelo Naselli &lt;anaselli\@linux.it&gt;",
    #                                                       "Matteo Pasotti &lt;matteo.pasotti\@gmail.com&gt;",
    #                                                       $translators
    #                                                      ),
    #                             }
    #                 );
                }
                elsif ($widget == $packageTbl) {
                    yui::YUI::app()->busyCursor();
                    my $item = $packageTbl->selectedItem();
                    if ($item) {
                        my $pkg = $data{$item->index()}{fullname};
                        $info_options = {};
                        AdminPanel::Rpmdragora::gui::setInfoOnWidget($pkg, $infoBox);
                    }
                    my $wEvent = yui::toYWidgetEvent($event);
                    if ($wEvent->reason() == $yui::YEvent::ValueChanged) {
                        $item = $packageTbl->changedItem();
                        if ($item) {
                            my $name = $data{$item->index()}{fullname};
                            toggle($packageTbl, $name );
                            $num_pkgs = _refresh_packages_list($dialog, $packageTbl);
                        }
                    }
                    yui::YUI::app()->normalCursor();
                }
                elsif ($widget == $selectButton) {
                    yui::YUI::app()->busyCursor();
                    my @list;
                    foreach my $key (sort(keys %data)) {
                        push @list, $data{$key}{fullname};
                    }
                    toggle_all({
                        widgets => {detail_list => $packageTbl},
                        table_item_list => \@list,
                        set_state_callback => sub {1},
                    });
                    $num_pkgs = _refresh_packages_list($dialog, $packageTbl);

                    yui::YUI::app()->normalCursor();
                }
                elsif ($widget == $updateButton) {
                    my $res = do_action({ tree_mode => 'all_updates' }, $callback_action);
                    $initialized = 0 if !$res;
                    $num_pkgs =  _refresh_packages_list($dialog, $packageTbl);
                }
                elsif ($widget == $helpButton) {
                }
                last if !$num_pkgs;
            }
        }
    }

    $dialog->destroy();

    #restore old application title
    yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle;

}
# -=-=-=---=-=-=---=-=-=-- main -=-=-=---=-=-=---=-=-=-

AdminPanel::Rpmdragora::rpmnew::do_merge_if_needed();

AdminPanel::rpmdragora::readconf();

init();
run_treeview_dialog(\&perform_installation);

AdminPanel::rpmdragora::writeconf();

# myexit(0);