<div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">Wow! First of all, I would like to say thank you for so much attention to my small contribution!</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">


Really I didn&#39;t expect that, thanks! I&#39;m glad that my work to someone in good stead.</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><br></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">


<span style="font-family:arial">&gt; Sorry for not replying to your earlier private email about this.</span><br style="font-family:arial"><div><span style="font-family:arial">It&#39;s ok :)</span></div></div><div><br></div>


&gt; I have one major issue with the implementation you&#39;re suggesting though.<br>&gt; Unlike the mimetype stuff which is based on a mmap&#39;ed cached (mime.cache), it<br>&gt; seems to parse all the .desktop files in-process. This means, if you start 10<br>


&gt; apps and they all need at some point to use xdg_mime_*_apps_lookup, they will<br>&gt; each suffer the runtime penalty (slowness and memory usage) of parsing all the<br><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">


&gt; .desktop files on the system.</div><div><div><font face="&#39;trebuchet ms&#39;, sans-serif">You are absolutely right! I&#39;m thinking about some mechanism to cache all that staff</font></div><div><font face="&#39;trebuchet ms&#39;, sans-serif">like other parts of xdgmime does. But specification does not describe where </font><font face="&#39;trebuchet ms&#39;, sans-serif">it could</font></div>
<div><font face="&#39;trebuchet ms&#39;, sans-serif">be </font><font face="&#39;trebuchet ms&#39;, sans-serif">stored, so </font><span style="font-family:&#39;trebuchet ms&#39;,sans-serif">I decided to not to do it right now. But, maybe this is the time :)</span></div>
<div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><br></div></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">

&gt; <span style="font-family:arial">So for application .desktop files, we could have another helper binary, say</span><br style="font-family:arial">&gt; <span style="font-family:arial">update-app-database (part of shared-mime-info maybe, so that we don&#39;t need to</span><br style="font-family:arial">


&gt; <span style="font-family:arial">depend on xdgmime, which we don&#39;t use in KDE and I think gnome might not</span><br style="font-family:arial">&gt; <span style="font-family:arial">either, or in a new module), which updates a new cache, say</span><br style="font-family:arial">


&gt; <span style="font-family:arial">&quot;application.cache&quot; in a given directory. RPMs and other packages would run</span><br style="font-family:arial">&gt; <span style="font-family:arial">that script when installing .desktop files, and then xdgmime could just mmap</span><br style="font-family:arial">


&gt; <span style="font-family:arial">that and look things up directly, without the need to parse any .desktop files</span><br style="font-family:arial">&gt; <span style="font-family:arial">during the application runtime. Now if you implemented that, it would</span><br style="font-family:arial">


&gt; <span style="font-family:arial">definitely be the best Christmas ever, in my eyes :-)</span></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">I think this is a great idea! I will begin the implementation of mmap&#39;ed cache</div>


<div style="font-family:&#39;trebuchet ms&#39;,sans-serif">on the weekend.</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><br></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">&gt; <span style>So overall, I&#39;m not sure what this would be fixing, apart from the</span><br style>
&gt; <span style>lack of an icon spec implementation at that level of the stack. There&#39;s</span><br style>&gt; <span style>already one in KDE, one in Qt, and surely a few in the gnome/glib/gtk world,</span><br style>&gt; <span style>but I suppose none of this fits your bill otherwise you wouldn&#39;t have written</span><br style>
&gt; <span style>it :-)</span><br style></div><div><div><font color="#222222" face="arial, sans-serif">This implementations do not suits me because, well they are in a huge libraries :)</font></div><div><font color="#222222" face="arial, sans-serif"><div>
I&#39;m adherent of small modules each of which is implementing strictly defined task</div><div>with strictly defined interface.</div></font></div></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif"><br>
</span></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><span style>&gt; I agree the contents of the theme file itself is probably not as urgent to</span><br style><span style>&gt; </span><span style>cache.</span><br style>
</div><div><span style>I agree with you, but maybe the thing is that I&#39;m an </span><font color="#222222" face="arial, sans-serif">perfectionist :) and I think</font></div><div><font color="#222222" face="arial, sans-serif">if I can make an improvement I should do it.</font></div>
<div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><span style><br></span></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><span style><br></span></div><div><div><span style="font-family:&#39;trebuchet ms&#39;,sans-serif">Let me briefly explain how current implementation works, I hope it will clarify</span></div>
<div><font face="&#39;trebuchet ms&#39;, sans-serif">some things and help to understand what to do next.</font></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><br></div></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">
There are two entry points, first one in</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">&quot;xdgmime.c:143: xdg_mime_init_from_directory(...)&quot;. There is a call to private</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">
method &quot;_xdg_mime_applications_read_from_directory(...)&quot;. This entry point is</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">for &quot;Desktop Entry Specification&quot; (xdgmimeapp{.h, .c, _p.h}).</div>


<div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><br></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">&quot;_xdg_mime_applications_read_from_directory(...)&quot; does parsing of all &quot;*.desktop&quot;</div>
<div style="font-family:&#39;trebuchet ms&#39;,sans-serif">and &quot;*.list&quot; files found according to &quot;The Desktop Base Directory Specification&quot;</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">
then stores all &quot;*.desktop&quot; files into AVL tree using the file name as key (I&#39;ve taken</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">into consideration that there could be subdirs which means prefix for the file name</div>
<div style="font-family:&#39;trebuchet ms&#39;,sans-serif">in global scope, like &quot;kde4-&quot;). As a value of key-value pair for AVL tree another</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">AVL tree is used with contents of &quot;*.desktop&quot; file. This makes access to any field</div>
<div style="font-family:&#39;trebuchet ms&#39;,sans-serif">of any &quot;*.desktop&quot; file in the system very fast, I would say as fast as possible (this</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">was the major task for me). Contents of all &quot;*.list&quot; files is stored in one AVL tree.</div>
<div style="font-family:&#39;trebuchet ms&#39;,sans-serif">Also, all associations of mime type with &quot;*.desktop&quot; files (from &quot;*.desktop&quot; files)</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">
are stored in another AVL tree.</div>

<div style="font-family:&#39;trebuchet ms&#39;,sans-serif"><br></div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">So, it was about internals. Let me describe public interface of the</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">
&quot;Desktop Entry Specification&quot; (file: &quot;xdgmimeapp.h&quot;). As already mentioned</div><div style="font-family:&#39;trebuchet ms&#39;,sans-serif">by David, the are three interesting methods:</div></div><font color="#000000"><font><font face="trebuchet ms,sans-serif"><div>
<div><br></div><div> - &quot;xdg_mime_default_apps_lookup(...)&quot; - this method searches for all applications</div><div>associated with the given mime type in section &quot;Default Applications&quot; of all found</div>
<div>&quot;*.list&quot; files (do you remember, contents of all &quot;*.list&quot; files is stored in one</div><div>AVL tree - it&#39;s like we merged all &quot;*.list&quot; files into one);</div>

</div><div><br></div><div><div><div> - &quot;xdg_mime_user_apps_lookup(...)&quot; - this method searches for all applications</div><div>associated with the given mime type in section &quot;Added Associations&quot; of all found</div>
<div>&quot;*.list&quot; files. As mentioned by David, it is not quite correct because there is</div><div>&quot;Removed Associations&quot; section about which I didn&#39;t know (or missed it);</div></div></div><div><br></div>
<div><div><div><div> - &quot;xdg_mime_known_apps_lookup(...)&quot; - this method searches for all applications</div><div>associated with the given mime type using third AVL tree I have described at</div><div>very beggining (where all associations of mime type with &quot;*.desktop&quot; files);</div>
</div></div></div><div><br></div><div> - &quot;xdg_mime_app_icon_lookup(..)&quot; - well, it depends on &quot;Icon theme specification&quot;</div><div>and will be described later;</div>

<div><br></div><div> - &quot;xdg_mime_app_group_lookup(...)&quot; - this method can return a group</div><div>from &quot;*.desktop&quot; file (like &quot;Desktop Entry&quot;);</div><div><br></div><div> - &quot;xdg_mime_app_entry_lookup(...)&quot; - this method can return array of entry values</div>
<div>from group of &quot;*.desktop&quot; file (like &quot;Name&quot;);</div>

<div><br></div><div> - &quot;xdg_mime_array_app_item_at(...)&quot; - this method is needed for traversing through</div><div>array of XdgApp (&quot;*.desktop&quot; files).</div><div><br></div><div><div>Note: I&#39;m thinking about localized fields... I think it should be merged with parent field</div>
<div>(for example Name[de] with Name). Provide convinient interface for reading of</div><div>localized values of the same field.</div></div><div><br></div><div>We got to the second entry point which is in &quot;xdgmime.c:449: xdg_mime_init(...)&quot;.</div>
<div>There is a call to private method &quot;_xdg_mime_themes_read_from_directory(...)&quot;.</div><div>This entry point is for &quot;Icon Theme Specification&quot; (xdgmimetheme{.h, .c, _p.h}).</div><div>This implementation has a &quot;special&quot; entry point (not in &quot;convinient&quot; place) because it</div>
<div>relies on diffrent layout of directories than &quot;The Desktop Base Directory Specification&quot;</div><div>describes (includes &quot;~/.icons/&quot; and &quot;/usr/share/pixmaps/&quot;).</div><div><br></div><div><div>
Initialization of this mechanism works similar to previous one with one difference - it</div><div>reads &quot;index.theme&quot; files. &quot;_xdg_mime_themes_read_from_directory(...)&quot; does parsing of</div><div>all &quot;index.theme&quot; files found according to directory layout from &quot;Icon Theme Specification&quot;</div>
<div>then stores all &quot;index.theme&quot; files into AVL tree using theme directory name as key.</div><div>As a value of key-value pair for AVL tree another AVL tree is used with contents of</div><div>&quot;index.theme&quot; file. This approach eliminates need of scanning whole theme directory and</div>
<div>directory of parent theme (and parent of parent, etc) to find icon.</div></div>

<div><div><br></div><div><div>In general, for algorithm of filesystem scanning we have absolute path to directories</div><div>where icon could be. The only thing we have to do is to check existence of the icon file</div>
<div>in this directories. If its not there take the parent theme and so on.</div></div></div><div><br></div><div>Here is the public interface of the &quot;Icon Theme Specification&quot; (file: &quot;xdgmimetheme.h&quot;):</div>
<div><br></div><div> - &quot;xdg_mime_type_icon_lookup(...)&quot; - this method can return absolute path to icon file</div><div>for given mime type, icon size and theme name. It converts mime type to icon name</div><div>by replacing &quot;/&quot; to &quot;-&quot; then searches for theme by given theme name (for example &quot;hicolor&quot;)</div>
<div>and looks for icon in directories listed in the theme file (&quot;index.theme&quot;);</div>

<div><br></div><div> - &quot;xdg_mime_icon_lookup(...)&quot; - this method can return absolute path to icon file for</div><div>given icon name, icon size, context and theme name. It searches for theme by given</div><div>
theme name (for example &quot;oxygen&quot;) and then looks for icon in directories listed in</div><div>the theme file (&quot;index.theme&quot;);</div><div><br></div><div><div> - &quot;xdg_mime_app_icon_lookup(..)&quot; - It was mentioned in &quot;Desktop Entry Specification&quot;</div>
<div>interface. This method takes icon name from &quot;*.desktop&quot; file and searches for it in a given</div><div>theme.</div><div><div><br></div><div>Note: I think this implementation could be improved by adding an AVL tree for indexing</div>
<div>(by size and/or context) directories inside of theme file. But I&#39;m not assured would it</div><div>be really improvement or not.</div></div></div><div><br></div><div>P.S.: sorry for by bad english.</div></font></font></font><div style="line-height:12px;font-family:Arial,Helvetica,&#39;Nimbus Sans L&#39;,sans-serif">
<h3 style="font-family:inherit;font-style:inherit;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;border-left-width:0px;border-style:initial;border-color:initial;outline-width:0px;outline-style:initial;outline-color:initial;font-weight:inherit;vertical-align:baseline;color:rgb(51,51,51)">


<font>--------------------------------</font></h3></div><div style="line-height:12px;font-family:Arial,Helvetica,&#39;Nimbus Sans L&#39;,sans-serif"><h3 style="font-family:inherit;font-style:inherit;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;border-left-width:0px;border-style:initial;border-color:initial;outline-width:0px;outline-style:initial;outline-color:initial;font-weight:inherit;vertical-align:baseline;color:rgb(51,51,51)">


<font>Best regards, Dmitriy.</font></h3></div><br>
<br><br><div class="gmail_quote">24 января 2012 г. 2:20 пользователь David Faure <span dir="ltr">&lt;<a href="mailto:faure@kde.org" target="_blank">faure@kde.org</a>&gt;</span> написал:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div>On Sunday 15 January 2012 17:40:27 DAV wrote:<br>
&gt; I added missing features:<br>
&gt;  - C-implementation of AVL trees;<br>
&gt;  - indexed (by using of AVL trees) access to all &quot;.desktop&quot; files and its<br>
&gt; contents (implementation of &quot;Desktop Entry Specification&quot;);<br>
<br>
</div>Hello Dmitriy,<br>
<br>
Sorry for not replying to your earlier private email about this. But let&#39;s<br>
discuss this here, it&#39;s a better idea indeed.<br>
<br>
I&#39;m very excited by the idea of having a cross-desktop solution to the very<br>
common issue of getting the list of apps associated with a given mimetype,<br>
I&#39;ve been thinking that we need that, for quite some time (when I saw your<br>
mail, I thought &quot;wow, it&#39;s Christmas!&quot;).<br>
<br>
(We use ksycoca in kde4 for this purpose, but I&#39;d like to get rid of it for<br>
kde5, so the timing is perfect.)<br>
<br>
I have one major issue with the implementation you&#39;re suggesting though.<br>
Unlike the mimetype stuff which is based on a mmap&#39;ed cached (mime.cache), it<br>
seems to parse all the .desktop files in-process. This means, if you start 10<br>
apps and they all need at some point to use xdg_mime_*_apps_lookup, they will<br>
each suffer the runtime penalty (slowness and memory usage) of parsing all the<br>
.desktop files on the system.<br>
<br>
We don&#39;t do that with mimetypes: shared-mime-info has a binary called &quot;update-<br>
mime-database&quot; which does the collecting and parsing of the (mime) files, and<br>
generates a binary file called mime.cache, whose on-disk layout is such that it<br>
can be used via mmap. This way, the applications are fast.<br>
<br>
So for application .desktop files, we could have another helper binary, say<br>
update-app-database (part of shared-mime-info maybe, so that we don&#39;t need to<br>
depend on xdgmime, which we don&#39;t use in KDE and I think gnome might not<br>
either, or in a new module), which updates a new cache, say<br>
&quot;application.cache&quot; in a given directory. RPMs and other packages would run<br>
that script when installing .desktop files, and then xdgmime could just mmap<br>
that and look things up directly, without the need to parse any .desktop files<br>
during the application runtime. Now if you implemented that, it would<br>
definitely be the best Christmas ever, in my eyes :-)<br>
<br>
Alex, Bastien: do you agree about the approach? Would gnome/gtk/glib use it,<br>
if it was done that way? (Otherwise half the RPMs/DEBs in the world will<br>
forget to run the update-app-database... so to me this solution will only work<br>
out in practice if it&#39;s used by everyone.)<br>
<br>
&gt; const XdgArray *xdg_mime_default_apps_lookup(const char *mimeType);<br>
&gt; const XdgArray *xdg_mime_user_apps_lookup(const char *mimeType);<br>
&gt; const XdgArray *xdg_mime_known_apps_lookup(const char *mimeType);<br>
<br>
A bit of documentation wouldn&#39;t hurt ;-) What&#39;s each of those doing exactly?<br>
It seems user_apps looks at the contents of mimeapps.list (but allows any<br>
*.list file? Is that in the spec?), but it only looks at [Added Associations],<br>
so this is missing support for [Removed Associations]. I think &quot;user apps&quot;<br>
should return the final set: default apps plus those added by the user, minus<br>
those removed by user. That&#39;s what client code cares mostly about.<br>
<br>
There&#39;s also the issue that the defaults should be desktop-dependent, but<br>
that&#39;s an entire new topic. The current situation is that KDE uses<br>
InitialPreference in the desktop files while Gnome uses a defaults.list file<br>
(iirc). One could say it sucks that this is non-standard, but on the other<br>
hand it gives &quot;defaults are desktop-dependent&quot; de facto.<br>
If we were to use a common way (which would definitely please distros and<br>
ISVs), then we would still need a way to make the defaults desktop-dependent,<br>
I would think, somehow (maybe a *.list file per desktop). (Although I definitely<br>
prefer the more modular KDE solution where an app can be installed later on<br>
and not have to hack into a global file to take precedence).<br>
I&#39;m sure we&#39;ve had this discussion already on this list, but I forgot the<br>
outcome of it :-}<br>
<div><br>
&gt;   - indexed (by using of AVL trees) access to icon themes and its contents<br>
&gt; (implemetation of &quot;<br>
</div>&gt; <a href="http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html" target="_blank">http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html</a><br>
&gt; &quot; and<br>
&gt; &quot;<br>
&gt; <a href="http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.ht" target="_blank">http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.ht</a><br>
&gt; ml &quot;).<br>
<br>
My first reaction was: this, too, only seems interesting to me if it&#39;s based on<br>
a mmap&#39;ed binary cache. Otherwise apps can just look things up directly on<br>
disk, as they already do currently. But either it only caches the contents of<br>
the theme files, and then it seems not so useful (there are only very few of<br>
them, typically, right?), or it also caches the names of all available icons,<br>
but that might not be a big saving compared to looking up in the file system<br>
directly. So overall, I&#39;m not sure what this would be fixing, apart from the<br>
lack of an icon spec implementation at that level of the stack. There&#39;s<br>
already one in KDE, one in Qt, and surely a few in the gnome/glib/gtk world,<br>
but I suppose none of this fits your bill otherwise you wouldn&#39;t have written<br>
it :-)<br>
Anyhow, no real objection from me, but the target audience probably needs to<br>
be defined, and like xdgmime itself (AFAIK), I think it wouldn&#39;t be much used.<br>
<span><font color="#888888"><br>
--<br>
David Faure, <a href="mailto:faure@kde.org" target="_blank">faure@kde.org</a>, <a href="http://www.davidfaure.fr" target="_blank">http://www.davidfaure.fr</a><br>
Sponsored by Nokia to work on KDE, incl. KDE Frameworks 5<br>
<br>
</font></span></blockquote></div><br>