Revision: 4973 http://geany.svn.sourceforge.net/geany/?rev=4973&view=rev Author: statc Date: 2010-05-31 09:25:02 +0000 (Mon, 31 May 2010)
Log Message: ----------- keyfile.c: Extract common code of opening, writing and closing geany.conf to separate functions.
Modified Paths: -------------- branches/sm/src/keyfile.c
Modified: branches/sm/src/keyfile.c =================================================================== --- branches/sm/src/keyfile.c 2010-05-31 09:24:43 UTC (rev 4972) +++ branches/sm/src/keyfile.c 2010-05-31 09:25:02 UTC (rev 4973) @@ -226,6 +226,29 @@ }
+static void open_config(GKeyFile ** config, gchar ** configfile) +{ + *config = g_key_file_new(); + *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL); + g_key_file_load_from_file(*config, *configfile, G_KEY_FILE_NONE, NULL); +} + + +static void write_config(GKeyFile * config, gchar * configfile) +{ + gchar *data = g_key_file_to_data(config, NULL, NULL); + utils_write_file(configfile, data); + g_free(data); +} + + +static void close_config(GKeyFile * config, gchar * configfile) +{ + g_key_file_free(config); + g_free(configfile); +} + + static void save_recent_files(GKeyFile *config, GQueue *queue, gchar const *key) { gchar **recent_files = g_new0(gchar*, file_prefs.mru_length + 1); @@ -334,12 +357,10 @@
void configuration_save_dialog_prefs(void) { - GKeyFile *config = g_key_file_new(); - gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL); - gchar *data; + GKeyFile *config; + gchar *configfile; + open_config(&config, &configfile);
- g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); - /* new settings should be added in init_pref_groups() */ settings_action(config, SETTING_WRITE);
@@ -488,13 +509,8 @@ } #endif
- /* write the file */ - data = g_key_file_to_data(config, NULL, NULL); - utils_write_file(configfile, data); - g_free(data); - - g_key_file_free(config); - g_free(configfile); + write_config(config, configfile); + close_config(config, configfile); }
@@ -551,12 +567,10 @@
void configuration_save(void) { - GKeyFile *config = g_key_file_new(); - gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL); - gchar *data; + GKeyFile *config; + gchar *configfile; + open_config(&config, &configfile);
- g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); - /* this signal can be used e.g. to prepare any settings before Stash code reads them below */ g_signal_emit_by_name(geany_object, "save-settings", config);
@@ -568,13 +582,8 @@ if (cl_options.load_session) configuration_save_session_files(config);
- /* write the file */ - data = g_key_file_to_data(config, NULL, NULL); - utils_write_file(configfile, data); - g_free(data); - - g_key_file_free(config); - g_free(configfile); + write_config(config, configfile); + close_config(config, configfile); }
@@ -911,22 +920,15 @@ */ void configuration_save_default_session(void) { - gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL); - gchar *data; - GKeyFile *config = g_key_file_new(); + GKeyFile *config; + gchar *configfile; + open_config(&config, &configfile);
- g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); - if (cl_options.load_session) configuration_save_session_files(config);
- /* write the file */ - data = g_key_file_to_data(config, NULL, NULL); - utils_write_file(configfile, data); - g_free(data); - - g_key_file_free(config); - g_free(configfile); + write_config(config, configfile); + close_config(config, configfile); }
@@ -935,15 +937,13 @@ */ void configuration_reload_default_session(void) { - gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL); - GKeyFile *config = g_key_file_new(); + GKeyFile *config; + gchar *configfile; + open_config(&config, &configfile);
- g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); - configuration_load_session_files(config, FALSE);
- g_key_file_free(config); - g_free(configfile); + close_config(config, configfile); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.