2003-05-19 18:46:03 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
# gdialog -> zenity conversion wrapper
|
|
|
|
#
|
|
|
|
# by Mike Newman <mikegtn@gnome.org>
|
|
|
|
#
|
|
|
|
# This is all, of course, horrible - but it should translate
|
|
|
|
# most commond gdialog types to zenity equivalents. It will drop
|
|
|
|
# the pointless and unused (even by gdialog!) size arguments
|
|
|
|
# but hopefully will pass all the others.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# a problem with the script
|
|
|
|
|
|
|
|
my $command = "zenity "; # the command line we build up to execute
|
|
|
|
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
|
|
|
|
|
|
|
# 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-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;
|
|
|
|
$command .= "--title=\"$element\" ";
|
|
|
|
|
|
|
|
# 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;
|
|
|
|
$command .= "--info --text=\"$element\" ";
|
|
|
|
|
|
|
|
# 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;
|
|
|
|
$command .= "--question --text=\"$element\" ";
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($element eq "--inputbox") {
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
|
|
|
$command .= "--entry --text=\"$element\" ";
|
|
|
|
|
|
|
|
# ignore size elements and maybe there is some
|
|
|
|
# default text to initialize the entry with?
|
|
|
|
|
|
|
|
$argn+=3;
|
|
|
|
get_arg;
|
|
|
|
$command .= "--entry-text=\"$element\" ";
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($element eq "--textbox") {
|
|
|
|
$command .= "--text-info ";
|
|
|
|
|
|
|
|
# the arg immediately following the dialog type in
|
|
|
|
# gdialog is the filename, so pass this to zenity
|
|
|
|
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
|
|
|
$command .= "--filename=\"$element\" ";
|
|
|
|
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
|
|
|
|
|
|
|
$command .= "--list $list --column='' --column $element ";
|
2003-05-23 16:57:16 +00:00
|
|
|
|
|
|
|
# should output be line by line?
|
|
|
|
if ($separator) {
|
|
|
|
$command .= " --separator='\n' ";
|
|
|
|
}
|
|
|
|
|
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-05-20 23:48:12 +00:00
|
|
|
$argn += 5;
|
2003-05-19 18:46:03 +00:00
|
|
|
|
|
|
|
# Loop over the remainder of the commandline
|
|
|
|
# discarding the 'status' and 'tag' 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-05-20 23:48:12 +00:00
|
|
|
$command .= "NULL $element ";
|
2003-05-19 18:46:03 +00:00
|
|
|
$argn += 3;
|
|
|
|
}
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
2003-05-20 23:48:12 +00:00
|
|
|
if ($element eq "--menu") {
|
|
|
|
$list=$element;
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
|
|
|
|
|
|
|
# a gdialog --menu is just a one column zenity --list
|
|
|
|
# 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
|
|
|
|
|
|
|
$command .= "--list --column $element ";
|
|
|
|
|
|
|
|
# Skip to the first 'item' arg of the list content
|
|
|
|
# bypassing height, width and list-height
|
|
|
|
# from here args run [tag] [item] ...
|
|
|
|
|
|
|
|
$argn += 5;
|
|
|
|
|
|
|
|
# Loop over the remainder of the commandline
|
|
|
|
# discarding the 'tag' args of each item
|
|
|
|
# and using the 'item' for display in our second column
|
|
|
|
|
|
|
|
while ($argn < $args) {
|
|
|
|
get_arg;
|
|
|
|
$command .= "$element ";
|
|
|
|
$argn += 2;
|
|
|
|
}
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
2003-05-19 18:46:03 +00:00
|
|
|
if ($element eq "--gauge") {
|
|
|
|
$argn++;
|
|
|
|
get_arg;
|
|
|
|
$command .= "--progress --text=\"$element\" ";
|
|
|
|
|
|
|
|
# discard the size args as usually, and see if
|
|
|
|
# a percentage value was supplied to initialize the
|
|
|
|
# dialog
|
|
|
|
|
|
|
|
$argn += 3;
|
|
|
|
get_arg;
|
|
|
|
if ($element) {
|
|
|
|
$command .= "--percentage=$element ";
|
|
|
|
}
|
|
|
|
last ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
$argn++;
|
|
|
|
}
|
|
|
|
|
|
|
|
# execute the constructed zenity command line
|
2003-05-23 16:57:16 +00:00
|
|
|
$command .= " 2>&1";
|
2003-05-19 18:46:03 +00:00
|
|
|
system($command);
|