#!/bin/bash
#PupSnap 4.0
#Copyright 2025 GPL3
#Roger Grider (radky)
#20140621 gettext (vicmz)

export TEXTDOMAIN=pupsnap2
export OUTPUT_CHARSET=UTF-8

[ "`whoami`" != "root" ] && exec sudo -A ${0} ${@}

export VERSION=4.0

APPDIR="/usr/local/PupSnap"
[ ! -d $APPDIR ] && mkdir -p $APPDIR
PREFDIR="$APPDIR/preferences"
[ ! -d $PREFDIR ] && mkdir -p $PREFDIR
[ ! -d $HOME/Pictures ] && mkdir -p $HOME/Pictures
[ ! -d $HOME/Pictures/Screenshots ] && mkdir -p $HOME/Pictures/Screenshots

for g in gtkdialog4 gtkdialog; do [ "`which $g 2>/dev/null`" ] && { GTKDIALOG="$g"; break; } done
export GTKDIALOG

########################################################################
#                                                                      #
# FUNCTIONS                                                            #
#                                                                      #
########################################################################

case "$1" in
#confirmation dialog
-confirm_dialog)
	Xdialog --title PS --no-buttons --infobox "\n     $(gettext 'Update complete')     \n" 0 0 2000
	exit 0
;;

#image-host activity log
-imgur_log)
	[ "`cat $APPDIR/imgur.log 2>/dev/null`" = "" ] && echo "$(gettext 'Log Start Date:') `date +%F`" > $APPDIR/imgur.log
	cat $APPDIR/imgur.log 2>/dev/null | Xdialog --fixed-font --title "$(gettext 'Imgur Activity Log')" --no-cancel --textbox "-" 32 125 &
	exit 0
;;

#image-host log deletion
-imgur_deletelog)
	Xdialog --title "PS" --cancel-label "$(gettext 'No')" --ok-label "$(gettext 'Yes')"  --yesno "\n     $(gettext 'Delete entries in current log?')     \n" 0 0
	if [[ $? == 0 ]]; then
		echo "$(gettext 'Log Start Date:') `date +%F`" > $APPDIR/imgur.log
	fi
	exit 0
;;
esac

#reset default PupSnap configuration
func_reset_config(){
	rm -rf $APPDIR/preferences
	$APPDIR/PupSnap &
}
export -f func_reset_config

#view screenshot
func_screenshot_view(){
	FILETYPE="`echo ${FILETYPE} | tr [:upper:] [:lower:]`"
	if [ -f "$SAVEFOLDER$FILENAME.$FILETYPE" ]; then
		$IMAGEVIEWER "$SAVEFOLDER$FILENAME.$FILETYPE" &
	elif [ -d "$SAVEFOLDER" ]; then
		$FILEMANAGER "$SAVEFOLDER" &
	fi
}
export -f func_screenshot_view

########################################################################
#                                                                      #
# GUI PARAMETERS                                                       #
#                                                                      #
########################################################################

SAVEFOLDER=`cat $PREFDIR/savefolder 2>/dev/null`
[ ! "$SAVEFOLDER" ] && SAVEFOLDER="$HOME/Pictures/Screenshots/" && echo "$SAVEFOLDER" > $PREFDIR/savefolder
ACTION=`cat $PREFDIR/action 2>/dev/null`
[ ! "$ACTION" ] && ACTION="$(gettext 'None')" && echo "$ACTION" > $PREFDIR/action
CURSOR=`cat $PREFDIR/cursor 2>/dev/null`
[ ! "$CURSOR" ] && CURSOR="$(gettext 'Enable')" &&  echo "$CURSOR" > $PREFDIR/cursor
DATE=`cat $PREFDIR/date 2>/dev/null`
[ ! "$DATE" ] && DATE="false" && echo "$DATE" > $PREFDIR/date
DELAY=`cat $PREFDIR/delay 2>/dev/null`
[ ! "$DELAY" ] && DELAY=0 && echo "$DELAY" > $PREFDIR/delay
FILEMANAGER=`cat $PREFDIR/filemanager 2>/dev/null`
if [ ! "$FILEMANAGER" ]; then
	for i in defaultfilemanager roxfiler rox spacefm pcmanfm xfe Thunar emelfm2; do [ "`which $i 2>/dev/null`" ] && { FILEMANAGER="$i"; break; } done
	echo "$FILEMANAGER" > $PREFDIR/filemanager
fi
FILENAME=`cat $PREFDIR/filename 2>/dev/null`
[ ! "$FILENAME" ] && FILENAME="$(gettext 'Screenshot')" && echo "$FILENAME" > $PREFDIR/filename
FILETYPE=`cat $PREFDIR/filetype 2>/dev/null`
[ ! "$FILETYPE" ] && FILETYPE="png" && echo "$FILETYPE" > $PREFDIR/filetype
FULL_CAPTURE=`cat $PREFDIR/full_capture 2>/dev/null`
[ ! "$FULL_CAPTURE" ] && FULL_CAPTURE="true" && echo "$FULL_CAPTURE" > $PREFDIR/full_capture
if [ "$FULL_CAPTURE" = "true" ]; then
	echo "false" > $PREFDIR/region_capture
	echo "false" > $PREFDIR/window_capture
	echo "false" > $PREFDIR/border
fi
HOST=`cat $PREFDIR/image_host 2>/dev/null`
[ ! "$HOST" ] && HOST="false" && echo "$HOST" > $PREFDIR/image_host
IMAGEEDITOR=`cat $PREFDIR/imageeditor 2>/dev/null`
if [ ! "$IMAGEEDITOR" ]; then
	for i in defaultimageeditor mtpaint gimp; do [ "`which $i 2>/dev/null`" ] && { IMAGEEDITOR="$i"; break; } done
	echo "$IMAGEEDITOR" > $PREFDIR/imageeditor
fi
IMAGEVIEWER=`cat $PREFDIR/imageviewer 2>/dev/null`
if [ ! "$IMAGEVIEWER" ]; then
	for i in defaultimageviewer viewnior gpicview fotoxx geeqie gqview gwenview ristretto xnview; do [ "`which $i 2>/dev/null`" ] && { IMAGEVIEWER="$i"; break; } done
	echo "$IMAGEVIEWER" > $PREFDIR/imageviewer
fi
QUALITY=`cat $PREFDIR/quality 2>/dev/null`
[ ! "$QUALITY" ] && QUALITY="false" && echo "$QUALITY" > $PREFDIR/quality
QUALITY_NUM=`cat $PREFDIR/quality_num 2>/dev/null`
[ ! "$QUALITY_NUM" ] && QUALITY_NUM=85 && echo "$QUALITY_NUM" > $PREFDIR/quality_num
SCALE=`cat $PREFDIR/scale 2>/dev/null`
[ ! "$SCALE" ] && SCALE="false" && echo "$SCALE" > $PREFDIR/scale
SCALE_PCT=`cat $PREFDIR/scale_pct 2>/dev/null`
[ ! "$SCALE_PCT" ] && SCALE_PCT="95" && echo "$SCALE_PCT" > $PREFDIR/scale_pct

EDIT_CAPTURE=`cat $PREFDIR/edit_capture 2>/dev/null`
[ ! "$EDIT_CAPTURE" ] && EDIT_CAPTURE="false" && echo "$EDIT_CAPTURE" > $PREFDIR/edit_capture
VIEW_CAPTURE=`cat $PREFDIR/view_capture 2>/dev/null`
[ ! "$VIEW_CAPTURE" ] && VIEW_CAPTURE="true" && echo "$VIEW_CAPTURE" > $PREFDIR/view_capture

export APPDIR PREFDIR SAVEFOLDER DELAY FILEMANAGER IMAGEEDITOR IMAGEVIEWER

#define audio alert (beep confirmation of screenshot)
if [ "`which aplay 2>/dev/null`" ]; then
	BEEP=`cat $PREFDIR/beep 2>/dev/null`
	[ ! "$BEEP" ] && BEEP="false" && echo "$BEEP" > $PREFDIR/beep
	AUDIO_ALERT="<checkbox tooltip-text=\" $(gettext 'Enable beep confirmation of screenshot') \">
				<label>$(gettext 'Audio Alert')  </label>
				<variable>BEEP</variable>
				<input>cat $PREFDIR/beep</input>
				<action>if true echo true > $PREFDIR/beep</action>
				<action>if false echo false > $PREFDIR/beep</action>
			</checkbox>"
else
	AUDIO_ALERT=""
fi

#define combobox width (and GUI width)
[ "$HOST" = "true" ] && CBB_WIDTH="175" || CBB_WIDTH="150"

#define $FILE_TYPE_ITEMS for Format combobox
FILE_TYPE_ITEMS="<item>PNG</item> <item>JPG</item> <item>BMP</item> <item>TIFF</item> <item>WEBP</item>"

#define $IMAGE_QUALITY_ITEMS for Quality combobox
IMAGE_QUALITY_ITEMS="<item>100</item> <item>95</item> <item>90</item> <item>85</item> <item>80</item> <item>75</item> <item>70</item> <item>65</item> <item>60</item> <item>55</item> <item>50</item> <item>45</item> <item>40</item> <item>35</item> <item>30</item> <item>25</item>"

#define $IMAGE_SCALE_ITEMS for Scale combobox
IMAGE_SCALE_ITEMS="<item>95%</item> <item>90%</item> <item>85%</item> <item>80%</item> <item>75%</item> <item>70%</item> <item>65%</item> <item>60%</item> <item>55%</item> <item>50%</item> <item>45%</item> <item>40%</item> <item>35%</item> <item>30%</item> <item>25%</item> <item>800px</item>"

#define $DELAY_ITEMS for Delay combobox
DELAY_ITEMS="<item>0</item> <item>2</item> <item>4</item> <item>6</item> <item>8</item> <item>10</item> <item>15</item> <item>20</item> <item>30</item> <item>40</item> <item>50</item><item>60</item>"

#define $CURSOR_ITEMS for Cursor combobox
CURSOR_ITEMS="<item>$(gettext 'Enable')</item> <item>$(gettext 'Disable')</item>"

#define $ACTION_ITEMS for Action combobox
CLIPBOARD=$(type xclip && LANG=C xclip -help 2>&1 | grep -q -- '-target')
if [ "$CLIPBOARD" ]; then
	CLIPBOARD="<item>$(gettext 'Clipboard')</item>"
	echo true > $PREFDIR/clipboard
else
	CLIPBOARD=""
	echo false > $PREFDIR/clipboard
fi
ACTION_ITEMS="<item>$(gettext 'None')</item> <item>$(gettext 'Editor')</item> <item>$(gettext 'Viewer')</item> $CLIPBOARD"

#define gui-title color
DARK_GTKT_THEME=$(grep 'gtk-theme-name' $HOME/.config/gtk-3.0/settings.ini | grep -Ei 'black|dark|dusk|night')
[ -n "$DARK_GTKT_THEME" ] && COLOR=#84aad9 || COLOR=#3272C0

#define title-bar icon
[ ! -f /usr/share/icons/hicolor/48x48/apps/pupsnap.svg ] && \
ln -snf $APPDIR/icons/pupsnap.svg /usr/share/icons/hicolor/48x48/apps && gtk-update-icon-cache -f -i /usr/share/icons/hicolor 2>/dev/null

########################################################################
#                                                                      #
# IMAGE HOST NOTEBOOK TAB                                              #
#                                                                      #
########################################################################

HOST=`cat $PREFDIR/image_host`
[ "$HOST" = "" ] && echo "true" > $PREFDIR/image_host
if [ "$HOST" = "true" ]; then
	NB_LABEL="<notebook labels=\"  $(gettext  'Screen Capture  |  Image Host')  \">"
	HOST_TAB="
	<vbox space-expand=\"true\" space-fill=\"true\">
	<frame $(gettext 'imgur.com')>
	<vbox space-expand=\"true\" space-fill=\"true\" homogeneous=\"true\">
	<vbox>
		<text><label>\"$(gettext 'Local Image File')\"</label></text>
		<hbox>
			<entry has-focus=\"true\" tooltip-text=\" $(gettext 'Use the Image-file selector or drag 
 and drop image from a filemanager.') \" fs-action=\"newfile\" fs-folder=\""$SAVEFOLDER"\" fs-filters=\"*|*.png|*.jpg|*.jpeg|*.bmp|*.gif|*.tiff|*.pdf|*.xcf|*.webp\" fs-title=\"$(gettext 'Select Image for Upload')\" secondary-icon-stock=\"gtk-add\" secondary-icon-tooltip-text=\" $(gettext 'Upload image file to imgur.com 
 Requirement: enable javascript') \" primary-icon-stock=\"gtk-info\" primary-icon-tooltip-text=\" $(gettext 'Go to imgur.com online FAQ') \">
				<variable>IMAGE_UPLOAD</variable>
				<input>cat $APPDIR/imgur-file</input>
				<action signal=\"primary-icon-release\">defaultbrowser https://help.imgur.com/hc/en-us/sections/200332527-FAQ &</action>
				<action signal=\"secondary-icon-release\">echo \$IMAGE_UPLOAD > $APPDIR/imgur-file</action>
				<action signal=\"secondary-icon-release\">. $APPDIR/imgur</action>
				<action signal=\"secondary-icon-release\">refresh:IMAGE_URL</action>
				<action signal=\"secondary-icon-release\">refresh:SMALLTHUMB_URL</action>
				<action signal=\"secondary-icon-release\">refresh:LARGETHUMB_URL</action>
				<action signal=\"secondary-icon-release\">refresh:DELETE_URL</action>
			</entry>
			<button relief=\"2\" tooltip-text=\" $(gettext 'Image-file selector') \">	
				<input file>$APPDIR/icons/directory20.png</input>
				<action>fileselect:IMAGE_UPLOAD</action>
				<action type=\"clear\">IMAGE_URL</action>
				<action type=\"clear\">SMALLTHUMB_URL</action>
				<action type=\"clear\">LARGETHUMB_URL</action>
				<action type=\"clear\">DELETE_URL</action>
			</button>
		</hbox>
	</vbox>
	<vbox>
		<text><label>\"$(gettext 'Online Image Link')\"</label></text>
		<entry editable=\"false\" tooltip-text=\" $(gettext 'Link to online primary image') \" secondary-icon-stock=\"gtk-find\" secondary-icon-tooltip-text=\" $(gettext 'View image in default browser') \">
			<variable>IMAGE_URL</variable>
			<input>cat /tmp/PS-uploadlink 2>/dev/null</input>
			<action signal=\"secondary-icon-release\">/tmp/PS-browse_uploadlink 2>/dev/null &</action>
		</entry>
	</vbox>
	<vbox>
		<text><label>\"$(gettext 'Small Thumb Link')\"</label></text>
		<entry editable=\"false\" tooltip-text=\" $(gettext 'Link to online small thumb image') \" secondary-icon-stock=\"gtk-find\" secondary-icon-tooltip-text=\" $(gettext 'View image in default browser') \">
			<variable>SMALLTHUMB_URL</variable>
			<input>cat /tmp/PS-smallthumb 2>/dev/null</input>
			<action signal=\"secondary-icon-release\">/tmp/PS-browse_smallthumb 2>/dev/null &</action>
		</entry>
	</vbox>
	<vbox>
		<text><label>\"$(gettext 'Large Thumb Link')\"</label></text>
		<entry editable=\"false\" tooltip-text=\" $(gettext 'Link to online large thumb image') \" secondary-icon-stock=\"gtk-find\" secondary-icon-tooltip-text=\" $(gettext 'View image in default browser') \">
			<variable>LARGETHUMB_URL</variable>
			<input>cat /tmp/PS-largethumb 2>/dev/null</input>
			<action signal=\"secondary-icon-release\">/tmp/PS-browse_largethumb 2>/dev/null &</action>
		</entry>
	</vbox>
	<vbox>
		<text><label>\"$(gettext 'Online Delete Link')\"</label></text>
		<entry editable=\"false\" tooltip-text=\" $(gettext 'Link to delete online image') \" secondary-icon-stock=\"gtk-clear\" secondary-icon-tooltip-text=\" $(gettext 'Go to delete-link in default browser') \">
			<variable>DELETE_URL</variable>
			<input>cat /tmp/PS-deletelink 2>/dev/null</input>
			<action signal=\"secondary-icon-release\">/tmp/PS-browse_deletelink 2>/dev/null &</action>
			<action signal=\"secondary-icon-release\">echo ""$(gettext 'No file selected')"" > $APPDIR/imgur-file</action>
			<action signal=\"secondary-icon-release\">refresh:IMAGE_UPLOAD</action>
			<action signal=\"secondary-icon-release\">clear:IMAGE_URL</action>
			<action signal=\"secondary-icon-release\">clear:DELETE_URL</action>
			<action signal=\"secondary-icon-release\">clear:SMALLTHUMB_URL</action>
			<action signal=\"secondary-icon-release\">clear:LARGETHUMB_URL</action>
			<action signal=\"secondary-icon-release\">rm -f /tmp/PS-* &</action>
		</entry>
	</vbox>
	</vbox>
	</frame>
		<hbox space-expand=\"false\" space-fill=\"true\" homogeneous=\"true\">
			<button height-request=\"35\" use-underline=\"true\" tooltip-text=\" $(gettext 'Go to imgur.com in default browser') \">
				<label>\"$(gettext 'Image _Host')\"</label>
				<action>defaultbrowser https://imgur.com &</action>
			</button>
			<button height-request=\"35\" use-underline=\"true\" tooltip-text=\" $(gettext 'View Imgur activity log') \">
				<label>\"$(gettext '_View Log')\"</label>
				<action>$APPDIR/PupSnap-bin -imgur_log &</action>
			</button>
			<button height-request=\"35\" use-underline=\"true\" tooltip-text=\" $(gettext 'Delete entries in current log') \">
				<label>\"$(gettext '_Delete Log')\"</label>
				<action>$APPDIR/PupSnap-bin -imgur_deletelog &</action>
			</button>
		</hbox>
	</vbox>"
else
 NB_LABEL="<notebook labels=\"   $(gettext 'Screen Capture')   \">"
 HOST_TAB=""
fi

########################################################################
#                                                                      #
# ABOUT DIALOG                                                         #
#                                                                      #
########################################################################

pupsnap_help() {
export PUPSNAP_HELP="
<window title=\"PupSnap Help\" icon-name=\"pupsnap\" window-position=\"3\" resizable=\"false\">
	<vbox margin=\"10\" width-request=\"350\">
	<pixmap><input file>$APPDIR/icons/pupsnap.svg</input><height>80</height><width>80</width></pixmap>
		<vbox margin=\"5\">
		<text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>PupSnap</span> $VERSION</b>\"</label></text>
		<text use-markup=\"true\"><label>\"<b><span size='"'large'"'>Simple Screenshot Tool</span></b>\"</label></text>
		<text use-markup=\"true\"><label>\"<b>$(gettext 'Frontend for scrot &amp; imlib2 library')</b>\"</label></text>
		<text><label>\"Roger D. Grider (C) 2010-2025 GPL3\"</label></text>
		</vbox>
		<hbox space-expand=\"true\" space-fill=\"true\" homogeneous=\"true\">
			<button space-expand=\"false\" space-fill=\"true\">
				<label>\"$(gettext 'Help')\"</label>
				<action>defaulthtmlviewer $APPDIR/Help.html &</action>
			</button>
			<button space-expand=\"false\" space-fill=\"true\" tooltip-text=\" http://www.gnu.org/licenses \">
				<label>\"$(gettext 'License')\"</label>
				<action>defaulthtmlviewer http:\/\/www.gnu.org\/licenses\/ &</action>
			</button>
		</hbox>
	</vbox>
</window>"
gtkdialog -p PUPSNAP_HELP
unset PUPSNAP_HELP
}
export -f pupsnap_help

########################################################################
#                                                                      #
# MAIN DIALOG                                                          #
#                                                                      #
########################################################################

export PUPSNAP_DIALOG="
<window title=\"PS\" icon-name=\"pupsnap\" resizable=\"false\" window-position=\"3\">
	<vbox>
		<hbox margin=\"2\">
			<text width-request=\"75\" space-expand=\"false\" space-fill=\"true\"><label>\" \"</label></text>
			<text space-expand=\"true\" space-fill=\"true\"><label>\" \"</label></text>
			<text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Pup</span><span size='"'x-large'"' color='"$COLOR"'>Snap</span></b>\"</label></text>
			<text space-expand=\"true\" space-fill=\"true\"><label>\" \"</label></text>
			<hbox width-request=\"75\">
				<button relief=\"2\" height-request=\"32\" width-request=\"35\" tooltip-text=\" $(gettext 'Reset default configuration') \"><input file>$APPDIR/icons/refresh.svg</input><height>18</height><width>18</width><action>func_reset_config &</action><action type=\"exit\">quit_now</action></button>
				<button relief=\"2\" height-request=\"32\" width-request=\"35\" tooltip-text=\" $(gettext 'Help') \"><input file>$APPDIR/icons/help.svg</input><height>18</height><width>18</width><action>pupsnap_help &</action></button>
			</hbox>
		</hbox>

		$NB_LABEL

		<vbox>
			<hbox margin=\"2\" space-expand=\"true\" space-fill=\"true\">
				<vbox space-expand=\"true\" space-fill=\"true\">
					<entry height-request=\"35\" space-expand=\"true\" space-fill=\"true\" has-focus=\"true\" tooltip-text=\" $(gettext 'Name for captured image') \" secondary-icon-stock=\"gtk-clear\" secondary-icon-tooltip-text=\" $(gettext 'Clear name') \">
						<variable>FILENAME</variable>
						<input>cat $PREFDIR/filename</input>
						<action>echo "\$FILENAME" > $PREFDIR/filename</action>
						<action signal=\"secondary-icon-release\">clear:FILENAME</action>
						<action signal=\"secondary-icon-release\">echo > $PREFDIR/filename</action>
					</entry>
				</vbox>
				<vbox width-request=\"105\" homogeneous=\"true\" space-expand=\"false\" space-fill=\"false\">
					<hbox homogeneous=\"true\" space-expand=\"false\" space-fill=\"false\">
						<checkbox tooltip-text=\" $(gettext 'Assign current date to image file name') \">
							<label>$(gettext 'Date')</label>
							<variable>DATE</variable>
							<input>cat $PREFDIR/date</input>
							<action>if true echo true > $PREFDIR/date</action>
							<action>if true clear:FILENAME</action>
							<action>if true echo "$(gettext 'Screenshot')_$(date +%F)" > $PREFDIR/filename</action>
							<action>if true refresh:FILENAME</action>
							<action>if false echo false > $PREFDIR/date</action>
							<action>if false clear:FILENAME</action>
							<action>if false echo "$(gettext 'Screenshot')" > $PREFDIR/filename</action>
							<action>if false refresh:FILENAME</action>
						</checkbox>
					</hbox>
				</vbox>
			</hbox>

			<hbox margin=\"2\" space-expand=\"true\" space-fill=\"true\">
				<vbox space-expand=\"true\" space-fill=\"true\">
					<entry height-request=\"35\" space-expand=\"true\" space-fill=\"true\" tooltip-text=\" $(gettext 'Folder for captured image') \" fs-action=\"directory\" fs-folder=\""$SAVEFOLDER"\" fs-title=\"$(gettext 'PupSnap Folder')\">
						<input>cat $PREFDIR/savefolder</input>
						<variable>SAVEFOLDER</variable>
						<action>echo \$SAVEFOLDER\/ | sed -e 's%\/\/$%\/%g' > $PREFDIR/savefolder</action>
					</entry>
				</vbox>
				<vbox space-expand=\"false\" space-fill=\"false\">
					<button relief=\"1\" height-request=\"35\" width-request=\"50\" space-expand=\"false\" space-fill=\"false\" tooltip-text=\" $(gettext 'Folder selector') \">
						<input file>$APPDIR/icons/directory20.png</input>
						<action>fileselect:SAVEFOLDER</action>
						<action>echo \$SAVEFOLDER\/ | sed -e 's%\/\/$%\/%g' > $PREFDIR/savefolder</action>
						<action type=\"refresh\">SAVEFOLDER</action>
					</button>
				</vbox>
				<vbox space-expand=\"false\" space-fill=\"false\">
					<button relief=\"1\" height-request=\"35\" width-request=\"50\" space-expand=\"false\" space-fill=\"false\" tooltip-text=\" $(gettext 'Manage images with') $FILEMANAGER \">
						<input file>$APPDIR/icons/filemanager20.png</input>
						<action>$FILEMANAGER '"$SAVEFOLDER"' &</action>
					</button>
				</vbox>
			</hbox>

			<hbox margin=\"2\" homogeneous=\"true\">
				<vbox>
					<hbox>
						<vbox>
							<text height-request=\"35\"><label>$(gettext 'Format')</label></text>
							<comboboxtext wrap-width=\"1\" width-request=\"$CBB_WIDTH\" tooltip-text=\" $(gettext 'Graphic image format') \">
								<variable>FILETYPE</variable>
								<default>"$FILETYPE"</default>
								$FILE_TYPE_ITEMS
								<action>echo "\$FILETYPE" > $PREFDIR/filetype</action>
							</comboboxtext>
						</vbox>

						<vbox>
							<hbox homogeneous=\"true\">
								<checkbox height-request=\"35\" tooltip-text=\" $(gettext "Set the quality of jpg and webp images. 
 MAX:100  (Default = JPG:85  WEBP:75)") \">
									<label>$(gettext 'Quality')</label>
									<variable>QUALITY</variable>
									<input>cat $PREFDIR/quality</input>
									<action>if true echo true > $PREFDIR/quality</action>
									<action>if true enable:QUALITY_NUM</action>
									<action>if false echo false > $PREFDIR/quality</action>
									<action>if false disable:QUALITY_NUM</action>
								</checkbox>
							</hbox>
							<hbox>
								<comboboxtext wrap-width=\"2\" width-request=\"$CBB_WIDTH\" tooltip-text=\" $(gettext 'The quality option applies only to jpg and webp images. 
 Recommended values of 75-85 render images of small 
 file size and optimal visual quality for web compatibility. 
 N.B. The quality settings do not apply to scaled images.') \">
									<variable>QUALITY_NUM</variable>
									<default>"$QUALITY_NUM"</default>
									$IMAGE_QUALITY_ITEMS
									<action>echo "\$QUALITY_NUM" > $PREFDIR/quality_num</action>
									<sensitive>"${QUALITY}"</sensitive>
								</comboboxtext>
							</hbox>
						</vbox>

						<vbox>
							<hbox homogeneous=\"true\">
								<checkbox height-request=\"35\" tooltip-text=\" $(gettext 'Scale image size') \">
									<label>$(gettext 'Scale (%)')</label>
									<variable>SCALE</variable>
									<input>cat $PREFDIR/scale</input>
									<action>if true echo true > $PREFDIR/scale</action>
									<action>if true enable:SCALE_PCT</action>
									<action>if false echo false > $PREFDIR/scale</action>
									<action>if false disable:SCALE_PCT</action>
								</checkbox>
							</hbox>
							<hbox>
								<comboboxtext wrap-width=\"2\" width-request=\"$CBB_WIDTH\" tooltip-text=\" "$(gettext "Select percent of the original image size (25-95%) 
 or the 800px option to reduce a large screenshot 
 to the 800-pixel width which is forum-compatible.")" \">
									<variable>SCALE_PCT</variable>
									<default>"$SCALE_PCT"</default>
									$IMAGE_SCALE_ITEMS
									<action>echo "\$SCALE_PCT" > $PREFDIR/scale_pct</action>
									<sensitive>"${SCALE}"</sensitive>
								</comboboxtext>
							</hbox>
						</vbox>
					</hbox>

					<hbox>
						<vbox>
							<text height-request=\"35\"><label>$(gettext 'Delay')</label></text>
							<comboboxtext wrap-width=\"1\" width-request=\"$CBB_WIDTH\" tooltip-text=\" $(gettext 'Capture delay in seconds') \">
								<variable>DELAY</variable>
								<default>"$DELAY"</default>
								$DELAY_ITEMS
								<action>echo "\$DELAY" > $PREFDIR/delay</action>
							</comboboxtext>
						</vbox>

						<vbox>
							<text height-request=\"35\"><label>$(gettext 'Cursor')</label></text>
							<comboboxtext wrap-width=\"1\" width-request=\"$CBB_WIDTH\" tooltip-text=\" $(gettext 'Include cursor in captured image') \">
								<variable>CURSOR</variable>
								<default>"$CURSOR"</default>
								$CURSOR_ITEMS
								<action>echo "\$CURSOR" > $PREFDIR/cursor</action>
							</comboboxtext>
						</vbox>

						<vbox>
							<text height-request=\"35\"><label>$(gettext 'Action')</label></text>
							<comboboxtext wrap-width=\"1\" width-request=\"$CBB_WIDTH\" tooltip-text=\" $(gettext 'Post-capture image destination') \">
								<variable>ACTION</variable>
								<default>"$ACTION"</default>
								$ACTION_ITEMS
								<action>echo "\$ACTION" > $PREFDIR/action</action>
							</comboboxtext>
						</vbox>
					</hbox>
				</vbox>
			</hbox>

			<pixmap><input file>\"$APPDIR/icons/blank1.png\"</input></pixmap>
			<pixmap><input file>\"$APPDIR/icons/blank1.png\"</input></pixmap>

			<hbox homogeneous=\"true\">
			<hbox>
				<checkbox tooltip-text=\" $(gettext 'Capture full-screen image') \">
					<label>$(gettext 'Fullscreen')  </label>
					<variable>FULL_CAPTURE</variable>
					<input>cat $PREFDIR/full_capture</input>
					<action>if true disable:BORDER</action>
					<action>if true echo true > $PREFDIR/full_capture</action>
					<action>if true echo false > $PREFDIR/region_capture</action>
					<action>if true echo false > $PREFDIR/window_capture</action>
					<action>if true echo false > $PREFDIR/border</action>
					<action>if false echo false > $PREFDIR/full_capture</action>
					<action>refresh:REGION_CAPTURE</action>
					<action>refresh:WINDOW_CAPTURE</action>
					<action>refresh:BORDER</action>
				</checkbox>
				<checkbox tooltip-text=\" $(gettext 'Capture a rectangular region (ROI). 
 Use the mouse to outline the area 
 after pressing the Capture button.') \">
					<label>$(gettext 'Region')  </label>
					<variable>REGION_CAPTURE</variable>
					<input>cat $PREFDIR/region_capture</input>
					<action>if true disable:BORDER</action>
					<action>if true echo false > $PREFDIR/full_capture</action>
					<action>if true echo true > $PREFDIR/region_capture</action>
					<action>if true echo false > $PREFDIR/window_capture</action>
					<action>if true echo false > $PREFDIR/border</action>
					<action>if false echo false > $PREFDIR/region_capture</action>
					<action>refresh:FULL_CAPTURE</action>
					<action>refresh:WINDOW_CAPTURE</action>
					<action>refresh:BORDER</action>
				</checkbox>
				<checkbox tooltip-text=\" $(gettext 'Use the mouse to select a window 
 after pressing the Capture button.') \">
					<label>$(gettext 'Window')  </label>
					<variable>WINDOW_CAPTURE</variable>
					<input>cat $PREFDIR/window_capture</input>
					<action>if true enable:BORDER</action>
					<action>if true echo false > $PREFDIR/full_capture</action>
					<action>if true echo false > $PREFDIR/region_capture</action>
					<action>if true echo true > $PREFDIR/window_capture</action>
					<action>if true echo true > $PREFDIR/border</action>
					<action>if false disable:BORDER</action>
					<action>if false echo false > $PREFDIR/window_capture</action>
					<action>if false echo false > $PREFDIR/border</action>
					<action>refresh:FULL_CAPTURE</action>
					<action>refresh:REGION_CAPTURE</action>
					<action>refresh:BORDER</action>
					</checkbox>
				<checkbox tooltip-text=\" $(gettext 'Include border decoration 
 with the captured window.') \">
					<label>$(gettext 'Border')</label>
					<variable>BORDER</variable>
					<input>cat $PREFDIR/border</input>
					<action>if true echo false > $PREFDIR/full_capture</action>
					<action>if true echo false > $PREFDIR/region_capture</action>
					<action>if true echo true > $PREFDIR/window_capture</action>
					<action>if true echo true > $PREFDIR/border</action>
					<action>if false echo false > $PREFDIR/border</action>
					<action>refresh:FULL_CAPTURE</action>
					<action>refresh:WINDOW_CAPTURE</action>
					<action>refresh:REGION_CAPTURE</action>
				</checkbox>
			</hbox>
			</hbox>

			<pixmap><input file>\"$APPDIR/icons/blank1.png\"</input></pixmap>

			<hbox homogeneous=\"true\">
			<hbox>
				$AUDIO_ALERT
				<checkbox tooltip-text=\" $(gettext 'Enable Image Host option') \">
					<label>$(gettext 'Image Host')</label>
					<variable>IMAGE_HOST</variable>
					<input>cat $PREFDIR/image_host</input>
					<action>if true echo true > $PREFDIR/image_host</action>
					<action>if false echo false > $PREFDIR/image_host</action>
					<action>$APPDIR/PupSnap &</action>
					<action type=\"exit\">quit_now</action>
				</checkbox>
			</hbox>
			</hbox>

			<pixmap><input file>\"$APPDIR/icons/blank1.png\"</input></pixmap>
			<hseparator space-expand=\"false\" space-fill=\"false\"></hseparator>

			<hbox margin=\"2\" space-expand=\"false\" space-fill=\"true\" homogeneous=\"true\">
				<button height-request=\"35\" width-request=\"130\" use-underline=\"true\" tooltip-text=\" $(gettext 'View captured image') \">
					<label>$(gettext '_View')  </label>
					<input file>$APPDIR/icons/view.svg</input><height>20</height><width>20</width>
					<action>func_screenshot_view &</action>
				</button>
				<button height-request=\"35\" width-request=\"130\" use-underline=\"true\" tooltip-text=\" $(gettext 'Capture the screen image') \">
					<label>\"$(gettext '_Capture') \"</label>
					<input file stock=\"gtk-fullscreen\"></input>
					<action>. $APPDIR/func -screen_capture &</action>
					<action>echo ""$(gettext 'No file selected')"" > $APPDIR/imgur-file</action>
					<action type=\"clear\">IMAGE_URL</action>
					<action type=\"clear\">DELETE_URL</action>
					<action type=\"exit\">quit_now</action>
				</button>
				<button height-request=\"35\" width-request=\"130\" use-underline=\"true\" tooltip-text=\" $(gettext 'Close PupSnap') \">
					<label>\"$(gettext 'E_xit')  \"</label>
					<input file stock=\"gtk-close\"></input>
					<action>echo ""$(gettext 'No file selected')"" > $APPDIR/imgur-file</action>
					<action type=\"clear\">IMAGE_URL</action>
					<action type=\"clear\">DELETE_URL</action>
					<action type=\"exit\">quit_now</action>
				</button>
			</hbox>
		</vbox>

		$HOST_TAB

		</notebook>
	</vbox>
</window>"

$GTKDIALOG -p PUPSNAP_DIALOG

unset PUPSNAP_DIALOG

rm -f /tmp/PS-* 2>/dev/null

exit 0
