aboutsummaryrefslogtreecommitdiffstats
path: root/Category.pm
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 /Category.pm
parenteb0eab8fc6d0c89262daa80d199bb7091540943b (diff)
downloadmanatools-11533544ca01c2c54899af0a00f2c062c1831433.tar
manatools-11533544ca01c2c54899af0a00f2c062c1831433.tar.gz
manatools-11533544ca01c2c54899af0a00f2c062c1831433.tar.bz2
manatools-11533544ca01c2c54899af0a00f2c062c1831433.tar.xz
manatools-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
Diffstat (limited to 'Category.pm')
-rw-r--r--Category.pm71
1 files changed, 67 insertions, 4 deletions
diff --git a/Category.pm b/Category.pm
index fedb8495..69eafc63 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);