gimpplugindef.c 6.84 KB
Newer Older
1 2 3 4 5
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimpplugindef.c
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9 10 11 12 13 14 15 16
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
 */

#include "config.h"

#include <glib-object.h>

#include "plug-in-types.h"

#include "core/gimp-utils.h"

#include "gimpplugindef.h"
#include "gimppluginprocedure.h"


static void     gimp_plug_in_def_finalize    (GObject    *object);

static gint64   gimp_plug_in_def_get_memsize (GimpObject *object,
                                              gint64     *gui_size);


G_DEFINE_TYPE (GimpPlugInDef, gimp_plug_in_def, GIMP_TYPE_OBJECT)

#define parent_class gimp_plug_in_def_parent_class


static void
gimp_plug_in_def_class_init (GimpPlugInDefClass *klass)
{
  GObjectClass    *object_class      = G_OBJECT_CLASS (klass);
  GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);

  object_class->finalize         = gimp_plug_in_def_finalize;

  gimp_object_class->get_memsize = gimp_plug_in_def_get_memsize;
}

static void
gimp_plug_in_def_init (GimpPlugInDef *def)
{
}

static void
gimp_plug_in_def_finalize (GObject *object)
{
  GimpPlugInDef *plug_in_def = GIMP_PLUG_IN_DEF (object);

  g_free (plug_in_def->prog);
  g_free (plug_in_def->locale_domain_name);
  g_free (plug_in_def->locale_domain_path);
  g_free (plug_in_def->help_domain_name);
  g_free (plug_in_def->help_domain_uri);

70
  g_slist_free_full (plug_in_def->procedures, (GDestroyNotify) g_object_unref);
71 72 73 74 75 76 77 78 79 80 81

  G_OBJECT_CLASS (parent_class)->finalize (object);
}

static gint64
gimp_plug_in_def_get_memsize (GimpObject *object,
                              gint64     *gui_size)
{
  GimpPlugInDef *plug_in_def = GIMP_PLUG_IN_DEF (object);
  gint64         memsize     = 0;

82 83 84 85 86
  memsize += gimp_string_get_memsize (plug_in_def->prog);
  memsize += gimp_string_get_memsize (plug_in_def->locale_domain_name);
  memsize += gimp_string_get_memsize (plug_in_def->locale_domain_path);
  memsize += gimp_string_get_memsize (plug_in_def->help_domain_name);
  memsize += gimp_string_get_memsize (plug_in_def->help_domain_uri);
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

  memsize += gimp_g_slist_get_memsize (plug_in_def->procedures, 0);

  return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
                                                                  gui_size);
}


/*  public functions  */

GimpPlugInDef *
gimp_plug_in_def_new (const gchar *prog)
{
  GimpPlugInDef *plug_in_def;

  g_return_val_if_fail (prog != NULL, NULL);

  plug_in_def = g_object_new (GIMP_TYPE_PLUG_IN_DEF, NULL);

  plug_in_def->prog = g_strdup (prog);

  return plug_in_def;
}

void
gimp_plug_in_def_add_procedure (GimpPlugInDef       *plug_in_def,
                                GimpPlugInProcedure *proc)
{
  GimpPlugInProcedure *overridden;

  g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));

  overridden = gimp_plug_in_procedure_find (plug_in_def->procedures,
121
                                            gimp_object_get_name (proc));
122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234

  if (overridden)
    gimp_plug_in_def_remove_procedure (plug_in_def, overridden);

  proc->mtime = plug_in_def->mtime;

  gimp_plug_in_procedure_set_locale_domain (proc,
                                            plug_in_def->locale_domain_name);
  gimp_plug_in_procedure_set_help_domain (proc,
                                          plug_in_def->help_domain_name);

  plug_in_def->procedures = g_slist_append (plug_in_def->procedures,
                                            g_object_ref (proc));
}

void
gimp_plug_in_def_remove_procedure (GimpPlugInDef       *plug_in_def,
                                   GimpPlugInProcedure *proc)
{
  g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));

  plug_in_def->procedures = g_slist_remove (plug_in_def->procedures, proc);
  g_object_unref (proc);
}

void
gimp_plug_in_def_set_locale_domain (GimpPlugInDef *plug_in_def,
                                    const gchar   *domain_name,
                                    const gchar   *domain_path)
{
  GSList *list;

  g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));

  if (plug_in_def->locale_domain_name)
    g_free (plug_in_def->locale_domain_name);
  plug_in_def->locale_domain_name = g_strdup (domain_name);

  if (plug_in_def->locale_domain_path)
    g_free (plug_in_def->locale_domain_path);
  plug_in_def->locale_domain_path = g_strdup (domain_path);

  for (list = plug_in_def->procedures; list; list = g_slist_next (list))
    {
      GimpPlugInProcedure *procedure = list->data;

      gimp_plug_in_procedure_set_locale_domain (procedure,
                                                plug_in_def->locale_domain_name);
    }
}

void
gimp_plug_in_def_set_help_domain (GimpPlugInDef *plug_in_def,
                                  const gchar   *domain_name,
                                  const gchar   *domain_uri)
{
  GSList *list;

  g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));

  if (plug_in_def->help_domain_name)
    g_free (plug_in_def->help_domain_name);
  plug_in_def->help_domain_name = g_strdup (domain_name);

  if (plug_in_def->help_domain_uri)
    g_free (plug_in_def->help_domain_uri);
  plug_in_def->help_domain_uri = g_strdup (domain_uri);

  for (list = plug_in_def->procedures; list; list = g_slist_next (list))
    {
      GimpPlugInProcedure *procedure = list->data;

      gimp_plug_in_procedure_set_help_domain (procedure,
                                              plug_in_def->help_domain_name);
    }
}

void
gimp_plug_in_def_set_mtime (GimpPlugInDef *plug_in_def,
                            time_t         mtime)
{
  GSList *list;

  g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));

  plug_in_def->mtime = mtime;

  for (list = plug_in_def->procedures; list; list = g_slist_next (list))
    {
      GimpPlugInProcedure *proc = list->data;

      proc->mtime = plug_in_def->mtime;
    }
}

void
gimp_plug_in_def_set_needs_query (GimpPlugInDef *plug_in_def,
                                  gboolean       needs_query)
{
  g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));

  plug_in_def->needs_query = needs_query ? TRUE : FALSE;
}

void
gimp_plug_in_def_set_has_init (GimpPlugInDef *plug_in_def,
                               gboolean       has_init)
{
  g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def));

  plug_in_def->has_init = has_init ? TRUE : FALSE;
}