diff options
author | Angelo Naselli <anaselli@linux.it> | 2014-12-05 16:49:56 +0100 |
---|---|---|
committer | Angelo Naselli <anaselli@linux.it> | 2014-12-05 16:49:56 +0100 |
commit | a7b02f6cee1153dd46a70323157b301c45065589 (patch) | |
tree | 38532b4bd5c634c82cb1ae809493bd1eca6a276e /lib | |
parent | eaffee0a867088ace7b07c0c4d7abaf7ef4f91da (diff) | |
download | manatools-a7b02f6cee1153dd46a70323157b301c45065589.tar manatools-a7b02f6cee1153dd46a70323157b301c45065589.tar.gz manatools-a7b02f6cee1153dd46a70323157b301c45065589.tar.bz2 manatools-a7b02f6cee1153dd46a70323157b301c45065589.tar.xz manatools-a7b02f6cee1153dd46a70323157b301c45065589.zip |
added dont_ask_again option to interactive_msg
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AdminPanel/rpmdragora.pm | 111 |
1 files changed, 88 insertions, 23 deletions
diff --git a/lib/AdminPanel/rpmdragora.pm b/lib/AdminPanel/rpmdragora.pm index 7896214f..c5f0f6c8 100644 --- a/lib/AdminPanel/rpmdragora.pm +++ b/lib/AdminPanel/rpmdragora.pm @@ -259,51 +259,116 @@ sub getbanner() { # Gtk2::Banner->new($ugtk2::wm_icon, $::MODE eq 'update' ? $loc->N("Software Packages Update") : $loc->N("Software Management")); } -# return value: -# - undef if if closed (aka really canceled) -# - 0 if if No/Cancel -# - 1 if if Yes/Ok + +#============================================================= + +=head2 interactive_msg + +=head3 INPUT + + $title: dialog title + $contents: dialog text + %options: optional HASH containing { + scroll => Rich Text with scroll bar used + yesno => dialog with "yes" and "no" buttons (deafult yes) + dont_ask_again => add a checkbox with "dont ask again text" + } + +=head3 OUTPUT + + retval: if dont_ask_again HASH reference containig { + value => 1 yes (or ok) pressed, 0 no pressed + dont_ask_again => 1 if checked + } + or if dont_ask_again is not passed: + 1 yes (or ok) pressed, 0 no pressed + +=head3 DESCRIPTION + + This function shows a dialog with contents text and return the button + pressed (1 ok or yes), optionally returns the checkbox value if dont_ask_again is + passed + +=cut + +#============================================================= sub interactive_msg { my ($title, $contents, %options) = @_; my $retVal = 0; - yui::YUI::widgetFactory; - my $factory = yui::YExternalWidgets::externalWidgetFactory("mga"); - $factory = yui::YMGAWidgetFactory::getYMGAWidgetFactory($factory); my $info; - $info->{title} = $title; if ($options{scroll}) { - $info->{richtext} = 1; ## richtext needs <br> instead of '\n' $contents =~ s/\n/<br>/g; } - $info->{text} = $contents; + my $oldTitle = yui::YUI::app()->applicationTitle(); + yui::YUI::app()->setApplicationTitle($title); - my $dlg; + my $factory = yui::YUI::widgetFactory; + my $dlg = $factory->createPopupDialog(); + my $minSize = $factory->createMinSize( $dlg, 75, 6); + my $vbox = $factory->createVBox( $minSize ); + my $midhbox = $factory->createHBox($vbox); + ## app description + my $toprightvbox = $factory->createVBox($midhbox); + $toprightvbox->setWeight($yui::YD_HORIZ, 5); + $factory->createSpacing($toprightvbox,$yui::YD_HORIZ, 0, 5.0); + $factory->createRichText($toprightvbox, $contents, !$options{scroll}); + $factory->createSpacing($toprightvbox, $yui::YD_HORIZ, 0, 5.0); + + if ($options{dont_ask_again}){ + my $hbox = $factory->createHBox($vbox); + my $align = $factory->createRight($hbox); + $info->{checkbox} = $factory->createCheckBox($align, $loc->N("Do not ask me next time")); + } + my $bottomhbox = $factory->createHBox($vbox); if ($options{yesno}) { - $dlg = $factory->createDialogBox($yui::YMGAMessageBox::B_TWO); - $dlg->setButtonLabel($options{text}{yes} || $loc->N("Yes"), $yui::YMGAMessageBox::B_ONE); - $dlg->setButtonLabel($options{text}{no} || $loc->N("No"), $yui::YMGAMessageBox::B_TWO); + my $alignRight = $factory->createRight($bottomhbox); + my $buttonBox = $factory->createHBox($alignRight); + + $info->{B1} = $factory->createPushButton($buttonBox, $options{text}{yes} || $loc->N("Yes")); + $info->{B2} = $factory->createPushButton($buttonBox, $options{text}{no} || $loc->N("No")); } else { - $dlg = $factory->createDialogBox($yui::YMGAMessageBox::B_ONE); - $dlg->setButtonLabel($loc->N("Ok"), $yui::YMGAMessageBox::B_ONE ); + $info->{B1} = $factory->createPushButton($bottomhbox, $loc->N("Ok")); } - $dlg->setTitle($info->{title}) if (exists $info->{title}); - my $rt = (exists $info->{richtext}) ? $info->{richtext} : 0; - $dlg->setText($info->{text}, $rt) if (exists $info->{text}); - $dlg->setDefaultButton($yui::YMGAMessageBox::B_ONE); + $dlg->setDefaultButton($info->{B1}); + + while (1) { + my $event = $dlg->waitForEvent(); + my $eventType = $event->eventType(); + #event type checking + if ($eventType == $yui::YEvent::CancelEvent) { + $retVal = 1; ##default value + last; + } + elsif ($eventType == $yui::YEvent::WidgetEvent) { + # widget selected + my $widget = $event->widget(); - $dlg->setMinSize(75, 6); + if ($info->{B1} && $widget == $info->{B1}) { + $retVal = 1; + last; + } + elsif ($info->{B2} && $widget == $info->{B2}) { + last; + } + } + } - $retVal = $dlg->show() == $yui::YMGAMessageBox::B_ONE ? 1 : 0; + if ($info->{checkbox}) { + my $value = $retVal; + $retVal->{value} = $value; + $retVal->{dont_ask_again} = $info->{checkbox}->isChecked(); + } - $dlg = undef; + $dlg->destroy(); + yui::YUI::app()->setApplicationTitle($oldTitle); return $retVal; } |