| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 #--------------------------------------------- | 2 #--------------------------------------------- |
| 3 # xdg-mime | 3 # xdg-mime |
| 4 # | 4 # |
| 5 # Utility script to manipulate MIME related information | 5 # Utility script to manipulate MIME related information |
| 6 # on XDG compliant systems. | 6 # on XDG compliant systems. |
| 7 # | 7 # |
| 8 # Refer to the usage() function below for usage. | 8 # Refer to the usage() function below for usage. |
| 9 # | 9 # |
| 10 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> | 10 # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 application is identified by its *.desktop file. | 78 application is identified by its *.desktop file. |
| 79 | 79 |
| 80 default | 80 default |
| 81 | 81 |
| 82 Ask the desktop environment to make application the default application for | 82 Ask the desktop environment to make application the default application for |
| 83 opening files of type mimetype. An application can be made the default for | 83 opening files of type mimetype. An application can be made the default for |
| 84 several file types by specifying multiple mimetypes. | 84 several file types by specifying multiple mimetypes. |
| 85 | 85 |
| 86 application is the desktop file id of the application and has the form | 86 application is the desktop file id of the application and has the form |
| 87 vendor-name.desktop application must already be installed in the desktop | 87 vendor-name.desktop application must already be installed in the desktop |
| 88 menu before it can be made the default handler. The application's desktop | 88 menu before it can be made the default handler. The aplication's desktop |
| 89 file must list support for all the MIME types that it wishes to be the | 89 file must list support for all the MIME types that it wishes to be the |
| 90 default handler for. | 90 default handler for. |
| 91 | 91 |
| 92 Requests to make an application a default handler may be subject to system | 92 Requests to make an application a default handler may be subject to system |
| 93 policy or approval by the end-user. xdg-mime query can be used to verify | 93 policy or approval by the end-user. xdg-mime query can be used to verify |
| 94 whether an application is the actual default handler for a specific file | 94 whether an application is the actual default handler for a specific file |
| 95 type. | 95 type. |
| 96 | 96 |
| 97 The default option is for use inside a desktop session only. It is not | 97 The default option is for use inside a desktop session only. It is not |
| 98 recommended to use xdg-mime default as root. | 98 recommended to use xdg-mime default as root. |
| 99 | 99 |
| 100 install | 100 install |
| 101 Adds the file type descriptions provided in mimetypes-file to the desktop | 101 Adds the file type descriptions provided in mimetypes-file to the desktop |
| 102 environment. mimetypes-file must be a XML file that follows the | 102 environment. mimetypes-file must be a XML file that follows the |
| 103 freedesktop.org Shared MIME-info Database specification and that has a | 103 freedesktop.org Shared MIME-info Database specification and that has a |
| 104 mime-info element as its document root. For each new file type one or more | 104 mime-info element as its document root. For each new file type one or more |
| 105 icons with name major-minor must be installed with the xdg-icon-resource | 105 icons with name type-subtype must be installed with the xdg-icon-resource |
| 106 command in the mimetypes context. For example the application/ | 106 command in the mimetypes context. For example the filetype application/ |
| 107 vnd.oasis.opendocument.text filetype requires an icon by the name of | 107 vnd.oasis.opendocument.text requires an icon named |
| 108 application-vnd.oasis.opendocument.text to be installed. | 108 application-vnd.oasis.opendocument.text to be installed (unless the file |
| 109 type recommends another icon name). |
| 109 uninstall | 110 uninstall |
| 110 Removes the file type descriptions provided in mimetypes-file and | 111 Removes the file type descriptions provided in mimetypes-file and |
| 111 previously added with xdg-mime install from the desktop environment. | 112 previously added with xdg-mime install from the desktop environment. |
| 112 mimetypes-file must be a XML file that follows the freedesktop.org Shared | 113 mimetypes-file must be a XML file that follows the freedesktop.org Shared |
| 113 MIME-info Database specification and that has a mime-info element as its | 114 MIME-info Database specification and that has a mime-info element as its |
| 114 document root. | 115 document root. |
| 115 | 116 |
| 116 Options | 117 Options |
| 117 | 118 |
| 118 --mode mode | 119 --mode mode |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info.
" | 395 echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info.
" |
| 395 exit_success | 396 exit_success |
| 396 ;; | 397 ;; |
| 397 | 398 |
| 398 --manual) | 399 --manual) |
| 399 manualpage | 400 manualpage |
| 400 exit_success | 401 exit_success |
| 401 ;; | 402 ;; |
| 402 | 403 |
| 403 --version) | 404 --version) |
| 404 echo "xdg-mime 1.0.2" | 405 echo "xdg-mime 1.1.0 rc1" |
| 405 exit_success | 406 exit_success |
| 406 ;; | 407 ;; |
| 407 esac | 408 esac |
| 408 done | 409 done |
| 409 } | 410 } |
| 410 | 411 |
| 411 check_common_commands "$@" | 412 check_common_commands "$@" |
| 412 | 413 |
| 413 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; | 414 [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL; |
| 414 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then | 415 if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then |
| 415 # Be silent | 416 # Be silent |
| 416 xdg_redirect_output=" > /dev/null 2> /dev/null" | 417 xdg_redirect_output=" > /dev/null 2> /dev/null" |
| 417 else | 418 else |
| 418 # All output to stderr | 419 # All output to stderr |
| 419 xdg_redirect_output=" >&2" | 420 xdg_redirect_output=" >&2" |
| 420 fi | 421 fi |
| 421 | 422 |
| 422 #-------------------------------------- | 423 #-------------------------------------- |
| 423 # Checks for known desktop environments | 424 # Checks for known desktop environments |
| 424 # set variable DE to the desktop environments name, lowercase | 425 # set variable DE to the desktop environments name, lowercase |
| 425 | 426 |
| 426 detectDE() | 427 detectDE() |
| 427 { | 428 { |
| 428 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; | 429 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
| 429 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; | 430 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
| 430 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; | 431 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; |
| 431 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; | 432 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; |
| 433 elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde; |
| 434 else DE="" |
| 432 fi | 435 fi |
| 433 } | 436 } |
| 434 | 437 |
| 435 #---------------------------------------------------------------------------- | 438 #---------------------------------------------------------------------------- |
| 436 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 | 439 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 |
| 437 # It also always returns 1 in KDE 3.4 and earlier | 440 # It also always returns 1 in KDE 3.4 and earlier |
| 438 # Simply return 0 in such case | 441 # Simply return 0 in such case |
| 439 | 442 |
| 440 kfmclient_fix_exit_code() | 443 kfmclient_fix_exit_code() |
| 441 { | 444 { |
| 442 version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE` | 445 [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0; |
| 443 major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'` | 446 version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'` |
| 444 minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'` | 447 major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'` |
| 445 release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` | 448 minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'` |
| 449 release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'` |
| 446 test "$major" -gt 3 && return $1 | 450 test "$major" -gt 3 && return $1 |
| 447 test "$minor" -gt 5 && return $1 | 451 test "$minor" -gt 5 && return $1 |
| 448 test "$release" -gt 4 && return $1 | 452 test "$release" -gt 4 && return $1 |
| 449 return 0 | 453 return 0 |
| 450 } | 454 } |
| 451 | 455 |
| 452 update_mime_database() | 456 update_mime_database() |
| 453 { | 457 { |
| 454 if [ x"$mode" = x"user" -a -n "$DISPLAY" ] ; then | 458 if [ x"$mode" = x"user" -a -n "$DISPLAY" ] ; then |
| 455 detectDE | 459 detectDE |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 rm -f $kde_dir/$x.desktop | 1207 rm -f $kde_dir/$x.desktop |
| 1204 fi | 1208 fi |
| 1205 done | 1209 done |
| 1206 ;; | 1210 ;; |
| 1207 esac | 1211 esac |
| 1208 | 1212 |
| 1209 update_mime_database $xdg_base_dir | 1213 update_mime_database $xdg_base_dir |
| 1210 | 1214 |
| 1211 exit_success | 1215 exit_success |
| 1212 | 1216 |
| OLD | NEW |