slitaz-tools view tinyutils/desktopbox @ rev 208

calendar: no more hardcoded date
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue May 27 15:32:37 2008 +0000 (2008-05-27)
parents dbf2e0b2feb7
children db0e82bebc70
line source
1 #! /bin/sh
2 #
3 # Multi-call script provinding GTK boxes to manage a desktop following
4 # Freedesktop standars.
5 #
6 # (C) GNU gpl v3 - SliTaz GNU/Linux 2008.
7 #
8 VERSION=20080512
10 # Glade XML file path.
11 GLADE_XML=/usr/share/slitaz-tools/glade
13 # Standards 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="Creat a new folder on the desktop:"
21 FOLDER_ENTRY_MSG="dirname"
22 NEW_FILE_LABEL="Creat a new file on the desktop:"
23 FILE_ENTRY_MSG="filename"
24 ADD_ICON_LABEL="Add some desktop icons"
25 DESKTOP_DIALOG_LABEL="Session logout, system shutdown or reboot" ;;
26 fr*)
27 lang="fr"
28 NEW_FOLDER_LABEL="Créer un nouveau dossier sur le bureau:"
29 FOLDER_ENTRY_MSG="dossier"
30 NEW_FILE_LABEL="Créer un nouveau fichier sur le bureau:"
31 FILE_ENTRY_MSG="fichier"
32 ADD_ICON_LABEL="Ajouter des icons de bureau"
33 DESKTOP_DIALOG_LABEL="Déconnexion, arrêt ou redémarrage du système" ;;
34 *)
35 lang=""
36 NEW_FOLDER_LABEL="Creat a new folder on the desktop:"
37 FOLDER_ENTRY_MSG="dirname"
38 NEW_FILE_LABEL="Creat a new file on the desktop:"
39 FILE_ENTRY_MSG="filename"
40 ADD_ICON_LABEL="Add some desktop icons"
41 DESKTOP_DIALOG_LABEL="Session logout, system shutdown or reboot" ;;
42 esac
44 # Command line usage.
45 usage()
46 {
47 echo -e "\nSliTaz Freedesktop Box - Version: $VERSION\n
48 \033[1mUsage: \033[0m `basename $0` command
49 \033[1mCommands: \033[0m\n
50 new-folder Creat a new folder on the desktop with mkdir.
51 new-file Creat a new empty file or SHell script on the desktop.
52 add-icons Add a system icon on the desktop.
53 calendar Display a calendard under mouse pointer.
54 logout Prompt for X session exit or system halt/reboot.\n"
55 }
57 # Box commands.
58 case $1 in
59 new-folder)
60 # Creat a directory on the ~/desktop.
61 #
62 DESKTOP_DIALOG="
63 <window title=\"Desktopbox - mkdir\" icon-name=\"folder-new\">
64 <vbox>
66 <text use-markup=\"true\" width-chars=\"40\">
67 <label>\"
68 <b>$NEW_FOLDER_LABEL</b>\"
69 </label>
70 </text>
72 <hbox>
73 <entry>
74 <default>$FOLDER_ENTRY_MSG</default>
75 <variable>DIR</variable>
76 </entry>
77 </hbox>"
78 ACTIONS='
79 <hbox>
80 <button>
81 <label>Mkdir</label>
82 <input file icon="folder-new"></input>
83 <action>mkdir -p "$HOME/Desktop/$DIR"</action>
84 <action type="exit">Exit</action>
85 </button>
86 <button cancel>
87 <action type="exit">Exit</action>
88 </button>
89 </hbox>
91 </vbox>
92 </window>'
93 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
94 new-file)
95 # Creat a file on the ~/desktop.
96 #
97 DESKTOP_DIALOG="
98 <window title=\"Desktopbox - touch/cat\" icon-name=\"document-new\">
99 <vbox>
100 <text use-markup=\"true\" width-chars=\"40\">
101 <label>\"
102 <b>$NEW_FILE_LABEL</b>\"
103 </label>
104 </text>
106 <hbox>
107 <entry>
108 <default>$FILE_ENTRY_MSG</default>
109 <variable>FILE</variable>
110 </entry>
111 </hbox>"
112 ACTIONS='
113 <hbox>
114 <button>
115 <label>SH script</label>
116 <input file icon="document-new"></input>
117 <action>echo "#!/bin/sh" > "$HOME/Desktop/$FILE"</action>
118 <action>echo "#" >> "$HOME/Desktop/$FILE"</action>
119 <action>chmod +x "$HOME/Desktop/$FILE"</action>
120 <action type="exit">Exit</action>
121 </button>
122 <button>
123 <label>Empty</label>
124 <input file icon="document-new"></input>
125 <action>touch "$HOME/Desktop/$FILE"</action>
126 <action type="exit">Exit</action>
127 </button>
128 <button cancel>
129 <action type="exit">Exit</action>
130 </button>
131 </hbox>
132 </vbox>
133 </window>'
134 export DESKTOP_DIALOG="${DESKTOP_DIALOG}${ACTIONS}" ;;
135 add-icons)
136 # Add a new icons on the ~/desktop from /usr/share/applications.
137 #
138 DESKTOP_DIALOG="
139 <window title=\"$ADD_ICON_LABEL\" icon-name=\"document-new\">
140 <vbox>
141 <text use-markup=\"true\" width-chars=\"40\">
142 <label>\"
143 <b>$ADD_ICON_LABEL</b>
144 \"
145 </label>
146 </text>
147 <tree headers_visible=\"false\">
148 <width>420</width><height>200</height>
149 <variable>ICON</variable>
150 <label>Filename|Application</label>"
151 # Get application name and icon.
152 cd /usr/share/applications
153 for file in *.desktop
154 do
155 # Try to get the name in the right locale.
156 NAME=`grep ^Name $file | grep $lang || grep ^Name= $file`
157 NAME=`echo $NAME | cut -d "=" -f 2`
158 ICON=`grep ^Icon= $file | cut -d "=" -f 2`
159 ICON=`basename $ICON`
160 ICON=${ICON%.*}
161 FILE=${file%.desktop}
162 ITEM="<item icon=\"$ICON\">$FILE | $NAME</item>"
163 DESKTOP_DIALOG="${DESKTOP_DIALOG}${ITEM}"
164 done
165 ACTIONS='<action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
166 </tree>
167 <hbox>
168 <button>
169 <label>Add</label>
170 <input file icon="gtk-add"></input>
171 <action>cp /usr/share/applications/$ICON.desktop ~/Desktop</action>
172 </button>
173 <button>
174 <label>Exit</label>
175 <input file icon="exit"></input>
176 <action type="exit">Exit</action>
177 </button>
178 </hbox>
179 </vbox>
180 </window>'
181 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${ACTIONS} ;;
182 calendar)
183 # Calendar using glade file.
184 #
185 gtkdialog --glade-xml=$GLADE_XML/calendar.glade \
186 --program=MAIN_WINDOW ;;
187 logout)
188 # X session/system logout.
189 #
190 DESKTOP_DIALOG="
191 <window title=\"SliTaz Desktop logout\" icon-name=\"user-desktop\">
192 <vbox>
193 <pixmap>
194 <input file>/usr/share/icons/Tango/32x32/places/user-desktop.png</input>
195 </pixmap>
196 <hbox>
197 <text use-markup=\"true\" width-chars=\"64\">
198 <label>
199 \"<b>$DESKTOP_DIALOG_LABEL</b>
200 \"
201 </label>
202 </text>
203 </hbox>"
204 # Logout for Openbox or JWM and system shutdown or reboot.
205 ACTIONS='
206 <hbox>
207 <button>
208 <label>Logout X session</label>
209 <input file icon="video-display"></input>
210 <action>openbox --exit || jwm -exit</action>
211 <action type="exit">Exit</action>
212 </button>
213 <button>
214 <label>Shutdown computer</label>
215 <input file icon="system-shutdown"></input>
216 <action>poweroff</action>
217 <action type="exit">Exit</action>
218 </button>
219 <button>
220 <label>Reboot system</label>
221 <input file icon="reload"></input>
222 <action>reboot</action>
223 <action type="exit">Exit</action>
224 </button>
225 <button cancel>
226 <action type="exit">Exit</action>
227 </button>
228 </hbox>
230 </vbox>
231 </window>'
232 export DESKTOP_DIALOG=${DESKTOP_DIALOG}${ACTIONS} ;;
233 *)
234 # Usage if executet from cmdline.
235 #
236 usage
237 exit 0 ;;
238 esac
240 gtkdialog --center --program=DESKTOP_DIALOG >/dev/null
242 exit 0