aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/dialogs/meeting-page.c
blob: a369646ab466709124669fc21b0c7d0d3047cab8 (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
/* 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 <liboaf/liboaf.h>
#include <gtk/gtknotebook.h>
#include <gtk/gtkradiobutton.h>
#include <gtk/gtksignal.h>
#include <gtk/gtktable.h>
#include <gtk/gtktogglebutton.h>
#include <gtk/gtkvbox.h>
#include <glade/glade.h>
#include <gal/widgets/e-unicode.h>
#include <widgets/misc/e-dateedit.h>
#include <widgets/meeting-time-sel/e-meeting-time-sel.h>
#include <e-util/e-dialog-widgets.h>
#include "../Evolution-Addressbook-SelectNames.h"
#include "comp-editor-util.h"
#include "meeting-page.h"


#define SELECT_NAMES_OAFID "OAFIID:GNOME_Evolution_Addressbook_SelectNames"

/* Private part of the MeetingPage structure */
struct _MeetingPagePrivate {
    /* Glade XML data */
    GladeXML *xml;

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

    EMeetingTimeSelector *selector;
    GtkWidget *table;
    
    /* Other widgets */
    GtkWidget *rb1[2];
    GtkWidget *rb2[2];
    
    /* For handling the invite button */
    GNOME_Evolution_Addressbook_SelectNames corba_select_names;

    gboolean updating;
};



static void meeting_page_class_init (MeetingPageClass *class);
static void meeting_page_init (MeetingPage *mpage);
static void meeting_page_destroy (GtkObject *object);

static GtkWidget *meeting_page_get_widget (CompEditorPage *page);
static void meeting_page_fill_widgets (CompEditorPage *page, CalComponent *comp);
static void meeting_page_fill_component (CompEditorPage *page, CalComponent *comp);
static void meeting_page_set_summary (CompEditorPage *page, const char *summary);
static void meeting_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates);

static CompEditorPageClass *parent_class = NULL;



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

    if (!meeting_page_type) {
        static const GtkTypeInfo meeting_page_info = {
            "MeetingPage",
            sizeof (MeetingPage),
            sizeof (MeetingPageClass),
            (GtkClassInitFunc) meeting_page_class_init,
            (GtkObjectInitFunc) meeting_page_init,
            NULL, /* reserved_1 */
            NULL, /* reserved_2 */
            (GtkClassInitFunc) NULL
        };

        meeting_page_type = 
            gtk_type_unique (TYPE_COMP_EDITOR_PAGE,
                     &meeting_page_info);
    }

    return meeting_page_type;
}

/* Class initialization function for the task page */
static void
meeting_page_class_init (MeetingPageClass *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 = meeting_page_get_widget;
    editor_page_class->fill_widgets = meeting_page_fill_widgets;
    editor_page_class->fill_component = meeting_page_fill_component;
    editor_page_class->set_summary = meeting_page_set_summary;
    editor_page_class->set_dates = meeting_page_set_dates;

    object_class->destroy = meeting_page_destroy;
}

/* Object initialization function for the task page */
static void
meeting_page_init (MeetingPage *mpage)
{
    MeetingPagePrivate *priv;

    priv = g_new0 (MeetingPagePrivate, 1);
    mpage->priv = priv;

    priv->xml = NULL;

    priv->main = NULL;
    priv->selector = NULL;

    priv->updating = FALSE;
}

/* Destroy handler for the task page */
static void
meeting_page_destroy (GtkObject *object)
{
    MeetingPage *mpage;
    MeetingPagePrivate *priv;

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

    mpage = MEETING_PAGE (object);
    priv = mpage->priv;

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

    g_free (priv);
    mpage->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 *
meeting_page_get_widget (CompEditorPage *page)
{
    MeetingPage *mpage;
    MeetingPagePrivate *priv;

    mpage = MEETING_PAGE (page);
    priv = mpage->priv;

    return priv->main;
}

/* Fills the widgets with default values */
static void
clear_widgets (MeetingPage *mpage)
{
    MeetingPagePrivate *priv;

    priv = mpage->priv;
}

/* fill_widgets handler for the task page */
static void
meeting_page_fill_widgets (CompEditorPage *page, CalComponent *comp)
{
    MeetingPage *mpage;
    MeetingPagePrivate *priv;
    CalComponentDateTime dtstart, dtend;
    struct icaltimetype start, end;
    mpage = MEETING_PAGE (page);
    priv = mpage->priv;

    priv->updating = TRUE;
    
    /* Clean the screen */
    clear_widgets (mpage);
    
    /* Selector */
    cal_component_get_dtstart (comp, &dtstart);
    cal_component_get_dtend (comp, &dtend);
    start = icaltime_as_zone (*dtstart.value, dtstart.tzid);
    end = icaltime_as_zone (*dtend.value, dtend.tzid);
    e_meeting_time_selector_set_meeting_time (priv->selector,
                          start.year,
                          start.month,
                          start.day,
                          start.hour,
                          start.minute,
                          end.year,
                          end.month,
                          end.day,
                          end.hour,
                          end.minute);
    cal_component_free_datetime (&dtstart);
    cal_component_free_datetime (&dtend);

    priv->updating = FALSE;
}

/* fill_component handler for the task page */
static void
meeting_page_fill_component (CompEditorPage *page, CalComponent *comp)
{
#if 0
    MeetingPage *mpage;
    MeetingPagePrivate *priv;
    CalComponentDateTime date;
    time_t t;
    char *url;
    
    mpage = MEETING_PAGE (page);
    priv = mpage->priv;

    /* Completed Date. */
    date.value = g_new (struct icaltimetype, 1);
    date.tzid = NULL;

    t = e_date_edit_get_time (E_DATE_EDIT (priv->completed_date));
    if (t != -1) {
        *date.value = icaltime_from_timet (t, FALSE);
        cal_component_set_completed (comp, date.value);
    } else {
        cal_component_set_completed (comp, NULL);
    }

    g_free (date.value);

    /* URL. */
    url = e_dialog_editable_get (priv->url);
    cal_component_set_url (comp, url);
    if (url)
        g_free (url);
#endif
}

/* set_summary handler for the task page */
static void
meeting_page_set_summary (CompEditorPage *page, const char *summary)
{
#if 0
    MeetingPage *mpage;
    MeetingPagePrivate *priv;
    gchar *s;
    
    mpage = MEETING_PAGE (page);
    priv = mpage->priv;

    s = e_utf8_to_gtk_string (priv->summary, summary);
    gtk_label_set_text (GTK_LABEL (priv->summary), s);
    g_free (s);
#endif
}

static void
meeting_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates)
{
    MeetingPage *mpage;
    MeetingPagePrivate *priv;

    mpage = MEETING_PAGE (page);
    priv = mpage->priv;

//  comp_editor_date_label (dates, priv->date_time);
}



/* Gets the widgets from the XML file and returns if they are all available. */
static gboolean
get_widgets (MeetingPage *mpage)
{
    MeetingPagePrivate *priv;

    priv = mpage->priv;

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

    priv->main = GW ("meeting-page");
    g_assert (priv->main);
    gtk_widget_ref (priv->main);
    gtk_widget_unparent (priv->main);

    priv->selector = E_MEETING_TIME_SELECTOR (GW ("selector"));
    priv->table = GW ("status-table");
    
#undef GW

    return (priv->selector 
        && priv->table);
}

/* Creates the radio buttons in the given container */
static void
create_radio_buttons (GtkWidget *box, GtkWidget **button1, GtkWidget **button2)
{
    GtkWidget *rb1, *rb2;
    GSList *grp;

    /* The radio buttions to change views */
    rb1 = gtk_radio_button_new_with_label (NULL,
                           "Show attendee scheduling");
    gtk_widget_show (rb1);

    grp = gtk_radio_button_group (GTK_RADIO_BUTTON (rb1));
    rb2 = gtk_radio_button_new_with_label (grp, "Show attendee status");
    gtk_widget_show (rb2);
    
    gtk_box_pack_start (GTK_BOX (box), rb1, FALSE, FALSE, 0);
    gtk_box_pack_start (GTK_BOX (box), rb2, FALSE, FALSE, 0);

    *button1 = rb1;
    *button2 = rb2;
}

/* 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)
{
#if 0
    MeetingPage *mpage;
    MeetingPagePrivate *priv;
    CompEditorPageDates dates;

    mpage = MEETING_PAGE (data);
    priv = mpage->priv;

    if (priv->updating)
        return;

    dates.start = 0;
    dates.end = 0;
    dates.due = 0;
    dates.complete = e_date_edit_get_time (E_DATE_EDIT (priv->completed_date));
    
    /* Notify upstream */
    comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (mpage), &dates);
#endif
}

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

static gboolean
get_select_name_dialog (MeetingPage *mpage) 
{
    MeetingPagePrivate *priv;
    CORBA_Environment ev;
    
    priv = mpage->priv;

    if (priv->corba_select_names != CORBA_OBJECT_NIL)
        return TRUE;
    
    CORBA_exception_init (&ev);

    priv->corba_select_names = oaf_activate_from_id (SELECT_NAMES_OAFID, 0, NULL, &ev);

    /* OAF seems to be broken -- it can return a CORBA_OBJECT_NIL without
           raising an exception in `ev'.  */
    if (ev._major != CORBA_NO_EXCEPTION || priv->corba_select_names == CORBA_OBJECT_NIL) {
        g_warning ("Cannot activate -- %s", SELECT_NAMES_OAFID);
        CORBA_exception_free (&ev);
        return FALSE;
    }

    CORBA_exception_free (&ev);

    return TRUE;
}

/* Function called to invite more people */
static void
invite_cb (GtkWidget *widget, gpointer data) 
{
    MeetingPage *mpage;
    MeetingPagePrivate *priv;
    CORBA_Environment ev;
    
    mpage = MEETING_PAGE (data);
    priv = mpage->priv;
    
    if (!get_select_name_dialog (mpage))
        return;
    
    CORBA_exception_init (&ev);

    GNOME_Evolution_Addressbook_SelectNames_addSection (
        priv->corba_select_names, "Required", "Required", &ev);

    GNOME_Evolution_Addressbook_SelectNames_activateDialog (
        priv->corba_select_names, "Test", &ev);

    CORBA_exception_free (&ev);

    if (!priv->updating)
        comp_editor_page_notify_changed (COMP_EDITOR_PAGE (mpage));
}

static void
page_toggle_cb (GtkWidget *widget, gpointer data)
{
    MeetingPage *mpage;
    MeetingPagePrivate *priv;
    gboolean active;
    
    mpage = MEETING_PAGE (data);
    priv = mpage->priv;

    active = GTK_TOGGLE_BUTTON (widget)->active;
    if (active)
        gtk_notebook_set_page (GTK_NOTEBOOK (priv->main), 0);
    else
        gtk_notebook_set_page (GTK_NOTEBOOK (priv->main), 1);

    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->rb1[0]), active);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->rb1[1]), !active);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->rb2[0]), active);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->rb2[1]), !active);
}
    
/* Hooks the widget signals */
static void
init_widgets (MeetingPage *mpage)
{
    MeetingPagePrivate *priv;

    priv = mpage->priv;

    /* Selector */
    gtk_signal_connect (GTK_OBJECT (priv->selector->invite_button), 
                "clicked", GTK_SIGNAL_FUNC (invite_cb), mpage);

    /* Radio buttons */
    gtk_signal_connect (GTK_OBJECT (priv->rb1[0]), "toggled", 
                GTK_SIGNAL_FUNC (page_toggle_cb), mpage);
    gtk_signal_connect (GTK_OBJECT (priv->rb2[0]), "toggled", 
                GTK_SIGNAL_FUNC (page_toggle_cb), mpage);
    
#if 0
    /* Completed Date */
    gtk_signal_connect (GTK_OBJECT (priv->completed_date), "changed",
                GTK_SIGNAL_FUNC (date_changed_cb), mpage);

#endif
}



/**
 * meeting_page_construct:
 * @mpage: An task details page.
 * 
 * Constructs an task page by loading its Glade data.
 * 
 * Return value: The same object as @mpage, or NULL if the widgets could not 
 * be created.
 **/
MeetingPage *
meeting_page_construct (MeetingPage *mpage)
{
    MeetingPagePrivate *priv;
    GtkWidget *vbox;
    
    priv = mpage->priv;

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

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

    /* Stuff for the second page */
    vbox = gtk_vbox_new (FALSE, 2);
    gtk_widget_show (vbox);
    gtk_table_attach (GTK_TABLE (priv->table), vbox, 0, 1, 0, 1,
              GTK_EXPAND | GTK_FILL, GTK_FILL, 2, 0);

    /* The radio buttions to change views on first page */
    create_radio_buttons (priv->selector->attendees_title_bar_vbox, 
                  &priv->rb1[0], &priv->rb1[1]);

    /* The radio buttions to change views on second page */
    create_radio_buttons (vbox, &priv->rb2[0], &priv->rb2[1]);

    /* Init the widget signals */
    init_widgets (mpage);

    return mpage;
}

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

    mpage = gtk_type_new (TYPE_MEETING_PAGE);
    if (!meeting_page_construct (mpage)) {
        gtk_object_unref (GTK_OBJECT (mpage));
        return NULL;
    }

    return mpage;
}

GtkWidget *meeting_page_create_selector (void);

GtkWidget *
meeting_page_create_selector (void)
{
    GtkWidget *sel;

    sel = e_meeting_time_selector_new ();

    return sel;
}