[libgsf] Fix GParameter deprecation warnings



commit f40e77565bf281adf206903005cb847db07c9bba
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Wed Jan 15 21:19:51 2020 +0400

    Fix GParameter deprecation warnings
    
    Introduce a gsf-priv unit, and implement our own property/params
    functions. Note: there are probably better ways of doing this.
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 gsf/Makefile.am       |   4 +-
 gsf/gsf-outfile-zip.c |  46 +++++++++--------
 gsf/gsf-priv.c        | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gsf/gsf-priv.h        |  53 +++++++++++++++++++
 gsf/gsf-utils.c       |   3 ++
 gsf/gsf-utils.h       |   6 +++
 6 files changed, 231 insertions(+), 21 deletions(-)
---
diff --git a/gsf/Makefile.am b/gsf/Makefile.am
index fb662fc..c8d7c2f 100644
--- a/gsf/Makefile.am
+++ b/gsf/Makefile.am
@@ -24,6 +24,7 @@ endif
 
 libgsf_1_la_SOURCES =          \
        gsf-utils.c             \
+       gsf-priv.c              \
        gsf-libxml.c            \
        gsf-doc-meta-data.c     \
        gsf-docprop-vector.c    \
@@ -134,7 +135,8 @@ libgsf_1_include_HEADERS =  \
 
 noinst_HEADERS = \
        gsf-msole-impl.h        \
-       gsf-zip-impl.h
+       gsf-zip-impl.h          \
+       gsf-priv.h
 
 
 CPP_CFLAGS = -DGLIB_CHECK_VERSION\(x,y,z\)
diff --git a/gsf/gsf-outfile-zip.c b/gsf/gsf-outfile-zip.c
index 0359849..68d71fb 100644
--- a/gsf/gsf-outfile-zip.c
+++ b/gsf/gsf-outfile-zip.c
@@ -25,6 +25,7 @@
 #include <gsf/gsf.h>
 #include <gsf/gsf-zip-impl.h>
 #include <glib/gi18n-lib.h>
+#include "gsf-priv.h"
 
 #include <string.h>
 #include <time.h>
@@ -911,33 +912,38 @@ gsf_outfile_zip_new_child (GsfOutfile *parent,
        GsfOutfileZip *zip_parent = (GsfOutfileZip *)parent;
        GsfOutfileZip *child;
        size_t n_params = 0;
-       GParameter *params = NULL;
+       GsfParam *params = NULL;
        char *display_name;
+       g_autofree const char **names = NULL;
+       g_autofree GValue *values = NULL;
 
        g_return_val_if_fail (zip_parent != NULL, NULL);
        g_return_val_if_fail (zip_parent->vdir, NULL);
        g_return_val_if_fail (zip_parent->vdir->is_directory, NULL);
        g_return_val_if_fail (name && *name, NULL);
 
-       gsf_property_settings_collect (GSF_OUTFILE_ZIP_TYPE,
-                                      &params, &n_params,
-                                      "sink", zip_parent->sink,
-                                      "entry-name", name,
-                                      NULL);
-       gsf_property_settings_collect_valist (GSF_OUTFILE_ZIP_TYPE,
-                                             &params, &n_params,
-                                             first_property_name,
-                                             args);
-       if (!gsf_property_settings_find ("modtime", params, n_params))
-               gsf_property_settings_collect (GSF_OUTFILE_ZIP_TYPE,
-                                              &params, &n_params,
-                                              "modtime", gsf_output_get_modtime (GSF_OUTPUT (parent)),
-                                              NULL);
-
-       child = (GsfOutfileZip *)g_object_newv (GSF_OUTFILE_ZIP_TYPE,
-                                               n_params,
-                                               params);
-       gsf_property_settings_free (params, n_params);
+       gsf_prop_settings_collect (GSF_OUTFILE_ZIP_TYPE,
+                                  &params, &n_params,
+                                  "sink", zip_parent->sink,
+                                  "entry-name", name,
+                                  NULL);
+       gsf_prop_settings_collect_valist (GSF_OUTFILE_ZIP_TYPE,
+                                         &params, &n_params,
+                                         first_property_name,
+                                         args);
+       if (!gsf_prop_settings_find ("modtime", params, n_params))
+               gsf_prop_settings_collect (GSF_OUTFILE_ZIP_TYPE,
+                                          &params, &n_params,
+                                          "modtime", gsf_output_get_modtime (GSF_OUTPUT (parent)),
+                                          NULL);
+
+       gsf_params_to_properties (params, n_params, &names, &values);
+
+       child = (GsfOutfileZip *)g_object_new_with_properties (GSF_OUTFILE_ZIP_TYPE,
+                                                              n_params,
+                                                              names,
+                                                              values);
+       gsf_prop_settings_free (params, n_params);
 
        child->zip64 = zip_parent->zip64;
        child->vdir = gsf_zip_vdir_new (name, is_dir, NULL);
diff --git a/gsf/gsf-priv.c b/gsf/gsf-priv.c
new file mode 100644
index 0000000..e66bf45
--- /dev/null
+++ b/gsf/gsf-priv.c
@@ -0,0 +1,140 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gsf-priv.c:
+ *
+ * Copyright (C) 2002-2006 Jody Goldberg (jody gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2.1 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+
+#include <gsf-config.h>
+#include <gsf/gsf-priv.h>
+#include <gsf/gsf.h>
+
+#include <gobject/gvaluecollector.h>
+#include <glib/gi18n-lib.h>
+
+struct _GsfParam {
+       const gchar *name;
+       GValue       value;
+};
+
+void
+gsf_params_to_properties(GsfParam *params, size_t n_params,
+                        const char ***p_names, GValue **p_values)
+{
+       size_t i;
+       const char **names = g_new(const char *, n_params);
+       GValue *values = g_new(GValue, n_params);
+
+       for (i = 0; i < n_params; i++) {
+               names[i] = params[i].name;
+               values[i] = params[i].value;
+       }
+
+       *p_names = names;
+       *p_values = values;
+}
+
+/* Largely a copy of g_object_new_valist.  */
+void
+gsf_prop_settings_collect_valist (GType object_type,
+                                 GsfParam **p_params,
+                                 size_t *p_n_params,
+                                 const gchar *first_property_name,
+                                 va_list var_args)
+{
+       GObjectClass *class;
+       GsfParam *params = *p_params;
+       const gchar *name;
+       size_t n_params = *p_n_params;
+       size_t n_alloced_params = n_params;  /* We might have more.  */
+
+       g_return_if_fail (G_TYPE_IS_OBJECT (object_type));
+
+       class = g_type_class_ref (object_type);
+
+       name = first_property_name;
+       while (name) {
+               gchar *error = NULL;
+               GParamSpec *pspec = g_object_class_find_property (class, name);
+               if (!pspec) {
+                       g_warning ("%s: object class `%s' has no property named `%s'",
+                                  G_STRFUNC,
+                                  g_type_name (object_type),
+                                  name);
+                       break;
+               }
+
+               if (n_params >= n_alloced_params) {
+                       n_alloced_params += 16;
+                       params = g_renew (GsfParam, params, n_alloced_params);
+               }
+               params[n_params].name = name;
+               params[n_params].value.g_type = 0;
+               g_value_init (&params[n_params].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+               G_VALUE_COLLECT (&params[n_params].value, var_args, 0, &error);
+               if (error) {
+                       g_warning ("%s: %s", G_STRFUNC, error);
+                       g_free (error);
+                       g_value_unset (&params[n_params].value);
+                       break;
+               }
+               n_params++;
+               name = va_arg (var_args, gchar*);
+       }
+
+       g_type_class_unref (class);
+
+       *p_params = params;
+       *p_n_params = n_params;
+}
+
+/* This is a vararg version of gsf_property_settings_collect_valist.  */
+void
+gsf_prop_settings_collect (GType object_type,
+                          GsfParam **p_params,
+                          size_t *p_n_params,
+                          const gchar *first_property_name,
+                          ...)
+{
+       va_list var_args;
+       va_start (var_args, first_property_name);
+       gsf_prop_settings_collect_valist (object_type, p_params, p_n_params, first_property_name, var_args);
+       va_end (var_args);
+}
+
+const GsfParam *
+gsf_prop_settings_find (const char *name,
+                       const GsfParam *params,
+                       size_t n_params)
+{
+       size_t i;
+
+       for (i = 0; i < n_params; i++)
+               if (g_str_equal (name, params[i].name))
+                       return params + i;
+
+       return NULL;
+}
+
+void
+gsf_prop_settings_free (GsfParam *params,
+                       size_t n_params)
+{
+       while (n_params--)
+               g_value_unset (&params[n_params].value);
+       g_free (params);
+}
diff --git a/gsf/gsf-priv.h b/gsf/gsf-priv.h
new file mode 100644
index 0000000..b67c644
--- /dev/null
+++ b/gsf/gsf-priv.h
@@ -0,0 +1,53 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gsf-priv.h:
+ *
+ * Copyright (C) 2002-2006 Jody Goldberg (jody gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2.1 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+
+#ifndef GSF_PRIV_H
+#define GSF_PRIV_H
+
+#include <gsf/gsf-fwd.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GsfParam GsfParam;
+
+void        gsf_params_to_properties(GsfParam *params, size_t n_params,
+                                    const char ***p_names, GValue **p_values);
+
+void        gsf_prop_settings_collect_valist (GType object_type,
+                                                 GsfParam **p_params,
+                                                 size_t *p_n_params,
+                                                 const gchar *first_property_name,
+                                                 va_list var_args);
+void        gsf_prop_settings_collect (GType object_type,
+                                      GsfParam **p_params,
+                                      size_t *p_n_params,
+                                      const gchar *first_property_name,
+                                      ...);
+const GsfParam *gsf_prop_settings_find (const char *name,
+                                       const GsfParam *params,
+                                       size_t n_params);
+void        gsf_prop_settings_free (GsfParam *params,
+                                   size_t n_params);
+
+
+G_END_DECLS
+
+#endif /* GSF_PRIV_H */
diff --git a/gsf/gsf-utils.c b/gsf/gsf-utils.c
index 8906405..1792478 100644
--- a/gsf/gsf-utils.c
+++ b/gsf/gsf-utils.c
@@ -700,6 +700,8 @@ gsf_base64_decode_simple (guint8 *data, size_t len)
 }
 
 
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
 /* Largely a copy of g_object_new_valist.  */
 /**
  * gsf_property_settings_collect_valist:
@@ -819,6 +821,7 @@ gsf_property_settings_free (GParameter *params,
                g_value_unset (&params[n_params].value);
        g_free (params);
 }
+G_GNUC_END_IGNORE_DEPRECATIONS
 
 
 
diff --git a/gsf/gsf-utils.h b/gsf/gsf-utils.h
index 359c445..ab4d0c2 100644
--- a/gsf/gsf-utils.h
+++ b/gsf/gsf-utils.h
@@ -299,21 +299,27 @@ extern int libgsf_micro_version;
 char const *gsf_extension_pointer (char const * path);
 void       gsf_iconv_close (GIConv handle);
 
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+G_DEPRECATED
 void        gsf_property_settings_collect_valist (GType object_type,
                                                  GParameter **p_params,
                                                  size_t *p_n_params,
                                                  const gchar *first_property_name,
                                                  va_list var_args);
+G_DEPRECATED
 void        gsf_property_settings_collect (GType object_type,
                                           GParameter **p_params,
                                           size_t *p_n_params,
                                           const gchar *first_property_name,
                                           ...);
+G_DEPRECATED
 const GParameter *gsf_property_settings_find (const char *name,
                                              const GParameter *params,
                                              size_t n_params);
+G_DEPRECATED
 void        gsf_property_settings_free (GParameter *params,
                                        size_t n_params);
+G_GNUC_END_IGNORE_DEPRECATIONS
 
 
 


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