GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit 7ba003ac authored by Milan Crha's avatar Milan Crha

I#380 - [Calendar] Prefill start time in the future, rather than in the past

Closes GNOME/evolution#380
parent e3711af3
......@@ -1482,30 +1482,29 @@ e_calendar_view_open_event (ECalendarView *cal_view)
}
/**
* e_calendar_view_new_appointment_full
* e_calendar_view_new_appointment
* @cal_view: an #ECalendarView
* @all_day: Whether create all day event or not.
* @meeting: This is a meeting or an appointment.
* @no_past_date: Don't create event in past date, use actual date instead
* (if %TRUE).
* @flags: bit-or of ENewAppointmentFlags
*
* Opens an event editor dialog for a new appointment. The appointment's
* start and end times are set to the currently selected time range in
* the calendar view.
* the calendar view, unless the flags contain E_NEW_APPOINTMENT_FLAG_FORCE_CURRENT_TIME,
* in which case the current time is used.
*
* When the selection is for all day and we don't need @all_day event,
* then this do a rounding to the actual hour for actual day (today) and
* When the selection is for all day and we don't need all day event,
* then this does a rounding to the actual hour for actual day (today) and
* to the 'day begins' from preferences in other selected day.
*/
void
e_calendar_view_new_appointment_full (ECalendarView *cal_view,
gboolean all_day,
gboolean meeting,
gboolean no_past_date)
e_calendar_view_new_appointment (ECalendarView *cal_view,
guint32 flags)
{
ECalModel *model;
time_t dtstart, dtend, now;
gboolean do_rounding = FALSE;
gboolean all_day = (flags & E_NEW_APPOINTMENT_FLAG_ALL_DAY) != 0;
gboolean meeting = (flags & E_NEW_APPOINTMENT_FLAG_MEETING) != 0;
gboolean no_past_date = (flags & E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE) != 0;
g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view));
......@@ -1513,12 +1512,13 @@ e_calendar_view_new_appointment_full (ECalendarView *cal_view,
now = time (NULL);
if (!e_calendar_view_get_selected_time_range (cal_view, &dtstart, &dtend)) {
if ((flags & E_NEW_APPOINTMENT_FLAG_FORCE_CURRENT_TIME) != 0 ||
!e_calendar_view_get_selected_time_range (cal_view, &dtstart, &dtend)) {
dtstart = now;
dtend = dtstart + 3600;
}
if (no_past_date && dtstart < now) {
if (no_past_date && dtstart <= now) {
dtend = time_day_begin (now) + (dtend - dtstart);
dtstart = time_day_begin (now);
do_rounding = TRUE;
......@@ -1550,6 +1550,8 @@ e_calendar_view_new_appointment_full (ECalendarView *cal_view,
}
dtstart = dtstart + (60 * 60 * hours) + (mins * 60);
if (no_past_date && dtstart <= now)
dtstart += ((((now - dtstart) / 60 / time_div)) + time_div) * 60;
dtend = dtstart + (time_div * 60);
}
......@@ -1558,14 +1560,6 @@ e_calendar_view_new_appointment_full (ECalendarView *cal_view,
dtstart, dtend, meeting, all_day);
}
void
e_calendar_view_new_appointment (ECalendarView *cal_view)
{
g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view));
e_calendar_view_new_appointment_full (cal_view, FALSE, FALSE, FALSE);
}
/* Ensures the calendar is selected */
static void
object_created_cb (ECompEditor *comp_editor,
......
......@@ -133,6 +133,14 @@ typedef enum {
E_CALENDAR_VIEW_MOVE_TO_EXACT_DAY
} ECalendarViewMoveType;
typedef enum {
E_NEW_APPOINTMENT_FLAG_NONE = 0,
E_NEW_APPOINTMENT_FLAG_ALL_DAY = 1 << 0,
E_NEW_APPOINTMENT_FLAG_MEETING = 1 << 1,
E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE = 1 << 2,
E_NEW_APPOINTMENT_FLAG_FORCE_CURRENT_TIME = 1 << 3
} ENewAppointmentFlags;
struct _ECalendarViewClass {
GtkGridClass parent_class;
......@@ -231,12 +239,8 @@ void e_calendar_view_add_event (ECalendarView *cal_view,
icaltimezone *default_zone,
icalcomponent *icalcomp,
gboolean in_top_canvas);
void e_calendar_view_new_appointment_full
(ECalendarView *cal_view,
gboolean all_day,
gboolean meeting,
gboolean no_past_date);
void e_calendar_view_new_appointment (ECalendarView *cal_view);
void e_calendar_view_new_appointment (ECalendarView *cal_view,
guint32 flags); /* bit-or of ENewAppointmentFlags */
void e_calendar_view_edit_appointment
(ECalendarView *cal_view,
ECalClient *client,
......
......@@ -2993,7 +2993,8 @@ e_week_view_on_button_press (GtkWidget *widget,
week_view->before_click_dtstart,
week_view->before_click_dtend);
}
e_calendar_view_new_appointment_full (E_CALENDAR_VIEW (week_view), FALSE, calendar_config_get_prefer_meeting (), FALSE);
e_calendar_view_new_appointment (E_CALENDAR_VIEW (week_view), E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE |
(calendar_config_get_prefer_meeting () ? E_NEW_APPOINTMENT_FLAG_MEETING : 0));
return TRUE;
}
......
......@@ -320,7 +320,7 @@ action_interface_do_action (AtkAction *action,
switch (index) {
case 0:
/* New Appointment */
e_calendar_view_new_appointment (cal_view);
e_calendar_view_new_appointment (cal_view, E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE);
break;
case 1:
/* New All Day Event */
......
......@@ -82,7 +82,10 @@ action_event_new_cb (GtkAction *action,
view = e_cal_shell_content_get_current_calendar_view (E_CAL_SHELL_CONTENT (shell_content));
if (view != NULL) {
e_calendar_view_new_appointment_full (view, is_all_day, is_meeting, TRUE);
e_calendar_view_new_appointment (view, E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE |
(is_all_day ? E_NEW_APPOINTMENT_FLAG_ALL_DAY : 0) |
(is_meeting ? E_NEW_APPOINTMENT_FLAG_MEETING : 0) |
(e_shell_view_is_active (shell_view) ? 0 : E_NEW_APPOINTMENT_FLAG_FORCE_CURRENT_TIME));
return;
}
}
......
......@@ -516,16 +516,11 @@ action_event_all_day_new_cb (GtkAction *action,
ECalShellContent *cal_shell_content;
ECalendarView *calendar_view;
/* These are just for readability. */
gboolean all_day = TRUE;
gboolean meeting = FALSE;
gboolean no_past_date = FALSE;
cal_shell_content = cal_shell_view->priv->cal_shell_content;
calendar_view = e_cal_shell_content_get_current_calendar_view (cal_shell_content);
e_calendar_view_new_appointment_full (
calendar_view, all_day, meeting, no_past_date);
e_calendar_view_new_appointment (calendar_view, E_NEW_APPOINTMENT_FLAG_ALL_DAY | E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE |
(e_shell_view_is_active (E_SHELL_VIEW (cal_shell_view)) ? 0 : E_NEW_APPOINTMENT_FLAG_FORCE_CURRENT_TIME));
}
static void
......@@ -793,16 +788,11 @@ action_event_meeting_new_cb (GtkAction *action,
ECalShellContent *cal_shell_content;
ECalendarView *calendar_view;
/* These are just for readability. */
gboolean all_day = FALSE;
gboolean meeting = TRUE;
gboolean no_past_date = FALSE;
cal_shell_content = cal_shell_view->priv->cal_shell_content;
calendar_view = e_cal_shell_content_get_current_calendar_view (cal_shell_content);
e_calendar_view_new_appointment_full (
calendar_view, all_day, meeting, no_past_date);
e_calendar_view_new_appointment (calendar_view, E_NEW_APPOINTMENT_FLAG_MEETING | E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE |
(e_shell_view_is_active (E_SHELL_VIEW (cal_shell_view)) ? 0 : E_NEW_APPOINTMENT_FLAG_FORCE_CURRENT_TIME));
}
static void
......@@ -815,7 +805,8 @@ action_event_new_cb (GtkAction *action,
cal_shell_content = cal_shell_view->priv->cal_shell_content;
calendar_view = e_cal_shell_content_get_current_calendar_view (cal_shell_content);
e_calendar_view_new_appointment (calendar_view);
e_calendar_view_new_appointment (calendar_view, E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE |
(e_shell_view_is_active (E_SHELL_VIEW (cal_shell_view)) ? 0 : E_NEW_APPOINTMENT_FLAG_FORCE_CURRENT_TIME));
}
typedef struct
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment