e-calendar-view.c 65.4 KB
Newer Older
1
/*
2 3 4
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation.
5
 *
6 7 8 9
 * 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.
10
 *
11 12
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
13 14 15 16 17 18
 *
 *
 * Authors:
 *		Rodrigo Moya <rodrigo@ximian.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
19 20 21
 *
 */

JP Rosevear's avatar
JP Rosevear committed
22
#ifdef HAVE_CONFIG_H
23
#include <config.h>
JP Rosevear's avatar
JP Rosevear committed
24 25
#endif

26
#include <string.h>
27
#include <time.h>
28 29
#include <gtk/gtk.h>
#include <glib/gi18n.h>
Tor Lillqvist's avatar
Tor Lillqvist committed
30
#include <glib/gstdio.h>
31
#include <gdk/gdkkeysyms.h>
32 33
#include <libebackend/libebackend.h>

34
#include <shell/e-shell.h>
35

36
#include "comp-util.h"
37
#include "ea-calendar.h"
38
#include "e-cal-ops.h"
39
#include "e-cal-model-calendar.h"
40
#include "e-calendar-view.h"
41 42 43
#include "e-day-view.h"
#include "e-month-view.h"
#include "e-cal-list-view.h"
44
#include "ea-cal-view.h"
45
#include "itip-utils.h"
46
#include "dialogs/comp-editor-util.h"
47
#include "dialogs/delete-comp.h"
48
#include "dialogs/event-editor.h"
49
#include "dialogs/send-comp.h"
50 51
#include "dialogs/cancel-comp.h"
#include "dialogs/recur-comp.h"
52
#include "dialogs/select-source-dialog.h"
53
#include "dialogs/goto-dialog.h"
54
#include "print.h"
55
#include "misc.h"
56

57 58 59 60
#define E_CALENDAR_VIEW_GET_PRIVATE(obj) \
	(G_TYPE_INSTANCE_GET_PRIVATE \
	((obj), E_TYPE_CALENDAR_VIEW, ECalendarViewPrivate))

61
struct _ECalendarViewPrivate {
62 63
	/* The calendar model we are monitoring */
	ECalModel *model;
64

65
	gint time_divisions;
66
	GSList *selected_cut_list;
Matthew Barnes's avatar
Matthew Barnes committed
67 68 69

	GtkTargetList *copy_target_list;
	GtkTargetList *paste_target_list;
70 71 72 73

	/* All keyboard devices are grabbed
	 * while a tooltip window is shown. */
	GQueue grabbed_keyboards;
74 75
};

76
enum {
77
	PROP_0,
Matthew Barnes's avatar
Matthew Barnes committed
78 79
	PROP_COPY_TARGET_LIST,
	PROP_MODEL,
80
	PROP_PASTE_TARGET_LIST,
81 82
	PROP_TIME_DIVISIONS,
	PROP_IS_EDITING
83
};
84

85
/* FIXME Why are we emitting these event signals here? Can't the model just be listened to? */
Rodrigo Moya's avatar
Rodrigo Moya committed
86 87
/* Signal IDs */
enum {
88
	POPUP_EVENT,
Rodrigo Moya's avatar
Rodrigo Moya committed
89
	SELECTION_CHANGED,
90
	SELECTED_TIME_CHANGED,
91
	TIMEZONE_CHANGED,
92 93
	EVENT_CHANGED,
	EVENT_ADDED,
94
	OPEN_EVENT,
95
	MOVE_VIEW_RANGE,
Rodrigo Moya's avatar
Rodrigo Moya committed
96 97 98
	LAST_SIGNAL
};

99
static guint signals[LAST_SIGNAL];
Rodrigo Moya's avatar
Rodrigo Moya committed
100

101
static void calendar_view_selectable_init (ESelectableInterface *iface);
102

103 104 105
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (
	ECalendarView, e_calendar_view, GTK_TYPE_TABLE,
	G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL)
106 107
	G_IMPLEMENT_INTERFACE (E_TYPE_SELECTABLE, calendar_view_selectable_init));

108 109 110
static void
calendar_view_add_retract_data (ECalComponent *comp,
                                const gchar *retract_comment,
111
                                ECalObjModType mod)
112 113 114 115 116 117 118 119 120 121 122 123
{
	icalcomponent *icalcomp = NULL;
	icalproperty *icalprop = NULL;

	icalcomp = e_cal_component_get_icalcomponent (comp);
	if (retract_comment && *retract_comment)
		icalprop = icalproperty_new_x (retract_comment);
	else
		icalprop = icalproperty_new_x ("0");
	icalproperty_set_x_name (icalprop, "X-EVOLUTION-RETRACT-COMMENT");
	icalcomponent_add_property (icalcomp, icalprop);

124
	if (mod == E_CAL_OBJ_MOD_ALL)
125 126 127 128 129 130 131 132 133
		icalprop = icalproperty_new_x ("All");
	else
		icalprop = icalproperty_new_x ("This");
	icalproperty_set_x_name (icalprop, "X-EVOLUTION-RECUR-MOD");
	icalcomponent_add_property (icalcomp, icalprop);
}

static gboolean
calendar_view_check_for_retract (ECalComponent *comp,
134
                                 ECalClient *client)
135 136 137 138 139 140 141 142 143
{
	ECalComponentOrganizer organizer;
	const gchar *strip;
	gchar *email = NULL;
	gboolean ret_val;

	if (!e_cal_component_has_attendees (comp))
		return FALSE;

144
	if (!e_cal_client_check_save_schedules (client))
145 146 147 148 149 150
		return FALSE;

	e_cal_component_get_organizer (comp, &organizer);
	strip = itip_strip_mailto (organizer.value);

	ret_val =
151
		e_client_get_backend_property_sync (E_CLIENT (client), CAL_BACKEND_PROPERTY_CAL_EMAIL_ADDRESS, &email, NULL, NULL) &&
152 153 154 155 156 157 158 159 160 161 162
		(g_ascii_strcasecmp (email, strip) == 0);

	g_free (email);

	return ret_val;
}

static void
calendar_view_delete_event (ECalendarView *cal_view,
                            ECalendarViewEvent *event)
{
163
	ECalModel *model;
164 165
	ECalComponent *comp;
	ECalComponentVType vtype;
166
	ESourceRegistry *registry;
167
	gboolean delete = TRUE;
168

169 170 171
	if (!is_comp_data_valid (event))
		return;

172
	model = e_calendar_view_get_model (cal_view);
173
	registry = e_cal_model_get_registry (model);
174

175 176 177 178 179
	comp = e_cal_component_new ();
	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
	vtype = e_cal_component_get_vtype (comp);

	/*FIXME remove it once the we dont set the recurrence id for all the generated instances */
180
	if (!e_cal_client_check_recurrences_no_master (event->comp_data->client))
181 182 183 184 185 186 187 188 189
		e_cal_component_set_recurid (comp, NULL);

	/*FIXME Retract should be moved to Groupwise features plugin */
	if (calendar_view_check_for_retract (comp, event->comp_data->client)) {
		gchar *retract_comment = NULL;
		gboolean retract = FALSE;

		delete = prompt_retract_dialog (comp, &retract_comment, GTK_WIDGET (cal_view), &retract);
		if (retract) {
190
			icalcomponent *icalcomp;
191

192
			calendar_view_add_retract_data (comp, retract_comment, E_CAL_OBJ_MOD_ALL);
193 194 195
			icalcomp = e_cal_component_get_icalcomponent (comp);
			icalcomponent_set_method (icalcomp, ICAL_METHOD_CANCEL);

196
			e_cal_ops_send_component (model, event->comp_data->client, icalcomp);
197
		}
198 199 200
	} else if (e_cal_model_get_confirm_delete (model))
		delete = delete_component_dialog (
			comp, FALSE, 1, vtype, GTK_WIDGET (cal_view));
201 202 203 204 205

	if (delete) {
		const gchar *uid;
		gchar *rid = NULL;

206 207
		if ((itip_organizer_is_user (registry, comp, event->comp_data->client) ||
		     itip_sentby_is_user (registry, comp, event->comp_data->client))
208 209 210
		    && cancel_component_dialog ((GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (cal_view)),
						event->comp_data->client,
						comp, TRUE))
211
			itip_send_component (model, E_CAL_COMPONENT_METHOD_CANCEL,
212
				comp, event->comp_data->client, NULL, NULL,
213
				NULL, TRUE, FALSE, FALSE);
214 215 216 217 218 219 220

		e_cal_component_get_uid (comp, &uid);
		if (!uid || !*uid) {
			g_object_unref (comp);
			return;
		}
		rid = e_cal_component_get_recurid_as_string (comp);
221 222 223
		if (e_cal_util_component_is_instance (event->comp_data->icalcomp) ||
		    e_cal_util_component_has_recurrences (event->comp_data->icalcomp))
			e_cal_ops_remove_component (model, event->comp_data->client, uid, rid, E_CAL_OBJ_MOD_ALL, FALSE);
224
		else
225
			e_cal_ops_remove_component (model, event->comp_data->client, uid, NULL, E_CAL_OBJ_MOD_THIS, FALSE);
226 227 228 229 230 231 232

		g_free (rid);
	}

	g_object_unref (comp);
}

233 234 235 236 237 238 239 240 241
static void
calendar_view_set_model (ECalendarView *calendar_view,
                         ECalModel *model)
{
	g_return_if_fail (calendar_view->priv->model == NULL);
	g_return_if_fail (E_IS_CAL_MODEL (model));

	calendar_view->priv->model = g_object_ref (model);
}
242

243
static void
244 245 246 247
calendar_view_set_property (GObject *object,
                            guint property_id,
                            const GValue *value,
                            GParamSpec *pspec)
248
{
249 250 251 252 253 254
	switch (property_id) {
		case PROP_MODEL:
			calendar_view_set_model (
				E_CALENDAR_VIEW (object),
				g_value_get_object (value));
			return;
255 256 257 258 259 260

		case PROP_TIME_DIVISIONS:
			e_calendar_view_set_time_divisions (
				E_CALENDAR_VIEW (object),
				g_value_get_int (value));
			return;
261
	}
262

263 264
	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
265

266 267 268 269 270 271
static void
calendar_view_get_property (GObject *object,
                            guint property_id,
                            GValue *value,
                            GParamSpec *pspec)
{
272
	switch (property_id) {
Matthew Barnes's avatar
Matthew Barnes committed
273 274 275 276 277 278
		case PROP_COPY_TARGET_LIST:
			g_value_set_boxed (
				value, e_calendar_view_get_copy_target_list (
				E_CALENDAR_VIEW (object)));
			return;

279 280 281 282 283
		case PROP_MODEL:
			g_value_set_object (
				value, e_calendar_view_get_model (
				E_CALENDAR_VIEW (object)));
			return;
Matthew Barnes's avatar
Matthew Barnes committed
284 285 286 287 288 289

		case PROP_PASTE_TARGET_LIST:
			g_value_set_boxed (
				value, e_calendar_view_get_paste_target_list (
				E_CALENDAR_VIEW (object)));
			return;
290 291 292 293 294 295

		case PROP_TIME_DIVISIONS:
			g_value_set_int (
				value, e_calendar_view_get_time_divisions (
				E_CALENDAR_VIEW (object)));
			return;
296 297 298 299

		case PROP_IS_EDITING:
			g_value_set_boolean (value, e_calendar_view_is_editing (E_CALENDAR_VIEW (object)));
			return;
300
	}
301 302

	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
303 304 305
}

static void
306
calendar_view_dispose (GObject *object)
307
{
308
	ECalendarViewPrivate *priv;
309

310
	priv = E_CALENDAR_VIEW_GET_PRIVATE (object);
311

312 313 314 315 316 317
	if (priv->model != NULL) {
		g_signal_handlers_disconnect_matched (
			priv->model, G_SIGNAL_MATCH_DATA,
			0, 0, NULL, NULL, object);
		g_object_unref (priv->model);
		priv->model = NULL;
318
	}
319

Matthew Barnes's avatar
Matthew Barnes committed
320 321 322 323 324 325 326 327 328
	if (priv->copy_target_list != NULL) {
		gtk_target_list_unref (priv->copy_target_list);
		priv->copy_target_list = NULL;
	}

	if (priv->paste_target_list != NULL) {
		gtk_target_list_unref (priv->paste_target_list);
		priv->paste_target_list = NULL;
	}
Matthew Barnes's avatar
Matthew Barnes committed
329

330 331 332 333 334
	if (priv->selected_cut_list) {
		g_slist_foreach (priv->selected_cut_list, (GFunc) g_object_unref, NULL);
		g_slist_free (priv->selected_cut_list);
		priv->selected_cut_list = NULL;
	}
Matthew Barnes's avatar
Matthew Barnes committed
335

336 337 338 339 340 341 342
	while (!g_queue_is_empty (&priv->grabbed_keyboards)) {
		GdkDevice *keyboard;
		keyboard = g_queue_pop_head (&priv->grabbed_keyboards);
		gdk_device_ungrab (keyboard, GDK_CURRENT_TIME);
		g_object_unref (keyboard);
	}

343
	/* Chain up to parent's dispose() method. */
344
	G_OBJECT_CLASS (e_calendar_view_parent_class)->dispose (object);
345 346
}

347 348 349 350 351 352 353
static void
calendar_view_constructed (GObject *object)
{
	/* Do this after calendar_view_init() so extensions can query
	 * the GType accurately.  See GInstanceInitFunc documentation
	 * for details of the problem. */
	e_extensible_load_extensions (E_EXTENSIBLE (object));
354 355

	/* Chain up to parent's constructed() method. */
356
	G_OBJECT_CLASS (e_calendar_view_parent_class)->constructed (object);
357 358
}

359
static void
360 361 362 363
calendar_view_update_actions (ESelectable *selectable,
                              EFocusTracker *focus_tracker,
                              GdkAtom *clipboard_targets,
                              gint n_clipboard_targets)
364
{
365 366
	ECalendarView *view;
	GtkAction *action;
Matthew Barnes's avatar
Matthew Barnes committed
367
	GtkTargetList *target_list;
368
	GList *list, *iter;
Matthew Barnes's avatar
Matthew Barnes committed
369
	gboolean can_paste = FALSE;
370
	gboolean sources_are_editable = TRUE;
371
	gboolean recurring = FALSE;
372
	gboolean is_editing;
373 374 375
	gboolean sensitive;
	const gchar *tooltip;
	gint n_selected;
Matthew Barnes's avatar
Matthew Barnes committed
376
	gint ii;
377

378
	view = E_CALENDAR_VIEW (selectable);
379
	is_editing = e_calendar_view_is_editing (view);
380

381 382
	list = e_calendar_view_get_selected_events (view);
	n_selected = g_list_length (list);
383

384 385
	for (iter = list; iter != NULL; iter = iter->next) {
		ECalendarViewEvent *event = iter->data;
386
		ECalClient *client;
387
		icalcomponent *icalcomp;
388

389 390
		if (event == NULL || event->comp_data == NULL)
			continue;
391

392 393 394
		client = event->comp_data->client;
		icalcomp = event->comp_data->icalcomp;

395
		sources_are_editable = sources_are_editable && !e_client_is_readonly (E_CLIENT (client));
396 397 398 399

		recurring |=
			e_cal_util_component_is_instance (icalcomp) ||
			e_cal_util_component_has_recurrences (icalcomp);
400
	}
401

402 403
	g_list_free (list);

Matthew Barnes's avatar
Matthew Barnes committed
404 405 406 407
	target_list = e_selectable_get_paste_target_list (selectable);
	for (ii = 0; ii < n_clipboard_targets && !can_paste; ii++)
		can_paste = gtk_target_list_find (
			target_list, clipboard_targets[ii], NULL);
408 409

	action = e_focus_tracker_get_cut_clipboard_action (focus_tracker);
410
	sensitive = (n_selected > 0) && sources_are_editable && !is_editing;
411 412 413 414 415
	tooltip = _("Cut selected events to the clipboard");
	gtk_action_set_sensitive (action, sensitive);
	gtk_action_set_tooltip (action, tooltip);

	action = e_focus_tracker_get_copy_clipboard_action (focus_tracker);
416
	sensitive = (n_selected > 0) && !is_editing;
417 418 419 420 421
	tooltip = _("Copy selected events to the clipboard");
	gtk_action_set_sensitive (action, sensitive);
	gtk_action_set_tooltip (action, tooltip);

	action = e_focus_tracker_get_paste_clipboard_action (focus_tracker);
422
	sensitive = sources_are_editable && can_paste && !is_editing;
423 424 425
	tooltip = _("Paste events from the clipboard");
	gtk_action_set_sensitive (action, sensitive);
	gtk_action_set_tooltip (action, tooltip);
426 427

	action = e_focus_tracker_get_delete_selection_action (focus_tracker);
428
	sensitive = (n_selected > 0) && sources_are_editable && !recurring && !is_editing;
429 430 431
	tooltip = _("Delete selected events");
	gtk_action_set_sensitive (action, sensitive);
	gtk_action_set_tooltip (action, tooltip);
432
}
433

434 435 436 437
static void
calendar_view_cut_clipboard (ESelectable *selectable)
{
	ECalendarView *cal_view;
438
	ECalendarViewPrivate *priv;
439
	GList *selected, *l;
440

441
	cal_view = E_CALENDAR_VIEW (selectable);
442
	priv = cal_view->priv;
443

444 445 446
	selected = e_calendar_view_get_selected_events (cal_view);
	if (!selected)
		return;
447

448
	e_selectable_copy_clipboard (selectable);
Matthew Barnes's avatar
Matthew Barnes committed
449

450
	for (l = selected; l != NULL; l = g_list_next (l)) {
451
		ECalendarViewEvent *event = (ECalendarViewEvent *) l->data;
452

453
		priv->selected_cut_list = g_slist_prepend (priv->selected_cut_list, g_object_ref (event->comp_data));
454
	}
Matthew Barnes's avatar
Matthew Barnes committed
455

456
	g_list_free (selected);
457 458
}

459
static void
460 461 462
add_related_timezones (icalcomponent *des_icalcomp,
                       icalcomponent *src_icalcomp,
                       ECalClient *client)
463
{
464 465 466 467 468 469
	icalproperty_kind look_in[] = {
		ICAL_DTSTART_PROPERTY,
		ICAL_DTEND_PROPERTY,
		ICAL_NO_PROPERTY
	};
	gint i;
470

471 472 473
	g_return_if_fail (des_icalcomp != NULL);
	g_return_if_fail (src_icalcomp != NULL);
	g_return_if_fail (client != NULL);
474

475 476
	for (i = 0; look_in[i] != ICAL_NO_PROPERTY; i++) {
		icalproperty *prop = icalcomponent_get_first_property (src_icalcomp, look_in[i]);
Harry Lu's avatar
Harry Lu committed
477

478 479
		if (prop) {
			icalparameter *par = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
480

481 482
			if (par) {
				const gchar *tzid = icalparameter_get_tzid (par);
Harry Lu's avatar
Harry Lu committed
483

484 485 486
				if (tzid) {
					GError *error = NULL;
					icaltimezone *zone = NULL;
487

Matthew Barnes's avatar
Matthew Barnes committed
488 489 490 491 492 493 494
					e_cal_client_get_timezone_sync (
						client, tzid, &zone, NULL, &error);
					if (error != NULL) {
						g_warning (
							"%s: Cannot get timezone for '%s'. %s",
							G_STRFUNC, tzid, error->message);
						g_error_free (error);
495 496 497 498
					} else if (zone &&
						icalcomponent_get_timezone (des_icalcomp, icaltimezone_get_tzid (zone)) == NULL) {
						/* do not duplicate timezones in the component */
						icalcomponent *vtz_comp;
499

500 501 502 503 504 505
						vtz_comp = icaltimezone_get_component (zone);
						if (vtz_comp)
							icalcomponent_add_component (des_icalcomp, icalcomponent_new_clone (vtz_comp));
					}
				}
			}
506
		}
507 508
	}
}
Chenthill Palanisamy's avatar
Chenthill Palanisamy committed
509

510 511 512 513
static void
calendar_view_copy_clipboard (ESelectable *selectable)
{
	ECalendarView *cal_view;
514
	ECalendarViewPrivate *priv;
515 516 517 518 519 520
	GList *selected, *l;
	gchar *comp_str;
	icalcomponent *vcal_comp;
	icalcomponent *new_icalcomp;
	ECalendarViewEvent *event;
	GtkClipboard *clipboard;
Chenthill Palanisamy's avatar
Chenthill Palanisamy committed
521

522
	cal_view = E_CALENDAR_VIEW (selectable);
523
	priv = cal_view->priv;
Chenthill Palanisamy's avatar
Chenthill Palanisamy committed
524

525 526 527
	selected = e_calendar_view_get_selected_events (cal_view);
	if (!selected)
		return;
Matthew Barnes's avatar
Matthew Barnes committed
528

529 530 531 532 533
	if (priv->selected_cut_list) {
		g_slist_foreach (priv->selected_cut_list, (GFunc) g_object_unref, NULL);
		g_slist_free (priv->selected_cut_list);
		priv->selected_cut_list = NULL;
	}
534

535 536 537 538
	/* create top-level VCALENDAR component and add VTIMEZONE's */
	vcal_comp = e_cal_util_new_top_level ();
	for (l = selected; l != NULL; l = l->next) {
		event = (ECalendarViewEvent *) l->data;
Harry Lu's avatar
Harry Lu committed
539

540
		if (event && is_comp_data_valid (event)) {
541
			e_cal_util_add_timezones_from_component (vcal_comp, event->comp_data->icalcomp);
542

543 544 545
			add_related_timezones (vcal_comp, event->comp_data->icalcomp, event->comp_data->client);
		}
	}
546

547 548
	for (l = selected; l != NULL; l = l->next) {
		event = (ECalendarViewEvent *) l->data;
549

550 551 552
		if (!is_comp_data_valid (event))
			continue;

553
		new_icalcomp = icalcomponent_new_clone (event->comp_data->icalcomp);
554

555
		/* do not remove RECURRENCE-IDs from copied objects */
556
		icalcomponent_add_component (vcal_comp, new_icalcomp);
557 558
	}

559
	comp_str = icalcomponent_as_ical_string_r (vcal_comp);
560

561 562 563 564
	/* copy the VCALENDAR to the clipboard */
	clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
	e_clipboard_set_calendar (clipboard, comp_str, -1);
	gtk_clipboard_store (clipboard);
Rodrigo Moya's avatar
Rodrigo Moya committed
565

566 567 568 569
	/* free memory */
	icalcomponent_free (vcal_comp);
	g_free (comp_str);
	g_list_free (selected);
Rodrigo Moya's avatar
Rodrigo Moya committed
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
static void
calendar_view_component_created_cb (ECalModel *model,
				    ECalClient *client,
				    icalcomponent *original_icalcomp,
				    const gchar *new_uid,
				    gpointer user_data)
{
	gboolean strip_alarms = TRUE;
	ECalComponent *comp;
	ESourceRegistry *registry;
	GtkWidget *toplevel = user_data;

	comp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone (original_icalcomp));
	g_return_if_fail (comp != NULL);

	registry = e_cal_model_get_registry (model);

	if (new_uid)
		e_cal_component_set_uid (comp, new_uid);

	if ((itip_organizer_is_user (registry, comp, client) ||
	     itip_sentby_is_user (registry, comp, client)) &&
	     send_component_dialog ((GtkWindow *) toplevel, client, comp, TRUE, &strip_alarms, NULL)) {
		itip_send_component (model, E_CAL_COMPONENT_METHOD_REQUEST,
			comp, client, NULL, NULL, NULL, strip_alarms, FALSE, FALSE);
	}

	g_object_unref (comp);
}

static void
e_calendar_view_add_event_sync (ECalModel *model,
				ECalClient *client,
				time_t dtstart,
				icaltimezone *default_zone,
				icalcomponent *icalcomp,
				gboolean all_day,
				gboolean is_day_view,
				gint time_division,
				GtkWidget *top_level)
{
	ECalComponent *comp;
	struct icaltimetype itime, old_dtstart, old_dtend;
	time_t tt_start, tt_end, new_dtstart = 0;
	struct icaldurationtype ic_dur, ic_oneday;
	gchar *uid;
	gint start_offset, end_offset;
	gboolean all_day_event = FALSE;

	start_offset = 0;
	end_offset = 0;

	old_dtstart = icalcomponent_get_dtstart (icalcomp);
	tt_start = icaltime_as_timet (old_dtstart);
	old_dtend = icalcomponent_get_dtend (icalcomp);
	tt_end = icaltime_as_timet (old_dtend);
	ic_dur = icaldurationtype_from_int (tt_end - tt_start);

	if (icaldurationtype_as_int (ic_dur) > 60 *60 *24) {
		/* This is a long event */
		start_offset = old_dtstart.hour * 60 + old_dtstart.minute;
		end_offset = old_dtstart.hour * 60 + old_dtend.minute;
	}

	ic_oneday = icaldurationtype_null_duration ();
	ic_oneday.days = 1;

	if (is_day_view) {
		if (start_offset == 0 && end_offset == 0 && all_day)
			all_day_event = TRUE;

		if (all_day_event) {
			ic_dur = ic_oneday;
		} else if (icaldurationtype_as_int (ic_dur) >= 60 *60 *24 && !all_day) {
			/* copy & paste from top canvas to main canvas */
			ic_dur = icaldurationtype_from_int (time_division * 60);
		}

		if (all_day)
			new_dtstart = dtstart + start_offset * 60;
		else
			new_dtstart = dtstart;
	} else {
		if (old_dtstart.is_date && old_dtend.is_date
			&& memcmp (&ic_dur, &ic_oneday, sizeof (ic_dur)) == 0) {
			all_day_event = TRUE;
			new_dtstart = dtstart;
		} else {
			icaltimetype new_time = icaltime_from_timet_with_zone (dtstart, FALSE, default_zone);

			new_time.hour = old_dtstart.hour;
			new_time.minute = old_dtstart.minute;
			new_time.second = old_dtstart.second;

			new_dtstart = icaltime_as_timet_with_zone (new_time, old_dtstart.zone ? old_dtstart.zone : default_zone);
		}
	}

	itime = icaltime_from_timet_with_zone (new_dtstart, FALSE, old_dtstart.zone ? old_dtstart.zone : default_zone);
	/* set the timezone properly */
	itime.zone = old_dtstart.zone ? old_dtstart.zone : default_zone;
	if (all_day_event)
		itime.is_date = TRUE;
	icalcomponent_set_dtstart (icalcomp, itime);

	itime.is_date = FALSE;
	itime = icaltime_add (itime, ic_dur);
	if (all_day_event)
		itime.is_date = TRUE;
	icalcomponent_set_dtend (icalcomp, itime);

	/* The new uid stuff can go away once we actually set it in the backend */
	uid = e_cal_component_gen_uid ();
	comp = e_cal_component_new ();
	e_cal_component_set_icalcomponent (
		comp, icalcomponent_new_clone (icalcomp));
	e_cal_component_set_uid (comp, uid);
	g_free (uid);

	e_cal_component_commit_sequence (comp);

	e_cal_ops_create_component (model, client, e_cal_component_get_icalcomponent (comp),
		calendar_view_component_created_cb, g_object_ref (top_level), g_object_unref);

	g_object_unref (comp);
}

typedef struct {
	ECalendarView *cal_view;
	GSList *selected_cut_list; /* ECalModelComponent * */
	GSList *copied_uids; /* gchar * */
	gchar *ical_str;
	time_t selection_start;
	time_t selection_end;
	gboolean is_day_view;
	gint time_division;
	GtkWidget *top_level;
	gboolean success;
	ECalClient *client;
} PasteClipboardData;

static void
paste_clipboard_data_free (gpointer ptr)
Rodrigo Moya's avatar
Rodrigo Moya committed
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
	PasteClipboardData *pcd = ptr;

	if (pcd) {
		if (pcd->success && pcd->copied_uids && pcd->selected_cut_list) {
			ECalModel *model;
			ESourceRegistry *registry;
			GSList *link;

			model = e_calendar_view_get_model (pcd->cal_view);
			registry = e_cal_model_get_registry (model);

			for (link = pcd->selected_cut_list; link != NULL; link = g_slist_next (link)) {
				ECalModelComponent *comp_data = (ECalModelComponent *) link->data;
				ECalComponent *comp;
				const gchar *uid;
				GSList *found = NULL;

				/* Remove them one by one after ensuring it has been copied to the destination successfully */
				found = g_slist_find_custom (pcd->copied_uids, icalcomponent_get_uid (comp_data->icalcomp), (GCompareFunc) strcmp);
				if (!found)
					continue;

				g_free (found->data);
				pcd->copied_uids = g_slist_delete_link (pcd->copied_uids, found);

				comp = e_cal_component_new ();
				e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp));

				if ((itip_organizer_is_user (registry, comp, comp_data->client) ||
				    itip_sentby_is_user (registry, comp, comp_data->client))
				    && cancel_component_dialog ((GtkWindow *) pcd->top_level, comp_data->client, comp, TRUE))
					itip_send_component (model, E_CAL_COMPONENT_METHOD_CANCEL,
						comp, comp_data->client, NULL, NULL, NULL, TRUE, FALSE, TRUE);

				e_cal_component_get_uid (comp, &uid);
				if (e_cal_component_is_instance (comp)) {
					gchar *rid = NULL;

					/* when cutting detached instances, only cut that instance */
					rid = e_cal_component_get_recurid_as_string (comp);
					e_cal_ops_remove_component (model, comp_data->client, uid, rid, E_CAL_OBJ_MOD_THIS, TRUE);
					g_free (rid);
				} else {
					e_cal_ops_remove_component (model, comp_data->client, uid, NULL, E_CAL_OBJ_MOD_ALL, FALSE);
				}

				g_object_unref (comp);
			}
		}

		if (pcd->success && pcd->client) {
			ECalModel *model;

			model = e_calendar_view_get_model (pcd->cal_view);
			e_cal_model_emit_object_created (model, pcd->client);
		}

		g_clear_object (&pcd->cal_view);
		g_clear_object (&pcd->top_level);
		g_clear_object (&pcd->client);
		g_slist_free_full (pcd->selected_cut_list, g_object_unref);
		g_slist_free_full (pcd->copied_uids, g_free);
		g_free (pcd->ical_str);
		g_free (pcd);
	}
}

static void
cal_view_paste_clipboard_thread (EAlertSinkThreadJobData *job_data,
				 gpointer user_data,
				 GCancellable *cancellable,
				 GError **error)
{
	PasteClipboardData *pcd = user_data;
790 791 792
	icalcomponent *icalcomp;
	icalcomponent_kind kind;
	icaltimezone *default_zone;
793 794
	ECalModel *model;
	ESourceRegistry *registry;
795
	ESource *source = NULL, *default_source = NULL;
796 797 798 799 800
	EClientCache *client_cache;
	EClient *e_client;
	ECalClient *client = NULL;
	const gchar *message;
	const gchar *extension_name;
801
	gchar *display_name;
802 803 804 805 806 807 808 809 810 811 812 813
	guint copied_components = 1;
	gboolean all_day;
	GError *local_error = NULL;

	g_return_if_fail (pcd != NULL);

	icalcomp = icalparser_parse_string (pcd->ical_str);
	if (!icalcomp) {
		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
			_("Pasted text doesn't contain valid iCalendar data"));
		return;
	}
Rodrigo Moya's avatar
Rodrigo Moya committed
814

815 816
	model = e_calendar_view_get_model (pcd->cal_view);
	registry = e_cal_model_get_registry (model);
817

818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
	switch (e_cal_model_get_component_kind (model)) {
		case ICAL_VEVENT_COMPONENT:
			default_source = e_source_registry_ref_default_calendar (registry);
			extension_name = E_SOURCE_EXTENSION_CALENDAR;
			message = _("Default calendar not found");
			break;
		case ICAL_VJOURNAL_COMPONENT:
			default_source = e_source_registry_ref_default_memo_list (registry);
			extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
			message = _("Default memo list not found");
			break;
		case ICAL_VTODO_COMPONENT:
			default_source = e_source_registry_ref_default_task_list (registry);
			extension_name = E_SOURCE_EXTENSION_TASK_LIST;
			message = _("Default task list not found");
			break;
		default:
			g_warn_if_reached ();
			goto out;
	}
838

839 840 841 842 843
	source = e_source_registry_ref_source (registry, e_cal_model_get_default_source_uid (model));
	if (!source) {
		source = default_source;
		default_source = NULL;
	}
844

845 846
	if (!source) {
		const gchar *default_source_uid = e_cal_model_get_default_source_uid (model);
847

848 849
		e_alert_sink_thread_job_set_alert_arg_0 (job_data, default_source_uid ? default_source_uid : "");
		g_set_error_literal (&local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, message);
850

851 852
		return;
	}
853

854 855 856
	display_name = e_util_get_source_full_name (registry, source);
	e_alert_sink_thread_job_set_alert_arg_0 (job_data, display_name);
	g_free (display_name);
857 858
	client_cache = e_cal_model_get_client_cache (model);

859
	e_client = e_client_cache_get_client_sync (client_cache, source, extension_name, 30, cancellable, &local_error);
860 861 862 863 864 865 866 867 868 869
	if (!e_client) {
		e_util_propagate_open_source_job_error (job_data, extension_name, local_error, error);
		goto out;
	}

	client = E_CAL_CLIENT (e_client);
	kind = icalcomponent_isa (icalcomp);
	default_zone = e_cal_model_get_timezone (model);
	all_day = pcd->selection_end - pcd->selection_start == 60 * 60 * 24;
	copied_components = 0;
870

871 872
	if (kind == ICAL_VCALENDAR_COMPONENT) {
		icalcomponent *subcomp;
873

874 875 876 877 878
		/* add timezones first, to have them ready */
		for (subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VTIMEZONE_COMPONENT);
		     subcomp;
		     subcomp = icalcomponent_get_next_component (icalcomp, ICAL_VTIMEZONE_COMPONENT)) {
			icaltimezone *zone;
879

880 881
			zone = icaltimezone_new ();
			icaltimezone_set_component (zone, subcomp);
882 883 884 885

			if (!e_cal_client_add_timezone_sync (client, zone, cancellable, error)) {
				icaltimezone_free (zone, 1);
				goto out;
886
			}
887

888 889
			icaltimezone_free (zone, 1);
		}
890

891 892 893 894 895 896 897 898
		for (subcomp = icalcomponent_get_first_component (icalcomp, ICAL_VEVENT_COMPONENT);
		     subcomp;
		     subcomp = icalcomponent_get_next_component (icalcomp, ICAL_VEVENT_COMPONENT)) {
			if (e_cal_util_component_has_recurrences (subcomp)) {
				icalproperty *icalprop = icalcomponent_get_first_property (subcomp, ICAL_RRULE_PROPERTY);
				if (icalprop)
					icalproperty_remove_parameter_by_name (icalprop, "X-EVOLUTION-ENDDATE");
			}
899

900 901
			e_calendar_view_add_event_sync (model, client, pcd->selection_start, default_zone, subcomp, all_day,
				pcd->is_day_view, pcd->time_division, pcd->top_level);
902

903 904 905
			copied_components++;
			if (pcd->selected_cut_list)
				pcd->copied_uids = g_slist_prepend (pcd->copied_uids, g_strdup (icalcomponent_get_uid (subcomp)));
906
		}
907 908 909
	} else if (kind == e_cal_model_get_component_kind (model)) {
		e_calendar_view_add_event_sync (model, client, pcd->selection_start, default_zone, icalcomp, all_day,
			pcd->is_day_view, pcd->time_division, pcd->top_level);
910

911 912 913
		copied_components++;
		if (pcd->selected_cut_list)
			pcd->copied_uids = g_slist_prepend (pcd->copied_uids, g_strdup (icalcomponent_get_uid (icalcomp)));
914
	}
915

916 917
	pcd->success = !g_cancellable_is_cancelled (cancellable);
	pcd->client = g_object_ref (client);
918

919 920 921
 out:
	if (!copied_components && !g_cancellable_is_cancelled (cancellable) && error && !*error)
		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("No suitable component found"));
922

923 924 925 926
	icalcomponent_free (icalcomp);
	g_clear_object (&source);
	g_clear_object (&default_source);
	g_clear_object (&client);
927 928
}

929 930
static void
calendar_view_paste_clipboard (ESelectable *selectable)
931
{
932
	ECalModel *model;
933 934
	ECalendarView *cal_view;
	GtkClipboard *clipboard;
935

936
	cal_view = E_CALENDAR_VIEW (selectable);
937

938 939
	model = e_calendar_view_get_model (cal_view);

940
	clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
941

942 943 944
	/* Paste text into an event being edited. */
	if (gtk_clipboard_wait_is_text_available (clipboard)) {
		ECalendarViewClass *class;
945

946 947
		class = E_CALENDAR_VIEW_GET_CLASS (cal_view);
		g_return_if_fail (class->paste_text != NULL);
948

949
		class->paste_text (cal_view);
950

951 952
	/* Paste iCalendar data into the view. */
	} else if (e_clipboard_wait_is_calendar_available (clipboard)) {
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
		PasteClipboardData *pcd;
		ECalDataModel *data_model;
		GCancellable *cancellable;
		const gchar *alert_ident = NULL;

		switch (e_cal_model_get_component_kind (model)) {
			case ICAL_VEVENT_COMPONENT:
				alert_ident = "calendar:failed-create-event";
				break;
			case ICAL_VJOURNAL_COMPONENT:
				alert_ident = "calendar:failed-create-memo";
				break;
			case ICAL_VTODO_COMPONENT:
				alert_ident = "calendar:failed-create-task";
				break;
			default:
				g_warn_if_reached ();
				return;
971 972
		}

973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
		pcd = g_new0 (PasteClipboardData, 1);
		pcd->cal_view = g_object_ref (cal_view);
		pcd->selected_cut_list = cal_view->priv->selected_cut_list;
		cal_view->priv->selected_cut_list = NULL;
		pcd->copied_uids = NULL; /* gchar * */
		pcd->ical_str = e_clipboard_wait_for_calendar (clipboard);
		g_warn_if_fail (e_calendar_view_get_selected_time_range (cal_view, &pcd->selection_start, &pcd->selection_end));
		pcd->is_day_view = E_IS_DAY_VIEW (cal_view);
		if (pcd->is_day_view)
			pcd->time_division = e_calendar_view_get_time_divisions (cal_view);
		pcd->top_level = gtk_widget_get_toplevel (GTK_WIDGET (cal_view));
		if (pcd->top_level)
			g_object_ref (pcd->top_level);
		pcd->success = FALSE;
		pcd->client = NULL;

		data_model = e_cal_model_get_data_model (model);

		cancellable = e_cal_data_model_submit_thread_job (data_model, _("Pasting iCalendar data"), alert_ident,
			NULL, cal_view_paste_clipboard_thread, pcd, paste_clipboard_data_free);

		g_clear_object (&cancellable);
995
	}
996 997
}

998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
static void
calendar_view_delete_selection (ESelectable *selectable)
{
	ECalendarView *cal_view;
	GList *selected, *iter;

	cal_view = E_CALENDAR_VIEW (selectable);

	selected = e_calendar_view_get_selected_events (cal_view);

	for (iter = selected; iter != NULL; iter = iter->next) {
		ECalendarViewEvent *event = iter->data;

		/* XXX Why would this ever be NULL? */
		if (event == NULL)
			continue;

		calendar_view_delete_event (cal_view, event);
	}

	g_list_free (selected);
}

1021
static void
1022
e_calendar_view_class_init (ECalendarViewClass *class)
Rodrigo Moya's avatar
Rodrigo Moya committed
1023
{
1024
	GObjectClass *object_class;
1025
	GtkWidgetClass *widget_class;
1026
	GtkBindingSet *binding_set;
1027

1028
	g_type_class_add_private (class, sizeof (ECalendarViewPrivate));
Rodrigo Moya's avatar
Rodrigo Moya committed
1029

1030 1031 1032 1033
	object_class = G_OBJECT_CLASS (class);
	object_class->set_property = calendar_view_set_property;
	object_class->get_property = calendar_view_get_property;
	object_class->dispose = calendar_view_dispose;
1034
	object_class->constructed = calendar_view_constructed;
1035

1036 1037 1038 1039
	class->selection_changed = NULL;
	class->selected_time_changed = NULL;
	class->event_changed = NULL;
	class->event_added = NULL;
Rodrigo Moya's avatar
Rodrigo Moya committed
1040

1041 1042 1043 1044
	class->get_selected_events = NULL;
	class->get_selected_time_range = NULL;
	class->set_selected_time_range = NULL;
	class->get_visible_time_range = NULL;
1045
	class->precalc_visible_time_range = NULL;
1046 1047 1048
	class->update_query = NULL;
	class->open_event = e_calendar_view_open_event;
	class->paste_text = NULL;
1049

Matthew Barnes's avatar
Matthew Barnes committed
1050 1051 1052 1053 1054 1055
	/* Inherited from ESelectableInterface */
	g_object_class_override_property (
		object_class,
		PROP_COPY_TARGET_LIST,
		"copy-target-list");

1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
	g_object_class_install_property (
		object_class,
		PROP_MODEL,
		g_param_spec_object (
			"model",
			"Model",
			NULL,
			E_TYPE_CAL_MODEL,
			G_PARAM_READWRITE |
			G_PARAM_CONSTRUCT_ONLY));
1066

Matthew Barnes's avatar
Matthew Barnes committed
1067 1068 1069 1070 1071 1072
	/* Inherited from ESelectableInterface */
	g_object_class_override_property (
		object_class,
		PROP_PASTE_TARGET_LIST,
		"paste-target-list");

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
	g_object_class_install_property (
		object_class,
		PROP_TIME_DIVISIONS,
		g_param_spec_int (
			"time-divisions",
			"Time Divisions",
			NULL,
			G_MININT,
			G_MAXINT,
			30,
			G_PARAM_READWRITE));

1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
	g_object_class_install_property (
		object_class,
		PROP_IS_EDITING,
		g_param_spec_boolean (
			"is-editing",
			"Whether is in an editing mode",
			"Whether is in an editing mode",
			FALSE,
			G_PARAM_READABLE));

1095 1096 1097 1098 1099 1100 1101 1102 1103
	signals[POPUP_EVENT] = g_signal_new (
		"popup-event",
		G_TYPE_FROM_CLASS (class),
		G_SIGNAL_RUN_FIRST,
		G_STRUCT_OFFSET (ECalendarViewClass, popup_event),
		NULL, NULL,
		g_cclosure_marshal_VOID__BOXED,
		G_TYPE_NONE, 1,
		GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1104

1105 1106 1107 1108 1109 1110 1111 1112
	signals[SELECTION_CHANGED] = g_signal_new (
		"selection-changed",
		G_TYPE_FROM_CLASS (class),
		G_SIGNAL_RUN_LAST,
		G_STRUCT_OFFSET (ECalendarViewClass, selection_changed),
		NULL, NULL,
		g_cclosure_marshal_VOID__VOID,
		G_TYPE_NONE, 0);
1113

1114 1115 1116 1117 1118 1119 1120 1121
	signals[SELECTED_TIME_CHANGED] = g_signal_new (
		"selected-time-changed",
		G_TYPE_FROM_CLASS (class),
		G_SIGNAL_RUN_LAST,
		G_STRUCT_OFFSET (ECalendarViewClass, selected_time_changed),
		NULL, NULL,
		g_cclosure_marshal_VOID__VOID,
		G_TYPE_NONE, 0);
1122

1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
	signals[TIMEZONE_CHANGED] = g_signal_new (
		"timezone-changed",
		G_TYPE_FROM_CLASS (class),
		G_SIGNAL_RUN_LAST,
		G_STRUCT_OFFSET (ECalendarViewClass, timezone_changed),
		NULL, NULL,
		e_marshal_VOID__POINTER_POINTER,
		G_TYPE_NONE, 2,
		G_TYPE_POINTER,
		G_TYPE_POINTER);
1133

1134 1135 1136 1137 1138 1139 1140 1141 1142
	signals[EVENT_CHANGED] = g_signal_new (
		"event-changed",
		G_TYPE_FROM_CLASS (object_class),
		G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
		G_STRUCT_OFFSET (ECalendarViewClass, event_changed),
		NULL, NULL,
		g_cclosure_marshal_VOID__POINTER,
		G_TYPE_NONE, 1,
		G_TYPE_POINTER);
1143

1144 1145 1146 1147 1148 1149 1150 1151 1152
	signals[EVENT_ADDED] = g_signal_new (
		"event-added",
		G_TYPE_FROM_CLASS (object_class),
		G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
		G_STRUCT_OFFSET (ECalendarViewClass, event_added),
		NULL, NULL,
		g_cclosure_marshal_VOID__POINTER,
		G_TYPE_NONE, 1,
		G_TYPE_POINTER);
1153

1154 1155 1156 1157 1158 1159 1160 1161
	signals[OPEN_EVENT] = g_signal_new (
		"open-event",
		G_TYPE_FROM_CLASS (class),
		G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
		G_STRUCT_OFFSET (ECalendarViewClass, open_event),
		NULL, NULL,
		g_cclosure_marshal_VOID__VOID,
		G_TYPE_NONE, 0);
1162

1163 1164 1165 1166 1167 1168 1169 1170
	signals[MOVE_VIEW_RANGE] = g_signal_new (
		"move-view-range",
		G_TYPE_FROM_CLASS (object_class),
		G_SIGNAL_RUN_LAST,
		G_STRUCT_OFFSET (ECalendarViewClass, move_view_range),
		NULL, NULL,
		NULL, /* default marshal */
		G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT64);
1171

1172
	/* Key bindings */
Milan Crha's avatar
Milan Crha committed
1173

1174
	binding_set = gtk_binding_set_by_class (class);
1175

1176 1177
	gtk_binding_entry_add_signal (
		binding_set, GDK_KEY_o, GDK_CONTROL_MASK, "open-event", 0);
1178

1179 1180 1181 1182
	/* init the accessibility support for e_day_view */
	widget_class = GTK_WIDGET_CLASS (class);
	gtk_widget_class_set_accessible_type (widget_class, EA_TYPE_CAL_VIEW);
}
1183

1184 1185 1186 1187
static void
e_calendar_view_init (ECalendarView *calendar_view)
{
	GtkTargetList *target_list;
1188

1189
	calendar_view->priv = E_CALENDAR_VIEW_GET_PRIVATE (calendar_view);
1190

1191 1192
	/* Set this early to avoid a divide-by-zero during init. */
	calendar_view->priv->time_divisions = 30;
Milan Crha's avatar
Milan Crha committed
1193

1194 1195 1196
	target_list = gtk_target_list_new (NULL, 0);
	e_target_list_add_calendar_targets (target_list, 0);
	calendar_view->priv->copy_target_list = target_list;
1197

1198 1199 1200
	target_list = gtk_target_list_new (NULL, 0);
	e_target_list_add_calendar_targets (target_list, 0);
	calendar_view->priv->paste_target_list = target_list;
1201
}
1202

1203 1204
static void
calendar_view_selectable_init (ESelectableInterface *iface)
1205
{
1206 1207 1208 1209 1210
	iface->update_actions = calendar_view_update_actions;
	iface->cut_clipboard = calendar_view_cut_clipboard;
	iface->copy_clipboard = calendar_view_copy_clipboard;
	iface->paste_clipboard = calendar_view_paste_clipboard;
	iface->delete_selection = calendar_view_delete_selection;
1211
}
Rodrigo Moya's avatar
Rodrigo Moya committed
1212

1213
void
1214 1215
e_calendar_view_popup_event (ECalendarView *calendar_view,
                             GdkEvent *button_event)
1216
{
1217 1218
	g_return_if_fail (E_IS_CALENDAR_VIEW (calendar_view));
	g_return_if_fail (button_event != NULL);
1219

1220
	g_signal_emit (calendar_view, signals[POPUP_EVENT], 0, button_event);
1221
}
1222

1223 1224 1225 1226
ECalModel *
e_calendar_view_get_model (ECalendarView *cal_view)
{
	g_return_val_if_fail (E_IS_CALENDAR_VIEW (cal_view), NULL);
1227

1228
	return cal_view->priv->model;
1229 1230
}

1231 1232
icaltimezone *
e_calendar_view_get_timezone (ECalendarView *cal_view)
Rodrigo Moya's avatar
Rodrigo Moya committed
1233
{
1234 1235 1236
	g_return_val_if_fail (E_IS_CALENDAR_VIEW (cal_view), NULL);
	return e_cal_model_get_timezone (cal_view->priv->model);
}
Rodrigo Moya's avatar
Rodrigo Moya committed
1237

1238
void
1239 1240
e_calendar_view_set_timezone (ECalendarView *cal_view,
                              icaltimezone *zone)
1241 1242
{
	icaltimezone *old_zone;
Rodrigo Moya's avatar
Rodrigo Moya committed