From ba8f98e4dbb9ae9490f86a5587818fde9ab31c45 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Tue, 14 Jan 2014 18:24:35 +0100 Subject: Managed title and icon accordingly to the constructor --- AdminPanel/Users/GUsers.pm | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'AdminPanel') diff --git a/AdminPanel/Users/GUsers.pm b/AdminPanel/Users/GUsers.pm index 5371c440..97f35588 100644 --- a/AdminPanel/Users/GUsers.pm +++ b/AdminPanel/Users/GUsers.pm @@ -31,7 +31,6 @@ package AdminPanel::Users::GUsers; use strict; # TODO evaluate if Moose is too heavy and use Moo # instead -use Moose; use POSIX qw(ceil); # use Time::localtime; use common qw(N @@ -47,6 +46,7 @@ use Glib; use yui; use AdminPanel::Shared; use AdminPanel::Users::users; +use Moose; extends qw( Module ); has '+icon' => ( @@ -670,7 +670,9 @@ sub _buildUserData { =head3 INPUT - $self: this object + $self: this object + $standalone: if set the application title is set + from the name set in costructor =head3 DESCRIPTION @@ -682,6 +684,7 @@ sub _buildUserData { #============================================================= sub addUserDialog { my $self = shift; + my $standalone = shift; my $dontcreatehomedir = 0; my $is_system = 0; @@ -689,7 +692,12 @@ sub addUserDialog { ## push application title my $appTitle = yui::YUI::app()->applicationTitle(); ## set new title to get it in dialog - yui::YUI::app()->setApplicationTitle(N("Create New User")); + if ($standalone) { + yui::YUI::app()->setApplicationTitle($self->name); + } + else { + yui::YUI::app()->setApplicationTitle(N("Create New User")); + } my $factory = yui::YUI::widgetFactory; my $optional = yui::YUI::optionalWidgetFactory; @@ -877,7 +885,7 @@ sub addUserDialog { destroy $dlg; #restore old application title - yui::YUI::app()->setApplicationTitle($appTitle); + yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle; } #============================================================= @@ -2279,8 +2287,12 @@ sub manageUsersDialog { my $pixdir = '/usr/share/userdrake/pixmaps/'; ## push application title my $appTitle = yui::YUI::app()->applicationTitle(); + ## set new title to get it in dialog - yui::YUI::app()->setApplicationTitle(N("Mageia Users Management Tool")); + 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 $optional = yui::YUI::optionalWidgetFactory; @@ -2459,7 +2471,7 @@ sub manageUsersDialog { $self->dialog->destroy() ; #restore old application title - yui::YUI::app()->setApplicationTitle($appTitle); + yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle; } #============================================================= @@ -2549,4 +2561,4 @@ sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 } no Moose; __PACKAGE__->meta->make_immutable; -1; \ No newline at end of file +1; -- cgit v1.2.1 From 963b4b7c7f0ab173e2c732dddb7d0aa7c6e4a48f Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Tue, 14 Jan 2014 18:38:16 +0100 Subject: Fixed also admin service (title and icon) --- AdminPanel/Services/AdminService.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'AdminPanel') diff --git a/AdminPanel/Services/AdminService.pm b/AdminPanel/Services/AdminService.pm index 2f3f1d98..3dfb38f3 100644 --- a/AdminPanel/Services/AdminService.pm +++ b/AdminPanel/Services/AdminService.pm @@ -21,9 +21,6 @@ package AdminPanel::Services::AdminService; - - - #-###################################################################################### #- misc imports #-###################################################################################### @@ -239,8 +236,11 @@ sub servicePanel { my $self = shift; my $appTitle = yui::YUI::app()->applicationTitle(); + ## set new title to get it in dialog - yui::YUI::app()->setApplicationTitle(N("Services and daemons")); + yui::YUI::app()->setApplicationTitle($self->name); + ## set icon if not already set by external launcher + yui::YUI::app()->setApplicationIcon($self->icon); my ($l, $on_services) = services(); my @xinetd_services = map { $_->[0] } xinetd_services(); @@ -329,8 +329,8 @@ sub servicePanel { elsif ($widget == $aboutButton) { my $license = translate($::license); # TODO fix version value - AboutDialog({ name => N("Services and daemons"), - version => "1.0.0", + AboutDialog({ name => N("AdminService"), + version => $self->VERSION, copyright => N("Copyright (C) %s Mageia community", '2013-2014'), license => $license, comments => N("Service Manager is the Mageia service and daemon management tool \n(from the original idea of Mandriva draxservice)."), @@ -376,7 +376,7 @@ sub servicePanel { $dialog->destroy(); #restore old application title - yui::YUI::app()->setApplicationTitle($appTitle); + yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle; } no Moose; -- cgit v1.2.1 From 1f0a53f65d026d328f34714dd2d7b0ba254e1dad Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Thu, 16 Jan 2014 00:02:07 +0100 Subject: Increase speed startup lunching from apanel (slow exit now) todo add back service reload function if xinetd is enabled (drakxservice don't have it though) --- AdminPanel/Services/AdminService.pm | 202 ++++++++++++++++++++++++++++++++---- 1 file changed, 184 insertions(+), 18 deletions(-) (limited to 'AdminPanel') diff --git a/AdminPanel/Services/AdminService.pm b/AdminPanel/Services/AdminService.pm index 3dfb38f3..7313249e 100644 --- a/AdminPanel/Services/AdminService.pm +++ b/AdminPanel/Services/AdminService.pm @@ -54,7 +54,66 @@ has '+name' => ( default => N("AdminService"), ); +has 'services' => ( + traits => ['Array'], + is => 'rw', + isa => 'ArrayRef[Str]', + default => sub { [] }, + init_arg => undef, + handles => { + all_services => 'elements', + add_service => 'push', + map_service => 'map', + service_count => 'count', + sorted_services => 'sort', + }, +); + +has 'xinetd_services' => ( + traits => ['Array'], + is => 'rw', + isa => 'ArrayRef[Str]', + default => sub { [] }, + init_arg => undef, + handles => { + all_xinetd_services => 'elements', + add_xinetd_service => 'push', + map_xinetd_service => 'map', + xinetd_service_count => 'count', + sorted_xinetd_services => 'sort', + }, +); +has 'on_services' => ( + traits => ['Array'], + is => 'rw', + isa => 'ArrayRef[Str]', + default => sub { [] }, + init_arg => undef, + handles => { + all_on_services => 'elements', + add_on_service => 'push', + map_on_service => 'map', + on_service_count => 'count', + sorted_on_services => 'sort', + }, +); + + +has 'running_services' => ( + traits => ['Array'], + is => 'rw', + isa => 'ArrayRef[Str]', + default => sub { [] }, + init_arg => undef, + handles => { + all_running_services => 'elements', + add_running_service => 'push', + map_running_service => 'map', + running_service_count => 'count', + sorted_running_services => 'sort', + }, +); =head1 VERSION Version 1.0.0 @@ -198,7 +257,29 @@ xinetd => N_("Starts other deamons on demand."), $s; } +sub BUILD { + my $self = shift; + + $self->loadServices(); +} + + +#============================================================= + +=head2 start + +=head3 INPUT + $self: this object + +=head3 DESCRIPTION + + This method extends Module::start and is invoked to + start adminService + +=cut + +#============================================================= sub start { my $self = shift; @@ -206,6 +287,49 @@ sub start { }; +#============================================================= + +=head2 loadServices + +=head3 INPUT + + $self: this object + +=head3 DESCRIPTION + + This methonds load service info into local attributes such + as xinetd_services, on_services and all the available, + services + +=cut + +#============================================================= +sub loadServices { + my $self = shift; + + my ($l, $on_services) = AdminPanel::Services::Utility::services(); + my @xinetd_services = map { $_->[0] } AdminPanel::Services::Utility::xinetd_services(); + + $self->xinetd_services(); + $self->xinetd_services(\@xinetd_services); + $self->services(\@$l); + $self->on_services(\@$on_services); + + $self->refreshRunningServices(); +} + +sub refreshRunningServices { + my $self = shift; + + my @running; + foreach ($self->all_services) { + + my $serviceName = $_; + push @running, $serviceName if is_service_running($serviceName); + } + $self->running_services(\@running); +} + ## serviceInfo sets widgets accordingly to selected service status ## param ## 'service' service name @@ -222,7 +346,14 @@ sub serviceInfo { sub serviceStatus { my ($self, $tbl, $item) = @_; - my $started = (is_service_running($item->label())? N("running") : N("stopped")); + my $started; + + if (member($item->label(), $self->all_xinetd_services)) { + $started = N("Start when requested"); + } + else { + $started = (member($item->label(), $self->all_running_services)? N("running") : N("stopped")); + } # TODO add icon green/red led my $cell = $tbl->toCBYTableItem($item)->cell(1); if ($cell) { @@ -242,8 +373,8 @@ sub servicePanel { ## set icon if not already set by external launcher yui::YUI::app()->setApplicationIcon($self->icon); - my ($l, $on_services) = services(); - my @xinetd_services = map { $_->[0] } xinetd_services(); +# my ($l, $on_services) = services(); +# my @xinetd_services = map { $_->[0] } xinetd_services(); my $mageiaPlugin = "mga"; my $factory = yui::YUI::widgetFactory; @@ -265,15 +396,24 @@ sub servicePanel { ## service list (serviceBox) my $serviceTbl = $mgaFactory->createCBTable($hbox, $yTableHeader, $yui::YCBTableCheckBoxOnLastColumn); my $itemCollection = new yui::YItemCollection; - foreach (@$l) { + foreach ($self->all_services) { + my $serviceName = $_; my $item = new yui::YCBTableItem($serviceName); - my $started = (is_service_running($serviceName)? N("running") : N("stopped")); + my $started; + if (member($serviceName, $self->all_xinetd_services)) { + $started = N("Start when requested"); + } + else { + $started = (member($serviceName, $self->all_running_services)? N("running") : N("stopped")); + } + # TODO add icon green/red led my $cell = new yui::YTableCell($started); $item->addCell($cell); - $item->check(member($serviceName, @$on_services)); + + $item->check(member($serviceName, $self->all_on_services)); $item->setLabel($serviceName); $itemCollection->push($item); $item->DISOWN(); @@ -309,12 +449,22 @@ sub servicePanel { #first item status my $item = $serviceTbl->selectedItem(); - $self->serviceInfo($item->label(), $infoPanel) if ($item); + if ($item) { + $self->serviceInfo($item->label(), $infoPanel); + if (member($item->label(), $self->all_xinetd_services)) { + $stopButton->setDisabled(); + $startButton->setDisabled(); + } + else { + $stopButton->setEnabled(1); + $startButton->setEnabled(1); + } + } while(1) { - my $event = $dialog->waitForEvent(); - my $eventType = $event->eventType(); - + my $event = $dialog->waitForEvent(); + my $eventType = $event->eventType(); + #event type checking if ($eventType == $yui::YEvent::CancelEvent) { last; @@ -322,7 +472,8 @@ sub servicePanel { elsif ($eventType == $yui::YEvent::WidgetEvent) { # widget selected my $widget = $event->widget(); - + my $wEvent = yui::toYWidgetEvent($event); + if ($widget == $closeButton) { last; } @@ -343,14 +494,29 @@ sub servicePanel { ); } elsif ($widget == $serviceTbl) { + # service selection changed $item = $serviceTbl->selectedItem(); - $self->serviceInfo($item->label(), $infoPanel) if ($item); - $item = $serviceTbl->changedItem(); if ($item) { - set_service($item->label(), $item->checked()); - # we can push/pop service, but this (slower) should return real situation - ($l, $on_services) = services(); + $self->serviceInfo($item->label(), $infoPanel); + if (member($item->label(), $self->all_xinetd_services)) { + $stopButton->setDisabled(); + $startButton->setDisabled(); + } + else { + $stopButton->setEnabled(1); + $startButton->setEnabled(1); + } + } +# TODO fix libyui-mga-XXX item will always be changed after first one + if ($wEvent->reason() == $yui::YEvent::ValueChanged) { + $item = $serviceTbl->changedItem(); + if ($item) { + + set_service($item->label(), $item->checked()); + # we can push/pop service, but this (slower) should return real situation + $self->refreshRunningServices(); + } } } elsif ($widget == $startButton) { @@ -358,7 +524,7 @@ sub servicePanel { if ($item) { restart_or_start($item->label()); # we can push/pop service, but this (slower) should return real situation - ($l, $on_services) = services(); + $self->refreshRunningServices(); $self->serviceStatus($serviceTbl, $item); } } @@ -367,7 +533,7 @@ sub servicePanel { if ($item) { stop($item->label()); # we can push/pop service, but this (slower) should return real situation - ($l, $on_services) = services(); + $self->refreshRunningServices(); $self->serviceStatus($serviceTbl, $item); } } -- cgit v1.2.1 From ce5290dcdbba11a8ea5c80fb8ba9f221c6863f85 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Thu, 16 Jan 2014 22:56:16 +0100 Subject: Added License into Shared to be used by admin panel modules easily set back dependency from /usr/lib/libDrakX to use apanel without -I --- AdminPanel/Services/AdminService.pm | 11 ++++++-- AdminPanel/Shared.pm | 53 ++++++++++++++++++++++++++++++++++--- AdminPanel/Users/GUsers.pm | 10 +++++-- 3 files changed, 67 insertions(+), 7 deletions(-) (limited to 'AdminPanel') diff --git a/AdminPanel/Services/AdminService.pm b/AdminPanel/Services/AdminService.pm index 7313249e..5055683c 100644 --- a/AdminPanel/Services/AdminService.pm +++ b/AdminPanel/Services/AdminService.pm @@ -26,7 +26,14 @@ package AdminPanel::Services::AdminService; #-###################################################################################### use strict; -use common; + +# TODO same translation atm +use lib qw(/usr/lib/libDrakX); +use common qw(N + N_ + cat_ + formatAlaTeX + translate); use run_program; use Moose; @@ -478,7 +485,7 @@ sub servicePanel { last; } elsif ($widget == $aboutButton) { - my $license = translate($::license); + my $license = translate($AdminPanel::Shared::License); # TODO fix version value AboutDialog({ name => N("AdminService"), version => $self->VERSION, diff --git a/AdminPanel/Shared.pm b/AdminPanel/Shared.pm index c337dfcc..21f98684 100644 --- a/AdminPanel/Shared.pm +++ b/AdminPanel/Shared.pm @@ -77,18 +77,22 @@ along with this file. If not, see . use strict; use warnings; use diagnostics; -#use lib qw(/usr/lib/libDrakX); -use common qw(N); + +use lib qw(/usr/lib/libDrakX); +use common qw(N + N_); use yui; use base qw(Exporter); +# TODO move GUI dialogs to Shared::GUI our @EXPORT = qw(warningMsgBox msgBox infoMsgBox ask_YesOrNo ask_OkCancel AboutDialog - trim); + trim, + member); =head1 VERSION @@ -99,6 +103,21 @@ Version 0.01 our $VERSION = '0.01'; +our $License = N_("This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +"); + #============================================================= @@ -569,4 +588,32 @@ sub trim { return $st; } +#============================================================= + +=head2 member + +=head3 INPUT + + $e: Array element to be found into array + @_: any array + +=head3 OUTPUT + + 1 or 0: if $e is a member of the given array + +=head3 DESCRIPTION + +This function look for an element into an array + +=cut + +#============================================================= +sub member { + my $e = shift; + foreach (@_) { + $e eq $_ and return 1; + } + 0; +} + 1; # End of AdminPanel::Shared diff --git a/AdminPanel/Users/GUsers.pm b/AdminPanel/Users/GUsers.pm index 97f35588..fe95a0b2 100644 --- a/AdminPanel/Users/GUsers.pm +++ b/AdminPanel/Users/GUsers.pm @@ -33,6 +33,12 @@ use strict; # instead use POSIX qw(ceil); # use Time::localtime; + +# TODO same translation atm +use lib qw(/usr/lib/libDrakX); +# i18n: IMPORTANT: to get correct namespace (userdrake instead of libDrakX) +BEGIN { unshift @::textdomains, 'userdrake', 'libuser', 'drakconf' } + use common qw(N translate); use security::level; @@ -2398,7 +2404,7 @@ sub manageUsersDialog { last; } elsif ($menuLabel eq $helpMenu{about}->label()) { - my $license = translate($::license); + my $license = translate($AdminPanel::Shared::License); AboutDialog({ name => N("AdminUser"), version => $self->VERSION, copyright => N("Copyright (C) %s Mageia community", '2013-2014'), @@ -2556,7 +2562,7 @@ sub TimeOfArray { $cm and $h->{month} = $mth{$2}; $h; } -sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 } + no Moose; __PACKAGE__->meta->make_immutable; -- cgit v1.2.1 From 8d4f4039062d11d56b1681a824425acd155ba443 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Thu, 16 Jan 2014 23:18:24 +0100 Subject: Missed common::find dependency --- AdminPanel/Services/AdminService.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'AdminPanel') diff --git a/AdminPanel/Services/AdminService.pm b/AdminPanel/Services/AdminService.pm index 5055683c..8b02227f 100644 --- a/AdminPanel/Services/AdminService.pm +++ b/AdminPanel/Services/AdminService.pm @@ -33,7 +33,8 @@ use common qw(N N_ cat_ formatAlaTeX - translate); + translate + find); use run_program; use Moose; -- cgit v1.2.1 From 8be4c570361e4df7a3e319e9b9bd029d7520fb7b Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Sat, 18 Jan 2014 14:13:13 +0100 Subject: wrong comma --- AdminPanel/Shared.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'AdminPanel') diff --git a/AdminPanel/Shared.pm b/AdminPanel/Shared.pm index 21f98684..5d052e08 100644 --- a/AdminPanel/Shared.pm +++ b/AdminPanel/Shared.pm @@ -91,7 +91,7 @@ our @EXPORT = qw(warningMsgBox ask_YesOrNo ask_OkCancel AboutDialog - trim, + trim member); -- cgit v1.2.1