wineshelllink 5.59 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 20 21 22
# 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
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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
  --link xx     name of link to create
  --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
48
    exit 2
49 50
}

51 52 53 54
if [ $# -eq 0 ] ; then
    usage
fi

55 56 57
while [ $# -gt 0 ]
do
  case "$1" in
Simon Walton's avatar
Simon Walton committed
58 59 60 61 62 63 64 65 66
    --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 ;;
67 68 69
  esac
done

70 71
if [ -z "$mode" ] ; then
    echo "Either --desktop or --menu required"
72 73 74
    usage
fi

75 76
if [ -z "$link" ] ; then
    echo "You must specify a link name with --link"
77 78 79
    usage
fi

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

gnome_entry()
{
97
    xname=`basename "$link"`
98 99
    cat <<EOF
[Desktop Entry]
100
Name=$xname
Ove Kaaven's avatar
Ove Kaaven committed
101
Exec=wine "$path" -- $args
102 103 104 105 106 107 108
Type=Application
Comment=$descr
EOF
    [ -z "$workdir" ] || echo "Path=\"$workdir\""
    [ -z "$xpmicon" ] || echo "Icon=$xpmicon"
}

109 110 111 112 113
mdk_entry()
{
    base=`basename "$link"`
    section=`dirname "$link"`
    [ -z "$icon" ] || xicon="icon=\"$xpmicon\""
Ove Kaaven's avatar
Ove Kaaven committed
114
    echo "?package(local.Wine):needs=x11 section=\"Wine/$section\" title=\"$base\" longtitle=\"$descr\" command=\"wine \\\"$path\\\" -- $args\" $xicon"
115 116
}

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

132 133
# Debian/Mandrake

134
which update-menus > /dev/null 2>&1
135 136 137 138 139 140
if [ $? = 0 -a $mode = "menu" ]
then
  iconname="`basename "$link"`.xpm"
  dir="$HOME/.menu/icons"
  if [ -f "$icon" ]
  then
141
    mkdir -p "$dir"
142 143 144 145 146 147
    cp "$icon" "$dir/$iconname"
    xpmicon="$dir/$iconname"
  else
    xpmicon=""
  fi
  mdk_entry >> "$HOME/.menu/wine"
148 149 150 151
  if [ -d "/usr/lib/menu" ]
  then
    mdk_entry >> "/usr/lib/menu/wine"
  fi
152 153 154
  update-menus > /dev/null 2>&1
fi

155 156 157 158
# KDE

if [ -d "$HOME/.kde" ]
then
159 160
  kdeversion=0
  if which kde-config >/dev/null 2>&1
161
  then
162 163
    kdeversion=`kde-config -v | grep KDE: | sed -n "s/^KDE: \([^.]*\)\..*$/\1/p"`
  fi
164

165
  if [ $kdeversion -ge 2 ]
166
  then
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    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
      which kwmcom >/dev/null 2>/dev/null && \
        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...
      which kfmclient >/dev/null 2>/dev/null && \
        ps u -C kfm >/dev/null 2>/dev/null  && \
          kfmclient refreshDesktop
    fi
194
  fi
195 196 197 198 199 200 201
fi

if [ -d "$HOME/.kde2" ]
then
  copy_icon "$HOME/.kde2/share/applnk/Wine"
  if [ $mode = "menu" ]
  then
202
    gnome_entry > "$HOME/.kde2/share/applnk/Wine/$link.desktop"
Dustin Navea's avatar
Dustin Navea committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
  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" ]
219
  then
Dustin Navea's avatar
Dustin Navea committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233
    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
234
  fi
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
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