summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-11-04 23:05:12 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-11-04 23:05:12 (EDT)
commitfede25538616c5bc2a3b42ab2c6796a5ed4aa7a2 (patch)
tree5a2128c0cbe8352d7a9d28b99ae7c34af5d03352 /src/config
parent7c43696d8473307da50455fa972be9cc9873ccb7 (diff)
downloadmarquee-fede25538616c5bc2a3b42ab2c6796a5ed4aa7a2.zip
marquee-fede25538616c5bc2a3b42ab2c6796a5ed4aa7a2.tar.gz
marquee-fede25538616c5bc2a3b42ab2c6796a5ed4aa7a2.tar.bz2
mq_profiles_insert(): New function
Diffstat (limited to 'src/config')
-rw-r--r--src/config/profiles.c19
-rw-r--r--src/config/profiles.h3
2 files changed, 22 insertions, 0 deletions
diff --git a/src/config/profiles.c b/src/config/profiles.c
index 171b3aa..d006025 100644
--- a/src/config/profiles.c
+++ b/src/config/profiles.c
@@ -163,6 +163,25 @@ mq_profiles_set_default(MqProfiles *profiles, const gchar *profile)
g_key_file_set_boolean(profiles->key_file, profile, "default", TRUE);
}
+gchar *
+mq_profiles_insert(MqProfiles *profiles, const gchar *name, const gchar *color)
+{
+ gchar *id;
+
+ /* The ID must be safe for both the file system and HTML5 "name" and
+ * "id" attributes. To make profile directories portable to other file
+ * systems, use the lowest common denominator of allowed characters. */
+ id = g_strdelimit(g_strdup(name),
+ "/\\:*\"?<>|" /* Lowest common denominator of modern FSes */
+ " \t\n\f\r", /* HTML5 "space characters" */
+ '-');
+
+ mq_profiles_set_name(profiles, id, name);
+ mq_profiles_set_color(profiles, id, color);
+
+ return id;
+}
+
gboolean
mq_profiles_remove(MqProfiles *profiles, const gchar *profile)
{
diff --git a/src/config/profiles.h b/src/config/profiles.h
index 9fa5ce1..3104531 100644
--- a/src/config/profiles.h
+++ b/src/config/profiles.h
@@ -57,6 +57,9 @@ mq_profiles_set_color(MqProfiles *profiles, const gchar *profile,
void
mq_profiles_set_default(MqProfiles *profiles, const gchar *profile);
+gchar *
+mq_profiles_insert(MqProfiles *profiles, const gchar *name, const gchar *color);
+
gboolean
mq_profiles_remove(MqProfiles *profiles, const gchar *profile);