slitaz-tools view tinyutils/desktopbox @ rev 268

desktopbox logout: add tazusb support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Oct 12 11:46:22 2008 +0000 (2008-10-12)
parents db0e82bebc70
children 77c872f708ab
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 DESKTOP_DIALOG_TAZUSB="Save filesystem using compression"
26 DESKTOP_DIALOG_LABEL="Session logout, system shutdown or reboot" ;;
27 fr*)
28 lang="fr"
29 NEW_FOLDER_LABEL="Créer un nouveau dossier sur le bureau:"
30 FOLDER_ENTRY_MSG="dossier"
31 NEW_FILE_LABEL="Créer un nouveau fichier sur le bureau:"
32 FILE_ENTRY_MSG="fichier"
33 ADD_ICON_LABEL="Ajouter des icons de bureau"
34 DESKTOP_DIALOG_TAZUSB="Enregistrer le système avec la compression"
35 DESKTOP_DIALOG_LABEL="Déconnexion, arrêt ou redémarrage du système" ;;
36 *)
37 lang=""
38 NEW_FOLDER_LABEL="Create a new folder on the desktop:"
39 FOLDER_ENTRY_MSG="dirname"
40 NEW_FILE_LABEL="Create a new file on the desktop:"
41 FILE_ENTRY_MSG="filename"
42 ADD_ICON_LABEL="Add some desktop icons"
43 DESKTOP_DIALOG_TAZUSB="Save filesystem using compression"
44 DESKTOP_DIALOG_LABEL="Session logout, system shutdown or reboot" ;;
45 esac
47 # Command line usage.
48 usage()
49 {
50 echo -e "\nSliTaz Freedesktop Box - Version: $VERSION\n
51 \033[1mUsage: \033[0m `basename $0` command
52 \033[1mCommands: \033[0m\n
53 new-folder Create a new folder on the desktop with mkdir.
54 new-file Create a new empty file or SHell script on the desktop.
55 add-icons Add a system icon on the desktop.
56 calendar Display a calendar under mouse pointer.
57 logout Prompt for X session exit or system halt/reboot.\n"
58 }
60 # Box commands.
61 case $1 in
62 new-folder)
63 # Create a directory on the ~/Desktop.
64 #
65 DESKTOP_DIALOG="
66 <window title=\"Desktopbox - mkdir\" icon-name=\"folder-new\">
67 <vbox>
69 <text use-markup=\"true\" width-chars=\"40\">
70 <label>\"
71 <b>$NEW_FOLDER_LABEL</b>\"
72 </label>
73 </text>
75 <hbox>
76 <entry>
77 <default>$FOLDER_ENTRY_MSG</default>
78 <variable>DIR</variable>
79 </entry>
80 </hbox>"
81 ACTIONS='
82 <hbox>
83 <button>
84 <label>Mkdir</label>
85 <input file icon="folder-new"></input>
86 <action>mkdir -p "$HOME/Desktop/$DIR"</action>
87 <action type="exit">Exit</action>
88 </button>
89 <button cancel>
90 <action type="exit">Exit</action>
91 </button>
92 </hbox>
94 </vbox>
95 </window>'
96 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
97 new-file)
98 # Create a file on the ~/Desktop.
99 #
100 DESKTOP_DIALOG="
101 <window title=\"Desktopbox - touch/cat\" icon-name=\"document-new\">
102 <vbox>
103 <text use-markup=\"true\" width-chars=\"40\">
104 <label>\"
105 <b>$NEW_FILE_LABEL</b>\"
106 </label>
107 </text>
109 <hbox>
110 <entry>
111 <default>$FILE_ENTRY_MSG</default>
112 <variable>FILE</variable>
113 </entry>
114 </hbox>"
115 ACTIONS='
116 <hbox>
117 <button>
118 <label>SH script</label>
119 <input file icon="document-new"></input>
120 <action>echo "#!/bin/sh" > "$HOME/Desktop/$FILE"</action>
121 <action>echo "#" >> "$HOME/Desktop/$FILE"</action>
122 <action>chmod +x "$HOME/Desktop/$FILE"</action>
123 <action type="exit">Exit</action>
124 </button>
125 <button>
126 <label>Empty</label>
127 <input file icon="document-new"></input>
128 <action>touch "$HOME/Desktop/$FILE"</action>
129 <action type="exit">Exit</action>
130 </button>
131 <button cancel>
132 <action type="exit">Exit</action>
133 </button>
134 </hbox>
135 </vbox>
136 </window>'
137 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
138 add-icons)
139 # Add new icons on the ~/Desktop from /usr/share/applications.
140 #
141 DESKTOP_DIALOG="
142 <window title=\"$ADD_ICON_LABEL\" icon-name=\"document-new\">
143 <vbox>
144 <text use-markup=\"true\" width-chars=\"40\">
145 <label>\"
146 <b>$ADD_ICON_LABEL</b>
147 \"
148 </label>
149 </text>
150 <tree headers_visible=\"false\">
151 <width>420</width><height>200</height>
152 <variable>ICON</variable>
153 <label>Filename|Application</label>"
154 # Get application name and icon.
155 cd /usr/share/applications
156 for file in *.desktop
157 do
158 # Try to get the name in the right locale.
159 NAME=`grep ^Name $file | grep $lang || grep ^Name= $file`
160 NAME=`echo $NAME | cut -d "=" -f 2`
161 ICON=`grep ^Icon= $file | cut -d "=" -f 2`
162 ICON=`basename $ICON`
163 ICON=${ICON%.*}
164 FILE=${file%.desktop}
165 ITEM="<item icon=\"$ICON\">$FILE | $NAME</item>"
166 DESKTOP_DIALOG="${DESKTOP_DIALOG}${ITEM}"
167 done
168 ACTIONS='<action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
169 </tree>
170 <hbox>
171 <button>
172 <label>Add</label>
173 <input file icon="gtk-add"></input>
174 <action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
175 </button>
176 <button>
177 <label>Exit</label>
178 <input file icon="exit"></input>
179 <action type="exit">Exit</action>
180 </button>
181 </hbox>
182 </vbox>
183 </window>'
184 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${ACTIONS} ;;
185 calendar)
186 # Calendar using glade file.
187 #
188 gtkdialog --glade-xml=$GLADE_XML/calendar.glade \
189 --program=MAIN_WINDOW ;;
190 logout)
191 # X session/system logout.
192 #
193 DESKTOP_DIALOG="
194 <window title=\"SliTaz Desktop logout\" icon-name=\"user-desktop\">
195 <vbox>
196 <pixmap>
197 <input file>/usr/share/icons/Tango/32x32/places/user-desktop.png</input>
198 </pixmap>
199 <hbox>
200 <text use-markup=\"true\" width-chars=\"64\">
201 <label>
202 \"<b>$DESKTOP_DIALOG_LABEL</b>
203 \"
204 </label>
205 </text>
206 </hbox>"
207 TAZUSB_DIALOG="
208 <hbox>
209 <checkbox>
210 <label>$DESKTOP_DIALOG_TAZUSB</label>
211 <variable>TAZUSB_WRITE</variable>
212 <default>false</default>
213 </checkbox>
214 <radiobutton>
215 <label>lzma</label>
216 <variable>LZMA</variable>
217 </radiobutton>
218 <radiobutton active=\"true\">
219 <label>gzip</label>
220 <variable>GZIP</variable>
221 </radiobutton>
222 <radiobutton>
223 <label>none</label>
224 <variable>NONE</variable>
225 </radiobutton>
226 </hbox>"
227 EXTRA="COMP=none; [ '\$LZMA' = 'true' ] && COMP=lzma; [ '\$GZIP' = 'true' ] && COMP=gzip; [ '\$TAZUSB_WRITE' = 'true' ] && subox 'xterm -e \"tazusb writefs \$COMP\"';"
228 #[ -f /home/boot/rootfs.gz ] || { TAZUSB_DIALOG=""; EXTRA=""; }
229 # Logout for Openbox or JWM and system shutdown or reboot.
230 ACTIONS="
231 <hbox>
232 <button>
233 <label>Logout X session</label>
234 <input file icon=\"video-display\"></input>
235 <action>$EXTRA; openbox --exit || jwm -exit</action>
236 <action type=\"exit\">Exit</action>
237 </button>
238 <button>
239 <label>Shutdown computer</label>
240 <input file icon=\"system-shutdown\"></input>
241 <action>$EXTRA; poweroff</action>
242 <action type=\"exit\">Exit</action>
243 </button>
244 <button>
245 <label>Reboot system</label>
246 <input file icon=\"reload\"></input>
247 <action>$EXTRA; reboot</action>
248 <action type=\"exit\">Exit</action>
249 </button>
250 <button cancel>
251 <action type=\"exit\">Exit</action>
252 </button>
253 </hbox>
255 </vbox>
256 </window>"
257 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${TAZUSB_DIALOG}${ACTIONS} ;;
258 *)
259 # Usage if executed from cmdline.
260 #
261 usage
262 exit 0 ;;
263 esac
265 gtkdialog --center --program=DESKTOP_DIALOG >/dev/null
267 exit 0