diff options
-rw-r--r-- | AdminPanel/Shared.pm | 175 | ||||
-rwxr-xr-x | modules/logviewer/logviewer.pl | 134 |
2 files changed, 190 insertions, 119 deletions
diff --git a/AdminPanel/Shared.pm b/AdminPanel/Shared.pm new file mode 100644 index 00000000..0779d0ea --- /dev/null +++ b/AdminPanel/Shared.pm @@ -0,0 +1,175 @@ +#!/usr/bin/perl +# vim: set et ts=4 sw=4: +# Copyright 2012-2013 Angelo Naselli <anaselli@linux.it> +# +# This file is part of LogViever +# +# LogViever is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# LogViever is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LogViever. If not, see <http://www.gnu.org/licenses/>. + +package AdminPanel::Shared; + +use strict; +use warnings; +use diagnostics; +use yui; +use base qw(Exporter); + +our @EXPORT = qw(warningMsgBox + msgBox + infoMsgBox + ask_YesOrNo + ask_OkCancel); + +sub warningMsgBox { + my ($st) = @_; + my $factory = yui::YUI::widgetFactory; + my $msg_box = $factory->createPopupDialog($yui::YDialogWarnColor); + my $layout = $factory->createVBox($msg_box); + my $align = $factory->createAlignment($layout, 3, 0); + $factory->createLabel( $align, $st, 1, 0); + $align = $factory->createAlignment($layout, 3, 0); + $factory->createPushButton($align, N("Ok")); + $msg_box->waitForEvent(); + + destroy $msg_box; +} + +sub infoMsgBox { + my ($st) = @_; + my $factory = yui::YUI::widgetFactory; + my $msg_box = $factory->createPopupDialog($yui::YDialogInfoColor); + my $layout = $factory->createVBox($msg_box); + my $align = $factory->createAlignment($layout, 3, 0); + $factory->createLabel( $align, $st, 1, 0); + $align = $factory->createAlignment($layout, 3, 0); + $factory->createPushButton($align, N("Ok")); + $msg_box->waitForEvent(); + + destroy $msg_box; +} + +sub msgBox { + my ($st) = @_; + my $factory = yui::YUI::widgetFactory; + my $msg_box = $factory->createPopupDialog($yui::YDialogNormalColor); + my $layout = $factory->createVBox($msg_box); + my $align = $factory->createAlignment($layout, 3, 0); + $factory->createLabel( $align, $st, 1, 0); + $align = $factory->createAlignment($layout, 3, 0); + $factory->createPushButton($align, N("Ok")); + $msg_box->waitForEvent(); + + destroy $msg_box; +} + +sub ask_OkCancel { + my ($title, $text) = @_; + my $retVal = 0; + my $factory = yui::YUI::widgetFactory; + + my $msg_box = $factory->createPopupDialog($yui::YDialogNormalColor); + my $layout = $factory->createVBox($msg_box); + + my $align = $factory->createAlignment($layout, 3, 0); + ## title with headings true + $factory->createLabel( $align, $title, 1, 0); + $align = $factory->createLeft($layout); + $factory->createLabel( $align, $text, 0, 0); + + $align = $factory->createRight($layout); + my $hbox = $factory->createHBox($align); + my $okButton = $factory->createPushButton($hbox, N("Ok")); + my $cancelButton = $factory->createPushButton($hbox, N("Cancel")); + + my $event = $msg_box->waitForEvent(); + + my $eventType = $event->eventType(); + + if ($eventType == $yui::YEvent::WidgetEvent) { + # widget selected + my $widget = $event->widget(); + $retVal = ($widget == $okButton); + } + + destroy $msg_box; + + return $retVal; +} + +sub ask_YesOrNo { + my ($title, $text) = @_; + my $retVal = "No"; + my $factory = yui::YUI::widgetFactory; + + my $msg_box = $factory->createPopupDialog($yui::YDialogNormalColor); + my $layout = $factory->createVBox($msg_box); + + my $align = $factory->createAlignment($layout, 3, 0); + ## title with headings true + $factory->createLabel( $align, $title, 1, 0); + $align = $factory->createLeft($layout); + $factory->createLabel( $align, $text, 0, 0); + + $align = $factory->createRight($layout); + my $hbox = $factory->createHBox($align); + my $yesButton = $factory->createPushButton($hbox, N("Yes")); + my $noButton = $factory->createPushButton($hbox, N("No")); + + my $event = $msg_box->waitForEvent(); + + my $eventType = $event->eventType(); + + if ($eventType == $yui::YEvent::WidgetEvent) { + # widget selected + my $widget = $event->widget(); + $retVal = ($widget == $yesButton) ? "Yes" : "No"; + } + + destroy $msg_box; + + return $retVal; +} + +1; + +=head1 NAME + + Shared - shared module providing common routines + +=head1 SYNOPSIS + + +=head1 METHODS + +=head2 warningMsgBox + +=head2 msgBox + + shows a simple message box + +=head2 infoMsgBox + + shows a message box for informations + +=head2 ask_YesOrNo + + shows a dialog with two buttons (Yes/No) + +=head3 return value(string) + +=head2 ask_OkCancel + + shows a dialog with to buttons (Ok/Cancel) + +=head3 return value(string) diff --git a/modules/logviewer/logviewer.pl b/modules/logviewer/logviewer.pl index 4bbfb9c1..c0c0e705 100755 --- a/modules/logviewer/logviewer.pl +++ b/modules/logviewer/logviewer.pl @@ -29,16 +29,23 @@ use lib qw(/usr/lib/libDrakX); use standalone; #- warning, standalone must be loaded very first, for 'explanations' use c; use common; -#use AdminPanel::Privileges; use yui; +#use AdminPanel::Privileges; +use AdminPanel::Shared; + ### TODO icon my $wm_icon = "/usr/share/mcc/themes/default/logdrake-mdk.png"; -#ask_for_authentication() if(require_root_capability()); +#ask_for_authentication($USE_CHLP) if(require_root_capability()); my ($isExplain, $Explain, $isFile, $File, $isWord, $Word); +# prototypes +sub alert_config; +sub quit; +sub search; + #- parse arguments list. foreach (@ARGV) { /^--explain=(.*)$/ and do { $isExplain = ($Explain) = $1; $isFile = 1; $File = "/var/log/explanations"; next }; @@ -232,9 +239,9 @@ while(1) { elsif ($widget == $mailALertButton) { alert_config(); } - else { - warningMsgBox(N("Unmanaged WidgetEvent")); - } + else { + warningMsgBox(N("Unmanaged WidgetEvent")); + } } } @@ -407,7 +414,7 @@ sub logText { } ## Save as -sub save() { +sub save { my $outFile = yui::YUI::app()->askForSaveFileName(home(), "*", N("Save as..")); if ($outFile) { output($outFile, $logView->logText()); @@ -415,129 +422,18 @@ sub save() { } ## Quit -sub quit() { +sub quit { $my_win->destroy(); } ## alert config call back -sub alert_config() { +sub alert_config { ## TODO infoMsgBox(N("To be implemented yet")); return; } -### Begin interactive functions ### -# NOTE next routines (from BEGIN to END) have to be moved to a package and -# factory got by using yui::YUI::widgetFactory - -sub warningMsgBox() { - my ($st) = @_; - my $msg_box = $factory->createPopupDialog($yui::YDialogWarnColor); - my $layout = $factory->createVBox($msg_box); - my $align = $factory->createAlignment($layout, 3, 0); - $factory->createLabel( $align, $st, 1, 0); - $align = $factory->createAlignment($layout, 3, 0); - $factory->createPushButton($align, N("Ok")); - $msg_box->waitForEvent(); - - destroy $msg_box; -} - -sub infoMsgBox() { - my ($st) = @_; - my $msg_box = $factory->createPopupDialog($yui::YDialogInfoColor); - my $layout = $factory->createVBox($msg_box); - my $align = $factory->createAlignment($layout, 3, 0); - $factory->createLabel( $align, $st, 1, 0); - $align = $factory->createAlignment($layout, 3, 0); - $factory->createPushButton($align, N("Ok")); - $msg_box->waitForEvent(); - - destroy $msg_box; -} - -sub msgBox() { - my ($st) = @_; - my $msg_box = $factory->createPopupDialog($yui::YDialogNormalColor); - my $layout = $factory->createVBox($msg_box); - my $align = $factory->createAlignment($layout, 3, 0); - $factory->createLabel( $align, $st, 1, 0); - $align = $factory->createAlignment($layout, 3, 0); - $factory->createPushButton($align, N("Ok")); - $msg_box->waitForEvent(); - - destroy $msg_box; -} - -sub ask_OkCancel() { - my ($title, $text) = @_; - my $retVal = 0; - - my $msg_box = $factory->createPopupDialog($yui::YDialogNormalColor); - my $layout = $factory->createVBox($msg_box); - - my $align = $factory->createAlignment($layout, 3, 0); - ## title with headings true - $factory->createLabel( $align, $title, 1, 0); - my $align = $factory->createLeft($layout); - $factory->createLabel( $align, $text, 0, 0); - - $align = $factory->createRight($layout); - my $hbox = $factory->createHBox($align); - my $okButton = $factory->createPushButton($hbox, N("Ok")); - my $cancelButton = $factory->createPushButton($hbox, N("Cancel")); - - my $event = $msg_box->waitForEvent(); - - my $eventType = $event->eventType(); - - if ($eventType == $yui::YEvent::WidgetEvent) { - # widget selected - my $widget = $event->widget(); - $retVal = ($widget == $okButton); - } - - destroy $msg_box; - - return $retVal; -} - -sub ask_YesOrNo() { - my ($title, $text) = @_; - my $retVal = "No"; - - my $msg_box = $factory->createPopupDialog($yui::YDialogNormalColor); - my $layout = $factory->createVBox($msg_box); - - my $align = $factory->createAlignment($layout, 3, 0); - ## title with headings true - $factory->createLabel( $align, $title, 1, 0); - my $align = $factory->createLeft($layout); - $factory->createLabel( $align, $text, 0, 0); - - $align = $factory->createRight($layout); - my $hbox = $factory->createHBox($align); - my $yesButton = $factory->createPushButton($hbox, N("Yes")); - my $noButton = $factory->createPushButton($hbox, N("No")); - - my $event = $msg_box->waitForEvent(); - - my $eventType = $event->eventType(); - - if ($eventType == $yui::YEvent::WidgetEvent) { - # widget selected - my $widget = $event->widget(); - $retVal = ($widget == $yesButton) ? "Yes" : "No"; - } - - destroy $msg_box; - - return $retVal; -} - -### END interactive functions ### - ### NOTE next code has to be removed after getting mail alert functionality =comment |