slitaz-tools view tinyutils/desktopbox @ rev 549

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