Example #1
0
/* Event handler for day groups in the month item.  A button press makes the calendar jump to the
 * selected day and destroys the Go-to dialog box.
 */
static void
ecal_event (ECalendarItem *calitem, gpointer user_data)
{
	GoToDialog *dlg = user_data;
	GDate start_date, end_date;
	struct icaltimetype tt = icaltime_null_time ();
	time_t et;

	e_calendar_item_get_selection (calitem, &start_date, &end_date);

	tt.year = g_date_get_year (&start_date);
	tt.month = g_date_get_month (&start_date);
	tt.day = g_date_get_day (&start_date);

	et = icaltime_as_timet_with_zone (tt, gnome_calendar_get_timezone (dlg->gcal));

	gnome_calendar_goto (dlg->gcal, et);

	gtk_dialog_response (GTK_DIALOG (dlg->dialog), GTK_RESPONSE_NONE);
	/* gnome_dialog_close (GNOME_DIALOG (dlg->dialog)); */
}
Example #2
0
static void date_changed_cb (AnnumShellWindow *self,
			     GnomeCalendarViewType view,
			     AnnumShellView *shell_view)
{
	const char *view_id;
	ECalendar *date_navigator;
	GDate *today;
	GDate start;
	GDate end;

	if (view != GNOME_CAL_DAY_VIEW)
		return;

	/* Week_View also uses GNOME_CAL_DAY_VIEW, so make sure */
	view_id = e_shell_view_get_view_id (E_SHELL_VIEW (shell_view));
	if (!g_strcmp0 (view_id, "Week_View"))
		return;

	/* DAY_VIEW is treated specially, because we only want to have
	 * the button toggled if we are showing today, not any other
	 * day
	 */

	date_navigator = annum_shell_sidebar_get_date_navigator (ANNUM_SHELL_SIDEBAR (self->priv->sidebar));

	today = g_date_new ();
	g_date_set_time_t (today, time (NULL));

	e_calendar_item_get_selection (date_navigator->calitem,
				       &start, &end);

	if (g_date_compare (today, &start) || g_date_compare (&start, &end)) {
		GtkAction *action = gtk_action_group_get_action (self->priv->action_group,
								 "ShowDay");
		gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action),
						    ANNUM_VIEW_DAY);
	}

	g_date_free (today);
}
Example #3
0
static void annum_shell_view_notify_view_id_cb (AnnumShellView * self)
{
	AnnumShellContent *shell_content;
	ECalendar *date_navigator;
	GnomeCalendar *calendar;
	const gchar *view_id;
	GnomeCalendarViewType view_type;
	GDate gdate_start;
	GDate gdate_end;

	view_id = e_shell_view_get_view_id (E_SHELL_VIEW (self));

	/* A NULL view ID implies we're in a custom view.  But you can
	 * only get to a custom view via the "Define Views" dialog, which
	 * would have already modified the view instance appropriately.
	 * Furthermore, there's no way to refer to a custom view by ID
	 * anyway, since custom views have no IDs. */
	if (view_id == NULL)
		return;

	view_type = gnome_cal_view_type_from_view_id (view_id);

	shell_content = self->priv->prox_shell_content;
	calendar = annum_shell_content_get_calendar (shell_content);

	gnome_calendar_display_view (calendar, view_type);

	if (view_type != GNOME_CAL_DAY_VIEW)
		return;

	/* Make sure just the day is selected, for this case */
	date_navigator = annum_shell_sidebar_get_date_navigator (self->priv->prox_shell_sidebar);
	e_calendar_item_get_selection (date_navigator->calitem,
				       &gdate_start, &gdate_end);
	e_calendar_item_set_selection (date_navigator->calitem,
				       &gdate_start, &gdate_start);
}
Example #4
0
static void
annum_shell_view_date_navigator_selection_changed_cb (AnnumShellView * self,
						       ECalendarItem * calitem)
{
	AnnumShellContent *prox_shell_content;
	GnomeCalendarViewType switch_to;
	GnomeCalendarViewType view_type;
	GnomeCalendar *calendar;
	ECalModel *model;
	GDate start_date, end_date;
	GDate new_start_date, new_end_date;
	icaltimetype tt;
	icaltimezone *timezone;
	time_t start, end, new_time;
	gboolean starts_on_week_start_day;
	gint new_days_shown;
	gint week_start_day;

	prox_shell_content = self->priv->prox_shell_content;
	calendar = annum_shell_content_get_calendar (prox_shell_content);

	model = gnome_calendar_get_model (calendar);
	view_type = gnome_calendar_get_view (calendar);
	switch_to = view_type;

	timezone = e_cal_model_get_timezone (model);
	week_start_day = e_cal_model_get_week_start_day (model);
	e_cal_model_get_time_range (model, &start, &end);

	time_to_gdate_with_zone (&start_date, start, timezone);
	time_to_gdate_with_zone (&end_date, end, timezone);

	if (view_type == GNOME_CAL_MONTH_VIEW) {
		EWeekView *week_view;
		ECalendarView *calendar_view;
		gboolean multi_week_view;
		gboolean compress_weekend;

		calendar_view =
		    gnome_calendar_get_calendar_view (calendar,
						      GNOME_CAL_MONTH_VIEW);

		week_view = E_WEEK_VIEW (calendar_view);
		multi_week_view = e_week_view_get_multi_week_view (week_view);
		compress_weekend = e_week_view_get_compress_weekend (week_view);

		if (week_start_day == 0
		    && (!multi_week_view || compress_weekend))
			g_date_add_days (&start_date, 1);
	}

	g_date_subtract_days (&end_date, 1);

	e_calendar_item_get_selection (calitem, &new_start_date, &new_end_date);

	/* There used to be a check here to make sure the rest of the
	 * code only ran when the date actually changed. We do not
	 * this to simplify always having three columns for the day
	 * view.
	 */

	new_days_shown =
	    g_date_get_julian (&new_end_date) -
	    g_date_get_julian (&new_start_date) + 1;

	/* If a complete week is selected we show the week view.
	 * Note that if weekends are compressed and the week start
	 * day is set to Sunday, we don't actually show complete
	 * weeks in the week view, so this may need tweaking. */
	starts_on_week_start_day =
	    (g_date_get_weekday (&new_start_date) % 7 == week_start_day);

	/* Update selection to be in the new time range. */
	tt = icaltime_null_time ();
	tt.year = g_date_get_year (&new_start_date);
	tt.month = g_date_get_month (&new_start_date);
	tt.day = g_date_get_day (&new_start_date);
	new_time = icaltime_as_timet_with_zone (tt, timezone);

	/* Switch views as appropriate, and change the number of
	 * days or weeks shown. */
	if (new_days_shown > 9) {
		if (view_type != GNOME_CAL_LIST_VIEW) {
			ECalendarView *calendar_view;

			calendar_view =
			    gnome_calendar_get_calendar_view (calendar,
							      GNOME_CAL_MONTH_VIEW);
			e_week_view_set_weeks_shown (E_WEEK_VIEW
						     (calendar_view),
						     (new_days_shown + 6) / 7);
			switch_to = GNOME_CAL_MONTH_VIEW;
		}
	} else if (new_days_shown == 7 && starts_on_week_start_day)
		switch_to = GNOME_CAL_WEEK_VIEW;
	else {
		ECalendarView *calendar_view;

		calendar_view =
		    gnome_calendar_get_calendar_view (calendar,
						      GNOME_CAL_DAY_VIEW);

		/* We always show three days */
		if (new_days_shown == 1)
		    new_days_shown = 3;

		e_day_view_set_days_shown (E_DAY_VIEW (calendar_view),
					   new_days_shown);

		if (new_days_shown != 5 || !starts_on_week_start_day)
			switch_to = GNOME_CAL_DAY_VIEW;

		else if (view_type != GNOME_CAL_WORK_WEEK_VIEW)
			switch_to = GNOME_CAL_DAY_VIEW;
	}

	/* Make the views display things properly. */
	gnome_calendar_update_view_times (calendar, new_time);
	gnome_calendar_set_view (calendar, switch_to);
	gnome_calendar_set_range_selected (calendar, TRUE);

	gnome_calendar_notify_dates_shown_changed (calendar);

	g_signal_emit (self, signals[DATE_CHANGED], 0, switch_to);
}