slitaz-tools view tinyutils/desktopbox @ rev 294

desktopbox: add notification support
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 20 00:05:58 2009 +0100 (2009-02-20)
parents 16a335d7c86a
children c90e38d22ae6
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
13 # Standard directories.
14 mkdir -p $HOME/Desktop $HOME/.local/share/applications
16 # Get the active locale (default to English).
17 case $LANG in
18 es*)
19 lang="es"
20 NEW_FOLDER_LABEL="Create a new folder on the desktop:"
21 FOLDER_ENTRY_MSG="dirname"
22 NEW_FILE_LABEL="Create a new file on the desktop:"
23 FILE_ENTRY_MSG="filename"
24 ADD_ICON_LABEL="Add some desktop icons"
25 CHARS_SIZE="64"
26 DESKTOP_DIALOG_TAZUSB="Save filesystem using compression"
27 DESKTOP_DIALOG_LABEL="Session logout, system shutdown or reboot"
28 DESKTOP_LOGOUT_BUTTON="Logout X session"
29 DESKTOP_SHUTDOWN_BUTTON="Shutdown computer"
30 DESKTOP_REBOOT_BUTTON="Reboot system" ;;
31 fr*)
32 lang="fr"
33 NEW_FOLDER_LABEL="Créer un nouveau dossier sur le bureau:"
34 FOLDER_ENTRY_MSG="dossier"
35 NEW_FILE_LABEL="Créer un nouveau fichier sur le bureau:"
36 FILE_ENTRY_MSG="fichier"
37 ADD_ICON_LABEL="Ajouter des icônes de bureau"
38 CHARS_SIZE="72"
39 DESKTOP_DIALOG_TAZUSB="Enregistrer le système avec la compression"
40 DESKTOP_DIALOG_LABEL="Déconnexion, arrêt ou redémarrage du système"
41 DESKTOP_LOGOUT_BUTTON="Fermer la session X"
42 DESKTOP_SHUTDOWN_BUTTON="Eteindre le système"
43 DESKTOP_REBOOT_BUTTON="Redémarrer le système" ;;
44 *)
45 lang=""
46 NEW_FOLDER_LABEL="Create a new folder on the desktop:"
47 FOLDER_ENTRY_MSG="dirname"
48 NEW_FILE_LABEL="Create a new file on the desktop:"
49 FILE_ENTRY_MSG="filename"
50 ADD_ICON_LABEL="Add some desktop icons"
51 CHARS_SIZE="64"
52 DESKTOP_DIALOG_TAZUSB="Save filesystem using compression"
53 DESKTOP_DIALOG_LABEL="Session logout, system shutdown or reboot"
54 DESKTOP_LOGOUT_BUTTON="Logout X session"
55 DESKTOP_SHUTDOWN_BUTTON="Shutdown computer"
56 DESKTOP_REBOOT_BUTTON="Reboot system" ;;
57 esac
59 # Command line usage.
60 usage()
61 {
62 echo -e "\nSliTaz Freedesktop Box - Version: $VERSION\n
63 \033[1mUsage: \033[0m `basename $0` command
64 \033[1mCommands: \033[0m\n
65 new-folder Create a new folder on the desktop with mkdir.
66 new-file Create a new empty file or SHell script on the desktop.
67 add-icons Add a system icon on the desktop.
68 calendar Display a calendar under mouse pointer.
69 notify Display a notification message (center/no decoration).
70 Ex: `basename $0` notify \"Message to display\" 4
71 logout Prompt for X session exit or system halt/reboot.\n"
72 }
74 # Box commands.
75 case $1 in
76 new-folder)
77 # Create a directory on the ~/Desktop.
78 #
79 DESKTOP_DIALOG="
80 <window title=\"Desktopbox - mkdir\" icon-name=\"folder-new\">
81 <vbox>
83 <text use-markup=\"true\" width-chars=\"40\">
84 <label>\"
85 <b>$NEW_FOLDER_LABEL</b>\"
86 </label>
87 </text>
89 <hbox>
90 <entry>
91 <default>$FOLDER_ENTRY_MSG</default>
92 <variable>DIR</variable>
93 </entry>
94 </hbox>"
95 ACTIONS='
96 <hbox>
97 <button>
98 <label>Mkdir</label>
99 <input file icon="folder-new"></input>
100 <action>mkdir -p "$HOME/Desktop/$DIR"</action>
101 <action type="exit">Exit</action>
102 </button>
103 <button cancel>
104 <action type="exit">Exit</action>
105 </button>
106 </hbox>
108 </vbox>
109 </window>'
110 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
111 new-file)
112 # Create a file on the ~/Desktop.
113 #
114 DESKTOP_DIALOG="
115 <window title=\"Desktopbox - touch/cat\" icon-name=\"document-new\">
116 <vbox>
117 <text use-markup=\"true\" width-chars=\"40\">
118 <label>\"
119 <b>$NEW_FILE_LABEL</b>\"
120 </label>
121 </text>
123 <hbox>
124 <entry>
125 <default>$FILE_ENTRY_MSG</default>
126 <variable>FILE</variable>
127 </entry>
128 </hbox>"
129 ACTIONS='
130 <hbox>
131 <button>
132 <label>SH script</label>
133 <input file icon="document-new"></input>
134 <action>echo "#!/bin/sh" > "$HOME/Desktop/$FILE"</action>
135 <action>echo "#" >> "$HOME/Desktop/$FILE"</action>
136 <action>chmod +x "$HOME/Desktop/$FILE"</action>
137 <action type="exit">Exit</action>
138 </button>
139 <button>
140 <label>Empty</label>
141 <input file icon="document-new"></input>
142 <action>touch "$HOME/Desktop/$FILE"</action>
143 <action type="exit">Exit</action>
144 </button>
145 <button cancel>
146 <action type="exit">Exit</action>
147 </button>
148 </hbox>
149 </vbox>
150 </window>'
151 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
152 add-icons)
153 # Add new icons on the ~/Desktop from /usr/share/applications.
154 #
155 DESKTOP_DIALOG="
156 <window title=\"$ADD_ICON_LABEL\" icon-name=\"document-new\">
157 <vbox>
158 <text use-markup=\"true\" width-chars=\"40\">
159 <label>\"
160 <b>$ADD_ICON_LABEL</b>
161 \"
162 </label>
163 </text>
164 <tree headers_visible=\"false\">
165 <width>420</width><height>200</height>
166 <variable>ICON</variable>
167 <label>Filename|Application</label>"
168 # Get application name and icon.
169 cd /usr/share/applications
170 for file in *.desktop
171 do
172 # Try to get the name in the right locale.
173 NAME=`grep ^Name $file | grep $lang || grep ^Name= $file`
174 NAME=`echo $NAME | cut -d "=" -f 2`
175 ICON=`grep ^Icon= $file | cut -d "=" -f 2`
176 ICON=`basename $ICON`
177 ICON=${ICON%.*}
178 FILE=${file%.desktop}
179 ITEM="<item icon=\"$ICON\">$FILE | $NAME</item>"
180 DESKTOP_DIALOG="${DESKTOP_DIALOG}${ITEM}"
181 done
182 ACTIONS='<action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
183 </tree>
184 <hbox>
185 <button>
186 <label>Add</label>
187 <input file icon="gtk-add"></input>
188 <action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
189 </button>
190 <button>
191 <label>Exit</label>
192 <input file icon="exit"></input>
193 <action type="exit">Exit</action>
194 </button>
195 </hbox>
196 </vbox>
197 </window>'
198 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${ACTIONS} ;;
199 calendar)
200 # Calendar using glade file.
201 #
202 gtkdialog --glade-xml=$GLADE_XML/calendar.glade \
203 --program=MAIN_WINDOW ;;
204 logout)
205 # X session/system logout.
206 #
207 DESKTOP_DIALOG="
208 <window title=\"SliTaz Desktop logout\" icon-name=\"user-desktop\" skip_taskbar_hint=\"true\">
209 <vbox>
210 <pixmap>
211 <input file>/usr/share/icons/Tango/32x32/places/user-desktop.png</input>
212 </pixmap>
213 <hbox>
214 <text use-markup=\"true\" width-chars=\"$CHARS_SIZE\">
215 <label>
216 \"<b>$DESKTOP_DIALOG_LABEL</b>
217 \"
218 </label>
219 </text>
220 </hbox>"
221 TAZUSB_DIALOG="
222 <hbox>
223 <checkbox>
224 <label>$DESKTOP_DIALOG_TAZUSB</label>
225 <variable>TAZUSB_WRITE</variable>
226 <default>false</default>
227 </checkbox>
228 <radiobutton>
229 <label>lzma</label>
230 <variable>LZMA</variable>
231 </radiobutton>
232 <radiobutton active=\"true\">
233 <label>gzip</label>
234 <variable>GZIP</variable>
235 </radiobutton>
236 <radiobutton>
237 <label>none</label>
238 <variable>NONE</variable>
239 </radiobutton>
240 </hbox>"
241 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; };"
242 [ -f /home/boot/rootfs.gz ] || { TAZUSB_DIALOG=""; EXTRA=""; }
243 # Logout for Openbox or JWM and system shutdown or reboot.
244 ACTIONS="
245 <hbox>
246 <button>
247 <label>$DESKTOP_LOGOUT_BUTTON</label>
248 <input file icon=\"video-display\"></input>
249 <action>$EXTRA openbox --exit || jwm -exit</action>
250 <action type=\"exit\">Exit</action>
251 </button>
252 <button>
253 <label>$DESKTOP_SHUTDOWN_BUTTON</label>
254 <input file icon=\"system-shutdown\"></input>
255 <action>$EXTRA poweroff</action>
256 <action type=\"exit\">Exit</action>
257 </button>
258 <button>
259 <label>$DESKTOP_REBOOT_BUTTON</label>
260 <input file icon=\"reload\"></input>
261 <action>$EXTRA reboot</action>
262 <action type=\"exit\">Exit</action>
263 </button>
264 <button cancel>
265 <action type=\"exit\">Exit</action>
266 </button>
267 </hbox>
268 </vbox>
269 </window>"
270 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${TAZUSB_DIALOG}${ACTIONS} ;;
271 notify)
272 # Nofification message without window decoration.
273 MSG="$2"
274 SEC=$3
275 [ -z $SEC ] && SEC=2
276 export NOTIFY_BOX="
277 <window decorated=\"false\" skip_taskbar_hint=\"true\">
278 <vbox>
279 <text width-chars=\"64\" use-markup=\"true\">
280 <label>\"
281 $MSG
282 \"</label>
283 </text>
284 </vbox>
285 </window>"
286 gtkdialog --center --program=NOTIFY_BOX >/dev/null &
287 sleep $SEC
288 pid=`ps | grep NOTIFY_BOX | awk '{ print $1 }'`
289 kill $pid 2>/dev/null
290 exit 0 ;;
291 *)
292 # Usage if executed from cmdline.
293 #
294 usage
295 exit 0 ;;
296 esac
298 gtkdialog --center --program=DESKTOP_DIALOG >/dev/null
300 exit 0