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