slitaz-tools rev 296

desktopbox: Add autostart (GUI to enable/disable apps started with Openbox)
author Christophe Lincoln <pankso@slitaz.org>
date Sat Feb 21 22:33:58 2009 +0100 (2009-02-21)
parents c90e38d22ae6
children f390590b62b4
files rootfs/usr/share/applications/desktopbox-autostart.desktop tinyutils/desktopbox
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rootfs/usr/share/applications/desktopbox-autostart.desktop	Sat Feb 21 22:33:58 2009 +0100
     1.3 @@ -0,0 +1,7 @@
     1.4 +[Desktop Entry]
     1.5 +Encoding=UTF-8
     1.6 +Name=Auto started applications
     1.7 +Icon=preferences-system-session
     1.8 +Exec=desktopbox autostart
     1.9 +Type=Application
    1.10 +Categories=Settings;DesktopSettings;GTK;
     2.1 --- a/tinyutils/desktopbox	Fri Feb 20 01:40:30 2009 +0100
     2.2 +++ b/tinyutils/desktopbox	Sat Feb 21 22:33:58 2009 +0100
     2.3 @@ -9,6 +9,9 @@
     2.4  
     2.5  # Glade XML file path.
     2.6  GLADE_XML=/usr/share/slitaz-tools/glade
     2.7 +# Export script path and other if needed so we can use them in 'quote'.
     2.8 +export BIN=$0
     2.9 +export AUTOSTART_SCRIPT=$HOME/.config/openbox/autostart.sh
    2.10  
    2.11  # Standard directories.
    2.12  mkdir -p $HOME/Desktop $HOME/.local/share/applications
    2.13 @@ -68,10 +71,88 @@
    2.14    calendar     Display a calendar under mouse pointer.
    2.15    notify       Display a notification message (center/no decoration).
    2.16                 Ex: `basename $0` notify \"Message to display\" 4
    2.17 +  autostart    Manage autostarted applications with Openbox.
    2.18    logout       Prompt for X session exit or system halt/reboot.\n"
    2.19  }
    2.20  
    2.21 +# Openbox autostart functions, first column is used for icon
    2.22 +autostart_list()
    2.23 +{
    2.24 +	# Enabled
    2.25 +	for app in `cat $AUTOSTART_SCRIPT | grep ^[a-z] | awk '{ print $1 }'`
    2.26 +	do
    2.27 +		comment=`grep -B 1 "^$app" $AUTOSTART_SCRIPT | grep '^# ' | sed s/'#'//`
    2.28 +		[ -x /usr/bin/$app ] && echo "go-next | $app | $comment"
    2.29 +	done
    2.30 +	# Disabled
    2.31 +	for app in `cat $AUTOSTART_SCRIPT | grep ^#[a-z] | awk '{ print $1 }'`
    2.32 +	do
    2.33 +		comment=`grep -B 1 "^$app" $AUTOSTART_SCRIPT | grep '^# ' | sed s/'#'//`
    2.34 +		app=${app#\#}
    2.35 +		[ -x /usr/bin/$app ] && echo "stop | $app | $comment"
    2.36 +	done
    2.37 +}
    2.38 +
    2.39 +# Enable or disbale autostarted applications.
    2.40 +autostart_actions()
    2.41 +{
    2.42 +	if grep -q "^$APPLICATION" $AUTOSTART_SCRIPT; then
    2.43 +		sed -i s/"^$APPLICATION"/"\#$APPLICATION"/ $AUTOSTART_SCRIPT
    2.44 +	else
    2.45 +		sed -i s/"^\#$APPLICATION"/"$APPLICATION"/ $AUTOSTART_SCRIPT
    2.46 +	fi
    2.47 +}
    2.48 +
    2.49 +add_autostarted_app()
    2.50 +{
    2.51 +	if ! grep -q "^$NEW_APP" $AUTOSTART_SCRIPT; then
    2.52 +		NEW_APP=`echo $NEW_APP | sed s/'&'/''/`
    2.53 +		echo "" >> $AUTOSTART_SCRIPT
    2.54 +		echo "# $NEW_COMMENT" >> $AUTOSTART_SCRIPT
    2.55 +		echo "$NEW_APP &" >> $AUTOSTART_SCRIPT
    2.56 +	fi
    2.57 +}
    2.58 +
    2.59 +add_autostarted_app_box()
    2.60 +{
    2.61 +	export ADD_AUTO_START_BOX='
    2.62 +<window title="Add auto started applications" icon-name="preferences-system-session">
    2.63 +<vbox>
    2.64 +	<text width-chars="54">
    2.65 +		<label>"
    2.66 +Add a new application starting with your session
    2.67 +		"</label>
    2.68 +	</text>
    2.69 +	<hbox>
    2.70 +		<text>
    2.71 +			<label>"Application:"</label>
    2.72 +		</text>
    2.73 +		<entry>
    2.74 +			<variable>NEW_APP</variable>
    2.75 +		</entry>
    2.76 +	</hbox>
    2.77 +	<hbox>
    2.78 +		<text>
    2.79 +			<label>"Comment:  "</label>
    2.80 +		</text>
    2.81 +		<entry>
    2.82 +			<variable>NEW_COMMENT</variable>
    2.83 +		</entry>
    2.84 +	</hbox>
    2.85 +	<hbox>
    2.86 +		<button ok>
    2.87 +			<action>$BIN add_autostarted_app</action>
    2.88 +			<action type="exit">exit</action>
    2.89 +		</button>
    2.90 +		<button cancel></button>
    2.91 +	</hbox>
    2.92 +</vbox>
    2.93 +</window>'
    2.94 +	gtkdialog --center --program=ADD_AUTO_START_BOX
    2.95 +}
    2.96 +
    2.97  # Box commands.
    2.98 +
    2.99  case $1 in
   2.100  	new-folder)
   2.101  		# Create a directory on the ~/Desktop.
   2.102 @@ -288,6 +369,51 @@
   2.103  		pid=`ps | grep NOTIFY_BOX | awk '{ print $1 }'`
   2.104  		kill $pid 2>/dev/null
   2.105  		exit 0 ;;
   2.106 +	autostart)
   2.107 +		# Autostarted apps management. Functions are used for input 
   2.108 +		# and actions
   2.109 +		export DESKTOP_DIALOG='
   2.110 +<window title="Auto start applications with Openbox" icon-name="preferences-system-session">
   2.111 +<vbox>
   2.112 +	<tree>
   2.113 +		<width>540</width><height>200</height>
   2.114 +		<variable>APPLICATION</variable>
   2.115 +		<label>Application|Comment</label>
   2.116 +		<input icon_column="0">$BIN autostart_list</input>
   2.117 +		<action>$BIN autostart_actions</action>
   2.118 +		<action>refresh:APPLICATION</action>
   2.119 +	</tree>
   2.120 +	<hbox>
   2.121 +		<text width-chars="36">
   2.122 +				<label>
   2.123 +"Double clic to enable/disable an application"
   2.124 +				</label>
   2.125 +			</text>
   2.126 +		<button>
   2.127 +			<label>Add</label>
   2.128 +			<input file icon="gtk-add"></input>
   2.129 +			<action>$BIN add_autostarted_app_box</action>
   2.130 +			<action>refresh:APPLICATION</action>
   2.131 +		</button>
   2.132 +		<button>
   2.133 +			<label>Configuration</label>
   2.134 +			<input file icon="accessories-text-editor"></input>
   2.135 +			<action>leafpad $AUTOSTART_SCRIPT</action>
   2.136 +			<action>refresh:APPLICATION</action>
   2.137 +		</button>
   2.138 +		<button>
   2.139 +			<label>Exit</label>
   2.140 +			<input file icon="exit"></input>	
   2.141 +			<action type="exit">exit</action>
   2.142 +		</button>
   2.143 +	</hbox>
   2.144 +</vbox>
   2.145 +</window>'
   2.146 +		;;
   2.147 +	*_*)
   2.148 +		# Exec all function called by args (must have an underscore).
   2.149 +		$1
   2.150 +		exit 0 ;;
   2.151  	*)
   2.152  		# Usage if executed from cmdline.
   2.153  		#