diff options
-rw-r--r-- | src/config/profiles.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/config/profiles.c b/src/config/profiles.c index ade081e..bf08af0 100644 --- a/src/config/profiles.c +++ b/src/config/profiles.c @@ -89,6 +89,28 @@ load(MqProfiles *profiles) G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL); } +static gboolean +insert(MqProfiles *profiles, const gchar *id, const gchar *name, + const gchar *color) +{ + gchar *dir; + + /* Make sure the profile directory can be created and doesn't already + * exist (or, on a case-insensitive file system, a directory by the same + * name but in a different case doesn't exist). */ + dir = g_build_filename(profiles->config_dir, id, NULL); + if (g_mkdir(dir, 0700) != 0) { + g_free(dir); + return FALSE; + } + g_free(dir); + + mq_profiles_set_name(profiles, id, name); + mq_profiles_set_color(profiles, id, color); + + return TRUE; +} + MqProfiles * mq_profiles_new(void) { @@ -221,7 +243,6 @@ gchar * mq_profiles_insert(MqProfiles *profiles, const gchar *name, const gchar *color) { gchar *id; - gchar *dir; /* The ID must be safe for both the file system and HTML5 "name" and * "id" attributes. To make profile directories portable to other file @@ -231,21 +252,12 @@ mq_profiles_insert(MqProfiles *profiles, const gchar *name, const gchar *color) " \t\n\f\r", /* HTML5 "space characters" */ '_'); - /* Make sure the profile directory can be created and doesn't already - * exist (or, on a case-insensitive file system, a directory by the same - * name but in a different case doesn't exist). */ - dir = g_build_filename(profiles->config_dir, id, NULL); - if (g_mkdir(dir, 0700) != 0) { + if (insert(profiles, id, name, color)) { + return id; + } else { g_free(id); - g_free(dir); return NULL; } - g_free(dir); - - mq_profiles_set_name(profiles, id, name); - mq_profiles_set_color(profiles, id, color); - - return id; } gboolean |