Commit 3bd3300d authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

libgimpbase/Makefile.am added new function gimp_plug_in_directory() to

2001-12-10  Sven Neumann  <sven@gimp.org>

	* libgimpbase/Makefile.am
	* libgimpbase/gimpenv.[ch]: added new function gimp_plug_in_directory()
	to retrieve the compile_time defined plug_in directory. Declared some
	functions G_GNUC_CONST and simplified code by introducing a helper
	function.

	* app/config/Makefile.am
	* app/config/gimpcoreconfig.[ch]: started to implement GimpCoreConfig
	derived from GimpBaseConfig.

	* app/config/gimpbaseconfig.[ch]: misc small changes.

	* app/config/gimpconfig-deserialize.c
	(gimp_config_deserialize_properties): return quietly if there are no
	properties.

	* app/config/gimpconfig-substitute.c: more special cases.

	* app/config/test-config.c: test GimpCoreConfig.
parent 49e4062e
2001-12-10 Sven Neumann <sven@gimp.org>
* libgimpbase/Makefile.am
* libgimpbase/gimpenv.[ch]: added new function gimp_plug_in_directory()
to retrieve the compile_time defined plug_in directory. Declared some
functions G_GNUC_CONST and simplified code by introducing a helper
function.
* app/config/Makefile.am
* app/config/gimpcoreconfig.[ch]: started to implement GimpCoreConfig
derived from GimpBaseConfig.
* app/config/gimpbaseconfig.[ch]: misc small changes.
* app/config/gimpconfig-deserialize.c
(gimp_config_deserialize_properties): return quietly if there are no
properties.
* app/config/gimpconfig-substitute.c: more special cases.
* app/config/test-config.c: test GimpCoreConfig.
2001-12-10 Sven Neumann <sven@gimp.org>
* app/config/Makefile.am
......
......@@ -18,6 +18,8 @@ libappconfig_a_SOURCES = @STRIP_BEGIN@ \
gimpconfig-types.h \
gimpbaseconfig.c \
gimpbaseconfig.h \
gimpcoreconfig.c \
gimpcoreconfig.h \
@STRIP_END@
AM_CPPFLAGS = @STRIP_BEGIN@ \
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpBaseConfig class
* Copyright (C) 2001 Sven Neumann <sven@gimp.org>
*
* 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
......@@ -64,8 +67,8 @@ gimp_base_config_get_type (void)
static const GTypeInfo config_info =
{
sizeof (GimpBaseConfigClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_base_config_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
......@@ -73,16 +76,14 @@ gimp_base_config_get_type (void)
0, /* n_preallocs */
NULL /* instance_init */
};
static const GInterfaceInfo config_iface_info =
{
NULL, /* iface_init */
NULL, /* iface_finalize */
NULL /* iface_data */
};
static const GInterfaceInfo config_iface_info = { NULL, NULL, NULL };
config_type = g_type_register_static (G_TYPE_OBJECT, "GimpBaseConfig",
config_type = g_type_register_static (G_TYPE_OBJECT,
"GimpBaseConfig",
&config_info, 0);
g_type_add_interface_static (config_type, GIMP_TYPE_CONFIG_INTERFACE,
g_type_add_interface_static (config_type,
GIMP_TYPE_CONFIG_INTERFACE,
&config_iface_info);
}
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpBaseConfig class
* Copyright (C) 2001 Sven Neumann <sven@gimp.org>
*
* 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
......
......@@ -86,7 +86,8 @@ gimp_config_deserialize_properties (GObject *object,
klass = G_OBJECT_GET_CLASS (object);
property_specs = g_object_class_list_properties (klass, &n_property_specs);
g_return_val_if_fail (property_specs != NULL && n_property_specs > 0, FALSE);
if (!property_specs)
return TRUE;
scope_id = g_quark_from_static_string ("gimp_config_deserialize_properties");
old_scope_id = g_scanner_set_scope (scanner, scope_id);
......
......@@ -72,9 +72,20 @@ gimp_config_substitute_path (GObject *object,
if (!subst && use_env)
{
if (strcmp (token, "gimp_dir") == 0)
if (!subst && strcmp (token, "gimp_dir") == 0)
subst = gimp_directory ();
if (!subst && strcmp (token, "gimp_datadir") == 0)
subst = gimp_data_directory ();
if (!subst &&
((strcmp (token, "gimp_plug_in_dir")) == 0 ||
(strcmp (token, "gimp_plugin_dir")) == 0))
subst = gimp_plug_in_directory ();
if (!subst && strcmp (token, "gimp_sysconfdir") == 0)
subst = gimp_sysconf_directory ();
if (!subst)
subst = g_getenv (token);
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpCoreConfig class
* Copyright (C) 2001 Sven Neumann <sven@gimp.org>
*
* 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>
#include "core/core-enums.h"
#include "gimpconfig.h"
#include "gimpconfig-params.h"
#include "gimpconfig-types.h"
#include "gimpcoreconfig.h"
#define BUILD_PLUG_IN_PATH(name)\
("${gimp_dir}" G_DIR_SEPARATOR_S name G_SEARCHPATH_SEPARATOR_S \
"${gimp_plugin_dir}" G_DIR_SEPARATOR_S name)
#define BUILD_DATA_PATH(name)\
("${gimp_dir}" G_DIR_SEPARATOR_S name G_SEARCHPATH_SEPARATOR_S \
"${gimp_datadir}" G_DIR_SEPARATOR_S name)
static void gimp_core_config_class_init (GimpCoreConfigClass *klass);
static void gimp_core_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_core_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
enum
{
PROP_0,
PROP_PLUG_IN_PATH,
PROP_MODULE_PATH,
PROP_BRUSH_PATH,
PROP_PATTERN_PATH,
PROP_PALETTE_PATH,
PROP_GRADIENT_PATH
};
static GObjectClass *parent_class = NULL;
GType
gimp_core_config_get_type (void)
{
static GType config_type = 0;
if (! config_type)
{
static const GTypeInfo config_info =
{
sizeof (GimpCoreConfigClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_core_config_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpCoreConfig),
0, /* n_preallocs */
NULL /* instance_init */
};
config_type = g_type_register_static (GIMP_TYPE_BASE_CONFIG,
"GimpCoreConfig",
&config_info, 0);
}
return config_type;
}
static void
gimp_core_config_class_init (GimpCoreConfigClass *klass)
{
GObjectClass *object_class;
parent_class = g_type_class_peek_parent (klass);
object_class = G_OBJECT_CLASS (klass);
object_class->set_property = gimp_core_config_set_property;
object_class->get_property = gimp_core_config_get_property;
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PLUG_IN_PATH,
"plug-in-path",
BUILD_PLUG_IN_PATH ("plug-ins"));
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_MODULE_PATH,
"module-path",
BUILD_PLUG_IN_PATH ("modules"));
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_BRUSH_PATH,
"brush-path",
BUILD_DATA_PATH ("brushes"));
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PATTERN_PATH,
"pattern-path",
BUILD_DATA_PATH ("patterns"));
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PALETTE_PATH,
"palette-path",
BUILD_DATA_PATH ("palettes"));
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_GRADIENT_PATH,
"gradient-path",
BUILD_DATA_PATH ("gradients"));
}
static void
gimp_core_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpCoreConfig *core_config;
core_config = GIMP_CORE_CONFIG (object);
switch (property_id)
{
case PROP_PLUG_IN_PATH:
g_free (core_config->plug_in_path);
core_config->plug_in_path = g_value_dup_string (value);
break;
case PROP_MODULE_PATH:
g_free (core_config->module_path);
core_config->module_path = g_value_dup_string (value);
break;
case PROP_BRUSH_PATH:
g_free (core_config->brush_path);
core_config->brush_path = g_value_dup_string (value);
break;
case PROP_PATTERN_PATH:
g_free (core_config->pattern_path);
core_config->pattern_path = g_value_dup_string (value);
break;
case PROP_PALETTE_PATH:
g_free (core_config->palette_path);
core_config->palette_path = g_value_dup_string (value);
break;
case PROP_GRADIENT_PATH:
g_free (core_config->gradient_path);
core_config->gradient_path = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_core_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpCoreConfig *core_config;
core_config = GIMP_CORE_CONFIG (object);
switch (property_id)
{
case PROP_PLUG_IN_PATH:
g_value_set_string (value, core_config->plug_in_path);
break;
case PROP_MODULE_PATH:
g_value_set_string (value, core_config->module_path);
break;
case PROP_BRUSH_PATH:
g_value_set_string (value, core_config->brush_path);
break;
case PROP_PATTERN_PATH:
g_value_set_string (value, core_config->pattern_path);
break;
case PROP_PALETTE_PATH:
g_value_set_string (value, core_config->palette_path);
break;
case PROP_GRADIENT_PATH:
g_value_set_string (value, core_config->gradient_path);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpCoreConfig class
* Copyright (C) 2001 Sven Neumann <sven@gimp.org>
*
* 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.
*/
#ifndef __GIMP_CORE_CONFIG_H__
#define __GIMP_CORE_CONFIG_H__
#include "core/core-enums.h"
#include "gimpbaseconfig.h"
#define GIMP_TYPE_CORE_CONFIG (gimp_core_config_get_type ())
#define GIMP_CORE_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CORE_CONFIG, GimpCoreConfig))
#define GIMP_CORE_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CORE_CONFIG, GimpCoreConfigClass))
#define GIMP_IS_CORE_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CORE_CONFIG))
#define GIMP_IS_CORE_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CORE_CONFIG))
typedef struct _GimpCoreConfig GimpCoreConfig;
typedef struct _GimpCoreConfigClass GimpCoreConfigClass;
struct _GimpCoreConfig
{
GimpBaseConfig parent_instance;
gchar *plug_in_path;
gchar *module_path;
gchar *brush_path;
gchar *pattern_path;
gchar *palette_path;
gchar *gradient_path;
};
struct _GimpCoreConfigClass
{
GimpBaseConfigClass parent_class;
};
GType gimp_core_config_get_type (void) G_GNUC_CONST;
#endif /* GIMP_CORE_CONFIG_H__ */
......@@ -24,9 +24,8 @@
#include <glib-object.h>
#include "gimpconfig.h"
#include "gimpbaseconfig.h"
#include "gimpcoreconfig.h"
#define FILENAME "foorc"
static void notify_callback (GObject *object,
GParamSpec *pspec);
......@@ -40,29 +39,33 @@ main (int argc,
char *argv[])
{
GimpBaseConfig *config;
gboolean header = TRUE;
const gchar *filename = "foorc";
gboolean header = TRUE;
g_type_init ();
g_print ("Testing GimpConfig ...\n");
config = g_object_new (GIMP_TYPE_BASE_CONFIG, NULL);
config = g_object_new (GIMP_TYPE_CORE_CONFIG, NULL);
g_print (" Serializing default properties of GimpBaseConfig to '"
FILENAME "' ...\n");
gimp_config_serialize (G_OBJECT (config), FILENAME);
g_print (" Serializing default properties of %s to '%s' ...\n",
g_type_name (G_TYPE_FROM_INSTANCE (config)), filename);
g_print (" Deserializing from '" FILENAME "' ...\n");
gimp_config_serialize (G_OBJECT (config), filename);
g_print (" Deserializing from '%s' ...\n", filename);
g_signal_connect (G_OBJECT (config), "notify",
G_CALLBACK (notify_callback),
NULL);
gimp_config_deserialize (G_OBJECT (config), FILENAME, TRUE);
gimp_config_deserialize (G_OBJECT (config), filename, TRUE);
gimp_config_foreach_unknown_token (G_OBJECT (config),
output_unknown_token, &header);
g_object_unref (config);
g_print ("Done.\n");
......@@ -89,17 +92,14 @@ notify_callback (GObject *object,
g_value_init (&dest, G_TYPE_STRING);
g_value_transform (&src, &dest);
g_print (" %s::%s -> %s\n",
g_type_name (G_TYPE_FROM_INSTANCE (object)), pspec->name,
g_value_get_string (&dest));
g_print (" %s -> %s\n", pspec->name, g_value_get_string (&dest));
g_value_unset (&src);
g_value_unset (&dest);
}
else
{
g_print (" %s::%s changed\n",
g_type_name (G_TYPE_FROM_INSTANCE (object)), pspec->name);
g_print (" %s changed\n", pspec->name);
}
}
......
......@@ -5,6 +5,7 @@ libgimpbaseincludedir = $(includedir)/gimp-$(LT_RELEASE)/libgimpbase
AM_CPPFLAGS = @STRIP_BEGIN@ \
-DGIMPDIR=\""$(gimpdir)"\" \
-DDATADIR=\""$(gimpdatadir)"\" \
-DPLUGINDIR=\""$(gimpplugindir)"\" \
-DSYSCONFDIR=\""$(gimpsysconfdir)"\" \
-DG_LOG_DOMAIN=\"LibGimpBase\" \
@GIMP_THREAD_FLAGS@ \
......
......@@ -57,6 +57,9 @@
extern const char *__XOS2RedirRoot(const char *);
#endif
static gchar * gimp_env_get_dir (const gchar *gimp_env_name,
const gchar *env_dir);
/**
* gimp_directory:
*
......@@ -87,7 +90,7 @@ gimp_directory (void)
const gchar *env_gimp_dir;
const gchar *home_dir;
if (gimp_dir != NULL)
if (gimp_dir)
return gimp_dir;
env_gimp_dir = g_getenv ("GIMP_DIRECTORY");
......@@ -120,7 +123,7 @@ gimp_directory (void)
gimp_dir = g_strdup(__XOS2RedirRoot(GIMPDIR));
return gimp_dir;
#endif
if (NULL != home_dir)
if (home_dir)
{
gimp_dir = g_build_filename (home_dir, GIMPDIR, NULL);
}
......@@ -175,61 +178,11 @@ gimp_data_directory (void)
{
static gchar *gimp_data_dir = NULL;
const gchar *env_gimp_data_dir;
if (gimp_data_dir != NULL)
if (gimp_data_dir)
return gimp_data_dir;
env_gimp_data_dir = g_getenv ("GIMP_DATADIR");
if (NULL != env_gimp_data_dir)
{
if (!g_path_is_absolute (env_gimp_data_dir))
g_error ("GIMP_DATADIR environment variable should be an absolute path.");
#ifndef __EMX__
gimp_data_dir = g_strdup (env_gimp_data_dir);
#else
gimp_data_dir = g_strdup (__XOS2RedirRoot(env_gimp_data_dir));
#endif
}
else
{
#ifndef G_OS_WIN32
#ifndef __EMX__
gimp_data_dir = DATADIR;
#else
gimp_data_dir = g_strdup(__XOS2RedirRoot(DATADIR));
#endif
#else
/* Figure it out from the executable name */
gchar filename[MAX_PATH];
gchar *sep1, *sep2;
if (GetModuleFileName (NULL, filename, sizeof (filename)) == 0)
g_error ("GetModuleFilename failed\n");
/* If the executable file name is of the format
* <foobar>\bin\gimp.exe of <foobar>\plug-ins\filter.exe, * use
* <foobar>. Otherwise, use the directory where the executable
* is.
*/
sep1 = strrchr (filename, G_DIR_SEPARATOR);
*sep1 = '\0';
sep2 = strrchr (filename, G_DIR_SEPARATOR);
if (sep2 != NULL)
{
if (g_strcasecmp (sep2 + 1, "bin") == 0
|| g_strcasecmp (sep2 + 1, "plug-ins") == 0)
*sep2 = '\0';
}
gimp_data_dir = gimp_env_get_dir ("GIMP_DATADIR", DATADIR);
gimp_data_dir = g_strdup (filename);
#endif
}
return gimp_data_dir;
}
......@@ -252,62 +205,39 @@ gimp_sysconf_directory (void)
{
static gchar *gimp_sysconf_dir = NULL;
const gchar *env_gimp_sysconf_dir;
if (gimp_sysconf_dir != NULL)
return gimp_sysconf_dir;
env_gimp_sysconf_dir = g_getenv ("GIMP_SYSCONFDIR");
gimp_sysconf_dir = gimp_env_get_dir ("GIMP_SYSCONFDIR", SYSCONFDIR);
if (NULL != env_gimp_sysconf_dir)
{
if (! g_path_is_absolute (env_gimp_sysconf_dir))
g_error ("GIMP_SYSCONFDIR environment variable should be an absolute path.");
#ifndef __EMX__
gimp_sysconf_dir = g_strdup (env_gimp_sysconf_dir);
#else
gimp_sysconf_dir = g_strdup (__XOS2RedirRoot (env_gimp_sysconf_dir));
#endif
}
else
{
#ifndef G_OS_WIN32
#ifndef __EMX__
gimp_sysconf_dir = SYSCONFDIR;
#else
gimp_sysconf_dir = g_strdup (__XOS2RedirRoot(SYSCONFDIR));
#endif
#else
/* Figure it out from the executable name */
gchar filename[MAX_PATH];
gchar *sep1, *sep2;
if (GetModuleFileName (NULL, filename, sizeof (filename)) == 0)
g_error ("GetModuleFilename failed\n");
/* If the executable file name is of the format
* <foobar>\bin\gimp.exe or <foobar>\plug-ins\filter.exe, use
* <foobar>. Otherwise, use the directory where the executable
* is.
*/
sep1 = strrchr (filename, G_DIR_SEPARATOR);
return gimp_sysconf_dir;
}
*sep1 = '\0';
/**
* gimp_plug_in_directory:
*
* Returns the top directory for GIMP plug_ins and modules. If the
* environment variable GIMP_PLUGINDIR exists, that is used. It
* should be an absolute pathname. Otherwise, on Unix the compile-time
* defined directory is used. On Win32, the installation directory as
* deduced from the executable's name is used.
*
* The returned string is allocated just once, and should *NOT* be
* freed with g_free().
*
* Returns: The top directory for GIMP plug_ins and modules.
**/
const gchar *
gimp_plug_in_directory (void)
{
static gchar *gimp_plug_in_dir = NULL;
sep2 = strrchr (filename, G_DIR_SEPARATOR);