LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-22-2024, 01:14 PM   #1
Java programmer
LQ Newbie
 
Registered: Jan 2024
Posts: 3

Rep: Reputation: 0
Obtaining list of mimetypes and the file names of their icons


When I am looking at files in Linux's file explorer, each file has an icon on the left and a name on the right.
The icons represent the mimetype of the file , for example .so. .sh or .properties.


I want to present something like Linux's file explorer to my users. In connection with this, I want to show them the appropriate icon they expect to see next to each file, according to its mime type, like Linux does.

I would like to pre-assemble each of these icons and associate (map) them to their mimetypes exactly once when the program starts, rather query Linux for the icon for each and every file as I discover those files when my program starts up.

I do not know how to assemble this infornation for myself even through I can see Linux obviously knows how to do it.

I am wondering how I would go about doing this on an arbitrary but modern Linux.
 
Old 01-22-2024, 02:15 PM   #2
Java programmer
LQ Newbie
 
Registered: Jan 2024
Posts: 3

Original Poster
Rep: Reputation: 0
Doing this appears to be a pipe dream...

Apparently, I'm dreaming a dream one should never dream:

https://stackoverflow.com/questions/...tion-in-ubuntu


Quote:
Originally Posted by Java programmer View Post
When I am looking at files in Linux's file explorer, each file has an icon on the left and a name on the right.
The icons represent the mimetype of the file , for example .so. .sh or .properties.


I want to present something like Linux's file explorer to my users. In connection with this, I want to show them the appropriate icon they expect to see next to each file, according to its mime type, like Linux does.

I would like to pre-assemble each of these icons and associate (map) them to their mimetypes exactly once when the program starts, rather query Linux for the icon for each and every file as I discover those files when my program starts up.

I do not know how to assemble this infornation for myself even through I can see Linux obviously knows how to do it.

I am wondering how I would go about doing this on an arbitrary but modern Linux.
 
Old 01-22-2024, 02:47 PM   #3
EdGr
Senior Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 1,000

Rep: Reputation: 472Reputation: 472Reputation: 472Reputation: 472Reputation: 472
Read the XDG Desktop Entry Specification. https://specifications.freedesktop.o...-spec-1.1.html

Two steps are required:

1) Determine the MIME type from a file's name or contents
2) Look up the desktop files installed by applications for matching MIME types

The first step is unreliable (see the "file" program's documentation). The second is expensive and may yield multiple matches. Every desktop environment has its own ways of doing this.
Ed
 
1 members found this post helpful.
Old 01-22-2024, 02:56 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,246

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
I found a slightly better link:

https://stackoverflow.com/questions/...h-a-file-in-th
 
1 members found this post helpful.
Old 01-30-2024, 11:34 AM   #5
Java programmer
LQ Newbie
 
Registered: Jan 2024
Posts: 3

Original Poster
Rep: Reputation: 0
Troublesome variants in Linux file structure- how to handle?

Thanks I did start off with that document. What I found was Linux Mint's /usr/share/icon sub directory structure corresponded only partially with the assumptions of the algorithms there. I wonder if I follow the algos and rewrite them to work on Mint if it will also work on KDE.

Basically that's what I am wondering.

Last edited by Java programmer; 01-30-2024 at 01:43 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] KDE's default mimetypes mapping Bad Blue Bull Linux - Software 1 12-11-2018 01:11 PM
[PCManFM] and .local/share/applications: associate all MimeTypes Michael Uplawski Linux - Software 3 11-15-2017 01:39 PM
[SOLVED] How to changing same file names by their directory names? bayaraa_u Linux - General 3 04-09-2010 08:26 AM
Gnome 2.8.3 mimetypes vanished shade13 Linux - Software 0 03-20-2005 02:55 PM
Apache mimetypes Mikessu Linux - Networking 1 12-31-2003 09:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration