New GtkTextView widget based on the XMPModel widget.

The new widget provides editing capabilities for the description and
keywords. It uses the new interface for XMPModel widgets.
This commit is contained in:
Roman Joost 2010-05-09 21:49:56 +10:00
parent c628c1e949
commit b124fe6de6
4 changed files with 197 additions and 48 deletions

View File

@ -33,8 +33,12 @@ metadata_SOURCES = \
xmp-schemas.c \
interface.h \
interface.c \
gimpxmpmodelwidget.h \
gimpxmpmodelwidget.c \
gimpxmpmodelentry.h \
gimpxmpmodelentry.c \
gimpxmpmodeltext.h \
gimpxmpmodeltext.c \
exif-decode.h \
exif-decode.c
# exif-encode.h \

View File

@ -0,0 +1,115 @@
/* gimpxmpmodeltext.c - custom text widget linked to the xmp model
*
* Copyright (C) 2010, Róman Joost <romanofski@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "xmp-schemas.h"
#include "xmp-model.h"
#include "gimpxmpmodelwidget.h"
#include "gimpxmpmodeltext.h"
static void gimp_xmp_model_text_iface_init (GimpXmpModelWidgetInterface *iface);
static void gimp_xmp_model_text_changed (GtkTextBuffer *text_buffer,
gpointer *user_data);
void gimp_xmp_model_text_set_text (GimpXmpModelWidget *widget,
const gchar *tree_value);
G_DEFINE_TYPE_WITH_CODE (GimpXmpModelText, gimp_xmp_model_text,
GTK_TYPE_TEXT_VIEW,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_XMP_MODEL_WIDGET,
gimp_xmp_model_text_iface_init))
#define parent_class gimp_xmp_model_text_parent_class
static GObject *
gimp_xmp_model_text_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *obj;
obj = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
gimp_xmp_model_widget_constructor (obj);
return obj;
}
static void
gimp_xmp_model_text_class_init (GimpXmpModelTextClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructor = gimp_xmp_model_text_constructor;
object_class->set_property = gimp_xmp_model_widget_set_property;
object_class->get_property = gimp_xmp_model_widget_get_property;
gimp_xmp_model_widget_install_properties (object_class);
}
static void
gimp_xmp_model_text_init (GimpXmpModelText *text)
{
GtkTextBuffer *text_buffer;
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
g_signal_connect (text_buffer, "end-user-action",
G_CALLBACK (gimp_xmp_model_text_changed),
text);
}
static void
gimp_xmp_model_text_iface_init (GimpXmpModelWidgetInterface *iface)
{
iface->widget_set_text = gimp_xmp_model_text_set_text;
}
static void
gimp_xmp_model_text_changed (GtkTextBuffer *text_buffer,
gpointer *user_data)
{
GimpXmpModelText *text = GIMP_XMP_MODEL_TEXT (user_data);
GtkTextIter start;
GtkTextIter end;
const gchar *value;
gtk_text_buffer_get_bounds (text_buffer, &start, &end);
value = gtk_text_buffer_get_text (text_buffer, &start, &end, FALSE);
gimp_xmp_model_widget_changed (GIMP_XMP_MODEL_WIDGET (text),
value);
}
void
gimp_xmp_model_text_set_text (GimpXmpModelWidget *widget,
const gchar *tree_value)
{
GtkTextBuffer *text_buffer;
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
gtk_text_buffer_set_text (text_buffer, tree_value, -1);
}

View File

@ -0,0 +1,67 @@
/* GimpXmpModelText.h - custom text widget linked to the xmp model
*
* Copyright (C) 2010, Róman Joost <romanofski@gimp.org>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_XMP_MODEL_TEXT_H__
#define __GIMP_XMP_MODEL_TEXT_H__
G_BEGIN_DECLS
#define GIMP_TYPE_XMP_MODEL_TEXT (gimp_xmp_model_text_get_type ())
#define GIMP_XMP_MODEL_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_XMP_MODEL_TEXT, GimpXmpModelText))
#define GIMP_XMP_MODEL_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_XMP_MODEL_TEXT, XMPModelClass))
#define GIMP_IS_XMP_MODEL_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_XMP_MODEL_TEXT))
#define GIMP_IS_XMP_MODEL_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_XMP_MODEL_TEXT))
#define GIMP_XMP_MODEL_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_XMP_MODEL_TEXT, XMPModelClass))
typedef struct _GimpXmpModelText GimpXmpModelText;
typedef struct _GimpXmpModelTextClass GimpXmpModelTextClass;
struct _GimpXmpModelTextClass
{
GtkTextViewClass parent_class;
void (*gimp_xmp_model_set_text_text) (GimpXmpModelText *text,
const gchar *value);
const gchar * (*gimp_xmp_model_get_text_text) (GimpXmpModelText *text);
};
struct _GimpXmpModelText
{
GtkTextView parent_instance;
gpointer priv;
};
GType gimp_xmp_model_text_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_xmp_model_text_new (const gchar *schema_uri,
const gchar *property,
XMPModel *xmp_model);
void gimp_xmp_model_set_text_text (GimpXmpModelText *text,
const gchar *value);
const gchar * gimp_xmp_model_get_text_text (GimpXmpModelText *text);
G_END_DECLS
#endif /* __GIMP_XMP_MODEL_TEXT_H__ */

View File

@ -54,6 +54,7 @@
#include "metadata.h"
#include "xmp-encode.h"
#include "gimpxmpmodelentry.h"
#include "gimpxmpmodeltext.h"
#define RESPONSE_IMPORT 1
@ -190,42 +191,6 @@ update_icons (MetadataGui *mgui)
gtk_tree_model_foreach (model, icon_foreach_func, mgui);
}
/* FIXME: temporary data structure for testing */
typedef struct
{
const gchar *schema;
const gchar *property_name;
GSList *widget_list;
MetadataGui *mgui;
} WidgetXRef;
static void
text_changed (GtkTextBuffer *text_buffer,
gpointer user_data)
{
WidgetXRef *xref = user_data;
GtkTextIter start;
GtkTextIter end;
gtk_text_buffer_get_bounds (text_buffer, &start, &end);
g_print ("XMP: %s %p %p %s\n", xref->property_name, text_buffer, user_data, gtk_text_buffer_get_text (text_buffer, &start, &end, FALSE)); /* FIXME */
}
static void
register_text_xref (GtkTextBuffer *text_buffer,
const gchar *schema,
const gchar *property_name)
{
WidgetXRef *xref;
xref = g_new (WidgetXRef, 1);
xref->schema = schema;
xref->property_name = property_name;
xref->widget_list = g_slist_prepend (NULL, text_buffer);
g_signal_connect (GTK_TEXT_BUFFER (text_buffer), "changed",
G_CALLBACK (text_changed), xref);
}
static void
add_description_tab (GtkWidget *notebook,
MetadataGui *mgui)
@ -235,7 +200,6 @@ add_description_tab (GtkWidget *notebook,
GtkWidget *entry;
GtkWidget *scrolled_window;
GtkWidget *text_view;
GtkTextBuffer *text_buffer;
frame = gimp_frame_new (_("Description"));
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame,
@ -273,14 +237,11 @@ add_description_tab (GtkWidget *notebook,
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
text_view = gtk_text_view_new ();
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
gtk_text_buffer_set_text (text_buffer,
"FIXME:\n"
"These widgets are currently disconnected from the XMP model.\n"
"Please use the Advanced tab.",
-1);
register_text_xref (text_buffer, XMP_SCHEMA_DUBLIN_CORE, "description");
text_view = g_object_new (GIMP_TYPE_XMP_MODEL_TEXT,
"schema-uri", XMP_SCHEMA_DUBLIN_CORE,
"property-name", "description",
"xmp-model", mgui->xmp_model,
NULL);
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("_Description:"), 0.0, 0.5,
@ -301,9 +262,11 @@ add_description_tab (GtkWidget *notebook,
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
text_view = gtk_text_view_new ();
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
register_text_xref (text_buffer, XMP_SCHEMA_PDF, "Keywords");
text_view = g_object_new (GIMP_TYPE_XMP_MODEL_TEXT,
"schema-uri", XMP_SCHEMA_PDF,
"property-name", "Keywords",
"xmp-model", mgui->xmp_model,
NULL);
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 4,
_("_Keywords:"), 0.0, 0.5,