gtk - 如何从文件扩展名中获取 GTK mime-type/content-type 信息

标签 gtk gnome

我不允许访问文件内容(出于性能原因),因此无法使用 GFile。

最佳答案

你需要 g_content_type_guess。

在 Python (GTK2) 中:

import gio
gio.content_type_guess('foo.pdf')

这将返回 application/pdf

在 Python (GTK3) 中:

from gi.repository import Gio
content_type, val = Gio.content_type_guess('filename=foo.pdf', data=None)

content_type 将包含 application/pdf

文档中有更多详细信息:http://developer.gnome.org/gio/stable/gio-GContentType.html#g-content-type-guess

关于gtk - 如何从文件扩展名中获取 GTK mime-type/content-type 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5724080/

相关文章:

c - GTK C - 获取指向 gint64 的指针的值以提供给 gtk_list_store_set

Linux,更改文本字段行为

linux - Qt 应用程序需要 KDE 吗?

installation - OCaml 中的 GUI 交叉开发,具有自然的外观和感觉

python - Linux 上使用 pygtk (gtk.gdk) 的桌面/根窗口上的键盘/鼠标事件

c - ld 提示 : in function "_start", undefined reference to "__libc_csu_fini"& "__libc_csu_init"

c - 自动错误报告工具 (ABRT) 如何工作以便在运行时捕获核心?

aptana - aptana3 上的 pydev 无法导入 gi.repository

bash - 如何在bash中本地更改主机名

linux - 在Linux中的GTK应用程序中处理音量键