Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 1 | #!/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 Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 8 | # 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 Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 21 | # |
| 22 | |
Bill Medland | d5739ed | 2005-12-19 21:25:52 +0100 | [diff] [blame] | 23 | # 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 Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 28 | mode="" |
| 29 | args="" |
| 30 | menu="" |
| 31 | icon="" |
| 32 | descr="" |
| 33 | link="" |
| 34 | path="" |
| 35 | workdir="" |
| 36 | |
| 37 | usage() |
| 38 | { |
| 39 | cat <<EOF |
| 40 | usage: wineshelllink options |
| 41 | |
| 42 | options: |
| 43 | --desktop create a desktop link |
| 44 | --menu create a menu entry |
| 45 | --path xx path to the application |
Bill Medland | d5739ed | 2005-12-19 21:25:52 +0100 | [diff] [blame] | 46 | --link xx name of link to create, including path |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 47 | --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 | |
| 52 | EOF |
Francois Gouget | bc4f8f9 | 2003-09-30 00:28:13 +0000 | [diff] [blame] | 53 | exit 2 |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Jeremy White | 8dad1d8 | 2001-01-17 20:17:03 +0000 | [diff] [blame] | 56 | if [ $# -eq 0 ] ; then |
| 57 | usage |
| 58 | fi |
| 59 | |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 60 | while [ $# -gt 0 ] |
| 61 | do |
| 62 | case "$1" in |
Simon Walton | 44b15b18 | 2001-12-14 22:45:06 +0000 | [diff] [blame] | 63 | --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 Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 72 | esac |
| 73 | done |
| 74 | |
Francois Gouget | bc4f8f9 | 2003-09-30 00:28:13 +0000 | [diff] [blame] | 75 | if [ -z "$mode" ] ; then |
| 76 | echo "Either --desktop or --menu required" |
Jeremy White | 8dad1d8 | 2001-01-17 20:17:03 +0000 | [diff] [blame] | 77 | usage |
| 78 | fi |
| 79 | |
Francois Gouget | bc4f8f9 | 2003-09-30 00:28:13 +0000 | [diff] [blame] | 80 | if [ -z "$link" ] ; then |
| 81 | echo "You must specify a link name with --link" |
Jeremy White | 8dad1d8 | 2001-01-17 20:17:03 +0000 | [diff] [blame] | 82 | usage |
| 83 | fi |
| 84 | |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 85 | kde_entry() |
| 86 | { |
Marcus Meissner | 9c6af0a | 2001-12-13 00:58:20 +0000 | [diff] [blame] | 87 | xname=`basename "$link"` |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 88 | cat <<EOF |
| 89 | # KDE Config File |
| 90 | [KDE Desktop Entry] |
Marcus Meissner | 9c6af0a | 2001-12-13 00:58:20 +0000 | [diff] [blame] | 91 | Name=$xname |
Marcus Meissner | cb54fe6 | 2004-09-27 20:32:50 +0000 | [diff] [blame] | 92 | Exec=wine '$path' $args |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 93 | Type=Application |
| 94 | Comment=$descr |
| 95 | EOF |
| 96 | [ -z "$workdir" ] || echo "Path=\"$workdir\"" |
| 97 | [ -z "$xpmicon" ] || echo "Icon=$xpmicon" |
| 98 | } |
| 99 | |
| 100 | gnome_entry() |
| 101 | { |
Marcus Meissner | 9c6af0a | 2001-12-13 00:58:20 +0000 | [diff] [blame] | 102 | xname=`basename "$link"` |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 103 | cat <<EOF |
| 104 | [Desktop Entry] |
Marcus Meissner | 9c6af0a | 2001-12-13 00:58:20 +0000 | [diff] [blame] | 105 | Name=$xname |
Marcus Meissner | cb54fe6 | 2004-09-27 20:32:50 +0000 | [diff] [blame] | 106 | Exec=wine "$path" $args |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 107 | Type=Application |
| 108 | Comment=$descr |
| 109 | EOF |
Vitaly Lipatov | 5072fd4 | 2006-03-26 19:06:54 +0400 | [diff] [blame] | 110 | [ -z "$workdir" ] || echo "Path=$workdir" |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 111 | [ -z "$xpmicon" ] || echo "Icon=$xpmicon" |
| 112 | } |
| 113 | |
Dusan Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 114 | mdk_entry() |
| 115 | { |
| 116 | base=`basename "$link"` |
| 117 | section=`dirname "$link"` |
| 118 | [ -z "$icon" ] || xicon="icon=\"$xpmicon\"" |
Brouard Nicolas | 555eaaf | 2005-03-10 17:16:22 +0000 | [diff] [blame] | 119 | 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 Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 123 | # copy the icon file to a specified dir and set xpmicon to the resulting path |
| 124 | copy_icon() |
| 125 | { |
Marcus Meissner | 9c6af0a | 2001-12-13 00:58:20 +0000 | [diff] [blame] | 126 | dir="$1" |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 127 | mkdir -p "$dir" |
Andreas Mohr | 1a0eeb5 | 2000-12-14 20:30:35 +0000 | [diff] [blame] | 128 | mkdir -p "$dir/""`dirname "$link"`" || true |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 129 | 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 Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 138 | # Debian/Mandrake |
| 139 | |
Laurent Blume | a79b48e | 2005-05-09 09:28:05 +0000 | [diff] [blame] | 140 | type update-menus > /dev/null 2>&1 |
Dusan Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 141 | if [ $? = 0 -a $mode = "menu" ] |
| 142 | then |
| 143 | iconname="`basename "$link"`.xpm" |
| 144 | dir="$HOME/.menu/icons" |
| 145 | if [ -f "$icon" ] |
| 146 | then |
Marcus Meissner | 9c6af0a | 2001-12-13 00:58:20 +0000 | [diff] [blame] | 147 | mkdir -p "$dir" |
Dusan Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 148 | cp "$icon" "$dir/$iconname" |
| 149 | xpmicon="$dir/$iconname" |
| 150 | else |
| 151 | xpmicon="" |
| 152 | fi |
| 153 | mdk_entry >> "$HOME/.menu/wine" |
Brouard Nicolas | 555eaaf | 2005-03-10 17:16:22 +0000 | [diff] [blame] | 154 | if [ -d "/usr/lib/menu" ] && [ -w "/usr/lib/menu" ] |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 155 | then |
| 156 | mdk_entry >> "/usr/lib/menu/wine" |
| 157 | fi |
Dusan Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 158 | update-menus > /dev/null 2>&1 |
| 159 | fi |
| 160 | |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 161 | # KDE |
| 162 | |
| 163 | if [ -d "$HOME/.kde" ] |
| 164 | then |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 165 | kdeversion=0 |
Laurent Blume | a79b48e | 2005-05-09 09:28:05 +0000 | [diff] [blame] | 166 | if type kde-config >/dev/null 2>&1 |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 167 | then |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 168 | kdeversion=`kde-config -v | grep KDE: | sed -n "s/^KDE: \([^.]*\)\..*$/\1/p"` |
| 169 | fi |
Jeremy White | 8dad1d8 | 2001-01-17 20:17:03 +0000 | [diff] [blame] | 170 | |
Dustin Navea | 1222aa6 | 2002-05-14 23:20:45 +0000 | [diff] [blame] | 171 | if [ $kdeversion -ge 2 ] |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 172 | then |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 173 | 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 Blume | a79b48e | 2005-05-09 09:28:05 +0000 | [diff] [blame] | 188 | type kwmcom >/dev/null 2>/dev/null && \ |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 189 | 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 Blume | a79b48e | 2005-05-09 09:28:05 +0000 | [diff] [blame] | 196 | type kfmclient >/dev/null 2>/dev/null && \ |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 197 | ps u -C kfm >/dev/null 2>/dev/null && \ |
| 198 | kfmclient refreshDesktop |
| 199 | fi |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 200 | fi |
Marcus Meissner | b686a90 | 2001-03-08 01:12:52 +0000 | [diff] [blame] | 201 | fi |
| 202 | |
| 203 | if [ -d "$HOME/.kde2" ] |
| 204 | then |
| 205 | copy_icon "$HOME/.kde2/share/applnk/Wine" |
| 206 | if [ $mode = "menu" ] |
| 207 | then |
Marcus Meissner | ed9c2df | 2001-03-16 16:40:12 +0000 | [diff] [blame] | 208 | gnome_entry > "$HOME/.kde2/share/applnk/Wine/$link.desktop" |
Dustin Navea | 9df2e56 | 2002-05-23 16:31:22 +0000 | [diff] [blame] | 209 | 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 |
| 219 | fi |
| 220 | |
| 221 | if [ -d "$HOME/.kde3/share/applnk" ] |
| 222 | then |
| 223 | copy_icon "$HOME/.kde3/share/applnk/Wine" |
| 224 | if [ $mode = "menu" ] |
Dustin Navea | 1222aa6 | 2002-05-14 23:20:45 +0000 | [diff] [blame] | 225 | then |
Dustin Navea | 9df2e56 | 2002-05-23 16:31:22 +0000 | [diff] [blame] | 226 | 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 Meissner | b686a90 | 2001-03-08 01:12:52 +0000 | [diff] [blame] | 240 | fi |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 241 | fi |
| 242 | |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 243 | # Gnome |
| 244 | |
| 245 | if [ -d "$HOME/.gnome" ] |
| 246 | then |
| 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 |
| 255 | fi |
| 256 | |
| 257 | exit 0 |