wineshelllink 5.66 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
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\""
114 115
    pathmenu=`echo "$path" | sed 's+\\\\+\\\\\\\\+g'`
    echo "?package(local.Wine):needs=x11 section=\"/Wine/$section\" title=\"$base\" longtitle=\"$descr\" command=\"wine '$pathmenu' $args\" $xicon"
116 117
}

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

133 134
# Debian/Mandrake

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

156 157 158 159
# KDE

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

166
  if [ $kdeversion -ge 2 ]
167
  then
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 194
    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
195
  fi
196 197 198 199 200 201 202
fi

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