# vim: set et ts=4 sw=4: package AdminPanel::Module::Clock; #============================================================= -*-perl-*- =head1 NAME AdminPanel::Module::Clock - This module aims to configure system clock and time =head1 SYNOPSIS my $clockSettings = AdminPanel::Module::Clock->new(); $clockSettings->start(); =head1 DESCRIPTION Long_description =head1 SUPPORT You can find documentation for this module with the perldoc command: perldoc AdminPanel::Module::Clock =head1 SEE ALSO SEE_ALSO =head1 AUTHOR Angelo Naselli =head1 COPYRIGHT and LICENSE Copyright (C) 2014, Angelo Naselli. 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 =head1 FUNCTIONS =cut use Moose; use diagnostics; use strict; use AdminPanel::Shared::GUI; use AdminPanel::Shared::Locales; use AdminPanel::Shared::TimeZone; use AdminPanel::Shared::Services;# qw (services); use Time::Piece; use yui; extends qw( AdminPanel::Module ); ### TODO icon has '+icon' => ( default => "/usr/share/mcc/themes/default/time-mdk.png", ); has 'loc' => ( is => 'rw', init_arg => undef, builder => '_localeInitialize' ); sub _localeInitialize { my $self = shift; # TODO fix domain binding for translation $self->loc(AdminPanel::Shared::Locales->new(domain_name => 'libDrakX-standalone') ); # TODO if we want to give the opportunity to test locally add dir_name => 'path' } has 'sh_gui' => ( is => 'rw', lazy => 1, init_arg => undef, builder => '_SharedGUIInitialize' ); sub _SharedGUIInitialize { my $self = shift; $self->sh_gui(AdminPanel::Shared::GUI->new() ); } has 'sh_tz' => ( is => 'rw', lazy => 1, builder => '_SharedTimeZoneInitialize' ); sub _SharedTimeZoneInitialize { my $self = shift; $self->sh_tz(AdminPanel::Shared::TimeZone->new() ); } =head1 VERSION Version 1.0.0 =cut our $VERSION = '1.0.0'; #============================================================= =head2 BUILD =head3 INPUT $self: this object =head3 DESCRIPTION The BUILD method is called after a Moose object is created, in this methods Services loads all the service information. =cut #============================================================= sub BUILD { my $self = shift; if (! $self->name) { $self->name ($self->loc->N("Date, Clock & Time Zone Settings")); } } #============================================================= =head2 start =head3 INPUT $self: this object =head3 DESCRIPTION This method extends Module::start and is invoked to start admin clock =cut #============================================================= sub start { my $self = shift; $self->_adminClockPanel(); }; ### _get_NTPservers ## returns ntp servers in the format ## Zone|Nation: server # sub _get_NTPservers { my $self = shift; my $servs = $self->sh_tz->ntpServers(); [ map { "$servs->{$_}|$_" } sort { $servs->{$a} cmp $servs->{$b} || $a cmp $b } keys %$servs ]; } ### _restoreValues ## restore NTP server and Time Zone from configuration files # ## input '$datetime_only' restore date and time only # ## returns 'info', a HASH references containing: ## time_zone => time zone hash reference to be restored ## ntp_server => ntp server address ## date => date string ## time => time string ## ntp_running => is NTP running? # sub _restoreValues { my ($self, $datetime_only) = @_; my $info; if (!$datetime_only) { $info->{time_zone} = $self->sh_tz->readConfiguration(); $info->{ntp_server} = $self->sh_tz->ntpCurrentServer(); #- strip digits from \d+.foo.pool.ntp.org $info->{ntp_server} =~ s/^\d+\.// if $info->{ntp_server}; $info->{ntp_running} = $self->sh_tz->isNTPRunning(); } my $t = localtime; my $day = $t->strftime("%F"); my $time = $t->strftime("%H:%M:%S"); $info->{date} = $day; $info->{time} = $time; return $info; } sub _adminClockPanel { my $self = shift; my $appTitle = yui::YUI::app()->applicationTitle(); ## set new title to get it in dialog yui::YUI::app()->setApplicationTitle($self->name); ## set icon if not already set by external launcher yui::YUI::app()->setApplicationIcon($self->icon); my $factory = yui::YUI::widgetFactory; my $optFactory = yui::YUI::optionalWidgetFactory; die "calendar widgets missing" if (!$optFactory->hasDateField() || !$optFactory->hasTimeField()); # Create Dialog my $dialog = $factory->createMainDialog; # my $minSize = $factory->createMinSize($dialog, 40, 15); # Start Dialog layout: my $layout = $factory->createVBox($dialog); my $align = $factory->createLeft($layout); my $frame = $factory->createFrame($align, $self->loc->N("Setting date and time")); my $hbox = $factory->createHBox($frame); my $dateField = $optFactory->createDateField($hbox, ""); $factory->createHSpacing($hbox, 3.0); my $timeField = $optFactory->createTimeField($hbox, ""); $factory->createHSpacing($hbox, 1.0); $factory->createVSpacing($hbox, 1.0); $factory->createVSpacing($layout, 1.0); $align = $factory->createLeft($layout); $hbox = $factory->createHBox($align); my $ntpFrame = $factory->createCheckBoxFrame($hbox, $self->loc->N("Enable Network Time Protocol"), 0); my $hbox1 = $factory->createHBox($ntpFrame); my $changeNTPButton = $factory->createPushButton($hbox1, $self->loc->N("Change NTP server")); $factory->createHSpacing($hbox1, 1.0); $factory->createLabel($hbox1,$self->loc->N("Current:")); $factory->createHSpacing($hbox1, 1.0); my $ntpLabel = $factory->createLabel($hbox1, $self->loc->N("not defined")); $factory->createHSpacing($hbox1, 1.0); $ntpLabel->setWeight($yui::YD_HORIZ, 2); $changeNTPButton->setWeight($yui::YD_HORIZ, 1); $factory->createHSpacing($hbox, 1.0); $factory->createVSpacing($layout, 1.0); $align = $factory->createLeft($layout); $hbox = $factory->createHBox($align); $frame = $factory->createFrame ($hbox, $self->loc->N("TimeZone")); $hbox1 = $factory->createHBox( $frame ); my $changeTZButton = $factory->createPushButton($hbox1, $self->loc->N("Change Time Zone")); $factory->createHSpacing($hbox1, 1.0); $factory->createLabel($hbox1,$self->loc->N("Current:")); $factory->createHSpacing($hbox1, 1.0); my $timeZoneLbl = $factory->createLabel($hbox1, $self->loc->N("not defined")); $factory->createHSpacing($hbox1, 1.0); $timeZoneLbl->setWeight($yui::YD_HORIZ, 2); $changeTZButton->setWeight($yui::YD_HORIZ, 1); $factory->createHSpacing($hbox, 1.0); # buttons on the last line $factory->createVSpacing($layout, 1.0); $hbox = $factory->createHBox($layout); $align = $factory->createLeft($hbox); $hbox = $factory->createHBox($align); my $aboutButton = $factory->createPushButton($hbox, $self->loc->N("About") ); my $resetButton = $factory->createPushButton($hbox, $self->loc->N("Reset") ); $align = $factory->createRight($hbox); $hbox = $factory->createHBox($align); my $cancelButton = $factory->createPushButton($hbox, $self->loc->N("Cancel")); my $okButton = $factory->createPushButton($hbox, $self->loc->N("Ok")); $factory->createHSpacing($hbox, 1.0); ## no changes by default $dialog->setDefaultButton($cancelButton); # End Dialof layout ## default value my $info = $self->_restoreValues(); $dateField->setValue($info->{date}); $timeField->setValue($info->{time}); if (exists $info->{time_zone} && $info->{time_zone}->{ZONE}) { $timeZoneLbl->setValue($info->{time_zone}->{ZONE}); } if ($info->{ntp_server}) { $ntpLabel->setValue($info->{ntp_server}); } $ntpFrame->setValue($info->{ntp_running}); # get only once my $NTPservers = $self->_get_NTPservers(); while(1) { my $event = $dialog->waitForEvent(1000); my $eventType = $event->eventType(); #event type checking if ($eventType == $yui::YEvent::CancelEvent) { last; } elsif ($eventType == $yui::YEvent::TimeoutEvent) { my $t = Time::Piece->strptime($timeField->value(), "%H:%M:%S") + 1; $timeField->setValue($t->strftime("%H:%M:%S")); } elsif ($eventType == $yui::YEvent::WidgetEvent) { # widget selected my $widget = $event->widget(); if ($widget == $cancelButton) { last; } elsif ($widget == $okButton) { yui::YUI::app()->busyCursor(); my $finished = 1; # (1) write new TZ settings # (2) write new NTP settigs if checked # (3) use date time fields if NTP is not checked if ($info->{time_zone}->{UTC}) { # (1) $self->sh_tz->writeConfiguration($info->{time_zone}); } if ($ntpFrame->value()) { # (2) if ($info->{ntp_server}) { $self->sh_tz->setNTPServer($info->{ntp_server}); } else { $self->sh_gui->warningMsgBox({text => $self->loc->N("Please enter a valid NTP server address.")}); $finished = 0; } } else { $self->sh_tz->disableAndStopNTP(); # (3) my $t = Time::Piece->strptime($timeField->value(), "%H:%M:%S"); my $d = Time::Piece->strptime($dateField->value(), "%Y-%m-%d"); my $ts = sprintf("%02d%02d%02d%02d%04d.%02d", $d->mon, $d->mday, $t->hour, $t->min, $d->year,$t->sec); $ENV{PATH} = "/usr/bin:/usr/sbin"; system("/usr/bin/date " . $ts); -e '/usr/sbin/hwclock' and system('/usr/sbin/hwclock', '--systohc'); } yui::YUI::app()->normalCursor(); last if ($finished); } elsif ($widget == $changeNTPButton) { # get time to calculate elapsed my $t0 = localtime; my $item = $self->sh_gui->ask_fromTreeList({title => $self->loc->N("NTP server - DrakClock"), header => $self->loc->N("Choose your NTP server"), default_button => 1, item_separator => '|', default_item => $info->{ntp_server}, skip_path => 1, list => $NTPservers}); if ($item) { $ntpLabel->setValue($item); $info->{ntp_server} = $item; } # fixing elapsed time (dialog is modal) my $t1 = localtime; my $elapsed = $t1->epoch - $t0->epoch; my $t = Time::Piece->strptime($dateField->value() . "T" . $timeField->value(), '%Y-%m-%dT%H:%M:%S') + $elapsed; $timeField->setValue($t->strftime("%H:%M:%S")); $dateField->setValue($t->strftime("%F")); } elsif ($widget == $changeTZButton) { # get time to calculate elapsed my $t0 = localtime; my $timezones = $self->sh_tz->getTimeZones(); if (!$timezones || scalar (@{$timezones}) == 0) { $self->sh_gui->warningMsgBox({title => $self->loc->N("Timezone - DrakClock"), text => $self->loc->N("Failed to retrieve timezone list"), }); $changeTZButton->setDisabled(); } else { my $item = $self->sh_gui->ask_fromTreeList({title => $self->loc->N("Timezone - DrakClock"), header => $self->loc->N("Which is your timezone?"), default_button => 1, item_separator => '/', default_item => $info->{time_zone}->{ZONE}, list => $timezones}); if ($item) { my $utc = 0; if ($info->{time_zone}->{UTC} ) { $utc = lc $info->{time_zone}->{UTC}; $utc = ($utc eq "false" || $utc eq "0") ? 0 : 1; } $utc = $self->sh_gui->ask_YesOrNo({ title => $self->loc->N("GMT - DrakClock"), text => $self->loc->N("Is your hardware clock set to GMT?"), default_button => $utc, }); $info->{time_zone}->{UTC} = $utc == 1 ? 'true' : 'false'; $info->{time_zone}->{ZONE} = $item; $timeZoneLbl->setValue($info->{time_zone}->{ZONE}); } } # fixing elapsed time (dialog is modal) my $t1 = localtime; my $elapsed = $t1->epoch - $t0->epoch; my $t = Time::Piece->strptime($dateField->value() . "T" . $timeField->value(), '%Y-%m-%dT%H:%M:%S') + $elapsed; $timeField->setValue($t->strftime("%H:%M:%S")); $dateField->setValue($t->strftime("%F")); } elsif ($widget == $resetButton) { my $datetime_only = $self->sh_gui->ask_YesOrNo({ title => $self->loc->N("Restore data"), text => $self->loc->N("Restore date and time only?"), default_button => 1, #Yes }); my $newInfo = $self->_restoreValues($datetime_only); if ($datetime_only) { $info->{date} = $newInfo->{date}; $info->{time} = $newInfo->{time}; } else{ $info = $newInfo; } $dateField->setValue($info->{date}); $timeField->setValue($info->{time}); if (exists $info->{time_zone} && $info->{time_zone}->{ZONE}) { $timeZoneLbl->setValue($info->{time_zone}->{ZONE}); } else { $timeZoneLbl->setValue($self->loc->N("not defined")); } if ($info->{ntp_server}) { $ntpLabel->setValue($info->{ntp_server}); } else { $ntpLabel->setValue($self->loc->N("not defined")); } $ntpFrame->setValue($info->{ntp_running}); } elsif($widget == $aboutButton) { my $translators = $self->loc->N("_: Translator(s) name(s) & email(s)\n"); $translators =~ s/\/\>\;/g; $self->sh_gui->AboutDialog({ name => $self->name, version => $self->VERSION, credits => $self->loc->N("Copyright (C) %s Mageia community", '2014'), license => $self->loc->N("GPLv2"), description => $self->loc->N("Date, Clock & Time Zone Settings allows to setup time zone and adjust date and time"), authors => $self->loc->N("

Developers

Translators

", "Angelo Naselli <anaselli\@linux.it>", $translators ), } ); } } } $dialog->destroy(); #restore old application title yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle; } n367' href='#n367'>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
package install_steps_gtk; # $Id$

use diagnostics;
use strict;
use vars qw(@ISA);

@ISA = qw(install_steps_interactive interactive::gtk);

#-######################################################################################
#- misc imports
#-######################################################################################
use pkgs;
use install_steps_interactive;
use interactive::gtk;
use xf86misc::main;
use common;
use mygtk2;
use ugtk2 qw(:helpers :wrappers :create);
use devices;
use modules;
use install_gtk;
use install_any;
use mouse;
use help;
use log;

#-######################################################################################
#- In/Out Steps Functions
#-######################################################################################
sub new($$) {
    my ($type, $o) = @_;

    $ENV{DISPLAY} ||= $o->{display} || ":0";
    my $wanted_DISPLAY = $::testing && -x '/usr/X11R6/bin/Xnest' ? ':9' : $ENV{DISPLAY};

    if (!$::local_install && 
	($::testing ? $ENV{DISPLAY} ne $wanted_DISPLAY : $ENV{DISPLAY} =~ /^:\d/)) { #- is the display local or distant?
	my $f = "/tmp/Xconf";
	if (!$::testing) {
	    devices::make("/dev/kbd");
	}
	my $launchX = sub {
	    my ($server, $Driver) = @_;

	    mkdir '/var/log' if !-d '/var/log';

	    my @options = $wanted_DISPLAY;
	    if ($server eq 'Xnest') {
		push @options, '-ac', '-geometry', $o->{vga} || ($o->{vga16} ? '640x480' : '800x600');
	    } elsif ($::globetrotter || !$::move) {
		install_gtk::createXconf($f, @{$o->{mouse}}{"XMOUSETYPE", "device"}, $o->{mouse}{wacom}[0], $Driver);

		push @options, if_(!$::globetrotter, '-kb'), '-allowMouseOpenFail', '-xf86config', $f if arch() !~ /^sparc/;
		push @options, 'tty7', '-dpms', '-s', '240';

		#- old weird servers: Xsun
		push @options, '-fp', '/usr/X11R6/lib/X11/fonts:unscaled' if $server =~ /Xsun/;
	    }

	    if (!fork()) {
		c::setsid();
		exec $server, @options or c::_exit(1);
	    }

	    #- wait for the server to start
	    foreach (1..5) {
		sleep 1;
		last if fuzzy_pidofs(qr/\b$server\b/);
		log::l("$server still not running, trying again");
	    }
	    my $nb;
	    foreach (1..60) {
		log::l("waiting for the server to start ($_ $nb)");
		log::l("Server died"), return 0 if !fuzzy_pidofs(qr/\b$server\b/);
		$nb++ if xf86misc::main::Xtest($wanted_DISPLAY);
		if ($nb > 2) { #- one succeeded test is not enough :-(
		    log::l("AFAIK X server is up");
		    return 1;
		}
		sleep 1;
	    }
	    log::l("Timeout!!");
	    0;
	};
	my @servers = qw(Driver:fbdev); #-)
	if ($::testing) {
	    @servers = 'Xnest';
	} elsif (arch() eq "alpha") {
	    require Xconfig::card;
	    my ($card) = Xconfig::card::probe();
	    Xconfig::card::add_to_card__using_Cards($card, $card->{type}) if $card && $card->{type};
	    @servers = $card->{server} || "TGA";
	    #-@servers = qw(SVGA 3DLabs TGA) 
	} elsif (arch() =~ /^sparc/) {
	    local $_ = cat_("/proc/fb");
	    if (/Mach64/) {
		@servers = qw(Mach64);
	    } elsif (/Permedia2/) {
		@servers = qw(3DLabs);
	    } else {
		@servers = qw(Xsun24);
	    }
	} elsif (arch() =~ /ia64/) {
	    require Xconfig::card;
	    my ($card) = Xconfig::card::probe();
	    @servers = map { if_($_, "Driver:$_") } $card && $card->{Driver}, 'fbdev';
        }

        if (($::move || $::globetrotter) && !$::testing) {
            require move;
            require run_program;
            move::automatic_xconf($o);
            run_program::run('/sbin/service', 'xfs', 'start');
            @servers = $::globetrotter ? qw(Driver:fbdev) : qw(X_move);
	}

	foreach (@servers) {
	    log::l("Trying with server $_");
	    my ($prog, $Driver) = /Driver:(.*)/ ? ('Xorg', $1) : /Xsun|Xnest|^X_move$/ ? $_ : "XF86_$_";
	    if (/FB/i) {
		!$o->{vga16} && $o->{allowFB} or next;

		$o->{allowFB} = &$launchX($prog, $Driver) #- keep in mind FB is used.
		  and goto OK;
	    } else {
		$o->{vga16} = 1 if /VGA16/;
		&$launchX($prog, $Driver) and goto OK;
	    }
            $::move and print("can not launch graphical mode :(\n"), c::_exit(1);
	}
	return undef;
    }
  OK:
    $ENV{DISPLAY} = $wanted_DISPLAY;
    run_program::run('xset', 'm', '1/8', '1') if is_xbox();
    install_gtk::init_gtk($o);
    install_gtk::init_sizes();
    install_gtk::install_theme($o);
    install_gtk::create_logo_window($o);
    install_gtk::create_steps_window($o);

    $ugtk2::grab = 1;

    $o = (bless {}, ref($type) || $type)->SUPER::new($o);
    $o->interactive::gtk::new;
    $o;
}

sub enteringStep {
    my ($o, $step) = @_;

    printf "Entering step `%s'\n", $o->{steps}{$step}{text};
    $o->SUPER::enteringStep($step);
    install_gtk::update_steps_position($o);
}
sub leavingStep {
    my ($o, $step) = @_;
    $o->SUPER::leavingStep($step);
}


sub charsetChanged {
    my ($o) = @_;
    Gtk2->set_locale;
    install_gtk::load_font($o);
    install_gtk::create_steps_window($o);
}

#-######################################################################################
#- Steps Functions
#-######################################################################################
sub selectLanguage {
    my ($o, $first_time) = @_;
    $o->SUPER::selectLanguage;
  
    $o->ask_warn('',
formatAlaTeX(N("Your system is low on resources. You may have some problem installing
Mandriva Linux. If that occurs, you can try a text install instead. For this,
press `F1' when booting on CDROM, then enter `text'."))) if $first_time && availableRamMB() < 70; # 70MB

}

#------------------------------------------------------------------------------
sub selectMouse {
    my ($o, $force) = @_;
    my %old = %{$o->{mouse}};
    $o->SUPER::selectMouse($force) or return;
    my $mouse = $o->{mouse};
    $mouse->{type} eq 'none' ||
      $old{type}   eq $mouse->{type}   && 
      $old{name}   eq $mouse->{name}   &&
      $old{device} eq $mouse->{device} && !$force and return;

    while (1) {
	my $x_protocol_changed = mouse::change_mouse_live($mouse, \%old);
	mouse::test_mouse_install($mouse, $x_protocol_changed) and return;

	%old = %$mouse;
	$o->SUPER::selectMouse(1);
	$mouse = $o->{mouse};
    } 
}

sub reallyChooseGroups {
    my ($o, $size_to_display, $individual, $_compssUsers) = @_;

    my $w = ugtk2->new('');
    my $w_size = gtknew('Label', text => &$size_to_display);

    my $entry = sub {
	my ($e) = @_;

	gtknew('CheckButton', 
	       text => translate($e->{label}), 
	       tip => translate($e->{descr}),
	       active_ref => \$e->{selected},
	       toggled => sub { 
		   gtkset($w_size, text => &$size_to_display);
	       });
    };
    #- when restarting this step, it might be necessary to reload the compssUsers.pl (bug 11558). kludgy.
    if (!ref $o->{gtk_display_compssUsers}) { install_any::load_rate_files($o) }
    ugtk2::gtkadd($w->{window},
	   gtkpack_($w->create_box_with_title(N("Package Group Selection")),
		    1, $o->{gtk_display_compssUsers}->($entry),
		    1, '',
		    0, gtknew('HBox', children_loose => [
			  gtknew('Button', text => N("Help"), clicked => $o->interactive_help_sub_display_id('choosePackages')),
			  $w_size,
			  if_($individual,
			      gtknew('CheckButton', text => N("Individual package selection"), active_ref => $individual),
			  ),
			  gtknew('Button', text => N("Next"), clicked => sub { Gtk2->main_quit }),
			 ]),
		  ),
	  );
    $w->main;
    1;
}

sub choosePackagesTree {
    my ($o, $packages, $o_limit_medium) = @_;

    my $available = install_any::getAvailableSpace($o);
    my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024);

    my $common;
    $common = {             get_status => sub {
				my $size = pkgs::selectedSize($packages);
				N("Total size: %d / %d MB", pkgs::correctSize($size / sqr(1024)), $available / sqr(1024));
			    },
			    node_state => sub {
				my $p = pkgs::packageByName($packages, $_[0]) or return;
				pkgs::packageMedium($packages, $p)->selected or return;
				$p->arch eq 'src'                       and return;
				$p->flag_base                           and return 'base';
				$p->flag_installed && !$p->flag_upgrade and return 'installed';
				$p->flag_selected                       and return 'selected';
				return 'unselected';
			    },
			    build_tree => sub {
				my ($add_node, $flat) = @_;
				if ($flat) {
				    foreach (sort map { $_->name }
					     grep { !$o_limit_medium || pkgs::packageMedium($packages, $_) == $o_limit_medium }
					     grep { $_ && $_->arch ne 'src' }
					     @{$packages->{depslist}}) {
					$add_node->($_, undef);
				    }
				} else {
				    foreach my $root (@{$o->{compssUsers}}) {
					my (@firstchoice, @others);
					my %fl = map { ("CAT_$_" => 1) } @{$root->{flags}};
					foreach my $p (@{$packages->{depslist}}) {
					    !$o_limit_medium || pkgs::packageMedium($packages, $p) == $o_limit_medium or next;
					    my @flags = $p->rflags;