47
38
retval = g_build_filename (xdg_dir, "desktop-metadata", NULL);
55
save_in_idle_cb (gpointer data)
57
GKeyFile *keyfile = data;
58
gchar *contents, *filename;
62
save_in_idle_source_id = 0;
64
contents = g_key_file_to_data (keyfile, &length, NULL);
65
filename = get_keyfile_path ();
67
if (contents != NULL) {
68
g_file_set_contents (filename,
75
g_warning ("Couldn't save the desktop metadata keyfile to disk: %s",
86
save_in_idle (GKeyFile *keyfile)
88
if (save_in_idle_source_id != 0) {
89
g_source_remove (save_in_idle_source_id);
92
save_in_idle_source_id = g_idle_add (save_in_idle_cb, keyfile);
96
load_metadata_keyfile (void)
102
retval = g_key_file_new ();
103
filename = get_keyfile_path ();
105
g_key_file_load_from_file (retval,
111
if (!g_error_matches (error,
113
G_FILE_ERROR_NOENT)) {
114
g_print ("Unable to open the desktop metadata keyfile: %s\n",
118
g_error_free (error);
129
static gboolean keyfile_loaded = FALSE;
130
static GKeyFile *keyfile = NULL;
132
if (!keyfile_loaded) {
133
keyfile = load_metadata_keyfile ();
134
keyfile_loaded = TRUE;
144
49
const gchar *string)
148
keyfile = get_keyfile ();
150
g_key_file_set_string (keyfile,
155
save_in_idle (keyfile);
157
if (nautilus_desktop_update_metadata_from_keyfile (file, name)) {
158
nautilus_file_changed (file);
51
gchar *keyfile_filename;
53
keyfile_filename = get_keyfile_path ();
55
nautilus_keyfile_metadata_set_string (file, keyfile_filename,
58
g_free (keyfile_filename);
162
#define STRV_TERMINATOR "@x-nautilus-desktop-metadata-term@"
165
62
nautilus_desktop_set_metadata_stringv (NautilusFile *file,
168
65
const char * const *stringv)
172
gchar **actual_stringv = NULL;
173
gboolean free_strv = FALSE;
175
keyfile = get_keyfile ();
177
/* if we would be setting a single-length strv, append a fake
178
* terminator to the array, to be able to differentiate it later from
179
* the single string case
181
length = g_strv_length ((gchar **) stringv);
184
actual_stringv = g_malloc0 (3 * sizeof (gchar *));
185
actual_stringv[0] = (gchar *) stringv[0];
186
actual_stringv[1] = STRV_TERMINATOR;
187
actual_stringv[2] = NULL;
192
actual_stringv = (gchar **) stringv;
195
g_key_file_set_string_list (keyfile,
198
(const gchar **) actual_stringv,
201
save_in_idle (keyfile);
203
if (nautilus_desktop_update_metadata_from_keyfile (file, name)) {
204
nautilus_file_changed (file);
208
g_free (actual_stringv);
67
gchar *keyfile_filename;
69
keyfile_filename = get_keyfile_path ();
71
nautilus_keyfile_metadata_set_stringv (file, keyfile_filename,
74
g_free (keyfile_filename);
213
78
nautilus_desktop_update_metadata_from_keyfile (NautilusFile *file,
214
79
const gchar *name)
216
gchar **keys, **values;
217
const gchar *actual_values[2];
218
const gchar *key, *value;
220
gsize length, values_length;
226
keyfile = get_keyfile ();
228
keys = g_key_file_get_keys (keyfile,
237
info = g_file_info_new ();
239
for (idx = 0; idx < length; idx++) {
241
values = g_key_file_get_string_list (keyfile,
247
gio_key = g_strconcat ("metadata::", key, NULL);
249
if (values_length < 1) {
251
} else if (values_length == 1) {
252
g_file_info_set_attribute_string (info,
255
} else if (values_length == 2) {
256
/* deal with the fact that single-length strv are stored
257
* with an additional terminator in the keyfile string, to differentiate
258
* them from the regular string case.
262
if (g_strcmp0 (value, STRV_TERMINATOR) == 0) {
263
/* if the 2nd value is the terminator, remove it */
264
actual_values[0] = values[0];
265
actual_values[1] = NULL;
267
g_file_info_set_attribute_stringv (info,
269
(gchar **) actual_values);
271
/* otherwise, set it as a regular strv */
272
g_file_info_set_attribute_stringv (info,
277
g_file_info_set_attribute_stringv (info,
286
res = nautilus_file_update_metadata_from_info (file, info);
289
g_object_unref (info);
81
gchar *keyfile_filename;
84
keyfile_filename = get_keyfile_path ();
86
result = nautilus_keyfile_metadata_update_from_keyfile (file,
90
g_free (keyfile_filename);