| 1 | package UI::Dialog::GNOME; | ||
| 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 UI::Dialog; | ||
| 24 | |||
| 25 | BEGIN { | ||
| 26 | use vars qw( $VERSION @ISA ); | ||
| 27 | @ISA = qw( UI::Dialog ); | ||
| 28 | $VERSION = '1.14'; | ||
| 29 | } | ||
| 30 | |||
| 31 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 32 | #: Constructor Method | ||
| 33 | #: | ||
| 34 | |||
| 35 | sub new { | ||
| 36 | my $proto = shift(); | ||
| 37 | my $class = ref($proto) || $proto; | ||
| 38 | my $cfg = {@_} || {}; | ||
| 39 | my $self = {}; | ||
| 40 | bless($self, $class); | ||
| 41 | |||
| 42 | $self->{'debug'} = $cfg->{'debug'} || 0; | ||
| 43 | |||
| 44 | #: Dynamic path discovery... | ||
| 45 | my $CFG_PATH = $cfg->{'PATH'}; | ||
| 46 | if ($CFG_PATH) { | ||
| 47 | if (ref($CFG_PATH) eq "ARRAY") { $self->{'PATHS'} = $CFG_PATH; } | ||
| 48 | elsif ($CFG_PATH =~ m!:!) { $self->{'PATHS'} = [ split(/:/,$CFG_PATH) ]; } | ||
| 49 | elsif (-d $CFG_PATH) { $self->{'PATHS'} = [ $CFG_PATH ]; } | ||
| 50 | } elsif ($ENV{'PATH'}) { $self->{'PATHS'} = [ split(/:/,$ENV{'PATH'}) ]; } | ||
| 51 | else { $self->{'PATHS'} = ''; } | ||
| 52 | |||
| 53 | $cfg->{'order'} ||= [ 'zenity', 'xdialog', 'gdialog' ]; | ||
| 54 | |||
| 55 | $self->_debug("ENV->UI_DIALOGS: ".($ENV{'UI_DIALOGS'}||'NULL'),2); | ||
| 56 | $cfg->{'order'} = [ split(/\:/,$ENV{'UI_DIALOGS'}) ] if $ENV{'UI_DIALOGS'}; | ||
| 57 | |||
| 58 | $self->_debug("ENV->UI_DIALOG: ".($ENV{'UI_DIALOG'}||'NULL'),2); | ||
| 59 | unshift(@{$cfg->{'order'}},$ENV{'UI_DIALOG'}) if $ENV{'UI_DIALOG'}; | ||
| 60 | |||
| 61 | $cfg->{'trust-input'} = | ||
| 62 | ( exists $cfg->{'trust-input'} | ||
| 63 | && $cfg->{'trust-input'}==1 | ||
| 64 | ) ? 1 : 0; | ||
| 65 | |||
| 66 | my @opts = (); | ||
| 67 | foreach my $opt (keys(%$cfg)) { push(@opts,$opt,$cfg->{$opt}); } | ||
| 68 | |||
| 69 | foreach my $try (@{$cfg->{'order'}}) { | ||
| 70 | if ($try =~ /^zenity$/i) { | ||
| 71 | $self->_debug("trying zenity",2); | ||
| 72 | if (eval "require UI::Dialog::Backend::Zenity; 1" && $self->_has_variant('zenity')) { | ||
| 73 | require UI::Dialog::Backend::Zenity; | ||
| 74 | $self->{'_ui_dialog'} = new UI::Dialog::Backend::Zenity (@opts); | ||
| 75 | $self->_debug("using zenity",2); | ||
| 76 | last; | ||
| 77 | } else { next; } | ||
| 78 | } elsif ($try =~ /^(?:gdialog|gdialog\.real)$/i) { | ||
| 79 | $self->_debug("trying gdialog",2); | ||
| 80 | if (eval "require UI::Dialog::Backend::GDialog; 1" && ($self->_has_variant('gdialog.real') || | ||
| 81 | $self->_has_variant('gdialog'))) { | ||
| 82 | require UI::Dialog::Backend::GDialog; | ||
| 83 | $self->{'_ui_dialog'} = new UI::Dialog::Backend::GDialog (@opts); | ||
| 84 | $self->_debug("using gdialog",2); | ||
| 85 | last; | ||
| 86 | } else { next; } | ||
| 87 | } elsif ($try =~ /^(?:xdialog|X)$/i) { | ||
| 88 | $self->_debug("trying xdialog",2); | ||
| 89 | if (eval "require UI::Dialog::Backend::XDialog; 1" && $self->_has_variant('Xdialog')) { | ||
| 90 | require UI::Dialog::Backend::XDialog; | ||
| 91 | $self->{'_ui_dialog'} = new UI::Dialog::Backend::XDialog (@opts,'XDIALOG_HIGH_DIALOG_COMPAT',1); | ||
| 92 | $self->_debug("using xdialog",2); | ||
| 93 | last; | ||
| 94 | } else { next; } | ||
| 95 | } else { | ||
| 96 | # we don't know what they're asking for... try UI::Dialog... | ||
| 97 | if (eval "require UI::Dialog; 1") { | ||
| 98 | require UI::Dialog; | ||
| 99 | $self->{'_ui_dialog'} = new UI::Dialog (@opts); | ||
| 100 | $self->_debug(ref($self)." unknown backend: '".$try."', using UI::Dialog instead.",2); | ||
| 101 | last; | ||
| 102 | } else { next; } | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | ref($self->{'_ui_dialog'}) or croak("unable to load suitable backend."); | ||
| 107 | |||
| 108 | return($self); | ||
| 109 | } | ||
| 110 | |||
| 111 | sub editbox { return(shift()->{'_ui_dialog'}->editbox(@_)); } | ||
| 112 | |||
| 113 | 1; |