开发者

How to register a "Linux" file association with autotools

开发者 https://www.devze.com 2023-03-13 08:52 出处:网络
I\'m w开发者_StackOverflow中文版riting an application that uses its own file type. I\'d like to integrate the file association with the desktop environment. I know that this can be done with a command

I'm w开发者_StackOverflow中文版riting an application that uses its own file type. I'd like to integrate the file association with the desktop environment. I know that this can be done with a command, but how should it be integrated with autotools?

Currently, my app can be installed without root to ~/.local for example. It would be nice to keep this feature.


Add a myapp.xml to your project that contains the desired MIME data. It'll look something like:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="image/png">
     <comment xml:lang="en">PNG image</comment>
     <comment xml:lang="af">png beeld</comment>
     ...
     <magic priority="50">
            <match type="string" value="\x89PNG" offset="0"/>
     </magic>
     <glob pattern="*.png"/>
  </mime-type>
</mime-info>

See the tutorial for more details on the format of the XML files.

Now you need to figure out where to install your XML file to. In my projects, I provide a --with-xdgdatadir option to configure, which is left as an exercise to the reader. By default, XDGDATADIR should be ${prefix}/share (i.e. ${datarootdir}). Add the following to your Makefile.am:

xdgdatadir=@XDGDATADIR@
mimedir=$(xdgdatadir)/mime
xmldir=$(mimedir)/packages
xml_DATA = myapp.xml

This will ensure that the MIME data is installed correctly.

Finally, it's necessary to ensure that the MIME database is updated on make install and make uninstall. Add a check for the update-mime-database tool to your configure.ac. Then add the following to your Makefile.am:

install-data-hook:
    $(UPDATE_MIME_DATABASE) "$(DESTDIR)$(mimedir)"

uninstall-hook:
    $(UPDATE_MIME_DATABASE) "$(DESTDIR)$(mimedir)"

I hope that answers your question.

0

精彩评论

暂无评论...
验证码 换一张
取 消