summaryrefslogtreecommitdiffstats
path: root/meta/classes/mime-xdg.bbclass
diff options
context:
space:
mode:
authorAndreas Müller <schnitzeltony@gmail.com>2020-01-17 22:29:06 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-01-19 13:24:38 +0000
commit94c42e7fdd69ed39d475156a776f6f80d4165932 (patch)
tree62c00a8279499bff6b4b102156cab91f28478986 /meta/classes/mime-xdg.bbclass
parent27767c55df1c0686c42303aecec9c4720d2bb9bc (diff)
downloadpoky-94c42e7fdd69ed39d475156a776f6f80d4165932.tar.gz
mime-xdg.bbclass: initial add
When opening files by file-browsers on fresh images, user has to choose the application to open from the pool af ALL known applications even those not designed to open the file selected. By inheriting this classs in recipes the assosiations in /usr/share/applications/mimeinfo.cache are build by calling update-desktop-database. (From OE-Core rev: 20208d6763e725cea211f933ec1c8e32733a10af) Signed-off-by: Andreas Müller <schnitzeltony@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/mime-xdg.bbclass')
-rw-r--r--meta/classes/mime-xdg.bbclass74
1 files changed, 74 insertions, 0 deletions
diff --git a/meta/classes/mime-xdg.bbclass b/meta/classes/mime-xdg.bbclass
new file mode 100644
index 0000000000..63169e990d
--- /dev/null
+++ b/meta/classes/mime-xdg.bbclass
@@ -0,0 +1,74 @@
1#
2# This class creates mime <-> application associations based on entry
3# 'MimeType' in *.desktop files
4#
5
6DEPENDS += "desktop-file-utils"
7PACKAGE_WRITE_DEPS += "desktop-file-utils-native"
8DESKTOPDIR = "${datadir}/applications"
9
10# There are recipes out there installing their .desktop files as absolute
11# symlinks. For us these are dangling and cannot be introspected for "MymeType"
12# easily. By addding package-names to MIME_XDG_PACKAGES, packager can force
13# proper update-desktop-database handling. Note that all introspection is
14# skipped for MIME_XDG_PACKAGES not empty
15MIME_XDG_PACKAGES ?= ""
16
17mime_xdg_postinst() {
18if [ "x$D" != "x" ]; then
19 $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \
20 mlprefix=${MLPREFIX} \
21 desktop_dir=${DESKTOPDIR}
22else
23 update-desktop-database $D${DESKTOPDIR}
24fi
25}
26
27mime_xdg_postrm() {
28if [ "x$D" != "x" ]; then
29 $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \
30 mlprefix=${MLPREFIX} \
31 desktop_dir=${DESKTOPDIR}
32else
33 update-desktop-database $D${DESKTOPDIR}
34fi
35}
36
37python populate_packages_append () {
38 packages = d.getVar('PACKAGES').split()
39 pkgdest = d.getVar('PKGDEST')
40 desktop_base = d.getVar('DESKTOPDIR')
41 forced_mime_xdg_pkgs = (d.getVar('MIME_XDG_PACKAGES') or '').split()
42
43 for pkg in packages:
44 desktops_with_mime_found = pkg in forced_mime_xdg_pkgs
45 if d.getVar('MIME_XDG_PACKAGES') == '':
46 desktop_dir = '%s/%s%s' % (pkgdest, pkg, desktop_base)
47 if os.path.exists(desktop_dir):
48 for df in os.listdir(desktop_dir):
49 if df.endswith('.desktop'):
50 try:
51 with open(desktop_dir + '/'+ df, 'r') as f:
52 for line in f.read().split('\n'):
53 if 'MimeType' in line:
54 desktops_with_mime_found = True
55 break;
56 except:
57 bb.warn('Could not open %s. Set MIME_XDG_PACKAGES in recipe or add mime-xdg to INSANE_SKIP.' % desktop_dir + '/'+ df)
58 if desktops_with_mime_found:
59 break
60 if desktops_with_mime_found:
61 bb.note("adding mime-xdg postinst and postrm scripts to %s" % pkg)
62 postinst = d.getVar('pkg_postinst_%s' % pkg)
63 if not postinst:
64 postinst = '#!/bin/sh\n'
65 postinst += d.getVar('mime_xdg_postinst')
66 d.setVar('pkg_postinst_%s' % pkg, postinst)
67 postrm = d.getVar('pkg_postrm_%s' % pkg)
68 if not postrm:
69 postrm = '#!/bin/sh\n'
70 postrm += d.getVar('mime_xdg_postrm')
71 d.setVar('pkg_postrm_%s' % pkg, postrm)
72 bb.note("adding desktop-file-utils dependency to %s" % pkg)
73 d.appendVar('RDEPENDS_' + pkg, " " + d.getVar('MLPREFIX')+"desktop-file-utils")
74}