summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);