programs/wcmd: Rename to programs/cmd.
[wine] / tools / wineshelllink
index 5f4c2de..db65efa 100755 (executable)
 #
 # 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
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 #
 
+# 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)
+
 mode=""
 args=""
 menu=""
@@ -38,14 +43,14 @@ options:
   --desktop     create a desktop link
   --menu        create a menu entry
   --path xx     path to the application
-  --link xx     name of link to create
+  --link xx     name of link to create, including path
   --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
-    exit 1
+    exit 2
 }
 
 if [ $# -eq 0 ] ; then
@@ -67,13 +72,13 @@ do
   esac
 done
 
-if [ "$mode" = ""  ] ; then
-    echo Either --desktop or --menu required
+if [ -z "$mode" ] ; then
+    echo "Either --desktop or --menu required"
     usage
 fi
 
-if [ "$link" = ""  ] ; then
-    echo You must specify a link name with --link
+if [ -z "$link" ] ; then
+    echo "You must specify a link name with --link"
     usage
 fi
 
@@ -84,7 +89,7 @@ kde_entry()
 # KDE Config File
 [KDE Desktop Entry]
 Name=$xname
-Exec=wine "$path" -- $args
+Exec=wine '$path' $args
 Type=Application
 Comment=$descr
 EOF
@@ -98,11 +103,11 @@ gnome_entry()
     cat <<EOF
 [Desktop Entry]
 Name=$xname
-Exec=wine "$path" -- $args
+Exec=wine "$path" $args
 Type=Application
 Comment=$descr
 EOF
-    [ -z "$workdir" ] || echo "Path=\"$workdir\""
+    [ -z "$workdir" ] || echo "Path=$workdir"
     [ -z "$xpmicon" ] || echo "Icon=$xpmicon"
 }
 
@@ -111,7 +116,8 @@ mdk_entry()
     base=`basename "$link"`
     section=`dirname "$link"`
     [ -z "$icon" ] || xicon="icon=\"$xpmicon\""
-    echo "?package(local.Wine):needs=x11 section=\"Wine/$section\" title=\"$base\" longtitle=\"$descr\" command=\"wine \\\"$path\\\" -- $args\" $xicon"
+    pathmenu=`echo "$path" | sed 's+\\\\+\\\\\\\\+g'`
+    echo "?package(local.Wine):needs=x11 section=\"/Wine/$section\" title=\"$base\" longtitle=\"$descr\" command=\"wine '$pathmenu' $args\" $xicon"
 }
 
 # copy the icon file to a specified dir and set xpmicon to the resulting path
@@ -131,7 +137,7 @@ copy_icon()
 
 # Debian/Mandrake
 
-which update-menus > /dev/null 2>&1
+type update-menus > /dev/null 2>&1
 if [ $? = 0 -a $mode = "menu" ]
 then
   iconname="`basename "$link"`.xpm"
@@ -145,6 +151,10 @@ then
     xpmicon=""
   fi
   mdk_entry >> "$HOME/.menu/wine"
+  if [ -d "/usr/lib/menu" ] && [ -w "/usr/lib/menu" ]
+  then
+    mdk_entry >> "/usr/lib/menu/wine"
+  fi
   update-menus > /dev/null 2>&1
 fi
 
@@ -152,23 +162,41 @@ fi
 
 if [ -d "$HOME/.kde" ]
 then
-  copy_icon "$HOME/.kde/share/applnk/Wine"
-  if [ $mode = "menu" ]
+  kdeversion=0
+  if type kde-config >/dev/null 2>&1
   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
+    kdeversion=`kde-config -v | grep KDE: | sed -n "s/^KDE: \([^.]*\)\..*$/\1/p"`
+  fi
 
-  elif [ -d "$HOME/Desktop" ]
+  if [ $kdeversion -ge 2 ]
   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
+    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
+      type 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...
+      type kfmclient >/dev/null 2>/dev/null && \
+        ps u -C kfm >/dev/null 2>/dev/null  && \
+          kfmclient refreshDesktop
+    fi
   fi
 fi
 
@@ -178,14 +206,39 @@ then
   if [ $mode = "menu" ]
   then
     gnome_entry > "$HOME/.kde2/share/applnk/Wine/$link.desktop"
-  elif [ -d "$HOME/Desktop2" ]
-  then
-    gnome_entry > "$HOME/Desktop2/$link.desktop"
+  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" ]
+  then
+    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
+  fi
+fi
 
 # Gnome