| 1 | package UI::Dialog::Backend::Zenity; | ||
| 2 | ############################################################################### | ||
| 3 | # Copyright (C) 2004-2016 Kevin C. Krinke <kevin@krinke.ca> | ||
| 4 | # | ||
| 5 | # This library is free software; you can redistribute it and/or | ||
| 6 | # modify it under the terms of the GNU Lesser General Public | ||
| 7 | # License as published by the Free Software Foundation; either | ||
| 8 | # version 2.1 of the License, or (at your option) any later version. | ||
| 9 | # | ||
| 10 | # This library is distributed in the hope that it will be useful, | ||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 13 | # Lesser General Public License for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU Lesser General Public | ||
| 16 | # License along with this library; if not, write to the Free Software | ||
| 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 18 | ############################################################################### | ||
| 19 | 1 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | 1 | ▶ | use FileHandle; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 1 | ▶ | use Cwd qw( abs_path ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 1 | ▶ | use UI::Dialog::Backend; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 26 | use File::Slurp::Unicode; | ||
| 27 | use String::ShellQuote; | ||
| 28 | |||
| 29 | BEGIN { | ||
| 30 | use vars qw( $VERSION @ISA ); | ||
| 31 | @ISA = qw( UI::Dialog::Backend ); | ||
| 32 | $VERSION = '1.14'; | ||
| 33 | } | ||
| 34 | |||
| 35 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 36 | #: Constructor Method | ||
| 37 | #: | ||
| 38 | |||
| 39 | sub new { | ||
| 40 | my $proto = shift(); | ||
| 41 | my $class = ref($proto) || $proto; | ||
| 42 | my $cfg = ((ref($_[0]) eq "HASH") ? $_[0] : (@_) ? { @_ } : {}); | ||
| 43 | my $self = {}; | ||
| 44 | bless($self, $class); | ||
| 45 | $self->{'_state'} = {}; | ||
| 46 | $self->{'_opts'} = {}; | ||
| 47 | |||
| 48 | #: Dynamic path discovery... | ||
| 49 | my $CFG_PATH = $cfg->{'PATH'}; | ||
| 50 | if ($CFG_PATH) { | ||
| 51 | if (ref($CFG_PATH) eq "ARRAY") { | ||
| 52 | $self->{'PATHS'} = $CFG_PATH; | ||
| 53 | } | ||
| 54 | elsif ($CFG_PATH =~ m!:!) { | ||
| 55 | $self->{'PATHS'} = [ split(/:/,$CFG_PATH) ]; | ||
| 56 | } | ||
| 57 | elsif (-d $CFG_PATH) { | ||
| 58 | $self->{'PATHS'} = [ $CFG_PATH ]; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | elsif ($ENV{'PATH'}) { | ||
| 62 | $self->{'PATHS'} = [ split(/:/,$ENV{'PATH'}) ]; | ||
| 63 | } | ||
| 64 | else { | ||
| 65 | $self->{'PATHS'} = ''; | ||
| 66 | } | ||
| 67 | |||
| 68 | $self->{'_opts'}->{'literal'} = $cfg->{'literal'} || 0; | ||
| 69 | $self->{'_opts'}->{'debug'} = $cfg->{'debug'} || undef(); | ||
| 70 | $self->{'_opts'}->{'window-icon'} = $cfg->{'window-icon'} || undef(); | ||
| 71 | $self->{'_opts'}->{'title'} = $cfg->{'title'} || undef(); | ||
| 72 | $self->{'_opts'}->{'width'} = $cfg->{'width'} || 65; | ||
| 73 | $self->{'_opts'}->{'height'} = $cfg->{'height'} || 10; | ||
| 74 | $self->{'_opts'}->{'display'} = $cfg->{'display'} || undef(); | ||
| 75 | $self->{'_opts'}->{'name'} = $cfg->{'name'} || undef(); | ||
| 76 | $self->{'_opts'}->{'class'} = $cfg->{'class'} || undef(); | ||
| 77 | $self->{'_opts'}->{'bin'} = $self->_find_bin('zenity'); | ||
| 78 | $self->{'_opts'}->{'autoclear'} = $cfg->{'autoclear'} || 0; | ||
| 79 | $self->{'_opts'}->{'clearbefore'} = $cfg->{'clearbefore'} || 0; | ||
| 80 | $self->{'_opts'}->{'clearafter'} = $cfg->{'clearafter'} || 0; | ||
| 81 | $self->{'_opts'}->{'beepbin'} = $cfg->{'beepbin'} || $self->_find_bin('beep') || '/usr/bin/beep'; | ||
| 82 | $self->{'_opts'}->{'beepbefore'} = $cfg->{'beepbefore'} || 0; | ||
| 83 | $self->{'_opts'}->{'beepafter'} = $cfg->{'beepafter'} || 0; | ||
| 84 | $self->{'_opts'}->{'callbacks'} = $cfg->{'callbacks'} || undef(); | ||
| 85 | $self->{'_opts'}->{'timeout'} = $cfg->{'timeout'} || 0; | ||
| 86 | $self->{'_opts'}->{'wait'} = $cfg->{'wait'} || 0; | ||
| 87 | unless (-x $self->{'_opts'}->{'bin'}) { | ||
| 88 | croak("the zenity binary could not be found at: ".$self->{'_opts'}->{'bin'}); | ||
| 89 | } | ||
| 90 | |||
| 91 | $self->{'_opts'}->{'trust-input'} = $cfg->{'trust-input'} || 0; | ||
| 92 | |||
| 93 | my $command = $self->{'_opts'}->{'bin'}." --version"; | ||
| 94 | my $version = `$command 2>&1`; | ||
| 95 | chomp( $version ); | ||
| 96 | $self->{'ZENITY_VERSION'} = $version || '1'; | ||
| 97 | |||
| 98 | $self->{'test_mode'} = $cfg->{'test_mode'} if exists $cfg->{'test_mode'}; | ||
| 99 | $self->{'test_mode_result'} = ''; | ||
| 100 | |||
| 101 | return($self); | ||
| 102 | } | ||
| 103 | |||
| 104 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 105 | #: Private Methods | ||
| 106 | #: | ||
| 107 | |||
| 108 | my $SIG_CODE = {}; | ||
| 109 | sub _del_gauge { | ||
| 110 | #: this is beyond self... | ||
| 111 | my $CODE = $SIG_CODE->{$$}; | ||
| 112 | unless (not ref($CODE)) { | ||
| 113 | delete($CODE->{'_GAUGE'}); | ||
| 114 | $CODE->rv('1'); | ||
| 115 | $CODE->rs('null'); | ||
| 116 | $CODE->ra('null'); | ||
| 117 | $SIG_CODE->{$$} = ""; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | sub append_format_base { | ||
| 121 | my ($self,$args,$fmt) = @_; | ||
| 122 | $ENV{'ZENITY_CANCEL'} = '1'; | ||
| 123 | $ENV{'ZENITY_ERROR'} = '254'; | ||
| 124 | $ENV{'ZENITY_ESC'} = '255'; | ||
| 125 | $ENV{'ZENITY_EXTRA'} = '3'; | ||
| 126 | $ENV{'ZENITY_HELP'} = '2'; | ||
| 127 | $ENV{'ZENITY_OK'} = '0'; | ||
| 128 | $fmt = $self->append_format_check($args,$fmt,'window-icon','--window-icon {{window-icon}}'); | ||
| 129 | $fmt = $self->append_format_check($args,$fmt,'width','--width {{width}}'); | ||
| 130 | $fmt = $self->append_format_check($args,$fmt,'height','--height {{height}}'); | ||
| 131 | $fmt = $self->append_format_check($args,$fmt,'display','--display {{display}}'); | ||
| 132 | $fmt = $self->append_format_check($args,$fmt,'name','--name {{name}}'); | ||
| 133 | $fmt = $self->append_format_check($args,$fmt,'class','--class {{class}}'); | ||
| 134 | |||
| 135 | return $fmt; | ||
| 136 | } | ||
| 137 | |||
| 138 | sub _is_bad_version { | ||
| 139 | # my $self = shift(); | ||
| 140 | # my ($d_maj, $d_min, $d_mac) = ( 1, 4, 0 ); | ||
| 141 | # my ($z_maj, $z_min, $z_mac) = ( 0, 0, 0 ); | ||
| 142 | # my $zenity_version = $self->{'ZENITY_VERSION'} || '0.0.0'; | ||
| 143 | # if ( $zenity_version =~ m!^(\d+)\.(\d+)\.(\d+)$! ) { | ||
| 144 | # ($z_maj, $z_min, $z_mac) = ( $1, $2, $3 ); | ||
| 145 | # } | ||
| 146 | # if ( ( $d_maj < $z_maj ) || | ||
| 147 | # ( $d_maj == $z_maj && $d_min < $z_min ) || | ||
| 148 | # ( $d_maj == $z_maj && $d_min == $z_min && $d_mac < $z_mac ) | ||
| 149 | # ) { | ||
| 150 | # return(0); | ||
| 151 | # } | ||
| 152 | return(1); | ||
| 153 | } | ||
| 154 | |||
| 155 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 156 | #: Override Inherited Methods | ||
| 157 | #: | ||
| 158 | |||
| 159 | # May want to override Backend::perform_command(). Not sure. | ||
| 160 | #: run command and return the rv and any text output from stderr | ||
| 161 | sub perform_command { | ||
| 162 | my $self = $_[0]; | ||
| 163 | my $cmnd = $_[1]; | ||
| 164 | if ($self->is_unit_test_mode()) { | ||
| 165 | $self->{'test_mode_result'} = $cmnd; | ||
| 166 | return (0,'test_mode_result'); | ||
| 167 | } | ||
| 168 | $self->_debug("perform_command: ".$cmnd.";"); | ||
| 169 | my $null_dev = $^O =~ /win32/i ? 'NUL:' : '/dev/null'; | ||
| 170 | my $tmp_stderr = $self->gen_tempfile_name(); | ||
| 171 | system($cmnd." 2> $null_dev > ".$tmp_stderr); | ||
| 172 | my $rv = $? >> 8; | ||
| 173 | my $text = read_file($tmp_stderr); | ||
| 174 | unlink($tmp_stderr) if -f $tmp_stderr; | ||
| 175 | $self->_debug("perform_command: stderr=".shell_quote($text),2); | ||
| 176 | return ($rv,$text); | ||
| 177 | } | ||
| 178 | |||
| 179 | |||
| 180 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 181 | #: Public Methods | ||
| 182 | #: | ||
| 183 | |||
| 184 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 185 | #: Ask a binary question (Yes/No) | ||
| 186 | sub question { | ||
| 187 | my $self = shift(); | ||
| 188 | my $caller = (caller(1))[3] || 'main'; | ||
| 189 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 190 | if ($_[0] && $_[0] eq 'caller') { | ||
| 191 | shift(); $caller = shift(); | ||
| 192 | } | ||
| 193 | my $args = $self->_pre($caller,@_); | ||
| 194 | |||
| 195 | my $fmt = $self->prepare_format($args); | ||
| 196 | $fmt = $self->append_format_base($args,$fmt); | ||
| 197 | $fmt = $self->append_format($fmt,'--question --text {{text}}'); | ||
| 198 | my $command = $self->prepare_command | ||
| 199 | ( $args, $fmt, | ||
| 200 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 201 | ); | ||
| 202 | |||
| 203 | my $rv = $self->command_state($command); | ||
| 204 | if ($rv && $rv >= 1) { | ||
| 205 | $self->ra("NO"); | ||
| 206 | $self->rs("NO"); | ||
| 207 | } | ||
| 208 | else { | ||
| 209 | $self->ra("YES"); | ||
| 210 | $self->rs("YES"); | ||
| 211 | } | ||
| 212 | $self->_post($args); | ||
| 213 | return($rv == 0 ? 1 : 0); | ||
| 214 | } | ||
| 215 | #: Zenity doesn't support alternation of the buttons like gdialog et al. | ||
| 216 | #: so here we just wrap for compliance. | ||
| 217 | sub yesno { | ||
| 218 | my $self = shift(); | ||
| 219 | return($self->question('caller',((caller(1))[3]||'main'),@_)); | ||
| 220 | } | ||
| 221 | sub noyes { | ||
| 222 | my $self = shift(); | ||
| 223 | return($self->question('caller',((caller(1))[3]||'main'),@_)); | ||
| 224 | } | ||
| 225 | |||
| 226 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 227 | #: Text entry | ||
| 228 | sub entry { | ||
| 229 | my $self = shift(); | ||
| 230 | my $caller = (caller(1))[3] || 'main'; | ||
| 231 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 232 | if ($_[0] && $_[0] eq 'caller') { | ||
| 233 | shift(); $caller = shift(); | ||
| 234 | } | ||
| 235 | my $args = $self->_pre($caller,@_); | ||
| 236 | |||
| 237 | $args->{'entry'} ||= ($args->{'init'} || $args->{'entry'}); | ||
| 238 | |||
| 239 | my $fmt = $self->prepare_format($args); | ||
| 240 | $fmt = $self->append_format_base($args,$fmt); | ||
| 241 | $fmt = $self->append_format($fmt,'--entry'); | ||
| 242 | $fmt = $self->append_format_check($args,$fmt,'hide-text','--hide-text'); | ||
| 243 | $fmt = $self->append_format_check($args,$fmt,'entry','--entry-text {{entry}}'); | ||
| 244 | $fmt = $self->append_format($fmt,'--text {{text}}'); | ||
| 245 | my $command = $self->prepare_command | ||
| 246 | ( $args, $fmt, | ||
| 247 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 248 | ); | ||
| 249 | |||
| 250 | my ($rv,$text) = $self->command_string($command); | ||
| 251 | $self->_post($args); | ||
| 252 | return($rv == 0 ? $text : 0); | ||
| 253 | } | ||
| 254 | sub inputbox { | ||
| 255 | my $self = shift(); | ||
| 256 | return($self->entry('caller',((caller(1))[3]||'main'),@_)); | ||
| 257 | } | ||
| 258 | sub password { | ||
| 259 | my $self = shift(); | ||
| 260 | return($self->entry('caller',((caller(1))[3]||'main'),@_,'hide-text',1)); | ||
| 261 | } | ||
| 262 | |||
| 263 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 264 | #: Text box | ||
| 265 | sub info { | ||
| 266 | my $self = shift(); | ||
| 267 | my $caller = (caller(1))[3] || 'main'; | ||
| 268 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 269 | if ($_[0] && $_[0] eq 'caller') { | ||
| 270 | shift(); $caller = shift(); | ||
| 271 | } | ||
| 272 | my $args = $self->_pre($caller,@_); | ||
| 273 | |||
| 274 | my $fmt = $self->prepare_format($args); | ||
| 275 | $fmt = $self->append_format_base($args,$fmt); | ||
| 276 | if ($args->{'error'}) { | ||
| 277 | $fmt = $self->append_format($fmt,'--error'); | ||
| 278 | } | ||
| 279 | elsif ($args->{'warning'}) { | ||
| 280 | $fmt = $self->append_format($fmt,'--warning'); | ||
| 281 | } | ||
| 282 | else { | ||
| 283 | $fmt = $self->append_format($fmt,'--info'); | ||
| 284 | } | ||
| 285 | $fmt = $self->append_format($fmt,'--text {{text}}'); | ||
| 286 | my $command = $self->prepare_command | ||
| 287 | ( $args, $fmt, | ||
| 288 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 289 | ); | ||
| 290 | |||
| 291 | my $rv = $self->command_state($command); | ||
| 292 | $self->_post($args); | ||
| 293 | return($rv == 0 ? 1 : 0); | ||
| 294 | } | ||
| 295 | sub infobox { | ||
| 296 | my $self = shift(); | ||
| 297 | return($self->info('caller',((caller(1))[3]||'main'),@_)); | ||
| 298 | } | ||
| 299 | sub msgbox { | ||
| 300 | my $self = shift(); | ||
| 301 | return($self->info('caller',((caller(1))[3]||'main'),@_)); | ||
| 302 | } | ||
| 303 | sub error { | ||
| 304 | my $self = shift(); | ||
| 305 | return($self->info('caller',((caller(1))[3]||'main'),@_,'error',1)); | ||
| 306 | } | ||
| 307 | sub warning { | ||
| 308 | my $self = shift(); | ||
| 309 | return($self->info('caller',((caller(1))[3]||'main'),@_,'warning',1)); | ||
| 310 | } | ||
| 311 | |||
| 312 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 313 | #: File box | ||
| 314 | sub text_info { | ||
| 315 | my $self = shift(); | ||
| 316 | my $caller = (caller(1))[3] || 'main'; | ||
| 317 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 318 | if ($_[0] && $_[0] eq 'caller') { | ||
| 319 | shift(); $caller = shift(); | ||
| 320 | } | ||
| 321 | my $args = $self->_pre($caller,@_); | ||
| 322 | |||
| 323 | my $filename = $args->{'path'} || $args->{'filename'}; | ||
| 324 | my $fmt = $self->prepare_format($args); | ||
| 325 | $fmt = $self->append_format_base($args,$fmt); | ||
| 326 | $fmt = $self->append_format($fmt,'--text-info'); | ||
| 327 | $fmt = $self->append_format_check($args,$fmt,'editable','--editable'); | ||
| 328 | $fmt = $self->append_format($fmt,'--filename {{filename}}'); | ||
| 329 | my $command = $self->prepare_command | ||
| 330 | ( $args, $fmt, | ||
| 331 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 332 | filename => $self->make_kvl($args,$filename) | ||
| 333 | ); | ||
| 334 | |||
| 335 | my ($rv,$text) = $self->command_string($command); | ||
| 336 | $self->_post($args); | ||
| 337 | return($rv == 0 ? $text : 0); | ||
| 338 | } | ||
| 339 | sub textbox { | ||
| 340 | my $self = shift(); | ||
| 341 | return($self->text_info('caller',((caller(1))[3]||'main'),@_)); | ||
| 342 | } | ||
| 343 | sub editbox { | ||
| 344 | my $self = shift(); | ||
| 345 | return($self->text_info('caller',((caller(1))[3]||'main'),@_,'editable',1)); | ||
| 346 | } | ||
| 347 | |||
| 348 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 349 | #: Lists | ||
| 350 | sub list { | ||
| 351 | my $self = shift(); | ||
| 352 | my $caller = (caller(1))[3] || 'main'; | ||
| 353 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 354 | if ($_[0] && $_[0] eq 'caller') { | ||
| 355 | shift(); $caller = shift(); | ||
| 356 | } | ||
| 357 | my $args = $self->_pre($caller,@_); | ||
| 358 | |||
| 359 | my $fmt = $self->prepare_format($args); | ||
| 360 | $fmt = $self->append_format_base($args,$fmt); | ||
| 361 | $fmt = $self->append_format($fmt,'--list'); | ||
| 362 | if ($args->{'checklist'}) { | ||
| 363 | $fmt = $self->append_format($fmt,'--checklist'); | ||
| 364 | } | ||
| 365 | elsif ($args->{'radiolist'}) { | ||
| 366 | $fmt = $self->append_format($fmt,'--radiolist'); | ||
| 367 | } | ||
| 368 | $fmt = $self->append_format($fmt,"--separator '\\n'"); | ||
| 369 | |||
| 370 | if (ref($args->{'list'}) eq "ARRAY") { | ||
| 371 | if ($args->{'checklist'}||$args->{'radiolist'}) { | ||
| 372 | $fmt = $self->append_format($fmt,'--column " " --column " " --column " "'); | ||
| 373 | } else { | ||
| 374 | $fmt = $self->append_format($fmt,'--column " " --column " "'); | ||
| 375 | } | ||
| 376 | while (@{$args->{'list'}}) { | ||
| 377 | my $item = shift(@{$args->{'list'}}); | ||
| 378 | $self->clean_format($args->{'trust-input'},\$item); | ||
| 379 | my $info = shift(@{$args->{'list'}}); | ||
| 380 | if (ref($info) eq "ARRAY") { | ||
| 381 | $self->clean_format($args->{'trust-input'},\$info->[0]); | ||
| 382 | $fmt = $self->append_format($fmt,'"'.(($info->[1]) ? 'TRUE' : 'FALSE').'"'); | ||
| 383 | $fmt = $self->append_format($fmt,'"'.$item.'"'); | ||
| 384 | $fmt = $self->append_format($fmt,'"'.$info->[0].'"'); | ||
| 385 | } | ||
| 386 | else { | ||
| 387 | $self->clean_format($args->{'trust-input'},\$info); | ||
| 388 | $fmt = $self->append_format($fmt,'"'.$item.'"'); | ||
| 389 | $fmt = $self->append_format($fmt,'"'.$info.'"'); | ||
| 390 | } | ||
| 391 | } | ||
| 392 | } else { | ||
| 393 | croak("Programmer error. list argument missing or not an array.") | ||
| 394 | } | ||
| 395 | |||
| 396 | my $command = $self->prepare_command( $args, $fmt ); | ||
| 397 | |||
| 398 | if ($args->{'checklist'}) { | ||
| 399 | my ($rv,$selected) = $self->command_array($command); | ||
| 400 | $self->_post($args); | ||
| 401 | return($rv == 0 ? $selected : 0) unless defined wantarray and wantarray; | ||
| 402 | return($rv == 0 ? $self->ra() : (0)); | ||
| 403 | } | ||
| 404 | my ($rv,$selected) = $self->command_string($command); | ||
| 405 | $self->_post($args); | ||
| 406 | return($rv == 0 ? $selected : 0); | ||
| 407 | } | ||
| 408 | sub menu { | ||
| 409 | my $self = shift(); | ||
| 410 | return($self->list('caller',((caller(1))[3]||'main'),@_)); | ||
| 411 | } | ||
| 412 | sub checklist { | ||
| 413 | my $self = shift(); | ||
| 414 | return($self->list('caller',((caller(1))[3]||'main'),@_,'checklist',1)); | ||
| 415 | } | ||
| 416 | sub radiolist { | ||
| 417 | my $self = shift(); | ||
| 418 | return($self->list('caller',((caller(1))[3]||'main'),@_,'radiolist',1)); | ||
| 419 | } | ||
| 420 | |||
| 421 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 422 | #: file select | ||
| 423 | sub fselect { | ||
| 424 | my $self = shift(); | ||
| 425 | my $caller = (caller(1))[3] || 'main'; | ||
| 426 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 427 | if ($_[0] && $_[0] eq 'caller') { | ||
| 428 | shift(); $caller = shift(); | ||
| 429 | } | ||
| 430 | my $args = $self->_pre($caller,@_); | ||
| 431 | |||
| 432 | my $filename = $args->{'path'} || $args->{'filename'} || abs_path(); | ||
| 433 | $args->{'path'} = $filename; | ||
| 434 | $args->{'path'} = (-d $args->{'path'}) ? $args->{'path'}."/" : $args->{'path'}; | ||
| 435 | $args->{'path'} =~ s!/+!/!g; | ||
| 436 | |||
| 437 | my $fmt = $self->prepare_format($args); | ||
| 438 | $fmt = $self->append_format_base($args,$fmt); | ||
| 439 | $fmt = $self->append_format($fmt,'--file-selection'); | ||
| 440 | $fmt = $self->append_format($fmt,'--filename {{filename}}'); | ||
| 441 | my $command = $self->prepare_command | ||
| 442 | ( $args, $fmt, | ||
| 443 | filename => $self->make_kvl($args,$filename) | ||
| 444 | ); | ||
| 445 | |||
| 446 | $self->_debug("fselect: ".$args->{'path'}); | ||
| 447 | my ($rv,$file) = $self->command_string($command); | ||
| 448 | $self->_post($args); | ||
| 449 | return($rv == 0 ? $file : 0); | ||
| 450 | } | ||
| 451 | |||
| 452 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 453 | #: directory select | ||
| 454 | sub dselect { | ||
| 455 | my $self = shift(); | ||
| 456 | my $caller = (caller(1))[3] || 'main'; | ||
| 457 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 458 | if ($_[0] && $_[0] eq 'caller') { | ||
| 459 | shift(); $caller = shift(); | ||
| 460 | } | ||
| 461 | my $args = $self->_pre($caller,@_); | ||
| 462 | |||
| 463 | my $filename = $args->{'path'} || $args->{'filename'} || abs_path(); | ||
| 464 | $args->{'path'} = $filename; | ||
| 465 | $args->{'path'} = (-d $args->{'path'}) ? $args->{'path'}."/" : $args->{'path'}; | ||
| 466 | $args->{'path'} =~ s!/+!/!g; | ||
| 467 | |||
| 468 | my $fmt = $self->prepare_format($args); | ||
| 469 | $fmt = $self->append_format_base($args,$fmt); | ||
| 470 | $fmt = $self->append_format($fmt,'--file-selection --directory'); | ||
| 471 | $fmt = $self->append_format($fmt,'--filename {{filename}}'); | ||
| 472 | my $command = $self->prepare_command | ||
| 473 | ( $args, $fmt, | ||
| 474 | filename => $self->make_kvl($args,$filename) | ||
| 475 | ); | ||
| 476 | |||
| 477 | $self->_debug("fselect: ".$args->{'path'}); | ||
| 478 | my ($rv,$file) = $self->command_string($command); | ||
| 479 | $self->_post($args); | ||
| 480 | return($rv == 0 ? $file : 0); | ||
| 481 | } | ||
| 482 | |||
| 483 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 484 | #: calendar | ||
| 485 | sub calendar { | ||
| 486 | my $self = shift(); | ||
| 487 | my $caller = (caller(1))[3] || 'main'; | ||
| 488 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 489 | if ($_[0] && $_[0] eq 'caller') { | ||
| 490 | shift(); $caller = shift(); | ||
| 491 | } | ||
| 492 | my $args = $self->_pre($caller,@_); | ||
| 493 | |||
| 494 | my $fmt = $self->prepare_format($args); | ||
| 495 | $fmt = $self->append_format_base($args,$fmt); | ||
| 496 | $fmt = $self->append_format($fmt,'--calendar'); | ||
| 497 | $fmt = $self->append_format_check($args,$fmt,'text','--text {{text}}'); | ||
| 498 | $fmt = $self->append_format_check($args,$fmt,'date-format','--date-format {{date-format}}'); | ||
| 499 | $fmt = $self->append_format_check($args,$fmt,'day','--day {{day}}'); | ||
| 500 | $fmt = $self->append_format_check($args,$fmt,'month','--month {{month}}'); | ||
| 501 | $fmt = $self->append_format_check($args,$fmt,'year','--year {{year}}'); | ||
| 502 | my $command = $self->prepare_command | ||
| 503 | ( $args, $fmt, | ||
| 504 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 505 | ); | ||
| 506 | |||
| 507 | my ($rv,$date) = $self->command_string($command); | ||
| 508 | if ($rv == 0) { | ||
| 509 | $self->ra(split(m!/!,$date)); | ||
| 510 | } | ||
| 511 | $self->_post($args); | ||
| 512 | return($rv == 0 ? $date : 0); | ||
| 513 | } | ||
| 514 | |||
| 515 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 516 | #: progress | ||
| 517 | |||
| 518 | sub gauge_start { | ||
| 519 | my $self = shift(); | ||
| 520 | my $caller = (caller(1))[3] || 'main'; | ||
| 521 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 522 | if ($_[0] && $_[0] eq 'caller') { | ||
| 523 | shift(); $caller = shift(); | ||
| 524 | } | ||
| 525 | my $args = $self->_pre($caller,@_); | ||
| 526 | |||
| 527 | $self->{'_GAUGE'} ||= {}; | ||
| 528 | $self->{'_GAUGE'}->{'ARGS'} = $args; | ||
| 529 | |||
| 530 | if (defined $self->{'_GAUGE'}->{'FH'}) { | ||
| 531 | $self->rv(129); | ||
| 532 | $self->_post($args); | ||
| 533 | return(0); | ||
| 534 | } | ||
| 535 | |||
| 536 | my $fmt = $self->prepare_format($args); | ||
| 537 | $fmt = $self->append_format_base($args,$fmt); | ||
| 538 | $fmt = $self->append_format($fmt,'--progress'); | ||
| 539 | $fmt = $self->append_format_check($args,$fmt,'pulsate','--pulsate'); | ||
| 540 | $fmt = $self->append_format_check($args,$fmt,'text','--text {{text}}'); | ||
| 541 | $fmt = $self->append_format($fmt,'--percentage {{percentage}}'); | ||
| 542 | my $command = $self->prepare_command | ||
| 543 | ( $args, $fmt, | ||
| 544 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 545 | percentage => $self->make_kvl($args,$args->{'percentage'}||'0'), | ||
| 546 | ); | ||
| 547 | |||
| 548 | $self->{'_GAUGE'}->{'PERCENT'} = ($args->{'percentage'} || '0'); | ||
| 549 | $self->{'_GAUGE'}->{'FH'} = new FileHandle; | ||
| 550 | $self->{'_GAUGE'}->{'FH'}->open("| $command"); | ||
| 551 | my $rv = ($? >> 8); | ||
| 552 | $self->{'_GAUGE'}->{'FH'}->autoflush(1); | ||
| 553 | $self->rv($rv||'null'); | ||
| 554 | $self->ra('null'); | ||
| 555 | $self->rs('null'); | ||
| 556 | return($rv == 0 ? 1 : 0); | ||
| 557 | } | ||
| 558 | sub gauge_inc { | ||
| 559 | my $self = $_[0]; | ||
| 560 | my $incr = $_[1] || 1; | ||
| 561 | |||
| 562 | return(0) unless defined $self->{'_GAUGE'}->{'FH'}; | ||
| 563 | |||
| 564 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 565 | $self->{'_GAUGE'}->{'PERCENT'} += $incr; | ||
| 566 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 567 | print $fh $self->{'_GAUGE'}->{'PERCENT'}."\n"; | ||
| 568 | return(((defined $self->{'_GAUGE'}->{'FH'}) ? 1 : 0)); | ||
| 569 | } | ||
| 570 | sub gauge_dec { | ||
| 571 | my $self = $_[0]; | ||
| 572 | my $decr = $_[1] || 1; | ||
| 573 | |||
| 574 | return(0) unless defined $self->{'_GAUGE'}->{'FH'}; | ||
| 575 | |||
| 576 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 577 | $self->{'_GAUGE'}->{'PERCENT'} -= $decr; | ||
| 578 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 579 | print $fh $self->{'_GAUGE'}->{'PERCENT'}."\n"; | ||
| 580 | return(((defined $self->{'_GAUGE'}->{'FH'}) ? 1 : 0)); | ||
| 581 | } | ||
| 582 | sub gauge_set { | ||
| 583 | my $self = $_[0]; | ||
| 584 | my $perc = $_[1] || $self->{'_GAUGE'}->{'PERCENT'} || 1; | ||
| 585 | |||
| 586 | return(0) unless $self->{'_GAUGE'}->{'FH'}; | ||
| 587 | |||
| 588 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 589 | $self->{'_GAUGE'}->{'PERCENT'} = $perc; | ||
| 590 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 591 | print $fh $self->{'_GAUGE'}->{'PERCENT'}."\n"; | ||
| 592 | return(((defined $self->{'_GAUGE'}->{'FH'}) ? 1 : 0)); | ||
| 593 | } | ||
| 594 | #: Textual updates are not supported by Zenity... | ||
| 595 | sub gauge_text { | ||
| 596 | my $self = $_[0]; | ||
| 597 | my $mesg = $_[1] || return(0); | ||
| 598 | |||
| 599 | my $fh = $self->{'_GAUGE'}; | ||
| 600 | return(0) unless $self->{'_GAUGE'}; | ||
| 601 | |||
| 602 | # $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 603 | # print $fh "\nXXX\n\n".$mesg."\n\nXXX\n\n".$self->{'_GAUGE'}->{'PERCENT'}."\n"; | ||
| 604 | return(((defined $self->{'_GAUGE'}) ? 1 : 0)); | ||
| 605 | } | ||
| 606 | sub gauge_stop { | ||
| 607 | my $self = $_[0]; | ||
| 608 | my $args = $self->{'_GUAGE'}->{'ARGS'} || | ||
| 609 | $self->_merge_attrs( title => 'gauge_stop', | ||
| 610 | 'caller' => ((caller(1))[3]||'main') ); | ||
| 611 | |||
| 612 | unless ($self->{'_GAUGE'}->{'FH'}) { | ||
| 613 | $self->rv(129); | ||
| 614 | $self->_post($args); | ||
| 615 | return(0); | ||
| 616 | } | ||
| 617 | |||
| 618 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 619 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 620 | $self->{'_GAUGE'}->{'FH'}->close(); | ||
| 621 | delete($self->{'_GAUGE'}->{'ARGS'}); | ||
| 622 | delete($self->{'_GAUGE'}->{'FH'}); | ||
| 623 | delete($self->{'_GAUGE'}->{'PERCENT'}); | ||
| 624 | delete($self->{'_GAUGE'}); | ||
| 625 | $self->rv('null'); | ||
| 626 | $self->rs('null'); | ||
| 627 | $self->ra('null'); | ||
| 628 | $self->_post($args); | ||
| 629 | return(1); | ||
| 630 | } | ||
| 631 | |||
| 632 | 1; | ||
| 633 | |||