linux环境中获取文件图标,c++ 如何在Linux桌面中获取与文件相关联的图标,MIME类型和应用程序?...

以下是使用GLib / GIO获取所需信息的示例。

#include

#include

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值