summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-desktop-directory-file.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2009-06-29 14:38:40 +0200
committerAlexander Larsson <alexl@redhat.com>2009-06-29 14:38:40 +0200
commitb8995fce159472dac07666dfb4d7e3ff1412403a (patch)
tree595e80233581336a647bc351840c65e231f7dfdf /libnautilus-private/nautilus-desktop-directory-file.c
parent02f908f3d864f1f3bf0729158907f312e0306c05 (diff)
downloadnautilus-b8995fce159472dac07666dfb4d7e3ff1412403a.tar.gz
Support metadata for the virtual desktop icons
Diffstat (limited to 'libnautilus-private/nautilus-desktop-directory-file.c')
-rw-r--r--libnautilus-private/nautilus-desktop-directory-file.c154
1 files changed, 153 insertions, 1 deletions
diff --git a/libnautilus-private/nautilus-desktop-directory-file.c b/libnautilus-private/nautilus-desktop-directory-file.c
index a0cce281e..ac541f822 100644
--- a/libnautilus-private/nautilus-desktop-directory-file.c
+++ b/libnautilus-private/nautilus-desktop-directory-file.c
@@ -33,11 +33,15 @@
#include "nautilus-file-utilities.h"
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-macros.h>
+#include <gconf/gconf-client.h>
+#include <gconf/gconf-value.h>
#include "nautilus-desktop-directory.h"
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <string.h>
+#define NAUTILUS_DESKTOP_METADATA_GCONF_PATH "/apps/nautilus/desktop-metadata"
+
struct NautilusDesktopDirectoryFileDetails {
NautilusDesktopDirectory *desktop_directory;
@@ -448,6 +452,150 @@ monitor_destroy (gpointer data)
g_free (monitor);
}
+static char *
+get_metadata_gconf_path (const char *name,
+ const char *key)
+{
+ return g_build_filename (NAUTILUS_DESKTOP_METADATA_GCONF_PATH, name, key, NULL);
+}
+
+void
+nautilus_desktop_set_metadata_string (NautilusFile *file,
+ const char *name,
+ const char *key,
+ const char *string)
+{
+ GConfClient *client;
+ char *gconf_key;
+
+ client = gconf_client_get_default ();
+ gconf_key = get_metadata_gconf_path (name, key);
+
+ if (string) {
+ gconf_client_set_string (client, gconf_key, string, NULL);
+ } else {
+ gconf_client_unset (client, gconf_key, NULL);
+ }
+
+ g_free (gconf_key);
+ g_object_unref (client);
+
+ if (nautilus_desktop_update_metadata_from_gconf (file, name)) {
+ nautilus_file_changed (file);
+ }
+}
+
+void
+nautilus_desktop_set_metadata_stringv (NautilusFile *file,
+ const char *name,
+ const char *key,
+ char **stringv)
+{
+ GConfClient *client;
+ char *gconf_key;
+ GSList *list;
+ int i;
+
+ client = gconf_client_get_default ();
+ gconf_key = get_metadata_gconf_path (name, key);
+
+ list = NULL;
+ for (i = 0; stringv[i] != NULL; i++) {
+ list = g_slist_prepend (list, stringv[i]);
+ }
+ list = g_slist_reverse (list);
+
+ gconf_client_set_list (client, gconf_key,
+ GCONF_VALUE_STRING,
+ list, NULL);
+
+ g_slist_free (list);
+ g_free (gconf_key);
+ g_object_unref (client);
+
+ if (nautilus_desktop_update_metadata_from_gconf (file, name)) {
+ nautilus_file_changed (file);
+ }
+}
+
+gboolean
+nautilus_desktop_update_metadata_from_gconf (NautilusFile *file,
+ const char *name)
+{
+ GConfClient *client;
+ GSList *entries, *l;
+ char *dir;
+ const char *key;
+ GConfEntry *entry;
+ GConfValue *value;
+ GFileInfo *info;
+ gboolean changed;
+ char *gio_key;
+ GSList *value_list;
+ char **strv;
+ int i;
+
+ client = gconf_client_get_default ();
+
+ dir = get_metadata_gconf_path (name, NULL);
+ entries = gconf_client_all_entries (client, dir, NULL);
+ g_free (dir);
+
+ info = g_file_info_new ();
+
+ for (l = entries; l != NULL; l = l->next) {
+ entry = l->data;
+
+ key = gconf_entry_get_key (entry);
+ value = gconf_entry_get_value (entry);
+
+ key = strrchr (key, '/') + 1;
+
+ gio_key = g_strconcat ("metadata::", key, NULL);
+ if (value->type == GCONF_VALUE_STRING) {
+ g_file_info_set_attribute_string (info, gio_key,
+ gconf_value_get_string (value));
+ } else if (value->type == GCONF_VALUE_LIST &&
+ gconf_value_get_list_type (value) == GCONF_VALUE_STRING) {
+ value_list = gconf_value_get_list (value);
+ strv = g_new (char *, g_slist_length (value_list) + 1);
+ for (i = 0; value_list != NULL; i++, value_list = value_list->next) {
+ strv[i] = l->data;
+ }
+ strv[i] = NULL;
+ g_file_info_set_attribute_stringv (info, gio_key, strv);
+ g_free (strv);
+ }
+
+ g_free (gio_key);
+
+ gconf_entry_unref (entry);
+ }
+
+ changed = nautilus_file_update_metadata_from_info (file, info);
+
+ g_object_unref (info);
+ g_object_unref (client);
+
+ return changed;
+}
+
+static void
+nautilus_desktop_directory_file_set_metadata (NautilusFile *file,
+ const char *key,
+ const char *value)
+{
+ nautilus_desktop_set_metadata_string (file, "directory", key, value);
+}
+
+static void
+nautilus_desktop_directory_file_set_metadata_as_list (NautilusFile *file,
+ const char *key,
+ char **value)
+{
+ nautilus_desktop_set_metadata_stringv (file, "directory", key, value);
+}
+
static void
nautilus_desktop_directory_file_init (gpointer object, gpointer klass)
{
@@ -473,7 +621,9 @@ nautilus_desktop_directory_file_init (gpointer object, gpointer klass)
nautilus_directory_unref (real_dir);
desktop_file->details->real_dir_file = real_dir_file;
-
+
+ nautilus_desktop_update_metadata_from_gconf (NAUTILUS_FILE (desktop_file), "directory");
+
g_signal_connect_object (real_dir_file, "changed",
G_CALLBACK (real_file_changed_callback), desktop_file, 0);
}
@@ -542,4 +692,6 @@ nautilus_desktop_directory_file_class_init (gpointer klass)
file_class->get_deep_counts = desktop_directory_file_get_deep_counts;
file_class->get_date = desktop_directory_file_get_date;
file_class->get_where_string = desktop_directory_file_get_where_string;
+ file_class->set_metadata = nautilus_desktop_directory_file_set_metadata;
+ file_class->set_metadata_as_list = nautilus_desktop_directory_file_set_metadata_as_list;
}