| 1 | package UI::Dialog::Backend::KDialog; | ||
| 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 | use 5.006; | ||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | use Carp; | ||
| 23 | use Cwd qw( abs_path ); | ||
| 24 | use UI::Dialog::Backend; | ||
| 25 | |||
| 26 | BEGIN { | ||
| 27 | use vars qw( $VERSION @ISA ); | ||
| 28 | @ISA = qw( UI::Dialog::Backend ); | ||
| 29 | $VERSION = '1.14'; | ||
| 30 | } | ||
| 31 | |||
| 32 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 33 | #: Constructor Method | ||
| 34 | #: | ||
| 35 | |||
| 36 | sub new { | ||
| 37 | my $proto = shift(); | ||
| 38 | my $class = ref($proto) || $proto; | ||
| 39 | my $cfg = ((ref($_[0]) eq "HASH") ? $_[0] : (@_) ? { @_ } : {}); | ||
| 40 | my $self = {}; | ||
| 41 | bless($self, $class); | ||
| 42 | $self->{'_state'} = {}; | ||
| 43 | $self->{'_opts'} = {}; | ||
| 44 | |||
| 45 | #: Dynamic path discovery... | ||
| 46 | my $CFG_PATH = $cfg->{'PATH'}; | ||
| 47 | if ($CFG_PATH) { | ||
| 48 | if (ref($CFG_PATH) eq "ARRAY") { | ||
| 49 | $self->{'PATHS'} = $CFG_PATH; | ||
| 50 | } | ||
| 51 | elsif ($CFG_PATH =~ m!:!) { | ||
| 52 | $self->{'PATHS'} = [ split(/:/,$CFG_PATH) ]; | ||
| 53 | } | ||
| 54 | elsif (-d $CFG_PATH) { | ||
| 55 | $self->{'PATHS'} = [ $CFG_PATH ]; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | elsif ($ENV{'PATH'}) { | ||
| 59 | $self->{'PATHS'} = [ split(/:/,$ENV{'PATH'}) ]; | ||
| 60 | } | ||
| 61 | else { | ||
| 62 | $self->{'PATHS'} = ''; | ||
| 63 | } | ||
| 64 | |||
| 65 | $self->{'_opts'}->{'literal'} = $cfg->{'literal'} || 0; | ||
| 66 | $self->{'_opts'}->{'callbacks'} = $cfg->{'callbacks'} || undef(); | ||
| 67 | $self->{'_opts'}->{'debug'} = $cfg->{'debug'} || undef(); | ||
| 68 | $self->{'_opts'}->{'caption'} = $cfg->{'caption'} || undef(); | ||
| 69 | $self->{'_opts'}->{'icon'} = $cfg->{'icon'} || undef(); | ||
| 70 | $self->{'_opts'}->{'miniicon'} = $cfg->{'miniicon'} || 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'}->{'bin'} ||= $self->_find_bin('kdialog'); | ||
| 75 | $self->{'_opts'}->{'autoclear'} = $cfg->{'autoclear'} || 0; | ||
| 76 | $self->{'_opts'}->{'clearbefore'} = $cfg->{'clearbefore'} || 0; | ||
| 77 | $self->{'_opts'}->{'clearafter'} = $cfg->{'clearafter'} || 0; | ||
| 78 | $self->{'_opts'}->{'beepbin'} = $cfg->{'beepbin'} || $self->_find_bin('beep') || '/usr/bin/beep'; | ||
| 79 | $self->{'_opts'}->{'beepbefore'} = $cfg->{'beepbefore'} || 0; | ||
| 80 | $self->{'_opts'}->{'beepafter'} = $cfg->{'beepafter'} || 0; | ||
| 81 | $self->{'_opts'}->{'timeout'} = $cfg->{'timeout'} || 0; | ||
| 82 | $self->{'_opts'}->{'wait'} = $cfg->{'wait'} || 0; | ||
| 83 | unless (-x $self->{'_opts'}->{'bin'}) { | ||
| 84 | croak("the kdialog binary could not be found at: ".$self->{'_opts'}->{'bin'}); | ||
| 85 | } | ||
| 86 | |||
| 87 | $self->{'_opts'}->{'trust-input'} = | ||
| 88 | ( exists $cfg->{'trust-input'} | ||
| 89 | && $cfg->{'trust-input'}==1 | ||
| 90 | ) ? 1 : 0; | ||
| 91 | |||
| 92 | return($self); | ||
| 93 | } | ||
| 94 | |||
| 95 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 96 | #: Override Inherited Methods | ||
| 97 | #: | ||
| 98 | |||
| 99 | #: execute a simple command (return the exit code only); | ||
| 100 | sub command_state { | ||
| 101 | my $self = $_[0]; | ||
| 102 | my $cmnd = $_[1]; | ||
| 103 | $self->_debug("command: ".$cmnd,1); | ||
| 104 | system($cmnd . "> /dev/null 2> /dev/null"); | ||
| 105 | my $rv = $? >> 8; | ||
| 106 | $self->_debug("command rv: ".$rv,2); | ||
| 107 | return($rv); | ||
| 108 | } | ||
| 109 | |||
| 110 | #: execute a command and return the exit code and one-line SCALAR | ||
| 111 | sub command_string { | ||
| 112 | my $self = $_[0]; | ||
| 113 | my $cmnd = $_[1]; | ||
| 114 | $self->_debug("command: ".$cmnd,1); | ||
| 115 | chomp(my $text = `$cmnd 2> /dev/null`); | ||
| 116 | my $rv = $? >> 8; | ||
| 117 | $self->_debug("command rs: ".$rv." '".$text."'",2); | ||
| 118 | return($text) unless defined wantarray; | ||
| 119 | return (wantarray) ? ($rv,$text) : $text; | ||
| 120 | } | ||
| 121 | |||
| 122 | #: execute a command and return the exit code and ARRAY of data | ||
| 123 | sub command_array { | ||
| 124 | my $self = $_[0]; | ||
| 125 | my $cmnd = $_[1]; | ||
| 126 | $self->_debug("command: ".$cmnd,1); | ||
| 127 | chomp(my $text = `$cmnd 2> /dev/null`); | ||
| 128 | my $rv = $? >> 8; | ||
| 129 | $self->_debug("command ra: ".$rv." '".$text."'",2); | ||
| 130 | return([split(/\n/,$text)]) unless defined wantarray; | ||
| 131 | return (wantarray) ? ($rv,[split(/\n/,$text)]) : [split(/\n/,$text)]; | ||
| 132 | } | ||
| 133 | |||
| 134 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 135 | #: Private Methods | ||
| 136 | #: | ||
| 137 | |||
| 138 | sub append_format_base { | ||
| 139 | my ($self,$args,$fmt) = @_; | ||
| 140 | $fmt = $self->append_format_check($args,$fmt,'title','--title {{title}}'); | ||
| 141 | $fmt = $self->append_format_check($args,$fmt,'caption','--caption {{caption}}'); | ||
| 142 | $fmt = $self->append_format_check($args,$fmt,'icon','--icon {{icon}}'); | ||
| 143 | $fmt = $self->append_format_check($args,$fmt,'miniicon','--miniicon {{miniicon}}'); | ||
| 144 | if ($self->{'_opts'}->{'force-no-separate-output'}) { | ||
| 145 | delete $args->{'separate-output'}; | ||
| 146 | } | ||
| 147 | else { | ||
| 148 | $fmt = $self->append_format_check($args,$fmt,"separate-output","--separate-output") | ||
| 149 | } | ||
| 150 | return $fmt; | ||
| 151 | } | ||
| 152 | |||
| 153 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 154 | #: Public Methods | ||
| 155 | #: | ||
| 156 | |||
| 157 | |||
| 158 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 159 | #: Ask a binary question (Yes/No) | ||
| 160 | sub yesno { | ||
| 161 | my $self = shift(); | ||
| 162 | my $caller = (caller(1))[3] || 'main'; | ||
| 163 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 164 | if ($_[0] && $_[0] eq 'caller') { | ||
| 165 | shift(); $caller = shift(); | ||
| 166 | } | ||
| 167 | my $args = $self->_pre($caller,@_); | ||
| 168 | |||
| 169 | $args->{'yesno'} ||= "yesno"; | ||
| 170 | |||
| 171 | my $fmt = $self->prepare_format($args); | ||
| 172 | $fmt = $self->append_format_base($args,$fmt); | ||
| 173 | $fmt = $self->append_format($fmt,'--'.$args->{'yesno'}.' {{text}} {{height}} {{width}}'); | ||
| 174 | my $command = $self->prepare_command | ||
| 175 | ( $args, $fmt, | ||
| 176 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 177 | ); | ||
| 178 | |||
| 179 | my $rv = $self->command_state($command); | ||
| 180 | $self->rv($rv||'null'); | ||
| 181 | $self->ra('null'); | ||
| 182 | $self->rs('null'); | ||
| 183 | my $this_rv; | ||
| 184 | if ($rv && $rv >= 1) { | ||
| 185 | $self->ra("NO"); | ||
| 186 | $self->rs("NO"); | ||
| 187 | $this_rv = 0; | ||
| 188 | } | ||
| 189 | else { | ||
| 190 | $self->ra("YES"); | ||
| 191 | $self->rs("YES"); | ||
| 192 | $this_rv = 1; | ||
| 193 | } | ||
| 194 | $self->_post($args); | ||
| 195 | return($this_rv); | ||
| 196 | } | ||
| 197 | sub yesnocancel { | ||
| 198 | my $self = shift(); | ||
| 199 | return($self->yesno('caller',((caller(1))[3]||'main'),@_,'yesno','yesnocancel')); | ||
| 200 | } | ||
| 201 | sub warningyesno { | ||
| 202 | my $self = shift(); | ||
| 203 | return($self->yesno('caller',((caller(1))[3]||'main'),@_,'yesno','warningyesno')); | ||
| 204 | } | ||
| 205 | sub warningyesnocancel { | ||
| 206 | my $self = shift(); | ||
| 207 | return($self->yesno('caller',((caller(1))[3]||'main'),@_,'yesno','warningyesnocancel')); | ||
| 208 | } | ||
| 209 | #: Broken documented "feature" | ||
| 210 | # sub warningcontinuecancel { | ||
| 211 | # my $self = shift(); | ||
| 212 | # return($self->yesno(@_,'yesno','warningcontinuecancel')); | ||
| 213 | # } | ||
| 214 | sub noyes { | ||
| 215 | my $self = shift(); | ||
| 216 | return($self->yesno('caller',((caller(1))[3]||'main'),@_)); | ||
| 217 | } | ||
| 218 | |||
| 219 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 220 | #: Text entry | ||
| 221 | sub inputbox { | ||
| 222 | my $self = shift(); | ||
| 223 | my $caller = (caller(1))[3] || 'main'; | ||
| 224 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 225 | if ($_[0] && $_[0] eq 'caller') { | ||
| 226 | shift(); $caller = shift(); | ||
| 227 | } | ||
| 228 | my $args = $self->_pre($caller,@_); | ||
| 229 | |||
| 230 | $args->{'inputbox'} ||= 'inputbox'; | ||
| 231 | |||
| 232 | my $fmt = $self->prepare_format($args); | ||
| 233 | $fmt = $self->append_format_base($args,$fmt); | ||
| 234 | $fmt = $self->append_format($fmt,'--'.$args->{'inputbox'}.' {{text}} {{entry}}'); | ||
| 235 | my $command = $self->prepare_command | ||
| 236 | ( $args, $fmt, | ||
| 237 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 238 | entry => $self->make_kvl($args,($args->{'init'}||$args->{'entry'})), | ||
| 239 | ); | ||
| 240 | |||
| 241 | my ($rv,$text) = $self->command_string($command); | ||
| 242 | $self->rv($rv||'null'); | ||
| 243 | $self->ra('null'); | ||
| 244 | my $this_rv; | ||
| 245 | if ($rv && $rv >= 1) { | ||
| 246 | $self->rs('null'); | ||
| 247 | $this_rv = 0; | ||
| 248 | } | ||
| 249 | else { | ||
| 250 | $self->ra($text); | ||
| 251 | $self->rs($text); | ||
| 252 | $this_rv = $text; | ||
| 253 | } | ||
| 254 | $self->_post($args); | ||
| 255 | return($this_rv); | ||
| 256 | } | ||
| 257 | sub password { | ||
| 258 | my $self = shift(); | ||
| 259 | return($self->inputbox('caller',((caller(1))[3]||'main'),@_,'inputbox','password')); | ||
| 260 | } | ||
| 261 | |||
| 262 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 263 | #: Text box | ||
| 264 | sub msgbox { | ||
| 265 | my $self = shift(); | ||
| 266 | my $caller = (caller(1))[3] || 'main'; | ||
| 267 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 268 | if ($_[0] && $_[0] eq 'caller') { | ||
| 269 | shift(); $caller = shift(); | ||
| 270 | } | ||
| 271 | my $args = $self->_pre($caller,@_); | ||
| 272 | |||
| 273 | $args->{'msgbox'} ||= 'msgbox'; | ||
| 274 | |||
| 275 | my $fmt = $self->prepare_format($args); | ||
| 276 | $fmt = $self->append_format_base($args,$fmt); | ||
| 277 | $fmt = $self->append_format($fmt,'--'.$args->{'msgbox'}.' {{text}}'); | ||
| 278 | my $command = $self->prepare_command | ||
| 279 | ( $args, $fmt, | ||
| 280 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 281 | ); | ||
| 282 | |||
| 283 | my $rv = $self->command_state($command); | ||
| 284 | $self->rv($rv||'null'); | ||
| 285 | $self->ra('null'); | ||
| 286 | $self->rs('null'); | ||
| 287 | my $this_rv; | ||
| 288 | if ($rv && $rv >= 1) { | ||
| 289 | $this_rv = 0; | ||
| 290 | } | ||
| 291 | else { | ||
| 292 | $this_rv = 1; | ||
| 293 | } | ||
| 294 | $self->_post($args); | ||
| 295 | return($this_rv); | ||
| 296 | } | ||
| 297 | sub error { | ||
| 298 | my $self = shift(); | ||
| 299 | return($self->msgbox('caller',((caller(1))[3]||'main'),@_,'msgbox','error')); | ||
| 300 | } | ||
| 301 | sub sorry { | ||
| 302 | my $self = shift(); | ||
| 303 | return($self->msgbox('caller',((caller(1))[3]||'main'),@_,'msgbox','sorry')); | ||
| 304 | } | ||
| 305 | |||
| 306 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 307 | #: File box | ||
| 308 | sub textbox { | ||
| 309 | my $self = shift(); | ||
| 310 | my $caller = (caller(1))[3] || 'main'; | ||
| 311 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 312 | if ($_[0] && $_[0] eq 'caller') { | ||
| 313 | shift(); $caller = shift(); | ||
| 314 | } | ||
| 315 | my $args = $self->_pre($caller,@_); | ||
| 316 | |||
| 317 | my $fmt = $self->prepare_format($args); | ||
| 318 | $fmt = $self->append_format_base($args,$fmt); | ||
| 319 | $fmt = $self->append_format($fmt,'--textbox'); | ||
| 320 | $fmt = $self->append_format($fmt,'{{path}} {{height}} {{width}}'); | ||
| 321 | my $command = $self->prepare_command | ||
| 322 | ( $args, $fmt, | ||
| 323 | path => $self->make_kvl($args,($args->{'filename'}||$args->{'path'}||'.')), | ||
| 324 | ); | ||
| 325 | |||
| 326 | my ($rv,$text) = $self->command_string($command); | ||
| 327 | $self->rv($rv||'null'); | ||
| 328 | $self->ra('null'); | ||
| 329 | $self->rs('null'); | ||
| 330 | my $this_rv; | ||
| 331 | if ($rv && $rv >= 1) { | ||
| 332 | $this_rv = 0; | ||
| 333 | } | ||
| 334 | else { | ||
| 335 | $this_rv = 1; | ||
| 336 | } | ||
| 337 | $self->_post($args); | ||
| 338 | return($this_rv); | ||
| 339 | } | ||
| 340 | |||
| 341 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 342 | #: a simple menu | ||
| 343 | sub menu { | ||
| 344 | my $self = shift(); | ||
| 345 | my $caller = (caller(1))[3] || 'main'; | ||
| 346 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 347 | if ($_[0] && $_[0] eq 'caller') { | ||
| 348 | shift(); $caller = shift(); | ||
| 349 | } | ||
| 350 | my $args = $self->_pre($caller,@_); | ||
| 351 | |||
| 352 | my $fmt = $self->prepare_format($args); | ||
| 353 | $fmt = $self->append_format_base($args,$fmt); | ||
| 354 | $fmt = $self->append_format($fmt,'--separate-output'); | ||
| 355 | $fmt = $self->append_format($fmt,'--menu'); | ||
| 356 | $fmt = $self->append_format($fmt,'{{text}} {{list}}'); | ||
| 357 | my $command = $self->prepare_command | ||
| 358 | ( $args, $fmt, | ||
| 359 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 360 | ); | ||
| 361 | |||
| 362 | my ($rv,$selected) = $self->command_string($command); | ||
| 363 | $self->rv($rv||'null'); | ||
| 364 | $self->ra('null'); | ||
| 365 | my $this_rv; | ||
| 366 | if ($rv && $rv >= 1) { | ||
| 367 | $self->rs('null'); | ||
| 368 | $this_rv = 0; | ||
| 369 | } | ||
| 370 | else { | ||
| 371 | $self->ra($selected); | ||
| 372 | $self->rs($selected); | ||
| 373 | $this_rv = $selected; | ||
| 374 | } | ||
| 375 | $self->_post($args); | ||
| 376 | return($this_rv); | ||
| 377 | } | ||
| 378 | |||
| 379 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 380 | #: a check list | ||
| 381 | sub checklist { | ||
| 382 | my $self = shift(); | ||
| 383 | my $caller = (caller(1))[3] || 'main'; | ||
| 384 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 385 | if ($_[0] && $_[0] eq 'caller') { | ||
| 386 | shift(); $caller = shift(); | ||
| 387 | } | ||
| 388 | my $args = $self->_pre($caller,@_); | ||
| 389 | |||
| 390 | $args->{'listheight'} = $args->{'menuheight'} | ||
| 391 | if exists $args->{'menuheight'}; | ||
| 392 | |||
| 393 | my $fmt = $self->prepare_format($args); | ||
| 394 | $fmt = $self->append_format_base($args,$fmt); | ||
| 395 | if ($args->{radiolist} == 1) { | ||
| 396 | $fmt = $self->append_format($fmt,'--radiolist'); | ||
| 397 | } | ||
| 398 | else { | ||
| 399 | $fmt = $self->append_format($fmt,'--separate-output'); | ||
| 400 | $fmt = $self->append_format($fmt,'--checklist'); | ||
| 401 | } | ||
| 402 | $fmt = $self->append_format($fmt,'{{text}} {{list}}'); | ||
| 403 | my $command = $self->prepare_command | ||
| 404 | ( $args, $fmt, | ||
| 405 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 406 | ); | ||
| 407 | |||
| 408 | my ($rv,$selected) = $self->command_array($command); | ||
| 409 | $self->rv($rv||'null'); | ||
| 410 | $self->ra('null'); | ||
| 411 | my $this_rv; | ||
| 412 | if ($rv && $rv >= 1) { | ||
| 413 | $self->rs('null'); | ||
| 414 | $this_rv = 0; | ||
| 415 | } | ||
| 416 | else { | ||
| 417 | $self->ra(@$selected); | ||
| 418 | $self->rs(join("\n",@$selected)); | ||
| 419 | $this_rv = $selected; | ||
| 420 | } | ||
| 421 | $self->_post($args); | ||
| 422 | return($this_rv) unless ref($this_rv) eq "ARRAY"; | ||
| 423 | return(@{$this_rv}); | ||
| 424 | } | ||
| 425 | #: a radio button list | ||
| 426 | sub radiolist { | ||
| 427 | my $self = shift(); | ||
| 428 | return($self->checklist('caller',((caller(1))[3]||'main'),@_,'radiolist',1)); | ||
| 429 | } | ||
| 430 | |||
| 431 | |||
| 432 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 433 | #: file select | ||
| 434 | sub fselect { | ||
| 435 | my $self = shift(); | ||
| 436 | my $caller = (caller(1))[3] || 'main'; | ||
| 437 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 438 | if ($_[0] && $_[0] eq 'caller') { | ||
| 439 | shift(); $caller = shift(); | ||
| 440 | } | ||
| 441 | my $args = $self->_pre($caller,@_); | ||
| 442 | |||
| 443 | $args->{'fselect'} ||= 'getopenfilename'; | ||
| 444 | |||
| 445 | my $fmt = $self->prepare_format($args); | ||
| 446 | $fmt = $self->append_format_base($args,$fmt); | ||
| 447 | $fmt = $self->append_format($fmt,'--separate-output'); | ||
| 448 | $fmt = $self->append_format($fmt,'--'.$args->{'fselect'}); | ||
| 449 | if ($args->{'getexistingdirectory'}) { | ||
| 450 | $fmt = $self->append_format($fmt,'{{path}}'); | ||
| 451 | } else { | ||
| 452 | $fmt = $self->append_format($fmt,'{{path}} {{filter}}'); | ||
| 453 | } | ||
| 454 | my $command = $self->prepare_command | ||
| 455 | ( $args, $fmt, | ||
| 456 | path => $self->make_kvl($args,($args->{'path'}||abs_path())), | ||
| 457 | filter => ($args->{'filter'}||'*') | ||
| 458 | ); | ||
| 459 | |||
| 460 | my ($rv,$file) = $self->command_string($command); | ||
| 461 | $self->rv($rv||'null'); | ||
| 462 | $self->ra('null'); | ||
| 463 | my $this_rv; | ||
| 464 | if ($rv && $rv >= 1) { | ||
| 465 | $self->rs('null'); | ||
| 466 | $this_rv = 0; | ||
| 467 | } | ||
| 468 | else { | ||
| 469 | $self->ra($file); | ||
| 470 | $self->rs($file); | ||
| 471 | $this_rv = $file; | ||
| 472 | } | ||
| 473 | $self->_post($args); | ||
| 474 | return($this_rv); | ||
| 475 | } | ||
| 476 | sub getopenfilename { | ||
| 477 | my $self = shift(); | ||
| 478 | return($self->fselect('caller',((caller(1))[3]||'main'),@_,'fselect','getopenfilename')); | ||
| 479 | } | ||
| 480 | sub getsavefilename { | ||
| 481 | my $self = shift(); | ||
| 482 | return($self->fselect('caller',((caller(1))[3]||'main'),@_,'fselect','getsavefilename')); | ||
| 483 | } | ||
| 484 | sub getopenurl { | ||
| 485 | my $self = shift(); | ||
| 486 | return($self->fselect('caller',((caller(1))[3]||'main'),@_,'fselect','getopenurl')); | ||
| 487 | } | ||
| 488 | sub getsaveurl { | ||
| 489 | my $self = shift(); | ||
| 490 | return($self->fselect('caller',((caller(1))[3]||'main'),@_,'fselect','getsaveurl')); | ||
| 491 | } | ||
| 492 | |||
| 493 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 494 | #: directory select | ||
| 495 | sub dselect { | ||
| 496 | my $self = shift(); | ||
| 497 | return($self->fselect('caller',((caller(1))[3]||'main'),@_,'fselect','getexistingdirectory')); | ||
| 498 | } | ||
| 499 | sub getexistingdirectory { | ||
| 500 | my $self = shift(); | ||
| 501 | return($self->fselect('caller',((caller(1))[3]||'main'),@_,'fselect','getexistingdirectory')); | ||
| 502 | } | ||
| 503 | |||
| 504 | |||
| 505 | 1; |