1

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.

molok
  • 1,491
  • 1
  • 14
  • 19

2 Answers2

1

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);
molok
  • 1,491
  • 1
  • 14
  • 19
0

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.

detly
  • 29,332
  • 18
  • 93
  • 152
  • I want Nautilus to show the "favorite" emblem, which is a stock one, I don't want to *create* a new emblem. I found out that the value of "metadata::emblems" MUST be an array. – molok Mar 19 '11 at 14:16
  • This won't create a new emblem, it will display an existing named emblem. – detly Mar 19 '11 at 15:18