slitaz-tools view tinyutils/desktopbox @ rev 317

Edits/typos (more to be done)
author Paul Issott <paul@slitaz.org>
date Tue Mar 10 20:19:52 2009 +0000 (2009-03-10)
parents 79abb50ea00a
children edffcc2c8ef5
line source
1 #! /bin/sh
2 #
3 # Multi-call script providing GTK boxes to manage a desktop following
4 # Freedesktop standards.
5 #
6 # (C) GNU gpl v3 - SliTaz GNU/Linux 2008.
7 #
8 VERSION=20080719
10 # Glade XML file path.
11 GLADE_XML=/usr/share/slitaz-tools/glade
12 # Export script path and other if needed so we can use them in 'quote'.
13 export BIN=$0
14 export AUTOSTART_SCRIPT=$HOME/.config/openbox/autostart.sh
16 # Standard directories.
17 mkdir -p $HOME/Desktop $HOME/.local/share/applications
19 # Get the active locale (default to English).
20 case $LANG in
21 es*)
22 lang="es"
23 NEW_FOLDER_LABEL="Create a new folder on the desktop:"
24 FOLDER_ENTRY_MSG="dirname"
25 NEW_FILE_LABEL="Create a new file on the desktop:"
26 FILE_ENTRY_MSG="filename"
27 ADD_ICON_LABEL="Add some desktop icons"
28 CHARS_SIZE="64"
29 DESKTOP_DIALOG_TAZUSB="Save filesystem using compression"
30 DESKTOP_DIALOG_LABEL="Session logout, system shutdown or reboot"
31 DESKTOP_LOGOUT_BUTTON="Logout X session"
32 DESKTOP_SHUTDOWN_BUTTON="Shutdown computer"
33 DESKTOP_REBOOT_BUTTON="Reboot system" ;;
34 fr*)
35 lang="fr"
36 NEW_FOLDER_LABEL="Créer un nouveau dossier sur le bureau:"
37 FOLDER_ENTRY_MSG="dossier"
38 NEW_FILE_LABEL="Créer un nouveau fichier sur le bureau:"
39 FILE_ENTRY_MSG="fichier"
40 ADD_ICON_LABEL="Ajouter des icônes de bureau"
41 CHARS_SIZE="72"
42 DESKTOP_DIALOG_TAZUSB="Enregistrer le système avec la compression"
43 DESKTOP_DIALOG_LABEL="Déconnexion, arrêt ou redémarrage du système"
44 DESKTOP_LOGOUT_BUTTON="Fermer la session X"
45 DESKTOP_SHUTDOWN_BUTTON="Eteindre le système"
46 DESKTOP_REBOOT_BUTTON="Redémarrer le système" ;;
47 *)
48 lang=""
49 NEW_FOLDER_LABEL="Create a new folder on the desktop:"
50 FOLDER_ENTRY_MSG="dirname"
51 NEW_FILE_LABEL="Create a new file on the desktop:"
52 FILE_ENTRY_MSG="filename"
53 ADD_ICON_LABEL="Add some desktop icons"
54 CHARS_SIZE="64"
55 DESKTOP_DIALOG_TAZUSB="Save filesystem using compression"
56 DESKTOP_DIALOG_LABEL="Session logout, system shutdown or reboot"
57 DESKTOP_LOGOUT_BUTTON="Logout X session"
58 DESKTOP_SHUTDOWN_BUTTON="Shutdown computer"
59 DESKTOP_REBOOT_BUTTON="Reboot system" ;;
60 esac
62 # Command line usage.
63 usage()
64 {
65 echo -e "\nSliTaz Freedesktop Box - Version: $VERSION\n
66 \033[1mUsage: \033[0m `basename $0` command
67 \033[1mCommands: \033[0m\n
68 new-folder Create a new folder on the desktop with mkdir.
69 new-file Create a new empty file or SHell script on the desktop.
70 add-icons Add a system icon to the desktop.
71 calendar Display a calendar under mouse pointer.
72 notify Display a notification message (center/no decoration).
73 Ex: `basename $0` notify \"Message to display\" 4
74 autostart Manage autostarted applications with Openbox.
75 logout Prompt for X session exit or system halt/reboot.\n"
76 }
78 # Openbox autostart functions, first column is used for icon
79 autostart_list()
80 {
81 # Enabled
82 for app in `cat $AUTOSTART_SCRIPT | grep ^[a-z] | awk '{ print $1 }'`
83 do
84 comment=`grep -B 1 "^$app" $AUTOSTART_SCRIPT | grep '^# ' | sed s/'#'//`
85 [ -x /usr/bin/$app ] && echo "go-next | $app | $comment"
86 done
87 # Disabled
88 for app in `cat $AUTOSTART_SCRIPT | grep ^#[a-z] | awk '{ print $1 }'`
89 do
90 comment=`grep -B 1 "^$app" $AUTOSTART_SCRIPT | grep '^# ' | sed s/'#'//`
91 app=${app#\#}
92 [ -x /usr/bin/$app ] && echo "stop | $app | $comment"
93 done
94 }
96 # Enable or disbale autostarted applications.
97 autostart_actions()
98 {
99 if grep -q "^$APPLICATION" $AUTOSTART_SCRIPT; then
100 sed -i s/"^$APPLICATION"/"\#$APPLICATION"/ $AUTOSTART_SCRIPT
101 else
102 sed -i s/"^\#$APPLICATION"/"$APPLICATION"/ $AUTOSTART_SCRIPT
103 fi
104 }
106 add_autostarted_app()
107 {
108 if ! grep -q "^$NEW_APP" $AUTOSTART_SCRIPT; then
109 NEW_APP=`echo $NEW_APP | sed s/'&'/''/`
110 echo "" >> $AUTOSTART_SCRIPT
111 echo "# $NEW_COMMENT" >> $AUTOSTART_SCRIPT
112 echo "$NEW_APP &" >> $AUTOSTART_SCRIPT
113 fi
114 }
116 add_autostarted_app_box()
117 {
118 export ADD_AUTO_START_BOX='
119 <window title="Add auto started applications" icon-name="preferences-system-session">
120 <vbox>
121 <text width-chars="54">
122 <label>"
123 Add a new application starting with your session
124 "</label>
125 </text>
126 <hbox>
127 <text>
128 <label>"Application:"</label>
129 </text>
130 <entry>
131 <variable>NEW_APP</variable>
132 </entry>
133 </hbox>
134 <hbox>
135 <text>
136 <label>"Comment: "</label>
137 </text>
138 <entry>
139 <variable>NEW_COMMENT</variable>
140 </entry>
141 </hbox>
142 <hbox>
143 <button ok>
144 <action>$BIN add_autostarted_app</action>
145 <action type="exit">exit</action>
146 </button>
147 <button cancel></button>
148 </hbox>
149 </vbox>
150 </window>'
151 gtkdialog --center --program=ADD_AUTO_START_BOX
152 }
154 # Box commands.
156 case $1 in
157 new-folder)
158 # Create a directory on the ~/Desktop.
159 #
160 DESKTOP_DIALOG="
161 <window title=\"Desktopbox - mkdir\" icon-name=\"folder-new\">
162 <vbox>
164 <text use-markup=\"true\" width-chars=\"40\">
165 <label>\"
166 <b>$NEW_FOLDER_LABEL</b>\"
167 </label>
168 </text>
170 <hbox>
171 <entry>
172 <default>$FOLDER_ENTRY_MSG</default>
173 <variable>DIR</variable>
174 </entry>
175 </hbox>"
176 ACTIONS='
177 <hbox>
178 <button>
179 <label>Mkdir</label>
180 <input file icon="folder-new"></input>
181 <action>mkdir -p "$HOME/Desktop/$DIR"</action>
182 <action type="exit">Exit</action>
183 </button>
184 <button cancel>
185 <action type="exit">Exit</action>
186 </button>
187 </hbox>
189 </vbox>
190 </window>'
191 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
192 new-file)
193 # Create a file on the ~/Desktop.
194 #
195 DESKTOP_DIALOG="
196 <window title=\"Desktopbox - touch/cat\" icon-name=\"document-new\">
197 <vbox>
198 <text use-markup=\"true\" width-chars=\"40\">
199 <label>\"
200 <b>$NEW_FILE_LABEL</b>\"
201 </label>
202 </text>
204 <hbox>
205 <entry>
206 <default>$FILE_ENTRY_MSG</default>
207 <variable>FILE</variable>
208 </entry>
209 </hbox>"
210 ACTIONS='
211 <hbox>
212 <button>
213 <label>SH script</label>
214 <input file icon="document-new"></input>
215 <action>echo "#!/bin/sh" > "$HOME/Desktop/$FILE"</action>
216 <action>echo "#" >> "$HOME/Desktop/$FILE"</action>
217 <action>chmod +x "$HOME/Desktop/$FILE"</action>
218 <action type="exit">Exit</action>
219 </button>
220 <button>
221 <label>Empty</label>
222 <input file icon="document-new"></input>
223 <action>touch "$HOME/Desktop/$FILE"</action>
224 <action type="exit">Exit</action>
225 </button>
226 <button cancel>
227 <action type="exit">Exit</action>
228 </button>
229 </hbox>
230 </vbox>
231 </window>'
232 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
233 add-icons)
234 # Add new icons on the ~/Desktop from /usr/share/applications.
235 #
236 DESKTOP_DIALOG="
237 <window title=\"$ADD_ICON_LABEL\" icon-name=\"document-new\">
238 <vbox>
239 <text use-markup=\"true\" width-chars=\"40\">
240 <label>\"
241 <b>$ADD_ICON_LABEL</b>
242 \"
243 </label>
244 </text>
245 <tree headers_visible=\"false\">
246 <width>420</width><height>200</height>
247 <variable>ICON</variable>
248 <label>Filename|Application</label>"
249 # Get application name and icon.
250 cd /usr/share/applications
251 for file in *.desktop
252 do
253 # Try to get the name in the right locale.
254 NAME=`grep ^Name $file | grep $lang || grep ^Name= $file`
255 NAME=`echo $NAME | cut -d "=" -f 2`
256 ICON=`grep ^Icon= $file | cut -d "=" -f 2`
257 ICON=`basename $ICON`
258 ICON=${ICON%.*}
259 FILE=${file%.desktop}
260 ITEM="<item icon=\"$ICON\">$FILE | $NAME</item>"
261 DESKTOP_DIALOG="${DESKTOP_DIALOG}${ITEM}"
262 done
263 ACTIONS='<action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
264 </tree>
265 <hbox>
266 <button>
267 <label>Add</label>
268 <input file icon="gtk-add"></input>
269 <action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
270 </button>
271 <button>
272 <label>Exit</label>
273 <input file icon="exit"></input>
274 <action type="exit">Exit</action>
275 </button>
276 </hbox>
277 </vbox>
278 </window>'
279 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${ACTIONS} ;;
280 calendar)
281 # Calendar using glade file.
282 #
283 gtkdialog --glade-xml=$GLADE_XML/calendar.glade \
284 --program=MAIN_WINDOW ;;
285 logout)
286 # X session/system logout.
287 #
288 DESKTOP_DIALOG="
289 <window title=\"SliTaz Desktop logout\" icon-name=\"user-desktop\" skip_taskbar_hint=\"true\">
290 <vbox>
291 <pixmap>
292 <input file>/usr/share/icons/Tango/32x32/places/user-desktop.png</input>
293 </pixmap>
294 <hbox>
295 <text use-markup=\"true\" width-chars=\"$CHARS_SIZE\">
296 <label>
297 \"<b>$DESKTOP_DIALOG_LABEL</b>
298 \"
299 </label>
300 </text>
301 </hbox>"
302 TAZUSB_DIALOG="
303 <hbox>
304 <checkbox>
305 <label>$DESKTOP_DIALOG_TAZUSB</label>
306 <variable>TAZUSB_WRITE</variable>
307 <default>false</default>
308 </checkbox>
309 <radiobutton>
310 <label>lzma</label>
311 <variable>LZMA</variable>
312 </radiobutton>
313 <radiobutton active=\"true\">
314 <label>gzip</label>
315 <variable>GZIP</variable>
316 </radiobutton>
317 <radiobutton>
318 <label>none</label>
319 <variable>NONE</variable>
320 </radiobutton>
321 </hbox>"
322 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; };"
323 [ -f /home/boot/rootfs.gz ] || { TAZUSB_DIALOG=""; EXTRA=""; }
324 # Logout for Openbox or JWM and system shutdown or reboot.
325 ACTIONS="
326 <hbox>
327 <button>
328 <label>$DESKTOP_LOGOUT_BUTTON</label>
329 <input file icon=\"video-display\"></input>
330 <action>$EXTRA openbox --exit || jwm -exit</action>
331 <action type=\"exit\">Exit</action>
332 </button>
333 <button>
334 <label>$DESKTOP_SHUTDOWN_BUTTON</label>
335 <input file icon=\"system-shutdown\"></input>
336 <action>$EXTRA poweroff</action>
337 <action type=\"exit\">Exit</action>
338 </button>
339 <button>
340 <label>$DESKTOP_REBOOT_BUTTON</label>
341 <input file icon=\"reload\"></input>
342 <action>$EXTRA reboot</action>
343 <action type=\"exit\">Exit</action>
344 </button>
345 <button cancel>
346 <action type=\"exit\">Exit</action>
347 </button>
348 </hbox>
349 </vbox>
350 </window>"
351 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${TAZUSB_DIALOG}${ACTIONS} ;;
352 notify)
353 # Nofification message without window decoration.
354 MSG="$2"
355 SEC=$3
356 [ -z $SEC ] && SEC=4
357 export NOTIFY_BOX="
358 <window decorated=\"false\" skip_taskbar_hint=\"true\">
359 <vbox>
360 <text width-chars=\"64\" use-markup=\"true\">
361 <label>\"
362 <b>$MSG</b>
363 \"</label>
364 </text>
365 </vbox>
366 </window>"
367 gtkdialog --center --program=NOTIFY_BOX >/dev/null &
368 sleep $SEC
369 pid=`ps | grep NOTIFY_BOX | awk '{ print $1 }'`
370 kill $pid 2>/dev/null
371 exit 0 ;;
372 autostart)
373 # Autostarted apps management. Functions are used for input
374 # and actions
375 export DESKTOP_DIALOG='
376 <window title="Auto start applications with Openbox" icon-name="preferences-system-session">
377 <vbox>
378 <tree>
379 <width>540</width><height>200</height>
380 <variable>APPLICATION</variable>
381 <label>Application|Comment</label>
382 <input icon_column="0">$BIN autostart_list</input>
383 <action>$BIN autostart_actions</action>
384 <action>refresh:APPLICATION</action>
385 </tree>
386 <hbox>
387 <text width-chars="36">
388 <label>
389 "Double click to enable/disable an application"
390 </label>
391 </text>
392 <button>
393 <label>Add</label>
394 <input file icon="gtk-add"></input>
395 <action>$BIN add_autostarted_app_box</action>
396 <action>refresh:APPLICATION</action>
397 </button>
398 <button>
399 <label>Configuration</label>
400 <input file icon="accessories-text-editor"></input>
401 <action>leafpad $AUTOSTART_SCRIPT</action>
402 <action>refresh:APPLICATION</action>
403 </button>
404 <button>
405 <label>Exit</label>
406 <input file icon="exit"></input>
407 <action type="exit">exit</action>
408 </button>
409 </hbox>
410 </vbox>
411 </window>'
412 ;;
413 *_*)
414 # Exec all function called by args (must have an underscore).
415 $1
416 exit 0 ;;
417 *)
418 # Usage if executed from cmdline.
419 #
420 usage
421 exit 0 ;;
422 esac
424 gtkdialog --center --program=DESKTOP_DIALOG >/dev/null
426 exit 0