aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2014-01-28 12:32:08 +0100
committerAngelo Naselli <anaselli@linux.it>2014-01-28 12:32:08 +0100
commit1c08ae3363794192339be4ec9436eaee4bc143e9 (patch)
tree52d0f14a48a0ce72981bc326a8056f1e7a625ac4
parent3249c6f581f90ade1bdbc23d233cc0fc452bfceb (diff)
downloadcolin-keep-1c08ae3363794192339be4ec9436eaee4bc143e9.tar
colin-keep-1c08ae3363794192339be4ec9436eaee4bc143e9.tar.gz
colin-keep-1c08ae3363794192339be4ec9436eaee4bc143e9.tar.bz2
colin-keep-1c08ae3363794192339be4ec9436eaee4bc143e9.tar.xz
colin-keep-1c08ae3363794192339be4ec9436eaee4bc143e9.zip
- fixed POD
- better management for events
-rw-r--r--lib/AdminPanel/Category.pm89
-rw-r--r--lib/AdminPanel/MainDisplay.pm291
2 files changed, 244 insertions, 136 deletions
diff --git a/lib/AdminPanel/Category.pm b/lib/AdminPanel/Category.pm
index 7c89fbb..95abf91 100644
--- a/lib/AdminPanel/Category.pm
+++ b/lib/AdminPanel/Category.pm
@@ -27,6 +27,27 @@ use yui;
## Can only add the config file data at constructor
## The Gui elements are added in setupGui inside MainDisplay
+#=============================================================
+
+=head2 new
+
+=head3 INPUT
+
+ $newName: new category name
+ $newIcon: new category icon
+
+=head3 OUTPUT
+
+ $self: this object
+
+=head3 DESCRIPTION
+
+ Constructor: creates a new category named Name
+
+=cut
+
+#=============================================================
+
sub new {
my ($class, $newName, $newIcon) = @_;
my $self = {
@@ -122,7 +143,23 @@ sub moduleLoaded {
return $present;
}
-## Create and add buttons for each module
+#=============================================================
+
+=head2 addButtons
+
+=head3 INPUT
+
+ $self: this object
+ $pane: parent panel in which create buttons
+ $factory: yui factory
+
+=head3 DESCRIPTION
+
+ Creates and adds buttons for each module_name
+
+=cut
+
+#=============================================================
sub addButtons {
my($self, $pane, $factory) = @_;
my $count = 0;
@@ -148,7 +185,21 @@ sub addButtons {
$factory->createVStretch($pane);
}
-## Delete the module buttons
+#=============================================================
+
+=head2 removeButtons
+
+=head3 INPUT
+
+$self: this object
+
+=head3 DESCRIPTION
+
+Delete the module buttons
+
+=cut
+
+#=============================================================
sub removeButtons {
my($self) = @_;
@@ -157,6 +208,21 @@ sub removeButtons {
}
}
+#=============================================================
+
+=head2 setIcon
+
+=head3 INPUT
+
+ $self: this object
+
+=head3 DESCRIPTION
+
+ set the button icon
+
+=cut
+
+#=============================================================
sub setIcon {
my($self) = @_;
@@ -179,23 +245,10 @@ __END__
=head1 USAGE
- my $display = new MainDisplay();
-
- my $category = new Category('Network');
- $display->loadCategory($category);
-
- $display->start();
+ This class is used by MainDisplay internally and should not
+ be used outside, since MainDisplay::setupGui use it to
+ build GUI layout.
=head1 FUNCTIONS
-=head2 new (name)
-
- Constructor: creates a new category named Name
-
- $category = new Category('Name');
-
-=head3 name (String)
-
- The name of the category
-
=cut
diff --git a/lib/AdminPanel/MainDisplay.pm b/lib/AdminPanel/MainDisplay.pm
index 8792bb2..23c435e 100644
--- a/lib/AdminPanel/MainDisplay.pm
+++ b/lib/AdminPanel/MainDisplay.pm
@@ -27,6 +27,8 @@ AdminPanel::MainDisplay - class for AdminPaneol main window
=head1 SYNOPSIS
$mainDisplay = new AdminPanel::MainDisplay();
+ $mainDisplay->start();
+ $mainDisplay->destroy();
=head1 METHODS
@@ -94,6 +96,18 @@ use AdminPanel::Module;
use Data::Dumper;
use yui;
+#=============================================================
+
+=head2 new
+
+=head3 DESCRIPTION
+
+This method instanziates the MainWindo object, and setups
+the startup GUI.
+
+=cut
+
+#=============================================================
sub new {
my $self = {
@@ -143,8 +157,6 @@ sub new {
{
$self->{confDir} = "/etc/$self->{title}";
}
-# print "name = ".$self->{title}."\n";
-# print "conf dir = ".$self->{confDir}."\n";
$self->setupGui();
@@ -168,58 +180,57 @@ sub start {
## Grab Event
$self->{event} = $self->{mainWin}->waitForEvent();
-
+ my $eventType = $self->{event}->eventType();
+
## Check for window close
- if ($self->{event}->eventType() == $yui::YEvent::CancelEvent)
- {
+ if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
-
-## why i can't test item() with $self->{menus}->{file}[0]?
- ## Check for Exit button push or menu
- if($self->{event}->widget() == $self->{exitButton} ||
- ($self->{event}->item() && ($self->{event}->item()->label() eq $self->{menus}->{file}[0]->label() ))) {
- last;
- };
-
- ## Discover if a menu button was selected.
- ## If menu button selected, set right panel to display
- ## selected Category Modules
- for(@{$self->{categories}}){
- if( $_->{button} == $self->{event}->widget() ){
- ## Menu item selected, set right pane
- $self->{mainWin}->startMultipleChanges();
- ## Remove existing modules
- $self->{replacePoint}->deleteChildren();
- $self->{rightPane} = $self->{factory}->createVBox($self->{replacePoint});
-
- ## Change Current Category to the selected one
- $self->{currCategory} = $_;
- ## Add new Module Buttons to Right Pane
- $self->{currCategory}->addButtons($self->{rightPane}, $self->{factory});
- $self->{rightPaneFrame}->setLabel($self->{currCategory}->{name});
- $self->{factory}->createSpacing($self->{rightPane}, 1, 1, 1.0 );
- $self->{replacePoint}->showChild();
- $self->{mainWin}->recalcLayout();
- $self->{mainWin}->doneMultipleChanges();
-
+ elsif ($eventType == $yui::YEvent::MenuEvent) {
+ ### MENU ###
+ my $item = $self->{event}->item();
+ if ($item->label() eq $self->{menus}->{file}[0]->label()) {
+ ## quit menu item
last;
}
- }
-
- ## Check if event is from current Category View
- ## If icon click, launch the Module
- for(@{$self->{currCategory}->{modules}}) {
- if( $_->{button} == $self->{event}->widget() ){
- $launch = $_;
+ }
+ elsif ($eventType == $yui::YEvent::WidgetEvent) {
+ my $widget = $self->{event}->widget();
+
+ ## Check for Exit button push or menu
+ if($widget == $self->{exitButton}) {
last;
}
- }
+ else {
+ # category button selected?
+ my $isCat = $self->_categorySelected($widget);
+ if (!$isCat) {
+ # module button selected?
+ $launch = $self->_moduleSelected($widget);
+ }
+ }
+ }
}
return $launch;
}
+#=============================================================
+
+=head2 destroy
+
+=head3 INPUT
+
+ $self: this object
+
+=head3 DESCRIPTION
+
+ This method destroyes the main window and all the
+ relevanto bojects (category and modules buttons).
+
+=cut
+
+#=============================================================
sub destroy {
my ($self) = shift;
$self->{mainWin}->destroy();
@@ -229,10 +240,25 @@ sub destroy {
}
}
+#=============================================================
+
+=head2 setupGui
+
+=head3 INPUT
+
+ $self: this object
+
+=head3 DESCRIPTION
+
+ This method load configuration and build the GUI layout.
+
+=cut
+
+#=============================================================
sub setupGui {
my ($self) = shift;
- $self->loadSettings();
+ $self->_loadSettings();
yui::YUILog::setLogFileName($self->{settings}->{log});
$self->{name} = $self->{settings}->{title};
yui::YUI::app()->setApplicationTitle($self->{name});
@@ -240,7 +266,6 @@ sub setupGui {
$self->{factory} = yui::YUI::widgetFactory;
$self->{mainWin} = $self->{factory}->createMainDialog;
-#print "Title: ".yui::YUI::app()->applicationTitle()."\n";
$self->{mainLayout} = $self->{factory}->createVBox($self->{mainWin});
$self->{menuLayout} = $self->{factory}->createHBox($self->{mainLayout});
@@ -284,17 +309,72 @@ sub setupGui {
# $self->{leftPaneFrame}->setWeight(0, 1);
$self->{rightPaneFrame}->setWeight(0, 2);
- $self->loadCategories();
+ $self->_loadCategories();
$self->{factory}->createVStretch($self->{leftPane});
$self->{exitButton} = $self->{factory}->createPushButton($self->{leftPane}, "Exit");
$self->{exitButton}->setIcon("$self->{settings}->{images_dir}/quit.png");
$self->{exitButton}->setStretchable(0, 1);
-# $self->{exitButton}->setStretchable(1, 1);
+}
+
+
+## internal methods
+
+## Check if event is from current Category View
+## If icon click, returns the module to be launched
+
+sub _moduleSelected {
+ my ($self, $selectedWidget) = @_;
+
+ for(@{$self->{currCategory}->{modules}}) {
+ if( $_->{button} == $selectedWidget ){
+ return $_;
+ }
+ }
+ return 0;
+}
+
+
+## Discover if a category button was selected.
+## If category button is selected, sets right panel to display
+## the selected Category Modules
+## returns 1 if category button is selected
+sub _categorySelected {
+ my ($self, $selectedWidget) = @_;
+ for (@{$self->{categories}}) {
+ if( $_->{button} == $selectedWidget ) {
+
+ #if current is already set then skips
+ if ($self->{currCategory} == $_) {
+ ## returns 1 to skip any other checks on
+ ## the selected widget
+ return 1;
+ }
+ ## Menu item selected, set right pane
+ $self->{mainWin}->startMultipleChanges();
+ ## Remove existing modules
+ $self->{replacePoint}->deleteChildren();
+ $self->{rightPane} = $self->{factory}->createVBox($self->{replacePoint});
+
+ ## Change Current Category to the selected one
+ $self->{currCategory} = $_;
+ ## Add new Module Buttons to Right Pane
+ $self->{currCategory}->addButtons($self->{rightPane}, $self->{factory});
+ $self->{rightPaneFrame}->setLabel($self->{currCategory}->{name});
+ $self->{factory}->createSpacing($self->{rightPane}, 1, 1, 1.0 );
+ $self->{replacePoint}->showChild();
+ $self->{mainWin}->recalcLayout();
+ $self->{mainWin}->doneMultipleChanges();
+
+ return 1;
+ }
+ }
+
+ return 0;
}
## adpanel settings
-sub loadSettings {
+sub _loadSettings {
my ($self, $force_load) = @_;
# configuration file name
my $fileName = "$self->{confDir}/settings.conf";
@@ -304,26 +384,24 @@ sub loadSettings {
}
#=============================================================
-
-=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
-
+# _categoryLoaded
+#
+# INPUT
+#
+# $self: this object
+# $category: category to look for
+#
+# OUTPUT
+#
+# $present: category is present or not
+#
+# DESCRIPTION
+#
+# This method looks for the given category and if already in
+# returns true.
+#
#=============================================================
-sub categoryLoaded {
+sub _categoryLoaded {
my ($self, $category) = @_;
my $present = 0;
@@ -342,26 +420,23 @@ sub categoryLoaded {
}
#=============================================================
-
-=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
-
+# _getCategory
+#
+# INPUT
+#
+# $self: this object
+# $name: category name
+#
+# OUTPUT
+#
+# $category: category object if exists
+#
+# DESCRIPTION
+#
+# This method looks for the given category name and returns
+# the realte object.
#=============================================================
-sub getCategory {
+sub _getCategory {
my ($self, $name) = @_;
my $category = undef;
@@ -374,10 +449,14 @@ sub getCategory {
return $category;
}
-sub loadCategory {
+# _loadCategory
+#
+# creates a new button representing a category
+#
+sub _loadCategory {
my ($self, $category) = @_;
- if (!$self->categoryLoaded($category)) {
+ if (!$self->_categoryLoaded($category)) {
push ( @{$self->{categories}}, $category );
@{$self->{categories}}[-1]->{button} = $self->{factory}->createPushButton(
@@ -405,7 +484,7 @@ sub loadCategory {
}
}
-sub loadCategories {
+sub _loadCategories {
my ($self) = @_;
# category files
@@ -427,11 +506,11 @@ sub loadCategories {
my $hasNextCat = $inFile->hasNextCat();
while( $hasNextCat ) {
$tmp = $inFile->getNextCat();
- $tmpCat = $self->getCategory($tmp->{title});
+ $tmpCat = $self->_getCategory($tmp->{title});
if (!$tmpCat) {
$tmpCat = new AdminPanel::Category($tmp->{title}, $tmp->{icon});
}
- $self->loadCategory($tmpCat);
+ $self->_loadCategory($tmpCat);
$hasNextCat = $inFile->hasNextCat();
$currCategory = $tmpCat;
@@ -463,43 +542,19 @@ sub loadCategories {
}
}
-sub menuEventIndex {
- my ($self) = shift;
-
- my $index = -1;
-
- for(my $i = 0; $i < scalar(@{$self->{categories}} ); ++$i)
- {
- print "Current Index = ".$index."\n";
- if($self->{event}->widget() == @{$self->{categories}}[$i]->{button})
- {
- $index = $i;
- print "Index found is : ".$index;
- last;
- }
- }
- return $index;
-}
-
1;
=pod
=head2 start
- contains the main loop of the application
- where we can check for events
+ contains the main loop of the application
+ where we can check for events
=head2 setupGui
- creates a popupDialog using a YUI::WidgetFactory
- and then populate this dialog with some components
-
-=head2 loadCategory
-
- creates a new button representing a category
-
-=head3 category (String)
+ creates a popupDialog using a YUI::WidgetFactory
+ and then populate this dialog with some components
=cut