diff options
author | Milan Crha <mcrha@redhat.com> | 2011-12-14 18:52:51 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2011-12-14 18:53:38 +0800 |
commit | 737ad1158fd44e7f8e9231b20ed83bae44c41609 (patch) | |
tree | cc1a7495b758ebd41328c6d2e38ca4ce58c6c30b /calendar | |
parent | 26def2a624952219840990f83397a7bb5add49bf (diff) | |
download | gsoc2013-evolution-737ad1158fd44e7f8e9231b20ed83bae44c41609.tar.gz gsoc2013-evolution-737ad1158fd44e7f8e9231b20ed83bae44c41609.tar.zst gsoc2013-evolution-737ad1158fd44e7f8e9231b20ed83bae44c41609.zip |
Bug #666106 - libical 0.47 handles CATEGORIES as multiple parameters
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/gui/e-cal-model.c | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c index fb9898775b..c1ff096208 100644 --- a/calendar/gui/e-cal-model.c +++ b/calendar/gui/e-cal-model.c @@ -41,6 +41,10 @@ #include "e-util/e-account-utils.h" #include "e-util/e-util-enumtypes.h" +struct _ECalModelComponentPrivate { + GString *categories_str; +}; + typedef struct { ECalClient *client; ECalClientView *view; @@ -747,13 +751,25 @@ ecm_row_count (ETableModel *etm) static gpointer get_categories (ECalModelComponent *comp_data) { - icalproperty *prop; + if (!comp_data->priv->categories_str) { + icalproperty *prop; - prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CATEGORIES_PROPERTY); - if (prop) - return (gpointer) icalproperty_get_categories (prop); + comp_data->priv->categories_str = g_string_new (""); - return (gpointer) ""; + for (prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CATEGORIES_PROPERTY); + prop; + prop = icalcomponent_get_next_property (comp_data->icalcomp, ICAL_CATEGORIES_PROPERTY)) { + const gchar *categories = icalproperty_get_categories (prop); + if (!categories) + continue; + + if (comp_data->priv->categories_str->len) + g_string_append_c (comp_data->priv->categories_str, ','); + g_string_append (comp_data->priv->categories_str, categories); + } + } + + return comp_data->priv->categories_str->str; } static gchar * @@ -1023,18 +1039,26 @@ set_categories (ECalModelComponent *comp_data, { icalproperty *prop; + /* remove all categories first */ prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CATEGORIES_PROPERTY); - if (!value || !(*value)) { - if (prop) { - icalcomponent_remove_property (comp_data->icalcomp, prop); - icalproperty_free (prop); - } - } else { - if (!prop) { - prop = icalproperty_new_categories (value); - icalcomponent_add_property (comp_data->icalcomp, prop); - } else - icalproperty_set_categories (prop, value); + while (prop) { + icalproperty *to_remove = prop; + prop = icalcomponent_get_next_property (comp_data->icalcomp, ICAL_CATEGORIES_PROPERTY); + + icalcomponent_remove_property (comp_data->icalcomp, to_remove); + icalproperty_free (to_remove); + } + + if (comp_data->priv->categories_str) + g_string_free (comp_data->priv->categories_str, TRUE); + comp_data->priv->categories_str = NULL; + + /* then set a new value; no need to populate categories_str, + it'll be populated on demand (in the get_categories() function) + */ + if (value && *value) { + prop = icalproperty_new_categories (value); + icalcomponent_add_property (comp_data->icalcomp, prop); } } @@ -3617,10 +3641,6 @@ copy_ecdv (ECellDateEditValue *ecdv) return new_ecdv; } */ -struct _ECalModelComponentPrivate { - gchar nouse; -}; - static void e_cal_model_component_finalize (GObject *object); static GObjectClass *component_parent_class; @@ -3632,6 +3652,7 @@ e_cal_model_component_class_init (ECalModelComponentClass *class) GObjectClass *object_class; object_class = (GObjectClass *) class; + g_type_class_add_private (class, sizeof (ECalModelComponentPrivate)); component_parent_class = g_type_class_peek_parent (class); @@ -3680,6 +3701,10 @@ e_cal_model_component_finalize (GObject *object) comp_data->color = NULL; } + if (comp_data->priv->categories_str) + g_string_free (comp_data->priv->categories_str, TRUE); + comp_data->priv->categories_str = NULL; + /* Chain up to parent's finalize() method. */ G_OBJECT_CLASS (component_parent_class)->finalize (object); } @@ -3688,6 +3713,9 @@ e_cal_model_component_finalize (GObject *object) static void e_cal_model_component_init (ECalModelComponent *comp) { + comp->priv = G_TYPE_INSTANCE_GET_PRIVATE ( + comp, E_TYPE_CAL_MODEL_COMPONENT, ECalModelComponentPrivate); + comp->dtstart = NULL; comp->dtend = NULL; comp->due = NULL; @@ -3695,6 +3723,7 @@ e_cal_model_component_init (ECalModelComponent *comp) comp->created = NULL; comp->lastmodified = NULL; comp->color = NULL; + comp->priv->categories_str = NULL; } GType |