2 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
4 # copyright 2002 lmoore@tump.com under the terms of the GNU LGPL.
5 # additions 2005 collective@riseup.net
7 # whiptail has trouble being called in the foo=$(whiptail ...) fashion for
8 # some reason. this is very annoying. this means that we need to use
9 # temporary files to store the answers from the input and list based boxes
10 # and then read the answers into a REPLY variable. that just really
11 # stinks, oh well, that's what you get when you have a weak link
14 # inputBox and passwordBox could be refactored to use a common function
16 test -z "$WIDTH" && WIDTH=0
17 test -z "$HEIGHT" && HEIGHT=0
22 setApplicationTitle() {
36 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
37 `[ "$3" == no ] && echo '--defaultno'` --yesno "$2" $HEIGHT $WIDTH
41 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
42 --msgbox "$2" $HEIGHT $WIDTH
46 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
47 --gauge "$2" $HEIGHT $WIDTH 0
51 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
54 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
55 --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp
57 [ $status = 0 ] && REPLY=$(cat $temp)
62 # Xdialog and {dialog,whiptail} use different mechanism to "qoute" the
63 # values from a checklist. {dialog,whiptail} uses standard double quoting
64 # while Xdialog uses a "/" as the separator. the slash is arguably better,
65 # but the double quoting is more standard. anyway, this function can be
66 # overridden to allow a derived implementation to change it's quoting
67 # mechanism to the standard double-quoting one. it receives two
68 # arguements, the file that has the data and the box type.
73 # this is the base implementation of all the list based boxes, it works
74 # out nicely that way. the real function just passes it's arguments to
75 # this function with an extra argument specifying the actual box that
76 # needs to be rendered.
83 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
86 $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \
87 $box "$text" $HEIGHT $WIDTH 10 \
90 [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box)
97 _DEFAULT="--default-item $1"
101 _genericListBox --menu "$@"
104 ## a menu box with additional help info displayed
105 ## at the bottom of the window when an item is selected
108 _genericListBox --menu "$@"
114 ## a menu box with an addition button 'help'
117 _genericListBox --menu "$@"
124 _genericListBox --checklist "$@"
128 _genericListBox --radiolist "$@"
132 $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH
136 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
139 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
140 --passwordbox "$2" $HEIGHT $WIDTH 2> $temp
142 [ $status = 0 ] && REPLY=$(cat $temp)
148 #########################################################
149 ## begin-item-display style lists
151 ## these lists are built by calling fuctions multiple times.
152 ## this can make it easier to build your list in a loop
165 _menu_labels[$_menu_items]=$1
166 _menu_text[$_menu_items]=$2
167 _menu_status[$_menu_items]=$3 # available only for checklist
168 let "_menu_items += 1"
174 ## menu, checklist, radiolist
178 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
185 echo -ne " $HELP $_DEFAULT "
186 echo -ne " --backtitle '$BACKTITLE' "
187 echo -ne " --title '$_menu_title' "
188 echo -ne " --$boxtype '$_menu_msg' "
189 echo -ne " $HEIGHT $WIDTH 10 "
190 for ((i=0; i < $_menu_items ; i++)); do
191 label=${_menu_labels[$i]}
192 text=${_menu_text[$i]}
193 status=${_menu_status[$i]}
194 echo -ne " $label '$text' $status "
196 ) | xargs $DIALOG 2> $temp
200 [ $status = 0 ] && REPLY=`cat $temp`
206 ####################################################
218 _form_labels[$_form_items]=$1
219 _form_text[$_form_items]=$2
220 let "_form_items += 1"
224 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
227 for ((i=0; i < ${#_form_labels[@]} ; i++)); do
228 label=${_form_labels[$i]}
229 length=`expr length $label`
230 if [ $length -gt $max_length ]; then
234 let "max_length += 2"
238 echo -n -e "--form '$_form_title' 0 0 20"
239 for ((i=0; i < $_form_items ; i++)); do
240 label=${_form_labels[$i]}
241 text=${_form_text[$i]}
242 echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30"
243 let "xpos += _form_gap"
245 ) | xargs $DIALOG 2> $temp
249 ## the exit status is meaningless, it is always 0.
250 ## i can't figure out how to get the exit status of dialog
251 ## if we do "dialog `arg code`" or "dialog $args", then the quotes
252 ## get messed up and dialog won't run.
253 ## if we do "(arg code) | xargs dialog", then the exit status is
254 ## swallowed by xargs. xargs should return different exit status
255 ## depending on the exit status of the command run, but i have
256 ## never been able to get that to work.
260 if [ $status = 0 ]; then