blob: db65efa4277c6ddd989814bd1a5a4b4a4ef2d986 [file] [log] [blame]
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +00001#!/bin/sh
2#
3# Create menu/desktop entries for an application
4# This is used by the IShellLink interface
5#
6# Copyright 2000 Alexandre Julliard
7#
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00008# This library is free software; you can redistribute it and/or
9# modify it under the terms of the GNU Lesser General Public
10# License as published by the Free Software Foundation; either
11# version 2.1 of the License, or (at your option) any later version.
12#
13# This library is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public
19# License along with this library; if not, write to the Free Software
Jonathan Ernst360a3f92006-05-18 14:49:52 +020020# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000021#
22
Bill Medlandd5739ed2005-12-19 21:25:52 +010023# Note that the link is a relative unix-style path name. Since the / character
24# is not valid in Windows filenames it is an adequate separator to show the
25# menu structure. (This program may need to split the menu structure out for
26# implementing xdg-style menus)
27
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +000028mode=""
29args=""
30menu=""
31icon=""
32descr=""
33link=""
34path=""
35workdir=""
36
37usage()
38{
39 cat <<EOF
40usage: wineshelllink options
41
42options:
43 --desktop create a desktop link
44 --menu create a menu entry
45 --path xx path to the application
Bill Medlandd5739ed2005-12-19 21:25:52 +010046 --link xx name of link to create, including path
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +000047 --args xx command-line arguments for the application
48 --icon xx icon to display
49 --workdir xx working directory for the application
50 --descr xx application description
51
52EOF
Francois Gougetbc4f8f92003-09-30 00:28:13 +000053 exit 2
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +000054}
55
Jeremy White8dad1d82001-01-17 20:17:03 +000056if [ $# -eq 0 ] ; then
57 usage
58fi
59
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +000060while [ $# -gt 0 ]
61do
62 case "$1" in
Simon Walton44b15b182001-12-14 22:45:06 +000063 --desktop) mode="desktop"; shift 1 ;;
64 --menu) mode="menu"; shift 1 ;;
65 --path) path="$2"; shift 2 ;;
66 --link) link="$2"; shift 2 ;;
67 --args) args="$2"; shift 2 ;;
68 --icon) icon="$2"; shift 2 ;;
69 --descr) descr="$2"; shift 2 ;;
70 --workdir) workdir="$2"; shift 2 ;;
71 *) usage ;;
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +000072 esac
73done
74
Francois Gougetbc4f8f92003-09-30 00:28:13 +000075if [ -z "$mode" ] ; then
76 echo "Either --desktop or --menu required"
Jeremy White8dad1d82001-01-17 20:17:03 +000077 usage
78fi
79
Francois Gougetbc4f8f92003-09-30 00:28:13 +000080if [ -z "$link" ] ; then
81 echo "You must specify a link name with --link"
Jeremy White8dad1d82001-01-17 20:17:03 +000082 usage
83fi
84
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +000085kde_entry()
86{
Marcus Meissner9c6af0a2001-12-13 00:58:20 +000087 xname=`basename "$link"`
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +000088 cat <<EOF
89# KDE Config File
90[KDE Desktop Entry]
Marcus Meissner9c6af0a2001-12-13 00:58:20 +000091Name=$xname
Marcus Meissnercb54fe62004-09-27 20:32:50 +000092Exec=wine '$path' $args
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +000093Type=Application
94Comment=$descr
95EOF
96 [ -z "$workdir" ] || echo "Path=\"$workdir\""
97 [ -z "$xpmicon" ] || echo "Icon=$xpmicon"
98}
99
100gnome_entry()
101{
Marcus Meissner9c6af0a2001-12-13 00:58:20 +0000102 xname=`basename "$link"`
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000103 cat <<EOF
104[Desktop Entry]
Marcus Meissner9c6af0a2001-12-13 00:58:20 +0000105Name=$xname
Marcus Meissnercb54fe62004-09-27 20:32:50 +0000106Exec=wine "$path" $args
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000107Type=Application
108Comment=$descr
109EOF
Vitaly Lipatov5072fd42006-03-26 19:06:54 +0400110 [ -z "$workdir" ] || echo "Path=$workdir"
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000111 [ -z "$xpmicon" ] || echo "Icon=$xpmicon"
112}
113
Dusan Lacko8e44ba12001-11-20 18:53:33 +0000114mdk_entry()
115{
116 base=`basename "$link"`
117 section=`dirname "$link"`
118 [ -z "$icon" ] || xicon="icon=\"$xpmicon\""
Brouard Nicolas555eaaf2005-03-10 17:16:22 +0000119 pathmenu=`echo "$path" | sed 's+\\\\+\\\\\\\\+g'`
120 echo "?package(local.Wine):needs=x11 section=\"/Wine/$section\" title=\"$base\" longtitle=\"$descr\" command=\"wine '$pathmenu' $args\" $xicon"
Dusan Lacko8e44ba12001-11-20 18:53:33 +0000121}
122
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000123# copy the icon file to a specified dir and set xpmicon to the resulting path
124copy_icon()
125{
Marcus Meissner9c6af0a2001-12-13 00:58:20 +0000126 dir="$1"
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000127 mkdir -p "$dir"
Andreas Mohr1a0eeb52000-12-14 20:30:35 +0000128 mkdir -p "$dir/""`dirname "$link"`" || true
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000129 if [ -f "$icon" ]
130 then
131 cp "$icon" "$dir/$link.xpm"
132 xpmicon="$dir/$link.xpm"
133 else
134 xpmicon=""
135 fi
136}
137
Dusan Lacko8e44ba12001-11-20 18:53:33 +0000138# Debian/Mandrake
139
Laurent Blumea79b48e2005-05-09 09:28:05 +0000140type update-menus > /dev/null 2>&1
Dusan Lacko8e44ba12001-11-20 18:53:33 +0000141if [ $? = 0 -a $mode = "menu" ]
142then
143 iconname="`basename "$link"`.xpm"
144 dir="$HOME/.menu/icons"
145 if [ -f "$icon" ]
146 then
Marcus Meissner9c6af0a2001-12-13 00:58:20 +0000147 mkdir -p "$dir"
Dusan Lacko8e44ba12001-11-20 18:53:33 +0000148 cp "$icon" "$dir/$iconname"
149 xpmicon="$dir/$iconname"
150 else
151 xpmicon=""
152 fi
153 mdk_entry >> "$HOME/.menu/wine"
Brouard Nicolas555eaaf2005-03-10 17:16:22 +0000154 if [ -d "/usr/lib/menu" ] && [ -w "/usr/lib/menu" ]
Dustin Navea35ba7b92002-04-29 19:33:09 +0000155 then
156 mdk_entry >> "/usr/lib/menu/wine"
157 fi
Dusan Lacko8e44ba12001-11-20 18:53:33 +0000158 update-menus > /dev/null 2>&1
159fi
160
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000161# KDE
162
163if [ -d "$HOME/.kde" ]
164then
Dustin Navea35ba7b92002-04-29 19:33:09 +0000165 kdeversion=0
Laurent Blumea79b48e2005-05-09 09:28:05 +0000166 if type kde-config >/dev/null 2>&1
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000167 then
Dustin Navea35ba7b92002-04-29 19:33:09 +0000168 kdeversion=`kde-config -v | grep KDE: | sed -n "s/^KDE: \([^.]*\)\..*$/\1/p"`
169 fi
Jeremy White8dad1d82001-01-17 20:17:03 +0000170
Dustin Navea1222aa62002-05-14 23:20:45 +0000171 if [ $kdeversion -ge 2 ]
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000172 then
Dustin Navea35ba7b92002-04-29 19:33:09 +0000173 copy_icon "$HOME/.kde/share/applnk/Wine"
174 if [ $mode = "menu" ]
175 then
176 gnome_entry > "$HOME/.kde/share/applnk/Wine/$link.desktop"
177 elif [ -d "$HOME/Desktop" ]
178 then
179 gnome_entry > "$HOME/Desktop/$link.desktop"
180 fi
181 else
182 copy_icon "$HOME/.kde/share/applnk/Wine"
183 if [ $mode = "menu" ]
184 then
185 kde_entry > "$HOME/.kde/share/applnk/Wine/$link.kdelnk"
186
187 # KDE 1.x kludge. Wake up KDE, if we can find kpanel running
Laurent Blumea79b48e2005-05-09 09:28:05 +0000188 type kwmcom >/dev/null 2>/dev/null && \
Dustin Navea35ba7b92002-04-29 19:33:09 +0000189 ps u -C kpanel >/dev/null 2>/dev/null && \
190 kwmcom kpanel:restart
191
192 elif [ -d "$HOME/Desktop" ]
193 then
194 kde_entry > "$HOME/Desktop/$link.kdelnk"
195 # KDE 1.x kludge: wake up KDE, if we can find kfm running...
Laurent Blumea79b48e2005-05-09 09:28:05 +0000196 type kfmclient >/dev/null 2>/dev/null && \
Dustin Navea35ba7b92002-04-29 19:33:09 +0000197 ps u -C kfm >/dev/null 2>/dev/null && \
198 kfmclient refreshDesktop
199 fi
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000200 fi
Marcus Meissnerb686a902001-03-08 01:12:52 +0000201fi
202
203if [ -d "$HOME/.kde2" ]
204then
205 copy_icon "$HOME/.kde2/share/applnk/Wine"
206 if [ $mode = "menu" ]
207 then
Marcus Meissnered9c2df2001-03-16 16:40:12 +0000208 gnome_entry > "$HOME/.kde2/share/applnk/Wine/$link.desktop"
Dustin Navea9df2e562002-05-23 16:31:22 +0000209 else
210 if [ -d "$HOME/Desktop2" ]
211 then
212 gnome_entry > "$HOME/Desktop2/$link.desktop"
213 fi
214 if [ -d "$HOME/Desktop" ]
215 then
216 gnome_entry > "$HOME/Desktop/$link.desktop"
217 fi
218 fi
219fi
220
221if [ -d "$HOME/.kde3/share/applnk" ]
222then
223 copy_icon "$HOME/.kde3/share/applnk/Wine"
224 if [ $mode = "menu" ]
Dustin Navea1222aa62002-05-14 23:20:45 +0000225 then
Dustin Navea9df2e562002-05-23 16:31:22 +0000226 gnome_entry > "$HOME/.kde3/share/applnk/Wine/$link.desktop"
227 else
228 if [ -d "$HOME/Desktop3" ]
229 then
230 gnome_entry > "$HOME/Desktop3/$link.desktop"
231 fi
232 if [ -d "$HOME/Desktop2" ]
233 then
234 gnome_entry > "$HOME/Desktop2/$link.desktop"
235 fi
236 if [ -d "$HOME/Desktop" ]
237 then
238 gnome_entry > "$HOME/Desktop/$link.desktop"
239 fi
Marcus Meissnerb686a902001-03-08 01:12:52 +0000240 fi
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000241fi
242
Alexandre Julliarde2b4efb2000-11-02 20:22:07 +0000243# Gnome
244
245if [ -d "$HOME/.gnome" ]
246then
247 copy_icon "$HOME/.gnome/apps/Wine"
248 if [ $mode = "menu" ]
249 then
250 gnome_entry > "$HOME/.gnome/apps/Wine/$link.desktop"
251 elif [ -d "$HOME/.gnome-desktop" ]
252 then
253 gnome_entry > "$HOME/.gnome-desktop/$link.desktop"
254 fi
255fi
256
257exit 0