aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui/dialogs')
-rw-r--r--calendar/gui/dialogs/comp-editor-util.c71
-rw-r--r--calendar/gui/dialogs/comp-editor-util.h1
-rw-r--r--calendar/gui/dialogs/event-page.c8
-rw-r--r--calendar/gui/dialogs/task-page.c8
4 files changed, 84 insertions, 4 deletions
diff --git a/calendar/gui/dialogs/comp-editor-util.c b/calendar/gui/dialogs/comp-editor-util.c
index 8ef7aebbab..df682f6880 100644
--- a/calendar/gui/dialogs/comp-editor-util.c
+++ b/calendar/gui/dialogs/comp-editor-util.c
@@ -472,3 +472,74 @@ comp_editor_contacts_to_component (GtkWidget *contacts_entry,
}
g_slist_free (contact_list);
}
+
+/**
+ * comp_editor_strip_categories:
+ * @categories: A string of category names entered by the user.
+ *
+ * Takes a string of the form "categ, categ, categ, ..." and removes the
+ * whitespace between categories to result in "categ,categ,categ,..."
+ *
+ * Return value: The category names stripped of surrounding whitespace
+ * and separated with commas.
+ **/
+char *
+comp_editor_strip_categories (const char *categories)
+{
+ char *new_categories;
+ const char *start, *end;
+ const char *p;
+ char *new_p;
+
+ if (!categories)
+ return NULL;
+
+ new_categories = g_new (char, strlen (categories) + 1);
+
+ start = end = NULL;
+ new_p = new_categories;
+
+ for (p = categories; *p; p++) {
+ int c;
+
+ c = *p;
+
+ if (isspace (c))
+ continue;
+ else if (c == ',') {
+ int len;
+
+ if (!start)
+ continue;
+
+ g_assert (start <= end);
+
+ len = end - start + 1;
+ strncpy (new_p, start, len);
+ new_p[len] = ',';
+ new_p += len + 1;
+
+ start = end = NULL;
+ } else {
+ if (!start) {
+ start = p;
+ end = p;
+ } else
+ end = p;
+ }
+ }
+
+ if (start) {
+ int len;
+
+ g_assert (start <= end);
+
+ len = end - start + 1;
+ strncpy (new_p, start, len);
+ new_p += len;
+ }
+
+ *new_p = '\0';
+
+ return new_categories;
+}
diff --git a/calendar/gui/dialogs/comp-editor-util.h b/calendar/gui/dialogs/comp-editor-util.h
index 45c45a72a3..0654289698 100644
--- a/calendar/gui/dialogs/comp-editor-util.h
+++ b/calendar/gui/dialogs/comp-editor-util.h
@@ -47,5 +47,6 @@ void comp_editor_contacts_to_widget (GtkWidget *contacts_entry,
void comp_editor_contacts_to_component (GtkWidget *contacts_entry,
CalComponent *comp);
+char *comp_editor_strip_categories (const char *categories);
#endif
diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c
index a3947b1cba..8f9d974178 100644
--- a/calendar/gui/dialogs/event-page.c
+++ b/calendar/gui/dialogs/event-page.c
@@ -644,11 +644,15 @@ event_page_fill_component (CompEditorPage *page, CalComponent *comp)
/* Categories */
cat = e_dialog_editable_get (priv->categories);
- cal_component_set_categories (comp, cat);
-
+ str = comp_editor_strip_categories (cat);
if (cat)
g_free (cat);
+ cal_component_set_categories (comp, str);
+
+ if (str)
+ g_free (str);
+
/* Classification */
classif = e_dialog_radio_get (priv->classification_public,
diff --git a/calendar/gui/dialogs/task-page.c b/calendar/gui/dialogs/task-page.c
index f6ad6da413..84eb1017d4 100644
--- a/calendar/gui/dialogs/task-page.c
+++ b/calendar/gui/dialogs/task-page.c
@@ -533,11 +533,15 @@ task_page_fill_component (CompEditorPage *page, CalComponent *comp)
/* Categories */
cat = e_dialog_editable_get (priv->categories);
- cal_component_set_categories (comp, cat);
-
+ str = comp_editor_strip_categories (cat);
if (cat)
g_free (cat);
+ cal_component_set_categories (comp, str);
+
+ if (str)
+ g_free (str);
+
/* Contacts */
comp_editor_contacts_to_component (priv->contacts_entry, comp);
}