summaryrefslogtreecommitdiff
path: root/Master/tlpkg/dev/tlmgrgui2.pl
blob: 70bf1a0c8cd217c66cd4eb92e95ed792c8774f32 (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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
#!/usr/bin/env perl
# $Id: tlmgrgui2.pl 15823 2009-10-18 01:41:28Z preining $
#
# Copyright 2009 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
#
# GUI for tlmgr

use Tk;
use Tk::Dialog;
use Tk::NoteBook;
use Tk::BrowseEntry;
use Tk::ROText;
use Tk::Balloon;
use Tk::TixGrid;
use TeXLive::Splashscreen;

use TeXLive::TLUtils qw(setup_programs platform_desc win32 debug);
use TeXLive::TLConfig;

our $Master;
our $tlmediatlpdb;
our $tlmediasrc;
our $location;
#
our %opts;
#
# the list of packages as shown by TixGrid
#
my %Packages;

sub update_status_box {
  update_status(join(" ", @_));
  $mw->update;
}

sub init_hooks {
  push @::info_hook, \&update_status_box;
  push @::warn_hook, \&update_status_box;
  push @::debug_hook, \&update_status_box;
  push @::ddebug_hook, \&update_status_box;
  push @::dddebug_hook, \&update_status_box;
}

sub update_status {
  my ($p) = @_;
  $::progressw->insert("end", "$p");
  $::progressw->see("end");
}

my $opt_screen = $::guiscreen;


# prepare for loading of lang.pl which expects $::lang and $::opt_lang
$::opt_lang = $opts{"gui-lang"} if (defined($opts{"gui-lang"}));

require("TeXLive/trans.pl");

our @update_function_list;

our $mw = MainWindow->new;
$mw->title("TeX Live Manager $TeXLive::TLConfig::ReleaseYear");
$mw->withdraw;

#
# default layout definitions
#
# priority 20 = widgetDefault 
# see Mastering Perl/Tk, 16.2. Using the Option Database
$mw->optionAdd("*Button.Relief", "ridge", 20);
#
# does not work, makes all buttons exactely 10, which is not a good idea
# I would like to have something like MinWidth 10...
#$mw->optionAdd("*Button.Width", "10", 20);
#
# shortcuts for padding, expand/fill, and pack sides, anchors
my @p_ii = qw/-padx 2m -pady 2m/;
my @p_iii= qw/-padx 3m -pady 3m/;
my @x_x = qw/-expand 1 -fill x/;
my @x_y = qw/-expand 1 -fill y/;
my @x_xy= qw/-expand 1 -fill both/;
my @left = qw/-side left/;
my @right= qw/-side right/;
my @bot  = qw/-side bottom/;
my @a_w = qw/-anchor w/;
my @a_c = qw/-anchor c/;


# create a progress bar window
$::progressw = $mw->Scrolled("ROText", -scrollbars => "e", -height => 4);
$::progressw->pack(-fill => "x", @bot);


init_hooks();

info(__("Loading local TeX Live Database\nThis may take some time, please wait!") . "\n");

our $localtlmedia = TeXLive::TLMedia->new ( $Master );
die("cannot setup TLMedia in $Master") unless (defined($localtlmedia));
$localtlpdb = $localtlmedia->tlpdb;
die("cannot find tlpdb!") unless (defined($localtlpdb));

our @main_list;

my $loc = $localtlpdb->option("location");
if (defined($loc)) {
  $location = $loc;
}
if (defined($opts{"location"})) {
  $location = $opts{"location"};
}

our $balloon = $mw->Balloon();


push @update_function_list, \&check_location_on_ctan;
push @update_function_list, \&init_install_media;

#
# check that we can actually save the database
#
if (check_on_writable()) {
  $::we_can_save = 1;
} else {
  $::we_can_save = 0;
  # here we should pop up a warning window!!!
}
$::action_button_state = ($::we_can_save ? "normal" : "disabled");

our $top = $mw->Frame;

our $top_top = $top->Frame;
our $top_bot = $top->Frame;
$top_top->pack(@x_x);
$top_bot->pack(@x_x);

our $quit = $top_top->Button(-text => __("Quit"), 
                         -command => sub { $mw->destroy; exit(0); });

my $tlmgrrev = give_version();
chomp($tlmgrrev);
our $about = $top_top->Button(-text => __("About"), 
  -command => sub {
    my $sw = $mw->DialogBox(-title => __("About"), 
                            -buttons => [ __("Ok") ]);
    $sw->add("Label", -text => "TeX Live Manager
$tlmgrrev
Copyright 2008 Tomasz Luczak
Copyright 2008, 2009 Norbert Preining

Licensed under the GNU General Public License version 2 or higher
In case of problems, please contact: texlive\@tug.org"
      )->pack(@p_iii);
    $sw->Show;
    });

$about->pack(@right);
$quit->pack(@right);

$mw->bind('<Escape>', [ $quit, 'Invoke' ]);


$top_top->Label(-text => __("Repository to use") . " ")->pack(@left);
$top_bot->Button(-text => __("Load default"), 
                 -command => sub { run_update_functions(); })->pack(@left);
$top_bot->Button(-text => __("Load other"), 
                 -command => sub { menu_edit_location(); })->pack(@left);
$top_bot->Label(-text => __("Loaded repository:") . " ")->pack(@left);
$top_bot->Label(-textvariable => \$location)->pack(@left);



# here we add a bit of trickery to make sure that the verbosity level
# as set on the cmd line (-v or -v -v) is kept during pressing the 
# debug button on and off. If -v is *not* given activating it afterwards
# defaults to one -v, while if -v -v is given on the cmd line, we keep
# it that way
$balloon->attach(
  $top_bot->Checkbutton(-text => __("Debug"), 
                    -onvalue => ($::opt_verbosity == 0 ? 1 : $::opt_verbosity),
                    -variable => \$::opt_verbosity)->pack(@right),
  -balloonmsg => __("Turn on debug mode."));

# frame .back -borderwidth 2
our $back = $mw->NoteBook(-borderwidth => 2, -dynamicgeometry => 1);


# pack .top .back -side top -fill both -expand 1
$top->pack(-fill => 'x', @p_ii);
$back->pack(@x_xy);

#require ("do_listframe.pl");

######### SHOULD GO INTO A SEPARTE FILE ########################
# install screen
our $back_f1 = $back->add("packages",-label => __("Packages"), -justify => "left");

$screens{"packages"} = $back_f1;

my $top_frame = $back_f1->Labelframe(-text => "Display configuration");
$top_frame->pack(@x_x, @p_ii);

my $filter_frame = $top_frame->Frame();
$filter_frame->pack;

my $filter_status = $filter_frame->Labelframe(-text => "Status");
$filter_status->pack(@left, @p_ii);

my $status_all = 0;
my $status_only_installed = 1;
my $status_only_not_installed = 2;
my $status_only_updated = 3;
my $status_value = 0;
$filter_status->Radiobutton(-text => "all", 
  -variable => \$status_value, -value => $status_all)->pack(@a_w);
$filter_status->Radiobutton(-text => "only installed", 
  -variable => \$status_value, -value => $status_only_installed)->pack(@a_w);
$filter_status->Radiobutton(-text => "only uninstalled", 
  -variable => \$status_value, -value => $status_only_not_installed)->pack(@a_w);
$filter_status->Radiobutton(-text => "only updated", 
  -variable => \$status_value, -value => $status_only_updated)->pack(@a_w);

my $filter_category = $filter_frame->Labelframe(-text => "Category");
$filter_category->pack(@left, @x_y, @p_ii);
my $show_packages = 1;
my $show_collections = 1;
my $show_schemes = 1;
$filter_category->Checkbutton(-text => "packages", 
   -variable => \$show_packages)->pack(@a_w);
$filter_category->Checkbutton(-text => "collections", 
   -variable => \$show_collections)->pack(@a_w);
$filter_category->Checkbutton(-text => "schemes", 
   -variable => \$show_schemes)->pack(@a_w);

my $filter_match = $filter_frame->Labelframe(-text => "Match");
$filter_match->pack(@left, @x_y, @p_ii);
my $match_value = 0;
$filter_match->Radiobutton(-text => "all", 
        -variable => \$match_value, -value => 0)->pack(@a_w);
$filter_match->Radiobutton(-text => "matching:",
        -variable => \$match_value, -value => 1)->pack(@a_w);
$filter_match->Entry(-width => 15)->pack(@a_w, -padx => '2m', @x_x);

my $filter_selection = $filter_frame->Labelframe(-text => "Selection");
$filter_selection->pack(@left, @x_y, @p_ii);
my $selection_value = 0;
$filter_selection->Radiobutton(-text => "all", 
                         -variable => \$selection_value, -value => 0)->pack(@a_w);
$filter_selection->Radiobutton(-text => "only selected", 
                         -variable => \$selection_value, -value => 1)->pack(@a_w);
$filter_selection->Radiobutton(-text => "only not selected", 
                         -variable => \$selection_value, -value => 2)->pack(@a_w);


my $filter_button = $filter_frame->Labelframe(-text => "Action");
$filter_button->pack(@left, @x_y, @p_ii);
$filter_button->Button(-text => "Apply filters",
  -command => sub { update_grid(); })->pack(@a_c, @p_ii);
$filter_button->Button(-text => "Reset filters",
  -command => sub { $status_value = $status_all;
                    $show_packages = 1; $show_collections = 1;
                    $show_schemes = 1; $show_tlcore = 1;
                    $selection_value = 0;
                    $match_value = 0;
                    update_grid();
                  })->pack(@a_c, @p_ii);

########## Packages #######################
my $list_frame = $back_f1->Labelframe(-text => "Packages");
$list_frame->pack(@x_xy, @p_ii);
my $g = $list_frame->Scrolled('TixGrid', -scrollbars => "se", -bd => 0,
                                      -floatingrows => 0, -floatingcols => 0,
				 -leftmargin => 2, # selection and label
				 -topmargin => 1, # top labels
				 -selectmode => "none", 
				 -selectunit => "row");

$g->pack(qw/-expand 1 -fill both -padx 3 -pady 3/);
$g->configure(-formatcmd=>[\&AlternatingLineColoring, $g]);
$g->size(qw/col 4 -size 10char/);
$g->size(qw/col 5 -size 10char/);
$g->size(qw/col default -size auto/);
$g->size(qw/row default -size 1.1char -pad0 3/);

setup_list();
update_grid();

sub update_grid {
  # fill the header
  #$g->set(0,0, -itemtype => 'window', -widget => $g->Checkbutton());
  $g->set(1,0, -itemtype => 'text', -text => "Package");
  $g->set(2,0, -itemtype => 'text', -text => "Local Rev");
  $g->set(3,0, -itemtype => 'text', -text => "Remote Rev");
  $g->set(4,0, -itemtype => 'text', -text => "Local Ver");
  $g->set(5,0, -itemtype => 'text', -text => "Remote Ver");
  $g->set(6,0, -itemtype => 'text', -text => "Short Desc");

  my @schemes;
  my @colls;
  my @packs;
  for my $p (sort keys %Packages) {
    if ($Packages{$p}{'category'} eq "Scheme") {
      push @schemes, $p;
    } elsif ($Packages{$p}{'category'} eq "Collection") {
      push @colls, $p;
    } else {
      push @packs, $p;
    }
  }
  my $i = 1;
  # the number of current lines:
  my (undef, $curlines) = $g->index(0, 'max');
  for my $p (@schemes, @colls, @packs) {
    if (MatchesFilters($p)) {
      if (!$g->infoExists(0,$i)) {
        $g->set(0,$i, -itemtype => 'window', -widget => $g->Checkbutton);
      }
      $g->set(1,$i, -itemtype => 'text', -text => $Packages{$p}{'displayname'});
      $g->set(2,$i, -itemtype => 'text', -text => $Packages{$p}{'localrevision'})
        if defined($Packages{$p}{'localrevision'});
      $g->set(3,$i, -itemtype => 'text', -text => $Packages{$p}{'remoterevision'})
        if defined($Packages{$p}{'remoterevision'});
      $g->set(4,$i, -itemtype => 'text', -text => $Packages{$p}{'localcatalogueversion'})
        if defined($Packages{$p}{'localcatalogueversion'});
      $g->set(5,$i, -itemtype => 'text', -text => $Packages{$p}{'remotecatalogueversion'})
        if defined($Packages{$p}{'remotecatalogueversion'});
      $g->set(6,$i, -itemtype => 'text', -text => $Packages{$p}{'shortdesc'});
      $i++;
    }
  }
  if ($i <= $curlines) {
    # remove the rest of the lines
    $g->deleteRow($i, $curlines);
  }
}
  
sub MatchesFilters {
  my $p = shift;
  # status
  if (( ($status_value == $status_all) ) ||
      ( ($status_value == $status_only_installed) && 
        (defined($Packages{$p}{'installed'})) && 
        ($Packages{$p}{'installed'} == 1) ) ||
      ( ($status_value == $status_only_not_installed) &&
        ( !defined($Packages{$p}{'installed'}) ||
          ($Packages{$p}{'installed'} == 0)) ) ||
      ( ($status_value == $status_only_updated) &&
        (defined($Packages{$p}{'localrevision'})) &&
        (defined($Packages{$p}{'remoterevision'})) &&
        ($Packages{$p}{'localrevision'} < $Packages{$p}{'remoterevision'}))) {
    # do nothing, more checks have to be done
  } else {
    return 0;
  }
  # category
  if (($show_packages    && ($Packages{$p}{'category'} eq 'Other')) ||
      ($show_collections && ($Packages{$p}{'category'} eq 'Collection')) ||
      ($show_schemes     && ($Packages{$p}{'category'} eq 'Scheme')) ) {
    # do nothing, more checks have to be done
  } else {
    return 0;
  }
  # match
  # TO BE DONE!!!
  # selection
  # TO BE DONE!!!
  #
  # if we come down to here the package matches
  return 1;
}


sub AlternatingLineColoring {
  my ($w, $area, @entbox) = @_;
  if ($area eq 'main') {
    # first format all cells
    # no select background -selectbackground => 'lightblue',
    $w->formatGrid( @entbox, -selectbackground => 'gray70',
      -xon => 1, -xoff => 0, -yon => 1, -yoff => 0,
      -relief => 'raised', -bd => 0, -filled => 1, -bg => 'gray70');
    # format odd lines 1,3,5,7, ... (counting starts at 0!!!)
    $w->formatGrid( @entbox, -selectbackground => 'gray90',
      -xon => 1, -xoff => 0, -yon => 1, -yoff => 1,
      -relief => 'raised', -bd => 0, -filled => 1, -bg => 'gray90');
  }
  if ($area eq 'y_margin') {
    my ($ulx, $uly, $lrx, $lry) = @entbox;
    # format the checkbuttons backgrounds
    for my $i ($uly..$lry) {
      if ($w->infoExists(0,$i)) {
        $cb = $w->entrycget(0, $i, "-window");
        $cb->configure(-background => (($i-$uly)%2 ? 'gray70' : 'gray90'));
      }
    }
    # first format all cells
    # no select background -selectbackground => 'lightblue',
    $w->formatBorder( @entbox, -selectbackground => 'gray70',
      -xon => 1, -xoff => 0, -yon => 1, -yoff => 0,
      -relief => 'raised', -bd => 0, -filled => 1, -bg => 'gray70');
    # format odd lines 1,3,5,7, ... (counting starts at 0!!!)
    $w->formatBorder( @entbox, -selectbackground => 'gray90',
      -xon => 1, -xoff => 0, -yon => 1, -yoff => 1,
      -relief => 'raised', -bd => 0, -filled => 1, -bg => 'gray90');
  }
}

####### actions frame

my $bot_frame = $back_f1->Labelframe(-text => "Actions");
$bot_frame->pack(@x_x, @p_ii);

my $actions_frame = $bot_frame->Frame;
$actions_frame->pack();

my $with_sel_frame = $actions_frame->Labelframe(-text => "with selected");
$with_sel_frame->pack(@left, @p_ii);
my $action_apply_filter = 1;
$with_sel_frame->Label(-text => "with filters")->pack(@left, @p_ii);

$with_sel_frame->Radiobutton(-text => "applied", 
        -variable => \$action_apply_filter, -value => 1)->pack(@left, @p_ii);
$with_sel_frame->Radiobutton(-text => "not applied", 
        -variable => \$action_apply_filter, -value => 0)->pack(@left, @p_ii);
$with_sel_frame->Button(-text => 'Install')->pack(@left, @p_ii);
$with_sel_frame->Button(-text => 'Upgrade')->pack(@left, @p_ii);
$with_sel_frame->Button(-text => 'Remove')->pack(@left, @p_ii);
$with_sel_frame->Button(-text => 'Backup')->pack(@left, @p_ii);

my $with_all_frame = $actions_frame->Labelframe(-text => "with all");
$with_all_frame->pack(@left, @p_ii);
$with_all_frame->Button(-text => 'Update all')->pack(@a_c,@left,@p_ii);

######################## UNINSTALL ###########################
# uninstall screen
require("gui-uninstall.pl");
# arch support not be done via tlmgr on win32
if (!win32()) {
  require("gui-arch.pl");
}
# config screen
require("gui-config.pl");

if ($opt_load) {
  run_update_functions();
}


if (defined($opt_screen)) {
  $back->raise("$opt_screen");
}

info(__("Completed") . "\n");
$mw->deiconify;


if (!$::we_can_save) {
  my $no_write_warn = $mw->Dialog(-title => "warning",
    -text => __("You don't have permissions to change the installation in any way,\nspecifically, the directory %s is not writable.\nPlease run this program as administrator, or contact your local admin.\n\nMost buttons will be disabled.", "$Master/tlpkg/"),
    -buttons => [ __("Ok") ])->Show();
}

Tk::MainLoop();


sub init_install_media {
  my $newroot = $location;
  if (defined($tlmediatlpdb) && ($tlmediatlpdb->root eq $newroot)) {
    # nothing to be done
  } else {
    $mw->Busy(-recurse => 1);
    info(__("Loading remote TeX Live Database\nThis may take some time, please wait!") . "\n");
    $tlmediasrc = TeXLive::TLMedia->new($newroot);
    info(__("Completed") . "\n");
    $mw->Unbusy;
    if (!defined($tlmediasrc)) {
      # something went badly wrong, maybe the newroot is wrong?
      $mw->Dialog(-title => "warning",
                 -text => __("Could not load the TeX Live Database from %s\nIf you want to install or update packages, please try with a different package repository!\n\nFor configuration and removal you don\'t have to do anything.", $newroot),
                        -buttons => [ __("Ok") ])->Show;
      $location = __("...please change me...");
    } else {
      $tlmediatlpdb = $tlmediasrc->tlpdb;
      setup_list();
      update_grid();
    }
  }
}

sub set_text_win {
  my ($w, $t) = @_;
  $w->delete("0.0", "end");
  $w->insert("0.0", "$t");
  $w->see("0.0");
}

sub install_selected_packages {
  if (@_) {
    my @args = qw/install/;
    push @args, @_;
    execute_action_gui(@args);
    reinit_local_tlpdb();
    # now we check that the installation has succeeded by checking that 
    # all packages in @_ are installed. Otherwise we pop up a warning window
    my $do_warn = 0;
    for my $p (@_) {
      if (!defined($localtlpdb->get_package($p))) {
        $do_warn = 1;
        last;
      }
    }
    give_warning_window(__("Installation"), @_) if $do_warn;
  }
}

sub update_selected_packages {
  if (@_) {
    my @args = qw/update/;
    # argument processing
    # in case we have critical updates present we do put the list of
    # critical updates into the argument instead of --all
    if ($critical_updates_present) {
      $opts{"self"} = 1;
    } else {
      if ($_[0] eq "--all") {
        $opts{"all"} = 1;
        # shift away the --all
        shift;
      }
    }
    push @args, @_;
    execute_action_gui(@args);
    if ($critical_updates_present) {
      # terminate here immediately so that we are sure the auto-updater
      # is run immediately
      # make sure we exit in finish(0)
      $::gui_mode = 0;
      finish(0); 
    }
    reinit_local_tlpdb();
  }
}

sub remove_selected_packages {
  if (@_) {
    my @args = qw/remove/;
    push @args, @_;
    execute_action_gui(@args);
    reinit_local_tlpdb();
    my $do_warn = 0;
    for my $p (@_) {
      if (defined($localtlpdb->get_package($p))) {
        $do_warn = 1;
        last;
      }
    }
    give_warning_window(__("Remove"), @_) if $do_warn;
  }
}

sub reinit_local_tlpdb {
  $mw->Busy(-recurse => 1);
  $localtlpdb = TeXLive::TLPDB->new ("root" => "$Master");
  die("cannot find tlpdb!") unless (defined($localtlpdb));
  setup_list();
  update_grid();
  $mw->Unbusy;
}


#
# creates/updates the list of packages as shown in tix grid
# 
sub setup_list {
  my @do_later;
  my @do_later_media;
  for my $p ($localtlpdb->list_packages()) {
    # collect packages containing a . for later
    # we want to ignore them in most cases but those where there is 
    # no father package (without .)
    if ($p =~ m;\.;) {
      push @do_later, $p;
      next;
    }
    my $tlp = $localtlpdb->get_package($p);
    # collect information about that package we will show
    $Packages{$p}{'displayname'}   = $p;
    $Packages{$p}{'localrevision'} = $tlp->revision;
    $Packages{$p}{'shortdesc'}     = $tlp->shortdesc;
    $Packages{$p}{'installed'}     = 1;
    if (($tlp->category eq "Collection") ||
        ($tlp->category eq "Scheme")) {
      $Packages{$p}{'category'}      = $tlp->category;
    } else {
      $Packages{$p}{'category'}      = "Other";
    }
    if (defined($tlp->cataloguedata->{'version'})) {
      $Packages{$p}{'localcatalogueversion'} = $tlp->cataloguedata->{'version'};
    }
  }
  if (defined($tlmediatlpdb)) {
    for my $p ($tlmediatlpdb->list_packages()) {
      if ($p =~ m;\.;) {
        push @do_later_media, $p;
        next;
      }
      my $tlp = $tlmediatlpdb->get_package($p);
      $Packages{$p}{'displayname'}   = $p;
      $Packages{$p}{'remoterevision'} = $tlp->revision;
      # overwrite, we assume that the remove version is better ;-)
      $Packages{$p}{'shortdesc'}     = $tlp->shortdesc;
      if (($tlp->category eq "Collection") ||
          ($tlp->category eq "Scheme")) {
        $Packages{$p}{'category'}      = $tlp->category;
      } else {
        $Packages{$p}{'category'}      = "Other";
      }
      if (defined($tlp->cataloguedata->{'version'})) {
        $Packages{$p}{'remotecatalogueversion'} = $tlp->cataloguedata->{'version'};
      }
    }
  }
  #
  for my $p (@do_later) {
    my $s = $p;
    $s =~ s!\.[^.]*$!!;
    if (!defined($Packages{$s})) {
      my $tlp = $localtlpdb->get_package($p);
      # collect information about that package we will show
      $Packages{$p}{'displayname'}   = $p;
      $Packages{$p}{'localrevision'} = $tlp->revision;
      $Packages{$p}{'shortdesc'}     = $tlp->shortdesc;
      $Packages{$p}{'installed'}     = 1;
      if (($tlp->category eq "Collection") ||
          ($tlp->category eq "Scheme")) {
        $Packages{$p}{'category'}      = $tlp->category;
      } else {
        $Packages{$p}{'category'}      = "Other";
      }
      if (defined($tlp->cataloguedata->{'version'})) {
        $Packages{$p}{'localcatalogueversion'} = $tlp->cataloguedata->{'version'};
      }
    }
  }
  for my $p (@do_later_media) {
    my $s = $p;
    $s =~ s!\.[^.]*$!!;
    if (!defined($Packages{$s})) {
      my $tlp = $tlmediatlpdb->get_package($p);
      # collect information about that package we will show
      $Packages{$p}{'displayname'}   = $p;
      $Packages{$p}{'remoterevision'} = $tlp->revision;
      $Packages{$p}{'shortdesc'}     = $tlp->shortdesc;
      if (($tlp->category eq "Collection") ||
          ($tlp->category eq "Scheme")) {
        $Packages{$p}{'category'}      = $tlp->category;
      } else {
        $Packages{$p}{'category'}      = "Other";
      }
      if (defined($tlp->cataloguedata->{'version'})) {
        $Packages{$p}{'remotecatalogueversion'} = $tlp->cataloguedata->{'version'};
      }
    }
  }
  # change display names
  for my $p (keys %Packages) {
    if ($p =~ m/^collection-documentation-(.*)$/) {
      $Packages{$p}{'displayname'} = "collection-doc-$1";
    }
  }
}


sub menu_edit_location {
  my $key = shift;
  my $val;
  my $sw = $mw->Toplevel(-title => __("Change package repository"));
  $sw->transient($mw);
  $sw->grab();
  $sw->Label(-text => __("New package repository:"))->pack(@p_ii);
  my $entry = $sw->Entry(-text => $location, -width => 30);
  $entry->pack();
  my $f1 = $sw->Frame;
  $f1->Button(-text => __("Choose Directory"),
    -command => sub {
                      my $var = $sw->chooseDirectory;
                      if (defined($var)) {
                        $entry->delete(0,"end");
                        $entry->insert(0,$var);
                      }
                    })->pack(@left, @p_ii);
  $f1->Button(-text => __("Default net package repository"),
    -command => sub {
                      $entry->delete(0,"end");
                      $entry->insert(0,$TeXLiveURL);
                    })->pack(@left, @p_ii);
  $f1->pack;
  my $f = $sw->Frame;
  my $okbutton = $f->Button(-text => __("Ok"),
    -command => sub { $location = $entry->get;
                      run_update_functions();
                      $sw->destroy;
                    })->pack(@left, @p_ii);
  my $cancelbutton = $f->Button(-text => __("Cancel"),
          -command => sub { $sw->destroy })->pack(@right, @p_ii);
  $f->pack(-expand => 1);
  $sw->bind('<Return>', [ $okbutton, 'Invoke' ]);
  $sw->bind('<Escape>', [ $cancelbutton, 'Invoke' ]);
}

sub run_update_functions {
  foreach my $f (@update_function_list) {
    &{$f}();
  }
}

sub check_location_on_ctan {
  # we want to check that if mirror.ctan.org
  # is used that we select a mirror once
  if ($location =~ m/$TeXLive::TLConfig::TeXLiveServerURL/) {
    $location = TeXLive::TLUtils::give_ctan_mirror();
  }
}

sub execute_action_gui {
  # my $td = $mw->Toplevel(-title => __("Status Window"));
  # $td->transient($mw);
  # $td->grab();
  # my $ok = $td->Button(-text => __("Ok"), @p_iii,
  #                      -command => sub { $td->destroy; });
  # my $lab = $td->Label(-text => __("Starting") . " @_\n");
  # $lab->pack;
  $mw->Busy(-recurse => 1);
  execute_action(@_);
  info(__("Completed") . "\n");
  $mw->Unbusy;
  # my $labb = $td->Label(-text => __("Completed"));
  # $labb->pack;
  # $ok->pack;
}

sub give_warning_window {
  my ($act, @args) = @_;
  my $sw = $mw->DialogBox(-title => __("Warning Window"), -buttons => [ __("Ok") ]);
  $sw->add("Label", -text => __("Running %s failed.\nPlease consult the log window for details.", "$act @args")
    )->pack(@p_iii);
  $sw->Show;
}

1;

__END__


### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #