gimppluginprocedure.c 7.92 KB
Newer Older
1
2
3
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
5
 * plug-in-proc-def.c
 *
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (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
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

23
24
#include <string.h>

25
#include <glib-object.h>
26
#include <gdk-pixbuf/gdk-pixbuf.h>
27

28
29
#include "libgimpbase/gimpbase.h"

30
31
#include "plug-in-types.h"

32
33
#include "core/gimp.h"

34
#include "plug-in.h"
35
#include "plug-ins.h"
36
#include "plug-in-proc-def.h"
37

38
39
#include "gimp-intl.h"

40

41
42
PlugInProcDef *
plug_in_proc_def_new (void)
43
{
44
45
46
47
48
  PlugInProcDef *proc_def = g_new0 (PlugInProcDef, 1);

  proc_def->icon_data_length = -1;

  return proc_def;
49
}
50
51

void
52
plug_in_proc_def_free (PlugInProcDef *proc_def)
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
  gint i;

  g_return_if_fail (proc_def != NULL);

  g_free (proc_def->db_info.name);
  g_free (proc_def->db_info.blurb);
  g_free (proc_def->db_info.help);
  g_free (proc_def->db_info.author);
  g_free (proc_def->db_info.copyright);
  g_free (proc_def->db_info.date);

  for (i = 0; i < proc_def->db_info.num_args; i++)
    {
      g_free (proc_def->db_info.args[i].name);
      g_free (proc_def->db_info.args[i].description);
    }

  for (i = 0; i < proc_def->db_info.num_values; i++)
    {
      g_free (proc_def->db_info.values[i].name);
      g_free (proc_def->db_info.values[i].description);
    }

  g_free (proc_def->db_info.args);
  g_free (proc_def->db_info.values);

  g_free (proc_def->prog);
81
  g_free (proc_def->menu_label);
82
83
84
85

  g_list_foreach (proc_def->menu_paths, (GFunc) g_free, NULL);
  g_list_free (proc_def->menu_paths);

86
87
88
  g_free (proc_def->icon_data);
  g_free (proc_def->image_types);

89
90
91
  g_free (proc_def->extensions);
  g_free (proc_def->prefixes);
  g_free (proc_def->magics);
92
  g_free (proc_def->mime_type);
93
94
95
96
97
98
99
100
101

  g_slist_foreach (proc_def->extensions_list, (GFunc) g_free, NULL);
  g_slist_free (proc_def->extensions_list);

  g_slist_foreach (proc_def->prefixes_list, (GFunc) g_free, NULL);
  g_slist_free (proc_def->prefixes_list);

  g_slist_foreach (proc_def->magics_list, (GFunc) g_free, NULL);
  g_slist_free (proc_def->magics_list);
102

103
104
  g_free (proc_def->thumb_loader);

105
106
107
  g_free (proc_def);
}

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
PlugInProcDef *
plug_in_proc_def_find (GSList      *list,
                       const gchar *proc_name)
{
  GSList *l;

  for (l = list; l; l = g_slist_next (l))
    {
      PlugInProcDef *proc_def = l->data;

      if (! strcmp (proc_name, proc_def->db_info.name))
        return proc_def;
    }

  return NULL;
}

125
126
const ProcRecord *
plug_in_proc_def_get_proc (const PlugInProcDef *proc_def)
127
128
129
130
131
132
133
{
  g_return_val_if_fail (proc_def != NULL, NULL);

  return &proc_def->db_info;
}

const gchar *
134
plug_in_proc_def_get_progname (const PlugInProcDef *proc_def)
135
136
137
138
139
140
141
142
143
144
{
  g_return_val_if_fail (proc_def != NULL, NULL);

  switch (proc_def->db_info.proc_type)
    {
    case GIMP_PLUGIN:
    case GIMP_EXTENSION:
      return proc_def->prog;

    case GIMP_TEMPORARY:
145
      return ((PlugIn *) proc_def->db_info.exec_method.temporary.plug_in)->prog;
146
147
148
149
150
151

    default:
      break;
    }

  return NULL;
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
gchar *
plug_in_proc_def_get_label (const PlugInProcDef *proc_def,
                            const gchar         *locale_domain)
{
  const gchar *path;
  gchar       *stripped;
  gchar       *ellipses;
  gchar       *label;

  g_return_val_if_fail (proc_def != NULL, NULL);

  if (proc_def->menu_label)
    path = dgettext (locale_domain, proc_def->menu_label);
  else if (proc_def->menu_paths)
    path = dgettext (locale_domain, proc_def->menu_paths->data);
  else
    return NULL;

  stripped = gimp_strip_uline (path);

  if (proc_def->menu_label)
    label = g_strdup (stripped);
  else
    label = g_path_get_basename (stripped);

  g_free (stripped);

  ellipses = strstr (label, "...");

  if (ellipses && ellipses == (label + strlen (label) - 3))
    *ellipses = '\0';

  return label;
}

Michael Natterer's avatar
Michael Natterer committed
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
void
plug_in_proc_def_set_icon (PlugInProcDef *proc_def,
                           GimpIconType   icon_type,
                           const gchar   *icon_data,
                           gint           icon_data_length)
{
  g_return_if_fail (proc_def != NULL);
  g_return_if_fail (icon_type == -1 || icon_data != NULL);
  g_return_if_fail (icon_type == -1 || icon_data_length > 0);

  if (proc_def->icon_data)
    {
      g_free (proc_def->icon_data);
      proc_def->icon_data_length = -1;
      proc_def->icon_data        = NULL;
    }

  proc_def->icon_type = icon_type;

  switch (proc_def->icon_type)
    {
    case GIMP_ICON_TYPE_STOCK_ID:
    case GIMP_ICON_TYPE_IMAGE_FILE:
      proc_def->icon_data_length = -1;
      proc_def->icon_data        = g_strdup (icon_data);
      break;

    case GIMP_ICON_TYPE_INLINE_PIXBUF:
      proc_def->icon_data_length = icon_data_length;
      proc_def->icon_data        = g_memdup (icon_data,
                                             icon_data_length);
      break;
    }
}

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
const gchar *
plug_in_proc_def_get_stock_id (const PlugInProcDef *proc_def)
{
  g_return_val_if_fail (proc_def != NULL, NULL);

  switch (proc_def->icon_type)
    {
    case GIMP_ICON_TYPE_STOCK_ID:
      return proc_def->icon_data;

    default:
      return NULL;
    }
}

GdkPixbuf *
plug_in_proc_def_get_pixbuf (const PlugInProcDef *proc_def)
{
  GdkPixbuf *pixbuf = NULL;
  GError    *error  = NULL;

  g_return_val_if_fail (proc_def != NULL, NULL);

  switch (proc_def->icon_type)
    {
    case GIMP_ICON_TYPE_INLINE_PIXBUF:
      pixbuf = gdk_pixbuf_new_from_inline (proc_def->icon_data_length,
                                           proc_def->icon_data, TRUE, &error);
      if (! pixbuf)
        {
          g_printerr (error->message);
          g_clear_error (&error);
        }
      break;

    case GIMP_ICON_TYPE_IMAGE_FILE:
      pixbuf = gdk_pixbuf_new_from_file (proc_def->icon_data, &error);
      if (! pixbuf)
        {
          g_printerr (error->message);
          g_clear_error (&error);
        }
      break;

    default:
      break;
    }

  return pixbuf;
}

275
gchar *
276
277
plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def,
                              const gchar         *help_domain)
278
{
Michael Natterer's avatar
Michael Natterer committed
279
280
  gchar *help_id;
  gchar *p;
281
282
283

  g_return_val_if_fail (proc_def != NULL, NULL);

Michael Natterer's avatar
Michael Natterer committed
284
  help_id = g_strdup (proc_def->db_info.name);
285

Michael Natterer's avatar
Michael Natterer committed
286
287
288
  for (p = help_id; p && *p; p++)
    if (*p == '_')
      *p = '-';
289

290
  if (help_domain)
Michael Natterer's avatar
Michael Natterer committed
291
    {
292
      gchar *domain_and_id;
Michael Natterer's avatar
Michael Natterer committed
293

294
      domain_and_id = g_strconcat (help_domain, "?", help_id, NULL);
Michael Natterer's avatar
Michael Natterer committed
295
      g_free (help_id);
296

297
      return domain_and_id;
Michael Natterer's avatar
Michael Natterer committed
298
    }
299
300
301

  return help_id;
}
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337

gboolean
plug_in_proc_def_get_sensitive (const PlugInProcDef *proc_def,
                                GimpImageType        image_type)
{
  gboolean sensitive;

  g_return_val_if_fail (proc_def != NULL, FALSE);

  switch (image_type)
    {
    case GIMP_RGB_IMAGE:
      sensitive = proc_def->image_types_val & PLUG_IN_RGB_IMAGE;
      break;
    case GIMP_RGBA_IMAGE:
      sensitive = proc_def->image_types_val & PLUG_IN_RGBA_IMAGE;
      break;
    case GIMP_GRAY_IMAGE:
      sensitive = proc_def->image_types_val & PLUG_IN_GRAY_IMAGE;
      break;
    case GIMP_GRAYA_IMAGE:
      sensitive = proc_def->image_types_val & PLUG_IN_GRAYA_IMAGE;
      break;
    case GIMP_INDEXED_IMAGE:
      sensitive = proc_def->image_types_val & PLUG_IN_INDEXED_IMAGE;
      break;
    case GIMP_INDEXEDA_IMAGE:
      sensitive = proc_def->image_types_val & PLUG_IN_INDEXEDA_IMAGE;
      break;
    default:
      sensitive = FALSE;
      break;
    }

  return sensitive ? TRUE : FALSE;
}