Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 2763  / 1 Year ago, sun, december 4, 2022, 7:47:55

About the mimetype



I have created a mimetype and I want to add an icon for it. The mimetype is for To-do lists, it matches the TODO pattern and is of type text/todo.



I can confirm that upon creating a file named TODO, it shows to be of mimetype text/todo.



Attempts to add the icon




  1. So, I have linked a SVG file to ~/.local/share/icons/hicolor/48x48/mimetypes/text-todo.svg hoping that such file will be used as icon for my mimetype. However, it is not.


  2. I proceed to run sudo update-icon-caches ~/.local/share/icons/hicolor, which runs quietly, but changes nothing.


  3. I then run sudo gtk-update-icon-cache ~/.local/share/icons/hicolor, but I get the message:





gtk-update-icon-cache: No theme index file.




or




gtk-update-icon-cache: The generated cache was invalid.




upon running sudo gtk-update-icon-cache -tf ~/.local/share/icons/hicolor. This also, as you'd expect, changes nothing.



So, how do I add an icon for my mimetype in my home directory?


More From » icons

 Answers
0

I have spent some rather lengthy time in trying to get this right, and I finally have.



Creating the mimetype



First, you need to create a mimetype file and save it to your local ~/.local/share/mime/packages/ directory. The file can have a structure like this one:



<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="text/todo">
<comment>To-do list</comment>
<glob case-sensitive="true" pattern="TODO" />
<glob case-sensitive="true" pattern="TODO *"/>
</mime-type>
</mime-info>


Be sure that fields like type in the mime-type element tag match your desired mimetype, and the glob element tags contain a pattern attribute whose value matches the pattern of your disired mimetype. As you can see, your mimetype can cover multiple filename patterns through multiple glob elements.



In the case of my TODO mimetype, I needed the pattern to be case-sensitive, so I threw in a case-sensitive="true" attribute-value pair; if you don't need case-sensitiveness, this attribute-value pair is not necessary.



Once you have finished your mimetype file, save it with a convenient name, like todo.xml. (Note: the XML extension might be important.)



Now run the command update-mime-database ~/.local/share/mime/ and you should be done with it. This command will place your mimetype in the correct category directory under ~/.local/share/mime.



Testing



You can test if your mimetype was parsed correctly by reading the ~/.local/share/mime/glob files and by testing specific files with commands like




  • mimetype FILENAME

  • xdg-mime query filetype FILENAME



These will only work after you've updated the mime database.



Adding the icon



In many linux distributions, third-party/addon icons are filed under the "hicolor" icon-theme, which is a fallback icon theme which other icon themes rely upon.



Add your icon to the correct directory under ~/.local/share/icons/hicolor/ (according to the /usr/share/icons/hicolor/index.theme descriptor file that lists valid subdirectories), run update-icon-caches ~/.local/share/icons/hicolor and you should be all set!



Your desktop manager may require a restart to associate the new mimetypes with the new icons.



Troubleshooting



If your files don't get the mimetype/icon you set for them, be sure to check very well the patterns in the mimetype XML file. Sometimes testing an obvious pattern may help you verify this.


[#27898] Tuesday, December 6, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
igeonlothe

Total Points: 370
Total Questions: 121
Total Answers: 114

Location: United States Minor Outlying Island
Member since Fri, Feb 5, 2021
3 Years ago
igeonlothe questions
Wed, May 31, 23, 02:34, 1 Year ago
Sat, Mar 12, 22, 17:13, 2 Years ago
Tue, Aug 31, 21, 09:46, 3 Years ago
;