[evolution] Bug 776958 - Treat categories as multivalue in component editor



commit 73db7e9bd084153cd7b27b3167ca5c50b903b221
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jan 9 16:07:18 2017 +0100

    Bug 776958 - Treat categories as multivalue in component editor

 src/calendar/gui/e-comp-editor-property-part.c  |   61 +++++++++++++++++++++--
 src/calendar/gui/e-comp-editor-property-part.h  |    5 ++
 src/calendar/gui/e-comp-editor-property-parts.c |    2 +
 3 files changed, 64 insertions(+), 4 deletions(-)
---
diff --git a/src/calendar/gui/e-comp-editor-property-part.c b/src/calendar/gui/e-comp-editor-property-part.c
index 8f94472..bc42ef1 100644
--- a/src/calendar/gui/e-comp-editor-property-part.c
+++ b/src/calendar/gui/e-comp-editor-property-part.c
@@ -315,7 +315,7 @@ e_comp_editor_property_part_emit_changed (ECompEditorPropertyPart *property_part
 /* ************************************************************************* */
 
 struct _ECompEditorPropertyPartStringPrivate {
-       gint dummy;
+       gboolean is_multivalue;
 };
 
 G_DEFINE_ABSTRACT_TYPE (ECompEditorPropertyPartString, e_comp_editor_property_part_string, 
E_TYPE_COMP_EDITOR_PROPERTY_PART)
@@ -391,6 +391,7 @@ ecepp_string_fill_widget (ECompEditorPropertyPart *property_part,
 {
        ECompEditorPropertyPartStringClass *klass;
        GtkWidget *edit_widget;
+       GString *multivalue = NULL;
        icalproperty *prop;
        const gchar *value = NULL;
 
@@ -405,9 +406,32 @@ ecepp_string_fill_widget (ECompEditorPropertyPart *property_part,
        g_return_if_fail (klass->ical_prop_kind != ICAL_NO_PROPERTY);
        g_return_if_fail (klass->ical_get_func != NULL);
 
-       prop = icalcomponent_get_first_property (component, klass->ical_prop_kind);
-       if (prop)
-               value = klass->ical_get_func (prop);
+       if (e_comp_editor_property_part_string_is_multivalue (E_COMP_EDITOR_PROPERTY_PART_STRING 
(property_part))) {
+               for (prop = icalcomponent_get_first_property (component, klass->ical_prop_kind);
+                    prop;
+                    prop = icalcomponent_get_next_property (component, klass->ical_prop_kind)) {
+                       value = klass->ical_get_func (prop);
+
+                       if (!value || !*value)
+                               continue;
+
+                       if (!multivalue)
+                               multivalue = g_string_new ("");
+                       else if (multivalue->len)
+                               g_string_append_c (multivalue, ',');
+
+                       g_string_append (multivalue, value);
+               }
+
+               if (multivalue)
+                       value = multivalue->str;
+               else
+                       value = NULL;
+       } else {
+               prop = icalcomponent_get_first_property (component, klass->ical_prop_kind);
+               if (prop)
+                       value = klass->ical_get_func (prop);
+       }
 
        if (!value)
                value = "";
@@ -422,6 +446,9 @@ ecepp_string_fill_widget (ECompEditorPropertyPart *property_part,
        }
 
        e_widget_undo_reset (edit_widget);
+
+       if (multivalue)
+               g_string_free (multivalue, TRUE);
 }
 
 static void
@@ -457,6 +484,14 @@ ecepp_string_fill_component (ECompEditorPropertyPart *property_part,
                value = gtk_text_buffer_get_text (buffer, &text_iter_start, &text_iter_end, FALSE);
        }
 
+       if (e_comp_editor_property_part_string_is_multivalue (E_COMP_EDITOR_PROPERTY_PART_STRING 
(property_part))) {
+               /* Clear all multivalues first */
+               while (prop = icalcomponent_get_first_property (component, klass->ical_prop_kind), prop) {
+                       icalcomponent_remove_property (component, prop);
+                       icalproperty_free (prop);
+               }
+       }
+
        prop = icalcomponent_get_first_property (component, klass->ical_prop_kind);
 
        if (value && *value) {
@@ -480,6 +515,7 @@ e_comp_editor_property_part_string_init (ECompEditorPropertyPartString *part_str
        part_string->priv = G_TYPE_INSTANCE_GET_PRIVATE (part_string,
                E_TYPE_COMP_EDITOR_PROPERTY_PART_STRING,
                ECompEditorPropertyPartStringPrivate);
+       part_string->priv->is_multivalue = FALSE;
 }
 
 static void
@@ -520,6 +556,23 @@ e_comp_editor_property_part_string_attach_focus_tracker (ECompEditorPropertyPart
                e_widget_undo_attach (edit_widget, focus_tracker);
 }
 
+void
+e_comp_editor_property_part_string_set_is_multivalue (ECompEditorPropertyPartString *part_string,
+                                                     gboolean is_multivalue)
+{
+       g_return_if_fail (E_IS_COMP_EDITOR_PROPERTY_PART_STRING (part_string));
+
+       part_string->priv->is_multivalue = is_multivalue;
+}
+
+gboolean
+e_comp_editor_property_part_string_is_multivalue (ECompEditorPropertyPartString *part_string)
+{
+       g_return_val_if_fail (E_IS_COMP_EDITOR_PROPERTY_PART_STRING (part_string), FALSE);
+
+       return part_string->priv->is_multivalue;
+}
+
 /* ************************************************************************* */
 
 struct _ECompEditorPropertyPartDatetimePrivate {
diff --git a/src/calendar/gui/e-comp-editor-property-part.h b/src/calendar/gui/e-comp-editor-property-part.h
index 0435f2a..b504e3b 100644
--- a/src/calendar/gui/e-comp-editor-property-part.h
+++ b/src/calendar/gui/e-comp-editor-property-part.h
@@ -224,6 +224,11 @@ GType              e_comp_editor_property_part_string_get_type     (void) G_GNUC_CONST;
 void           e_comp_editor_property_part_string_attach_focus_tracker
                                                                (ECompEditorPropertyPartString *part_string,
                                                                 EFocusTracker *focus_tracker);
+void           e_comp_editor_property_part_string_set_is_multivalue
+                                                               (ECompEditorPropertyPartString *part_string,
+                                                                gboolean is_multivalue);
+gboolean       e_comp_editor_property_part_string_is_multivalue
+                                                               (ECompEditorPropertyPartString *part_string);
 
 /* ************************************************************************* */
 
diff --git a/src/calendar/gui/e-comp-editor-property-parts.c b/src/calendar/gui/e-comp-editor-property-parts.c
index adbec6d..8bf8b00 100644
--- a/src/calendar/gui/e-comp-editor-property-parts.c
+++ b/src/calendar/gui/e-comp-editor-property-parts.c
@@ -471,6 +471,8 @@ ecepp_categories_create_widgets (ECompEditorPropertyPart *property_part,
 static void
 e_comp_editor_property_part_categories_init (ECompEditorPropertyPartCategories *part_categories)
 {
+       e_comp_editor_property_part_string_set_is_multivalue (
+               E_COMP_EDITOR_PROPERTY_PART_STRING (part_categories), TRUE);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]