aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/e-timezone-dialog/e-timezone-dialog.c
blob: fa2b994012af6310b21d74a706679685747fdc4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* Evolution calendar - Timezone selector dialog
 *
 * Copyright (C) 2001 Ximian, Inc.
 *
 * Authors: Damon Chaplin <damon@ximian.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkcombo.h>
#include <gtk/gtkentry.h>
#include <gtk/gtklabel.h>
#include <gnome.h>
#include <glade/glade.h>
#include <widgets/misc/e-map.h>
#include "e-timezone-dialog.h"

#define E_TIMEZONE_DIALOG_MAP_POINT_NORMAL_RGBA 0xc070a0ff
#define E_TIMEZONE_DIALOG_MAP_POINT_HOVER_RGBA 0xffff60ff
#define E_TIMEZONE_DIALOG_MAP_POINT_SELECTED_1_RGBA 0xff60e0ff
#define E_TIMEZONE_DIALOG_MAP_POINT_SELECTED_2_RGBA 0x000000ff

struct _ETimezoneDialogPrivate {
    /* The TZID of the timezone. May be NULL for a 'local time' (i.e. when
       the displayed name is "") or for builtin timezones which we haven't
       loaded yet. */
    char *tzid;

    /* Glade XML data */
    GladeXML *xml;

    EMapPoint *point_selected;
    EMapPoint *point_hover;

    EMap *map;

    /* The timeout used to flash the nearest point. */
    guint timeout_id;

    /* Widgets from the Glade file */
    GtkWidget *app;
    GtkWidget *table;
    GtkWidget *map_window;
    GtkWidget *timezone_preview;
    GtkWidget *timezone_combo;
};


static void e_timezone_dialog_class_init    (ETimezoneDialogClass *class);
static void e_timezone_dialog_init      (ETimezoneDialog      *etd);
static void e_timezone_dialog_destroy       (GtkObject  *object);

static gboolean get_widgets         (ETimezoneDialog *etd);
static gboolean on_map_timeout          (gpointer    data);
static gboolean on_map_motion           (GtkWidget  *widget,
                         GdkEventMotion *event,
                         gpointer    data);
static gboolean on_map_leave            (GtkWidget  *widget,
                         GdkEventCrossing *event,
                         gpointer    data);
static gboolean on_map_visibility_changed   (GtkWidget  *w,
                         GdkEventVisibility *event,
                         gpointer    data);
static gboolean on_map_button_pressed       (GtkWidget  *w,
                         GdkEventButton *event,
                         gpointer    data);

static char*    get_zone_from_point     (ETimezoneDialog *etd,
                         EMapPoint  *point);
static void find_selected_point     (ETimezoneDialog *etd);
static void on_combo_changed        (GtkEditable    *entry,
                         ETimezoneDialog *etd);


static GtkObjectClass *parent_class;


GtkType
e_timezone_dialog_get_type (void)
{
    static GtkType e_timezone_dialog_type = 0;

    if (!e_timezone_dialog_type) {
        static const GtkTypeInfo e_timezone_dialog_info = {
            "ETimezoneDialog",
            sizeof (ETimezoneDialog),
            sizeof (ETimezoneDialogClass),
            (GtkClassInitFunc) e_timezone_dialog_class_init,
            (GtkObjectInitFunc) e_timezone_dialog_init,
            NULL, /* reserved_1 */
            NULL, /* reserved_2 */
            (GtkClassInitFunc) NULL
        };

        e_timezone_dialog_type = gtk_type_unique (GTK_TYPE_OBJECT,
                              &e_timezone_dialog_info);
    }

    return e_timezone_dialog_type;
}

/* Class initialization function for the event editor */
static void
e_timezone_dialog_class_init (ETimezoneDialogClass *class)
{
    GtkObjectClass *object_class;

    object_class = (GtkObjectClass *) class;

    parent_class = gtk_type_class (GTK_TYPE_OBJECT);

    object_class->destroy = e_timezone_dialog_destroy;
}

/* Object initialization function for the event editor */
static void
e_timezone_dialog_init (ETimezoneDialog *etd)
{
    ETimezoneDialogPrivate *priv;

    GTK_OBJECT_UNSET_FLAGS (etd, GTK_FLOATING);

    priv = g_new0 (ETimezoneDialogPrivate, 1);
    etd->priv = priv;

    priv->tzid = NULL;
    priv->point_selected = NULL;
    priv->point_hover = NULL;
    priv->timeout_id = 0;
}

/* Destroy handler for the event editor */
static void
e_timezone_dialog_destroy (GtkObject *object)
{
    ETimezoneDialog *etd;
    ETimezoneDialogPrivate *priv;
    GtkWidget *dialog;

    g_return_if_fail (object != NULL);
    g_return_if_fail (E_IS_TIMEZONE_DIALOG (object));

    etd = E_TIMEZONE_DIALOG (object);
    priv = etd->priv;

    /* Destroy the actual dialog. */
    dialog = e_timezone_dialog_get_toplevel (etd);
    gtk_widget_destroy (dialog);

    g_free (priv->tzid);
    priv->tzid = NULL;

    if (priv->timeout_id) {
        g_source_remove (priv->timeout_id);
        priv->timeout_id = 0;
    }

    if (priv->xml) {
        gtk_object_unref (GTK_OBJECT (priv->xml));
        priv->xml = NULL;
    }

    g_free (priv);
    etd->priv = NULL;

    if (GTK_OBJECT_CLASS (parent_class)->destroy)
        (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}


static void
e_timezone_dialog_add_timezones (ETimezoneDialog *etd)
{
    ETimezoneDialogPrivate *priv;
    icalarray *zones;
    GtkWidget *listitem;
    GtkCombo *combo;
    int i;

    priv = etd->priv;

    combo = GTK_COMBO (priv->timezone_combo);

    /* Clear any existing items in the combo. */
    gtk_list_clear_items (GTK_LIST (combo->list), 0, -1);

    /* Put the "None" and "UTC" entries at the top of the combo's list.
       When "None" is selected we want the field to be cleared. */
    listitem = gtk_list_item_new_with_label (_("None"));
    gtk_combo_set_item_string (combo, GTK_ITEM (listitem), "");
    gtk_widget_show (listitem);
    gtk_container_add (GTK_CONTAINER (combo->list), listitem);

    listitem = gtk_list_item_new_with_label (_("UTC"));
    gtk_widget_show (listitem);
    gtk_container_add (GTK_CONTAINER (combo->list), listitem);

    /* Get the array of builtin timezones. */
    zones = icaltimezone_get_builtin_timezones ();

    for (i = 0; i < zones->num_elements; i++) {
        icaltimezone *zone;
        char *location;

        zone = icalarray_element_at (zones, i);

        location = _(icaltimezone_get_location (zone));

        e_map_add_point (priv->map, location,
                 icaltimezone_get_longitude (zone),
                 icaltimezone_get_latitude (zone),
                 E_TIMEZONE_DIALOG_MAP_POINT_NORMAL_RGBA);

        listitem = gtk_list_item_new_with_label (location);
        gtk_widget_show (listitem);
        gtk_container_add (GTK_CONTAINER (combo->list), listitem);
    }
}


ETimezoneDialog *
e_timezone_dialog_construct (ETimezoneDialog *etd)
{
    ETimezoneDialogPrivate *priv;
    GtkWidget *map;

    g_return_val_if_fail (etd != NULL, NULL);
    g_return_val_if_fail (E_IS_TIMEZONE_DIALOG (etd), NULL);

    priv = etd->priv;

    /* Load the content widgets */

    priv->xml = glade_xml_new (EVOLUTION_GLADEDIR "/e-timezone-dialog.glade", NULL, NULL);
    if (!priv->xml) {
        g_message ("e_timezone_dialog_construct(): Could not load the Glade XML file!");
        goto error;
    }

    if (!get_widgets (etd)) {
        g_message ("e_timezone_dialog_construct(): Could not find all widgets in the XML file!");
        goto error;
    }

    map = GTK_WIDGET (e_map_new ());
    priv->map = E_MAP (map);
    gtk_widget_set_events (map, gtk_widget_get_events (map)
                   | GDK_LEAVE_NOTIFY_MASK
                   | GDK_VISIBILITY_NOTIFY_MASK);

    gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (priv->timezone_combo)->entry), FALSE);

    e_timezone_dialog_add_timezones (etd);

    gtk_container_add (GTK_CONTAINER (priv->map_window), map);
    gtk_widget_show (map);

        gtk_signal_connect (GTK_OBJECT (map), "motion-notify-event",
                GTK_SIGNAL_FUNC (on_map_motion), etd);
        gtk_signal_connect (GTK_OBJECT (map), "leave-notify-event",
                GTK_SIGNAL_FUNC (on_map_leave), etd);
        gtk_signal_connect (GTK_OBJECT (map), "visibility-notify-event",
                GTK_SIGNAL_FUNC (on_map_visibility_changed), etd);
    gtk_signal_connect (GTK_OBJECT (map), "button-press-event",
                GTK_SIGNAL_FUNC (on_map_button_pressed), etd);

    gtk_signal_connect (GTK_OBJECT (GTK_COMBO (priv->timezone_combo)->entry), "changed", 
                GTK_SIGNAL_FUNC (on_combo_changed), etd);

    return etd;

 error:

    gtk_object_unref (GTK_OBJECT (etd));
    return NULL;
}

/* Gets the widgets from the XML file and returns if they are all available.
 * For the widgets whose values can be simply set with e-dialog-utils, it does
 * that as well.
 */
static gboolean
get_widgets (ETimezoneDialog *etd)
{
    ETimezoneDialogPrivate *priv;

    priv = etd->priv;

#define GW(name) glade_xml_get_widget (priv->xml, name)

    priv->app       = GW ("timezone-dialog");
    priv->map_window    = GW ("map-window");
    priv->timezone_combo    = GW ("timezone-combo");
    priv->timezone_preview  = GW ("timezone-preview");
    priv->table             = GW ("table1");

    return (priv->app
        && priv->map_window
        && priv->timezone_combo
        && priv->timezone_preview
        && priv->table);
}


/**
 * e_timezone_dialog_new:
 *
 * Creates a new event editor dialog.
 *
 * Return value: A newly-created event editor dialog, or NULL if the event
 * editor could not be created.
 **/
ETimezoneDialog *
e_timezone_dialog_new (void)
{
    ETimezoneDialog *etd;

    etd = E_TIMEZONE_DIALOG (gtk_type_new (E_TYPE_TIMEZONE_DIALOG));
    return e_timezone_dialog_construct (E_TIMEZONE_DIALOG (etd));
}



/* This flashes the currently selected timezone in the map. */
static gboolean
on_map_timeout (gpointer data)
{
    ETimezoneDialog *etd;
    ETimezoneDialogPrivate *priv;

    etd = E_TIMEZONE_DIALOG (data);
    priv = etd->priv;

    if (!priv->point_selected)
        return TRUE;

        if (e_map_point_get_color_rgba (priv->point_selected)
        == E_TIMEZONE_DIALOG_MAP_POINT_SELECTED_1_RGBA)
            e_map_point_set_color_rgba (priv->map, priv->point_selected,
                        E_TIMEZONE_DIALOG_MAP_POINT_SELECTED_2_RGBA);
    else
            e_map_point_set_color_rgba (priv->map, priv->point_selected,
                        E_TIMEZONE_DIALOG_MAP_POINT_SELECTED_1_RGBA);

    return TRUE;
}


static gboolean
on_map_motion (GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
    ETimezoneDialog *etd;
    ETimezoneDialogPrivate *priv;
    double longitude, latitude;
    char *old_zone, *new_zone;

    etd = E_TIMEZONE_DIALOG (data);
    priv = etd->priv;

    e_map_window_to_world (priv->map, (double) event->x, (double) event->y,
                   &longitude, &latitude);

    if (priv->point_hover && priv->point_hover != priv->point_selected)
            e_map_point_set_color_rgba (priv->map, priv->point_hover,
                        E_TIMEZONE_DIALOG_MAP_POINT_NORMAL_RGBA);

    priv->point_hover = e_map_get_closest_point (priv->map, longitude,
                             latitude, TRUE);

    if (priv->point_hover != priv->point_selected)
            e_map_point_set_color_rgba (priv->map, priv->point_hover,
                        E_TIMEZONE_DIALOG_MAP_POINT_HOVER_RGBA);

    gtk_label_get (GTK_LABEL (priv->timezone_preview), &old_zone);
    new_zone = get_zone_from_point (etd, priv->point_hover);
    if (strcmp (old_zone, new_zone))
        gtk_label_set_text (GTK_LABEL (priv->timezone_preview),
                    new_zone);

    return TRUE;
}


static gboolean
on_map_leave (GtkWidget *widget, GdkEventCrossing *event, gpointer data)
{
    ETimezoneDialog *etd;
    ETimezoneDialogPrivate *priv;
    char *old_zone;

    etd = E_TIMEZONE_DIALOG (data);
    priv = etd->priv;

    /* We only want to reset the hover point and the preview text if this
       is a normal leave event. For some reason we are getting leave events
       when the button is pressed in the map, which causes problems. */
    if (event->mode != GDK_CROSSING_NORMAL)
        return FALSE;

    if (priv->point_hover && priv->point_hover != priv->point_selected)
            e_map_point_set_color_rgba (priv->map, priv->point_hover,
                        E_TIMEZONE_DIALOG_MAP_POINT_NORMAL_RGBA);

    priv->point_hover = NULL;

    /* Clear the timezone preview label, if it isn't already empty. */
    gtk_label_get (GTK_LABEL (priv->timezone_preview), &old_zone);
    if (strcmp (old_zone, ""))
        gtk_label_set_text (GTK_LABEL (priv->timezone_preview), "");

    return FALSE;
}


static gboolean
on_map_visibility_changed (GtkWidget *w, GdkEventVisibility *event,
               gpointer data)
{
    ETimezoneDialog *etd;
    ETimezoneDialogPrivate *priv;
    
    etd = E_TIMEZONE_DIALOG (data);
    priv = etd->priv;

    if (event->state != GDK_VISIBILITY_FULLY_OBSCURED) {
        /* Map is visible, at least partly, so make sure we flash the
           selected point. */
        if (!priv->timeout_id)
            priv->timeout_id = gtk_timeout_add (100, on_map_timeout, etd);
    } else {
        /* Map is invisible, so don't waste resources on the timeout.*/
        if (priv->timeout_id) {
            g_source_remove (priv->timeout_id);
            priv->timeout_id = 0;
        }
    }

    return FALSE;
}


static gboolean
on_map_button_pressed (GtkWidget *w, GdkEventButton *event, gpointer data)
{
    ETimezoneDialog *etd;
    ETimezoneDialogPrivate *priv;
    double longitude, latitude;
    char *location;
    
    etd = E_TIMEZONE_DIALOG (data);
    priv = etd->priv;

    e_map_window_to_world (priv->map, (double) event->x, (double) event->y,
                   &longitude, &latitude);
    
    if (event->button != 1) {
            e_map_zoom_out (priv->map);
    } else {
        if (e_map_get_magnification (priv->map) <= 1.0)
                e_map_zoom_to_location (priv->map, longitude,
                        latitude);
    
        if (priv->point_selected)
                e_map_point_set_color_rgba (priv->map,
                            priv->point_selected,
                            E_TIMEZONE_DIALOG_MAP_POINT_NORMAL_RGBA);
        priv->point_selected = priv->point_hover;
        
        location = get_zone_from_point (etd, priv->point_selected);
        gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (priv->timezone_combo)->entry),
                    location);

        g_free (priv->tzid);
        priv->tzid = NULL;
    }
    
    return TRUE;
}


/* Returns the translated timezone location of the fiven EMapPoint,
   e.g. "Europe/London", in the current locale's encoding (not UTF-8). */
static char*
get_zone_from_point (ETimezoneDialog *etd,
             EMapPoint *point)
{
    ETimezoneDialogPrivate *priv;
    icalarray *zones;
    double longitude, latitude;
    int i;

    priv = etd->priv;

    if (point == NULL)
        return "";

    e_map_point_get_location (point, &longitude, &latitude);

    /* Get the array of builtin timezones. */
    zones = icaltimezone_get_builtin_timezones ();

    for (i = 0; i < zones->num_elements; i++) {
        icaltimezone *zone;
        double zone_longitude, zone_latitude;

        zone = icalarray_element_at (zones, i);
        zone_longitude = icaltimezone_get_longitude (zone);
        zone_latitude = icaltimezone_get_latitude (zone);

        if (zone_longitude - 0.005 <= longitude &&
            zone_longitude + 0.005 >= longitude &&
            zone_latitude - 0.005 <= latitude &&
            zone_latitude + 0.005 >= latitude)
        {
            return _(icaltimezone_get_location (zone));
        }
    }

    g_assert_not_reached ();

    return NULL;
}


/* Returns the TZID of the timezone set, and optionally its displayed name.
   The TZID may be NULL, in which case the builtin timezone with the city name
   of display_name should be used. If display_name is also NULL or "", then it
   is assumed to be a 'local time'. Note that display_name may be translated,
   so you need to convert it back to English before trying to load it. 
   It will be in the GTK+ encoding, i.e. not UTF-8. */
char*
e_timezone_dialog_get_timezone      (ETimezoneDialog  *etd,
                     const char **display_name)
{
    ETimezoneDialogPrivate *priv;

    g_return_val_if_fail (etd != NULL, NULL);
    g_return_val_if_fail (E_IS_TIMEZONE_DIALOG (etd), NULL);

    priv = etd->priv;

    if (display_name)
        *display_name = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (priv->timezone_combo)->entry));

    return priv->tzid;
}


/* Sets the TZID and displayed name of the timezone. The TZID may be NULL for
   a 'local time' (i.e. display_name is NULL or "") or if it is a builtin
   timezone which hasn't been loaded yet. (This is done so we don't load
   timezones until we really need them.) The display_name should be the
   translated name in the GTK+ - it will be displayed exactly as it is. */
void
e_timezone_dialog_set_timezone      (ETimezoneDialog  *etd,
                     char         *tzid,
                     char         *display_name)
{
    ETimezoneDialogPrivate *priv;

    g_return_if_fail (etd != NULL);
    g_return_if_fail (E_IS_TIMEZONE_DIALOG (etd));

    priv = etd->priv;

    if (priv->tzid)
        g_free (priv->tzid);

    priv->tzid = g_strdup (tzid);

    gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (priv->timezone_combo)->entry),
                display_name ? display_name : "");

    find_selected_point (etd);
}


GtkWidget *
e_timezone_dialog_get_toplevel  (ETimezoneDialog  *etd)
{
    ETimezoneDialogPrivate *priv;

    g_return_val_if_fail (etd != NULL, NULL);
    g_return_val_if_fail (E_IS_TIMEZONE_DIALOG (etd), NULL);

    priv = etd->priv;

    return priv->app;
}


/* This tries to find the timezone corresponding to the text in the combo,
   and selects the point so that it flashes. */
static void
find_selected_point (ETimezoneDialog *etd)
{
    ETimezoneDialogPrivate *priv;
    icalarray *zones;
    const char *current_zone;
    EMapPoint *point = NULL;
    int i;

    priv = etd->priv;

    current_zone = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (priv->timezone_combo)->entry));

    /* Get the array of builtin timezones. */
    zones = icaltimezone_get_builtin_timezones ();

    for (i = 0; i < zones->num_elements; i++) {
        icaltimezone *zone;
        char *location;

        zone = icalarray_element_at (zones, i);

        location = _(icaltimezone_get_location (zone));

        if (!strcmp (current_zone, location)) {
            double zone_longitude, zone_latitude;

            zone_longitude = icaltimezone_get_longitude (zone);
            zone_latitude = icaltimezone_get_latitude (zone);

            point = e_map_get_closest_point (priv->map,
                             zone_longitude,
                             zone_latitude,
                             FALSE);
            break;
        }
    }

    if (priv->point_selected)
        e_map_point_set_color_rgba (priv->map, priv->point_selected,
                        E_TIMEZONE_DIALOG_MAP_POINT_NORMAL_RGBA);

    priv->point_selected = point;
}


static void
on_combo_changed (GtkEditable *entry, ETimezoneDialog *etd)
{
    ETimezoneDialogPrivate *priv;

    priv = etd->priv;

    find_selected_point (etd);

    g_free (priv->tzid);
    priv->tzid = NULL;
}

/**
 * e_timezone_dialog_reparent:
 * @etd: #ETimezoneDialog.
 * @new_parent: The new parent widget.
 *
 * Takes the internal widgets out of the dialog and put them into @new_parent
 */
void
e_timezone_dialog_reparent (ETimezoneDialog *etd,
                GtkWidget *new_parent)
{
    ETimezoneDialogPrivate *priv;

    priv = etd->priv;

    gtk_widget_reparent (priv->table, new_parent);
}


/* Returns the builtin timezone corresponding to display_name, which is
   the translated location, e.g. 'Europe/London', in the locale's encoding.
   If display_name is NULL or "" it returns NULL. */
icaltimezone*
e_timezone_dialog_get_builtin_timezone  (char         *display_name)
{
    icalarray *zones;
    int i;

    /* If the field is empty, return NULL (i.e. a floating time). */
    if (!display_name || !display_name[0])
        return NULL;

    /* Check for UTC. */
    if (!strcmp (display_name, _("UTC")))
        return icaltimezone_get_utc_timezone ();

    /* Get the array of builtin timezones. */
    zones = icaltimezone_get_builtin_timezones ();

    for (i = 0; i < zones->num_elements; i++) {
        icaltimezone *zone;
        char *location;

        zone = icalarray_element_at (zones, i);
        location = icaltimezone_get_location (zone);
        if (!strcmp (display_name, _(location)))
            return zone;
    }

    return NULL;
}