store the gimprc filenames in the GimpRc object; will become properties

2002-11-20  Sven Neumann  <sven@gimp.org>

	* app/config/gimprc.[ch]: store the gimprc filenames in the
	GimpRc object; will become properties later.

	* app/app_procs.c: use the new GimpRc API and added the
	functionality back that allows to specify different gimprc
	files on the command-line.

	* app/gui/user-install-dialog.c: don't work on the real gimprc
	object but create one for the install procedure and save it.
This commit is contained in:
Sven Neumann 2002-11-20 19:32:51 +00:00 committed by Sven Neumann
parent 018dae5367
commit 726258238b
7 changed files with 194 additions and 147 deletions

View File

@ -1,3 +1,15 @@
2002-11-20 Sven Neumann <sven@gimp.org>
* app/config/gimprc.[ch]: store the gimprc filenames in the
GimpRc object; will become properties later.
* app/app_procs.c: use the new GimpRc API and added the
functionality back that allows to specify different gimprc
files on the command-line.
* app/gui/user-install-dialog.c: don't work on the real gimprc
object but create one for the install procedure and save it.
2002-11-20 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpenummenu.[ch]: added *_new_with_values() and
@ -28,7 +40,7 @@
2002-11-20 Sven Neumann <sven@gimp.org>
* app/gui/user_install.c: don't access the global base_config
* app/gui/user-install-dialog.c: don't access the global base_config
which is not initialized at this point.
2002-11-20 Dave Neary <bolsh@gimp.org>

View File

@ -125,17 +125,14 @@ app_init (gint gimp_argc,
/* this needs to be done before gimprc loading */
gimp_unitrc_load (the_gimp);
the_gimp->config = GIMP_CORE_CONFIG (gimp_rc_new ());
the_gimp->config = GIMP_CORE_CONFIG (gimp_rc_new (alternate_system_gimprc,
alternate_gimprc));
/* solely for debugging */
g_signal_connect (G_OBJECT (the_gimp->config), "notify",
G_CALLBACK (gimprc_notify_callback),
NULL);
/* parse the local GIMP configuration file */
/* FIXME: add back support for alternate_system_gimprc and alternate_gimprc */
gimp_rc_load (GIMP_RC (the_gimp->config));
/* initialize lowlevel stuff */
base_init (GIMP_BASE_CONFIG (the_gimp->config));

View File

@ -48,17 +48,22 @@
#include "libgimp/gimpintl.h"
static void gimp_rc_config_iface_init (gpointer iface,
gpointer iface_data);
static gboolean gimp_rc_serialize (GObject *object,
gint fd,
gint indent_level,
gpointer data);
static gboolean gimp_rc_deserialize (GObject *object,
GScanner *scanner,
gint nest_level,
gpointer data);
static GObject * gimp_rc_duplicate (GObject *object);
static void gimp_rc_class_init (GimpRcClass *klass);
static void gimp_rc_config_iface_init (gpointer iface,
gpointer iface_data);
static void gimp_rc_finalize (GObject *object);
static gboolean gimp_rc_serialize (GObject *object,
gint fd,
gint indent_level,
gpointer data);
static gboolean gimp_rc_deserialize (GObject *object,
GScanner *scanner,
gint nest_level,
gpointer data);
static GObject * gimp_rc_duplicate (GObject *object);
static void gimp_rc_load (GimpRc *rc);
static GObjectClass *parent_class = NULL;
GType
@ -73,7 +78,7 @@ gimp_rc_get_type (void)
sizeof (GimpRcClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_init */
(GClassInitFunc) gimp_rc_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpRc),
@ -99,6 +104,37 @@ gimp_rc_get_type (void)
return rc_type;
}
static void
gimp_rc_class_init (GimpRcClass *klass)
{
GObjectClass *object_class;
parent_class = g_type_class_peek_parent (klass);
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_rc_finalize;
}
static void
gimp_rc_finalize (GObject *object)
{
GimpRc *rc = (GimpRc *) object;
if (rc->system_gimprc)
{
g_free (rc->system_gimprc);
rc->system_gimprc = NULL;
}
if (rc->user_gimprc)
{
g_free (rc->user_gimprc);
rc->user_gimprc = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_rc_config_iface_init (gpointer iface,
gpointer iface_data)
@ -116,23 +152,17 @@ gimp_rc_serialize (GObject *object,
gint indent_level,
gpointer data)
{
gboolean success;
if (!gimp_config_serialize_unknown_tokens (object, fd, indent_level))
return FALSE;
if (write (fd, "\n", 1) < 0)
return FALSE;
if (data && GIMP_IS_RC (data))
success = gimp_config_serialize_changed_properties (object,
G_OBJECT (data),
fd,
indent_level);
return gimp_config_serialize_changed_properties (object, G_OBJECT (data),
fd, indent_level);
else
success = gimp_config_serialize_properties (object, fd, indent_level);
if (success)
success = (write (fd, "\n", 1) != -1);
if (success)
success = gimp_config_serialize_unknown_tokens (object, fd, indent_level);
return success;
return gimp_config_serialize_properties (object, fd, indent_level);
}
static gboolean
@ -166,17 +196,61 @@ gimp_rc_duplicate (GObject *object)
return dup;
}
/**
* gimp_rc_new:
*
* Creates a new #GimpRc object with default configuration values.
*
* Return value: the newly generated #GimpRc object.
**/
GimpRc *
gimp_rc_new (void)
static void
gimp_rc_load (GimpRc *rc)
{
return GIMP_RC (g_object_new (GIMP_TYPE_RC, NULL));
GError *error = NULL;
g_return_if_fail (GIMP_IS_RC (rc));
g_printerr ("parsing '%s' ... \n", rc->system_gimprc);
if (!gimp_config_deserialize (G_OBJECT (rc), rc->system_gimprc, NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
g_message (error->message);
g_clear_error (&error);
}
g_printerr ("parsing '%s' ... \n", rc->user_gimprc);
if (!gimp_config_deserialize (G_OBJECT (rc), rc->user_gimprc, NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
g_message (error->message);
g_clear_error (&error);
}
}
GimpRc *
gimp_rc_new (const gchar *system_gimprc,
const gchar *user_gimprc)
{
GimpRc *rc;
g_return_val_if_fail (system_gimprc == NULL ||
g_path_is_absolute (system_gimprc), NULL);
g_return_val_if_fail (user_gimprc == NULL ||
g_path_is_absolute (user_gimprc), NULL);
rc = GIMP_RC (g_object_new (GIMP_TYPE_RC, NULL));
if (system_gimprc)
rc->system_gimprc = g_strdup (system_gimprc);
else
rc->system_gimprc = g_build_filename (gimp_sysconf_directory (),
"gimprc", NULL);
if (user_gimprc)
rc->user_gimprc = g_strdup (user_gimprc);
else
rc->user_gimprc = gimp_personal_rc_file ("gimprc");
gimp_rc_load (rc);
return rc;
}
/**
@ -251,52 +325,10 @@ gimp_rc_query (GimpRc *rc,
}
void
gimp_rc_load (GimpRc *gimprc)
gimp_rc_save (GimpRc *rc)
{
gchar *filename;
GError *error = NULL;
GimpRc *global;
g_return_if_fail (GIMP_IS_RC (gimprc));
filename = g_build_filename (gimp_sysconf_directory (), "gimprc", NULL);
g_printerr ("parsing '%s' ... \n", filename);
if (!gimp_config_deserialize (G_OBJECT (gimprc), filename, NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
g_message (error->message);
g_clear_error (&error);
}
g_free (filename);
filename = gimp_personal_rc_file ("gimprc");
g_printerr ("parsing '%s' ... \n", filename);
if (!gimp_config_deserialize (G_OBJECT (gimprc), filename, NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
g_message (error->message);
g_clear_error (&error);
}
g_free (filename);
}
/**
* gimp_rc_save:
* @user_rc: the current #GimpRc.
* @global_rc: the global #GimpRC.
*
* Saves the users gimprc file. If you pass a global GimpRC, only the
* differences between the global and the users configuration is saved.
**/
void
gimp_rc_save (GimpRc *user_rc,
GimpRc *global_rc)
{
const gchar *top =
"# GIMP gimprc\n"
"#\n"
@ -311,27 +343,26 @@ gimp_rc_save (GimpRc *user_rc,
"# end of gimprc\n";
gchar *header;
gchar *filename;
gchar *system_filename;
GError *error = NULL;
g_return_if_fail (GIMP_IS_RC (user_rc));
g_return_if_fail (global_rc == NULL || GIMP_IS_RC (global_rc));
g_return_if_fail (GIMP_IS_RC (rc));
system_filename = g_build_filename (gimp_sysconf_directory (),
"gimprc", NULL);
header = g_strconcat (top, system_filename, bottom, NULL);
g_free (system_filename);
global = g_object_new (GIMP_TYPE_RC, NULL);
filename = gimp_personal_rc_file ("gimprc");
gimp_config_deserialize (G_OBJECT (global), rc->system_gimprc, NULL, NULL);
if (! gimp_config_serialize (G_OBJECT (user_rc),
filename, header, footer, global_rc, &error))
header = g_strconcat (top, rc->system_gimprc, bottom, NULL);
g_printerr ("saving '%s' ... \n", rc->user_gimprc);
if (! gimp_config_serialize (G_OBJECT (rc),
rc->user_gimprc, header, footer, global,
&error))
{
g_message (error->message);
g_error_free (error);
}
g_free (filename);
g_free (header);
g_object_unref (global);
}

View File

@ -37,6 +37,9 @@ typedef struct _GimpRcClass GimpRcClass;
struct _GimpRc
{
GimpGuiConfig parent_instance;
gchar *user_gimprc;
gchar *system_gimprc;
};
struct _GimpRcClass
@ -46,13 +49,11 @@ struct _GimpRcClass
GType gimp_rc_get_type (void) G_GNUC_CONST;
GimpRc * gimp_rc_new (void);
GimpRc * gimp_rc_new (const gchar *system_gimprc, /* NULL for default */
const gchar *user__gimprc); /* NULL for default */
void gimp_rc_save (GimpRc *gimprc);
gchar * gimp_rc_query (GimpRc *rc,
const gchar *key);
void gimp_rc_load (GimpRc *gimprc);
void gimp_rc_save (GimpRc *user_rc,
GimpRc *global_rc);
#endif /* GIMP_RC_H__ */

View File

@ -72,7 +72,7 @@ main (int argc,
g_print ("\nTesting GimpConfig ...\n\n");
g_print (" Creating a new GimpRc object ...");
gimprc = gimp_rc_new ();
gimprc = g_object_new (GIMP_TYPE_RC, NULL);
g_print (" done.\n\n");
g_print (" Adding the unknown token (foobar \"hadjaha\") ...");

View File

@ -83,10 +83,10 @@ static void user_install_cancel_callback (GtkWidget *widget,
gpointer data);
static gboolean user_install_run (void);
static void user_install_tuning (Gimp *gimp);
static void user_install_tuning_done (Gimp *gimp);
static void user_install_resolution (Gimp *gimp);
static void user_install_resolution_done (Gimp *gimp);
static void user_install_tuning (GimpRc *gimprc);
static void user_install_tuning_done (GimpRc *gimprc);
static void user_install_resolution (GimpRc *gimprc);
static void user_install_resolution_done (GimpRc *gimp);
/* private stuff */
@ -321,7 +321,8 @@ static void
user_install_continue_callback (GtkWidget *widget,
gpointer data)
{
static gint notebook_index = 0;
static gint notebook_index = 0;
static GimpRc *gimprc = NULL;
Gimp *gimp = (Gimp *) data;
@ -354,21 +355,23 @@ user_install_continue_callback (GtkWidget *widget,
FreeConsole ();
#endif
gimp_unitrc_load (gimp);
gimp->config = GIMP_CORE_CONFIG (gimp_rc_new ());
/* FIXME: add back support for alternate_system_gimprc
and alternate_gimprc */
gimp_rc_load (GIMP_RC (gimp->config));
gimprc = gimp_rc_new (alternate_system_gimprc, alternate_gimprc);
user_install_tuning (gimp);
user_install_tuning (gimprc);
break;
case 3:
user_install_tuning_done (gimp);
user_install_resolution (gimp);
user_install_tuning_done (gimprc);
user_install_resolution (gimprc);
break;
case 4:
user_install_resolution_done (gimp);
user_install_resolution_done (gimprc);
gimp_rc_save (gimprc);
g_object_unref (G_OBJECT (gimprc));
gimprc = NULL;
g_object_unref (G_OBJECT (title_style));
g_object_unref (G_OBJECT (page_style));
@ -1120,9 +1123,9 @@ static GtkWidget *xserver_toggle = NULL;
static GtkWidget *resolution_entry = NULL;
static void
user_install_tuning (Gimp *gimp)
user_install_tuning (GimpRc *gimprc)
{
GimpBaseConfig *config = GIMP_BASE_CONFIG (gimp->config);
GimpBaseConfig *config = GIMP_BASE_CONFIG (gimprc);
GtkWidget *hbox;
GtkWidget *sep;
GtkWidget *label;
@ -1177,7 +1180,7 @@ user_install_tuning (Gimp *gimp)
}
static void
user_install_tuning_done (Gimp *gimp)
user_install_tuning_done (GimpRc *gimprc)
{
gulong tile_cache_size;
gchar *swap_path;
@ -1185,7 +1188,7 @@ user_install_tuning_done (Gimp *gimp)
tile_cache_size = GTK_ADJUSTMENT (tile_cache_adj)->value;
swap_path = gimp_file_selection_get_filename (GIMP_FILE_SELECTION (swap_path_filesel));
g_object_set (G_OBJECT (gimp->config),
g_object_set (G_OBJECT (gimprc),
"tile-cache-size", tile_cache_size,
"swap-path", swap_path,
NULL);
@ -1217,9 +1220,9 @@ user_install_resolution_calibrate (GtkWidget *button,
}
static void
user_install_resolution (Gimp *gimp)
user_install_resolution (GimpRc *gimprc)
{
GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (gimp->config);
GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (gimprc);
GtkWidget *hbox;
GtkWidget *sep;
GimpChainButton *chain;
@ -1331,7 +1334,7 @@ user_install_resolution (Gimp *gimp)
}
static void
user_install_resolution_done (Gimp *gimp)
user_install_resolution_done (GimpRc *gimprc)
{
gdouble xres, yres;
gboolean res_from_gdk;
@ -1348,7 +1351,7 @@ user_install_resolution_done (Gimp *gimp)
res_from_gdk = FALSE;
}
g_object_set (G_OBJECT (gimp->config),
g_object_set (G_OBJECT (gimprc),
"monitor_xresolution", xres,
"monitor_yresolution", yres,
"monitor_resolution_from_windowing-system", res_from_gdk,

View File

@ -83,10 +83,10 @@ static void user_install_cancel_callback (GtkWidget *widget,
gpointer data);
static gboolean user_install_run (void);
static void user_install_tuning (Gimp *gimp);
static void user_install_tuning_done (Gimp *gimp);
static void user_install_resolution (Gimp *gimp);
static void user_install_resolution_done (Gimp *gimp);
static void user_install_tuning (GimpRc *gimprc);
static void user_install_tuning_done (GimpRc *gimprc);
static void user_install_resolution (GimpRc *gimprc);
static void user_install_resolution_done (GimpRc *gimp);
/* private stuff */
@ -321,7 +321,8 @@ static void
user_install_continue_callback (GtkWidget *widget,
gpointer data)
{
static gint notebook_index = 0;
static gint notebook_index = 0;
static GimpRc *gimprc = NULL;
Gimp *gimp = (Gimp *) data;
@ -354,21 +355,23 @@ user_install_continue_callback (GtkWidget *widget,
FreeConsole ();
#endif
gimp_unitrc_load (gimp);
gimp->config = GIMP_CORE_CONFIG (gimp_rc_new ());
/* FIXME: add back support for alternate_system_gimprc
and alternate_gimprc */
gimp_rc_load (GIMP_RC (gimp->config));
gimprc = gimp_rc_new (alternate_system_gimprc, alternate_gimprc);
user_install_tuning (gimp);
user_install_tuning (gimprc);
break;
case 3:
user_install_tuning_done (gimp);
user_install_resolution (gimp);
user_install_tuning_done (gimprc);
user_install_resolution (gimprc);
break;
case 4:
user_install_resolution_done (gimp);
user_install_resolution_done (gimprc);
gimp_rc_save (gimprc);
g_object_unref (G_OBJECT (gimprc));
gimprc = NULL;
g_object_unref (G_OBJECT (title_style));
g_object_unref (G_OBJECT (page_style));
@ -1120,9 +1123,9 @@ static GtkWidget *xserver_toggle = NULL;
static GtkWidget *resolution_entry = NULL;
static void
user_install_tuning (Gimp *gimp)
user_install_tuning (GimpRc *gimprc)
{
GimpBaseConfig *config = GIMP_BASE_CONFIG (gimp->config);
GimpBaseConfig *config = GIMP_BASE_CONFIG (gimprc);
GtkWidget *hbox;
GtkWidget *sep;
GtkWidget *label;
@ -1177,7 +1180,7 @@ user_install_tuning (Gimp *gimp)
}
static void
user_install_tuning_done (Gimp *gimp)
user_install_tuning_done (GimpRc *gimprc)
{
gulong tile_cache_size;
gchar *swap_path;
@ -1185,7 +1188,7 @@ user_install_tuning_done (Gimp *gimp)
tile_cache_size = GTK_ADJUSTMENT (tile_cache_adj)->value;
swap_path = gimp_file_selection_get_filename (GIMP_FILE_SELECTION (swap_path_filesel));
g_object_set (G_OBJECT (gimp->config),
g_object_set (G_OBJECT (gimprc),
"tile-cache-size", tile_cache_size,
"swap-path", swap_path,
NULL);
@ -1217,9 +1220,9 @@ user_install_resolution_calibrate (GtkWidget *button,
}
static void
user_install_resolution (Gimp *gimp)
user_install_resolution (GimpRc *gimprc)
{
GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (gimp->config);
GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (gimprc);
GtkWidget *hbox;
GtkWidget *sep;
GimpChainButton *chain;
@ -1331,7 +1334,7 @@ user_install_resolution (Gimp *gimp)
}
static void
user_install_resolution_done (Gimp *gimp)
user_install_resolution_done (GimpRc *gimprc)
{
gdouble xres, yres;
gboolean res_from_gdk;
@ -1348,7 +1351,7 @@ user_install_resolution_done (Gimp *gimp)
res_from_gdk = FALSE;
}
g_object_set (G_OBJECT (gimp->config),
g_object_set (G_OBJECT (gimprc),
"monitor_xresolution", xres,
"monitor_yresolution", yres,
"monitor_resolution_from_windowing-system", res_from_gdk,