summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-11-10 10:49:01 (EST)
committer Patrick McDermott <pj@pehjota.net>2017-11-10 10:49:01 (EST)
commite4a23a27484124dc0c1c23a06177f81767ed5fe7 (patch)
tree767a0a7e49833e57d9e644916024efa9f4b40e1b /src/config
parent5e93fa233809a4d64bdc5fc0774699c96892ee22 (diff)
downloadmarquee-e4a23a27484124dc0c1c23a06177f81767ed5fe7.zip
marquee-e4a23a27484124dc0c1c23a06177f81767ed5fe7.tar.gz
marquee-e4a23a27484124dc0c1c23a06177f81767ed5fe7.tar.bz2
mq_profiles_insert(): Split out insertion into new static function
Diffstat (limited to 'src/config')
-rw-r--r--src/config/profiles.c38
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