From 5a547e6b955ea5c655edb3b87b7ff7676ced36fe Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Tue, 6 Nov 2012 20:15:01 +0000 Subject: change code alignment using tabstop=4 shiftwidth=4 expandtab --- Auth.pm | 27 +++++++------- Category.pm | 38 +++++++++---------- ConfigReader.pm | 25 +++++++------ MainDisplay.pm | 110 +++++++++++++++++++++++++++--------------------------- Module.pm | 9 +++-- SettingsReader.pm | 1 + apanel.pl | 30 +++++++-------- modules/test.cpp | 54 ++++++++++++--------------- 8 files changed, 144 insertions(+), 150 deletions(-) diff --git a/Auth.pm b/Auth.pm index def5cd3b..81550564 100644 --- a/Auth.pm +++ b/Auth.pm @@ -1,3 +1,4 @@ +# vim: set et ts=4 sw=4: # Copyright 2012 Matteo Pasotti # # This file is part of AdminPanel @@ -20,7 +21,7 @@ package Auth; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(require_root_capability - ask_for_authentication); + ask_for_authentication); use strict; use warnings; @@ -29,22 +30,22 @@ use Data::Dumper; sub require_root_capability { - return 0 if(!$>); - return 1; + return 0 if(!$>); + return 1; } sub ask_for_authentication { - my @args = @ARGV; - my $command = wrap_command($0); - unshift(@args, $command->[2]); - exec { $command->[0] } $command->[1], @args or die ("command %s missing", $command->[0]); - die "You must be root to run this program" if $>; + my @args = @ARGV; + my $command = wrap_command($0); + unshift(@args, $command->[2]); + exec { $command->[0] } $command->[1], @args or die ("command %s missing", $command->[0]); + die "You must be root to run this program" if $>; } sub wrap_command { - my $currenv = "env"; - my $wrapper = "pkexec"; - my $app = $0; - my $command = [$wrapper, $currenv, $app]; - ($command); + my $currenv = "env"; + my $wrapper = "pkexec"; + my $app = $0; + my $command = [$wrapper, $currenv, $app]; + ($command); } diff --git a/Category.pm b/Category.pm index 6e4a58d4..fedb8495 100644 --- a/Category.pm +++ b/Category.pm @@ -1,3 +1,4 @@ +# vim: set et ts=4 sw=4: # Copyright 2012 Steven Tucker # # This file is part of AdminPanel @@ -31,8 +32,8 @@ sub new { my $self = { my $name = 0, my $button = 0, - my $icon = 0, - my $modules = 0 + my $icon = 0, + my $modules = 0 }; bless $self, 'Category'; @@ -58,23 +59,20 @@ sub addButtons { my $currLayout = 0; $factory->createVSpacing($pane, 2); foreach my $mod (@{$self->{modules}}) { - if(($count % 2) != 1) - { - $currLayout = $factory->createHBox($pane); - $factory->createHStretch($currLayout); - } - $count++; - $tmpButton = $factory->createPushButton($currLayout, - $mod->{name} - ); - $mod->setButton($tmpButton); - $tmpButton->setLabel($mod->{name}); - $tmpButton->setIcon($mod->{icon}); - $factory->createHStretch($currLayout); - if(($count % 2) != 1) - { - $factory->createVSpacing($pane, 2); - } + if(($count % 2) != 1) { + $currLayout = $factory->createHBox($pane); + $factory->createHStretch($currLayout); + } + $count++; + $tmpButton = $factory->createPushButton($currLayout, + $mod->{name}); + $mod->setButton($tmpButton); + $tmpButton->setLabel($mod->{name}); + $tmpButton->setIcon($mod->{icon}); + $factory->createHStretch($currLayout); + if(($count % 2) != 1) { + $factory->createVSpacing($pane, 2); + } } $factory->createVStretch($pane); } @@ -84,7 +82,7 @@ sub removeButtons { my($self) = @_; for(@{$self->{modules}}) { - $_->removeButton(); + $_->removeButton(); } } diff --git a/ConfigReader.pm b/ConfigReader.pm index 22d3b495..379d144e 100644 --- a/ConfigReader.pm +++ b/ConfigReader.pm @@ -1,3 +1,4 @@ +# vim: set et ts=4 sw=4: # Copyright 2012 Steven Tucker # # This file is part of AdminPanel @@ -29,12 +30,12 @@ sub new { my ($class, $fileName) = @_; my $self = { - my $data = 0, - my $catLen = 0, + my $data = 0, + my $catLen = 0, my $currCat = 0, - my $modLen = 0, - my $currMod = 0, - my $placeHolder = 0 + my $modLen = 0, + my $currMod = 0, + my $placeHolder = 0 }; bless $self, 'ConfigReader'; @@ -46,7 +47,7 @@ sub new { if(ref(@{$self->{data}->{category}}[0]->{module}) eq "ARRAY") { $self->{modLen} = scalar(@{@{$self->{data}->{category}}[0]->{module}}); } else { - $self->{modLen} = 1; + $self->{modLen} = 1; } $self->{currMod} = -1; @@ -57,7 +58,7 @@ sub hasNextCat { my ($self) = @_; if($self->{currCat} + 1 >= $self->{catLen}) { - return 0; + return 0; } return 1; } @@ -67,7 +68,7 @@ sub getNextCat { $self->{currCat}++; if($self->{currCat} >= $self->{catLen}) { - return 0; + return 0; } # Reset the Module Count and Mod length for new Category @@ -75,7 +76,7 @@ sub getNextCat { if(ref(@{$self->{data}->{category}}[$self->{currCat}]->{module}) eq "ARRAY") { $self->{modLen} = scalar(@{@{$self->{data}->{category}}[$self->{currCat}]->{module}}); } else { - $self->{modLen} = 1; + $self->{modLen} = 1; } my $tmp = @{$self->{data}->{category}}[$self->{currCat}]; @@ -87,7 +88,7 @@ sub hasNextMod { my ($self) = @_; if($self->{currMod} + 1 >= $self->{modLen}) { - return 0; + return 0; } return 1; } @@ -100,9 +101,9 @@ sub getNextMod { $self->{currMod}++; if($self->{modLen} == 1) { - $ret = @{$self->{data}->{category}}[$self->{currCat}]->{module}; + $ret = @{$self->{data}->{category}}[$self->{currCat}]->{module}; } else { - $ret = @{@{$self->{data}->{category} }[$self->{currCat}]->{module}}[$self->{currMod}]; + $ret = @{@{$self->{data}->{category} }[$self->{currCat}]->{module}}[$self->{currMod}]; } return $ret; diff --git a/MainDisplay.pm b/MainDisplay.pm index 5e42641c..efdfbd15 100644 --- a/MainDisplay.pm +++ b/MainDisplay.pm @@ -1,3 +1,4 @@ +# vim: set et ts=4 sw=4: # Copyright 2012 Steven Tucker # # This file is part of AdminPanel @@ -79,56 +80,55 @@ sub start { my $launch = 0; while(!$launch) { - ## Grab Event + ## Grab Event $self->{event} = $self->{mainWin}->waitForEvent(); - ## Check for window close - if ($self->{event}->eventType() == $yui::YEvent::CancelEvent) - { + ## Check for window close + if ($self->{event}->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 + ## 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 + ## 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}); + ## 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(); + $self->{replacePoint}->showChild(); + $self->{mainWin}->recalcLayout(); + $self->{mainWin}->doneMultipleChanges(); - last; - } + 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 = $_->{launch}; - 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 = $_->{launch}; + last; + } + } } return $launch; @@ -144,7 +144,7 @@ sub setupGui { my $cmdline = new yui::YCommandLine; -## TODO add parameter check + ## TODO add parameter check my $pos = $cmdline->find("--name"); if ($pos > 0) { @@ -257,23 +257,23 @@ sub loadCategories { 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(); - } + $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(); + } } undef($tmpCat); } @@ -289,7 +289,7 @@ sub menuEventIndex { if($self->{event}->widget() == @{$self->{categories}}[$i]->{button}) { $index = $i; - print "Index found is : ".$index; + print "Index found is : ".$index; last; } } diff --git a/Module.pm b/Module.pm index 990de15f..579832fe 100644 --- a/Module.pm +++ b/Module.pm @@ -1,5 +1,6 @@ #!/usr/bin/perl +# vim: set et ts=4 sw=4: # Copyright 2012 Steven Tucker # # This file is part of AdminPanel @@ -29,10 +30,10 @@ use yui; sub new { my ($class, $newName, $newIcon, $newLaunch) = @_; my $self = { - my $name = 0, - my $icon = 0, - my $launch = 0, - my $button = 0 + my $name = 0, + my $icon = 0, + my $launch = 0, + my $button = 0 }; bless $self, 'Module'; diff --git a/SettingsReader.pm b/SettingsReader.pm index dddcdd4e..e0790f61 100644 --- a/SettingsReader.pm +++ b/SettingsReader.pm @@ -1,3 +1,4 @@ +# vim: set et ts=4 sw=4: # Copyright 2012 Angelo Naselli # # This file is part of AdminPanel diff --git a/apanel.pl b/apanel.pl index d1c5c1ec..9c6c4de2 100755 --- a/apanel.pl +++ b/apanel.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl - +# vim: set et ts=4 sw=4: # Copyright 2012 Steven Tucker # # This file is part of AdminPanel @@ -35,14 +35,12 @@ ask_for_authentication() if(require_root_capability()); my $mainWin = new MainDisplay(); my $launch = $mainWin->start(); -while($launch) -{ +while ($launch) { $mainWin->destroy(); undef($mainWin); my $err = yui::YUI::app()->runInTerminal("$launch --ncurses"); - if ($err == -1) - { + if ($err == -1) { system($launch); } @@ -54,18 +52,18 @@ $mainWin->destroy(); undef($mainWin); sub usage { - print "\n"; - print "Usage apanel [options...]\n\n"; - print "Options:\n"; - print "\t--help | -h print this help\n"; + print "\n"; + print "Usage apanel [options...]\n\n"; + print "Options:\n"; + print "\t--help | -h print this help\n"; ## anaselli: --name now is used only to add a path to /etc (e.g. --name mcc2 means /etc/mcc2) - # and it is overriden by --conf_dir, so it should be discussed better to understand - # if it is really needed any more. - # Window title is got from settings.conf (key title) - print "\t--name string specify the window title of the administration panel\n"; - print "\t--conf_dir path specify the settings.conf file directory\n"; - print "\n"; - exit(0); + # and it is overriden by --conf_dir, so it should be discussed better to understand + # if it is really needed any more. + # Window title is got from settings.conf (key title) + print "\t--name string specify the window title of the administration panel\n"; + print "\t--conf_dir path specify the settings.conf file directory\n"; + print "\n"; + exit(0); } =pod diff --git a/modules/test.cpp b/modules/test.cpp index 6f3178ef..8c3aa647 100644 --- a/modules/test.cpp +++ b/modules/test.cpp @@ -1,3 +1,5 @@ +// vim: set et ts=4 sw=4: +// // Trivial libyui example. // // Compile with: @@ -46,7 +48,7 @@ int main( int argc, char **argv ) std::vectorbuttons; for (;;) - { + { YEvent* event = dialog->waitForEvent(); // Check for window close if (event->eventType() == YEvent::CancelEvent) @@ -56,7 +58,7 @@ int main( int argc, char **argv ) // Check for Exit button push if(event->widget() == (YWidget*)exitButton ) { - break; + break; }; if(event->widget() == (YWidget*)addButton ) { @@ -66,8 +68,7 @@ int main( int argc, char **argv ) vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); bnum++; buttons.clear(); - for (int i=0; i < bnum; ++i) - { + for (int i=0; i < bnum; ++i) { YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); buttons.push_back(tmpB); } @@ -75,14 +76,12 @@ int main( int argc, char **argv ) dialog->recalcLayout(); dialog->doneMultipleChanges(); } - else if (bnum == 6) - { + else if (bnum == 6) { dialog->startMultipleChanges(); replacePoint->deleteChildren(); vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); buttons.clear(); - for (int i=0; i < bnum; ++i) - { + for (int i=0; i < bnum; ++i) { YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); buttons.push_back(tmpB); } @@ -93,37 +92,32 @@ int main( int argc, char **argv ) } } if(event->widget() == (YWidget*)removeButton ) { - if (bnum > 0) - { - dialog->startMultipleChanges(); - replacePoint->deleteChildren(); - vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); - bnum--; - buttons.clear(); - for (int i=0; i < bnum; ++i) - { - YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); - buttons.push_back(tmpB); - } - replacePoint->showChild(); - dialog->recalcLayout(); - dialog->doneMultipleChanges(); + if (bnum > 0) { + dialog->startMultipleChanges(); + replacePoint->deleteChildren(); + vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); + bnum--; + buttons.clear(); + for (int i=0; i < bnum; ++i) { + YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); + buttons.push_back(tmpB); + } + replacePoint->showChild(); + dialog->recalcLayout(); + dialog->doneMultipleChanges(); } } - - for(int i = 0; i < bnum; ++i) - { + for(int i = 0; i < bnum; ++i) { if (event->widget() == (YWidget*)buttons[i]) { dialog->startMultipleChanges(); replacePoint->deleteChildren(); vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); bnum--; buttons.clear(); - for (int i=0; i < bnum; ++i) - { - YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); - buttons.push_back(tmpB); + for (int i=0; i < bnum; ++i) { + YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); + buttons.push_back(tmpB); } replacePoint->showChild(); dialog->recalcLayout(); -- cgit v1.2.1