]> pere.pagekite.me Git - homepage.git/blob - blog/data/2016-06-05-open-your-files.txt
Generated.
[homepage.git] / blog / data / 2016-06-05-open-your-files.txt
1 Title: A program should be able to open its own files on Linux
2 Tags: english, debian
3 Date: 2016-06-05 08:30
4
5 <p>Many years ago, when koffice was fresh and with few users, I
6 decided to test its presentation tool when making the slides for a
7 talk I was giving for NUUG on Japhar, a free Java virtual machine. I
8 wrote the first draft of the slides, saved the result and went to bed
9 the day before I would give the talk. The next day I took a plane to
10 the location where the meeting should take place, and on the plane I
11 started up koffice again to polish the talk a bit, only to discover
12 that kpresenter refused to load its own data file. I cursed a bit and
13 started making the slides again from memory, to have something to
14 present when I arrived. I tested that the saved files could be
15 loaded, and the day seemed to be rescued. I continued to polish the
16 slides until I suddenly discovered that the saved file could no longer
17 be loaded into kpresenter. In the end I had to rewrite the slides
18 three times, condensing the content until the talk became shorter and
19 shorter. After the talk I was able to pinpoint the problem &ndash;
20 kpresenter wrote inline images in a way itself could not understand.
21 Eventually that bug was fixed and kpresenter ended up being a great
22 program to make slides. The point I'm trying to make is that we
23 expect a program to be able to load its own data files, and it is
24 embarrassing to its developers if it can't.</p>
25
26 <p>Did you ever experience a program failing to load its own data
27 files from the desktop file browser? It is not a uncommon problem. A
28 while back I discovered that the screencast recorder
29 gtk-recordmydesktop would save an Ogg Theora video file the KDE file
30 browser would refuse to open. No video player claimed to understand
31 such file. I tracked down the cause being <tt>file --mime-type</tt>
32 returning the application/ogg MIME type, which no video player I had
33 installed listed as a MIME type they would understand. I asked for
34 <a href="http://bugs.gw.com/view.php?id=382">file to change its
35 behavour</a> and use the MIME type video/ogg instead. I also asked
36 several video players to add video/ogg to their desktop files, to give
37 the file browser an idea what to do about Ogg Theora files. After a
38 while, the desktop file browsers in Debian started to handle the
39 output from gtk-recordmydesktop properly.</p>
40
41 <p>But history repeats itself. A few days ago I tested the music
42 system Rosegarden again, and I discovered that the KDE and xfce file
43 browsers did not know what to do with the Rosegarden project files
44 (*.rg). I've reported <a href="http://bugs.debian.org/825993">the
45 rosegarden problem to BTS</a> and a fix is commited to git and will be
46 included in the next upload. To increase the chance of me remembering
47 how to fix the problem next time some program fail to load its files
48 from the file browser, here are some notes on how to fix it.</p>
49
50 <p>The file browsers in Debian in general operates on MIME types.
51 There are two sources for the MIME type of a given file. The output from
52 <tt>file --mime-type</tt> mentioned above, and the content of the
53 shared MIME type registry (under /usr/share/mime/). The file MIME
54 type is mapped to programs supporting the MIME type, and this
55 information is collected from
56 <a href="https://www.freedesktop.org/wiki/Specifications/desktop-entry-spec/">the
57 desktop files</a> available in /usr/share/applications/. If there is
58 one desktop file claiming support for the MIME type of the file, it is
59 activated when asking to open a given file. If there are more, one
60 can normally select which one to use by right-clicking on the file and
61 selecting the wanted one using 'Open with' or similar. In general
62 this work well. But it depend on each program picking a good MIME
63 type (preferably
64 <a href="http://www.iana.org/assignments/media-types/media-types.xhtml">a
65 MIME type registered with IANA</a>), file and/or the shared MIME
66 registry recognizing the file and the desktop file to list the MIME
67 type in its list of supported MIME types.</p>
68
69 <p>The <tt>/usr/share/mime/packages/rosegarden.xml</tt> entry for
70 <a href="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">the
71 Shared MIME database</a> look like this:</p>
72
73 <p><blockquote><pre>
74 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
75 &lt;mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"&gt;
76 &lt;mime-type type="audio/x-rosegarden"&gt;
77 &lt;sub-class-of type="application/x-gzip"/&gt;
78 &lt;comment&gt;Rosegarden project file&lt;/comment&gt;
79 &lt;glob pattern="*.rg"/&gt;
80 &lt;/mime-type&gt;
81 &lt;/mime-info&gt;
82 </pre></blockquote></p>
83
84 <p>This states that audio/x-rosegarden is a kind of application/x-gzip
85 (it is a gzipped XML file). Note, it is much better to use an
86 official MIME type registered with IANA than it is to make up ones own
87 unofficial ones like the x-rosegarden type used by rosegarden.</p>
88
89 <p>The desktop file of the rosegarden program failed to list
90 audio/x-rosegarden in its list of supported MIME types, causing the
91 file browsers to have no idea what to do with *.rg files:</p>
92
93 <p><blockquote><pre>
94 % grep Mime /usr/share/applications/rosegarden.desktop
95 MimeType=audio/x-rosegarden-composition;audio/x-rosegarden-device;audio/x-rosegarden-project;audio/x-rosegarden-template;audio/midi;
96 X-KDE-NativeMimeType=audio/x-rosegarden-composition
97 %
98 </pre></blockquote></p>
99
100 <p>The fix was to add "audio/x-rosegarden;" at the end of the
101 MimeType= line.</p>
102
103 <p>If you run into a file which fail to open the correct program when
104 selected from the file browser, please check out the output from
105 <tt>file --mime-type</tt> for the file, ensure the file ending and
106 MIME type is registered somewhere under /usr/share/mime/ and check
107 that some desktop file under /usr/share/applications/ is claiming
108 support for this MIME type. If not, please report a bug to have it
109 fixed. :)</p>