1998-10-30 03:47:54 +03:00
|
|
|
/* Convenience functions for metadata handling in the MIdnight Commander
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 The Free Software Foundation
|
|
|
|
*
|
|
|
|
* Author: Federico Mena <federico@nuclecu.unam.mx>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <libgnome/libgnome.h>
|
1999-01-27 04:14:57 +03:00
|
|
|
#include "global.h"
|
1998-10-30 03:47:54 +03:00
|
|
|
#include "gmetadata.h"
|
1998-10-30 20:51:28 +03:00
|
|
|
#include <sys/stat.h>
|
1998-10-30 20:08:03 +03:00
|
|
|
#include "../vfs/vfs.h"
|
1998-10-30 03:47:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define ICON_POSITION "icon-position"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
1998-11-24 01:09:58 +03:00
|
|
|
* gmeta_get_icon_pos
|
1998-10-30 03:47:54 +03:00
|
|
|
* @filename: The file under ~/desktop for which to get the icon position
|
|
|
|
* @x: The x position will be stored here. Must be non-NULL.
|
|
|
|
* @y: The y position will be stored here. Must be non-NULL.
|
|
|
|
*
|
1998-10-30 20:08:03 +03:00
|
|
|
* Checks if the specified file has an icon position associated to it. If so, returns TRUE and
|
|
|
|
* fills in the x and y values. Otherwise it returns FALSE and x and y are not modified.
|
|
|
|
*
|
1998-11-24 01:09:58 +03:00
|
|
|
* Icon position information is expected to be saved using the gmeta_set_icon_pos() function.
|
1998-10-30 03:47:54 +03:00
|
|
|
*/
|
|
|
|
int
|
1998-11-24 01:09:58 +03:00
|
|
|
gmeta_get_icon_pos (char *filename, int *x, int *y)
|
1998-10-30 03:47:54 +03:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
char *buf;
|
|
|
|
int tx, ty;
|
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (x != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (y != NULL, FALSE);
|
|
|
|
|
|
|
|
if (gnome_metadata_get (filename, ICON_POSITION, &size, &buf) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
1999-01-02 10:46:20 +03:00
|
|
|
if (!buf){
|
1998-10-30 03:47:54 +03:00
|
|
|
g_warning ("Invalid metadata for \"%s\"'s icon position, using auto-placement", filename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-01-02 10:46:20 +03:00
|
|
|
|
|
|
|
if ((sscanf (buf, "%d%d", &tx, &ty) != 2)) {
|
|
|
|
g_free (buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
g_free (buf);
|
1998-10-30 03:47:54 +03:00
|
|
|
*x = tx;
|
|
|
|
*y = ty;
|
|
|
|
return TRUE;
|
|
|
|
}
|
1998-10-30 20:08:03 +03:00
|
|
|
|
|
|
|
/**
|
1998-11-24 01:09:58 +03:00
|
|
|
* gmeta_set_icon_pos
|
1998-10-30 20:08:03 +03:00
|
|
|
* @filename: The file for which to save icon position information
|
|
|
|
* @x: X position of the icon
|
|
|
|
* @y: Y position of the icon
|
|
|
|
*
|
|
|
|
* Saves the icon position information for the specified file. This is expected to be read back
|
1998-11-24 01:09:58 +03:00
|
|
|
* using the gmeta_get_icon_pos() function.
|
1998-10-30 20:08:03 +03:00
|
|
|
*/
|
|
|
|
void
|
1998-11-24 01:09:58 +03:00
|
|
|
gmeta_set_icon_pos (char *filename, int x, int y)
|
1998-10-30 20:08:03 +03:00
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
|
|
|
|
g_return_if_fail (filename != NULL);
|
|
|
|
|
1999-01-27 04:14:57 +03:00
|
|
|
g_snprintf (buf, sizeof (buf), "%d %d", x, y);
|
1998-10-30 20:08:03 +03:00
|
|
|
|
|
|
|
if (gnome_metadata_set (filename, ICON_POSITION, strlen (buf) + 1, buf) != 0)
|
|
|
|
g_warning ("Error setting the icon position metadata for \"%s\"", filename);
|
|
|
|
}
|
1999-01-02 21:41:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gmeta_del_icon_pos:
|
|
|
|
* @filename: The filename for which to delete icon position information.
|
|
|
|
*
|
|
|
|
* Deletes the icon position information for the specified file.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gmeta_del_icon_pos (char *filename)
|
|
|
|
{
|
|
|
|
g_return_if_fail (filename != NULL);
|
|
|
|
|
|
|
|
gnome_metadata_remove (filename, ICON_POSITION);
|
|
|
|
}
|
|
|
|
|