3
# gdialog -> zenity conversion wrapper
5
# by Mike Newman <mikegtn@gnome.org>
7
# This is all, of course, horrible - but it should translate
8
# most commond gdialog types to zenity equivalents. It will mostly drop
9
# the pointless and unused (even by gdialog!) size arguments
10
# but hopefully will translate all the others.
12
# For testing purposes, I've used a couple of the nautilus scripts
13
# available at http://g-scripts.sourceforge.net - what is sometimes
14
# unclear is what is a gdialog/zenity translation problem, and what is
15
# a problem with the original script
17
my @command = ("zenity"); # the command line we build up to execute
18
my $element = ""; # current bit of command line
19
my $argn = 0; # counter for walking args
20
my $args = $#ARGV + 1; # total number of command line arguments
21
my $separator = 0; # set if --separate-output is in use
24
# Additon by: Kevin C. Krinke (kck) <kckrinke@opendoorsoftware.com>
26
# gdialog itself supports both the X-Windows interface as well as a console
27
# interface. Here's a fix to use regular dialog when appropriate.
28
# This should probably be a more advanced test of some sort, but I don't know
29
# of any other easy way of detecting and X-Windows environment. If someone does
30
# know better, please let me know. So for now this works: "no DISPLAY; no X".
32
unless (defined $ENV{'DISPLAY'} && length($ENV{'DISPLAY'})) {
34
# reset the command string
38
# examine all the available/default paths
40
my $PATHS = ($ENV{'PATH'}||'/bin:/usr/bin:/usr/local/bin:/opt/bin');
42
BIN: foreach my $PATH (split(/\:/,$PATHS)) {
44
if (-x $PATH."/gdialog.real") {
46
# Some GNU/Linux distributions divert binaries when
47
# other packages are installed. If this exists, chances
48
# are it's the real gdialog and not the Zenity wrapper.
49
# gdialog has full support for the Console medium and
50
# as such is the preference over using the "regular"
53
@command = ($PATH."/gdialog.real");
56
} elsif (-x $PATH."/dialog") {
58
# change the command and skip ahead!
60
@command = ($PATH."/dialog");
70
# we didn't find the dialog binary, exit(254) with a message
73
print STDERR "missing DISPLAY and a console dialog could".
76
# exit code 254 is used because 255, 1, 2, 3 are used by Zenity
77
# and cDialog. This error, is a very _bad_ error so it's semi-
78
# non-standard at 254.
84
# all is well if we've made it this far
86
# so join the arguments double-quoting things so that proper shell
91
# and fork the process
97
# Got DISPLAY, has X continue as normal...
98
# End Addtition by: KCK
100
# this just loads the current arg into $element
103
$element = $ARGV[$argn];
106
# walk the command line
108
ARG: while ($argn < $args) {
112
# Informational stuff
114
if ($element eq "--help" || $element eq "--about") {
115
print ( "gdialog is a compatibility wrapper around zenity, " .
116
"provided to hopefully\nallow older scripts to run. " .
117
"If you are reading this message, you should\n" .
118
"probably be using zenity directly\n\n" .
119
"type: 'zenity --help' or 'man zenity' for more information\n");
123
# Section 1 : Args which gdialog expects BEFORE box options
124
# --clear, --backtitle have no obvious effect - ignored
126
if ($element eq "--title") {
128
# --title argument is almost analogous in gdialog and
129
# zenity - so pass it almost entirely as is
133
push @command, "--title=$element";
135
# keep processing args
140
if ($element eq "--separate-output") {
142
# set the flag to pring list output line by line
145
# keep processing args
150
# Section 2 : Box Options and subsequent args
152
if ($element eq "--msgbox" || $element eq "--infobox") {
154
# This bit is common to almost all of the dialogs
155
# the arg following the dialog type in gdialog is usually
156
# equivalent to zenity's --text arg.
160
push @command, "--info", "--text=$element";
162
# this also happens a lot - gdialog accepted size args
163
# for dialog compatability - which it pretty much ignored
164
# and we will do the same
170
if ($element eq "--yesno") {
172
# this will silently ignore the gdialog option to set
173
# the default button in question dialogs - which is
174
# highly hig-norant anyway!
178
push @command, "--question", "--text=$element";
182
if ($element eq "--inputbox") {
185
push @command, "--entry", "--text=$element";
187
# ignore size elements and maybe there is some
188
# default text to initialize the entry with?
192
push @command, "--entry-text=$element";
196
if ($element eq "--textbox") {
197
push @command, "--text-info";
199
# the arg immediately following the dialog type in
200
# gdialog is the filename, so pass this to zenity
204
push @command, "--filename=$element";
206
# width and height matter for this one, so get them
207
# and apply the same multipliers as used in gdialog
211
$element = $element * 7;
212
push @command, "--height=$element";
215
$element = $element * 8;
216
push @command, "--width=$element";
220
if ($element eq "--checklist" || $element eq "--radiolist") {
225
# Conveniently, zenity and gdialog use the same names
226
# for list types, so pass this to zenity intact along with
227
# an untitled column for the check or radio buttons
228
# and the 'text' arg as a second column header
230
push @command, "--list", $list, "--column=''", "--column=''", "--column", $element;
232
# should output be line by line?
234
push @command, "--separator=\n";
237
# Skip to the first 'item' arg of the list content
238
# bypassing height, width and list-height
239
# from here args run [tag] [item] [status] ...
243
# Loop over the remainder of the commandline
244
# discarding the 'status' args of each item
245
# and using the 'item' for display in our second column
246
# also pass a fake NULL argument since zenity can't set
247
# the status of a row like gdialog can
249
while ($argn < $args) {
251
push @command, "NULL", $element;
254
push @command, $element;
260
if ($element eq "--menu") {
265
# a gdialog --menu is just a two column zenity --list
266
# Leave the first column blank (not provided)
267
# Use the 'text' arg as a second column header
268
# FIXME: or should it be the dialog text, or both?
270
push @command, "--list", "--column", "", "--column", $element;
272
# Skip to the first 'item' arg of the list content
273
# after using height, width and bypassing list-height
274
# from here args run [tag] [item] ...
279
# Height and width in characters to be displayed, so adjust
280
# cdialog uses 6 height for non-list, zenity uses ~24 pixels
281
# per list entry (default font), and 103 pixels for non-list
282
# This appears to be almost exact
283
$element = $element*24 - 35;
284
push @command, "--height", $element;
288
# cdialog uses 6 width for non-list, zenity uses ~7 pixels
289
# per character (default font), and 22 pixels for non-list
290
# This is not exact, but close enough
291
$element = $element*7 - 20;
292
push @command, "--width", $element;
296
# Loop over the remainder of the commandline
297
# keeping 'tag' args of each item (required to return)
298
# and using the 'item' for display in our second column
300
while ($argn < $args) {
302
push @command, $element;
308
if ($element eq "--gauge") {
311
push @command, "--progress", "--text=$element";
313
# discard the size args as usually, and see if
314
# a percentage value was supplied to initialize the
320
push @command, "--percentage=$element";
328
# save STDOUT and STDERR
329
open(ORG_STDOUT, ">&STDOUT");
330
open(ORG_STDERR, ">&STDERR");
332
# redirect STDERR to /dev/null (GTK messages ie:
333
# (zenity:637): Gtk-WARNING **: Unable to locate theme engine in module_path: "mist",)
334
open(STDERR, ">/dev/null");
336
# redirect STDOUT to STDERR (gdialog direct output to STDERR by default)
337
open(STDOUT, ">&ORG_STDERR");
339
# execute the constructed zenity command line
341
# perl doc: The return value of system() is the exit status of the
342
#program as returned by the wait() call. To get the actual exit value
345
my $return = system(@command)/256;
347
# restore STDOUT and STDERR
348
open(STDOUT, ">&ORG_STDOUT");
349
open(STDERR, ">&ORG_STDERR");