[evolution] Bug 769044 - Customized timezones not recognized



commit ab4689b096ee8b355065cebc1bea2742c98b666c
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 4 15:57:43 2016 +0200

    Bug 769044 - Customized timezones not recognized

 calendar/gui/e-comp-editor-event.c |   75 +++++++++++++++++++++++++++++------
 calendar/gui/e-comp-editor.c       |    6 +-
 calendar/gui/e-comp-editor.h       |    3 +-
 e-util/e-timezone-dialog.c         |   41 +++++++++++++++++++
 4 files changed, 107 insertions(+), 18 deletions(-)
---
diff --git a/calendar/gui/e-comp-editor-event.c b/calendar/gui/e-comp-editor-event.c
index 182cb7b..78a43dc 100644
--- a/calendar/gui/e-comp-editor-event.c
+++ b/calendar/gui/e-comp-editor-event.c
@@ -258,28 +258,33 @@ ece_event_get_timezone_from_property (ECompEditor *comp_editor,
 }
 
 static void
-ece_event_fill_widgets (ECompEditor *comp_editor,
-                       icalcomponent *component)
+ece_event_update_timezone (ECompEditorEvent *event_editor,
+                          struct icaltimetype *out_dtstart,
+                          struct icaltimetype *out_dtend)
 {
-       ECompEditorEvent *event_editor;
+       ECompEditor *comp_editor;
        struct icaltimetype dtstart, dtend;
-       icalproperty *prop;
+       icalcomponent *component;
        icaltimezone *zone = NULL;
-       gboolean all_day_event = FALSE;
-       GtkAction *action;
-       guint32 flags;
-
-       g_return_if_fail (E_IS_COMP_EDITOR_EVENT (comp_editor));
-       g_return_if_fail (component != NULL);
 
-       E_COMP_EDITOR_CLASS (e_comp_editor_event_parent_class)->fill_widgets (comp_editor, component);
+       g_return_if_fail (E_IS_COMP_EDITOR_EVENT (event_editor));
 
-       event_editor = E_COMP_EDITOR_EVENT (comp_editor);
+       comp_editor = E_COMP_EDITOR (event_editor);
 
-       flags = e_comp_editor_get_flags (comp_editor);
        dtstart = icaltime_null_time ();
        dtend = icaltime_null_time ();
 
+       component = e_comp_editor_get_component (comp_editor);
+       if (!component) {
+               if (out_dtstart)
+                       *out_dtstart = dtstart;
+
+               if (out_dtend)
+                       *out_dtend = dtend;
+
+               return;
+       }
+
        if (icalcomponent_get_first_property (component, ICAL_DTSTART_PROPERTY)) {
                dtstart = icalcomponent_get_dtstart (component);
                if (icaltime_is_valid_time (dtstart)) {
@@ -331,6 +336,37 @@ ece_event_fill_widgets (ECompEditor *comp_editor,
                }
        }
 
+       if (out_dtstart)
+               *out_dtstart = dtstart;
+
+       if (out_dtend)
+               *out_dtend = dtend;
+}
+
+static void
+ece_event_fill_widgets (ECompEditor *comp_editor,
+                       icalcomponent *component)
+{
+       ECompEditorEvent *event_editor;
+       struct icaltimetype dtstart, dtend;
+       icalproperty *prop;
+       gboolean all_day_event = FALSE;
+       GtkAction *action;
+       guint32 flags;
+
+       g_return_if_fail (E_IS_COMP_EDITOR_EVENT (comp_editor));
+       g_return_if_fail (component != NULL);
+
+       E_COMP_EDITOR_CLASS (e_comp_editor_event_parent_class)->fill_widgets (comp_editor, component);
+
+       event_editor = E_COMP_EDITOR_EVENT (comp_editor);
+
+       flags = e_comp_editor_get_flags (comp_editor);
+       dtstart = icaltime_null_time ();
+       dtend = icaltime_null_time ();
+
+       ece_event_update_timezone (event_editor, &dtstart, &dtend);
+
        if (icaltime_is_valid_time (dtstart) && !icaltime_is_null_time (dtstart) &&
            (!icaltime_is_valid_time (dtend) || icaltime_is_null_time (dtend))) {
                dtend = dtstart;
@@ -505,6 +541,16 @@ ece_event_fill_component (ECompEditor *comp_editor,
 }
 
 static void
+ece_event_notify_source_client_cb (GObject *object,
+                                  GParamSpec *param,
+                                  gpointer user_data)
+{
+       g_return_if_fail (E_IS_COMP_EDITOR_EVENT (object));
+
+       ece_event_update_timezone (E_COMP_EDITOR_EVENT (object), NULL, NULL);
+}
+
+static void
 ece_event_setup_ui (ECompEditorEvent *event_editor)
 {
        const gchar *ui =
@@ -786,6 +832,9 @@ e_comp_editor_event_constructed (GObject *object)
        e_binding_bind_property (widget, "text", comp_editor, "title-suffix", 0);
        /* Do this as the last thing, because some widgets can call the function as well */
        gtk_widget_grab_focus (widget);
+
+       g_signal_connect (comp_editor, "notify::source-client",
+               G_CALLBACK (ece_event_notify_source_client_cb), NULL);
 }
 
 static void
diff --git a/calendar/gui/e-comp-editor.c b/calendar/gui/e-comp-editor.c
index e58a78d..469ba8e 100644
--- a/calendar/gui/e-comp-editor.c
+++ b/calendar/gui/e-comp-editor.c
@@ -1396,7 +1396,7 @@ ece_print_or_preview (ECompEditor *comp_editor,
        g_return_if_fail (E_IS_COMP_EDITOR (comp_editor));
        g_return_if_fail (e_comp_editor_get_component (comp_editor) != NULL);
 
-       component = icalcomponent_new_clone ((icalcomponent *) e_comp_editor_get_component (comp_editor));
+       component = icalcomponent_new_clone (e_comp_editor_get_component (comp_editor));
        if (!e_comp_editor_fill_component (comp_editor, component)) {
                icalcomponent_free (component);
                return;
@@ -1865,7 +1865,7 @@ e_comp_editor_get_property (GObject *object,
                case PROP_COMPONENT:
                        g_value_set_pointer (
                                value,
-                               (gpointer) e_comp_editor_get_component (
+                               e_comp_editor_get_component (
                                E_COMP_EDITOR (object)));
                        return;
 
@@ -2692,7 +2692,7 @@ e_comp_editor_get_origin_source (ECompEditor *comp_editor)
        return comp_editor->priv->origin_source;
 }
 
-const icalcomponent *
+icalcomponent *
 e_comp_editor_get_component (ECompEditor *comp_editor)
 {
        g_return_val_if_fail (E_IS_COMP_EDITOR (comp_editor), NULL);
diff --git a/calendar/gui/e-comp-editor.h b/calendar/gui/e-comp-editor.h
index ac0d4c9..f5876c4 100644
--- a/calendar/gui/e-comp-editor.h
+++ b/calendar/gui/e-comp-editor.h
@@ -104,8 +104,7 @@ void                e_comp_editor_set_validation_error
 EShell *       e_comp_editor_get_shell         (ECompEditor *comp_editor);
 GSettings *    e_comp_editor_get_settings      (ECompEditor *comp_editor);
 ESource *      e_comp_editor_get_origin_source (ECompEditor *comp_editor);
-const icalcomponent *
-               e_comp_editor_get_component     (ECompEditor *comp_editor);
+icalcomponent *        e_comp_editor_get_component     (ECompEditor *comp_editor);
 guint32                e_comp_editor_get_flags         (ECompEditor *comp_editor);
 void           e_comp_editor_set_flags         (ECompEditor *comp_editor,
                                                 guint32 flags);
diff --git a/e-util/e-timezone-dialog.c b/e-util/e-timezone-dialog.c
index c4a56ed..297ac97 100644
--- a/e-util/e-timezone-dialog.c
+++ b/e-util/e-timezone-dialog.c
@@ -62,6 +62,9 @@ struct _ETimezoneDialogPrivate {
         * the displayed name is ""). */
        icaltimezone *zone;
 
+       /* In case a non-builtin timezone is used. */
+       GSList *custom_zones; /* icaltimezone * */
+
        GtkBuilder *builder;
 
        EMapPoint *point_selected;
@@ -164,6 +167,9 @@ e_timezone_dialog_dispose (GObject *object)
                priv->index = NULL;
        }
 
+       g_slist_free (priv->custom_zones);
+       priv->custom_zones = NULL;
+
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_timezone_dialog_parent_class)->dispose (object);
 }
@@ -798,6 +804,27 @@ e_timezone_dialog_set_timezone (ETimezoneDialog *etd,
        if (zone)
                display = zone_display_name_with_offset (zone);
 
+       /* Add any unknown/custom timezone with defined location */
+       if (zone && icaltimezone_get_location (zone) &&
+           !g_hash_table_lookup (etd->priv->index, icaltimezone_get_location (zone))) {
+               GtkTreeStore *tree_store;
+               GtkTreeIter *piter, iter;
+               const gchar *location;
+
+               location = icaltimezone_get_location (zone);
+               tree_store = GTK_TREE_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX 
(etd->priv->timezone_combo)));
+
+               gtk_tree_store_prepend (tree_store, &iter, NULL);
+               gtk_tree_store_set (tree_store, &iter, 0, (gchar *) location, 1, (gchar *) location, -1);
+
+               piter = g_new (GtkTreeIter, 1);
+               *piter = iter;
+
+               g_hash_table_insert (etd->priv->index, (gchar *) location, piter);
+
+               etd->priv->custom_zones = g_slist_prepend (etd->priv->custom_zones, zone);
+       }
+
        priv = etd->priv;
 
        priv->zone = zone;
@@ -885,6 +912,20 @@ on_combo_changed (GtkComboBox *combo_box,
                                break;
                        }
                }
+
+               if (!priv->zone) {
+                       GSList *link;
+
+                       for (link = priv->custom_zones; link; link = g_slist_next (link)) {
+                               icaltimezone *zone = link->data;
+
+                               if (zone && g_utf8_collate (new_zone_name, _(icaltimezone_get_location 
(zone))) == 0) {
+                                       map_zone = zone;
+                                       priv->zone = zone;
+                                       break;
+                               }
+                       }
+               }
        }
 
        set_map_timezone (etd, map_zone);


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