1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 /* NOTE: This file is auto-generated by pdbgen.pl. */
19 
20 #include "config.h"
21 
22 #include <string.h>
23 
24 #include <gegl.h>
25 
26 #include <gdk-pixbuf/gdk-pixbuf.h>
27 
28 #include "libgimpbase/gimpbase.h"
29 #include "libgimpconfig/gimpconfig.h"
30 #include "libgimpmodule/gimpmodule.h"
31 
32 #include "libgimpbase/gimpbase.h"
33 
34 #include "pdb-types.h"
35 
36 #include "config/gimprc.h"
37 #include "core/gimp-utils.h"
38 #include "core/gimp.h"
39 #include "core/gimpparamspecs.h"
40 #include "core/gimptemplate.h"
41 
42 #include "gimppdb.h"
43 #include "gimpprocedure.h"
44 #include "internal-procs.h"
45 
46 
47 static GimpValueArray *
gimprc_query_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)48 gimprc_query_invoker (GimpProcedure         *procedure,
49                       Gimp                  *gimp,
50                       GimpContext           *context,
51                       GimpProgress          *progress,
52                       const GimpValueArray  *args,
53                       GError               **error)
54 {
55   gboolean success = TRUE;
56   GimpValueArray *return_vals;
57   const gchar *token;
58   gchar *value = NULL;
59 
60   token = g_value_get_string (gimp_value_array_index (args, 0));
61 
62   if (success)
63     {
64       if (strlen (token))
65         {
66           /*  use edit_config because unknown tokens are set there  */
67           value = gimp_rc_query (GIMP_RC (gimp->edit_config), token);
68 
69           if (! value)
70             success = FALSE;
71         }
72       else
73         success = FALSE;
74     }
75 
76   return_vals = gimp_procedure_get_return_values (procedure, success,
77                                                   error ? *error : NULL);
78 
79   if (success)
80     g_value_take_string (gimp_value_array_index (return_vals, 1), value);
81 
82   return return_vals;
83 }
84 
85 static GimpValueArray *
gimprc_set_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)86 gimprc_set_invoker (GimpProcedure         *procedure,
87                     Gimp                  *gimp,
88                     GimpContext           *context,
89                     GimpProgress          *progress,
90                     const GimpValueArray  *args,
91                     GError               **error)
92 {
93   gboolean success = TRUE;
94   const gchar *token;
95   const gchar *value;
96 
97   token = g_value_get_string (gimp_value_array_index (args, 0));
98   value = g_value_get_string (gimp_value_array_index (args, 1));
99 
100   if (success)
101     {
102       if (strlen (token))
103         {
104           /*  use edit_config because that's the one that gets saved  */
105           gimp_rc_set_unknown_token (GIMP_RC (gimp->edit_config), token, value);
106         }
107       else
108         success = FALSE;
109     }
110 
111   return gimp_procedure_get_return_values (procedure, success,
112                                            error ? *error : NULL);
113 }
114 
115 static GimpValueArray *
get_default_comment_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)116 get_default_comment_invoker (GimpProcedure         *procedure,
117                              Gimp                  *gimp,
118                              GimpContext           *context,
119                              GimpProgress          *progress,
120                              const GimpValueArray  *args,
121                              GError               **error)
122 {
123   GimpValueArray *return_vals;
124   gchar *comment = NULL;
125 
126   comment = g_strdup (gimp_template_get_comment (gimp->config->default_image));
127 
128   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
129   g_value_take_string (gimp_value_array_index (return_vals, 1), comment);
130 
131   return return_vals;
132 }
133 
134 static GimpValueArray *
get_default_unit_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)135 get_default_unit_invoker (GimpProcedure         *procedure,
136                           Gimp                  *gimp,
137                           GimpContext           *context,
138                           GimpProgress          *progress,
139                           const GimpValueArray  *args,
140                           GError               **error)
141 {
142   GimpValueArray *return_vals;
143   GimpUnit unit_id = 0;
144 
145   unit_id = gimp_get_default_unit ();
146 
147   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
148   g_value_set_int (gimp_value_array_index (return_vals, 1), unit_id);
149 
150   return return_vals;
151 }
152 
153 static GimpValueArray *
get_monitor_resolution_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)154 get_monitor_resolution_invoker (GimpProcedure         *procedure,
155                                 Gimp                  *gimp,
156                                 GimpContext           *context,
157                                 GimpProgress          *progress,
158                                 const GimpValueArray  *args,
159                                 GError               **error)
160 {
161   GimpValueArray *return_vals;
162   gdouble xres = 0.0;
163   gdouble yres = 0.0;
164 
165   xres = GIMP_DISPLAY_CONFIG (gimp->config)->monitor_xres;
166   yres = GIMP_DISPLAY_CONFIG (gimp->config)->monitor_yres;
167 
168   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
169 
170   g_value_set_double (gimp_value_array_index (return_vals, 1), xres);
171   g_value_set_double (gimp_value_array_index (return_vals, 2), yres);
172 
173   return return_vals;
174 }
175 
176 static GimpValueArray *
get_theme_dir_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)177 get_theme_dir_invoker (GimpProcedure         *procedure,
178                        Gimp                  *gimp,
179                        GimpContext           *context,
180                        GimpProgress          *progress,
181                        const GimpValueArray  *args,
182                        GError               **error)
183 {
184   GimpValueArray *return_vals;
185   gchar *theme_dir = NULL;
186 
187   GFile *file = gimp_get_theme_dir (gimp);
188 
189   if (file)
190     theme_dir = g_file_get_path (file);
191 
192   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
193   g_value_take_string (gimp_value_array_index (return_vals, 1), theme_dir);
194 
195   return return_vals;
196 }
197 
198 static GimpValueArray *
get_icon_theme_dir_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)199 get_icon_theme_dir_invoker (GimpProcedure         *procedure,
200                             Gimp                  *gimp,
201                             GimpContext           *context,
202                             GimpProgress          *progress,
203                             const GimpValueArray  *args,
204                             GError               **error)
205 {
206   GimpValueArray *return_vals;
207   gchar *icon_theme_dir = NULL;
208 
209   GFile *file = gimp_get_icon_theme_dir (gimp);
210 
211   if (file)
212     icon_theme_dir = g_file_get_path (file);
213 
214   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
215   g_value_take_string (gimp_value_array_index (return_vals, 1), icon_theme_dir);
216 
217   return return_vals;
218 }
219 
220 static GimpValueArray *
get_color_configuration_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)221 get_color_configuration_invoker (GimpProcedure         *procedure,
222                                  Gimp                  *gimp,
223                                  GimpContext           *context,
224                                  GimpProgress          *progress,
225                                  const GimpValueArray  *args,
226                                  GError               **error)
227 {
228   GimpValueArray *return_vals;
229   gchar *config = NULL;
230 
231   config = gimp_config_serialize_to_string (GIMP_CONFIG (gimp->config->color_management), NULL);
232 
233   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
234   g_value_take_string (gimp_value_array_index (return_vals, 1), config);
235 
236   return return_vals;
237 }
238 
239 static GimpValueArray *
get_module_load_inhibit_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)240 get_module_load_inhibit_invoker (GimpProcedure         *procedure,
241                                  Gimp                  *gimp,
242                                  GimpContext           *context,
243                                  GimpProgress          *progress,
244                                  const GimpValueArray  *args,
245                                  GError               **error)
246 {
247   GimpValueArray *return_vals;
248   gchar *load_inhibit = NULL;
249 
250   load_inhibit = g_strdup (gimp_module_db_get_load_inhibit (gimp->module_db));
251 
252   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
253   g_value_take_string (gimp_value_array_index (return_vals, 1), load_inhibit);
254 
255   return return_vals;
256 }
257 
258 void
register_gimprc_procs(GimpPDB * pdb)259 register_gimprc_procs (GimpPDB *pdb)
260 {
261   GimpProcedure *procedure;
262 
263   /*
264    * gimp-gimprc-query
265    */
266   procedure = gimp_procedure_new (gimprc_query_invoker);
267   gimp_object_set_static_name (GIMP_OBJECT (procedure),
268                                "gimp-gimprc-query");
269   gimp_procedure_set_static_strings (procedure,
270                                      "gimp-gimprc-query",
271                                      "Queries the gimprc file parser for information on a specified token.",
272                                      "This procedure is used to locate additional information contained in the gimprc file considered extraneous to the operation of GIMP. Plug-ins that need configuration information can expect it will be stored in the user gimprc file and can use this procedure to retrieve it. This query procedure will return the value associated with the specified token. This corresponds _only_ to entries with the format: (<token> <value>). The value must be a string. Entries not corresponding to this format will cause warnings to be issued on gimprc parsing and will not be queryable.",
273                                      "Spencer Kimball & Peter Mattis",
274                                      "Spencer Kimball & Peter Mattis",
275                                      "1997",
276                                      NULL);
277   gimp_procedure_add_argument (procedure,
278                                gimp_param_spec_string ("token",
279                                                        "token",
280                                                        "The token to query for",
281                                                        FALSE, FALSE, FALSE,
282                                                        NULL,
283                                                        GIMP_PARAM_READWRITE));
284   gimp_procedure_add_return_value (procedure,
285                                    gimp_param_spec_string ("value",
286                                                            "value",
287                                                            "The value associated with the queried token",
288                                                            FALSE, FALSE, FALSE,
289                                                            NULL,
290                                                            GIMP_PARAM_READWRITE));
291   gimp_pdb_register_procedure (pdb, procedure);
292   g_object_unref (procedure);
293 
294   /*
295    * gimp-gimprc-set
296    */
297   procedure = gimp_procedure_new (gimprc_set_invoker);
298   gimp_object_set_static_name (GIMP_OBJECT (procedure),
299                                "gimp-gimprc-set");
300   gimp_procedure_set_static_strings (procedure,
301                                      "gimp-gimprc-set",
302                                      "Sets a gimprc token to a value and saves it in the gimprc.",
303                                      "This procedure is used to add or change additional information in the gimprc file that is considered extraneous to the operation of GIMP. Plug-ins that need configuration information can use this function to store it, and 'gimp-gimprc-query' to retrieve it. This will accept _only_ string values in UTF-8 encoding.",
304                                      "Seth Burgess",
305                                      "Seth Burgess",
306                                      "1999",
307                                      NULL);
308   gimp_procedure_add_argument (procedure,
309                                gimp_param_spec_string ("token",
310                                                        "token",
311                                                        "The token to add or modify",
312                                                        FALSE, FALSE, FALSE,
313                                                        NULL,
314                                                        GIMP_PARAM_READWRITE));
315   gimp_procedure_add_argument (procedure,
316                                gimp_param_spec_string ("value",
317                                                        "value",
318                                                        "The value to set the token to",
319                                                        FALSE, FALSE, FALSE,
320                                                        NULL,
321                                                        GIMP_PARAM_READWRITE));
322   gimp_pdb_register_procedure (pdb, procedure);
323   g_object_unref (procedure);
324 
325   /*
326    * gimp-get-default-comment
327    */
328   procedure = gimp_procedure_new (get_default_comment_invoker);
329   gimp_object_set_static_name (GIMP_OBJECT (procedure),
330                                "gimp-get-default-comment");
331   gimp_procedure_set_static_strings (procedure,
332                                      "gimp-get-default-comment",
333                                      "Get the default image comment as specified in the Preferences.",
334                                      "Returns a copy of the default image comment.",
335                                      "Spencer Kimball & Peter Mattis",
336                                      "Spencer Kimball & Peter Mattis",
337                                      "1995-1996",
338                                      NULL);
339   gimp_procedure_add_return_value (procedure,
340                                    gimp_param_spec_string ("comment",
341                                                            "comment",
342                                                            "Default image comment",
343                                                            FALSE, FALSE, FALSE,
344                                                            NULL,
345                                                            GIMP_PARAM_READWRITE));
346   gimp_pdb_register_procedure (pdb, procedure);
347   g_object_unref (procedure);
348 
349   /*
350    * gimp-get-default-unit
351    */
352   procedure = gimp_procedure_new (get_default_unit_invoker);
353   gimp_object_set_static_name (GIMP_OBJECT (procedure),
354                                "gimp-get-default-unit");
355   gimp_procedure_set_static_strings (procedure,
356                                      "gimp-get-default-unit",
357                                      "Get the default unit (taken from the user's locale).",
358                                      "Returns the default unit's integer ID.",
359                                      "Spencer Kimball & Peter Mattis",
360                                      "Spencer Kimball & Peter Mattis",
361                                      "1995-1996",
362                                      NULL);
363   gimp_procedure_add_return_value (procedure,
364                                    gimp_param_spec_unit ("unit-id",
365                                                          "unit id",
366                                                          "Default unit",
367                                                          TRUE,
368                                                          FALSE,
369                                                          GIMP_UNIT_PIXEL,
370                                                          GIMP_PARAM_READWRITE));
371   gimp_pdb_register_procedure (pdb, procedure);
372   g_object_unref (procedure);
373 
374   /*
375    * gimp-get-monitor-resolution
376    */
377   procedure = gimp_procedure_new (get_monitor_resolution_invoker);
378   gimp_object_set_static_name (GIMP_OBJECT (procedure),
379                                "gimp-get-monitor-resolution");
380   gimp_procedure_set_static_strings (procedure,
381                                      "gimp-get-monitor-resolution",
382                                      "Get the monitor resolution as specified in the Preferences.",
383                                      "Returns the resolution of the monitor in pixels/inch. This value is taken from the Preferences (or the windowing system if this is set in the Preferences) and there's no guarantee for the value to be reasonable.",
384                                      "Spencer Kimball & Peter Mattis",
385                                      "Spencer Kimball & Peter Mattis",
386                                      "1995-1996",
387                                      NULL);
388   gimp_procedure_add_return_value (procedure,
389                                    g_param_spec_double ("xres",
390                                                         "xres",
391                                                         "X resolution",
392                                                         -G_MAXDOUBLE, G_MAXDOUBLE, 0,
393                                                         GIMP_PARAM_READWRITE));
394   gimp_procedure_add_return_value (procedure,
395                                    g_param_spec_double ("yres",
396                                                         "yres",
397                                                         "Y resolution",
398                                                         -G_MAXDOUBLE, G_MAXDOUBLE, 0,
399                                                         GIMP_PARAM_READWRITE));
400   gimp_pdb_register_procedure (pdb, procedure);
401   g_object_unref (procedure);
402 
403   /*
404    * gimp-get-theme-dir
405    */
406   procedure = gimp_procedure_new (get_theme_dir_invoker);
407   gimp_object_set_static_name (GIMP_OBJECT (procedure),
408                                "gimp-get-theme-dir");
409   gimp_procedure_set_static_strings (procedure,
410                                      "gimp-get-theme-dir",
411                                      "Get the directory of the current GUI theme.",
412                                      "Returns a copy of the current GUI theme dir.\n"
413                                      "\n"
414                                      "Deprecated: There is no replacement for this procedure.",
415                                      "Spencer Kimball & Peter Mattis",
416                                      "Spencer Kimball & Peter Mattis",
417                                      "1995-1996",
418                                      "NONE");
419   gimp_procedure_add_return_value (procedure,
420                                    gimp_param_spec_string ("theme-dir",
421                                                            "theme dir",
422                                                            "The GUI theme dir",
423                                                            FALSE, FALSE, FALSE,
424                                                            NULL,
425                                                            GIMP_PARAM_READWRITE));
426   gimp_pdb_register_procedure (pdb, procedure);
427   g_object_unref (procedure);
428 
429   /*
430    * gimp-get-icon-theme-dir
431    */
432   procedure = gimp_procedure_new (get_icon_theme_dir_invoker);
433   gimp_object_set_static_name (GIMP_OBJECT (procedure),
434                                "gimp-get-icon-theme-dir");
435   gimp_procedure_set_static_strings (procedure,
436                                      "gimp-get-icon-theme-dir",
437                                      "Get the directory of the current icon theme.",
438                                      "Returns a copy of the current icon theme dir.\n"
439                                      "\n"
440                                      "Deprecated: There is no replacement for this procedure.",
441                                      "Michael Natterer <mitch@gimp.org>",
442                                      "Michael Natterer",
443                                      "2015",
444                                      "NONE");
445   gimp_procedure_add_return_value (procedure,
446                                    gimp_param_spec_string ("icon-theme-dir",
447                                                            "icon theme dir",
448                                                            "The icon theme dir",
449                                                            FALSE, FALSE, FALSE,
450                                                            NULL,
451                                                            GIMP_PARAM_READWRITE));
452   gimp_pdb_register_procedure (pdb, procedure);
453   g_object_unref (procedure);
454 
455   /*
456    * gimp-get-color-configuration
457    */
458   procedure = gimp_procedure_new (get_color_configuration_invoker);
459   gimp_object_set_static_name (GIMP_OBJECT (procedure),
460                                "gimp-get-color-configuration");
461   gimp_procedure_set_static_strings (procedure,
462                                      "gimp-get-color-configuration",
463                                      "Get a serialized version of the color management configuration.",
464                                      "Returns a string that can be deserialized into a GimpColorConfig object representing the current color management configuration.",
465                                      "Sven Neumann <sven@gimp.org>",
466                                      "Sven Neumann",
467                                      "2005",
468                                      NULL);
469   gimp_procedure_add_return_value (procedure,
470                                    gimp_param_spec_string ("config",
471                                                            "config",
472                                                            "Serialized color management configuration",
473                                                            FALSE, FALSE, FALSE,
474                                                            NULL,
475                                                            GIMP_PARAM_READWRITE));
476   gimp_pdb_register_procedure (pdb, procedure);
477   g_object_unref (procedure);
478 
479   /*
480    * gimp-get-module-load-inhibit
481    */
482   procedure = gimp_procedure_new (get_module_load_inhibit_invoker);
483   gimp_object_set_static_name (GIMP_OBJECT (procedure),
484                                "gimp-get-module-load-inhibit");
485   gimp_procedure_set_static_strings (procedure,
486                                      "gimp-get-module-load-inhibit",
487                                      "Get the list of modules which should not be loaded.",
488                                      "Returns a copy of the list of modules which should not be loaded.",
489                                      "Spencer Kimball & Peter Mattis",
490                                      "Spencer Kimball & Peter Mattis",
491                                      "1995-1996",
492                                      NULL);
493   gimp_procedure_add_return_value (procedure,
494                                    gimp_param_spec_string ("load-inhibit",
495                                                            "load inhibit",
496                                                            "The list of modules",
497                                                            FALSE, FALSE, FALSE,
498                                                            NULL,
499                                                            GIMP_PARAM_READWRITE));
500   gimp_pdb_register_procedure (pdb, procedure);
501   g_object_unref (procedure);
502 }
503