From 631110e061788a2271440199477e8f881548ab84 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 12 Sep 2016 23:51:29 +0200 Subject: [PATCH] app: merge units.[ch] into core/gimp-units.[ch] and initialize units in gimp_init(). This was completely over-engineered but in the end boils down to a bad hack that needs a static "the_unit_gimp" pointer anyway, so let's at least have the hacks in one file. --- app/Makefile.am | 2 - app/app.c | 3 - app/core/gimp-units.c | 110 +++++++++++++++++++++++++++++++ app/core/gimp.c | 3 +- app/main.c | 5 +- app/tests.c | 5 +- app/units.c | 146 ------------------------------------------ app/units.h | 30 --------- 8 files changed, 114 insertions(+), 190 deletions(-) delete mode 100644 app/units.c delete mode 100644 app/units.h diff --git a/app/Makefile.am b/app/Makefile.am index 63292ad7d6..38bceb9a9b 100644 --- a/app/Makefile.am +++ b/app/Makefile.am @@ -59,8 +59,6 @@ libapp_sources = \ tests.h \ unique.c \ unique.h \ - units.c \ - units.h \ version.c \ version.h \ gimp-debug.c \ diff --git a/app/app.c b/app/app.c index 8438c9710d..dbbf471741 100644 --- a/app/app.c +++ b/app/app.c @@ -61,7 +61,6 @@ #include "app.h" #include "errors.h" -#include "units.h" #include "language.h" #include "gimp-debug.h" @@ -210,8 +209,6 @@ app_run (const gchar *full_prog_name, errors_init (gimp, full_prog_name, use_debug_handler, stack_trace_mode); - units_init (gimp); - /* Check if the user's gimp_directory exists */ gimpdir = gimp_directory_file (NULL); diff --git a/app/core/gimp-units.c b/app/core/gimp-units.c index 0c5b5d5627..409f0c18b1 100644 --- a/app/core/gimp-units.c +++ b/app/core/gimp-units.c @@ -27,6 +27,7 @@ #include #include "libgimpbase/gimpbase.h" +#include "libgimpbase/gimpbase-private.h" #include "libgimpconfig/gimpconfig.h" #include "core-types.h" @@ -49,10 +50,119 @@ static GTokenType gimp_unitrc_unit_info_deserialize (GScanner *scanner, Gimp *gimp); +static Gimp *the_unit_gimp = NULL; + + +static gint +gimp_units_get_number_of_units (void) +{ + return _gimp_unit_get_number_of_units (the_unit_gimp); +} + +static gint +gimp_units_get_number_of_built_in_units (void) +{ + return GIMP_UNIT_END; +} + +static GimpUnit +gimp_units_unit_new (gchar *identifier, + gdouble factor, + gint digits, + gchar *symbol, + gchar *abbreviation, + gchar *singular, + gchar *plural) +{ + return _gimp_unit_new (the_unit_gimp, + identifier, + factor, + digits, + symbol, + abbreviation, + singular, + plural); +} + +static gboolean +gimp_units_unit_get_deletion_flag (GimpUnit unit) +{ + return _gimp_unit_get_deletion_flag (the_unit_gimp, unit); +} + +static void +gimp_units_unit_set_deletion_flag (GimpUnit unit, + gboolean deletion_flag) +{ + _gimp_unit_set_deletion_flag (the_unit_gimp, unit, deletion_flag); +} + +static gdouble +gimp_units_unit_get_factor (GimpUnit unit) +{ + return _gimp_unit_get_factor (the_unit_gimp, unit); +} + +static gint +gimp_units_unit_get_digits (GimpUnit unit) +{ + return _gimp_unit_get_digits (the_unit_gimp, unit); +} + +static const gchar * +gimp_units_unit_get_identifier (GimpUnit unit) +{ + return _gimp_unit_get_identifier (the_unit_gimp, unit); +} + +static const gchar * +gimp_units_unit_get_symbol (GimpUnit unit) +{ + return _gimp_unit_get_symbol (the_unit_gimp, unit); +} + +static const gchar * +gimp_units_unit_get_abbreviation (GimpUnit unit) +{ + return _gimp_unit_get_abbreviation (the_unit_gimp, unit); +} + +static const gchar * +gimp_units_unit_get_singular (GimpUnit unit) +{ + return _gimp_unit_get_singular (the_unit_gimp, unit); +} + +static const gchar * +gimp_units_unit_get_plural (GimpUnit unit) +{ + return _gimp_unit_get_plural (the_unit_gimp, unit); +} + void gimp_units_init (Gimp *gimp) { + GimpUnitVtable vtable; + g_return_if_fail (GIMP_IS_GIMP (gimp)); + g_return_if_fail (the_unit_gimp == NULL); + + the_unit_gimp = gimp; + + vtable.unit_get_number_of_units = gimp_units_get_number_of_units; + vtable.unit_get_number_of_built_in_units = gimp_units_get_number_of_built_in_units; + vtable.unit_new = gimp_units_unit_new; + vtable.unit_get_deletion_flag = gimp_units_unit_get_deletion_flag; + vtable.unit_set_deletion_flag = gimp_units_unit_set_deletion_flag; + vtable.unit_get_factor = gimp_units_unit_get_factor; + vtable.unit_get_digits = gimp_units_unit_get_digits; + vtable.unit_get_identifier = gimp_units_unit_get_identifier; + vtable.unit_get_symbol = gimp_units_unit_get_symbol; + vtable.unit_get_abbreviation = gimp_units_unit_get_abbreviation; + vtable.unit_get_singular = gimp_units_unit_get_singular; + vtable.unit_get_plural = gimp_units_unit_get_plural; + + gimp_base_init (&vtable); gimp->user_units = NULL; gimp->n_user_units = 0; diff --git a/app/core/gimp.c b/app/core/gimp.c index 9db4428fbc..817f9adc51 100644 --- a/app/core/gimp.c +++ b/app/core/gimp.c @@ -230,6 +230,8 @@ gimp_init (Gimp *gimp) gimp->parasites = gimp_parasite_list_new (); + gimp_units_init (gimp); + gimp->images = gimp_list_new_weak (GIMP_TYPE_IMAGE, FALSE); gimp_object_set_static_name (GIMP_OBJECT (gimp->images), "images"); @@ -268,7 +270,6 @@ gimp_constructed (GObject *object) G_OBJECT_CLASS (parent_class)->constructed (object); - gimp_units_init (gimp); gimp_modules_init (gimp); gimp->plug_in_manager = gimp_plug_in_manager_new (gimp); diff --git a/app/main.c b/app/main.c index 016f92530e..5892bb0369 100644 --- a/app/main.c +++ b/app/main.c @@ -68,7 +68,6 @@ #include "sanity.h" #include "signals.h" #include "unique.h" -#include "units.h" #include "version.h" #ifdef G_OS_WIN32 @@ -716,10 +715,8 @@ gimp_option_dump_gimprc (const gchar *option_name, Gimp *gimp; gboolean success; - gimp = g_object_new (GIMP_TYPE_GIMP, NULL); - - units_init (gimp); babl_init (); + gimp = g_object_new (GIMP_TYPE_GIMP, NULL); success = gimp_config_dump (format); diff --git a/app/tests.c b/app/tests.c index 889afe3fa3..d822c30fc5 100644 --- a/app/tests.c +++ b/app/tests.c @@ -41,7 +41,6 @@ #include "gimp-log.h" #include "tests.h" -#include "units.h" static void @@ -69,8 +68,6 @@ gimp_init_for_testing (void) FALSE, FALSE, TRUE, FALSE, GIMP_STACK_TRACE_QUERY, GIMP_PDB_COMPAT_OFF); - units_init (gimp); - gimp_load_config (gimp, NULL, NULL); gimp_gegl_init (gimp); @@ -124,8 +121,8 @@ gimp_init_for_gui_testing_internal (gboolean show_gui, gimp = gimp_new ("Unit Tested GIMP", NULL, NULL, FALSE, TRUE, TRUE, !show_gui, FALSE, FALSE, TRUE, FALSE, GIMP_STACK_TRACE_QUERY, GIMP_PDB_COMPAT_OFF); + gimp_set_show_gui (gimp, show_gui); - units_init (gimp); gimp_load_config (gimp, gimprc, NULL); gimp_gegl_init (gimp); gui_init (gimp, TRUE); diff --git a/app/units.c b/app/units.c deleted file mode 100644 index 434298403e..0000000000 --- a/app/units.c +++ /dev/null @@ -1,146 +0,0 @@ -/* GIMP - The GNU 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 3 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, see . - */ - -#include "config.h" - -#include - -#include "libgimpbase/gimpbase.h" -#include "libgimpbase/gimpbase-private.h" - -#include "core/core-types.h" - -#include "core/gimp.h" -#include "core/gimpunit.h" - -#include "units.h" - - -static Gimp *the_unit_gimp = NULL; - - -static gint -units_get_number_of_units (void) -{ - return _gimp_unit_get_number_of_units (the_unit_gimp); -} - -static gint -units_get_number_of_built_in_units (void) -{ - return GIMP_UNIT_END; -} - -static GimpUnit -units_unit_new (gchar *identifier, - gdouble factor, - gint digits, - gchar *symbol, - gchar *abbreviation, - gchar *singular, - gchar *plural) -{ - return _gimp_unit_new (the_unit_gimp, - identifier, - factor, - digits, - symbol, - abbreviation, - singular, - plural); -} - -static gboolean -units_unit_get_deletion_flag (GimpUnit unit) -{ - return _gimp_unit_get_deletion_flag (the_unit_gimp, unit); -} - -static void -units_unit_set_deletion_flag (GimpUnit unit, - gboolean deletion_flag) -{ - _gimp_unit_set_deletion_flag (the_unit_gimp, unit, deletion_flag); -} - -static gdouble -units_unit_get_factor (GimpUnit unit) -{ - return _gimp_unit_get_factor (the_unit_gimp, unit); -} - -static gint -units_unit_get_digits (GimpUnit unit) -{ - return _gimp_unit_get_digits (the_unit_gimp, unit); -} - -static const gchar * -units_unit_get_identifier (GimpUnit unit) -{ - return _gimp_unit_get_identifier (the_unit_gimp, unit); -} - -static const gchar * -units_unit_get_symbol (GimpUnit unit) -{ - return _gimp_unit_get_symbol (the_unit_gimp, unit); -} - -static const gchar * -units_unit_get_abbreviation (GimpUnit unit) -{ - return _gimp_unit_get_abbreviation (the_unit_gimp, unit); -} - -static const gchar * -units_unit_get_singular (GimpUnit unit) -{ - return _gimp_unit_get_singular (the_unit_gimp, unit); -} - -static const gchar * -units_unit_get_plural (GimpUnit unit) -{ - return _gimp_unit_get_plural (the_unit_gimp, unit); -} - -void -units_init (Gimp *gimp) -{ - GimpUnitVtable vtable; - - g_return_if_fail (GIMP_IS_GIMP (gimp)); - g_return_if_fail (the_unit_gimp == NULL); - - the_unit_gimp = gimp; - - vtable.unit_get_number_of_units = units_get_number_of_units; - vtable.unit_get_number_of_built_in_units = units_get_number_of_built_in_units; - vtable.unit_new = units_unit_new; - vtable.unit_get_deletion_flag = units_unit_get_deletion_flag; - vtable.unit_set_deletion_flag = units_unit_set_deletion_flag; - vtable.unit_get_factor = units_unit_get_factor; - vtable.unit_get_digits = units_unit_get_digits; - vtable.unit_get_identifier = units_unit_get_identifier; - vtable.unit_get_symbol = units_unit_get_symbol; - vtable.unit_get_abbreviation = units_unit_get_abbreviation; - vtable.unit_get_singular = units_unit_get_singular; - vtable.unit_get_plural = units_unit_get_plural; - - gimp_base_init (&vtable); -} diff --git a/app/units.h b/app/units.h deleted file mode 100644 index 03af44dee5..0000000000 --- a/app/units.h +++ /dev/null @@ -1,30 +0,0 @@ -/* GIMP - The GNU 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 3 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, see . - */ - -#ifndef __UNITS_H__ -#define __UNITS_H__ - - -#ifndef GIMP_APP_GLUE_COMPILATION -#error You must not #include "units.h" from an app/ subdir -#endif - - -void units_init (Gimp *gimp); - - -#endif /* __UNITS_H__ */