wineshelllink: Use FreeDesktop standard to create Wine menu structure.

This commit is contained in:
Vitaliy Margolen 2006-11-24 13:53:29 -07:00 committed by Alexandre Julliard
parent ada881cee6
commit da36762297
1 changed files with 109 additions and 143 deletions

View File

@ -4,6 +4,7 @@
# This is used by the IShellLink interface # This is used by the IShellLink interface
# #
# Copyright 2000 Alexandre Julliard # Copyright 2000 Alexandre Julliard
# Copyright 2006 Vitaliy Margolen
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
@ -22,8 +23,7 @@
# Note that the link is a relative unix-style path name. Since the / character # 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 # 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 # menu structure.
# implementing xdg-style menus)
mode="" mode=""
args="" args=""
@ -82,176 +82,142 @@ if [ -z "$link" ] ; then
usage usage
fi fi
kde_entry() desktop_entry()
{ {
xname=`basename "$link"`
cat <<EOF
# KDE Config File
[KDE Desktop Entry]
Name=$xname
Exec=wine '$path' $args
Type=Application
Comment=$descr
EOF
[ -z "$workdir" ] || echo "Path=\"$workdir\""
[ -z "$xpmicon" ] || echo "Icon=$xpmicon"
}
gnome_entry()
{
xname=`basename "$link"`
cat <<EOF cat <<EOF
[Desktop Entry] [Desktop Entry]
Name=$xname Name=$linkname
Exec=wine "$path" $args Exec=wine "$path" $args
Type=Application Type=Application
Comment=$descr
EOF EOF
[ -z "$descr" ] || echo "Comment=$descr"
[ -z "$workdir" ] || echo "Path=$workdir" [ -z "$workdir" ] || echo "Path=$workdir"
[ -z "$xpmicon" ] || echo "Icon=$xpmicon" [ -z "$xpmicon" ] || echo "Icon=$xpmicon"
} }
mdk_entry() directory_entry()
{ {
base=`basename "$link"` cat <<EOF
section=`dirname "$link"` [Desktop Entry]
[ -z "$icon" ] || xicon="icon=\"$xpmicon\"" Type=Directory
pathmenu=`echo "$path" | sed 's+\\\\+\\\\\\\\+g'` EOF
echo "?package(local.Wine):needs=x11 section=\"/Wine/$section\" title=\"$base\" longtitle=\"$descr\" command=\"wine '$pathmenu' $args\" $xicon" if [ "$1" == "wine" ] ; then
echo "Name=Wine"
echo "Icon=wine"
else
echo "Name=$1"
echo "Icon=folder"
fi
} }
# copy the icon file to a specified dir and set xpmicon to the resulting path # copy the icon file to a specified dir and set xpmicon to the resulting path
copy_icon() copy_icon()
{ {
dir="$1" if [ -f "$icon" ]
mkdir -p "$dir" then
mkdir -p "$dir/""`dirname "$link"`" || true xpmicon=`basename "$icon" .xpm`
if [ -f "$icon" ]
then mkdir -p "$1"
cp "$icon" "$dir/$link.xpm" cp "$icon" "$1/$xpmicon.xpm"
xpmicon="$dir/$link.xpm" else
else xpmicon=""
xpmicon="" fi
fi
} }
# Debian/Mandrake # XDG
type update-menus > /dev/null 2>&1 xdg_config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/menus/applications-merged"
if [ $? = 0 -a $mode = "menu" ] xdg_data_dir="${XDG_DATA_HOME:-$HOME/.local/share}"
then
iconname="`basename "$link"`.xpm"
dir="$HOME/.menu/icons"
if [ -f "$icon" ]
then
mkdir -p "$dir"
cp "$icon" "$dir/$iconname"
xpmicon="$dir/$iconname"
else
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
# KDE # Create common directories
mkdir -p "$xdg_config_dir"
mkdir -p "$xdg_data_dir/desktop-directories"
if [ -d "$HOME/.kde" ] get_menu_entries()
then {
kdeversion=0 tmp="$xdg_config_dir/$1.menu"
if type kde-config >/dev/null 2>&1
then
kdeversion=`kde-config -v | grep KDE: | sed -n "s/^KDE: \([^.]*\)\..*$/\1/p"`
fi
if [ $kdeversion -ge 2 ] if [ -r "$tmp" ] ; then
then awk '
copy_icon "$HOME/.kde/share/applnk/Wine" BEGIN { RS="<" }
if [ $mode = "menu" ] /^Filename/ {
then if (match($0,/>/)) {
gnome_entry > "$HOME/.kde/share/applnk/Wine/$link.desktop" print substr($0,RSTART+1)
elif [ -d "$HOME/Desktop" ] }
then }' $tmp
gnome_entry > "$HOME/Desktop/$link.desktop"
fi 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 # Input
type kwmcom >/dev/null 2>/dev/null && \ # menu file name
ps u -C kpanel >/dev/null 2>/dev/null && \ # new item
kwmcom kpanel:restart write_menu_file()
{
tmpfile=`mktemp`
(
echo '<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"'
echo '"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">'
echo '<Menu>'
echo ' <Name>Applications</Name>'
elif [ -d "$HOME/Desktop" ] IFS="-"
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
if [ -d "$HOME/.kde2" ] fullname='wine'
then for i in $1; do
copy_icon "$HOME/.kde2/share/applnk/Wine" echo " <Menu>"
if [ $mode = "menu" ] echo " <Name>$fullname-$i</Name>"
then echo " <Directory>$fullname-$i.directory</Directory>"
gnome_entry > "$HOME/.kde2/share/applnk/Wine/$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" ] dir_file_name="$xdg_data_dir/desktop-directories/$fullname-$i.directory"
then if [ ! -f "$dir_file_name" ] ; then
copy_icon "$HOME/.kde3/share/applnk/Wine" directory_entry "$i" > "$dir_file_name"
if [ $mode = "menu" ] fi
then test "$i" = "wine" || fullname="$fullname-$i"
gnome_entry > "$HOME/.kde3/share/applnk/Wine/$link.desktop" done
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 echo " <Include>"
if [ -d "$HOME/.gnome" ] IFS="
then "
copy_icon "$HOME/.gnome/apps/Wine" for i in $(get_menu_entries "$1"); do
if [ $mode = "menu" ] test "$i" = "$2" && continue
then echo " <Filename>$i</Filename>"
gnome_entry > "$HOME/.gnome/apps/Wine/$link.desktop" done
elif [ -d "$HOME/.gnome-desktop" ]
then # New record
gnome_entry > "$HOME/.gnome-desktop/$link.desktop" echo " <Filename>$2</Filename>"
fi echo " </Include>"
IFS='-'
for i in $1; do
echo " </Menu>"
done
echo '</Menu>'
) > $tmpfile
chmod 0600 $tmpfile
mv -f $tmpfile "$xdg_config_dir/$1.menu"
}
copy_icon "$xdg_data_dir/icons"
linkname=`basename "$link"`
if [ $mode = "menu" ] ; then
mkdir -p "$xdg_data_dir/applications/wine/`dirname "$link"`"
linkpath=`dirname "$link" | sed 's!/!-!g'`
if [ "$linkpath" == "." ] ; then
linkpath=""
else
linkpath="-$linkpath"
fi
desktop_entry > "$xdg_data_dir/applications/wine/$link.desktop"
write_menu_file "wine$linkpath" "wine$linkpath-$linkname.desktop"
else
desktop_entry > "$HOME/Desktop/$linkname.desktop"
fi fi
exit 0 exit 0