开发者

How do I set an emblem with GTK/GIO?

I'm trying to set an emblem using gio

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdio.h>

int main (int argc, char *argv[])
{
    GFile *gfile = NULL;
    g_type_init();
    gfile = g_file_new_for_path("./foo.txt");
    if (g_file_set_attribute_string(gfile, 
                                    "metadata::emblems", 
                                    "favorite", 
                                    G_FILE_QUERY_INFO_NONE, 
                                    NULL, NULL) == TRUE) {

        puts("Success");
    } else {
        puts("Fail");
    }

    return 0;
}

开发者_开发问答if the file exists, the function returns TRUE, which, according the docs means the metadata was set, but Nautilus (GNOME) doesn't display the favorite emblem. There are not many example on the net, so I'm kind of stuck.


It looks like metadata::emblems needs an array of strings even if you are only setting one value. This seems to work:

char *value[] = {"favorite", '\0'};
[...]
g_file_set_attribute(file, "metadata::emblems",
                     G_FILE_ATTRIBUTE_TYPE_STRINGV,
                     &value[0],
                     G_FILE_QUERY_INFO_NONE,
                     NULL, NULL);


If you want Nautilus to show an emblem, you need to actually provide an extension to Nautilus to do so. Your extension should use the nautilus-info-provider interface, and in the nautilus_info_provider_update_file_info() function you can call the nautilus_file_info_add_emblem() function to add an emblem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜