2003-05-27 22:00:43 +00:00
|
|
|
#!@PERL@
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
# gdialog -> zenity conversion wrapper
|
|
|
|
#
|
|
|
|
# by Mike Newman <mikegtn@gnome.org>
|
|
|
|
#
|
|
|
|
# This is all, of course, horrible - but it should translate
|
2003-05-27 18:00:56 +00:00
|
|
|
# most commond gdialog types to zenity equivalents. It will mostly drop
|
2003-05-19 18:46:03 +00:00
|
|
|
# the pointless and unused (even by gdialog!) size arguments
|
2003-05-27 18:00:56 +00:00
|
|
|
# but hopefully will translate all the others.
|
2003-05-19 18:46:03 +00:00
|
|
|
#
|
|
|
|
# For testing purposes, I've used a couple of the nautilus scripts
|
|
|
|
# available at http://g-scripts.sourceforge.net - what is sometimes
|
|
|
|
# unclear is what is a gdialog/zenity translation problem, and what is
|
2003-05-27 18:00:56 +00:00
|
|
|
# a problem with the original script
|
2003-05-19 18:46:03 +00:00
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
my @command = ("zenity"); # the command line we build up to execute
|
2003-05-19 18:46:03 +00:00
|
|
|
my $element = ""; # current bit of command line
|
|
|
|
my $argn = 0; # counter for walking args
|
|
|
|
my $args = $#ARGV + 1; # total number of command line arguments
|
2003-05-23 16:57:16 +00:00
|
|
|
my $separator = 0; # set if --separate-output is in use
|
2003-05-19 18:46:03 +00:00
|
|
|
|
2003-06-09 21:35:39 +00:00
|
|
|
|
|
|
|
# Additon by: Kevin C. Krinke (kck) <kckrinke@opendoorsoftware.com>
|
|
|
|
#
|
|
|
|
# gdialog itself supports both the X-Windows interface as well as a console
|
|
|
|
# interface. Here's a fix to use regular dialog when appropriate.
|
|
|
|
# This should probably be a more advanced test of some sort, but I don't know
|
|
|
|
# of any other easy way of detecting and X-Windows environment. If someone does
|
|
|
|
# know better, please let me know. So for now this works: "no DISPLAY; no X".
|
|
|
|
|
|
|
|
unless (defined $ENV{'DISPLAY'} && length($ENV{'DISPLAY'})) {
|
|
|
|
|
|
|
|
# reset the command string
|
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
@command = ();
|
2003-06-09 21:35:39 +00:00
|
|
|
|
|
|
|
# examine all the available/default paths
|
|
|
|
|
|
|
|
my $PATHS = ($ENV{'PATH'}||'/bin:/usr/bin:/usr/local/bin:/opt/bin');
|
|
|
|
|
|
|
|
BIN: foreach my $PATH (split(/\:/,$PATHS)) {
|
|
|
|
|
|
|
|
if (-x $PATH."/gdialog.real") {
|
|
|
|
|
|
|
|
# Some GNU/Linux distributions divert binaries when
|
|
|
|
# other packages are installed. If this exists, chances
|
|
|
|
# are it's the real gdialog and not the Zenity wrapper.
|
|
|
|
# gdialog has full support for the Console medium and
|
|
|
|
# as such is the preference over using the "regular"
|
|
|
|
# dialog interface.
|
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
@command = ($PATH."/gdialog.real");
|
2003-06-09 21:35:39 +00:00
|
|
|
last BIN;
|
|
|
|
|
|
|
|
} elsif (-x $PATH."/dialog") {
|
|
|
|
|
|
|
|
# change the command and skip ahead!
|
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
@command = ($PATH."/dialog");
|
2003-06-09 21:35:39 +00:00
|
|
|
last BIN;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
unless (@command) {
|
2003-06-09 21:35:39 +00:00
|
|
|
|
|
|
|
# we didn't find the dialog binary, exit(254) with a message
|
|
|
|
# to STDERR.
|
|
|
|
|
|
|
|
print STDERR "missing DISPLAY and a console dialog could".
|
|
|
|
" not be found.\n";
|
|
|
|
|
|
|
|
# exit code 254 is used because 255, 1, 2, 3 are used by Zenity
|
|
|
|
# and cDialog. This error, is a very _bad_ error so it's semi-
|
|
|
|
# non-standard at 254.
|
|
|
|
|
|
|
|
exit(254);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# all is well if we've made it this far
|
|
|
|
|
|
|
|
# so join the arguments double-quoting things so that proper shell
|
|
|
|
# notation is saved.
|
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, @ARGV;
|
2003-06-09 21:35:39 +00:00
|
|
|
|
|
|
|
# and fork the process
|
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
exec(@command);
|
2003-06-09 21:35:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Got DISPLAY, has X continue as normal...
|
|
|
|
# End Addtition by: KCK
|
|
|
|
|
2003-05-19 18:46:03 +00:00
|
|
|
# this just loads the current arg into $element
|
|
|
|
|
|
|
|
sub get_arg () {
|
|
|
|
$element = $ARGV[$argn];
|
|
|
|
}
|
|
|
|
|
|
|
|
# walk the command line
|
|
|
|
|
|
|
|
ARG: while ($argn < $args) {
|
|
|
|
|
|
|
|
get_arg;
|
|
|
|
|
2003-06-03 17:28:20 +00:00
|
|
|
# Informational stuff
|
|
|
|
|
|
|
|
if ($element eq "--help" || $element eq "--about") {
|
|
|
|
print ( "gdialog is a compatibility wrapper around zenity, " .
|
|
|
|
"provided to hopefully\nallow older scripts to run. " .
|
|
|
|
"If you are reading this message, you should\n" .
|
|
|
|
"probably be using zenity directly\n\n" .
|
|
|
|
"type: 'zenity --help' or 'man zenity' for more information\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
2003-05-23 16:57:16 +00:00
|
|
|
|
2003-05-24 09:15:50 +00:00
|
|
|
# Section 1 : Args which gdialog expects BEFORE box options
|
|
|
|
# --clear, --backtitle have no obvious effect - ignored
|
2003-05-23 16:57:16 +00:00
|
|
|
|
2003-05-19 18:46:03 +00:00
|
|
|
if ($element eq "--title") {
|
|
|
|
|
|
|
|
# --title argument is almost analogous in gdialog and
|
|
|
|
# zenity - so pass it almost entirely as is
|
|
|
|
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--title=$element";
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
# keep processing args
|
2003-05-23 16:57:16 +00:00
|
|
|
$argn++;
|
|
|
|
next ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($element eq "--separate-output") {
|
|
|
|
|
|
|
|
# set the flag to pring list output line by line
|
|
|
|
$separator = 1;
|
|
|
|
|
|
|
|
# keep processing args
|
|
|
|
$argn++;
|
2003-05-19 18:46:03 +00:00
|
|
|
next ARG;
|
|
|
|
}
|
2003-05-23 16:57:16 +00:00
|
|
|
|
2003-05-24 09:15:50 +00:00
|
|
|
# Section 2 : Box Options and subsequent args
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
if ($element eq "--msgbox" || $element eq "--infobox") {
|
|
|
|
|
|
|
|
# This bit is common to almost all of the dialogs
|
|
|
|
# the arg following the dialog type in gdialog is usually
|
|
|
|
# equivalent to zenity's --text arg.
|
|
|
|
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--info", "--text=$element";
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
# this also happens a lot - gdialog accepted size args
|
|
|
|
# for dialog compatability - which it pretty much ignored
|
|
|
|
# and we will do the same
|
|
|
|
|
|
|
|
$argn+=2;
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($element eq "--yesno") {
|
|
|
|
|
|
|
|
# this will silently ignore the gdialog option to set
|
|
|
|
# the default button in question dialogs - which is
|
|
|
|
# highly hig-norant anyway!
|
|
|
|
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--question", "--text=$element";
|
2003-05-19 18:46:03 +00:00
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($element eq "--inputbox") {
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--entry", "--text=$element";
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
# ignore size elements and maybe there is some
|
|
|
|
# default text to initialize the entry with?
|
|
|
|
|
|
|
|
$argn+=3;
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--entry-text=$element";
|
2003-05-19 18:46:03 +00:00
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($element eq "--textbox") {
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--text-info";
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
# the arg immediately following the dialog type in
|
|
|
|
# gdialog is the filename, so pass this to zenity
|
|
|
|
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--filename=$element";
|
2003-05-27 17:56:51 +00:00
|
|
|
|
|
|
|
# width and height matter for this one, so get them
|
|
|
|
# and apply the same multipliers as used in gdialog
|
|
|
|
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
|
|
|
$element = $element * 7;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--height=$element";
|
2003-05-27 18:05:18 +00:00
|
|
|
$argn++;
|
|
|
|
get_arg;
|
|
|
|
$element = $element * 8;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--width=$element";
|
2003-05-19 18:46:03 +00:00
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($element eq "--checklist" || $element eq "--radiolist") {
|
|
|
|
$list=$element;
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
|
|
|
|
|
|
|
# Conveniently, zenity and gdialog use the same names
|
|
|
|
# for list types, so pass this to zenity intact along with
|
|
|
|
# an untitled column for the check or radio buttons
|
2003-05-20 23:48:12 +00:00
|
|
|
# and the 'text' arg as a second column header
|
2003-05-19 18:46:03 +00:00
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--list", $list, "--column=''", "--column=''", "--column", $element;
|
2003-11-12 01:14:17 +00:00
|
|
|
|
2003-05-23 16:57:16 +00:00
|
|
|
# should output be line by line?
|
|
|
|
if ($separator) {
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--separator=\n";
|
2003-05-23 16:57:16 +00:00
|
|
|
}
|
|
|
|
|
2003-05-20 23:48:12 +00:00
|
|
|
# Skip to the first 'item' arg of the list content
|
|
|
|
# bypassing height, width and list-height
|
|
|
|
# from here args run [tag] [item] [status] ...
|
2003-05-19 18:46:03 +00:00
|
|
|
|
2003-11-12 01:14:17 +00:00
|
|
|
$argn += 4;
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
# Loop over the remainder of the commandline
|
2003-11-12 01:14:17 +00:00
|
|
|
# discarding the 'status' args of each item
|
2003-05-20 23:48:12 +00:00
|
|
|
# and using the 'item' for display in our second column
|
2003-05-24 09:15:50 +00:00
|
|
|
# also pass a fake NULL argument since zenity can't set
|
|
|
|
# the status of a row like gdialog can
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
while ($argn < $args) {
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "NULL", $element;
|
2003-11-12 01:14:17 +00:00
|
|
|
$argn += 1;
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, $element;
|
2003-11-12 01:14:17 +00:00
|
|
|
$argn += 2;
|
2003-05-19 18:46:03 +00:00
|
|
|
}
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
2003-05-20 23:48:12 +00:00
|
|
|
if ($element eq "--menu") {
|
|
|
|
$list=$element;
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
|
|
|
|
2003-09-01 18:44:19 +00:00
|
|
|
# a gdialog --menu is just a two column zenity --list
|
|
|
|
# Leave the first column blank (not provided)
|
2003-05-20 23:48:12 +00:00
|
|
|
# Use the 'text' arg as a second column header
|
2003-05-24 09:15:50 +00:00
|
|
|
# FIXME: or should it be the dialog text, or both?
|
2003-05-20 23:48:12 +00:00
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--list", "--column", "", "--column", $element;
|
2003-05-20 23:48:12 +00:00
|
|
|
|
|
|
|
# Skip to the first 'item' arg of the list content
|
2003-09-01 18:44:19 +00:00
|
|
|
# after using height, width and bypassing list-height
|
2003-05-20 23:48:12 +00:00
|
|
|
# from here args run [tag] [item] ...
|
|
|
|
|
2003-09-01 18:44:19 +00:00
|
|
|
$argn += 1;
|
|
|
|
|
|
|
|
get_arg;
|
|
|
|
# Height and width in characters to be displayed, so adjust
|
|
|
|
# cdialog uses 6 height for non-list, zenity uses ~24 pixels
|
|
|
|
# per list entry (default font), and 103 pixels for non-list
|
|
|
|
# This appears to be almost exact
|
|
|
|
$element = $element*24 - 35;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--height", $element;
|
2003-09-01 18:44:19 +00:00
|
|
|
|
|
|
|
$argn += 1;
|
|
|
|
get_arg;
|
|
|
|
# cdialog uses 6 width for non-list, zenity uses ~7 pixels
|
|
|
|
# per character (default font), and 22 pixels for non-list
|
|
|
|
# This is not exact, but close enough
|
|
|
|
$element = $element*7 - 20;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--width", $element;
|
2003-09-01 18:44:19 +00:00
|
|
|
|
|
|
|
$argn += 2;
|
2003-05-20 23:48:12 +00:00
|
|
|
|
|
|
|
# Loop over the remainder of the commandline
|
2003-09-01 18:44:19 +00:00
|
|
|
# keeping 'tag' args of each item (required to return)
|
2003-05-20 23:48:12 +00:00
|
|
|
# and using the 'item' for display in our second column
|
|
|
|
|
|
|
|
while ($argn < $args) {
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, $element;
|
2003-09-01 18:44:19 +00:00
|
|
|
$argn += 1;
|
2003-05-20 23:48:12 +00:00
|
|
|
}
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
2003-05-19 18:46:03 +00:00
|
|
|
if ($element eq "--gauge") {
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--progress", "--text=$element";
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
# discard the size args as usually, and see if
|
|
|
|
# a percentage value was supplied to initialize the
|
|
|
|
# dialog
|
|
|
|
|
|
|
|
$argn += 3;
|
|
|
|
get_arg;
|
|
|
|
if ($element) {
|
2003-12-01 23:27:45 +00:00
|
|
|
push @command, "--percentage=$element";
|
2003-05-19 18:46:03 +00:00
|
|
|
}
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
$argn++;
|
|
|
|
}
|
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
# save STDOUT and STDERR
|
|
|
|
open(ORG_STDOUT, ">&STDOUT");
|
|
|
|
open(ORG_STDERR, ">&STDERR");
|
|
|
|
|
|
|
|
# redirect STDERR to /dev/null (GTK messages ie:
|
|
|
|
# (zenity:637): Gtk-WARNING **: Unable to locate theme engine in module_path: "mist",)
|
|
|
|
open(STDERR, ">/dev/null");
|
|
|
|
|
|
|
|
# redirect STDOUT to STDERR (gdialog direct output to STDERR by default)
|
|
|
|
open(STDOUT, ">&ORG_STDERR");
|
|
|
|
|
2003-05-19 18:46:03 +00:00
|
|
|
# execute the constructed zenity command line
|
2003-06-29 16:21:12 +00:00
|
|
|
|
|
|
|
# perl doc: The return value of system() is the exit status of the
|
|
|
|
#program as returned by the wait() call. To get the actual exit value
|
|
|
|
# divide by 256.
|
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
my $return = system(@command)/256;
|
|
|
|
|
|
|
|
# restore STDOUT and STDERR
|
|
|
|
open(STDOUT, ">&ORG_STDOUT");
|
|
|
|
open(STDERR, ">&ORG_STDERR");
|
|
|
|
close(ORG_STDOUT);
|
|
|
|
close(ORG_STDERR);
|
2003-06-29 16:21:12 +00:00
|
|
|
|
2003-12-01 23:27:45 +00:00
|
|
|
exit $return;
|