From e6f3cfbba18862a02e27bd0da2823f5ea8440808 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sun, 21 Mar 2021 23:27:05 +0100 Subject: [type/__dtnrch_etax_sgnp] Patch icons on freedesktop systems --- type/__dtnrch_etax_sgnp/files/extract_icon_map.awk | 41 ++++++++++++++ type/__dtnrch_etax_sgnp/gencode-remote | 63 ++++++++++++++++++++++ type/__dtnrch_etax_sgnp/manifest | 3 ++ 3 files changed, 107 insertions(+) create mode 100644 type/__dtnrch_etax_sgnp/files/extract_icon_map.awk diff --git a/type/__dtnrch_etax_sgnp/files/extract_icon_map.awk b/type/__dtnrch_etax_sgnp/files/extract_icon_map.awk new file mode 100644 index 0000000..c295fc1 --- /dev/null +++ b/type/__dtnrch_etax_sgnp/files/extract_icon_map.awk @@ -0,0 +1,41 @@ +#!/usr/bin/awk -f +# Extracts a mapping from file extension to .ico file stored in i4jparams.conf + +// { + match($0, /^[ ]*/) + file_assoc = RLENGTH + next +} +/<\/object>/ && file_assoc { + match($0, /^[ ]*/) + if (RLENGTH == file_assoc) { + if (file_ext && file_icon) + printf "%s\t%s\n", file_ext, file_icon + file_assoc = 0 + file_ext = "" + file_icon = "" + next + } +} + +file_assoc && // { + while (getline && !/<\/void>/) { + if (/.*<\/string>/) { + file_ext = $0 + sub(/^.*/, "", file_ext) + sub(/<\/string>.*$/, "", file_ext) + break + } + } +} + +// { + while (getline && !/<\/void>/) { + if (/.*<\/string>/) { + file_icon = $0 + sub(/^.*/, "", file_icon) + sub(/<\/string>.*$/, "", file_icon) + break + } + } +} diff --git a/type/__dtnrch_etax_sgnp/gencode-remote b/type/__dtnrch_etax_sgnp/gencode-remote index 215f66b..2618939 100755 --- a/type/__dtnrch_etax_sgnp/gencode-remote +++ b/type/__dtnrch_etax_sgnp/gencode-remote @@ -18,6 +18,9 @@ # along with cdist. If not, see . # +quote() { printf "'%s'" "$(printf '%s\n' "$*" | sed -e "s/'/'\\\\''/g")"; } +drop_awk_comments() { quote "$(sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@")"; } + version=$(cat "${__object:?}/parameter/version") if test -s "${__object:?}/parameter/prefix" @@ -126,4 +129,64 @@ then # NOTE: # xdg-desktop-menu install --mode system "\${main_desktop_file}" # only works for files with no spaces + + # Install icons + cat <<-EOF + + + install_icon() { + _mime=application-x-\$1 + _ico=\$2 + + _tmp=\$(mktemp "${TMPDIR:-/tmp}/ico-XXXXXX.png") + chown 0:0 "\${_tmp}" + chmod 0644 "\${_tmp}" + + + identify "\${_ico}" \\ + | while read -r _i _fmt _size _ + do + convert "\${_i}" -alpha on "\${_tmp}" + + xdg-icon-resource install --mode system --context mimetypes \\ + --size "\${_size#*x}" "\${_tmp}" "\${_mime}" + done + + rm -f "\${_tmp}" + } + + awk $(drop_awk_comments "${__type:?}/files/extract_icon_map.awk") $(quote "${install_dir}/.install4j/i4jparams.conf") \\ + | while read -r _ext _ico_file + do + case \${_ext} + in + (sgnp$((version))) + install_icon sgnp$((version)) $(quote "${install_dir}/.install4j")/\${_ico_file} + ;; + (sgnp$((version + 100))) + install_icon sgnp$((version))-submission $(quote "${install_dir}/.install4j")/\${_ico_file} + ;; + (sgbe$((version + 1))) + install_icon sgbe$((version + 1)) $(quote "${install_dir}/.install4j")/\${_ico_file} + ;; + (sgbe$((version + 101))) + install_icon sgbe$((version + 1))-submission $(quote "${install_dir}/.install4j")/\${_ico_file} + ;; + esac + done + EOF + +elif grep -q "^__dtnrch_install4j${i4j_object_name}:uninstalled" "${__messages_in:?}" \ + && ${is_freedesktop} +then + # Remove icons + cat <<-EOF + for _mime in sgnp$((version)) sgnp$((version))-submission sgbe$((version+1)) sgbe$((version+1))-submission + do + for _size in 16 32 48 128 + do + xdg-icon-resource uninstall --mode system --context mimetypes --size \$((_size)) application-x-\${_mime} + done + done + EOF fi diff --git a/type/__dtnrch_etax_sgnp/manifest b/type/__dtnrch_etax_sgnp/manifest index db89d70..63262e9 100755 --- a/type/__dtnrch_etax_sgnp/manifest +++ b/type/__dtnrch_etax_sgnp/manifest @@ -221,6 +221,9 @@ if ${is_freedesktop} then if test "${custom_mime_state}" = 'present' then + # required for icon conversion + __package imagemagick + # Generate custom MIME declaration for SGnP application mkdir "${__object:?}/files" "${__type:?}/files/mkmime.xml.sh" >"${__object:?}/files/mime-sgnp${version}.xml" -- cgit v1.2.3