From fede25538616c5bc2a3b42ab2c6796a5ed4aa7a2 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 04 Nov 2017 23:05:12 -0400 Subject: mq_profiles_insert(): New function --- 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); -- cgit v0.9.1