slitaz-tools view tinyutils/desktopbox @ rev 456

Mountbox: mv tip to help file
author Paul Issott <paul@slitaz.org>
date Sun Mar 21 18:25:28 2010 +0000 (2010-03-21)
parents e9ddf09500d2
children 5fd45a76f488
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=20090504
10 # Glade XML file path and translated messages path.
11 GLADE_XML=/usr/share/slitaz/glade
12 MESSAGES=/usr/share/slitaz/messages
14 # Export script path and other if needed so we can use them in 'quote'.
15 export BIN=$0
16 export AUTOSTART_SCRIPT=$HOME/.config/openbox/autostart.sh
18 # Standard directories.
19 mkdir -p $HOME/Desktop $HOME/.local/share/applications
21 # Get the active locale (default to English).
22 case $LANG in
23 fr*)
24 . $MESSAGES/fr/desktopbox.msg ;;
25 *)
26 . $MESSAGES/en/desktopbox.msg ;;
27 esac
29 # Command line usage.
30 usage()
31 {
32 echo -e "\nSliTaz Freedesktop Box - Version: $VERSION\n
33 \033[1mUsage: \033[0m `basename $0` command
34 \033[1mCommands: \033[0m\n
35 new-folder Create a new folder on the desktop with mkdir.
36 new-file Create a new empty file or SHell script on the desktop.
37 add-icons Add a system icon to the desktop.
38 notify Display a notification message (center/no decoration).
39 Ex: `basename $0` notify \"Message to display\" 4
40 autostart Manage autostarted applications with Openbox.
41 logout Prompt for X session exit or system halt/reboot.\n"
42 }
44 # Openbox autostart functions, first column is used for icon
45 autostart_list()
46 {
47 # Enabled
48 for app in `cat $AUTOSTART_SCRIPT | grep ^[a-z] | awk '{ print $1 }'`
49 do
50 comment=`grep -B 1 "^$app" $AUTOSTART_SCRIPT | grep '^# ' | sed s/'#'//`
51 [ -x /usr/bin/$app ] && echo "go-next | $app | $comment"
52 done
53 # Disabled
54 for app in `cat $AUTOSTART_SCRIPT | grep ^#[a-z] | awk '{ print $1 }'`
55 do
56 comment=`grep -B 1 "^$app" $AUTOSTART_SCRIPT | grep '^# ' | sed s/'#'//`
57 app=${app#\#}
58 [ -x /usr/bin/$app ] && echo "stop | $app | $comment"
59 done
60 }
62 # Enable or disbale autostarted applications.
63 autostart_actions()
64 {
65 if grep -q "^$APPLICATION" $AUTOSTART_SCRIPT; then
66 sed -i s/"^$APPLICATION"/"\#$APPLICATION"/ $AUTOSTART_SCRIPT
67 else
68 sed -i s/"^\#$APPLICATION"/"$APPLICATION"/ $AUTOSTART_SCRIPT
69 fi
70 }
72 add_autostarted_app()
73 {
74 if ! grep -q "^$NEW_APP" $AUTOSTART_SCRIPT; then
75 NEW_APP=`echo $NEW_APP | sed s/'&'/''/`
76 echo "" >> $AUTOSTART_SCRIPT
77 echo "# $NEW_COMMENT" >> $AUTOSTART_SCRIPT
78 echo "$NEW_APP &" >> $AUTOSTART_SCRIPT
79 fi
80 }
82 add_autostarted_app_box()
83 {
84 export ADD_AUTO_START_BOX='
85 <window title="Add auto started applications" icon-name="preferences-system-session">
86 <vbox>
87 <text width-chars="54">
88 <label>"
89 Add a new application starting with your session
90 "</label>
91 </text>
92 <hbox>
93 <text>
94 <label>"Application:"</label>
95 </text>
96 <entry>
97 <variable>NEW_APP</variable>
98 </entry>
99 </hbox>
100 <hbox>
101 <text>
102 <label>"Comment: "</label>
103 </text>
104 <entry>
105 <variable>NEW_COMMENT</variable>
106 </entry>
107 </hbox>
108 <hbox>
109 <button ok>
110 <action>$BIN add_autostarted_app</action>
111 <action type="exit">exit</action>
112 </button>
113 <button cancel></button>
114 </hbox>
115 </vbox>
116 </window>'
117 gtkdialog --center --program=ADD_AUTO_START_BOX
118 }
120 # Box commands.
122 case $1 in
123 new-folder)
124 # Create a directory on the ~/Desktop.
125 #
126 DESKTOP_DIALOG="
127 <window title=\"Desktopbox - mkdir\" icon-name=\"folder-new\">
128 <vbox>
130 <text use-markup=\"true\" width-chars=\"40\">
131 <label>\"
132 <b>$NEW_FOLDER_LABEL</b>\"
133 </label>
134 </text>
136 <hbox>
137 <entry>
138 <default>$FOLDER_ENTRY_MSG</default>
139 <variable>DIR</variable>
140 </entry>
141 </hbox>"
142 ACTIONS='
143 <hbox>
144 <button>
145 <label>Mkdir</label>
146 <input file icon="folder-new"></input>
147 <action>mkdir -p "$HOME/Desktop/$DIR"</action>
148 <action type="exit">Exit</action>
149 </button>
150 <button cancel>
151 <action type="exit">Exit</action>
152 </button>
153 </hbox>
155 </vbox>
156 </window>'
157 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
158 new-file)
159 # Create a file on the ~/Desktop.
160 #
161 DESKTOP_DIALOG="
162 <window title=\"Desktopbox - touch/cat\" icon-name=\"document-new\">
163 <vbox>
164 <text use-markup=\"true\" width-chars=\"40\">
165 <label>\"
166 <b>$NEW_FILE_LABEL</b>\"
167 </label>
168 </text>
170 <hbox>
171 <entry>
172 <default>$FILE_ENTRY_MSG</default>
173 <variable>FILE</variable>
174 </entry>
175 </hbox>"
176 ACTIONS='
177 <hbox>
178 <button>
179 <label>SH script</label>
180 <input file icon="document-new"></input>
181 <action>echo "#!/bin/sh" > "$HOME/Desktop/$FILE"</action>
182 <action>echo "#" >> "$HOME/Desktop/$FILE"</action>
183 <action>chmod +x "$HOME/Desktop/$FILE"</action>
184 <action type="exit">Exit</action>
185 </button>
186 <button>
187 <label>Empty</label>
188 <input file icon="document-new"></input>
189 <action>touch "$HOME/Desktop/$FILE"</action>
190 <action type="exit">Exit</action>
191 </button>
192 <button cancel>
193 <action type="exit">Exit</action>
194 </button>
195 </hbox>
196 </vbox>
197 </window>'
198 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
199 add-icons)
200 # Add new icons on the ~/Desktop from /usr/share/applications.
201 #
202 DESKTOP_DIALOG="
203 <window title=\"$ADD_ICON_LABEL\" icon-name=\"document-new\">
204 <vbox>
205 <text use-markup=\"true\" width-chars=\"40\">
206 <label>\"
207 <b>$ADD_ICON_LABEL</b>
208 \"
209 </label>
210 </text>
211 <tree headers_visible=\"false\">
212 <width>420</width><height>200</height>
213 <variable>ICON</variable>
214 <label>Filename|Application</label>"
215 # Get application name and icon.
216 cd /usr/share/applications
217 for file in *.desktop
218 do
219 # Try to get the name in the right locale.
220 NAME=`grep ^Name $file | grep $lang || grep ^Name= $file`
221 NAME=`echo $NAME | cut -d "=" -f 2`
222 ICON=`grep ^Icon= $file | cut -d "=" -f 2`
223 ICON=`basename $ICON`
224 ICON=${ICON%.*}
225 FILE=${file%.desktop}
226 ITEM="<item icon=\"$ICON\">$FILE | $NAME</item>"
227 DESKTOP_DIALOG="${DESKTOP_DIALOG}${ITEM}"
228 done
229 ACTIONS='<action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
230 </tree>
231 <hbox>
232 <button>
233 <label>Add</label>
234 <input file icon="gtk-add"></input>
235 <action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
236 </button>
237 <button>
238 <label>Exit</label>
239 <input file icon="exit"></input>
240 <action type="exit">Exit</action>
241 </button>
242 </hbox>
243 </vbox>
244 </window>'
245 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${ACTIONS} ;;
246 logout)
247 # X session/system logout.
248 #
249 DESKTOP_DIALOG="
250 <window title=\"SliTaz Desktop logout\" icon-name=\"user-desktop\" skip_taskbar_hint=\"true\">
251 <vbox>
252 <pixmap>
253 <input file>/usr/share/icons/Tango/32x32/places/user-desktop.png</input>
254 </pixmap>
255 <hbox>
256 <text use-markup=\"true\" width-chars=\"$CHARS_SIZE\">
257 <label>
258 \"<b>$DESKTOP_DIALOG_LABEL</b>
259 \"
260 </label>
261 </text>
262 </hbox>"
263 TAZUSB_DIALOG="
264 <hbox>
265 <checkbox>
266 <label>$DESKTOP_DIALOG_TAZUSB</label>
267 <variable>TAZUSB_WRITE</variable>
268 <default>false</default>
269 </checkbox>
270 <radiobutton>
271 <label>lzma</label>
272 <variable>LZMA</variable>
273 </radiobutton>
274 <radiobutton active=\"true\">
275 <label>gzip</label>
276 <variable>GZIP</variable>
277 </radiobutton>
278 <radiobutton>
279 <label>none</label>
280 <variable>NONE</variable>
281 </radiobutton>
282 </hbox>"
283 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; };"
284 [ -f /home/boot/rootfs.gz ] || { TAZUSB_DIALOG=""; EXTRA=""; }
285 # Logout for Openbox or JWM and system shutdown or reboot.
286 ACTIONS="
287 <hbox>
288 <button>
289 <label>$DESKTOP_LOGOUT_BUTTON</label>
290 <input file icon=\"video-display\"></input>
291 <action>$EXTRA openbox --exit || jwm -exit</action>
292 <action type=\"exit\">Exit</action>
293 </button>
294 <button>
295 <label>$DESKTOP_SHUTDOWN_BUTTON</label>
296 <input file icon=\"system-shutdown\"></input>
297 <action>$EXTRA poweroff</action>
298 <action type=\"exit\">Exit</action>
299 </button>
300 <button>
301 <label>$DESKTOP_REBOOT_BUTTON</label>
302 <input file icon=\"reload\"></input>
303 <action>$EXTRA reboot</action>
304 <action type=\"exit\">Exit</action>
305 </button>
306 <button cancel>
307 <action type=\"exit\">Exit</action>
308 </button>
309 </hbox>
310 </vbox>
311 </window>"
312 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${TAZUSB_DIALOG}${ACTIONS} ;;
313 notify)
314 # Nofification message without window decoration.
315 MSG="$2"
316 SEC=$3
317 [ -z $SEC ] && SEC=4
318 export NOTIFY_BOX="
319 <window decorated=\"false\" skip_taskbar_hint=\"true\">
320 <vbox>
321 <text width-chars=\"64\" use-markup=\"true\">
322 <label>\"
323 <b>$MSG</b>
324 \"</label>
325 </text>
326 </vbox>
327 </window>"
328 gtkdialog --center --program=NOTIFY_BOX >/dev/null &
329 sleep $SEC
330 pid=`ps | grep NOTIFY_BOX | awk '{ print $1 }'`
331 kill $pid 2>/dev/null
332 exit 0 ;;
333 autostart)
334 # Autostarted apps management. Functions are used for input
335 # and actions
336 export DESKTOP_DIALOG='
337 <window title="Auto start applications with Openbox" icon-name="preferences-system-session">
338 <vbox>
339 <tree>
340 <width>540</width><height>200</height>
341 <variable>APPLICATION</variable>
342 <label>Application|Comment</label>
343 <input icon_column="0">$BIN autostart_list</input>
344 <action>$BIN autostart_actions</action>
345 <action>refresh:APPLICATION</action>
346 </tree>
347 <hbox>
348 <text width-chars="36">
349 <label>
350 "Double click to enable/disable an application"
351 </label>
352 </text>
353 <button>
354 <label>Add</label>
355 <input file icon="gtk-add"></input>
356 <action>$BIN add_autostarted_app_box</action>
357 <action>refresh:APPLICATION</action>
358 </button>
359 <button>
360 <label>Configuration</label>
361 <input file icon="accessories-text-editor"></input>
362 <action>editor $AUTOSTART_SCRIPT</action>
363 <action>refresh:APPLICATION</action>
364 </button>
365 <button>
366 <label>Exit</label>
367 <input file icon="exit"></input>
368 <action type="exit">exit</action>
369 </button>
370 </hbox>
371 </vbox>
372 </window>'
373 ;;
374 tazapps)
375 # Default applications configuration script. System wide config file
376 # is /etc/slitaz/applications.conf and each user can have personnal
377 # settings. System wide for root and personnal config for user.
378 export CONFIG="$HOME/.config/slitaz/applications.conf"
379 if [ ! -f $CONFIG ]; then
380 mkdir -p $HOME/.config/slitaz
381 cp /etc/slitaz/applications.conf $CONFIG
382 fi
383 export DESKTOP_DIALOG='
384 <window title="SliTaz default applications" icon-name="preferences-desktop">
385 <vbox>
386 <vbox>
387 <text use-markup="true" width-chars="54">
388 <label>"
389 <b>SliTaz default applications configuration</b>
390 "</label>
391 </text>
392 </vbox>
393 <hbox>
394 <text wrap="false">
395 <label>"File manager: "</label>
396 </text>
397 <entry>
398 <input>. $CONFIG; echo $FILE_MANAGER</input>
399 <variable>FILE_MANAGER</variable>
400 </entry>
401 <button>
402 <label>Change</label>
403 <input file icon="forward"></input>
404 <action>sed -i s/"FILE_MANAGER=.*"/"FILE_MANAGER=\"$FILE_MANAGER\""/ $CONFIG</action>
405 </button>
406 </hbox>
407 <hbox>
408 <text wrap="false">
409 <label>"Web browser: "</label>
410 </text>
411 <entry>
412 <input>. $CONFIG; echo $BROWSER</input>
413 <variable>BROWSER</variable>
414 </entry>
415 <button>
416 <label>Change</label>
417 <input file icon="forward"></input>
418 <action>sed -i s/"BROWSER=.*"/"BROWSER=\"$BROWSER\""/ $CONFIG</action>
419 </button>
420 </hbox>
421 <hbox>
422 <text wrap="false">
423 <label>"Text editor: "</label>
424 </text>
425 <entry>
426 <input>. $CONFIG; echo $EDITOR</input>
427 <variable>EDITOR</variable>
428 </entry>
429 <button>
430 <label>Change</label>
431 <input file icon="forward"></input>
432 <action>sed -i s/"EDITOR=.*"/"EDITOR=\"$EDITOR\""/ $CONFIG</action>
433 </button>
434 </hbox>
435 <hbox>
436 <text wrap="false">
437 <label>"Terminal: "</label>
438 </text>
439 <entry>
440 <input>. $CONFIG; echo $TERMINAL</input>
441 <variable>TERMINAL</variable>
442 </entry>
443 <button>
444 <label>Change</label>
445 <input file icon="forward"></input>
446 <action>sed -i s/"TERMINAL=.*"/"TERMINAL=\"$TERMINAL\""/ $CONFIG</action>
447 </button>
448 </hbox>
449 <hbox>
450 <text wrap="false">
451 <label>"Window manager:"</label>
452 </text>
453 <entry>
454 <input>. $CONFIG; echo $WINDOW_MANAGER</input>
455 <variable>WINDOW_MANAGER</variable>
456 </entry>
457 <button>
458 <label>Change</label>
459 <input file icon="forward"></input>
460 <action>sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WINDOW_MANAGER\""/ $CONFIG</action>
461 </button>
462 </hbox>
463 <hbox>
464 <button>
465 <label>Exit</label>
466 <input file icon="exit"></input>
467 <action type="exit">exit</action>
468 </button>
469 </hbox>
470 </vbox>
471 </window>' ;;
472 *_*)
473 # Exec all function called by args (must have an underscore).
474 $1
475 exit 0 ;;
476 *)
477 # Usage if executed from cmdline.
478 #
479 usage
480 exit 0 ;;
481 esac
483 gtkdialog --center --program=DESKTOP_DIALOG >/dev/null
485 exit 0