GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit 3e85deef authored by Michael Natterer's avatar Michael Natterer 😴

app: manage the system and user gimprc paths as GFiles

parent 6b6ba7b4
...@@ -140,8 +140,8 @@ app_exit (gint status) ...@@ -140,8 +140,8 @@ app_exit (gint status)
void void
app_run (const gchar *full_prog_name, app_run (const gchar *full_prog_name,
const gchar **filenames, const gchar **filenames,
const gchar *alternate_system_gimprc, GFile *alternate_system_gimprc,
const gchar *alternate_gimprc, GFile *alternate_gimprc,
const gchar *session_name, const gchar *session_name,
const gchar *batch_interpreter, const gchar *batch_interpreter,
const gchar **batch_commands, const gchar **batch_commands,
......
...@@ -32,8 +32,8 @@ void app_exit (gint status) G_GNUC_NORETURN; ...@@ -32,8 +32,8 @@ void app_exit (gint status) G_GNUC_NORETURN;
void app_run (const gchar *full_prog_name, void app_run (const gchar *full_prog_name,
const gchar **filenames, const gchar **filenames,
const gchar *alternate_system_gimprc, GFile *alternate_system_gimprc,
const gchar *alternate_gimprc, GFile *alternate_gimprc,
const gchar *session_name, const gchar *session_name,
const gchar *batch_interpreter, const gchar *batch_interpreter,
const gchar **batch_commands, const gchar **batch_commands,
......
...@@ -93,16 +93,16 @@ gimp_rc_class_init (GimpRcClass *klass) ...@@ -93,16 +93,16 @@ gimp_rc_class_init (GimpRcClass *klass)
G_PARAM_CONSTRUCT)); G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_SYSTEM_GIMPRC, g_object_class_install_property (object_class, PROP_SYSTEM_GIMPRC,
g_param_spec_string ("system-gimprc", g_param_spec_object ("system-gimprc",
NULL, NULL, NULL, NULL,
NULL, G_TYPE_FILE,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT)); G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_USER_GIMPRC, g_object_class_install_property (object_class, PROP_USER_GIMPRC,
g_param_spec_string ("user-gimprc", g_param_spec_object ("user-gimprc",
NULL, NULL, NULL, NULL,
NULL, G_TYPE_FILE,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT)); G_PARAM_CONSTRUCT));
} }
...@@ -132,12 +132,13 @@ gimp_rc_finalize (GObject *object) ...@@ -132,12 +132,13 @@ gimp_rc_finalize (GObject *object)
if (rc->system_gimprc) if (rc->system_gimprc)
{ {
g_free (rc->system_gimprc); g_object_unref (rc->system_gimprc);
rc->system_gimprc = NULL; rc->system_gimprc = NULL;
} }
if (rc->user_gimprc) if (rc->user_gimprc)
{ {
g_free (rc->user_gimprc); g_object_unref (rc->user_gimprc);
rc->user_gimprc = NULL; rc->user_gimprc = NULL;
} }
...@@ -150,18 +151,7 @@ gimp_rc_set_property (GObject *object, ...@@ -150,18 +151,7 @@ gimp_rc_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpRc *rc = GIMP_RC (object); GimpRc *rc = GIMP_RC (object);
const gchar *filename = NULL;
switch (property_id)
{
case PROP_SYSTEM_GIMPRC:
case PROP_USER_GIMPRC:
filename = g_value_get_string (value);
break;
default:
break;
}
switch (property_id) switch (property_id)
{ {
...@@ -170,22 +160,23 @@ gimp_rc_set_property (GObject *object, ...@@ -170,22 +160,23 @@ gimp_rc_set_property (GObject *object,
break; break;
case PROP_SYSTEM_GIMPRC: case PROP_SYSTEM_GIMPRC:
g_free (rc->system_gimprc); if (rc->system_gimprc)
g_object_unref (rc->system_gimprc);
if (filename) if (g_value_get_object (value))
rc->system_gimprc = g_strdup (filename); rc->system_gimprc = g_value_dup_object (value);
else else
rc->system_gimprc = g_build_filename (gimp_sysconf_directory (), rc->system_gimprc = gimp_sysconf_directory_file ("gimprc", NULL);
"gimprc", NULL);
break; break;
case PROP_USER_GIMPRC: case PROP_USER_GIMPRC:
g_free (rc->user_gimprc); if (rc->user_gimprc)
g_object_unref (rc->user_gimprc);
if (filename) if (g_value_get_object (value))
rc->user_gimprc = g_strdup (filename); rc->user_gimprc = g_value_dup_object (value);
else else
rc->user_gimprc = gimp_personal_rc_file ("gimprc"); rc->user_gimprc = gimp_directory_file ("gimprc", NULL);
break; break;
default: default:
...@@ -208,11 +199,12 @@ gimp_rc_get_property (GObject *object, ...@@ -208,11 +199,12 @@ gimp_rc_get_property (GObject *object,
g_value_set_boolean (value, rc->verbose); g_value_set_boolean (value, rc->verbose);
break; break;
case PROP_SYSTEM_GIMPRC: case PROP_SYSTEM_GIMPRC:
g_value_set_string (value, rc->system_gimprc); g_value_set_object (value, rc->system_gimprc);
break; break;
case PROP_USER_GIMPRC: case PROP_USER_GIMPRC:
g_value_set_string (value, rc->user_gimprc); g_value_set_object (value, rc->user_gimprc);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
...@@ -257,10 +249,10 @@ gimp_rc_load (GimpRc *rc) ...@@ -257,10 +249,10 @@ gimp_rc_load (GimpRc *rc)
if (rc->verbose) if (rc->verbose)
g_print ("Parsing '%s'\n", g_print ("Parsing '%s'\n",
gimp_filename_to_utf8 (rc->system_gimprc)); gimp_file_get_utf8_name (rc->system_gimprc));
if (! gimp_config_deserialize_file (GIMP_CONFIG (rc), if (! gimp_config_deserialize_gfile (GIMP_CONFIG (rc),
rc->system_gimprc, NULL, &error)) rc->system_gimprc, NULL, &error))
{ {
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT) if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
g_message ("%s", error->message); g_message ("%s", error->message);
...@@ -270,20 +262,16 @@ gimp_rc_load (GimpRc *rc) ...@@ -270,20 +262,16 @@ gimp_rc_load (GimpRc *rc)
if (rc->verbose) if (rc->verbose)
g_print ("Parsing '%s'\n", g_print ("Parsing '%s'\n",
gimp_filename_to_utf8 (rc->user_gimprc)); gimp_file_get_utf8_name (rc->user_gimprc));
if (! gimp_config_deserialize_file (GIMP_CONFIG (rc), if (! gimp_config_deserialize_gfile (GIMP_CONFIG (rc),
rc->user_gimprc, NULL, &error)) rc->user_gimprc, NULL, &error))
{ {
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT) if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
{ {
GFile *file;
g_message ("%s", error->message); g_message ("%s", error->message);
file = g_file_new_for_path (rc->user_gimprc); gimp_config_file_backup_on_error (rc->user_gimprc, "gimprc", NULL);
gimp_config_file_backup_on_error (file, "gimprc", NULL);
g_object_unref (file);
} }
g_clear_error (&error); g_clear_error (&error);
...@@ -326,15 +314,22 @@ gimp_rc_notify (GimpRc *rc, ...@@ -326,15 +314,22 @@ gimp_rc_notify (GimpRc *rc,
* Returns: the new #GimpRc. * Returns: the new #GimpRc.
*/ */
GimpRc * GimpRc *
gimp_rc_new (const gchar *system_gimprc, gimp_rc_new (GFile *system_gimprc,
const gchar *user_gimprc, GFile *user_gimprc,
gboolean verbose) gboolean verbose)
{ {
GimpRc *rc = g_object_new (GIMP_TYPE_RC, GimpRc *rc;
"verbose", verbose,
"system-gimprc", system_gimprc, g_return_val_if_fail (system_gimprc == NULL || G_IS_FILE (system_gimprc),
"user-gimprc", user_gimprc, NULL);
NULL); g_return_val_if_fail (user_gimprc == NULL || G_IS_FILE (user_gimprc),
NULL);
rc = g_object_new (GIMP_TYPE_RC,
"verbose", verbose,
"system-gimprc", system_gimprc,
"user-gimprc", user_gimprc,
NULL);
gimp_rc_load (rc); gimp_rc_load (rc);
...@@ -513,19 +508,20 @@ gimp_rc_save (GimpRc *rc) ...@@ -513,19 +508,20 @@ gimp_rc_save (GimpRc *rc)
global = g_object_new (GIMP_TYPE_RC, NULL); global = g_object_new (GIMP_TYPE_RC, NULL);
gimp_config_deserialize_file (GIMP_CONFIG (global), gimp_config_deserialize_gfile (GIMP_CONFIG (global),
rc->system_gimprc, NULL, NULL); rc->system_gimprc, NULL, NULL);
header = g_strconcat (top, rc->system_gimprc, bottom, NULL); header = g_strconcat (top, gimp_file_get_utf8_name (rc->system_gimprc),
bottom, NULL);
if (rc->verbose) if (rc->verbose)
g_print ("Writing '%s'\n", g_print ("Writing '%s'\n",
gimp_filename_to_utf8 (rc->user_gimprc)); gimp_file_get_utf8_name (rc->user_gimprc));
if (! gimp_config_serialize_to_file (GIMP_CONFIG (rc), if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (rc),
rc->user_gimprc, rc->user_gimprc,
header, footer, global, header, footer, global,
&error)) &error))
{ {
g_message ("%s", error->message); g_message ("%s", error->message);
g_error_free (error); g_error_free (error);
......
...@@ -37,8 +37,8 @@ struct _GimpRc ...@@ -37,8 +37,8 @@ struct _GimpRc
{ {
GimpPluginConfig parent_instance; GimpPluginConfig parent_instance;
gchar *user_gimprc; GFile *user_gimprc;
gchar *system_gimprc; GFile *system_gimprc;
gboolean verbose; gboolean verbose;
gboolean autosave; gboolean autosave;
guint save_idle_id; guint save_idle_id;
...@@ -51,9 +51,10 @@ struct _GimpRcClass ...@@ -51,9 +51,10 @@ struct _GimpRcClass
GType gimp_rc_get_type (void) G_GNUC_CONST; GType gimp_rc_get_type (void) G_GNUC_CONST;
GimpRc * gimp_rc_new (const gchar *system_gimprc, GimpRc * gimp_rc_new (GFile *system_gimprc,
const gchar *user_gimprc, GFile *user_gimprc,
gboolean verbose); gboolean verbose);
void gimp_rc_set_autosave (GimpRc *gimprc, void gimp_rc_set_autosave (GimpRc *gimprc,
gboolean autosave); gboolean autosave);
void gimp_rc_save (GimpRc *gimprc); void gimp_rc_save (GimpRc *gimprc);
......
...@@ -938,13 +938,17 @@ gimp_edit_config_notify (GObject *edit_config, ...@@ -938,13 +938,17 @@ gimp_edit_config_notify (GObject *edit_config,
} }
void void
gimp_load_config (Gimp *gimp, gimp_load_config (Gimp *gimp,
const gchar *alternate_system_gimprc, GFile *alternate_system_gimprc,
const gchar *alternate_gimprc) GFile *alternate_gimprc)
{ {
GimpRc *gimprc; GimpRc *gimprc;
g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (alternate_system_gimprc == NULL ||
G_IS_FILE (alternate_system_gimprc));
g_return_if_fail (alternate_gimprc == NULL ||
G_IS_FILE (alternate_gimprc));
g_return_if_fail (gimp->config == NULL); g_return_if_fail (gimp->config == NULL);
g_return_if_fail (gimp->edit_config == NULL); g_return_if_fail (gimp->edit_config == NULL);
......
...@@ -160,8 +160,8 @@ void gimp_set_show_gui (Gimp *gimp, ...@@ -160,8 +160,8 @@ void gimp_set_show_gui (Gimp *gimp,
gboolean gimp_get_show_gui (Gimp *gimp); gboolean gimp_get_show_gui (Gimp *gimp);
void gimp_load_config (Gimp *gimp, void gimp_load_config (Gimp *gimp,
const gchar *alternate_system_gimprc, GFile *alternate_system_gimprc,
const gchar *alternate_gimprc); GFile *alternate_gimprc);
void gimp_initialize (Gimp *gimp, void gimp_initialize (Gimp *gimp,
GimpInitStatusFunc status_callback); GimpInitStatusFunc status_callback);
void gimp_restore (Gimp *gimp, void gimp_restore (Gimp *gimp,
......
...@@ -286,6 +286,8 @@ main (int argc, ...@@ -286,6 +286,8 @@ main (int argc,
GError *error = NULL; GError *error = NULL;
const gchar *abort_message; const gchar *abort_message;
gchar *basename; gchar *basename;
GFile *system_gimprc_file = NULL;
GFile *user_gimprc_file = NULL;
gint i; gint i;
#if defined (__GNUC__) && defined (_WIN64) #if defined (__GNUC__) && defined (_WIN64)
...@@ -449,10 +451,16 @@ main (int argc, ...@@ -449,10 +451,16 @@ main (int argc,
gimp_init_signal_handlers (stack_trace_mode); gimp_init_signal_handlers (stack_trace_mode);
if (system_gimprc)
system_gimprc_file = g_file_new_for_commandline_arg (system_gimprc);
if (user_gimprc)
user_gimprc_file = g_file_new_for_commandline_arg (user_gimprc);
app_run (argv[0], app_run (argv[0],
filenames, filenames,
system_gimprc, system_gimprc_file,
user_gimprc, user_gimprc_file,
session_name, session_name,
batch_interpreter, batch_interpreter,
batch_commands, batch_commands,
...@@ -469,6 +477,12 @@ main (int argc, ...@@ -469,6 +477,12 @@ main (int argc,
stack_trace_mode, stack_trace_mode,
pdb_compat_mode); pdb_compat_mode);
if (system_gimprc_file)
g_object_unref (system_gimprc_file);
if (user_gimprc_file)
g_object_unref (user_gimprc_file);
g_strfreev (argv); g_strfreev (argv);
g_option_context_free (context); g_option_context_free (context);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment