gimppluginprocedure.c 4.61 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
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * 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"

#include <glib-object.h>

23
24
#include "libgimpbase/gimpbase.h"

25
26
#include "plug-in-types.h"

27
28
#include "core/gimp.h"

29
#include "plug-in.h"
30
#include "plug-ins.h"
31
32
#include "plug-in-proc.h"

33
34
#include "gimp-intl.h"

35

36
37
PlugInProcDef *
plug_in_proc_def_new (void)
38
{
39
  PlugInProcDef *proc_def;
40

41
42
43
  proc_def = g_new0 (PlugInProcDef, 1);

  return proc_def;
44
}
45
46

void
47
plug_in_proc_def_free (PlugInProcDef *proc_def)
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
  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);
76
  g_free (proc_def->menu_label);
77
78
79
80

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

81
82
83
84
85
  g_free (proc_def->extensions);
  g_free (proc_def->prefixes);
  g_free (proc_def->magics);
  g_free (proc_def->image_types);

86
87
88
  g_free (proc_def);
}

89
90
const ProcRecord *
plug_in_proc_def_get_proc (const PlugInProcDef *proc_def)
91
92
93
94
95
96
97
{
  g_return_val_if_fail (proc_def != NULL, NULL);

  return &proc_def->db_info;
}

const gchar *
98
plug_in_proc_def_get_progname (const PlugInProcDef *proc_def)
99
100
101
102
103
104
105
106
107
108
{
  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:
109
      return ((PlugIn *) proc_def->db_info.exec_method.temporary.plug_in)->prog;
110
111
112
113
114
115

    default:
      break;
    }

  return NULL;
116
}
117
118

gchar *
119
120
plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def,
                              const gchar         *help_domain)
121
{
Michael Natterer's avatar
Michael Natterer committed
122
123
  gchar *help_id;
  gchar *p;
124
125
126

  g_return_val_if_fail (proc_def != NULL, NULL);

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

Michael Natterer's avatar
Michael Natterer committed
129
130
131
  for (p = help_id; p && *p; p++)
    if (*p == '_')
      *p = '-';
132

133
  if (help_domain)
Michael Natterer's avatar
Michael Natterer committed
134
    {
135
      gchar *domain_and_id;
Michael Natterer's avatar
Michael Natterer committed
136

137
      domain_and_id = g_strconcat (help_domain, "?", help_id, NULL);
Michael Natterer's avatar
Michael Natterer committed
138
      g_free (help_id);
139

140
      return domain_and_id;
Michael Natterer's avatar
Michael Natterer committed
141
    }
142
143
144

  return help_id;
}
145
146

gint
147
148
149
plug_in_proc_def_compare_menu_path (gconstpointer a,
                                    gconstpointer b,
                                    gpointer      user_data)
150
151
152
153
154
{
  Gimp                *gimp       = GIMP (user_data);
  const PlugInProcDef *proc_def_a = a;
  const PlugInProcDef *proc_def_b = b;

155
  if (proc_def_a->menu_paths && proc_def_b->menu_paths)
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
    {
      const gchar *progname_a;
      const gchar *progname_b;
      const gchar *domain_a;
      const gchar *domain_b;
      gchar       *menu_path_a;
      gchar       *menu_path_b;
      gint         retval;

      progname_a = plug_in_proc_def_get_progname (proc_def_a);
      progname_b = plug_in_proc_def_get_progname (proc_def_b);

      domain_a = plug_ins_locale_domain (gimp, progname_a, NULL);
      domain_b = plug_ins_locale_domain (gimp, progname_b, NULL);

      menu_path_a = gimp_strip_uline (dgettext (domain_a,
172
                                                proc_def_a->menu_paths->data));
173
      menu_path_b = gimp_strip_uline (dgettext (domain_b,
174
                                                proc_def_b->menu_paths->data));
175
176
177
178
179
180
181
182

      retval = g_utf8_collate (menu_path_a, menu_path_b);

      g_free (menu_path_a);
      g_free (menu_path_b);

      return retval;
    }
183
  else if (proc_def_a->menu_paths)
184
    return 1;
185
  else if (proc_def_b->menu_paths)
186
187
188
189
    return -1;

  return 0;
}