LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   As a packager, can you prevent a program from taking over as default for file associations? (https://www.linuxquestions.org/questions/slackware-14/as-a-packager-can-you-prevent-a-program-from-taking-over-as-default-for-file-associations-4175693479/)

bassmadrigal 04-10-2021 06:56 PM

As a packager, can you prevent a program from taking over as default for file associations?
 
Per the title, is it possible to ensure a program can't take over as the default application for file types? My experience is strictly with KDE4 (on 14.2), so I'm not sure if this is specifically a KDE issue or something within the OS itself.

Background

I'm the maintainer of mediainfo. When I install this package (with the GUI=yes option), mediainfo-gui becomes the default application for several different file types (I've changed the defaults on my system, so I couldn't tell you which ones).

This also happens with MusicBrainz's picard, taking over aac, ac3 and midi.

I also noticed that EasyTag has become the default application for flac and mp3.

I know I can change the defaults back, but it seems that there should be a way to prevent certain programs from ever being default (assuming another program is already registered to the system). I don't think anyone would ever want to double click a media file and have mediainfo open up (especially when it adds an entry to the context menu).

I maintain both mediainfo and picard on SBo and I'd love to be able to add something to the resulting packages to make sure I'm not mucking up with people's file associations.

Any ideas?

giomat 04-11-2021 07:38 AM

So the culprit seems to be this command
Code:

if [ -x /usr/bin/update-desktop-database ]; then
  /usr/bin/update-desktop-database -q usr/share/applications
fi

which is run by the doinst.sh of most desktop application packages.
From the manpage:
Code:

The update-desktop-database program is a tool to build a cache database of the MIME types handled by desktop files...
As I understand, the command scans for .desktop files in the directory /usr/share/applications and updates the MIME types database reading the variable "MimeType" in the .desktop files.

For example, gvim.desktop contains the following
Code:

MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
You can override these associations using various config files, usually in the home directory, and these are handled by KDE/Gnome/whatever-desktop coming with MIME types association editing tools.
To answer your question, you could try disabling that command in the doinst.sh and see what happens.

shruggy 04-11-2021 08:05 AM

Disabling the command won't help in the long run because the next install of any desktop application will run it again. Unless you disable it in all software using GUI, that is.

A better approach would be creating Override.xml as described in the Shared MIME info specification. Or overriding the system MIME defaults via files in ~/.local/share/mime/ and/or /usr/local/share/mime/ because they take higher precedence.

Bonzoo 04-11-2021 08:48 AM

Just right click the file and look at permissions..."Opens With"
DONE. All files with that suffix will open with that program selected.
KDE ? Dunno. Never will

Bonzoo 04-11-2021 08:51 AM

Maybe if the Gates desktop environment gives a fit you could sudo dolphin in the terminal ?

EdGr 04-11-2021 10:08 AM

The idea that the computer could correctly guess which program the user wants to run on a file was doomed from the beginning.

If you are writing software, I recommend avoiding the MIME database.
Ed

bassmadrigal 04-11-2021 01:49 PM

Quote:

Originally Posted by giomat (Post 6239875)
So the culprit seems to be this command
Code:

if [ -x /usr/bin/update-desktop-database ]; then
  /usr/bin/update-desktop-database -q usr/share/applications
fi

which is run by the doinst.sh of most desktop application packages.

--snip--

To answer your question, you could try disabling that command in the doinst.sh and see what happens.

The problem with this is I believe it removes the program from the "Open With" dialog. I want to allow users to still open the program, but I just don't want the program to take over existing defaults without the user specifying it.

Quote:

Originally Posted by shruggy (Post 6239880)
A better approach would be creating Override.xml as described in the Shared MIME info specification. Or overriding the system MIME defaults via files in ~/.local/share/mime/ and/or /usr/local/share/mime/ because they take higher precedence.

If I'm understanding this correctly, this would just be for individual users, right? Not something a software packager can (or should) do.

Quote:

Originally Posted by EdGr (Post 6239910)
The idea that the computer could correctly guess which program the user wants to run on a file was doomed from the beginning.

If you are writing software, I recommend avoiding the MIME database.
Ed

What's the alternative for a MIME database?

From my albeit limited understanding, MIME databases are still handy for GUI apps and to let users know what programs are able to open what. However, I was just hoping there was some setting to state that you don't want to have a program become a default over other existing programs. I don't foresee anyone installing EasyTag would want that to open up by default when they double-click on an mp3, yet that's what happened on my system after installing it. I then needed to go through and adjust the default program back to my original program.

Loomx 04-11-2021 01:58 PM

[ Sorry, just realised that you are looking for something to add at a package level... please ignore the noise from here ]

Maybe try using a file ~/.config/mimeapps.list ?
This is what I set up for my students so that things open in the expected programs.
This is using XFCE, so it's possible it might not work under KDE.

Here is my default example:
(Where there are two options listed, the first one is the default)
Code:

[Default Applications]
image/jpeg=gthumb.desktop;
image/png=gthumb.desktop;
video/mp4=vlc.desktop;shotcut.desktop;
video/x-matroska=vlc.desktop;shotcut.desktop;
text/plain=mousepad.desktop
application/x-shellscript=mousepad.desktop;
application/pdf=atril.desktop;
application/octet-stream=soffice.desktop;
audio/mpeg=audacious.desktop;
audio/x-mpegurl=audacious.desktop;

[Added Associations]


bassmadrigal 04-11-2021 02:03 PM

Quote:

Originally Posted by Loomx (Post 6239985)
[ Sorry, just realised that you are looking for something to add at a package level... please ignore the noise from here ]

I renamed the title to hopefully clear it up better.

But your post might help someone searching for how to do it on their end... Thanks for keeping it!

shruggy 04-11-2021 02:26 PM

Quote:

Originally Posted by bassmadrigal (Post 6239980)
If I'm understanding this correctly, this would just be for individual users, right? Not something a software packager can (or should) do.

Then I misunderstood your question. I thought you want it as a user, not as a packager.

Determining what is the default application for a given MIME type is managed by KDE via mimeapps.list. See this question at SE. The file is searched in this order:
Code:

~/.config/kde-mimeapps.list
~/.config/mimeapps.list
/etc/xdg/kde-mimeapps.list
/etc/xdg/mimeapps.list
/usr/share/applications/kde-mimeapps.list
/usr/share/applications/mimeapps.list

Its format is described in MIME apps spec.

EdGr 04-11-2021 03:02 PM

Quote:

Originally Posted by bassmadrigal (Post 6239980)
What's the alternative for a MIME database?

From my albeit limited understanding, MIME databases are still handy for GUI apps and to let users know what programs are able to open what. However, I was just hoping there was some setting to state that you don't want to have a program become a default over other existing programs. I don't foresee anyone installing EasyTag would want that to open up by default when they double-click on an mp3, yet that's what happened on my system after installing it. I then needed to go through and adjust the default program back to my original program.

Let the user decide which program to run. This is most practical if one is writing new software. Otherwise, one needs to muck with mimeapps.list as shruggy described.
Ed

bassmadrigal 04-11-2021 03:23 PM

Quote:

Originally Posted by shruggy (Post 6239992)
Then I misunderstood your question. I thought you want it as a user, not as a packager.

Determining what is the default application for a given MIME type is managed by KDE via mimeapps.list. See this question at SE. The file is searched in this order:
Code:

~/.config/kde-mimeapps.list
~/.config/mimeapps.list
/etc/xdg/kde-mimeapps.list
/etc/xdg/mimeapps.list
/usr/share/applications/kde-mimeapps.list
/usr/share/applications/mimeapps.list

Its format is described in MIME apps spec.

Unfortunately, none of this seems to help a packager prevent their program from becoming default. Also, none of those exist on my 14.2 system except for ~/.config/mimeapps.list

Based on this thread, it seems that as a packager, I'll just have no control over this and it'll be up to users to change it back if the system decides to change things. That's unfortunate.

Quote:

Originally Posted by EdGr (Post 6240001)
Let the user decide which program to run. This is most practical if one is writing new software. Otherwise, one needs to muck with mimeapps.list as shruggy described.

How does a user know what programs are able to run a file without a MIME database? And how does the WM/DE know to associate a program with a specific type of file? I do like having EasyTag show up as a program in the "Open With" submenu, and I don't think that is possible without some sort of MIME database...

EdGr 04-11-2021 03:37 PM

Quote:

Originally Posted by bassmadrigal (Post 6240006)
How does a user know what programs are able to run a file without a MIME database? And how does the WM/DE know to associate a program with a specific type of file? I do like having EasyTag show up as a program in the "Open With" submenu, and I don't think that is possible without some sort of MIME database...

The user knows which program to run on a file. That works on the command line, and it works in GUI programs too. :)

At this point, I can't provide more help with MIME or KDE because I do not use them. One motivation for creating my own system was that I have a lot of file types that MIME and file sniffers don't recognize. The user (me) knows exactly what they are.
Ed

bassmadrigal 04-11-2021 07:21 PM

Quote:

Originally Posted by EdGr (Post 6240009)
The user knows which program to run on a file. That works on the command line, and it works in GUI programs too. :)

On commandline, there's no easy way (that I'm aware of) for users to know what programs support what. They need to just try programs until they find one that works the way they want it to. If you're on an unfamiliar system and only have the CLI available, how do you know what can open up an mp3? I ask because I had to do this recently while trying to debug conty. Luckily, mpg123 was on there and I was able to find it after digging through the /usr/bin directory.

However, there's no reason to do that in a WM/DE. When you double click on an mp3, you expect it to play in a program. If you want to see what other programs may be available to play the file, you can right click and see what's in the "Open with" submenu. A MIME database is key to this functionality.

Anyway, my post was not to debate the positives or negatives of a MIME database. I simply wanted to know if it's possible for a packager to prevent their package from taking over defaults when a user installs it. If you want to keep debating whether people should use MIME databases, please open a new thread to discuss it. Thanks! :)

shruggy 04-12-2021 02:44 AM

Quote:

Originally Posted by bassmadrigal (Post 6240045)
On commandline, there's no easy way (that I'm aware of) for users to know what programs support what. They need to just try programs until they find one that works the way they want it to. If you're on an unfamiliar system and only have the CLI available, how do you know what can open up an mp3?

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.


All times are GMT -5. The time now is 05:33 PM.