Accepting request 136538 from home:vuntz:branches:X11:common:Factory
Import SuSEconfig script from glib2 here OBS-URL: https://build.opensuse.org/request/show/136538 OBS-URL: https://build.opensuse.org/package/show/X11:common:Factory/desktop-file-utils?expand=0&rev=38
This commit is contained in:
parent
ca6e8c8d0d
commit
0b1d386744
@ -1,3 +1,18 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Mon Oct 1 11:22:30 UTC 2012 - vuntz@opensuse.org
|
||||||
|
|
||||||
|
- Import SuSEconfig script from glib2 here:
|
||||||
|
+ This is needed as SuSEconfig is now dead, and we need a way to
|
||||||
|
generate the defaults.list file needed for the default MIME
|
||||||
|
associations. Part of bnc#782120.
|
||||||
|
+ Add suse-update-mime-defaults as source, and install it.
|
||||||
|
+ Call suse-update-mime-defaults in %post.
|
||||||
|
+ Call suse-update-mime-defaults from the %desktop_database_post
|
||||||
|
and %desktop_database_postun macros defined in
|
||||||
|
macros.desktop-file-utils. This way, packages using those
|
||||||
|
macros will regenerate the defaults.list files on
|
||||||
|
install/removal.
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Wed Sep 26 08:24:42 UTC 2012 - idonmez@suse.com
|
Wed Sep 26 08:24:42 UTC 2012 - idonmez@suse.com
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ License: GPL-2.0+
|
|||||||
Group: Development/Tools/Other
|
Group: Development/Tools/Other
|
||||||
Url: http://www.freedesktop.org/wiki/Software/desktop-file-utils
|
Url: http://www.freedesktop.org/wiki/Software/desktop-file-utils
|
||||||
Source0: http://www.freedesktop.org/software/desktop-file-utils/releases/%{name}-%{version}.tar.xz
|
Source0: http://www.freedesktop.org/software/desktop-file-utils/releases/%{name}-%{version}.tar.xz
|
||||||
|
Source1: suse-update-mime-defaults
|
||||||
Source2: macros.desktop-file-utils
|
Source2: macros.desktop-file-utils
|
||||||
# PATCH-FEATURE-OPENSUSE desktop-file-utils-suse-keys.patch vuntz@opensuse.org -- Handle SUSE-specific keys in validator. This is not strictly necessary, since they are prefixed with X-, but we can verify that the value has the right type.
|
# PATCH-FEATURE-OPENSUSE desktop-file-utils-suse-keys.patch vuntz@opensuse.org -- Handle SUSE-specific keys in validator. This is not strictly necessary, since they are prefixed with X-, but we can verify that the value has the right type.
|
||||||
Patch0: desktop-file-utils-suse-keys.patch
|
Patch0: desktop-file-utils-suse-keys.patch
|
||||||
@ -58,6 +59,8 @@ http://freedesktop.org/wiki/Specifications/desktop-entry-spec
|
|||||||
# manually do it.
|
# manually do it.
|
||||||
test ! -f %{buildroot}%{_datadir}/emacs/site-lisp/desktop-entry-mode.el
|
test ! -f %{buildroot}%{_datadir}/emacs/site-lisp/desktop-entry-mode.el
|
||||||
install -D -m644 misc/desktop-entry-mode.el %{buildroot}%{_datadir}/emacs/site-lisp/desktop-entry-mode.el
|
install -D -m644 misc/desktop-entry-mode.el %{buildroot}%{_datadir}/emacs/site-lisp/desktop-entry-mode.el
|
||||||
|
# Install suse-update-mime-defaults
|
||||||
|
install -m0755 %{SOURCE1} %{buildroot}%{_bindir}/suse-update-mime-defaults
|
||||||
# Install rpm macros
|
# Install rpm macros
|
||||||
install -D -m644 %{S:2} %{buildroot}%{_sysconfdir}/rpm/macros.desktop-file-utils
|
install -D -m644 %{S:2} %{buildroot}%{_sysconfdir}/rpm/macros.desktop-file-utils
|
||||||
# Create ghosts based on default $XDG_DATA_DIRS:
|
# Create ghosts based on default $XDG_DATA_DIRS:
|
||||||
@ -66,6 +69,7 @@ touch %{buildroot}%{_datadir}/applications/mimeinfo.cache
|
|||||||
|
|
||||||
%post
|
%post
|
||||||
%{_bindir}/update-desktop-database --quiet %{_datadir}/applications || true
|
%{_bindir}/update-desktop-database --quiet %{_datadir}/applications || true
|
||||||
|
%{_bindir}/suse-update-mime-defaults || true
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%defattr(-, root, root)
|
%defattr(-, root, root)
|
||||||
@ -73,6 +77,7 @@ touch %{buildroot}%{_datadir}/applications/mimeinfo.cache
|
|||||||
%{_bindir}/desktop-file-edit
|
%{_bindir}/desktop-file-edit
|
||||||
%{_bindir}/desktop-file-install
|
%{_bindir}/desktop-file-install
|
||||||
%{_bindir}/desktop-file-validate
|
%{_bindir}/desktop-file-validate
|
||||||
|
%{_bindir}/suse-update-mime-defaults
|
||||||
%{_bindir}/update-desktop-database
|
%{_bindir}/update-desktop-database
|
||||||
%ghost %{_datadir}/applications/mimeinfo.cache
|
%ghost %{_datadir}/applications/mimeinfo.cache
|
||||||
%{_mandir}/man1/desktop-file-edit.1*
|
%{_mandir}/man1/desktop-file-edit.1*
|
||||||
|
@ -22,7 +22,10 @@ if test -x %{_bindir}/update-desktop-database; then
|
|||||||
%else \
|
%else \
|
||||||
%{_bindir}/update-desktop-database --quiet "%{_datadir}/applications" || true \
|
%{_bindir}/update-desktop-database --quiet "%{_datadir}/applications" || true \
|
||||||
%endif \
|
%endif \
|
||||||
fi
|
fi \
|
||||||
|
if test -x %{_bindir}/suse-update-mime-defaults; then \
|
||||||
|
%{_bindir}/suse-update-mime-defaults || true \
|
||||||
|
fi
|
||||||
|
|
||||||
# On uninstall, update the desktop database. Note: we ignore upgrades (already
|
# On uninstall, update the desktop database. Note: we ignore upgrades (already
|
||||||
# handled in %post of the new package).
|
# handled in %post of the new package).
|
||||||
@ -35,4 +38,7 @@ if [ $1 -eq 0 ]; then
|
|||||||
%{_bindir}/update-desktop-database --quiet "%{_datadir}/applications" || true \
|
%{_bindir}/update-desktop-database --quiet "%{_datadir}/applications" || true \
|
||||||
%endif \
|
%endif \
|
||||||
fi \
|
fi \
|
||||||
|
if test -x %{_bindir}/suse-update-mime-defaults; then \
|
||||||
|
%{_bindir}/suse-update-mime-defaults || true \
|
||||||
|
fi \
|
||||||
fi
|
fi
|
||||||
|
243
suse-update-mime-defaults
Normal file
243
suse-update-mime-defaults
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# suse-update-mime-defaults - create default application ordering for MIME associations
|
||||||
|
#
|
||||||
|
# Copyright (C) 2012 Guido Berhoerster <gber@opensuse.org>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# TORTIOUS ACTION, ARISING OUT OF PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
|
||||||
|
export LC_ALL=C
|
||||||
|
|
||||||
|
# reset XDG_DATA_DIRS so it can be trusted
|
||||||
|
unset XDG_DATA_DIRS
|
||||||
|
if [ "${PROFILEREAD}" != "true" ]; then
|
||||||
|
. $r/etc/profile
|
||||||
|
fi
|
||||||
|
|
||||||
|
for desktop in gnome xfce lxde; do
|
||||||
|
awk -vdesktop=${desktop} '
|
||||||
|
# print a warning to stderr
|
||||||
|
function warn(msg, cmd) {
|
||||||
|
cmd = "cat >&2"
|
||||||
|
print msg | cmd
|
||||||
|
close(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
# print an error message and exit with the given exit status
|
||||||
|
function err(status, msg)
|
||||||
|
{
|
||||||
|
warn(msg)
|
||||||
|
exit_status = status
|
||||||
|
exit exit_status
|
||||||
|
}
|
||||||
|
|
||||||
|
# delete all elements of an array
|
||||||
|
function delete_array(arr, i) {
|
||||||
|
for (i in arr) {
|
||||||
|
delete arr[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# find preferred combination of mimetype and category
|
||||||
|
function find_preferred_category(mimetypes_categories, categories, mimetype,
|
||||||
|
i) {
|
||||||
|
for (i = 1; i in categories; i++) {
|
||||||
|
if (mimetype SUBSEP categories[i] in mimetypes_categories) {
|
||||||
|
return mimetypes_categories[mimetype,categories[i]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# sort keys of an array by index (using the awk default comparison)
|
||||||
|
function asorti2(src, dest, key, len) {
|
||||||
|
len = 0
|
||||||
|
delete_array(dest)
|
||||||
|
for (key in src) {
|
||||||
|
dest[len++] = key
|
||||||
|
}
|
||||||
|
|
||||||
|
_qsorti(dest, 0, len - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function array_swap(arr, i, j, tmp) {
|
||||||
|
tmp = arr[i]
|
||||||
|
arr[i] = arr[j]
|
||||||
|
arr[j] = tmp
|
||||||
|
}
|
||||||
|
|
||||||
|
# Based on Bentley, J. L., 2000. Programming Pearls. 2nd ed. Reading, MA:
|
||||||
|
# Addison-Wesley Professional.
|
||||||
|
function _qsorti(dest, l, u, val, i, j) {
|
||||||
|
if (l >= u) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
array_swap(dest, l, l + int(rand() * (u - l)))
|
||||||
|
val = dest[l]
|
||||||
|
i = l
|
||||||
|
j = u + 1
|
||||||
|
while (1) {
|
||||||
|
do { i++ } while (i <= u && dest[i] < val)
|
||||||
|
do { j-- } while (dest[j] > val)
|
||||||
|
if (i > j) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
array_swap(dest, i, j)
|
||||||
|
}
|
||||||
|
array_swap(dest, l, j)
|
||||||
|
|
||||||
|
_qsorti(dest, l, j - 1)
|
||||||
|
_qsorti(dest, j + 1, u)
|
||||||
|
}
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
desktop = desktop != "" ? desktop : "gnome"
|
||||||
|
if (desktop == "gnome") {
|
||||||
|
categories_list = "GNOME,GTK"
|
||||||
|
} else if (desktop == "xfce") {
|
||||||
|
categories_list = "XFCE,GTK"
|
||||||
|
} else if (desktop == "lxde") {
|
||||||
|
categories_list = "GTK"
|
||||||
|
}
|
||||||
|
split(categories_list, categories, /,/)
|
||||||
|
root = ENVIRON["r"]
|
||||||
|
defaults_conf = root "/etc/" desktop "_defaults.conf"
|
||||||
|
|
||||||
|
# parse desktop defaults preferences
|
||||||
|
lineno = 0
|
||||||
|
while ((getline < defaults_conf) > 0) {
|
||||||
|
lineno++
|
||||||
|
if (NF == 0 || $1 ~ /^#/) {
|
||||||
|
# skip comments and empty lines
|
||||||
|
continue
|
||||||
|
} else if (NF != 1) {
|
||||||
|
err(1, "syntax error in " defaults_conf " line " lineno)
|
||||||
|
} else if (split($1, arr, /=/) == 2) {
|
||||||
|
# handle MIME type defaults
|
||||||
|
mimetype_default_apps[arr[1]] = arr[2]
|
||||||
|
} else if ($1 ~ /^!.+\.desktop$/) {
|
||||||
|
# handle preferred default applications
|
||||||
|
preferred_default_apps[substr($1, 2)] = substr($1, 2)
|
||||||
|
} else if ($1 ~ /^.+\.desktop$/) {
|
||||||
|
# handle regular default applications
|
||||||
|
default_apps[$1] = $1
|
||||||
|
} else {
|
||||||
|
err(1, "syntax error in " defaults_conf ", line " lineno)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(defaults_conf)
|
||||||
|
|
||||||
|
# find all desktop files
|
||||||
|
for (i = split("XDG_DATA_DIRS" in ENVIRON ? ENVIRON["XDG_DATA_DIRS"] : \
|
||||||
|
"/usr/local/share:/usr/share", xdg_data_dirs, /:/); i > 0; i--) {
|
||||||
|
# XDG_DATA_DIRS is trusted here because it has been reset
|
||||||
|
cmd = "ls -1 -- \"" root xdg_data_dirs[i] "/applications/\"*.desktop " \
|
||||||
|
"2>/dev/null"
|
||||||
|
while ((cmd | getline desktopfile) > 0) {
|
||||||
|
l = split(desktopfile, arr, "/")
|
||||||
|
desktopfiles[arr[l]] = desktopfile
|
||||||
|
}
|
||||||
|
close(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
# process all desktop files in alphabetical order
|
||||||
|
asorti2(desktopfiles, desktopfiles_keys)
|
||||||
|
for (i = 0; i in desktopfiles_keys; i++) {
|
||||||
|
# parse a desktop file
|
||||||
|
desktopfile = desktopfiles_keys[i]
|
||||||
|
delete_array(desktopfile_mimetypes)
|
||||||
|
delete_array(desktopfile_categories)
|
||||||
|
lineno = 0
|
||||||
|
in_desktop_entry = 0
|
||||||
|
while ((getline < desktopfiles[desktopfile]) > 0) {
|
||||||
|
lineno++
|
||||||
|
if (NF == 0 || $1 ~ /^#/) {
|
||||||
|
# skip comments and empty lines
|
||||||
|
continue
|
||||||
|
} else if (in_desktop_entry == 0 && \
|
||||||
|
$0 ~ /^\[Desktop Entry\][\t ]*$/) {
|
||||||
|
# desktop entry group
|
||||||
|
in_desktop_entry = 1
|
||||||
|
} else if (in_desktop_entry == 1) {
|
||||||
|
if (in_desktop_entry == 1 && $1 ~ /^\[/) {
|
||||||
|
# quit when a different group starts, "Desktop Entry" must
|
||||||
|
# come first
|
||||||
|
break
|
||||||
|
} else if ($0 ~ /^MimeType *=/ && split($0, arr, /=/) == 2) {
|
||||||
|
# handle MimeTypes
|
||||||
|
gsub(/(^ *|; *$)/, "", arr[2])
|
||||||
|
split(arr[2], desktopfile_mimetypes, /;/)
|
||||||
|
} else if ($0 ~ /^Categories *=/ && split($0, arr, /=/) == 2) {
|
||||||
|
# handle Categories
|
||||||
|
gsub(/(^ *|; *$)/, "", arr[2])
|
||||||
|
split(arr[2], desktopfile_categories, /;/)
|
||||||
|
} else if ($0 ~ /^[A-Za-z0-9\[\]@_-]+ *=/) {
|
||||||
|
# skip other keys
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn("syntax error in " desktopfiles[desktopfile] ", line " \
|
||||||
|
lineno)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(desktopfiles[desktopfile])
|
||||||
|
|
||||||
|
# store the results
|
||||||
|
for (j = 1; j in desktopfile_mimetypes; j++) {
|
||||||
|
if (desktopfile_mimetypes[j] in mimetype_default_apps && \
|
||||||
|
mimetype_default_apps[desktopfile_mimetypes[j]] == \
|
||||||
|
desktopfile) {
|
||||||
|
mimetype_defaults[desktopfile_mimetypes[j]] = desktopfile
|
||||||
|
}
|
||||||
|
if (desktopfile in preferred_default_apps) {
|
||||||
|
preferred_defaults[desktopfile_mimetypes[j]] = desktopfile
|
||||||
|
}
|
||||||
|
if (desktopfile in default_apps) {
|
||||||
|
defaults[desktopfile_mimetypes[j]] = desktopfile
|
||||||
|
}
|
||||||
|
for (k = 1; k in desktopfile_categories; k++) {
|
||||||
|
mimetypes_categories[desktopfile_mimetypes[j], \
|
||||||
|
desktopfile_categories[k]] = desktopfile
|
||||||
|
}
|
||||||
|
generic_mimetypes[desktopfile_mimetypes[j]] = desktopfile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# determine default mimetype handlers
|
||||||
|
for (mimetype in generic_mimetypes) {
|
||||||
|
if (mimetype in mimetype_defaults) {
|
||||||
|
defaults_list[mimetype] = mimetype_defaults[mimetype]
|
||||||
|
} else if (mimetype in preferred_defaults) {
|
||||||
|
defaults_list[mimetype] = preferred_defaults[mimetype]
|
||||||
|
} else if (mimetype in defaults) {
|
||||||
|
defaults_list[mimetype] = defaults[mimetype]
|
||||||
|
} else if ((desktopfile = \
|
||||||
|
find_preferred_category(mimetypes_categories, categories, \
|
||||||
|
mimetype)) != "") {
|
||||||
|
defaults_list[mimetype] = desktopfile
|
||||||
|
} else if (mimetype in generic_mimetypes) {
|
||||||
|
defaults_list[mimetype] = generic_mimetypes[mimetype]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print "# generated by suse-update-mime-defaults from " defaults_conf
|
||||||
|
print "[Default Applications]"
|
||||||
|
asorti2(defaults_list, defaults_list_keys)
|
||||||
|
for (i = 0; i in defaults_list_keys; i++) {
|
||||||
|
mimetype = defaults_list_keys[i]
|
||||||
|
printf("%s=%s\n", mimetype, defaults_list[mimetype])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' >$r/var/cache/gio-2.0/${desktop}-defaults.list
|
||||||
|
done
|
Loading…
Reference in New Issue
Block a user