2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-12-08 00:10:53 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-12-11 04:43:51 +08:00
|
|
|
* GimpBaseConfig class
|
|
|
|
* Copyright (C) 2001 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-12-08 00:10:53 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-12-08 00:10:53 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-12-08 00:10:53 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2006-07-14 21:13:37 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
#include <glib-object.h>
|
|
|
|
|
2001-12-17 00:33:18 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-12-17 00:33:18 +08:00
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
#include "config-types.h"
|
|
|
|
|
2008-05-22 03:07:26 +08:00
|
|
|
#include "base/base-types.h" /* eek */
|
2007-11-01 22:29:48 +08:00
|
|
|
#include "base/base-utils.h"
|
2005-02-14 08:34:38 +08:00
|
|
|
#include "base/pixel-processor.h"
|
|
|
|
|
2002-12-20 22:36:08 +08:00
|
|
|
#include "gimprc-blurbs.h"
|
2001-12-08 00:10:53 +08:00
|
|
|
#include "gimpbaseconfig.h"
|
|
|
|
|
2010-06-25 04:47:42 +08:00
|
|
|
#include "gimp-debug.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-01-26 04:29:42 +08:00
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_TEMP_PATH,
|
|
|
|
PROP_SWAP_PATH,
|
|
|
|
PROP_NUM_PROCESSORS,
|
2008-09-30 17:41:55 +08:00
|
|
|
PROP_TILE_CACHE_SIZE,
|
|
|
|
|
|
|
|
/* ignored, only for backward compatibility: */
|
|
|
|
PROP_STINGY_MEMORY_USE
|
2001-12-08 00:10:53 +08:00
|
|
|
};
|
|
|
|
|
2002-02-08 20:35:38 +08:00
|
|
|
|
2010-06-25 04:47:42 +08:00
|
|
|
static void gimp_base_config_class_init (GimpBaseConfigClass *klass);
|
|
|
|
static void gimp_base_config_init (GimpBaseConfig *config,
|
|
|
|
GimpBaseConfigClass *klass);
|
|
|
|
static void gimp_base_config_finalize (GObject *object);
|
|
|
|
static void gimp_base_config_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_base_config_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-12-11 03:24:36 +08:00
|
|
|
|
|
|
|
|
2010-06-25 04:47:42 +08:00
|
|
|
static GObjectClass *parent_class = NULL;
|
2005-12-11 03:24:36 +08:00
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
|
2010-06-25 04:47:42 +08:00
|
|
|
GType
|
|
|
|
gimp_base_config_get_type (void)
|
|
|
|
{
|
|
|
|
static GType config_type = 0;
|
|
|
|
|
|
|
|
if (! config_type)
|
|
|
|
{
|
|
|
|
const GTypeInfo config_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpBaseConfigClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_base_config_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpBaseConfig),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_base_config_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
config_type = g_type_register_static (G_TYPE_OBJECT,
|
|
|
|
"GimpBaseConfig",
|
|
|
|
&config_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return config_type;
|
|
|
|
}
|
2001-12-08 00:10:53 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_base_config_class_init (GimpBaseConfigClass *klass)
|
|
|
|
{
|
2005-12-11 03:24:36 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2006-07-14 21:13:37 +08:00
|
|
|
gint num_processors;
|
2001-12-08 00:10:53 +08:00
|
|
|
|
2010-06-25 04:47:42 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2002-02-08 20:35:38 +08:00
|
|
|
object_class->finalize = gimp_base_config_finalize;
|
2001-12-08 00:10:53 +08:00
|
|
|
object_class->set_property = gimp_base_config_set_property;
|
|
|
|
object_class->get_property = gimp_base_config_get_property;
|
|
|
|
|
2001-12-11 02:31:35 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_TEMP_PATH,
|
2002-11-28 23:19:19 +08:00
|
|
|
"temp-path", TEMP_PATH_BLURB,
|
2006-04-12 20:49:29 +08:00
|
|
|
GIMP_CONFIG_PATH_DIR,
|
2005-04-07 05:37:40 +08:00
|
|
|
"${gimp_dir}" G_DIR_SEPARATOR_S "tmp",
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
2005-02-05 22:52:58 +08:00
|
|
|
GIMP_CONFIG_PARAM_RESTART);
|
2001-12-11 02:31:35 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_SWAP_PATH,
|
2002-11-28 23:19:19 +08:00
|
|
|
"swap-path", SWAP_PATH_BLURB,
|
2006-04-12 20:49:29 +08:00
|
|
|
GIMP_CONFIG_PATH_DIR,
|
2005-04-07 05:37:40 +08:00
|
|
|
"${gimp_dir}",
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
2005-02-05 22:52:58 +08:00
|
|
|
GIMP_CONFIG_PARAM_RESTART);
|
2006-07-14 21:13:37 +08:00
|
|
|
|
2007-11-01 22:29:48 +08:00
|
|
|
num_processors = get_number_of_processors ();
|
2006-07-14 21:13:37 +08:00
|
|
|
|
|
|
|
#ifdef GIMP_UNSTABLE
|
|
|
|
num_processors = num_processors * 2;
|
|
|
|
#endif
|
|
|
|
|
2010-05-17 04:26:11 +08:00
|
|
|
num_processors = MIN (num_processors, GIMP_MAX_NUM_THREADS);
|
|
|
|
|
2001-12-11 02:31:35 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_UINT (object_class, PROP_NUM_PROCESSORS,
|
2002-11-28 23:19:19 +08:00
|
|
|
"num-processors", NUM_PROCESSORS_BLURB,
|
2006-07-14 21:13:37 +08:00
|
|
|
1, GIMP_MAX_NUM_THREADS, num_processors,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2001-12-11 02:31:35 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_MEMSIZE (object_class, PROP_TILE_CACHE_SIZE,
|
2002-11-28 23:19:19 +08:00
|
|
|
"tile-cache-size", TILE_CACHE_SIZE_BLURB,
|
2008-08-08 00:23:37 +08:00
|
|
|
0, MIN (G_MAXSIZE, GIMP_MAX_MEMSIZE),
|
2006-07-18 20:54:58 +08:00
|
|
|
1 << 30, /* 1GB */
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_STATIC_STRINGS |
|
2005-02-05 22:52:58 +08:00
|
|
|
GIMP_CONFIG_PARAM_CONFIRM);
|
2008-09-30 17:41:55 +08:00
|
|
|
|
|
|
|
/* only for backward compatibility: */
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_STINGY_MEMORY_USE,
|
|
|
|
"stingy-memory-use", NULL,
|
|
|
|
FALSE,
|
|
|
|
GIMP_CONFIG_PARAM_IGNORE);
|
2001-12-08 00:10:53 +08:00
|
|
|
}
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static void
|
2010-06-25 04:47:42 +08:00
|
|
|
gimp_base_config_init (GimpBaseConfig *config,
|
|
|
|
GimpBaseConfigClass *klass)
|
2005-12-11 03:24:36 +08:00
|
|
|
{
|
2010-06-25 04:47:42 +08:00
|
|
|
gimp_debug_add_instance (G_OBJECT (config), G_OBJECT_CLASS (klass));
|
2005-12-11 03:24:36 +08:00
|
|
|
}
|
|
|
|
|
2002-02-08 20:35:38 +08:00
|
|
|
static void
|
|
|
|
gimp_base_config_finalize (GObject *object)
|
|
|
|
{
|
2003-11-17 05:57:46 +08:00
|
|
|
GimpBaseConfig *base_config = GIMP_BASE_CONFIG (object);
|
2003-11-14 21:41:16 +08:00
|
|
|
|
2002-02-08 20:35:38 +08:00
|
|
|
g_free (base_config->temp_path);
|
|
|
|
g_free (base_config->swap_path);
|
|
|
|
|
2010-06-25 04:47:42 +08:00
|
|
|
gimp_debug_remove_instance (object);
|
|
|
|
|
2002-02-08 20:35:38 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
static void
|
|
|
|
gimp_base_config_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2003-11-17 05:57:46 +08:00
|
|
|
GimpBaseConfig *base_config = GIMP_BASE_CONFIG (object);
|
2001-12-08 00:10:53 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TEMP_PATH:
|
|
|
|
g_free (base_config->temp_path);
|
|
|
|
base_config->temp_path = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_SWAP_PATH:
|
|
|
|
g_free (base_config->swap_path);
|
|
|
|
base_config->swap_path = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_NUM_PROCESSORS:
|
|
|
|
base_config->num_processors = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_TILE_CACHE_SIZE:
|
2003-11-14 21:41:16 +08:00
|
|
|
base_config->tile_cache_size = g_value_get_uint64 (value);
|
2001-12-08 00:10:53 +08:00
|
|
|
break;
|
2006-03-11 00:40:09 +08:00
|
|
|
|
2008-09-30 17:41:55 +08:00
|
|
|
case PROP_STINGY_MEMORY_USE:
|
|
|
|
/* ignored */
|
|
|
|
break;
|
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_base_config_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2003-11-17 05:57:46 +08:00
|
|
|
GimpBaseConfig *base_config = GIMP_BASE_CONFIG (object);
|
2001-12-08 00:10:53 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TEMP_PATH:
|
|
|
|
g_value_set_string (value, base_config->temp_path);
|
|
|
|
break;
|
|
|
|
case PROP_SWAP_PATH:
|
|
|
|
g_value_set_string (value, base_config->swap_path);
|
|
|
|
break;
|
|
|
|
case PROP_NUM_PROCESSORS:
|
|
|
|
g_value_set_uint (value, base_config->num_processors);
|
|
|
|
break;
|
|
|
|
case PROP_TILE_CACHE_SIZE:
|
2003-11-14 21:41:16 +08:00
|
|
|
g_value_set_uint64 (value, base_config->tile_cache_size);
|
2001-12-08 00:10:53 +08:00
|
|
|
break;
|
2006-03-11 00:40:09 +08:00
|
|
|
|
2008-09-30 17:41:55 +08:00
|
|
|
case PROP_STINGY_MEMORY_USE:
|
|
|
|
/* ignored */
|
|
|
|
break;
|
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|