gegl-operation-meta.c 5.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/* This file is part of GEGL
 *
 * GEGL 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 2 of the License, or (at your option) any later version.
 *
 * GEGL 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 GEGL; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Copyright 2006 Øyvind Kolås
 */
#include "gegl-operation-meta.h"
#include <string.h>

enum
{
  PROP_0,
  PROP_LAST
};

static void     get_property         (GObject       *gobject,
                                      guint          prop_id,
                                      GValue        *value,
                                      GParamSpec    *pspec);

static void     set_property         (GObject       *gobject,
                                      guint          prop_id,
                                      const GValue  *value,
                                      GParamSpec    *pspec);
38 39
static void     finalize             (GObject       *self_object);

40 41 42 43 44 45 46 47 48 49

G_DEFINE_TYPE (GeglOperationMeta, gegl_operation_meta, GEGL_TYPE_OPERATION)

static void
gegl_operation_meta_class_init (GeglOperationMetaClass * klass)
{
  GObjectClass       *object_class    = G_OBJECT_CLASS (klass);

  object_class->set_property = set_property;
  object_class->get_property = get_property;
50
  object_class->finalize = finalize;
51 52 53 54 55
}

static void
gegl_operation_meta_init (GeglOperationMeta *self)
{
56
  self->redirects = NULL;
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
}


static void
get_property (GObject      *object,
              guint         prop_id,
              GValue       *value,
              GParamSpec   *pspec)
{
}

static void
set_property (GObject      *object,
              guint         prop_id,
              const GValue *value,
              GParamSpec   *pspec)
{
}
75 76 77 78 79 80 81 82

typedef struct Redirect {
  gchar    *name;
  void     *data;
  GeglNode *internal;
  gchar    *internal_name;
} Redirect;

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
static Redirect *redirect_new (const gchar *name,
                               void        *data,
                               GeglNode    *internal,
                               const gchar *internal_name)
{
  Redirect *self = g_malloc0 (sizeof (Redirect));
  self->name = g_strdup (name);
  self->data = data;
  self->internal = internal;
  self->internal_name = g_strdup (internal_name);
  return self;
}

static void redirect_destroy (Redirect *self)
{
  if (!self)
    return;
  if (self->name)
    g_free (self->name);
  if (self->internal_name)
    g_free (self->internal_name);
  g_free (self);
}

/* FIXME: take GeglNode's as parameters, since we need
 * extra behavior provided by GeglNode on top of GObject.
 */
static void
gegl_node_copy_property_property (GObject     *source,
                                  const gchar *source_property,
                                  GObject     *destination,
                                  const gchar *destination_property)
{
  GValue value = {0};
  GParamSpec *spec = g_object_class_find_property (
       G_OBJECT_GET_CLASS (source), source_property);
  g_assert (spec);
  g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
  gegl_node_get_property (GEGL_OPERATION(source)->node, source_property, &value);
  gegl_node_set_property (GEGL_OPERATION(destination)->node, destination_property, &value);
  g_value_unset (&value);
}

126 127 128 129 130 131 132
void
gegl_operation_meta_redirect (GeglOperation *operation,
                              const gchar   *name,
                              void          *data,
                              GeglNode      *internal,
                              const gchar   *internal_name)
{
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
  GeglOperationMeta *self = GEGL_OPERATION_META (operation);
  Redirect *redirect = redirect_new (name, data, internal, internal_name);

  self->redirects = g_slist_prepend (self->redirects, redirect);

  /* set default value */
  gegl_node_copy_property_property (G_OBJECT (operation), name, G_OBJECT (internal->operation), internal_name);
}

void gegl_operation_meta_property_changed (GeglOperationMeta *self,
                                           GParamSpec        *arg1,
                                           gpointer           user_data)
{
  g_assert (GEGL_IS_OPERATION_META (self));
  if (arg1)
    {
      GSList *iter = self->redirects;
      while (iter)
        {
          Redirect *redirect = iter->data;
          if (!strcmp (redirect->name, arg1->name))
            {
              gegl_node_copy_property_property (G_OBJECT (self), arg1->name,
                                                G_OBJECT (redirect->internal->operation),
                                                redirect->internal_name);
            }
          iter=iter->next;
        }
    }
}

static void
finalize (GObject *gobject)
{
  GeglOperationMeta *self = GEGL_OPERATION_META (gobject);
  GSList *iter = self->redirects;

  while (iter)
    {
      Redirect *redirect = iter->data;
      iter = g_slist_remove (iter, redirect);
      redirect_destroy (redirect);
    }

  G_OBJECT_CLASS (gegl_operation_meta_parent_class)->finalize (gobject);
178
}
179