aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2014-01-06 00:59:45 +0100
committerAngelo Naselli <anaselli@linux.it>2014-01-06 00:59:45 +0100
commit11533544ca01c2c54899af0a00f2c062c1831433 (patch)
treecdd13f3a209618ddde3a6927a392590238a01a4c
parenteb0eab8fc6d0c89262daa80d199bb7091540943b (diff)
downloadcolin-keep-11533544ca01c2c54899af0a00f2c062c1831433.tar
colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.tar.gz
colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.tar.bz2
colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.tar.xz
colin-keep-11533544ca01c2c54899af0a00f2c062c1831433.zip
- Added a Base class for modules.
- Now configuration can be read also int /etc/categories.conf.d/ so that external modules can add their own configuration to be launched and added to admin panel - perl modules can be run by extending Module class, creating a start() method and configuring module entry in categories configuration as class element - Admin User now extends Module
-rw-r--r--AdminPanel/Users/GUsers.pm24
-rw-r--r--Category.pm71
-rw-r--r--ConfigReader.pm7
-rw-r--r--MainDisplay.pm160
-rw-r--r--Module.pm91
-rwxr-xr-xapanel.pl5
-rwxr-xr-xmodules/usermanager/usermanager2
7 files changed, 300 insertions, 60 deletions
diff --git a/AdminPanel/Users/GUsers.pm b/AdminPanel/Users/GUsers.pm
index 56d58ff..3aba881 100644
--- a/AdminPanel/Users/GUsers.pm
+++ b/AdminPanel/Users/GUsers.pm
@@ -47,6 +47,16 @@ use Glib;
use yui;
use AdminPanel::Shared;
use AdminPanel::Users::users;
+extends qw( Module );
+
+has '+icon' => (
+ default => "/usr/share/icons/userdrake.png",
+);
+
+has '+name' => (
+ default => N("AdminUser"),
+);
+
=head1 VERSION
@@ -117,6 +127,11 @@ has 'edit_tab_widgets' => (
init_arg => undef,
);
+sub start {
+ my $self = shift;
+
+ $self->manageUsersDialog();
+};
# TODO move to Shared?
sub labeledFrameBox {
@@ -1662,8 +1677,6 @@ sub _userGroupsTabWidget {
my $userEnt = $self->ctx->LookupUserByName($userData{username});
my $lastchg = $userEnt->ShadowLastChange($self->USER_GetValue);
- my $align;
- my $hbox;
my $layout = labeledFrameBox($replace_pnt, N("Select groups that the user will be member of:"));
my $yTableHeader = new yui::YTableHeader();
@@ -2527,4 +2540,9 @@ sub TimeOfArray {
$cm and $h->{month} = $mth{$2};
$h;
}
-sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 } \ No newline at end of file
+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
diff --git a/Category.pm b/Category.pm
index fedb849..69eafc6 100644
--- a/Category.pm
+++ b/Category.pm
@@ -44,11 +44,74 @@ sub new {
}
## Add a new module to the list
+#=============================================================
+
+=head2 loadModule
+
+=head3 INPUT
+
+ $self: this object
+ $module: module to add
+
+=head3 OUTPUT
+
+ 1: if the module has been added
+ 0: otherwise
+
+=head3 DESCRIPTION
+
+ This method adds a module to the loaded
+ modules if it is not already in.
+
+=cut
+
+#=============================================================
sub loadModule {
my ($self, $module) = @_;
- push ( @{$self->{modules}}, $module );
+ if (!$self->moduleLoaded($module)) {
+ push ( @{$self->{modules}}, $module );
+ return 1;
+ }
+ return 0;
+}
+
+#=============================================================
+
+=head2 moduleLoaded
+
+=head3 INPUT
+
+ $self: this object
+ $module: module to look for
+
+=head3 OUTPUT
+
+ $present: module present or not
+
+=head3 DESCRIPTION
+
+ This method looks for the given module and if already in
+ returns true.
+=cut
+
+#=============================================================
+sub moduleLoaded {
+ my ($self, $module) = @_;
+ my $present = 0;
+
+ if (!$module) {
+ return $present;
+ }
+
+ foreach my $mod (@{$self->{modules}}) {
+ if ($mod->{name} eq $module->name) {
+ $present = 1;
+ last;
+ }
+ }
+ return $present;
}
## Create and add buttons for each module
@@ -65,10 +128,10 @@ sub addButtons {
}
$count++;
$tmpButton = $factory->createPushButton($currLayout,
- $mod->{name});
+ $mod->name);
$mod->setButton($tmpButton);
- $tmpButton->setLabel($mod->{name});
- $tmpButton->setIcon($mod->{icon});
+ $tmpButton->setLabel($mod->name);
+ $tmpButton->setIcon($mod->icon);
$factory->createHStretch($currLayout);
if(($count % 2) != 1) {
$factory->createVSpacing($pane, 2);
diff --git a/ConfigReader.pm b/ConfigReader.pm
index 379d144..d5ec8b1 100644
--- a/ConfigReader.pm
+++ b/ConfigReader.pm
@@ -41,6 +41,13 @@ sub new {
my $xml = new XML::Simple (KeyAttr=>[]);
$self->{data} = $xml->XMLin($fileName);
+ if (ref($self->{data}->{category}) eq "HASH") {
+ # one element alone
+ my @categories;
+ push @categories, $self->{data}->{category};
+ $self->{data}->{category} = undef;
+ push @{$self->{data}->{category}}, @categories;
+ }
$self->{catLen} = scalar(@{$self->{data}->{category}});
$self->{currCat} = -1;
diff --git a/MainDisplay.pm b/MainDisplay.pm
index efdfbd1..51c6a1e 100644
--- a/MainDisplay.pm
+++ b/MainDisplay.pm
@@ -125,7 +125,7 @@ sub start {
## If icon click, launch the Module
for(@{$self->{currCategory}->{modules}}) {
if( $_->{button} == $self->{event}->widget() ){
- $launch = $_->{launch};
+ $launch = $_;
last;
}
}
@@ -226,56 +226,150 @@ sub setupGui {
## adpanel settings
sub loadSettings {
my ($self) = @_;
-# configuration file name
+ # configuration file name
my $fileName = "$self->{confDir}/settings.conf";
$self->{settings} = new SettingsReader($fileName);
}
+#=============================================================
+
+=head2 categoryLoaded
+
+=head3 INPUT
+
+ $self: this object
+ $category: category to look for
+
+=head3 OUTPUT
+
+ $present: category is present or not
+
+=head3 DESCRIPTION
+
+ This method looks for the given category and if already in
+ returns true.
+=cut
+
+#=============================================================
+sub categoryLoaded {
+ my ($self, $category) = @_;
+ my $present = 0;
+
+ if (!$category) {
+ return $present;
+ }
+
+ foreach my $cat (@{$self->{categories}}) {
+ if ($cat->{name} eq $category->{name}) {
+ $present = 1;
+ last;
+ }
+ }
+
+ return $present;
+}
+
+#=============================================================
+
+=head2 getCategory
+
+=head3 INPUT
+
+ $self: this object
+ $name: category name
+
+=head3 OUTPUT
+
+ $category: category object if exists
+
+=head3 DESCRIPTION
+
+ This method looks for the given category name and returns
+ the realte object.
+=cut
+
+#=============================================================
+sub getCategory {
+ my ($self, $name) = @_;
+ my $category = undef;
+
+ foreach $category (@{$self->{categories}}) {
+ if ($category->{name} eq $name) {
+ last;
+ }
+ }
+
+ return $category;
+}
+
sub loadCategory {
my ($self, $category) = @_;
- push ( @{$self->{categories}}, $category );
+ if (!$self->categoryLoaded($category)) {
+ push ( @{$self->{categories}}, $category );
- @{$self->{categories}}[-1]->{button} = $self->{factory}->createPushButton(
- $self->{leftPane},
- $self->{categories}[-1]->{name}
- );
- @{$self->{categories}}[-1]->setIcon();
+ @{$self->{categories}}[-1]->{button} = $self->{factory}->createPushButton(
+ $self->{leftPane},
+ $self->{categories}[-1]->{name}
+ );
+ @{$self->{categories}}[-1]->setIcon();
- @{$self->{categories}}[-1]->{button}->setStretchable(0, 1);
-# @{$self->{categories}}[-1]->{button}->setStretchable(1, 1);
+ @{$self->{categories}}[-1]->{button}->setStretchable(0, 1);
+ }
}
sub loadCategories {
my ($self) = @_;
-# configuration file name
+ # category files
+ my @categoryFiles;
my $fileName = "$self->{confDir}/categories.conf";
-
- my $inFile = new ConfigReader($fileName);
- my $tmpCat;
- my $tmp;
- my $hasNextCat = $inFile->hasNextCat();
- while( $hasNextCat ) {
- $tmp = $inFile->getNextCat();
- $tmpCat = new Category($tmp->{title}, $tmp->{icon});
- $self->loadCategory($tmpCat);
- $hasNextCat = $inFile->hasNextCat();
- $self->{currCategory} = $tmpCat;
- my $hasNextMod = $inFile->hasNextMod();
- while( $hasNextMod ) {
- $tmp = $inFile->getNextMod();
- my $tmpMod = new Module($tmp->{title},
- $tmp->{icon},
- $tmp->{launcher}
- );
- $self->{currCategory}->loadModule($tmpMod);
-
- $hasNextMod = $inFile->hasNextMod();
+
+ # configuration file dir
+ my $directory = "$self->{confDir}/categories.conf.d";
+
+ push(@categoryFiles, $fileName);
+ push(@categoryFiles, <etc/categories.conf.d/*.conf>);
+
+ foreach $fileName (@categoryFiles) {
+ my $inFile = new ConfigReader($fileName);
+ my $tmpCat;
+ my $tmp;
+ my $hasNextCat = $inFile->hasNextCat();
+ while( $hasNextCat ) {
+ $tmp = $inFile->getNextCat();
+ $tmpCat = $self->getCategory($tmp->{title});
+ if (!$tmpCat) {
+ $tmpCat = new Category($tmp->{title}, $tmp->{icon});
+ $self->loadCategory($tmpCat);
+ }
+ $hasNextCat = $inFile->hasNextCat();
+ $self->{currCategory} = $tmpCat;
+
+ my $hasNextMod = $inFile->hasNextMod();
+ while( $hasNextMod ) {
+ $tmp = $inFile->getNextMod();
+ my $tmpMod;
+ my $loaded = 0;
+ if (exists $tmp->{title}) {
+ $tmpMod = Module->create(name => $tmp->{title},
+ icon => $tmp->{icon},
+ launcher => $tmp->{launcher}
+ );
+ }
+ elsif (exists $tmp->{class}) {
+ $tmpMod = Module->create(-CLASS => $tmp->{class});
+ }
+ if ($tmpMod) {
+ $loaded = $self->{currCategory}->loadModule($tmpMod);
+ undef $tmpMod if !$loaded;
+ }
+ $hasNextMod = $inFile->hasNextMod();
+ }
}
+ undef($tmpCat);
}
- undef($tmpCat);
}
sub menuEventIndex {
diff --git a/Module.pm b/Module.pm
index 579832f..a8803fc 100644
--- a/Module.pm
+++ b/Module.pm
@@ -22,28 +22,77 @@
#Class Module
package Module;
+use Moose;
+
+=head1 VERSION
+
+Version 0.01
+
+=cut
+
+our $VERSION = '1.0.0';
+
use strict;
use warnings;
use diagnostics;
use yui;
-sub new {
- my ($class, $newName, $newIcon, $newLaunch) = @_;
- my $self = {
- my $name = 0,
- my $icon = 0,
- my $launch = 0,
- my $button = 0
- };
- bless $self, 'Module';
-
- $self->{name} = $newName;
- $self->{icon} = $newIcon;
- $self->{launch} = $newLaunch;
-
- return $self;
+=head1 SUBROUTINES/METHODS
+
+=head2 create - returns a Module object such as a module
+ launcher (this object) or an extension of
+ this class
+
+=cut
+
+sub create {
+ my $class = shift;
+ $class = ref $class || $class;
+ my (%params) = @_;
+
+ my $obj;
+ if ( exists $params{-CLASS} ) {
+ my $driver = $params{-CLASS};
+
+ eval {
+ my $pkg = $driver;
+ $pkg =~ s/::/\//g;
+ $pkg .= '.pm';
+ require $pkg;
+ $obj=$driver->new();
+ };
+ if ( $@ ) {
+ die "Error getting obj for driver $params{-CLASS}: $@";
+ return undef;
+ }
+ }
+ else {
+ $obj = new Module(@_);
+ }
+ return $obj;
}
+has 'icon' => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has 'name' => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has 'launch' => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has 'button' => (
+ is => 'rw',
+ init_arg => undef,
+);
+
+
sub setButton {
my ($self, $button) = @_;
$self->{button} = $button;
@@ -55,4 +104,16 @@ sub removeButton {
undef($self->{button});
}
+# base class launcher
+sub start {
+ my $self = shift;
+
+ my $err = yui::YUI::app()->runInTerminal( $self->{launch} . " --ncurses");
+ if ($err == -1) {
+ system($self->{launch});
+ }
+}
+
+
+no Moose;
1;
diff --git a/apanel.pl b/apanel.pl
index c6148c7..e2042da 100755
--- a/apanel.pl
+++ b/apanel.pl
@@ -43,10 +43,7 @@ while ($launch) {
$mainWin->destroy();
undef($mainWin);
- my $err = yui::YUI::app()->runInTerminal("$launch --ncurses");
- if ($err == -1) {
- system($launch);
- }
+ $launch->start();
$mainWin = new MainDisplay();
$launch = $mainWin->start();
diff --git a/modules/usermanager/usermanager b/modules/usermanager/usermanager
index 80a5758..e4cbe5f 100755
--- a/modules/usermanager/usermanager
+++ b/modules/usermanager/usermanager
@@ -18,6 +18,6 @@ yui::YUI::app()->setApplicationTitle(N("Mageia Users Management Tool"));
yui::YUI::app()->setApplicationIcon($wm_icon);
my $userMan = AdminPanel::Users::GUsers->new();
-$userMan->manageUsersDialog();
+$userMan->start();
1;