diff options
author | Angelo Naselli <anaselli@linux.it> | 2014-01-16 16:02:49 +0100 |
---|---|---|
committer | Angelo Naselli <anaselli@linux.it> | 2014-01-16 16:02:49 +0100 |
commit | fed16eef71eacf5e06b7efb633e6cbf1e55f38f0 (patch) | |
tree | 04717956a7eca187aef30c4748c56338c9735ff9 | |
parent | 1f0a53f65d026d328f34714dd2d7b0ba254e1dad (diff) | |
download | colin-keep-fed16eef71eacf5e06b7efb633e6cbf1e55f38f0.tar colin-keep-fed16eef71eacf5e06b7efb633e6cbf1e55f38f0.tar.gz colin-keep-fed16eef71eacf5e06b7efb633e6cbf1e55f38f0.tar.bz2 colin-keep-fed16eef71eacf5e06b7efb633e6cbf1e55f38f0.tar.xz colin-keep-fed16eef71eacf5e06b7efb633e6cbf1e55f38f0.zip |
Added availability to instanziate once intead o many times
Fixed return Category (now is the one we left)
-rw-r--r-- | Category.pm | 19 | ||||
-rw-r--r-- | MainDisplay.pm | 96 | ||||
-rw-r--r-- | Module.pm | 8 | ||||
-rwxr-xr-x | apanel.pl | 5 |
4 files changed, 82 insertions, 46 deletions
diff --git a/Category.pm b/Category.pm index 7191fab..b43a4c1 100644 --- a/Category.pm +++ b/Category.pm @@ -69,7 +69,7 @@ sub new { sub loadModule { my ($self, $module) = @_; - if (!$self->moduleLoaded($module)) { + if (!$self->moduleLoaded($module->{name})) { push ( @{$self->{modules}}, $module ); return 1; @@ -83,8 +83,8 @@ sub loadModule { =head3 INPUT - $self: this object - $module: module to look for + $self: this object + $module_name or -CLASS => name : module/CLASS name to look for =head3 OUTPUT @@ -98,15 +98,22 @@ sub loadModule { #============================================================= sub moduleLoaded { - my ($self, $module) = @_; + my $self = shift; + my (%params) = @_; + my ($module_name) = @_; + my $present = 0; - if (!$module) { + if (!$module_name) { return $present; } foreach my $mod (@{$self->{modules}}) { - if ($mod->{name} eq $module->name) { + if (exists $params{-CLASS} && ref($mod) eq $params{-CLASS}) { + $present = 1; + last; + } + elsif ($mod->{name} eq $module_name) { $present = 1; last; } diff --git a/MainDisplay.pm b/MainDisplay.pm index afb730f..ed75108 100644 --- a/MainDisplay.pm +++ b/MainDisplay.pm @@ -61,8 +61,29 @@ sub new { $self->{categories} = []; $self->{confDir} = "/etc/apanel", $self->{title} = "apanel", - $self->setupGui(); + my $cmdline = new yui::YCommandLine; + + ## TODO add parameter check + my $pos = $cmdline->find("--name"); + if ($pos > 0) + { + $self->{title} = $cmdline->arg($pos+1); + } + $pos = $cmdline->find("--conf_dir"); + if ($pos > 0) + { + $self->{confDir} = $cmdline->arg($pos+1); + } + else + { + $self->{confDir} = "/etc/$self->{title}"; + } +# print "name = ".$self->{title}."\n"; +# print "conf dir = ".$self->{confDir}."\n"; + + $self->setupGui(); + return $self; } @@ -72,11 +93,12 @@ sub start { my $reqExit = 0; ##Default category selection - $self->{currCategory} = @{$self->{categories}}[0]; + if (!$self->{currCategory}) { + $self->{currCategory} = @{$self->{categories}}[0]; + } $self->{currCategory}->addButtons($self->{rightPane}, $self->{factory}); $self->{rightPaneFrame}->setLabel($self->{currCategory}->{name}); $self->{factory}->createSpacing($self->{rightPane}, 1, 1, 1.0 ); - my $launch = 0; while(!$launch) { @@ -137,31 +159,15 @@ sub start { sub destroy { my ($self) = shift; $self->{mainWin}->destroy(); + for (my $cat=0; $cat < scalar(@{$self->{categories}}); $cat++ ) { + @{$self->{categories}}[$cat]->{button} = 0; + @{$self->{categories}}[$cat]->removeButtons(); + } } sub setupGui { my ($self) = shift; - my $cmdline = new yui::YCommandLine; - - ## TODO add parameter check - my $pos = $cmdline->find("--name"); - if ($pos > 0) - { - $self->{title} = $cmdline->arg($pos+1); - } - $pos = $cmdline->find("--conf_dir"); - if ($pos > 0) - { - $self->{confDir} = $cmdline->arg($pos+1); - } - else - { - $self->{confDir} = "/etc/$self->{title}"; - } -# print "name = ".$self->{title}."\n"; -# print "conf dir = ".$self->{confDir}."\n"; - $self->loadSettings(); yui::YUILog::setLogFileName($self->{settings}->{log}); $self->{name} = $self->{settings}->{title}; @@ -225,10 +231,12 @@ sub setupGui { ## adpanel settings sub loadSettings { - my ($self) = @_; + my ($self, $force_load) = @_; # configuration file name my $fileName = "$self->{confDir}/settings.conf"; - $self->{settings} = new SettingsReader($fileName); + if (!$self->{settings} || $force_load) { + $self->{settings} = new SettingsReader($fileName); + } } #============================================================= @@ -316,6 +324,21 @@ sub loadCategory { @{$self->{categories}}[-1]->{button}->setStretchable(0, 1); } + else { + for (my $cat=0; $cat < scalar(@{$self->{categories}}); $cat++ ) { + if( @{$self->{categories}}[$cat]->{name} eq $category->{name} && + !@{$self->{categories}}[$cat]->{button}) { + @{$self->{categories}}[$cat]->{button} = $self->{factory}->createPushButton( + $self->{leftPane}, + $self->{categories}[$cat]->{name} + ); + @{$self->{categories}}[$cat]->setIcon(); + @{$self->{categories}}[$cat]->{button}->setStretchable(0, 1); + last; + + } + } + } } sub loadCategories { @@ -331,6 +354,7 @@ sub loadCategories { push(@categoryFiles, $fileName); push(@categoryFiles, <etc/categories.conf.d/*.conf>); + my $currCategory; foreach $fileName (@categoryFiles) { my $inFile = new ConfigReader($fileName); @@ -342,10 +366,10 @@ sub loadCategories { $tmpCat = $self->getCategory($tmp->{title}); if (!$tmpCat) { $tmpCat = new Category($tmp->{title}, $tmp->{icon}); - $self->loadCategory($tmpCat); } - $hasNextCat = $inFile->hasNextCat(); - $self->{currCategory} = $tmpCat; + $self->loadCategory($tmpCat); + $hasNextCat = $inFile->hasNextCat(); + $currCategory = $tmpCat; my $hasNextMod = $inFile->hasNextMod(); while( $hasNextMod ) { @@ -353,16 +377,20 @@ sub loadCategories { my $tmpMod; my $loaded = 0; if (exists $tmp->{title}) { - $tmpMod = Module->create(name => $tmp->{title}, - icon => $tmp->{icon}, - launcher => $tmp->{launcher} - ); + if (not $currCategory->moduleLoaded($tmp->{title})) { + $tmpMod = Module->create(name => $tmp->{title}, + icon => $tmp->{icon}, + launch => $tmp->{launcher} + ); + } } elsif (exists $tmp->{class}) { - $tmpMod = Module->create(-CLASS => $tmp->{class}); + if (not $currCategory->moduleLoaded(-CLASS => $tmp->{class})) { + $tmpMod = Module->create(-CLASS => $tmp->{class}); + } } if ($tmpMod) { - $loaded = $self->{currCategory}->loadModule($tmpMod); + $loaded = $currCategory->loadModule($tmpMod); undef $tmpMod if !$loaded; } $hasNextMod = $inFile->hasNextMod(); @@ -108,9 +108,11 @@ sub removeButton { sub start { my $self = shift; - my $err = yui::YUI::app()->runInTerminal( $self->{launch} . " --ncurses"); - if ($err == -1) { - system($self->{launch}); + if ($self->{launch}) { + my $err = yui::YUI::app()->runInTerminal( $self->{launch} . " --ncurses"); + if ($err == -1) { + system($self->{launch}); + } } } @@ -37,20 +37,19 @@ my $settings = getSettings(); ask_for_authentication($settings->{priv_method}) if(require_root_capability()); -while (1) { my $mainWin = new MainDisplay(); +while (1) { my $launch = $mainWin->start(); if ($launch) { $mainWin->destroy(); $launch->start(); - undef($mainWin); } else { $mainWin->destroy(); - undef($mainWin); last; } + $mainWin->setupGui(); } |