aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/dialogs/task-page.c
blob: d60ca5ba5be8694950cd34296e756057618b44c4 (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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
/* Evolution calendar - Main page of the task editor dialog
 *
 * Copyright (C) 2001 Ximian, Inc.
 *
 * Authors: Federico Mena-Quintero <federico@ximian.com>
 *          Miguel de Icaza <miguel@ximian.com>
 *          Seth Alves <alves@hungry.com>
 *          JP Rosevear <jpr@ximian.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include <gtk/gtksignal.h>
#include <gtk/gtktext.h>
#include <gtk/gtktogglebutton.h>
#include <gtk/gtkspinbutton.h>
#include <gtk/gtkoptionmenu.h>
#include <glade/glade.h>
#include <gal/widgets/e-unicode.h>
#include <gal/widgets/e-categories.h>
#include <widgets/misc/e-dateedit.h>
#include "e-util/e-dialog-widgets.h"
#include "e-util/e-categories-config.h"
#include "../e-timezone-entry.h"
#include "../calendar-config.h"
#include "comp-editor-util.h"
#include "task-page.h"



/* Private part of the TaskPage structure */
struct _TaskPagePrivate {
    /* Glade XML data */
    GladeXML *xml;

    /* Widgets from the Glade file */
    GtkWidget *main;

    GtkWidget *summary;

    GtkWidget *due_date;
    GtkWidget *start_date;
    GtkWidget *due_timezone;
    GtkWidget *start_timezone;

    GtkWidget *description;

    GtkWidget *classification_public;
    GtkWidget *classification_private;
    GtkWidget *classification_confidential;

    GtkWidget *contacts_btn;    
    GtkWidget *contacts_box;

    GtkWidget *categories_btn;
    GtkWidget *categories;

    gboolean updating;

    /* The Corba component for selecting contacts, and the entry field
       which we place in the dialog. */
    GNOME_Evolution_Addressbook_SelectNames corba_select_names;
    GtkWidget *contacts_entry;
};

static const int classification_map[] = {
    CAL_COMPONENT_CLASS_PUBLIC,
    CAL_COMPONENT_CLASS_PRIVATE,
    CAL_COMPONENT_CLASS_CONFIDENTIAL,
    -1
};



static void task_page_class_init (TaskPageClass *class);
static void task_page_init (TaskPage *tpage);
static void task_page_destroy (GtkObject *object);

static GtkWidget *task_page_get_widget (CompEditorPage *page);
static void task_page_focus_main_widget (CompEditorPage *page);
static void task_page_fill_widgets (CompEditorPage *page, CalComponent *comp);
static gboolean task_page_fill_component (CompEditorPage *page, CalComponent *comp);
static void task_page_set_summary (CompEditorPage *page, const char *summary);
static void task_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates);

static CompEditorPageClass *parent_class = NULL;



/**
 * task_page_get_type:
 * 
 * Registers the #TaskPage class if necessary, and returns the type ID
 * associated to it.
 * 
 * Return value: The type ID of the #TaskPage class.
 **/
GtkType
task_page_get_type (void)
{
    static GtkType task_page_type;

    if (!task_page_type) {
        static const GtkTypeInfo task_page_info = {
            "TaskPage",
            sizeof (TaskPage),
            sizeof (TaskPageClass),
            (GtkClassInitFunc) task_page_class_init,
            (GtkObjectInitFunc) task_page_init,
            NULL, /* reserved_1 */
            NULL, /* reserved_2 */
            (GtkClassInitFunc) NULL
        };

        task_page_type = gtk_type_unique (TYPE_COMP_EDITOR_PAGE,
                          &task_page_info);
    }

    return task_page_type;
}

/* Class initialization function for the task page */
static void
task_page_class_init (TaskPageClass *class)
{
    CompEditorPageClass *editor_page_class;
    GtkObjectClass *object_class;

    editor_page_class = (CompEditorPageClass *) class;
    object_class = (GtkObjectClass *) class;

    parent_class = gtk_type_class (TYPE_COMP_EDITOR_PAGE);

    editor_page_class->get_widget = task_page_get_widget;
    editor_page_class->focus_main_widget = task_page_focus_main_widget;
    editor_page_class->fill_widgets = task_page_fill_widgets;
    editor_page_class->fill_component = task_page_fill_component;
    editor_page_class->set_summary = task_page_set_summary;
    editor_page_class->set_dates = task_page_set_dates;

    object_class->destroy = task_page_destroy;
}

/* Object initialization function for the task page */
static void
task_page_init (TaskPage *tpage)
{
    TaskPagePrivate *priv;

    priv = g_new0 (TaskPagePrivate, 1);
    tpage->priv = priv;

    priv->xml = NULL;

    priv->main = NULL;
    priv->summary = NULL;
    priv->due_date = NULL;
    priv->start_date = NULL;
    priv->due_timezone = NULL;
    priv->start_timezone = NULL;
    priv->description = NULL;
    priv->classification_public = NULL;
    priv->classification_private = NULL;
    priv->classification_confidential = NULL;
    priv->contacts_btn = NULL;
    priv->contacts_box = NULL;
    priv->categories_btn = NULL;
    priv->categories = NULL;

    priv->updating = FALSE;

    priv->corba_select_names = CORBA_OBJECT_NIL;
    priv->contacts_entry = NULL;
}

/* Destroy handler for the task page */
static void
task_page_destroy (GtkObject *object)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;

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

    tpage = TASK_PAGE (object);
    priv = tpage->priv;

    if (priv->corba_select_names != CORBA_OBJECT_NIL) {
        CORBA_Environment ev;

        CORBA_exception_init (&ev);
        CORBA_Object_release (priv->corba_select_names, &ev);
        CORBA_exception_free (&ev);
    }

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

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

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



/* get_widget handler for the task page */
static GtkWidget *
task_page_get_widget (CompEditorPage *page)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;

    tpage = TASK_PAGE (page);
    priv = tpage->priv;

    return priv->main;
}

/* focus_main_widget handler for the task page */
static void
task_page_focus_main_widget (CompEditorPage *page)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;

    tpage = TASK_PAGE (page);
    priv = tpage->priv;

    gtk_widget_grab_focus (priv->summary);
}

/* Fills the widgets with default values */
static void
clear_widgets (TaskPage *tpage)
{
    TaskPagePrivate *priv;

    priv = tpage->priv;

    /* Summary, description */
    e_dialog_editable_set (priv->summary, NULL);
    e_dialog_editable_set (priv->description, NULL);

    /* Start, due times */
    e_date_edit_set_time (E_DATE_EDIT (priv->start_date), 0);
    e_date_edit_set_time (E_DATE_EDIT (priv->due_date), 0);

    /* Classification */
    e_dialog_radio_set (priv->classification_public,
                CAL_COMPONENT_CLASS_PRIVATE, classification_map);

    /* Categories */
    e_dialog_editable_set (priv->categories, NULL);
}

/* Decode the radio button group for classifications */
static CalComponentClassification
classification_get (GtkWidget *widget)
{
    return e_dialog_radio_get (widget, classification_map);
}

static void
contacts_changed_cb (BonoboListener    *listener,
             char              *event_name,
             CORBA_any         *arg,
             CORBA_Environment *ev,
             gpointer           data)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;
    
    tpage = TASK_PAGE (data);
    priv = tpage->priv;
    
    if (!priv->updating)
        comp_editor_page_notify_changed (COMP_EDITOR_PAGE (tpage));
}

/* fill_widgets handler for the task page */
static void
task_page_fill_widgets (CompEditorPage *page, CalComponent *comp)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;
    CalComponentText text;
    CalComponentDateTime d;
    CalComponentClassification cl;
    CalClientGetStatus get_tz_status;
    GSList *l;
    const char *categories;
    icaltimezone *zone;

    tpage = TASK_PAGE (page);
    priv = tpage->priv;

    priv->updating = TRUE;
    
    /* Clean the screen */
    clear_widgets (tpage);

        /* Summary, description(s) */
    cal_component_get_summary (comp, &text);
    e_dialog_editable_set (priv->summary, text.value);

    cal_component_get_description_list (comp, &l);
    if (l) {
        text = *(CalComponentText *)l->data;
        e_dialog_editable_set (priv->description, text.value);
    } else {
        e_dialog_editable_set (priv->description, NULL);
    }
    cal_component_free_text_list (l);

    /* Due Date. */
    cal_component_get_due (comp, &d);
    zone = NULL;
    if (d.value) {
        struct icaltimetype *due_tt = d.value;
        e_date_edit_set_date (E_DATE_EDIT (priv->due_date),
                      due_tt->year, due_tt->month,
                      due_tt->day);
        e_date_edit_set_time_of_day (E_DATE_EDIT (priv->due_date),
                         due_tt->hour, due_tt->minute);
    } else {
        char *location;

        e_date_edit_set_time (E_DATE_EDIT (priv->due_date), -1);

        /* If no time is set, we use the default timezone, so the
           user usually doesn't have to set this when they set the
           date. */
        location = calendar_config_get_timezone ();
        zone = icaltimezone_get_builtin_timezone (location);
    }

    /* Note that if we are creating a new task, the timezones may not be
       on the server, so we try to get the builtin timezone with the TZID
       first. */
    if (!zone)
        zone = icaltimezone_get_builtin_timezone_from_tzid (d.tzid);
    if (!zone) {
        get_tz_status = cal_client_get_timezone (page->client, d.tzid,
                             &zone);
        /* FIXME: Handle error better. */
        if (get_tz_status != CAL_CLIENT_GET_SUCCESS)
          g_warning ("Couldn't get timezone from server: %s",
                 d.tzid ? d.tzid : "");
    }
    e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->due_timezone),
                       zone);

    cal_component_free_datetime (&d);


    /* Start Date. */
    cal_component_get_dtstart (comp, &d);
    zone = NULL;
    if (d.value) {
        struct icaltimetype *start_tt = d.value;
        e_date_edit_set_date (E_DATE_EDIT (priv->start_date),
                      start_tt->year, start_tt->month,
                      start_tt->day);
        e_date_edit_set_time_of_day (E_DATE_EDIT (priv->start_date),
                         start_tt->hour, start_tt->minute);
    } else {
        char *location;

        e_date_edit_set_time (E_DATE_EDIT (priv->start_date), -1);

        /* If no time is set, we use the default timezone, so the
           user usually doesn't have to set this when they set the
           date. */
        location = calendar_config_get_timezone ();
        zone = icaltimezone_get_builtin_timezone (location);
    }

    if (!zone)
        zone = icaltimezone_get_builtin_timezone_from_tzid (d.tzid);
    if (!zone) {
        get_tz_status = cal_client_get_timezone (page->client, d.tzid,
                             &zone);
        /* FIXME: Handle error better. */
        if (get_tz_status != CAL_CLIENT_GET_SUCCESS)
            g_warning ("Couldn't get timezone from server: %s",
                   d.tzid ? d.tzid : "");
    }
    e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->start_timezone),
                       zone);

    cal_component_free_datetime (&d);

    /* Classification. */
    cal_component_get_classification (comp, &cl);

    switch (cl) {
    case CAL_COMPONENT_CLASS_PUBLIC:
            e_dialog_radio_set (priv->classification_public,
                    CAL_COMPONENT_CLASS_PUBLIC,
                    classification_map);
    case CAL_COMPONENT_CLASS_PRIVATE:
            e_dialog_radio_set (priv->classification_public,
                    CAL_COMPONENT_CLASS_PRIVATE,
                    classification_map);
    case CAL_COMPONENT_CLASS_CONFIDENTIAL:
            e_dialog_radio_set (priv->classification_public,
                    CAL_COMPONENT_CLASS_CONFIDENTIAL,
                    classification_map);
    default:
        /* What do do?  We can't g_assert_not_reached() since it is a
         * value from an external file.
         */
    }

    /* Categories */
    cal_component_get_categories (comp, &categories);
    e_dialog_editable_set (priv->categories, categories);


    /* Contacts */
    comp_editor_contacts_to_widget (priv->contacts_entry, comp);

    /* We connect the contacts changed signal here, as we have to be a bit
       more careful with it due to the use or Corba. The priv->updating
       flag won't work as we won't get the changed event immediately.
       FIXME: Unfortunately this doesn't work either. We never get the
       changed event now. */
    comp_editor_connect_contacts_changed (priv->contacts_entry,
                          contacts_changed_cb, tpage);


    priv->updating = FALSE;
}

/* fill_component handler for the task page */
static gboolean
task_page_fill_component (CompEditorPage *page, CalComponent *comp)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;
    CalComponentDateTime date;
    struct icaltimetype icaltime;
    char *cat, *str;
    gboolean date_set;
    icaltimezone *zone;

    tpage = TASK_PAGE (page);
    priv = tpage->priv;

    /* Summary. */

    str = e_dialog_editable_get (priv->summary);
    if (!str || strlen (str) == 0)
        cal_component_set_summary (comp, NULL);
    else {
        CalComponentText text;

        text.value = str;
        text.altrep = NULL;

        cal_component_set_summary (comp, &text);
    }

    if (str)
        g_free (str);

    /* Description */

    str = e_dialog_editable_get (priv->description);
    if (!str || strlen (str) == 0)
        cal_component_set_description_list (comp, NULL);
    else {
        GSList l;
        CalComponentText text;

        text.value = str;
        text.altrep = NULL;
        l.data = &text;
        l.next = NULL;

        cal_component_set_description_list (comp, &l);
    }

    if (!str)
        g_free (str);

    /* Dates */

    icaltime = icaltime_null_time ();

    date.value = &icaltime;
    date.tzid = NULL;

    /* FIXME: We should use is_date at some point. */

    /* Due Date. */
    date_set = e_date_edit_get_date (E_DATE_EDIT (priv->due_date),
                     &icaltime.year,
                     &icaltime.month,
                     &icaltime.day);
    e_date_edit_get_time_of_day (E_DATE_EDIT (priv->due_date),
                     &icaltime.hour,
                     &icaltime.minute);
    if (date_set) {
        zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->due_timezone));
        if (zone)
            date.tzid = icaltimezone_get_tzid (zone);
        cal_component_set_due (comp, &date);
    } else {
        cal_component_set_due (comp, NULL);
    }

    /* Start Date. */
    date_set = e_date_edit_get_date (E_DATE_EDIT (priv->start_date),
                     &icaltime.year,
                     &icaltime.month,
                     &icaltime.day);
    e_date_edit_get_time_of_day (E_DATE_EDIT (priv->start_date),
                     &icaltime.hour,
                     &icaltime.minute);
    if (date_set) {
        zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone));
        if (zone)
            date.tzid = icaltimezone_get_tzid (zone);
        cal_component_set_dtstart (comp, &date);
    } else {
        cal_component_set_dtstart (comp, NULL);
    }

    /* Classification. */
    cal_component_set_classification (comp, classification_get (priv->classification_public));

    /* Categories */
    cat = e_dialog_editable_get (priv->categories);
    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);

    return TRUE;
}

/* set_summary handler for the task page */
static void
task_page_set_summary (CompEditorPage *page, const char *summary)
{
    /* nothing */
}

static void
task_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;

    tpage = TASK_PAGE (page);
    priv = tpage->priv;

    if (priv->updating)
            return;

    priv->updating = TRUE;

    priv->updating = FALSE;
}



/* Gets the widgets from the XML file and returns if they are all available. */
static gboolean
get_widgets (TaskPage *tpage)
{
    CompEditorPage *page = COMP_EDITOR_PAGE (tpage);
    TaskPagePrivate *priv;
    GSList *accel_groups;
    GtkWidget *toplevel;

    priv = tpage->priv;

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

    priv->main = GW ("task-page");
    if (!priv->main)
        return FALSE;

    /* Get the GtkAccelGroup from the toplevel window, so we can install
       it when the notebook page is mapped. */
    toplevel = gtk_widget_get_toplevel (priv->main);
    accel_groups = gtk_accel_groups_from_object (GTK_OBJECT (toplevel));
    if (accel_groups) {
        page->accel_group = accel_groups->data;
        gtk_accel_group_ref (page->accel_group);
    }

    gtk_widget_ref (priv->main);
    gtk_widget_unparent (priv->main);

    priv->summary = GW ("summary");

    priv->due_date = GW ("due-date");
    priv->start_date = GW ("start-date");
    priv->due_timezone = GW ("due-timezone");
    priv->start_timezone = GW ("start-timezone");

    priv->description = GW ("description");

    priv->classification_public = GW ("classification-public");
    priv->classification_private = GW ("classification-private");
    priv->classification_confidential = GW ("classification-confidential");

    priv->contacts_btn = GW ("contacts-button");
    priv->contacts_box = GW ("contacts-box");

    priv->categories_btn = GW ("categories-button");
    priv->categories = GW ("categories");

#undef GW

    return (priv->summary
        && priv->due_date
        && priv->start_date
        && priv->due_timezone
        && priv->start_timezone
        && priv->classification_public
        && priv->classification_private
        && priv->classification_confidential
        && priv->description
        && priv->contacts_btn
        && priv->contacts_box
        && priv->categories_btn
        && priv->categories);
}

/* Callback used when the summary changes; we emit the notification signal. */
static void
summary_changed_cb (GtkEditable *editable, gpointer data)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;
    gchar *summary;
    
    tpage = TASK_PAGE (data);
    priv = tpage->priv;
    
    if (priv->updating)
        return;
    
    summary = e_dialog_editable_get (GTK_WIDGET (editable));
    comp_editor_page_notify_summary_changed (COMP_EDITOR_PAGE (tpage), 
                         summary);
    g_free (summary);
}

/* Callback used when the start or end date widgets change.  We check that the
 * start date < end date and we set the "all day task" button as appropriate.
 */
static void
date_changed_cb (EDateEdit *dedit, gpointer data)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;
    CompEditorPageDates dates;
    gboolean date_set;
    CalComponentDateTime start_dt, due_dt;
    struct icaltimetype start_tt = icaltime_null_time();
    struct icaltimetype due_tt = icaltime_null_time();

    tpage = TASK_PAGE (data);
    priv = tpage->priv;

    if (priv->updating)
        return;

    date_set = e_date_edit_get_date (E_DATE_EDIT (priv->start_date),
                     &start_tt.year,
                     &start_tt.month,
                     &start_tt.day);
    e_date_edit_get_time_of_day (E_DATE_EDIT (priv->start_date),
                     &start_tt.hour,
                     &start_tt.minute);
    if (date_set) {
        icaltimezone *zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone));
        start_dt.tzid = icaltimezone_get_tzid (zone);
    } else {
        start_tt = icaltime_null_time ();
        start_dt.tzid = NULL;
    }

    date_set = e_date_edit_get_date (E_DATE_EDIT (priv->due_date),
                     &due_tt.year,
                     &due_tt.month,
                     &due_tt.day);
    e_date_edit_get_time_of_day (E_DATE_EDIT (priv->due_date),
                     &due_tt.hour,
                     &due_tt.minute);
    if (date_set) {
        icaltimezone *zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->due_timezone));
        due_dt.tzid = icaltimezone_get_tzid (zone);
    } else {
        due_tt = icaltime_null_time ();
        due_dt.tzid = NULL;
    }

    start_dt.value = &start_tt;
    dates.start = &start_dt;
    dates.end = NULL;
    due_dt.value = &due_tt;
    dates.due = &due_dt;
    dates.complete = NULL;
    
    /* Notify upstream */
    comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (tpage),
                           &dates);
}

/* Callback used when the contacts button is clicked; we must bring up the
 * contact list dialog.
 */
static void
contacts_clicked_cb (GtkWidget *button, gpointer data)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;

    tpage = TASK_PAGE (data);
    priv = tpage->priv;

    g_print ("In contacts_clicked_cb\n");
    comp_editor_show_contacts_dialog (priv->corba_select_names);

    /* FIXME: Currently we aren't getting the changed event from the
       SelectNames component correctly, so we aren't saving the event
       if just the contacts are changed. To work around that, we assume
       that if the contacts button is clicked it is changed. */
    comp_editor_page_notify_changed (COMP_EDITOR_PAGE (tpage));
}

/* Callback used when the categories button is clicked; we must bring up the
 * category list dialog.
 */
static void
categories_clicked_cb (GtkWidget *button, gpointer data)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;
    GtkWidget *entry;

    tpage = TASK_PAGE (data);
    priv = tpage->priv;

    entry = priv->categories;
    e_categories_config_open_dialog_for_entry (GTK_ENTRY (entry));
}

/* This is called when any field is changed; it notifies upstream. */
static void
field_changed_cb (GtkWidget *widget, gpointer data)
{
    TaskPage *tpage;
    TaskPagePrivate *priv;
    
    tpage = TASK_PAGE (data);
    priv = tpage->priv;
    
    if (!priv->updating)
        comp_editor_page_notify_changed (COMP_EDITOR_PAGE (tpage));
}

/* Hooks the widget signals */
static gboolean
init_widgets (TaskPage *tpage)
{
    TaskPagePrivate *priv;
    char *location;
    icaltimezone *zone;

    priv = tpage->priv;

    /* Make sure the EDateEdit widgets use our timezones to get the
       current time. */
    e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->start_date),
                       (EDateEditGetTimeCallback) comp_editor_get_current_time,
                       tpage, NULL);
    e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->due_date),
                       (EDateEditGetTimeCallback) comp_editor_get_current_time,
                       tpage, NULL);
    
    /* Summary */
    gtk_signal_connect (GTK_OBJECT (priv->summary), "changed",
                GTK_SIGNAL_FUNC (summary_changed_cb), tpage);

    /* Description - turn on word wrap. */
    gtk_text_set_word_wrap (GTK_TEXT (priv->description), TRUE);

    /* Dates */
    gtk_signal_connect (GTK_OBJECT (priv->start_date), "changed",
                GTK_SIGNAL_FUNC (date_changed_cb), tpage);
    gtk_signal_connect (GTK_OBJECT (priv->due_date), "changed",
                GTK_SIGNAL_FUNC (date_changed_cb), tpage);

    gtk_signal_connect (GTK_OBJECT (priv->due_timezone), "changed",
                GTK_SIGNAL_FUNC (field_changed_cb), tpage);
    gtk_signal_connect (GTK_OBJECT (priv->start_timezone), "changed",
                GTK_SIGNAL_FUNC (field_changed_cb), tpage);

    /* Classification */
    gtk_signal_connect (GTK_OBJECT (priv->description), "changed",
                GTK_SIGNAL_FUNC (field_changed_cb), tpage);
    gtk_signal_connect (GTK_OBJECT (priv->classification_public),
                "toggled",
                GTK_SIGNAL_FUNC (field_changed_cb), tpage);
    gtk_signal_connect (GTK_OBJECT (priv->classification_private),
                "toggled",
                GTK_SIGNAL_FUNC (field_changed_cb), tpage);
    gtk_signal_connect (GTK_OBJECT (priv->classification_confidential),
                "toggled",
                GTK_SIGNAL_FUNC (field_changed_cb), tpage);

    /* Connect the default signal handler to use to make sure the "changed"
       field gets set whenever a field is changed. */
    gtk_signal_connect (GTK_OBJECT (priv->description), "changed",
                GTK_SIGNAL_FUNC (field_changed_cb), tpage);
    gtk_signal_connect (GTK_OBJECT (priv->categories), "changed",
                GTK_SIGNAL_FUNC (field_changed_cb), tpage);

    /* Contacts button */
    gtk_signal_connect (GTK_OBJECT (priv->contacts_btn), "clicked",
                GTK_SIGNAL_FUNC (contacts_clicked_cb), tpage);

    /* Categories button */
    gtk_signal_connect (GTK_OBJECT (priv->categories_btn), "clicked",
                GTK_SIGNAL_FUNC (categories_clicked_cb), tpage);


    /* Create the contacts entry, a corba control from the address book. */
    priv->corba_select_names = comp_editor_create_contacts_component ();
    if (priv->corba_select_names == CORBA_OBJECT_NIL)
        return FALSE;

    priv->contacts_entry = comp_editor_create_contacts_control (priv->corba_select_names);
    if (priv->contacts_entry == NULL)
        return FALSE;

    gtk_container_add (GTK_CONTAINER (priv->contacts_box),
               priv->contacts_entry);

    /* Set the default timezone, so the timezone entry may be hidden. */
    location = calendar_config_get_timezone ();
    zone = icaltimezone_get_builtin_timezone (location);
    e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->start_timezone), zone);
    e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->due_timezone), zone);

    return TRUE;
}



/**
 * task_page_construct:
 * @tpage: An task page.
 * 
 * Constructs an task page by loading its Glade data.
 * 
 * Return value: The same object as @tpage, or NULL if the widgets could not be
 * created.
 **/
TaskPage *
task_page_construct (TaskPage *tpage)
{
    TaskPagePrivate *priv;

    priv = tpage->priv;

    priv->xml = glade_xml_new (EVOLUTION_GLADEDIR "/task-page.glade",
                   NULL);
    if (!priv->xml) {
        g_message ("task_page_construct(): "
               "Could not load the Glade XML file!");
        return NULL;
    }

    if (!get_widgets (tpage)) {
        g_message ("task_page_construct(): "
               "Could not find all widgets in the XML file!");
        return NULL;
    }

    if (!init_widgets (tpage)) {
        g_message ("event_page_construct(): " 
               "Could not initialize the widgets!");
        return NULL;
    }

    return tpage;
}

/**
 * task_page_new:
 * 
 * Creates a new task page.
 * 
 * Return value: A newly-created task page, or NULL if the page could
 * not be created.
 **/
TaskPage *
task_page_new (void)
{
    TaskPage *tpage;

    tpage = gtk_type_new (TYPE_TASK_PAGE);
    if (!task_page_construct (tpage)) {
        gtk_object_unref (GTK_OBJECT (tpage));
        return NULL;
    }

    return tpage;
}

GtkWidget *task_page_create_date_edit (void);

GtkWidget *
task_page_create_date_edit (void)
{
    GtkWidget *dedit;

    dedit = comp_editor_new_date_edit (TRUE, TRUE, TRUE);
    e_date_edit_set_allow_no_date_set (E_DATE_EDIT (dedit), TRUE);

    return dedit;
}