wineshelllink 5.93 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/sh
#
# Create menu/desktop entries for an application
# This is used by the IShellLink interface
#
# Copyright 2000 Alexandre Julliard
#
8 9 10 11 12 13 14 15 16 17 18 19
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 22
#

23 24 25 26 27
# Note that the link is a relative unix-style path name.  Since the / character
# is not valid in Windows filenames it is an adequate separator to show the
# menu structure.  (This program may need to split the menu structure out for
# implementing xdg-style menus)

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
mode=""
args=""
menu=""
icon=""
descr=""
link=""
path=""
workdir=""

usage()
{
    cat <<EOF
usage: wineshelllink options

options:
  --desktop     create a desktop link
  --menu        create a menu entry
  --path xx     path to the application
46
  --link xx     name of link to create, including path
47 48 49 50 51 52
  --args xx     command-line arguments for the application
  --icon xx     icon to display
  --workdir xx  working directory for the application
  --descr xx    application description

EOF
53
    exit 2
54 55
}

56 57 58 59
if [ $# -eq 0 ] ; then
    usage
fi

60 61 62
while [ $# -gt 0 ]
do
  case "$1" in
Simon Walton's avatar
Simon Walton committed
63 64 65 66 67 68 69 70 71
    --desktop) mode="desktop"; shift 1 ;;
    --menu)    mode="menu"; shift 1 ;;
    --path)    path="$2"; shift 2 ;;
    --link)    link="$2"; shift 2 ;;
    --args)    args="$2"; shift 2 ;;
    --icon)    icon="$2"; shift 2 ;;
    --descr)   descr="$2"; shift 2 ;;
    --workdir) workdir="$2"; shift 2 ;;
    *) usage ;;
72 73 74
  esac
done

75 76
if [ -z "$mode" ] ; then
    echo "Either --desktop or --menu required"
77 78 79
    usage
fi

80 81
if [ -z "$link" ] ; then
    echo "You must specify a link name with --link"
82 83 84
    usage
fi

85 86
kde_entry()
{
87
    xname=`basename "$link"`
88 89 90
    cat <<EOF
# KDE Config File
[KDE Desktop Entry]
91
Name=$xname
92
Exec=wine '$path' $args
93 94 95 96 97 98 99 100 101
Type=Application
Comment=$descr
EOF
    [ -z "$workdir" ] || echo "Path=\"$workdir\""
    [ -z "$xpmicon" ] || echo "Icon=$xpmicon"
}

gnome_entry()
{
102
    xname=`basename "$link"`
103 104
    cat <<EOF
[Desktop Entry]
105
Name=$xname
106
Exec=wine "$path" $args
107 108 109
Type=Application
Comment=$descr
EOF
110
    [ -z "$workdir" ] || echo "Path=$workdir"
111 112 113
    [ -z "$xpmicon" ] || echo "Icon=$xpmicon"
}

114 115 116 117 118
mdk_entry()
{
    base=`basename "$link"`
    section=`dirname "$link"`
    [ -z "$icon" ] || xicon="icon=\"$xpmicon\""
119 120
    pathmenu=`echo "$path" | sed 's+\\\\+\\\\\\\\+g'`
    echo "?package(local.Wine):needs=x11 section=\"/Wine/$section\" title=\"$base\" longtitle=\"$descr\" command=\"wine '$pathmenu' $args\" $xicon"
121 122
}

123 124 125
# copy the icon file to a specified dir and set xpmicon to the resulting path
copy_icon()
{
126
  dir="$1"
127
  mkdir -p "$dir"
Andreas Mohr's avatar
Andreas Mohr committed
128
  mkdir -p "$dir/""`dirname "$link"`" || true
129 130 131 132 133 134 135 136 137
  if [ -f "$icon" ]
  then
    cp "$icon" "$dir/$link.xpm"
    xpmicon="$dir/$link.xpm"
  else
    xpmicon=""
  fi
}

138 139
# Debian/Mandrake

140
type update-menus > /dev/null 2>&1
141 142 143 144 145 146
if [ $? = 0 -a $mode = "menu" ]
then
  iconname="`basename "$link"`.xpm"
  dir="$HOME/.menu/icons"
  if [ -f "$icon" ]
  then
147
    mkdir -p "$dir"
148 149 150 151 152 153
    cp "$icon" "$dir/$iconname"
    xpmicon="$dir/$iconname"
  else
    xpmicon=""
  fi
  mdk_entry >> "$HOME/.menu/wine"
154
  if [ -d "/usr/lib/menu" ] && [ -w "/usr/lib/menu" ]
155 156 157
  then
    mdk_entry >> "/usr/lib/menu/wine"
  fi
158 159 160
  update-menus > /dev/null 2>&1
fi

161 162 163 164
# KDE

if [ -d "$HOME/.kde" ]
then
165
  kdeversion=0
166
  if type kde-config >/dev/null 2>&1
167
  then
168 169
    kdeversion=`kde-config -v | grep KDE: | sed -n "s/^KDE: \([^.]*\)\..*$/\1/p"`
  fi
170

171
  if [ $kdeversion -ge 2 ]
172
  then
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    copy_icon "$HOME/.kde/share/applnk/Wine"
    if [ $mode = "menu" ]
    then
      gnome_entry > "$HOME/.kde/share/applnk/Wine/$link.desktop"
    elif [ -d "$HOME/Desktop" ]
    then
      gnome_entry > "$HOME/Desktop/$link.desktop"
    fi
  else
    copy_icon "$HOME/.kde/share/applnk/Wine"
    if [ $mode = "menu" ]
    then
      kde_entry > "$HOME/.kde/share/applnk/Wine/$link.kdelnk"

      # KDE 1.x kludge.  Wake up KDE, if we can find kpanel running
188
      type kwmcom >/dev/null 2>/dev/null && \
189 190 191 192 193 194 195
        ps u -C kpanel >/dev/null 2>/dev/null && \
          kwmcom kpanel:restart

    elif [ -d "$HOME/Desktop" ]
    then
      kde_entry > "$HOME/Desktop/$link.kdelnk"
      #   KDE 1.x kludge:  wake up KDE, if we can find kfm running...
196
      type kfmclient >/dev/null 2>/dev/null && \
197 198 199
        ps u -C kfm >/dev/null 2>/dev/null  && \
          kfmclient refreshDesktop
    fi
200
  fi
201 202 203 204 205 206 207
fi

if [ -d "$HOME/.kde2" ]
then
  copy_icon "$HOME/.kde2/share/applnk/Wine"
  if [ $mode = "menu" ]
  then
208
    gnome_entry > "$HOME/.kde2/share/applnk/Wine/$link.desktop"
Dustin Navea's avatar
Dustin Navea committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
  else
    if [ -d "$HOME/Desktop2" ]
    then
      gnome_entry > "$HOME/Desktop2/$link.desktop"
    fi
    if [ -d "$HOME/Desktop" ]
    then
      gnome_entry > "$HOME/Desktop/$link.desktop"
    fi
  fi
fi

if [ -d "$HOME/.kde3/share/applnk" ]
then
  copy_icon "$HOME/.kde3/share/applnk/Wine"
  if [ $mode = "menu" ]
225
  then
Dustin Navea's avatar
Dustin Navea committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239
    gnome_entry > "$HOME/.kde3/share/applnk/Wine/$link.desktop"
  else
    if [ -d "$HOME/Desktop3" ]
    then
      gnome_entry > "$HOME/Desktop3/$link.desktop"
    fi
    if [ -d "$HOME/Desktop2" ]
    then
      gnome_entry > "$HOME/Desktop2/$link.desktop"
    fi
    if [ -d "$HOME/Desktop" ]
    then
      gnome_entry > "$HOME/Desktop/$link.desktop"
    fi
240
  fi
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
fi

# Gnome

if [ -d "$HOME/.gnome" ]
then
  copy_icon "$HOME/.gnome/apps/Wine"
  if [ $mode = "menu" ]
  then
    gnome_entry > "$HOME/.gnome/apps/Wine/$link.desktop"
  elif [ -d "$HOME/.gnome-desktop" ]
  then
    gnome_entry > "$HOME/.gnome-desktop/$link.desktop"
  fi
fi

exit 0