Commit 45a8d2c6 authored by Roman Joost's avatar Roman Joost
Browse files

Make use of the XMPModel widget interface.

The GtkEntry is re-factored to use the XMPModel based interface.
parent b124fe6d
......@@ -25,77 +25,37 @@
#include "xmp-schemas.h"
#include "xmp-model.h"
#include "gimpxmpmodelwidget.h"
#include "gimpxmpmodelentry.h"
enum
{
PROP_0,
PROP_SCHEMA_URI,
PROP_PROPERTY_NAME,
PROP_XMPMODEL
};
typedef struct
{
const gchar *schema_uri;
const gchar *property_name;
XMPModel *xmp_model;
} GimpXmpModelEntryPrivate;
static void gimp_xmp_model_entry_iface_init (GimpXmpModelWidgetInterface *iface);
static void gimp_xmp_model_entry_set_text (GimpXmpModelWidget *widget,
const gchar *tree_value);
static void gimp_xmp_model_entry_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_xmp_model_entry_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_entry_xmp_model_changed (XMPModel *xmp_model,
GtkTreeIter *iter,
gpointer *user_data);
static void gimp_xmp_model_entry_changed (GimpXmpModelEntry *entry);
static void gimp_xmp_model_entry_entry_changed (GimpXmpModelEntry *widget);
const gchar * find_schema_prefix (const gchar *schema_uri);
static void set_property_edit_icon (GimpXmpModelEntry *entry,
GtkTreeIter *iter);
G_DEFINE_TYPE_WITH_CODE (GimpXmpModelEntry, gimp_xmp_model_entry,
GTK_TYPE_ENTRY,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_XMP_MODEL_WIDGET,
gimp_xmp_model_entry_iface_init))
G_DEFINE_TYPE (GimpXmpModelEntry, gimp_xmp_model_entry, GTK_TYPE_ENTRY)
#define parent_class gimp_xmp_model_entry_parent_class
#define GIMP_XMP_MODEL_ENTRY_GET_PRIVATE(obj) \
((GimpXmpModelEntryPrivate *) GIMP_XMP_MODEL_ENTRY (obj)->priv)
static GObject *
gimp_xmp_model_entry_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *obj;
GimpXmpModelEntry *entry;
GimpXmpModelEntryPrivate *priv;
gchar *signal;
GObject *obj;
obj = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
entry = GIMP_XMP_MODEL_ENTRY (obj);
priv = GIMP_XMP_MODEL_ENTRY_GET_PRIVATE (entry);
signal = g_strdup_printf ("property-changed::%s:%s",
find_schema_prefix (priv->schema_uri),
priv->property_name);
g_signal_connect (priv->xmp_model, signal,
G_CALLBACK (gimp_entry_xmp_model_changed),
entry);
g_free (signal);
gimp_xmp_model_widget_constructor (obj);
return obj;
}
......@@ -106,179 +66,37 @@ gimp_xmp_model_entry_class_init (GimpXmpModelEntryClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructor = gimp_xmp_model_entry_constructor;
object_class->set_property = gimp_xmp_model_entry_set_property;
object_class->get_property = gimp_xmp_model_entry_get_property;
g_object_class_install_property (object_class, PROP_SCHEMA_URI,
g_param_spec_string ("schema-uri", NULL, NULL,
NULL,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_PROPERTY_NAME,
g_param_spec_string ("property-name", NULL, NULL,
NULL,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE));
object_class->set_property = gimp_xmp_model_widget_set_property;
object_class->get_property = gimp_xmp_model_widget_get_property;
g_object_class_install_property (object_class, PROP_XMPMODEL,
g_param_spec_object ("xmp-model", NULL, NULL,
GIMP_TYPE_XMP_MODEL,
G_PARAM_CONSTRUCT_ONLY |
GIMP_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (GimpXmpModelEntryPrivate));
gimp_xmp_model_widget_install_properties (object_class);
}
static void
gimp_xmp_model_entry_init (GimpXmpModelEntry *entry)
{
entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
GIMP_TYPE_XMP_MODEL_ENTRY,
GimpXmpModelEntryPrivate);
g_signal_connect (entry, "changed",
G_CALLBACK (gimp_xmp_model_entry_entry_changed),
G_CALLBACK (gimp_xmp_model_entry_changed),
NULL);
}
static void
gimp_xmp_model_entry_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpXmpModelEntryPrivate *priv = GIMP_XMP_MODEL_ENTRY_GET_PRIVATE (object);
switch (property_id)
{
case PROP_SCHEMA_URI:
priv->schema_uri = g_value_dup_string (value);
break;
case PROP_PROPERTY_NAME:
priv->property_name = g_value_dup_string (value);
break;
case PROP_XMPMODEL:
priv->xmp_model = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_xmp_model_entry_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
gimp_xmp_model_entry_iface_init (GimpXmpModelWidgetInterface *iface)
{
GimpXmpModelEntryPrivate *priv = GIMP_XMP_MODEL_ENTRY_GET_PRIVATE (object);
switch (property_id)
{
case PROP_SCHEMA_URI:
g_value_set_string (value, priv->schema_uri);
break;
case PROP_PROPERTY_NAME:
g_value_set_string (value, priv->property_name);
break;
case PROP_XMPMODEL:
g_value_set_object (value, priv->xmp_model);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
iface->widget_set_text = gimp_xmp_model_entry_set_text;
}
static void
gimp_entry_xmp_model_changed (XMPModel *xmp_model,
GtkTreeIter *iter,
gpointer *user_data)
gimp_xmp_model_entry_set_text (GimpXmpModelWidget *widget,
const gchar *tree_value)
{
GimpXmpModelEntry *entry = GIMP_XMP_MODEL_ENTRY (user_data);
GimpXmpModelEntryPrivate *priv = GIMP_XMP_MODEL_ENTRY_GET_PRIVATE (entry);
const gchar *tree_value;
const gchar *property_name;
GdkPixbuf *icon;
gtk_tree_model_get (GTK_TREE_MODEL (xmp_model), iter,
COL_XMP_NAME, &property_name,
COL_XMP_VALUE, &tree_value,
COL_XMP_EDIT_ICON, &icon,
-1);
if (! strcmp (priv->property_name, property_name))
gtk_entry_set_text (GTK_ENTRY (entry), tree_value);
if (icon == NULL)
set_property_edit_icon (entry, iter);
return;
gtk_entry_set_text (GTK_ENTRY (widget), tree_value);
}
static void
gimp_xmp_model_entry_entry_changed (GimpXmpModelEntry *entry)
gimp_xmp_model_entry_changed (GimpXmpModelEntry *entry)
{
GimpXmpModelEntryPrivate *priv = GIMP_XMP_MODEL_ENTRY_GET_PRIVATE (entry);
xmp_model_set_scalar_property (priv->xmp_model,
priv->schema_uri,
priv->property_name,
gtk_entry_get_text (GTK_ENTRY (entry)));
}
/* find the schema prefix for the given URI */
const gchar*
find_schema_prefix (const gchar *schema_uri)
{
int i;
for (i = 0; xmp_schemas[i].uri != NULL; ++i)
{
if (! strcmp (xmp_schemas[i].uri, schema_uri))
return xmp_schemas[i].prefix;
}
return NULL;
}
static void
set_property_edit_icon (GimpXmpModelEntry *entry,
GtkTreeIter *iter)
{
GimpXmpModelEntryPrivate *priv = GIMP_XMP_MODEL_ENTRY_GET_PRIVATE (entry);
GdkPixbuf *icon;
gboolean editable;
gtk_tree_model_get (GTK_TREE_MODEL (priv->xmp_model), iter,
COL_XMP_EDITABLE, &editable,
COL_XMP_EDIT_ICON, &icon,
-1);
if (editable == XMP_AUTO_UPDATE)
{
icon = gtk_widget_render_icon (GTK_WIDGET (entry), GIMP_STOCK_WILBER,
GTK_ICON_SIZE_MENU, NULL);
gtk_tree_store_set (GTK_TREE_STORE (priv->xmp_model), iter,
COL_XMP_EDIT_ICON, icon,
-1);
}
else if (editable == TRUE)
{
icon = gtk_widget_render_icon (GTK_WIDGET (entry), GTK_STOCK_EDIT,
GTK_ICON_SIZE_MENU, NULL);
gtk_tree_store_set (GTK_TREE_STORE (priv->xmp_model), iter,
COL_XMP_EDIT_ICON, icon,
-1);
}
return;
const gchar *value = gtk_entry_get_text (GTK_ENTRY (entry));
gimp_xmp_model_widget_changed (GIMP_XMP_MODEL_WIDGET (entry),
value);
}
......@@ -37,6 +37,11 @@ typedef struct _GimpXmpModelEntryClass GimpXmpModelEntryClass;
struct _GimpXmpModelEntryClass
{
GtkEntryClass parent_class;
void (*gimp_xmp_model_set_text) (GimpXmpModelEntry *entry,
const gchar *value);
const gchar * (*gimp_xmp_model_get_text) (GimpXmpModelEntry *entry);
};
struct _GimpXmpModelEntry
......@@ -46,12 +51,16 @@ struct _GimpXmpModelEntry
};
GType gimp_xmp_model_entry_get_type (void) G_GNUC_CONST;
GType gimp_xmp_model_entry_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_xmp_model_entry_new (const gchar *schema_uri,
const gchar *property,
XMPModel *xmp_model);
GtkWidget * gimp_xmp_model_entry_new (const gchar *schema_uri,
const gchar *property,
XMPModel *xmp_model);
void gimp_xmp_model_set_text (GimpXmpModelEntry *entry,
const gchar *value);
const gchar * gimp_xmp_model_get_text (GimpXmpModelEntry *entry);
G_END_DECLS
......
......@@ -48,8 +48,8 @@ G_DEFINE_TYPE_WITH_CODE (GimpXmpModelText, gimp_xmp_model_text,
static GObject *
gimp_xmp_model_text_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
guint n_params,
GObjectConstructParam *params)
{
GObject *obj;
......
/* gimpxmpmodelwidget.c - interface definition for xmpmodel gtkwidgets
/* gimpxmpmodelwidget.c - interface definition for XMPModel bound
* GTKWidgets
*
* Copyright (C) 2010, Róman Joost <romanofski@gimp.org>
*
......@@ -47,7 +48,7 @@ static void gimp_xmp_model_widget_iface_base_init (GimpXmpModelWidgetInter
static GimpXmpModelWidgetPrivate *
gimp_xmp_model_widget_get_private (GimpXmpModelWidget *widget);
static void gimp_widget_xmp_model_changed (XMPModel *xmp_model,
static void gimp_xmp_model_widget_xmpmodel_changed (XMPModel *xmp_model,
GtkTreeIter *iter,
gpointer *user_data);
......@@ -57,6 +58,7 @@ void set_property_edit_icon (GtkWidget *wid
XMPModel *xmp_model,
GtkTreeIter *iter);
GType
gimp_xmp_model_widget_interface_get_type (void)
{
......@@ -149,7 +151,7 @@ gimp_xmp_model_widget_constructor (GObject *object)
priv->property_name);
g_signal_connect (priv->xmp_model, signal,
G_CALLBACK (gimp_widget_xmp_model_changed),
G_CALLBACK (gimp_xmp_model_widget_xmpmodel_changed),
widget);
g_free (signal);
......@@ -237,10 +239,20 @@ gimp_xmp_model_widget_get_private (GimpXmpModelWidget *widget)
return private;
}
/**
* gimp_xmp_model_widget_xmpmodel_changed:
* @xmp_model: XMPModel this widget is bound to.
* @iter: The iter which points to the last change in the XMPModel
* @user_data: which should be the GtkWidget displaying the value.
*
* If the XMPModel has been changed, the GtkWidget needs to be updated.
* This method updates the corresponding GtkWidget with the new value
* from the XMPModel.
**/
static void
gimp_widget_xmp_model_changed (XMPModel *xmp_model,
GtkTreeIter *iter,
gpointer *user_data)
gimp_xmp_model_widget_xmpmodel_changed (XMPModel *xmp_model,
GtkTreeIter *iter,
gpointer *user_data)
{
GimpXmpModelWidget *widget = GIMP_XMP_MODEL_WIDGET (user_data);
GimpXmpModelWidgetPrivate *priv = GIMP_XMP_MODEL_WIDGET_GET_PRIVATE (widget);
......@@ -263,6 +275,14 @@ gimp_widget_xmp_model_changed (XMPModel *xmp_model,
return;
}
/**
* gimp_xmp_model_widget_set_text:
* @widget: The GtkWidget where the new value is set.
* @tree_value: The new string which will be set on the widget.
*
* This method sets the new value on the GtkWidget implementing the
* #GimpXmpModelWidgetInterface.
**/
void
gimp_xmp_model_widget_set_text (GimpXmpModelWidget *widget,
const gchar *tree_value)
......@@ -275,9 +295,16 @@ gimp_xmp_model_widget_set_text (GimpXmpModelWidget *widget,
iface->widget_set_text (widget, tree_value);
}
/**
* gimp_xmp_model_widget_changed:
* @widget: The GtkWidget which was changed.
* @value: The new string from the GtkWidget.
*
* If the GtkWidget was changed, a new value is set in the #XMPModel.
**/
void
gimp_xmp_model_widget_changed (GimpXmpModelWidget *widget,
const gchar *value)
const gchar *value)
{
GimpXmpModelWidgetPrivate *priv = GIMP_XMP_MODEL_WIDGET_GET_PRIVATE (widget);
......@@ -287,6 +314,10 @@ gimp_xmp_model_widget_changed (GimpXmpModelWidget *widget,
value);
}
/**
* utility methods
**/
/* find the schema prefix for the given URI */
const gchar*
find_schema_prefix (const gchar *schema_uri)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment