[gimp] plug-ins: port web-browser to GimpPlugIn



commit 605f349137b651ba12fd2a03f53ccbb4a566d060
Author: Michael Natterer <mitch gimp org>
Date:   Tue Aug 27 19:28:40 2019 +0200

    plug-ins: port web-browser to GimpPlugIn

 plug-ins/common/Makefile.am    |   2 +-
 plug-ins/common/plugin-defs.pl |   2 +-
 plug-ins/common/web-browser.c  | 149 +++++++++++++++++++++++++----------------
 3 files changed, 92 insertions(+), 61 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 5fe9d8f005..fab2cc15ca 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -1598,7 +1598,7 @@ wavelet_decompose_LDADD = \
 
 web_browser_LDFLAGS = $(framework_cocoa)
 
-web_browser_CPPFLAGS = $(AM_CPPFLAGS) $(xobjective_c) -DGIMP_DEPRECATED_REPLACE_NEW_API
+web_browser_CPPFLAGS = $(AM_CPPFLAGS) $(xobjective_c)
 
 web_browser_SOURCES = \
        web-browser.c
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 9960b79eec..51d8535d07 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -72,6 +72,6 @@
     'van-gogh-lic' => { ui => 1, gegl => 1, old_api => 1 },
     'warp' => { ui => 1, gegl => 1, old_api => 1 },
     'wavelet-decompose' => { ui => 1, gegl => 1, old_api => 1 },
-    'web-browser' => { ui => 1, ldflags => '$(framework_cocoa)', cppflags => '$(AM_CPPFLAGS) 
$(xobjective_c)', old_api => 1 },
+    'web-browser' => { ui => 1, ldflags => '$(framework_cocoa)', cppflags => '$(AM_CPPFLAGS) 
$(xobjective_c)' },
     'web-page' => { ui => 1, optional => 1, libs => 'WEBKIT_LIBS', cflags => 'WEBKIT_CFLAGS' }
 );
diff --git a/plug-ins/common/web-browser.c b/plug-ins/common/web-browser.c
index 3270d2d1e5..eabf07ec5f 100644
--- a/plug-ins/common/web-browser.c
+++ b/plug-ins/common/web-browser.c
@@ -43,84 +43,115 @@
 #define PLUG_IN_ROLE   "gimp-web-browser"
 
 
-static void     query            (void);
-static void     run              (const gchar      *name,
-                                  gint              nparams,
-                                  const GimpParam  *param,
-                                  gint             *nreturn_vals,
-                                  GimpParam       **return_vals);
-static gboolean browser_open_url (GtkWindow        *window,
-                                  const gchar      *url,
-                                  GError          **error);
-
-const GimpPlugInInfo PLUG_IN_INFO =
+typedef struct _Browser      Browser;
+typedef struct _BrowserClass BrowserClass;
+
+struct _Browser
+{
+  GimpPlugIn parent_instance;
+};
+
+struct _BrowserClass
 {
-  NULL,  /* init_proc  */
-  NULL,  /* quit_proc  */
-  query, /* query_proc */
-  run    /* run_proc   */
+  GimpPlugInClass parent_class;
 };
 
 
-MAIN ()
+#define BROWSER_TYPE  (browser_get_type ())
+#define BROWSER (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BROWSER_TYPE, Browser))
+
+GType                   browser_get_type         (void) G_GNUC_CONST;
+
+static GList          * browser_query_procedures (GimpPlugIn           *plug_in);
+static GimpProcedure  * browser_create_procedure (GimpPlugIn           *plug_in,
+                                                  const gchar          *name);
+
+static GimpValueArray * browser_run              (GimpProcedure        *procedure,
+                                                  const GimpValueArray *args,
+                                                  gpointer              run_data);
+
+static gboolean         browser_open_url         (GtkWindow            *window,
+                                                  const gchar          *url,
+                                                  GError              **error);
+
+
+G_DEFINE_TYPE (Browser, browser, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (BROWSER_TYPE)
+
 
 static void
-query (void)
+browser_class_init (BrowserClass *klass)
 {
-  static const GimpParamDef args[] =
-  {
-    { GIMP_PDB_STRING, "url", "URL to open" }
-  };
-
-  gimp_install_procedure (PLUG_IN_PROC,
-                          "Open an URL in the user specified web browser",
-                          "Opens the given URL in the user specified web browser.",
-                          "Henrik Brix Andersen <brix gimp org>",
-                          "2003",
-                          "2003/09/16",
-                          NULL, NULL,
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (args), 0,
-                          args, NULL);
+  GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+
+  plug_in_class->query_procedures = browser_query_procedures;
+  plug_in_class->create_procedure = browser_create_procedure;
 }
 
 static void
-run (const gchar      *name,
-     gint             nparams,
-     const GimpParam  *param,
-     gint             *nreturn_vals,
-     GimpParam       **return_vals)
+browser_init (Browser *browser)
 {
-  static GimpParam   values[2];
-  GimpPDBStatusType  status;
-  GError            *error = NULL;
-
-  *nreturn_vals = 1;
-  *return_vals  = values;
+}
 
-  status   = GIMP_PDB_SUCCESS;
+static GList *
+browser_query_procedures (GimpPlugIn *plug_in)
+{
+  return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
+}
 
-  INIT_I18N ();
+static GimpProcedure *
+browser_create_procedure (GimpPlugIn  *plug_in,
+                          const gchar *name)
+{
+  GimpProcedure *procedure = NULL;
 
-  if (nparams == 1 &&
-      param[0].data.d_string != NULL &&
-      strlen (param[0].data.d_string))
+  if (! strcmp (name, PLUG_IN_PROC))
     {
-      if (! browser_open_url (NULL, param[0].data.d_string, &error))
-        {
-          status                  = GIMP_PDB_EXECUTION_ERROR;
-          *nreturn_vals           = 2;
-          values[1].type          = GIMP_PDB_STRING;
-          values[1].data.d_string = error->message;
-        }
+      procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                      browser_run, NULL, NULL);
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Open an URL in the user specified "
+                                        "web browser",
+                                        "Opens the given URL in the user "
+                                        "specified web browser.",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "Henrik Brix Andersen <brix gimp org>",
+                                      "2003",
+                                      "2003/09/16");
+
+      GIMP_PROC_ARG_STRING (procedure, "url",
+                            "URL",
+                            "URL to open",
+                            "http://www.gimp.org/";,
+                            G_PARAM_READWRITE);
     }
-  else
+
+  return procedure;
+}
+
+static GimpValueArray *
+browser_run (GimpProcedure        *procedure,
+             const GimpValueArray *args,
+             gpointer              run_data)
+{
+  GError *error = NULL;
+
+  INIT_I18N ();
+
+  if (! browser_open_url (NULL, GIMP_VALUES_GET_STRING (args, 0),
+                          &error))
     {
-      status = GIMP_PDB_CALLING_ERROR;
+      return gimp_procedure_new_return_values (procedure,
+                                               GIMP_PDB_EXECUTION_ERROR,
+                                               error);
     }
 
-  values[0].type          = GIMP_PDB_STATUS;
-  values[0].data.d_status = status;
+  return gimp_procedure_new_return_values (procedure,
+                                           GIMP_PDB_SUCCESS,
+                                           NULL);
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]