From cf2a703b19d64f939890dcea79b3bd8d2a9a08fe Mon Sep 17 00:00:00 2001
From: Ongun Kanat <ongun.kanat@gmail.com>
Date: Fri, 12 Jul 2019 16:22:35 +0200
Subject: [PATCH] Fix xdg-mime for proper Plasma 5 support

This adds checks for Plasma 5 and runs kbuildsycoca5 after
updating mimeapps.list file. The path of the file is
detected via qtpaths utility.
---
 scripts/xdg-mime.in | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/scripts/xdg-mime.in b/scripts/xdg-mime.in
index 0e567c7..1ac6a3d 100644
--- a/scripts/xdg-mime.in
+++ b/scripts/xdg-mime.in
@@ -133,7 +133,10 @@ make_default_kde()
     # text/plain=gnome-gedit.desktop;gnu-emacs.desktop;
     vendor="$1"
     mimetype="$2"
-    if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
+    if [ x"$KDE_SESSION_VERSION" = x"5" ]; then
+        default_dir=$(qtpaths --writable-path ConfigLocation)
+        default_file="$default_dir/mimeapps.list"
+    elif [ x"$KDE_SESSION_VERSION" = x"4" ]; then
         default_dir=`kde4-config --path xdgdata-apps 2> /dev/null | cut -d ':' -f 1`
         default_file="$default_dir/mimeapps.list"
     else
@@ -148,7 +151,7 @@ make_default_kde()
     DEBUG 1 "Updating $default_file"
     mkdir -p "$default_dir"
     [ -f "$default_file" ] || touch "$default_file"
-    if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
+    if [ x"$KDE_SESSION_VERSION" = x"4" ] || [ x"$KDE_SESSION_VERSION" = x"5" ]; then
         [ -f "$default_file" ] || touch "$default_file"
         awk -v application="$vendor" -v mimetype="$mimetype" '
     BEGIN {
@@ -207,7 +210,7 @@ make_default_kde()
         }
     }
 ' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_file"
-        eval 'kbuildsycoca4'$xdg_redirect_output
+        eval 'kbuildsycoca${KDE_SESSION_VERSION}'$xdg_redirect_output
     else
         awk -v application="$vendor" -v mimetype="$mimetype" '
     BEGIN {
@@ -576,6 +579,11 @@ if [ "$action" = "makedefault" ]; then
 
         make_default_kde "$filename" "$mimetype"
         make_default_generic "$filename" "$mimetype"
+        detectDE
+
+        if [ x"$DE" = x"kde" ]; then
+            eval 'kbuildsycoca${KDE_SESSION_VERSION}'$xdg_redirect_output
+        fi
     done
     exit_success
 fi
-- 
2.21.0