slitaz-tools diff oldstuff/gtkdialog/desktopbox @ rev 915

Added tag 5.8.12 for changeset e0c2b81e8b1e
author Xander Ziiryanoff <psychomaniak@xakep.ru>
date Wed Nov 05 20:33:55 2014 +0200 (2014-11-05)
parents 0f5e3af5a51d
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/oldstuff/gtkdialog/desktopbox	Wed Nov 05 20:33:55 2014 +0200
     1.3 @@ -0,0 +1,483 @@
     1.4 +#! /bin/sh
     1.5 +#
     1.6 +# Multi-call script providing GTK boxes to manage a desktop following
     1.7 +# Freedesktop standards.
     1.8 +#
     1.9 +# (C) GNU gpl v3 - SliTaz GNU/Linux 2008.
    1.10 +#
    1.11 +VERSION=20090504
    1.12 +
    1.13 +# Glade XML file path and translated messages path.
    1.14 +GLADE_XML=/usr/share/slitaz/glade
    1.15 +MESSAGES=/usr/share/slitaz/messages
    1.16 +
    1.17 +# Export script path and others if needed so we can use them in 'quote'.
    1.18 +export BIN=$0
    1.19 +export AUTOSTART_SCRIPT=$HOME/.config/openbox/autostart.sh
    1.20 +
    1.21 +# Standard directories.
    1.22 +mkdir -p $HOME/Desktop $HOME/.local/share/applications
    1.23 +
    1.24 +# Get the active locale (default to English).
    1.25 +. $MESSAGES/en/desktopbox.msg
    1.26 +        test -f $MESSAGES/${LANG%.*}/desktopbox.msg && . $MESSAGES/${LANG%.*}/desktopbox.msg
    1.27 +        test -f $MESSAGES/${LANG%_*}/desktopbox.msg && . $MESSAGES/${LANG%_*}/desktopbox.msg
    1.28 +
    1.29 +
    1.30 +# Command line usage.
    1.31 +usage()
    1.32 +{
    1.33 +	echo -e "\nSliTaz Freedesktop Box - Version: $VERSION\n
    1.34 +\033[1mUsage: \033[0m `basename $0` command
    1.35 +\033[1mCommands: \033[0m\n
    1.36 +  new-folder   Create a new folder on the desktop with mkdir.
    1.37 +  new-file     Create a new empty file or SHell script on the desktop.
    1.38 +  add-icons    Add a system icon to the desktop.
    1.39 +  notify       Display a notification message (center/no decoration).
    1.40 +               Ex: `basename $0` notify \"Message to display\" 4
    1.41 +  autostart    Manage autostarted applications with Openbox.
    1.42 +  logout       Prompt for X session exit or system halt/reboot.\n"
    1.43 +}
    1.44 +
    1.45 +# Openbox autostart functions, first column is used for icons
    1.46 +autostart_list()
    1.47 +{
    1.48 +	# Enabled
    1.49 +	for app in `cat $AUTOSTART_SCRIPT | grep ^[a-z] | awk '{ print $1 }'`
    1.50 +	do
    1.51 +		comment=`grep -B 1 "^$app" $AUTOSTART_SCRIPT | grep '^# ' | sed s/'#'//`
    1.52 +		[ -x /usr/bin/$app ] && echo "go-next | $app | $comment"
    1.53 +	done
    1.54 +	# Disabled
    1.55 +	for app in `cat $AUTOSTART_SCRIPT | grep ^#[a-z] | awk '{ print $1 }'`
    1.56 +	do
    1.57 +		comment=`grep -B 1 "^$app" $AUTOSTART_SCRIPT | grep '^# ' | sed s/'#'//`
    1.58 +		app=${app#\#}
    1.59 +		[ -x /usr/bin/$app ] && echo "stop | $app | $comment"
    1.60 +	done
    1.61 +}
    1.62 +
    1.63 +# Enable or disable autostarted applications.
    1.64 +autostart_actions()
    1.65 +{
    1.66 +	if grep -q "^$APPLICATION" $AUTOSTART_SCRIPT; then
    1.67 +		sed -i s/"^$APPLICATION"/"\#$APPLICATION"/ $AUTOSTART_SCRIPT
    1.68 +	else
    1.69 +		sed -i s/"^\#$APPLICATION"/"$APPLICATION"/ $AUTOSTART_SCRIPT
    1.70 +	fi
    1.71 +}
    1.72 +
    1.73 +add_autostarted_app()
    1.74 +{
    1.75 +	if ! grep -q "^$NEW_APP" $AUTOSTART_SCRIPT; then
    1.76 +		NEW_APP=`echo $NEW_APP | sed s/'&'/''/`
    1.77 +		echo "" >> $AUTOSTART_SCRIPT
    1.78 +		echo "# $NEW_COMMENT" >> $AUTOSTART_SCRIPT
    1.79 +		echo "$NEW_APP &" >> $AUTOSTART_SCRIPT
    1.80 +	fi
    1.81 +}
    1.82 +
    1.83 +add_autostarted_app_box()
    1.84 +{
    1.85 +	export ADD_AUTO_START_BOX='
    1.86 +<window title="Add auto started applications" icon-name="preferences-system-session">
    1.87 +<vbox>
    1.88 +	<text width-chars="54">
    1.89 +		<label>"
    1.90 +Add a new application starting with your session
    1.91 +		"</label>
    1.92 +	</text>
    1.93 +	<hbox>
    1.94 +		<text>
    1.95 +			<label>"Application:"</label>
    1.96 +		</text>
    1.97 +		<entry>
    1.98 +			<variable>NEW_APP</variable>
    1.99 +		</entry>
   1.100 +	</hbox>
   1.101 +	<hbox>
   1.102 +		<text>
   1.103 +			<label>"Comment:  "</label>
   1.104 +		</text>
   1.105 +		<entry>
   1.106 +			<variable>NEW_COMMENT</variable>
   1.107 +		</entry>
   1.108 +	</hbox>
   1.109 +	<hbox>
   1.110 +		<button ok>
   1.111 +			<action>$BIN add_autostarted_app</action>
   1.112 +			<action type="exit">exit</action>
   1.113 +		</button>
   1.114 +		<button cancel></button>
   1.115 +	</hbox>
   1.116 +</vbox>
   1.117 +</window>'
   1.118 +	gtkdialog --center --program=ADD_AUTO_START_BOX
   1.119 +}
   1.120 +
   1.121 +# Box commands.
   1.122 +
   1.123 +case $1 in
   1.124 +	new-folder)
   1.125 +		# Create a directory on the ~/Desktop.
   1.126 +		#
   1.127 +		DESKTOP_DIALOG="
   1.128 +<window title=\"Desktopbox - mkdir\" icon-name=\"folder-new\">
   1.129 +<vbox>
   1.130 +
   1.131 +	<text use-markup=\"true\" width-chars=\"40\">
   1.132 +		<label>\"
   1.133 +<b>$NEW_FOLDER_LABEL</b>\"
   1.134 +		</label>
   1.135 +	</text>
   1.136 +
   1.137 +	<hbox>
   1.138 +		<entry>
   1.139 +			<default>$FOLDER_ENTRY_MSG</default>
   1.140 +			<variable>DIR</variable>
   1.141 +		</entry>
   1.142 +	</hbox>"
   1.143 +		ACTIONS='
   1.144 +	<hbox>
   1.145 +		<button>
   1.146 +			<label>Mkdir</label>
   1.147 +			<input file icon="folder-new"></input>
   1.148 +			<action>mkdir -p "$HOME/Desktop/$DIR"</action>
   1.149 +			<action type="exit">Exit</action>
   1.150 +		</button>
   1.151 +		<button cancel>
   1.152 +			<action type="exit">Exit</action>
   1.153 +		</button>
   1.154 +	</hbox>
   1.155 +
   1.156 +</vbox>
   1.157 +</window>'
   1.158 +		export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
   1.159 +	new-file)
   1.160 +		# Create a file on the ~/Desktop.
   1.161 +		#
   1.162 +		DESKTOP_DIALOG="
   1.163 +<window title=\"Desktopbox - touch/cat\" icon-name=\"document-new\">
   1.164 +<vbox>
   1.165 +	<text use-markup=\"true\" width-chars=\"40\">
   1.166 +		<label>\"
   1.167 +<b>$NEW_FILE_LABEL</b>\"
   1.168 +		</label>
   1.169 +	</text>
   1.170 +
   1.171 +	<hbox>
   1.172 +		<entry>
   1.173 +			<default>$FILE_ENTRY_MSG</default>
   1.174 +			<variable>FILE</variable>
   1.175 +		</entry>
   1.176 +	</hbox>"
   1.177 +		ACTIONS='
   1.178 +	<hbox>
   1.179 +		<button>
   1.180 +			<label>SH script</label>
   1.181 +			<input file icon="document-new"></input>
   1.182 +			<action>echo "#!/bin/sh" > "$HOME/Desktop/$FILE"</action>
   1.183 +			<action>echo "#" >> "$HOME/Desktop/$FILE"</action>
   1.184 +			<action>chmod +x "$HOME/Desktop/$FILE"</action>
   1.185 +			<action type="exit">Exit</action>
   1.186 +		</button>
   1.187 +		<button>
   1.188 +			<label>Empty</label>
   1.189 +			<input file icon="document-new"></input>
   1.190 +			<action>touch "$HOME/Desktop/$FILE"</action>
   1.191 +			<action type="exit">Exit</action>
   1.192 +		</button>
   1.193 +		<button cancel>
   1.194 +			<action type="exit">Exit</action>
   1.195 +		</button>
   1.196 +	</hbox>
   1.197 +</vbox>
   1.198 +</window>'
   1.199 +		export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
   1.200 +	add-icons)
   1.201 +		# Add new icons on the ~/Desktop from /usr/share/applications.
   1.202 +		#
   1.203 +		DESKTOP_DIALOG="
   1.204 +<window title=\"$ADD_ICON_LABEL\" icon-name=\"document-new\">
   1.205 +<vbox>
   1.206 +	<text use-markup=\"true\" width-chars=\"40\">
   1.207 +		<label>\"
   1.208 +<b>$ADD_ICON_LABEL</b>
   1.209 +\"
   1.210 +		</label>
   1.211 +	</text>
   1.212 +	<tree headers_visible=\"false\">
   1.213 +		<width>420</width><height>200</height>
   1.214 +		<variable>ICON</variable>
   1.215 +		<label>Filename|Application</label>"
   1.216 +		# Get application name and icon.
   1.217 +		cd /usr/share/applications
   1.218 +		for file in *.desktop
   1.219 +		do
   1.220 +			# Try to get the name in the right locale.
   1.221 +			NAME=`grep ^Name $file | grep $lang || grep ^Name= $file`
   1.222 +			NAME=`echo $NAME | cut -d "=" -f 2`
   1.223 +			ICON=`grep ^Icon= $file | cut -d "=" -f 2`
   1.224 +			ICON=`basename $ICON`
   1.225 +			ICON=${ICON%.*}
   1.226 +			FILE=${file%.desktop}
   1.227 +			ITEM="<item icon=\"$ICON\">$FILE | $NAME</item>"
   1.228 +			DESKTOP_DIALOG="${DESKTOP_DIALOG}${ITEM}"
   1.229 +		done
   1.230 +		ACTIONS='<action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
   1.231 +	</tree>
   1.232 +	<hbox>
   1.233 +		<button>
   1.234 +			<label>Add</label>
   1.235 +			<input file icon="gtk-add"></input>
   1.236 +			<action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
   1.237 +		</button>
   1.238 +		<button>
   1.239 +			<label>Exit</label>
   1.240 +			<input file icon="exit"></input>
   1.241 +			<action type="exit">Exit</action>
   1.242 +		</button>
   1.243 +	</hbox>
   1.244 +</vbox>
   1.245 +</window>'
   1.246 +		export DESKTOP_DIALOG=${DESKTOP_DIALOG}${ACTIONS} ;;
   1.247 +	logout)
   1.248 +		# X session/system logout.
   1.249 +		#
   1.250 +		DESKTOP_DIALOG="
   1.251 +<window title=\"SliTaz Desktop logout\" icon-name=\"user-desktop\" skip_taskbar_hint=\"true\">
   1.252 +<vbox>
   1.253 +	<pixmap>
   1.254 +		<input file>/usr/share/icons/Tango/32x32/places/user-desktop.png</input>
   1.255 +	</pixmap>
   1.256 +	<hbox>
   1.257 +		<text use-markup=\"true\" width-chars=\"$CHARS_SIZE\">
   1.258 +			<label>
   1.259 +\"<b>$DESKTOP_DIALOG_LABEL</b>
   1.260 +\"
   1.261 +			</label>
   1.262 +		</text>
   1.263 +	</hbox>"
   1.264 +		TAZUSB_DIALOG="
   1.265 +	<hbox>
   1.266 +		<checkbox>
   1.267 +			<label>$DESKTOP_DIALOG_TAZUSB</label>
   1.268 +			<variable>TAZUSB_WRITE</variable>
   1.269 +			<default>false</default>
   1.270 +		</checkbox>
   1.271 +		<radiobutton>
   1.272 +			<label>lzma</label>
   1.273 +			<variable>LZMA</variable>
   1.274 +		</radiobutton>
   1.275 +		<radiobutton active=\"true\">
   1.276 +			<label>gzip</label>
   1.277 +			<variable>GZIP</variable>
   1.278 +		</radiobutton>
   1.279 +		<radiobutton>
   1.280 +			<label>none</label>
   1.281 +			<variable>NONE</variable>
   1.282 +		</radiobutton>
   1.283 +	</hbox>"
   1.284 +		EXTRA="COMP=none; [ \$LZMA = true ] && COMP=lzma; [ \$GZIP = true ] && COMP=gzip; [ \$TAZUSB_WRITE = true ] && { subox \"xterm -e '/usr/bin/tazusb writefs \$COMP'\"; sleep 1; while ps x | grep -v grep | grep -q tazusb; do sleep 1; done; };"
   1.285 +		[ -f /home/boot/rootfs.gz ] || { TAZUSB_DIALOG=""; EXTRA=""; }
   1.286 +		# Logout for Openbox or JWM and system shutdown or reboot.
   1.287 +		ACTIONS="
   1.288 +	<hbox>
   1.289 +		<button>
   1.290 +			<label>$DESKTOP_LOGOUT_BUTTON</label>
   1.291 +			<input file icon=\"video-display\"></input>
   1.292 +			<action>$EXTRA openbox --exit || jwm -exit</action>
   1.293 +			<action type=\"exit\">Exit</action>
   1.294 +		</button>
   1.295 +		<button>
   1.296 +			<label>$DESKTOP_SHUTDOWN_BUTTON</label>
   1.297 +			<input file icon=\"system-shutdown\"></input>
   1.298 +			<action>$EXTRA poweroff</action>
   1.299 +			<action type=\"exit\">Exit</action>
   1.300 +		</button>
   1.301 +		<button>
   1.302 +			<label>$DESKTOP_REBOOT_BUTTON</label>
   1.303 +			<input file icon=\"reload\"></input>
   1.304 +			<action>$EXTRA reboot</action>
   1.305 +			<action type=\"exit\">Exit</action>
   1.306 +		</button>
   1.307 +		<button cancel>
   1.308 +			<action type=\"exit\">Exit</action>
   1.309 +		</button>
   1.310 +	</hbox>
   1.311 +</vbox>
   1.312 +</window>"
   1.313 +		export DESKTOP_DIALOG=${DESKTOP_DIALOG}${TAZUSB_DIALOG}${ACTIONS} ;;
   1.314 +	notify)
   1.315 +		# Notification message without window decoration.
   1.316 +		MSG="$2"
   1.317 +		SEC=$3
   1.318 +		[ -z $SEC ] && SEC=4
   1.319 +		export NOTIFY_BOX="
   1.320 +<window decorated=\"false\" skip_taskbar_hint=\"true\">
   1.321 +<vbox>
   1.322 +	<text width-chars=\"64\" use-markup=\"true\">
   1.323 +		<label>\"
   1.324 +<b>$MSG</b>
   1.325 +		\"</label>
   1.326 +	</text>
   1.327 +</vbox>
   1.328 +</window>"
   1.329 +		gtkdialog --center --program=NOTIFY_BOX >/dev/null &
   1.330 +		sleep $SEC
   1.331 +		pid=`ps | grep NOTIFY_BOX | awk '{ print $1 }'`
   1.332 +		kill $pid 2>/dev/null
   1.333 +		exit 0 ;;
   1.334 +	autostart)
   1.335 +		# Autostarted apps management. Functions are used for input 
   1.336 +		# and actions
   1.337 +		export DESKTOP_DIALOG='
   1.338 +<window title="Auto start applications with Openbox" icon-name="preferences-system-session">
   1.339 +<vbox>
   1.340 +	<tree>
   1.341 +		<width>540</width><height>200</height>
   1.342 +		<variable>APPLICATION</variable>
   1.343 +		<label>Application|Comment</label>
   1.344 +		<input icon_column="0">$BIN autostart_list</input>
   1.345 +		<action>$BIN autostart_actions</action>
   1.346 +		<action>refresh:APPLICATION</action>
   1.347 +	</tree>
   1.348 +	<hbox>
   1.349 +		<text width-chars="36">
   1.350 +				<label>
   1.351 +"Double click to enable/disable an application"
   1.352 +				</label>
   1.353 +			</text>
   1.354 +		<button>
   1.355 +			<label>Add</label>
   1.356 +			<input file icon="gtk-add"></input>
   1.357 +			<action>$BIN add_autostarted_app_box</action>
   1.358 +			<action>refresh:APPLICATION</action>
   1.359 +		</button>
   1.360 +		<button>
   1.361 +			<label>Configuration</label>
   1.362 +			<input file icon="accessories-text-editor"></input>
   1.363 +			<action>editor $AUTOSTART_SCRIPT</action>
   1.364 +			<action>refresh:APPLICATION</action>
   1.365 +		</button>
   1.366 +		<button>
   1.367 +			<label>Exit</label>
   1.368 +			<input file icon="exit"></input>	
   1.369 +			<action type="exit">exit</action>
   1.370 +		</button>
   1.371 +	</hbox>
   1.372 +</vbox>
   1.373 +</window>'
   1.374 +		;;
   1.375 +	tazapps)
   1.376 +		# Default applications configuration script. System wide config file
   1.377 +		# is /etc/slitaz/applications.conf and each user can have personal
   1.378 +		# settings. System wide for root and personal config for user.
   1.379 +		export CONFIG="$HOME/.config/slitaz/applications.conf"
   1.380 +		if [ ! -f $CONFIG ]; then
   1.381 +			mkdir -p $HOME/.config/slitaz
   1.382 +			cp /etc/slitaz/applications.conf $CONFIG
   1.383 +		fi
   1.384 +		export DESKTOP_DIALOG='
   1.385 +<window title="SliTaz default applications" icon-name="preferences-desktop">
   1.386 +<vbox>
   1.387 +	<vbox>
   1.388 +		<text use-markup="true" width-chars="54">
   1.389 +			<label>"
   1.390 +<b>SliTaz default applications configuration</b>
   1.391 +			"</label>
   1.392 +		</text>
   1.393 +	</vbox>
   1.394 +	<hbox>
   1.395 +		<text wrap="false">
   1.396 +			<label>"File manager:       "</label>
   1.397 +		</text>
   1.398 +		<entry>
   1.399 +			<input>. $CONFIG; echo $FILE_MANAGER</input>
   1.400 +			<variable>FILE_MANAGER</variable>
   1.401 +		</entry>
   1.402 +		<button>
   1.403 +			<label>Change</label>
   1.404 +			<input file icon="forward"></input>
   1.405 +			<action>sed -i s/"FILE_MANAGER=.*"/"FILE_MANAGER=\"$FILE_MANAGER\""/ $CONFIG</action>
   1.406 +		</button>
   1.407 +	</hbox>
   1.408 +	<hbox>
   1.409 +		<text wrap="false">
   1.410 +			<label>"Web browser:      "</label>
   1.411 +		</text>
   1.412 +		<entry>
   1.413 +			<input>. $CONFIG; echo $BROWSER</input>
   1.414 +			<variable>BROWSER</variable>
   1.415 +		</entry>
   1.416 +		<button>
   1.417 +			<label>Change</label>
   1.418 +			<input file icon="forward"></input>
   1.419 +			<action>sed -i s/"BROWSER=.*"/"BROWSER=\"$BROWSER\""/ $CONFIG</action>
   1.420 +		</button>
   1.421 +	</hbox>
   1.422 +	<hbox>
   1.423 +		<text wrap="false">
   1.424 +			<label>"Text editor:          "</label>
   1.425 +		</text>
   1.426 +		<entry>
   1.427 +			<input>. $CONFIG; echo $EDITOR</input>
   1.428 +			<variable>EDITOR</variable>
   1.429 +		</entry>
   1.430 +		<button>
   1.431 +			<label>Change</label>
   1.432 +			<input file icon="forward"></input>
   1.433 +			<action>sed -i s/"EDITOR=.*"/"EDITOR=\"$EDITOR\""/ $CONFIG</action>
   1.434 +		</button>
   1.435 +	</hbox>
   1.436 +	<hbox>
   1.437 +		<text wrap="false">
   1.438 +			<label>"Terminal:              "</label>
   1.439 +		</text>
   1.440 +		<entry>
   1.441 +			<input>. $CONFIG; echo $TERMINAL</input>
   1.442 +			<variable>TERMINAL</variable>
   1.443 +		</entry>
   1.444 +		<button>
   1.445 +			<label>Change</label>
   1.446 +			<input file icon="forward"></input>
   1.447 +			<action>sed -i s/"TERMINAL=.*"/"TERMINAL=\"$TERMINAL\""/ $CONFIG</action>
   1.448 +		</button>
   1.449 +	</hbox>
   1.450 +	<hbox>
   1.451 +		<text wrap="false">
   1.452 +			<label>"Window manager:"</label>
   1.453 +		</text>
   1.454 +		<entry>
   1.455 +			<input>. $CONFIG; echo $WINDOW_MANAGER</input>
   1.456 +			<variable>WINDOW_MANAGER</variable>
   1.457 +		</entry>
   1.458 +		<button>
   1.459 +			<label>Change</label>
   1.460 +			<input file icon="forward"></input>
   1.461 +			<action>sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WINDOW_MANAGER\""/ $CONFIG</action>
   1.462 +		</button>
   1.463 +	</hbox>
   1.464 +	<hbox>
   1.465 +		<button>
   1.466 +			<label>Exit</label>
   1.467 +			<input file icon="exit"></input>	
   1.468 +			<action type="exit">exit</action>
   1.469 +		</button>
   1.470 +	</hbox>
   1.471 +</vbox>
   1.472 +</window>' ;;
   1.473 +	*_*)
   1.474 +		# Exec all function called by args (must have an underscore).
   1.475 +		$1
   1.476 +		exit 0 ;;
   1.477 +	*)
   1.478 +		# Usage if executed from cmdline.
   1.479 +		#
   1.480 +		usage
   1.481 +		exit 0 ;;
   1.482 +esac
   1.483 +
   1.484 +gtkdialog --center --program=DESKTOP_DIALOG >/dev/null
   1.485 +
   1.486 +exit 0