aboutsummaryrefslogtreecommitdiffstats
path: root/AdminPanel
diff options
context:
space:
mode:
authorMatteo Pasotti <matteo.pasotti@gmail.com>2014-01-19 01:11:21 +0100
committerMatteo Pasotti <matteo.pasotti@gmail.com>2014-01-19 01:11:21 +0100
commit97d9107d09e7112c012bd3637e30e0821b5f6885 (patch)
treea6591e00c239b8324aeab92a0169a1f8143c70ef /AdminPanel
parent03509ca6ac225c921d5f15479198908eac6df605 (diff)
parent8be4c570361e4df7a3e319e9b9bd029d7520fb7b (diff)
downloadmanatools-97d9107d09e7112c012bd3637e30e0821b5f6885.tar
manatools-97d9107d09e7112c012bd3637e30e0821b5f6885.tar.gz
manatools-97d9107d09e7112c012bd3637e30e0821b5f6885.tar.bz2
manatools-97d9107d09e7112c012bd3637e30e0821b5f6885.tar.xz
manatools-97d9107d09e7112c012bd3637e30e0821b5f6885.zip
Merge branch 'master' of ssh://git.mageia.org/software/adminpanel
Diffstat (limited to 'AdminPanel')
-rw-r--r--AdminPanel/Services/AdminService.pm228
-rw-r--r--AdminPanel/Shared.pm53
-rw-r--r--AdminPanel/Users/GUsers.pm36
3 files changed, 278 insertions, 39 deletions
diff --git a/AdminPanel/Services/AdminService.pm b/AdminPanel/Services/AdminService.pm
index 2f3f1d98..8b02227f 100644
--- a/AdminPanel/Services/AdminService.pm
+++ b/AdminPanel/Services/AdminService.pm
@@ -21,15 +21,20 @@
package AdminPanel::Services::AdminService;
-
-
-
#-######################################################################################
#- misc imports
#-######################################################################################
use strict;
-use common;
+
+# TODO same translation atm
+use lib qw(/usr/lib/libDrakX);
+use common qw(N
+ N_
+ cat_
+ formatAlaTeX
+ translate
+ find);
use run_program;
use Moose;
@@ -57,7 +62,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
@@ -201,7 +265,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;
@@ -209,6 +295,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
@@ -225,7 +354,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) {
@@ -239,11 +375,14 @@ 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();
+# my ($l, $on_services) = services();
+# my @xinetd_services = map { $_->[0] } xinetd_services();
my $mageiaPlugin = "mga";
my $factory = yui::YUI::widgetFactory;
@@ -265,15 +404,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 +457,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,15 +480,16 @@ sub servicePanel {
elsif ($eventType == $yui::YEvent::WidgetEvent) {
# widget selected
my $widget = $event->widget();
-
+ my $wEvent = yui::toYWidgetEvent($event);
+
if ($widget == $closeButton) {
last;
}
elsif ($widget == $aboutButton) {
- my $license = translate($::license);
+ my $license = translate($AdminPanel::Shared::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)."),
@@ -343,14 +502,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 +532,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 +541,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);
}
}
@@ -376,7 +550,7 @@ sub servicePanel {
$dialog->destroy();
#restore old application title
- yui::YUI::app()->setApplicationTitle($appTitle);
+ yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle;
}
no Moose;
diff --git a/AdminPanel/Shared.pm b/AdminPanel/Shared.pm
index c337dfcc..5d052e08 100644
--- a/AdminPanel/Shared.pm
+++ b/AdminPanel/Shared.pm
@@ -77,18 +77,22 @@ along with this file. If not, see <http://www.gnu.org/licenses/>.
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 5371c440..fe95a0b2 100644
--- a/AdminPanel/Users/GUsers.pm
+++ b/AdminPanel/Users/GUsers.pm
@@ -31,9 +31,14 @@ 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;
+
+# 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;
@@ -47,6 +52,7 @@ use Glib;
use yui;
use AdminPanel::Shared;
use AdminPanel::Users::users;
+use Moose;
extends qw( Module );
has '+icon' => (
@@ -670,7 +676,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 +690,7 @@ sub _buildUserData {
#=============================================================
sub addUserDialog {
my $self = shift;
+ my $standalone = shift;
my $dontcreatehomedir = 0;
my $is_system = 0;
@@ -689,7 +698,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 +891,7 @@ sub addUserDialog {
destroy $dlg;
#restore old application title
- yui::YUI::app()->setApplicationTitle($appTitle);
+ yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle;
}
#=============================================================
@@ -2279,8 +2293,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;
@@ -2386,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'),
@@ -2459,7 +2477,7 @@ sub manageUsersDialog {
$self->dialog->destroy() ;
#restore old application title
- yui::YUI::app()->setApplicationTitle($appTitle);
+ yui::YUI::app()->setApplicationTitle($appTitle) if $appTitle;
}
#=============================================================
@@ -2544,9 +2562,9 @@ 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;
-1; \ No newline at end of file
+1;