Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:06:03+00:00 2026-05-13T14:06:03+00:00

Using C++ on the Linux desktop, what is the best way to get the

  • 0

Using C++ on the Linux desktop, what is the best way to get the icon, the document description and the application “associated” with an arbitrary file/file path?

I’d like to use the most “canonical” way to find icons, mime-type/file type descriptions and associated applications on both KDE and gnome and I’d like to avoid any “shelling out” to the command line and “low-level” routines as well as avoiding re-inventing the wheel myself (no parsing the mime-types file and such).

Edits and Notes:

Hey, I originally asked this question about the QT file info object and the answer that “there is no clear answer” seems to be correct as far as it goes. BUT this is such a screwed-up situation that I am opening the question looking for more information.

I don’t care about QT in particular any more, I’m just looking for the most cannonical way to find the mime type via C++/c function calls on both KDE and gnome (especially Gnome, since that’s where things confuse me most). I want to be able show icons and descriptions matching Nautilus in Gnome and Konquerer/whatever on KDE as well as opening files appropriately, etc.

I suppose it’s OK that I get this separately for KDE and Gnome. The big question is what’s the most common/best/cannonical way to get all this information for the Linux desktop? Gnome documentation is especially opaque. gnome-vsf has mime routines but it’s deprecated and I can’t find a mime routine for GIO/GFS, gnome-vsf’s replacement. There’s a vague implication that one should use the open desktop applications but which one to use is obscure. And where does libmagic and xdg fit in?

Pointers to an essay summarizing the issues gladly accepted. Again, I know the three line answer is “no such animal” but I’m looking for the long answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:06:03+00:00Added an answer on May 13, 2026 at 2:06 pm

    Here is an example of using GLib/GIO to get the information you want.

    #include <gio/gio.h>
    #include <stdio.h>
    
    int
    main (int argc, char **argv)
    {
        g_thread_init (NULL);
        g_type_init ();
    
        if (argc < 2)
            return -1;
    
        GError *error;
        GFile *file = g_file_new_for_path (argv[1]);
        GFileInfo *file_info = g_file_query_info (file,
                                                  "standard::*",
                                                  0,
                                                  NULL,
                                                  &error);
    
        const char *content_type = g_file_info_get_content_type (file_info);
        char *desc = g_content_type_get_description (content_type);
        GAppInfo *app_info = g_app_info_get_default_for_type (
                                      content_type,
                                      FALSE);
    
        /* you'd have to use g_loadable_icon_load to get the actual icon */
        GIcon *icon = g_file_info_get_icon (file_info);
    
        printf ("File: %s\nDescription: %s\nDefault Application: %s\n",
                argv[1],
                desc,
                g_app_info_get_executable (app_info));
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 287k
  • Answers 287k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer That project folder contains the metadata for your project, so… May 13, 2026 at 5:09 pm
  • Editorial Team
    Editorial Team added an answer I think getting the value of a select element doesn't… May 13, 2026 at 5:09 pm
  • Editorial Team
    Editorial Team added an answer Sourceforge offers SVN as one of many features, and is… May 13, 2026 at 5:09 pm

Related Questions

This might be in vain, as I know writing an operating system is unbearably
I'm looking to add full text indexing to a Linux desktop application written in
How would I change the wallpaper on a Linux desktop (using GNOME) within a
I have a few years of experience in cross-platform desktop development (Windows and MacOSX,
I need to port a screen capture utility to Linux. I'm not familiar with

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.