LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-12-2021, 03:12 AM   #16
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Original Poster
Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656

Quote:
Originally Posted by shruggy View Post
The xdg-utils package is part of Slackware 14.2. Does
Code:
xdg-mime query default audio/mp3
or
Code:
xdg-mime query default audio/mpeg
not work in Slackware?

BTW,
Code:
xdg-mime default org.kde.amarok.desktop audio/mpeg
is the command line way to set the default application for a MIME type.
Yes, it works. I wasn't aware of that command, but discussing how MIME types can be checked in the CLI is not the point of this thread.

Based on the posts, I think the only option for packagers would be to query the MIME database for any supported file associations before running the commands in the doinst.sh and then reset any changed MIME types, but that seems like something that would be frowned on by the SBo admins and would be an abuse of the doinst.sh script. I was hoping there would be something already provided by upstream to prevent this, but I guess it's something every Linux user will need to deal with.
 
Old 04-12-2021, 03:37 AM   #17
chris.willing
Member
 
Registered: Jun 2014
Location: Brisbane, Australia
Distribution: Slackware,LFS
Posts: 915

Rep: Reputation: 619Reputation: 619Reputation: 619Reputation: 619Reputation: 619Reputation: 619
Quote:
Originally Posted by bassmadrigal View Post
Based on the posts, I think the only option for packagers would be to query the MIME database for any supported file associations before running the commands in the doinst.sh and then reset any changed MIME types, but that seems like something that would be frowned on by the SBo admins and would be an abuse of the doinst.sh script.
Probably not an abuse, regardless of SBo admins. Have a look at the doinst.sh for xdg-utils itself (at /var/log/scripts/xdg-utils-1.1.1-noarch-1 for 14.2, /var/lib/pkgtools/scripts/xdg-utils-1.1.3-noarch-4 for -current). It checks for a file in the host file system (not part of the xdg-utils package itself, I think), then makes changes to it. That's not miles away from what you'd be doing.

chris
 
Old 04-12-2021, 05:55 AM   #18
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
I remember some time ago I, too, had some trouble with mimetypes and files being opened by the wrong apps. Although I do not use KDE I will still share the experience, it might be at least partially applicable or may give you some new ideas. To keep things simple I will only consider /usr/share/applications as the location that is processed. All that is said may apply (in part) to other locations such as /usr/local or $HOME/.local.

Quote:
Originally Posted by bassmadrigal View Post
I think the only option for packagers would be to query the MIME database for any supported file associations before running the commands in the doinst.sh and then reset any changed MIME types
This might not work. The app that opens the file is determined by the script /usr/share/xdg-mime. Here is the code that determines which application KDE uses for the mimetype:
Code:
defapp_kde()
{
    MIME="$1"

    if [ -n "${KDE_SESSION_VERSION}" ]; then
      case "${KDE_SESSION_VERSION}" in
        4)
          KTRADER=`which ktraderclient 2> /dev/null`
          MIMETYPE="--mimetype"
          SERVICETYPE="--servicetype"
        ;;
        5)
          KTRADER=`which ktraderclient${KDE_SESSION_VERSION} 2> /dev/null`
          MIMETYPE="--mimetype"
          SERVICETYPE="--servicetype"
        ;;
      esac
    else
...
        defapp_generic "$1"
    fi
}
KDE 4/5 uses ktraderclient to determine the application that processes the mimetype. As you can see, this branch is only entered when $KDE_SESSION_VERSION is set. This variable may not be set when you install as root. So the script will call the defapp_generic() function:

Code:
defapp_generic() {
...
    for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
       for prefix in "$XDG_MENU_PREFIX" ""; do
          DEBUG 2 "Checking $x/applications/${prefix}defaults.list and $x/applications/${prefix}mimeinfo.cache"
          trader_result=`grep "$MIME=" $x/applications/${prefix}defaults.list $x/ap     plications/${prefix}mimeinfo.cache 2> /dev/null | head -n 1 | cut -d '=' -f 2 | cut      -d ';' -f 1`
          if [ -n "$trader_result" ] ; then
              echo $trader_result
              exit_success
          fi
       done
    done

    defapp_fallback $MIME
    exit_success
}
I left out the part that process the file mimeapps.list since it is not present in Slackware 14.2. Emphasized in bold are two other lists that are processed in /usr/share/applications: defaults.list and mimeinfo.cache.

KDE may also have them as kde-defaults.list and kde-mimeinfo.cache, I am not sure about that.

If no hit is found in those lists then the script will call defapp_fallback(). This function will search all *.desktop files in /usr/share/applications for the mimetype. A desktop file may define its own priority, however, none of my *.desktop files do that on my 14.2 install. At this point it selects the first hit.

As I said, I do not use KDE and I do not know how ktraderclient determines the application for the mimetype, it may take aforementioned lists and *.desktop files into consideration.

So my suggestion would be to look in the source of your package and see if it installs a *.desktop file. It might be as "easy" as simply preventing it from installing that *.desktop file. Or install it as *.desktop.void, this way it would still be there as template. If someone wants to use 'mediainfo/picard/easytag' as default app then he would not have to recreate it from scratch. But those are just guesses, the different processes for different DEs certainly complicate things.

Hope this helps.

Last edited by crts; 04-12-2021 at 01:21 PM.
 
1 members found this post helpful.
Old 04-12-2021, 03:07 PM   #19
notzed
Member
 
Registered: Dec 2020
Location: South Australia
Distribution: slackware64-current
Posts: 95

Rep: Reputation: Disabled
But one needs to install the .desktop file(s) for GUI applications because that's how applications are detected by all the desktops for creating the application menus or searching. It's the only mechanism for app discovery for the GUI (showing a list of /usr/bin isn't a practical solution, and lol at the idea that people 'know what they want to run' in advance). It's not just for mime-type association.

The first-found approach seems as good a decision as any for selecting the default application when the set of applications changes. Without a properly implemented priority system there's no good way to select from amongst multiple choices - and even a priority system would be messy. I mean look at what windows does, yuck - the last app you installed is the default. On Android if you have more than one application that can service a type (or action) it just shows all options each time until you set one specifically - but defaults to the last one you used iirc.

An easy way to "fix" this would the xdg app-launching system to just lock-in whatever is used by the user the first time they open a given file type as the default. But that's somewhat out of the scope of tasks for a packager.

Or just let the user get confused that one time and then set what they want and have it stick after that. Presumably if they're gone of of their way to install a new non-system-supplied application they know what it does or want to find out so it showing up shouldn't be that big of a surprise? And it might teach some computer literacy along the way.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] what instruction to prevent one OS's boot taking over computer solarwarrior Linux - Desktop 4 02-16-2018 02:04 PM
File associations in Gnome Commander vs. associations in Nautilus taylorkh Linux - Software 0 01-01-2010 05:18 PM
File type associations with default applications in Gnome/FC3 mjbrej Fedora 3 12-25-2004 05:28 PM
Program Associations rkid Linux - Software 3 10-11-2003 12:06 PM
Program associations in Gnome jsin Linux - Newbie 4 09-26-2003 10:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration