~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/metadata/xmp-encode.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* xmp-encode.c - generate XMP metadata from the tree model
 
2
 *
 
3
 * Copyright (C) 2005, Raphaël Quinet <raphael@gimp.org>
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the
 
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdio.h>
 
24
#include <string.h>
 
25
 
 
26
#include <gtk/gtk.h>
 
27
#include <libgimp/gimp.h>
 
28
#include <libgimp/gimpui.h>
 
29
 
 
30
#include "libgimp/stdplugins-intl.h"
 
31
 
 
32
#include "xmp-encode.h"
 
33
#include "xmp-schemas.h"
 
34
 
 
35
static void
 
36
gen_schema_start (GString         *buffer,
 
37
                  const XMPSchema *schema)
 
38
{
 
39
  g_string_append_printf (buffer, " <rdf:Description xmlns:%s='%s'>\n",
 
40
                          schema->prefix, schema->uri);
 
41
}
 
42
 
 
43
static void
 
44
gen_schema_end (GString *buffer)
 
45
{
 
46
  g_string_append (buffer, " </rdf:Description>\n\n");
 
47
}
 
48
 
 
49
static void
 
50
gen_property (GString            *buffer,
 
51
              const XMPSchema    *schema,
 
52
              const XMPProperty  *property,
 
53
              const gchar       **value_array)
 
54
{
 
55
  gint         i;
 
56
  const gchar *ns_prefix;
 
57
 
 
58
  switch (property->type)
 
59
    {
 
60
    case XMP_TYPE_BOOLEAN:
 
61
    case XMP_TYPE_DATE:
 
62
    case XMP_TYPE_INTEGER:
 
63
    case XMP_TYPE_REAL:
 
64
    case XMP_TYPE_MIME_TYPE:
 
65
    case XMP_TYPE_TEXT:
 
66
    case XMP_TYPE_RATIONAL:
 
67
      g_string_append_printf (buffer, "  <%s:%s>%s</%s:%s>\n",
 
68
                              schema->prefix, property->name,
 
69
                              value_array[0],
 
70
                              schema->prefix, property->name);
 
71
      break;
 
72
 
 
73
    case XMP_TYPE_LOCALE_BAG:
 
74
    case XMP_TYPE_TEXT_BAG:
 
75
    case XMP_TYPE_XPATH_BAG:
 
76
    case XMP_TYPE_JOB_BAG:
 
77
      g_string_append_printf (buffer, "  <%s:%s>\n   <rdf:Bag>\n",
 
78
                              schema->prefix, property->name);
 
79
      for (i = 0; value_array[i] != NULL; i++)
 
80
        g_string_append_printf (buffer, "    <rdf:li>%s</rdf:li>\n",
 
81
                                value_array[i]);
 
82
      g_string_append_printf (buffer, "   </rdf:Bag>\n  </%s:%s>\n",
 
83
                              schema->prefix, property->name);
 
84
      break;
 
85
 
 
86
    case XMP_TYPE_INTEGER_SEQ:
 
87
    case XMP_TYPE_TEXT_SEQ:
 
88
    case XMP_TYPE_RESOURCE_EVENT_SEQ:
 
89
    case XMP_TYPE_RATIONAL_SEQ:
 
90
      g_string_append_printf (buffer, "  <%s:%s>\n   <rdf:Seq>\n",
 
91
                              schema->prefix, property->name);
 
92
      for (i = 0; value_array[i] != NULL; i++)
 
93
        g_string_append_printf (buffer, "    <rdf:li>%s</rdf:li>\n",
 
94
                                value_array[i]);
 
95
      g_string_append_printf (buffer, "   </rdf:Seq>\n  </%s:%s>\n",
 
96
                              schema->prefix, property->name);
 
97
      break;
 
98
 
 
99
    case XMP_TYPE_LANG_ALT:
 
100
      g_string_append_printf (buffer, "  <%s:%s>\n   <rdf:Alt>\n",
 
101
                              schema->prefix, property->name);
 
102
      for (i = 0; value_array[i] != NULL; i += 2)
 
103
        g_string_append_printf (buffer,
 
104
                                "    <rdf:li xml:lang='%s'>%s</rdf:li>\n",
 
105
                                value_array[i], value_array[i + 1]);
 
106
      g_string_append_printf (buffer, "   </rdf:Alt>\n  </%s:%s>\n",
 
107
                              schema->prefix, property->name);
 
108
      break;
 
109
 
 
110
    case XMP_TYPE_URI:
 
111
      g_string_append_printf (buffer, "  <%s:%s rdf:resource='%s' />\n",
 
112
                              schema->prefix, property->name, value_array[0]);
 
113
      break;
 
114
 
 
115
    case XMP_TYPE_RESOURCE_REF:
 
116
    case XMP_TYPE_DIMENSIONS:
 
117
    case XMP_TYPE_GPS_COORDINATE:
 
118
    case XMP_TYPE_FLASH:
 
119
    case XMP_TYPE_OECF_SFR:
 
120
    case XMP_TYPE_CFA_PATTERN:
 
121
    case XMP_TYPE_DEVICE_SETTINGS:
 
122
    case XMP_TYPE_CONTACT_INFO:
 
123
    case XMP_TYPE_GENERIC_STRUCTURE:
 
124
      if (value_array[0] && value_array[1]
 
125
          && !! strcmp (value_array[1], schema->uri))
 
126
        {
 
127
          g_string_append_printf (buffer,
 
128
                                  "  <%s:%s rdf:parseType='Resource'\n"
 
129
                                  "   xmlns:%s='%s'>\n",
 
130
                                  schema->prefix, property->name,
 
131
                                  value_array[0], value_array[1]);
 
132
          ns_prefix = value_array[0];
 
133
        }
 
134
      else
 
135
        {
 
136
          g_string_append_printf (buffer,
 
137
                                  "  <%s:%s rdf:parseType='Resource'>\n",
 
138
                                  schema->prefix, property->name);
 
139
          ns_prefix = schema->prefix;
 
140
        }
 
141
      for (i = 2; value_array[i] != NULL; i += 2)
 
142
        g_string_append_printf (buffer, "   <%s:%s>%s</%s:%s>\n",
 
143
                                ns_prefix, value_array[i],
 
144
                                value_array[i + 1],
 
145
                                ns_prefix, value_array[i]);
 
146
      g_string_append_printf (buffer, "  </%s:%s>\n",
 
147
                              schema->prefix, property->name);
 
148
      break;
 
149
 
 
150
    case XMP_TYPE_THUMBNAIL_ALT:
 
151
      g_warning ("FIXME: output not implemented yet (%s:%s)",
 
152
                 schema->prefix, property->name);
 
153
      break;
 
154
 
 
155
    case XMP_TYPE_UNKNOWN:
 
156
      g_warning ("Unknown property type for %s", property->name);
 
157
      break;
 
158
    }
 
159
}
 
160
 
 
161
/**
 
162
 * xmp_generate_block:
 
163
 * @xmp_model: An #XMPModel
 
164
 * @buffer: A #GString in which the generated XMP packet will be stored.
 
165
 *
 
166
 * Generate XMP packet from xmp_model and store it in the supplied buffer.
 
167
 *
 
168
 */
 
169
void
 
170
xmp_generate_packet (XMPModel *xmp_model,
 
171
                     GString  *buffer)
 
172
{
 
173
  GtkTreeModel    *model;
 
174
  GtkTreeIter      iter;
 
175
  GtkTreeIter      child;
 
176
  const XMPSchema *schema;
 
177
  gpointer         saved_ref;
 
178
 
 
179
  g_return_if_fail (xmp_model != NULL);
 
180
  g_return_if_fail (buffer != NULL);
 
181
  model = xmp_model_get_tree_model (xmp_model);
 
182
  g_return_if_fail (model != NULL);
 
183
  if (! buffer)
 
184
    buffer = g_string_new (NULL);
 
185
  buffer = g_string_append (buffer,
 
186
    "<?xpacket begin='\357\273\277' id='W5M0MpCehiHzreSzNTczkc9d'?>\n"
 
187
    "<x:xmpmeta xmlns:x='adobe:ns:meta/'>\n"
 
188
    "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n"
 
189
    "\n");
 
190
  /* generate the contents of the XMP packet */
 
191
  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter))
 
192
    {
 
193
      do
 
194
        {
 
195
          gtk_tree_model_get (model, &iter,
 
196
                              COL_XMP_TYPE_XREF, &schema,
 
197
                              -1);
 
198
          gen_schema_start (buffer, schema);
 
199
          if (gtk_tree_model_iter_children (model, &child, &iter))
 
200
            {
 
201
              saved_ref = NULL;
 
202
              do
 
203
                {
 
204
                  const XMPProperty  *property;
 
205
                  const gchar       **value_array;
 
206
 
 
207
                  gtk_tree_model_get (model, &child,
 
208
                                      COL_XMP_TYPE_XREF, &property,
 
209
                                      COL_XMP_VALUE_RAW, &value_array,
 
210
                                      -1);
 
211
                  /* do not process structured types multiple times */
 
212
                  if (saved_ref != value_array)
 
213
                    {
 
214
                      saved_ref = value_array;
 
215
                      g_return_if_fail (property->name != NULL);
 
216
                      gen_property (buffer, schema, property, value_array);
 
217
                    }
 
218
                }
 
219
              while (gtk_tree_model_iter_next (model, &child));
 
220
            }
 
221
          gen_schema_end (buffer);
 
222
        }
 
223
      while (gtk_tree_model_iter_next (model, &iter));
 
224
    }
 
225
  g_string_append (buffer, "</rdf:RDF>\n</x:xmpmeta>\n<?xpacket end='r'?>\n");
 
226
}