Package: xdg-utils Version: 1.0.2+cvs20100307-2 Severity: normal Tags: patch
xdg-open currently cannot handle magnet: links. It should probably be rewritten to recognize such links and call xdg-mime, as in $ xdg-mime query default application/x-bittorrent /usr/share/applications/transmission.desktop There is a patch online at http://www.void.gr/kargig/blog/2012/01/24/open-magnet-urls-with-xdg-open/ but this is clearly bogus, as the application is hard-coded. I have attempted to patch the code to use xdg-mime query default application/x-bittorrent My patch works on Debian in a generic desktop environment. I find the code somewhat ugly. The general idea is an optional second parameter to open_generic_xdg_mime() which, if present, is taken as the default mime type. In addition, I had to change the code to account for the possibility that xdg-mime returns an absolute pathname. Not beautiful, but it seems to get the job done. -- System Information: Debian Release: 6.0.5 APT prefers stable APT policy: (990, 'stable'), (500, 'testing') Architecture: i386 (i686) Kernel: Linux 3.2.0-2-686-pae (SMP w/2 CPU cores) Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968) Shell: /bin/sh linked to /bin/bash xdg-utils depends on no packages. Versions of packages xdg-utils recommends: ii file 5.04-5+squeeze2 Determines file type using "magic" ii google-chrome-stabl 19.0.1084.46-r135956 The web browser from Google ii iceweasel [www-brow 3.5.16-15 Web browser based on Firefox ii konqueror [www-brow 4:4.4.5-2 advanced file manager, web browser ii lynx-cur [www-brows 2.8.8dev.5-1 Text-mode WWW Browser with NLS sup ii mime-support 3.48-1 MIME files 'mime.types' & 'mailcap ii shared-mime-info 0.71-4 FreeDesktop.org shared MIME databa ii w3m [www-browser] 0.5.2-9 WWW browsable pager with excellent ii x11-utils 7.5+4 X11 utilities ii x11-xserver-utils 7.5+3 X server utilities Versions of packages xdg-utils suggests: pn gvfs-bin <none> (no description available) -- no debconf information
*** /usr/bin/xdg-open Wed Sep 15 13:08:29 2010 --- /home/nr/bin/xdg-open Sun Jun 24 22:36:13 2012 *************** *** 380,386 **** open_generic_xdg_mime() { ! filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"` default=`xdg-mime query default "$filetype"` if [ -n "$default" ] ; then xdg_user_dir="$XDG_DATA_HOME" --- 380,390 ---- open_generic_xdg_mime() { ! if [ -z "$2" ]; then ! filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"` ! else ! filetype="$2" ! fi default=`xdg-mime query default "$filetype"` if [ -n "$default" ] ; then xdg_user_dir="$XDG_DATA_HOME" *************** *** 390,396 **** [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/ for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do ! file="$x/applications/$default" if [ -r "$file" ] ; then command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`" command_exec=`which $command 2>/dev/null` --- 394,403 ---- [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/ for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do ! case $default in ! /*) file="$default" ;; # absolute pathname ! *) file="$x/applications/$default" ;; # relative pathname ! esac if [ -r "$file" ] ; then command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`" command_exec=`which $command 2>/dev/null` *************** *** 399,404 **** --- 406,412 ---- if [ $? -eq 0 ]; then exit_success fi + case $default in /*) break ;; esac # no need to try again fi fi done *************** *** 425,430 **** --- 433,458 ---- if [ -f /etc/debian_version ] && which run-mailcap 2>/dev/null 1>&2; then + run-mailcap --action=view "$file" + if [ $? -eq 0 ]; then + exit_success + fi + fi + + if mimeopen -v 2>/dev/null 1>&2; then + mimeopen -n "$file" + if [ $? -eq 0 ]; then + exit_success + fi + fi + fi + + # magnet links for a bittorrent client + if (echo "$1" | grep -q '^magnet:'); then + open_generic_xdg_mime "$1" application/x-bittorrent + + if [ -f /etc/debian_version ] && + which run-mailcap 2>/dev/null 1>&2; then run-mailcap --action=view "$file" if [ $? -eq 0 ]; then exit_success