Added cs to the list of languages
[midnight-commander.git] / gnome / gmetadata.c
blobbe6e73035064ea95f98c88a777cddeb3fe0e9db9
1 /* Convenience functions for metadata handling in the MIdnight Commander
3 * Copyright (C) 1998 The Free Software Foundation
5 * Author: Federico Mena <federico@nuclecu.unam.mx>
6 */
8 #include <config.h>
9 #include "global.h"
10 #include <libgnome/libgnome.h>
11 #include "gmetadata.h"
12 #include <sys/stat.h>
13 #include "../vfs/vfs.h"
16 #define ICON_POSITION "icon-position"
19 /**
20 * gmeta_get_icon_pos
21 * @filename: The file under ~/desktop for which to get the icon position
22 * @x: The x position will be stored here. Must be non-NULL.
23 * @y: The y position will be stored here. Must be non-NULL.
25 * Checks if the specified file has an icon position associated to it. If so, returns TRUE and
26 * fills in the x and y values. Otherwise it returns FALSE and x and y are not modified.
28 * Icon position information is expected to be saved using the gmeta_set_icon_pos() function.
30 int
31 gmeta_get_icon_pos (char *filename, int *x, int *y)
33 int size;
34 char *buf;
35 int tx, ty;
37 g_return_val_if_fail (filename != NULL, FALSE);
38 g_return_val_if_fail (x != NULL, FALSE);
39 g_return_val_if_fail (y != NULL, FALSE);
41 if (gnome_metadata_get (filename, ICON_POSITION, &size, &buf) != 0)
42 return FALSE;
44 if (!buf){
45 g_warning ("Invalid metadata for \"%s\"'s icon position, using auto-placement", filename);
46 return FALSE;
50 if ((sscanf (buf, "%d%d", &tx, &ty) != 2)) {
51 g_free (buf);
52 return FALSE;
54 g_free (buf);
55 *x = tx;
56 *y = ty;
57 return TRUE;
60 /**
61 * gmeta_set_icon_pos
62 * @filename: The file for which to save icon position information
63 * @x: X position of the icon
64 * @y: Y position of the icon
66 * Saves the icon position information for the specified file. This is expected to be read back
67 * using the gmeta_get_icon_pos() function.
69 void
70 gmeta_set_icon_pos (char *filename, int x, int y)
72 char buf[100];
74 g_return_if_fail (filename != NULL);
76 g_snprintf (buf, sizeof (buf), "%d %d", x, y);
78 if (gnome_metadata_set (filename, ICON_POSITION, strlen (buf) + 1, buf) != 0)
79 g_warning ("Error setting the icon position metadata for \"%s\"", filename);
82 /**
83 * gmeta_del_icon_pos:
84 * @filename: The filename for which to delete icon position information.
86 * Deletes the icon position information for the specified file.
87 **/
88 void
89 gmeta_del_icon_pos (char *filename)
91 g_return_if_fail (filename != NULL);
93 gnome_metadata_remove (filename, ICON_POSITION);