[evolution] Calendar: Option to shorten an event time from the end or from the start



commit 0097f452dc9d47fdc3d3452dd005219b3f2741ff
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jun 27 11:31:51 2022 +0200

    Calendar: Option to shorten an event time from the end or from the start
    
    This replaces the option to shorten the event from the end only and allows
    the user to set whether the even should have moved the start or the end.

 data/org.gnome.evolution.calendar.gschema.xml.in |  11 +-
 src/calendar/gui/comp-util.c                     |  17 +-
 src/calendar/gui/e-cal-ops.c                     |  11 +-
 src/calendar/gui/e-calendar-view.c               |  28 +--
 src/calendar/gui/e-comp-editor-event.c           |   2 +-
 src/calendar/gui/e-comp-editor-memo.c            |   2 +-
 src/calendar/gui/e-comp-editor-property-parts.c  | 242 ++++++++++++++++++++++-
 src/calendar/gui/e-comp-editor-property-parts.h  |   3 +-
 src/calendar/gui/e-comp-editor-task.c            |   2 +-
 src/calendar/gui/e-comp-editor.c                 |  21 +-
 src/e-util/e-dateedit.c                          |  59 +++++-
 src/e-util/e-dateedit.h                          |   3 +
 src/modules/calendar/e-calendar-preferences.c    |  39 +++-
 src/modules/calendar/e-calendar-preferences.ui   |  27 ++-
 14 files changed, 421 insertions(+), 46 deletions(-)
---
diff --git a/data/org.gnome.evolution.calendar.gschema.xml.in 
b/data/org.gnome.evolution.calendar.gschema.xml.in
index 01f61f2992..199a05689a 100644
--- a/data/org.gnome.evolution.calendar.gschema.xml.in
+++ b/data/org.gnome.evolution.calendar.gschema.xml.in
@@ -504,10 +504,15 @@
       <_summary>Year view vertical preview position</_summary>
       <_description>Position of the vertical event preview for the year view, in pixels</_description>
     </key>
-    <key name="shorten-end-time" type="i">
+    <key name="shorten-time" type="i">
       <default>5</default>
-      <_summary>Shorten event end time by minutes</_summary>
-      <_description>By how many minutes to shorted new event end time</_description>
+      <_summary>Shorten event time by minutes</_summary>
+      <_description>By how many minutes to shorted new event time. Whether event end or start is changed is 
determined by "shorten-time-end" setting</_description>
+    </key>
+    <key name="shorten-time-end" type="b">
+      <default>true</default>
+      <_summary>Whether to shorten event end time</_summary>
+      <_description>A pair option for "shorten-time" setting, to change the end time or the start 
time</_description>
     </key>
     <key name="today-background-color" type="s">
       <default>''</default>
diff --git a/src/calendar/gui/comp-util.c b/src/calendar/gui/comp-util.c
index b61361e6ef..a67dd55efd 100644
--- a/src/calendar/gui/comp-util.c
+++ b/src/calendar/gui/comp-util.c
@@ -466,21 +466,30 @@ cal_comp_event_new_with_current_time_sync (ECalClient *client,
        } else {
                GSettings *settings;
                gint shorten_by;
+               gboolean shorten_end;
+
+               settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+               shorten_by = g_settings_get_int (settings, "shorten-time");
+               shorten_end = g_settings_get_boolean (settings, "shorten-time-end");
+               g_clear_object (&settings);
 
                itt = i_cal_time_new_current_with_zone (zone);
                i_cal_time_adjust (itt, 0, 1, -i_cal_time_get_minute (itt), -i_cal_time_get_second (itt));
 
+               if (!shorten_end && shorten_by > 0 && shorten_by < 60)
+                       i_cal_time_adjust (itt, 0, 0, shorten_by, 0);
+
                dt = e_cal_component_datetime_new_take (itt, zone ? g_strdup (i_cal_timezone_get_tzid (zone)) 
: NULL);
 
                e_cal_component_set_dtstart (comp, dt);
 
                i_cal_time_adjust (e_cal_component_datetime_get_value (dt), 0, 1, 0, 0);
 
-               settings = e_util_ref_settings ("org.gnome.evolution.calendar");
-               shorten_by = g_settings_get_int (settings, "shorten-end-time");
-               g_clear_object (&settings);
+               /* Make the end time a rounded hour (with 0 minutes) */
+               if (!shorten_end && shorten_by > 0 && shorten_by < 60)
+                       i_cal_time_adjust (e_cal_component_datetime_get_value (dt), 0, 0, -shorten_by, 0);
 
-               if (shorten_by > 0 && shorten_by < 60)
+               if (shorten_end && shorten_by > 0 && shorten_by < 60)
                        i_cal_time_adjust (e_cal_component_datetime_get_value (dt), 0, 0, -shorten_by, 0);
 
                e_cal_component_set_dtend (comp, dt);
diff --git a/src/calendar/gui/e-cal-ops.c b/src/calendar/gui/e-cal-ops.c
index a80e687018..77bc1622c2 100644
--- a/src/calendar/gui/e-cal-ops.c
+++ b/src/calendar/gui/e-cal-ops.c
@@ -1688,11 +1688,16 @@ e_cal_ops_new_component_ex (EShellWindow *shell_window,
 
        if (!all_day && source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS) {
                GSettings *settings = e_util_ref_settings ("org.gnome.evolution.calendar");
-               gint shorten_by = g_settings_get_int (settings, "shorten-end-time");
+               gint shorten_by = g_settings_get_int (settings, "shorten-time");
+               gboolean shorten_end = g_settings_get_boolean (settings, "shorten-time-end");
                g_clear_object (&settings);
 
-               if (shorten_by && (dtend - dtstart) / 60 > shorten_by)
-                       dtend -= shorten_by * 60;
+               if (shorten_by > 0 && (dtend - dtstart) / 60 > shorten_by) {
+                       if (shorten_end)
+                               dtend -= shorten_by * 60;
+                       else
+                               dtstart += shorten_by * 60;
+               }
        }
 
        ncd = new_component_data_new ();
diff --git a/src/calendar/gui/e-calendar-view.c b/src/calendar/gui/e-calendar-view.c
index a30ed96534..b9e8e928c2 100644
--- a/src/calendar/gui/e-calendar-view.c
+++ b/src/calendar/gui/e-calendar-view.c
@@ -716,6 +716,14 @@ e_calendar_view_add_event_sync (ECalModel *model,
        gchar *uid;
        gint start_offset, end_offset;
        gboolean all_day_event = FALSE;
+       GSettings *settings;
+       gint shorten_by;
+       gboolean shorten_end;
+
+       settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+       shorten_by = g_settings_get_int (settings, "shorten-time");
+       shorten_end = g_settings_get_boolean (settings, "shorten-time-end");
+       g_clear_object (&settings);
 
        start_offset = 0;
        end_offset = 0;
@@ -779,22 +787,16 @@ e_calendar_view_add_event_sync (ECalModel *model,
        i_cal_time_set_timezone (itime, old_dtstart_zone);
        if (all_day_event)
                i_cal_time_set_is_date (itime, TRUE);
+       else if (!shorten_end && shorten_by > 0 && i_cal_duration_as_int (ic_dur) / 60 > shorten_by)
+               i_cal_time_adjust (itime, 0, 0, shorten_by, 0);
        i_cal_component_set_dtstart (icomp, itime);
 
        i_cal_time_set_is_date (itime, FALSE);
-       if (!all_day_event) {
-               GSettings *settings;
-               gint shorten_by;
-
-               settings = e_util_ref_settings ("org.gnome.evolution.calendar");
-               shorten_by = g_settings_get_int (settings, "shorten-end-time");
-               g_clear_object (&settings);
-
-               if (i_cal_duration_as_int (ic_dur) / 60 > shorten_by) {
-                       gint dur = i_cal_duration_as_int (ic_dur) - (shorten_by * 60);
-                       g_clear_object (&ic_dur);
-                       ic_dur = i_cal_duration_new_from_int (dur);
-               }
+       /* The duration can be shortened always, not only when changing the end time */
+       if (!all_day_event && shorten_by > 0 && i_cal_duration_as_int (ic_dur) / 60 > shorten_by) {
+               gint dur = i_cal_duration_as_int (ic_dur) - (shorten_by * 60);
+               g_clear_object (&ic_dur);
+               ic_dur = i_cal_duration_new_from_int (dur);
        }
        btime = i_cal_time_add (itime, ic_dur);
        if (all_day_event)
diff --git a/src/calendar/gui/e-comp-editor-event.c b/src/calendar/gui/e-comp-editor-event.c
index 1a8a96fc19..52db318b11 100644
--- a/src/calendar/gui/e-comp-editor-event.c
+++ b/src/calendar/gui/e-comp-editor-event.c
@@ -889,7 +889,7 @@ e_comp_editor_event_constructed (GObject *object)
        part = e_comp_editor_property_part_location_new (focus_tracker);
        e_comp_editor_page_add_property_part (page, part, 0, 3, 3, 1);
 
-       part = e_comp_editor_property_part_dtstart_new (C_("ECompEditor", "_Start time:"), FALSE, FALSE);
+       part = e_comp_editor_property_part_dtstart_new (C_("ECompEditor", "_Start time:"), FALSE, FALSE, 
TRUE);
        e_comp_editor_page_add_property_part (page, part, 0, 4, 2, 1);
        e_comp_editor_property_part_set_sensitize_handled (part, TRUE);
        event_editor->priv->dtstart = part;
diff --git a/src/calendar/gui/e-comp-editor-memo.c b/src/calendar/gui/e-comp-editor-memo.c
index e4cec2686f..7f9d5b658f 100644
--- a/src/calendar/gui/e-comp-editor-memo.c
+++ b/src/calendar/gui/e-comp-editor-memo.c
@@ -324,7 +324,7 @@ e_comp_editor_memo_constructed (GObject *object)
        e_comp_editor_page_add_property_part (page, part, 0, 2, 2, 1);
        memo_editor->priv->summary = part;
 
-       part = e_comp_editor_property_part_dtstart_new (C_("ECompEditor", "Sta_rt date:"), TRUE, TRUE);
+       part = e_comp_editor_property_part_dtstart_new (C_("ECompEditor", "Sta_rt date:"), TRUE, TRUE, FALSE);
        e_comp_editor_page_add_property_part (page, part, 0, 3, 2, 1);
        memo_editor->priv->dtstart = part;
 
diff --git a/src/calendar/gui/e-comp-editor-property-parts.c b/src/calendar/gui/e-comp-editor-property-parts.c
index 42b6074e08..62db93f900 100644
--- a/src/calendar/gui/e-comp-editor-property-parts.c
+++ b/src/calendar/gui/e-comp-editor-property-parts.c
@@ -1338,6 +1338,9 @@ typedef struct _ECompEditorPropertyPartDtstartClass ECompEditorPropertyPartDtsta
 
 struct _ECompEditorPropertyPartDtstart {
        ECompEditorPropertyPartDatetimeLabeled parent;
+
+       gint shorten_time;
+       gboolean shorten_end;
 };
 
 struct _ECompEditorPropertyPartDtstartClass {
@@ -1348,27 +1351,127 @@ GType e_comp_editor_property_part_dtstart_get_type (void) G_GNUC_CONST;
 
 G_DEFINE_TYPE (ECompEditorPropertyPartDtstart, e_comp_editor_property_part_dtstart, 
E_TYPE_COMP_EDITOR_PROPERTY_PART_DATETIME_LABELED)
 
+enum {
+       PROP_DTSTART_0,
+       PROP_DTSTART_SHORTEN_TIME,
+       PROP_DTSTART_SHORTEN_END
+};
+
 static void
 e_comp_editor_property_part_dtstart_init (ECompEditorPropertyPartDtstart *part_dtstart)
 {
+       part_dtstart->shorten_time = 0;
+       part_dtstart->shorten_end = TRUE;
+}
+
+static void
+e_comp_editor_property_part_dtstart_get_property (GObject *object,
+                                                 guint property_id,
+                                                 GValue *value,
+                                                 GParamSpec *pspec)
+{
+       ECompEditorPropertyPartDtstart *part_dtstart = E_COMP_EDITOR_PROPERTY_PART_DTSTART (object);
+
+       g_return_if_fail (part_dtstart != NULL);
+
+       switch (property_id) {
+               case PROP_DTSTART_SHORTEN_TIME:
+                       g_value_set_int (value, part_dtstart->shorten_time);
+                       return;
+
+               case PROP_DTSTART_SHORTEN_END:
+                       g_value_set_boolean (value, part_dtstart->shorten_end);
+                       return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+e_comp_editor_property_part_dtstart_set_property (GObject *object,
+                                                 guint property_id,
+                                                 const GValue *value,
+                                                 GParamSpec *pspec)
+{
+       ECompEditorPropertyPartDtstart *part_dtstart = E_COMP_EDITOR_PROPERTY_PART_DTSTART (object);
+
+       g_return_if_fail (part_dtstart != NULL);
+
+       switch (property_id) {
+               case PROP_DTSTART_SHORTEN_TIME:
+                       if (part_dtstart->shorten_time != g_value_get_int (value)) {
+                               part_dtstart->shorten_time = g_value_get_int (value);
+
+                               if (!part_dtstart->shorten_end) {
+                                       GtkWidget *edit_widget;
+
+                                       edit_widget = e_comp_editor_property_part_get_edit_widget 
(E_COMP_EDITOR_PROPERTY_PART (part_dtstart));
+
+                                       e_date_edit_set_shorten_time (E_DATE_EDIT (edit_widget), 
part_dtstart->shorten_time);
+                               }
+
+                               g_object_notify (object, "shorten-time");
+                       }
+                       return;
+               case PROP_DTSTART_SHORTEN_END:
+                       if (!part_dtstart->shorten_end != !g_value_get_boolean (value)) {
+                               GtkWidget *edit_widget;
+
+                               part_dtstart->shorten_end = g_value_get_boolean (value);
+
+                               edit_widget = e_comp_editor_property_part_get_edit_widget 
(E_COMP_EDITOR_PROPERTY_PART (part_dtstart));
+
+                               if (part_dtstart->shorten_end)
+                                       e_date_edit_set_shorten_time (E_DATE_EDIT (edit_widget), 0);
+                               else
+                                       e_date_edit_set_shorten_time (E_DATE_EDIT (edit_widget), 
part_dtstart->shorten_time);
+
+                               g_object_notify (object, "shorten-end");
+                       }
+                       return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
 static void
 e_comp_editor_property_part_dtstart_class_init (ECompEditorPropertyPartDtstartClass *klass)
 {
        ECompEditorPropertyPartDatetimeClass *part_datetime_class;
+       GObjectClass *object_class;
 
        part_datetime_class = E_COMP_EDITOR_PROPERTY_PART_DATETIME_CLASS (klass);
        part_datetime_class->prop_kind = I_CAL_DTSTART_PROPERTY;
        part_datetime_class->i_cal_new_func = i_cal_property_new_dtstart;
        part_datetime_class->i_cal_set_func = i_cal_property_set_dtstart;
        part_datetime_class->i_cal_get_func = i_cal_property_get_dtstart;
+
+       object_class = G_OBJECT_CLASS (klass);
+       object_class->get_property = e_comp_editor_property_part_dtstart_get_property;
+       object_class->set_property = e_comp_editor_property_part_dtstart_set_property;
+
+       g_object_class_install_property (
+               object_class,
+               PROP_DTSTART_SHORTEN_TIME,
+               g_param_spec_int (
+                       "shorten-time", NULL, NULL,
+                       0, 29, 0,
+                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_DTSTART_SHORTEN_END,
+               g_param_spec_boolean (
+                       "shorten-end", NULL, NULL,
+                       TRUE,
+                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
 }
 
 ECompEditorPropertyPart *
 e_comp_editor_property_part_dtstart_new (const gchar *label,
                                         gboolean date_only,
-                                        gboolean allow_no_date_set)
+                                        gboolean allow_no_date_set,
+                                        gboolean allow_shorten_time)
 {
        ECompEditorPropertyPart *part;
 
@@ -1380,6 +1483,31 @@ e_comp_editor_property_part_dtstart_new (const gchar *label,
                E_COMP_EDITOR_PROPERTY_PART_DATETIME_LABELED (part),
                date_only, allow_no_date_set);
 
+       if (allow_shorten_time) {
+               GtkWidget *edit_widget;
+
+               edit_widget = e_comp_editor_property_part_get_edit_widget (part);
+               if (E_IS_DATE_EDIT (edit_widget)) {
+                       GSettings *settings;
+
+                       e_date_edit_set_shorten_time_end (E_DATE_EDIT (edit_widget), FALSE);
+
+                       settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+
+                       g_settings_bind (settings, "shorten-time",
+                               part, "shorten-time",
+                               G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
+
+                       g_settings_bind (settings, "shorten-time-end",
+                               part, "shorten-end",
+                               G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
+
+                       g_object_unref (settings);
+               } else {
+                       g_warn_if_reached ();
+               }
+       }
+
        return part;
 }
 
@@ -1399,6 +1527,9 @@ typedef struct _ECompEditorPropertyPartDtendClass ECompEditorPropertyPartDtendCl
 
 struct _ECompEditorPropertyPartDtend {
        ECompEditorPropertyPartDatetimeLabeled parent;
+
+       gint shorten_time;
+       gboolean shorten_end;
 };
 
 struct _ECompEditorPropertyPartDtendClass {
@@ -1409,21 +1540,120 @@ GType e_comp_editor_property_part_dtend_get_type (void) G_GNUC_CONST;
 
 G_DEFINE_TYPE (ECompEditorPropertyPartDtend, e_comp_editor_property_part_dtend, 
E_TYPE_COMP_EDITOR_PROPERTY_PART_DATETIME_LABELED)
 
+enum {
+       PROP_DTEND_0,
+       PROP_DTEND_SHORTEN_TIME,
+       PROP_DTEND_SHORTEN_END
+};
+
 static void
 e_comp_editor_property_part_dtend_init (ECompEditorPropertyPartDtend *part_dtend)
 {
+       part_dtend->shorten_time = 0;
+       part_dtend->shorten_end = FALSE;
+}
+
+static void
+e_comp_editor_property_part_dtend_get_property (GObject *object,
+                                               guint property_id,
+                                               GValue *value,
+                                               GParamSpec *pspec)
+{
+       ECompEditorPropertyPartDtend *part_dtend = E_COMP_EDITOR_PROPERTY_PART_DTEND (object);
+
+       g_return_if_fail (part_dtend != NULL);
+
+       switch (property_id) {
+               case PROP_DTEND_SHORTEN_TIME:
+                       g_value_set_int (value, part_dtend->shorten_time);
+                       return;
+
+               case PROP_DTEND_SHORTEN_END:
+                       g_value_set_boolean (value, part_dtend->shorten_end);
+                       return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+e_comp_editor_property_part_dtend_set_property (GObject *object,
+                                               guint property_id,
+                                               const GValue *value,
+                                               GParamSpec *pspec)
+{
+       ECompEditorPropertyPartDtend *part_dtend = E_COMP_EDITOR_PROPERTY_PART_DTEND (object);
+
+       g_return_if_fail (part_dtend != NULL);
+
+       switch (property_id) {
+               case PROP_DTEND_SHORTEN_TIME:
+                       if (part_dtend->shorten_time != g_value_get_int (value)) {
+                               part_dtend->shorten_time = g_value_get_int (value);
+
+                               if (part_dtend->shorten_end) {
+                                       GtkWidget *edit_widget;
+
+                                       edit_widget = e_comp_editor_property_part_get_edit_widget 
(E_COMP_EDITOR_PROPERTY_PART (part_dtend));
+
+                                       e_date_edit_set_shorten_time (E_DATE_EDIT (edit_widget), 
part_dtend->shorten_time);
+                               }
+
+                               g_object_notify (object, "shorten-time");
+                       }
+                       return;
+               case PROP_DTEND_SHORTEN_END:
+                       if (!part_dtend->shorten_end != !g_value_get_boolean (value)) {
+                               GtkWidget *edit_widget;
+
+                               part_dtend->shorten_end = g_value_get_boolean (value);
+
+                               edit_widget = e_comp_editor_property_part_get_edit_widget 
(E_COMP_EDITOR_PROPERTY_PART (part_dtend));
+
+                               if (part_dtend->shorten_end)
+                                       e_date_edit_set_shorten_time (E_DATE_EDIT (edit_widget), 
part_dtend->shorten_time);
+                               else
+                                       e_date_edit_set_shorten_time (E_DATE_EDIT (edit_widget), 0);
+
+                               g_object_notify (object, "shorten-end");
+                       }
+                       return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
 static void
 e_comp_editor_property_part_dtend_class_init (ECompEditorPropertyPartDtendClass *klass)
 {
        ECompEditorPropertyPartDatetimeClass *part_datetime_class;
+       GObjectClass *object_class;
 
        part_datetime_class = E_COMP_EDITOR_PROPERTY_PART_DATETIME_CLASS (klass);
        part_datetime_class->prop_kind = I_CAL_DTEND_PROPERTY;
        part_datetime_class->i_cal_new_func = i_cal_property_new_dtend;
        part_datetime_class->i_cal_set_func = i_cal_property_set_dtend;
        part_datetime_class->i_cal_get_func = i_cal_property_get_dtend;
+
+       object_class = G_OBJECT_CLASS (klass);
+       object_class->get_property = e_comp_editor_property_part_dtend_get_property;
+       object_class->set_property = e_comp_editor_property_part_dtend_set_property;
+
+       g_object_class_install_property (
+               object_class,
+               PROP_DTEND_SHORTEN_TIME,
+               g_param_spec_int (
+                       "shorten-time", NULL, NULL,
+                       0, 29, 0,
+                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_DTEND_SHORTEN_END,
+               g_param_spec_boolean (
+                       "shorten-end", NULL, NULL,
+                       TRUE,
+                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
 }
 
 ECompEditorPropertyPart *
@@ -1446,10 +1676,16 @@ e_comp_editor_property_part_dtend_new (const gchar *label,
        if (E_IS_DATE_EDIT (edit_widget)) {
                GSettings *settings;
 
+               e_date_edit_set_shorten_time_end (E_DATE_EDIT (edit_widget), TRUE);
+
                settings = e_util_ref_settings ("org.gnome.evolution.calendar");
 
-               g_settings_bind (settings, "shorten-end-time",
-                       edit_widget, "shorten-time",
+               g_settings_bind (settings, "shorten-time",
+                       part, "shorten-time",
+                       G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
+
+               g_settings_bind (settings, "shorten-time-end",
+                       part, "shorten-end",
                        G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
 
                g_object_unref (settings);
diff --git a/src/calendar/gui/e-comp-editor-property-parts.h b/src/calendar/gui/e-comp-editor-property-parts.h
index e0cf5114e7..80549d7993 100644
--- a/src/calendar/gui/e-comp-editor-property-parts.h
+++ b/src/calendar/gui/e-comp-editor-property-parts.h
@@ -37,7 +37,8 @@ ECompEditorPropertyPart *
 ECompEditorPropertyPart *
                e_comp_editor_property_part_dtstart_new         (const gchar *label,
                                                                 gboolean date_only,
-                                                                gboolean allow_no_date_set);
+                                                                gboolean allow_no_date_set,
+                                                                gboolean allow_shorten_time);
 ECompEditorPropertyPart *
                e_comp_editor_property_part_dtend_new           (const gchar *label,
                                                                 gboolean date_only,
diff --git a/src/calendar/gui/e-comp-editor-task.c b/src/calendar/gui/e-comp-editor-task.c
index 26ac39e9fa..427781f00e 100644
--- a/src/calendar/gui/e-comp-editor-task.c
+++ b/src/calendar/gui/e-comp-editor-task.c
@@ -921,7 +921,7 @@ e_comp_editor_task_constructed (GObject *object)
        part = e_comp_editor_property_part_location_new (focus_tracker);
        e_comp_editor_page_add_property_part (page, part, 0, 3, 4, 1);
 
-       part = e_comp_editor_property_part_dtstart_new (C_("ECompEditor", "Sta_rt date:"), TRUE, TRUE);
+       part = e_comp_editor_property_part_dtstart_new (C_("ECompEditor", "Sta_rt date:"), TRUE, TRUE, FALSE);
        e_comp_editor_page_add_property_part (page, part, 0, 4, 2, 1);
        task_editor->priv->dtstart = part;
 
diff --git a/src/calendar/gui/e-comp-editor.c b/src/calendar/gui/e-comp-editor.c
index a62c66ddee..aefa7d14ac 100644
--- a/src/calendar/gui/e-comp-editor.c
+++ b/src/calendar/gui/e-comp-editor.c
@@ -3441,18 +3441,27 @@ ece_check_start_before_end (ECompEditor *comp_editor,
 
                                        if (!i_cal_time_is_date (start_tt)) {
                                                GSettings *settings;
-                                               gint shorten_end_time;
+                                               gint shorten_by;
+                                               gboolean shorten_end;
 
                                                settings = e_util_ref_settings 
("org.gnome.evolution.calendar");
-                                               shorten_end_time = g_settings_get_int (settings, 
"shorten-end-time");
+                                               shorten_by = g_settings_get_int (settings, "shorten-time");
+                                               shorten_end = g_settings_get_int (settings, "shorten-time");
                                                g_clear_object (&settings);
 
-                                               if (shorten_end_time > 0 && shorten_end_time < 60) {
-                                                       i_cal_time_adjust (end_tt, 0, 0, -shorten_end_time, 
0);
+                                               if (shorten_by > 0 && shorten_by < 60) {
+                                                       if (shorten_end)
+                                                               i_cal_time_adjust (end_tt, 0, 0, -shorten_by, 
0);
+                                                       else
+                                                               i_cal_time_adjust (start_tt, 0, 0, 
shorten_by, 0);
 
                                                        /* Revert the change, when it would make the time 
order reverse */
-                                                       if (i_cal_time_compare (start_tt, end_tt) >= 0)
-                                                               i_cal_time_adjust (end_tt, 0, 0, 
shorten_end_time, 0);
+                                                       if (i_cal_time_compare (start_tt, end_tt) >= 0) {
+                                                               if (shorten_end)
+                                                                       i_cal_time_adjust (end_tt, 0, 0, 
shorten_by, 0);
+                                                               else
+                                                                       i_cal_time_adjust (start_tt, 0, 0, 
-shorten_by, 0);
+                                                       }
                                                }
                                        }
                                }
diff --git a/src/e-util/e-dateedit.c b/src/e-util/e-dateedit.c
index 9bbd7841e6..2b22b0f71f 100644
--- a/src/e-util/e-dateedit.c
+++ b/src/e-util/e-dateedit.c
@@ -116,6 +116,7 @@ struct _EDateEditPrivate {
        gboolean time_been_changed;
 
        gboolean allow_no_date_set;
+       gboolean shorten_time_end;
        gint shorten_time_minutes;
 };
 
@@ -129,6 +130,7 @@ enum {
        PROP_WEEK_START_DAY,
        PROP_TWODIGIT_YEAR_CAN_FUTURE,
        PROP_SET_NONE,
+       PROP_SHORTEN_TIME_END,
        PROP_SHORTEN_TIME
 };
 
@@ -272,6 +274,12 @@ date_edit_set_property (GObject *object,
                                e_date_edit_set_time (E_DATE_EDIT (object), -1);
                        return;
 
+               case PROP_SHORTEN_TIME_END:
+                       e_date_edit_set_shorten_time_end (
+                               E_DATE_EDIT (object),
+                               g_value_get_boolean (value));
+                       return;
+
                case PROP_SHORTEN_TIME:
                        e_date_edit_set_shorten_time (
                                E_DATE_EDIT (object),
@@ -331,6 +339,12 @@ date_edit_get_property (GObject *object,
                                E_DATE_EDIT (object)));
                        return;
 
+               case PROP_SHORTEN_TIME_END:
+                       g_value_set_boolean (
+                               value, e_date_edit_get_shorten_time_end (
+                               E_DATE_EDIT (object)));
+                       return;
+
                case PROP_SHORTEN_TIME:
                        g_value_set_int (
                                value, e_date_edit_get_shorten_time (
@@ -471,6 +485,18 @@ e_date_edit_class_init (EDateEditClass *class)
                        FALSE,
                        G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
+       g_object_class_install_property (
+               object_class,
+               PROP_SHORTEN_TIME_END,
+               g_param_spec_boolean (
+                       "shorten-time-end",
+                       "Shorten Time End",
+                       NULL,
+                       TRUE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS |
+                       G_PARAM_EXPLICIT_NOTIFY));
+
        g_object_class_install_property (
                object_class,
                PROP_SHORTEN_TIME,
@@ -518,6 +544,7 @@ e_date_edit_init (EDateEdit *dedit)
        dedit->priv->twodigit_year_can_future = TRUE;
        dedit->priv->date_been_changed = FALSE;
        dedit->priv->time_been_changed = FALSE;
+       dedit->priv->shorten_time_end = TRUE;
        dedit->priv->shorten_time_minutes = 0;
 
        gtk_orientable_set_orientation (GTK_ORIENTABLE (dedit), GTK_ORIENTATION_HORIZONTAL);
@@ -1819,8 +1846,12 @@ rebuild_time_popup (EDateEdit *dedit)
                        tmp_tm.tm_hour = hour;
                        tmp_tm.tm_min = min;
 
-                       if (priv->shorten_time_minutes) {
-                               tmp_tm.tm_min += 30 - priv->shorten_time_minutes;
+                       if (priv->shorten_time_minutes > 0) {
+                               if (priv->shorten_time_end)
+                                       tmp_tm.tm_min += 30 - priv->shorten_time_minutes;
+                               else
+                                       tmp_tm.tm_min += priv->shorten_time_minutes;
+
                                if (tmp_tm.tm_min >= 60) {
                                        tmp_tm.tm_min -= 60;
                                        tmp_tm.tm_hour++;
@@ -2681,3 +2712,27 @@ e_date_edit_set_shorten_time (EDateEdit *self,
                g_object_notify (G_OBJECT (self), "shorten-time");
        }
 }
+
+gboolean
+e_date_edit_get_shorten_time_end (EDateEdit *self)
+{
+       g_return_val_if_fail (E_IS_DATE_EDIT (self), FALSE);
+
+       return self->priv->shorten_time_end;
+}
+
+void
+e_date_edit_set_shorten_time_end (EDateEdit *self,
+                                 gboolean shorten_time_end)
+{
+       g_return_if_fail (E_IS_DATE_EDIT (self));
+
+       if (!self->priv->shorten_time_end != !shorten_time_end) {
+               self->priv->shorten_time_end = shorten_time_end;
+
+               if (self->priv->shorten_time_minutes > 0)
+                       rebuild_time_popup (self);
+
+               g_object_notify (G_OBJECT (self), "shorten-time-end");
+       }
+}
diff --git a/src/e-util/e-dateedit.h b/src/e-util/e-dateedit.h
index 824737de67..cf9b14a8dc 100644
--- a/src/e-util/e-dateedit.h
+++ b/src/e-util/e-dateedit.h
@@ -216,6 +216,9 @@ gboolean    e_date_edit_has_focus           (EDateEdit *dedit);
 gint           e_date_edit_get_shorten_time    (EDateEdit *self);
 void           e_date_edit_set_shorten_time    (EDateEdit *self,
                                                 gint minutes);
+gboolean       e_date_edit_get_shorten_time_end(EDateEdit *self);
+void           e_date_edit_set_shorten_time_end(EDateEdit *self,
+                                                gboolean shorten_time_end);
 
 G_END_DECLS
 
diff --git a/src/modules/calendar/e-calendar-preferences.c b/src/modules/calendar/e-calendar-preferences.c
index 16f1487ad9..c5d3af35ca 100644
--- a/src/modules/calendar/e-calendar-preferences.c
+++ b/src/modules/calendar/e-calendar-preferences.c
@@ -249,6 +249,32 @@ calendar_preferences_map_gdk_color_to_string (const GValue *value,
        return variant;
 }
 
+static gboolean
+calendar_preferences_shorten_time_kind_to_object_cb (GValue *value,
+                                                    GVariant *variant,
+                                                    gpointer user_data)
+{
+       gboolean shorten_time_end;
+
+       shorten_time_end = g_variant_get_boolean (variant);
+
+       g_value_set_string (value, shorten_time_end ? "end" : "start");
+
+       return TRUE;
+}
+
+static GVariant *
+calendar_preferences_shorten_time_kind_to_settings_cb (const GValue *value,
+                                                      const GVariantType *expected_type,
+                                                      gpointer user_data)
+{
+       const gchar *string;
+
+       string = g_value_get_string (value);
+
+       return g_variant_new_boolean (g_strcmp0 (string, "end") == 0);
+}
+
 static void
 calendar_preferences_dispose (GObject *object)
 {
@@ -856,12 +882,21 @@ calendar_preferences_construct (ECalendarPreferences *prefs,
                widget, "active",
                G_SETTINGS_BIND_DEFAULT);
 
-       widget = e_builder_get_widget (prefs->priv->builder, "shorten_end_time_interval");
+       widget = e_builder_get_widget (prefs->priv->builder, "shorten_time_interval");
        g_settings_bind (
-               settings, "shorten-end-time",
+               settings, "shorten-time",
                widget, "value",
                G_SETTINGS_BIND_DEFAULT);
 
+       widget = e_builder_get_widget (prefs->priv->builder, "shorten_time_kind");
+       g_settings_bind_with_mapping (
+               settings, "shorten-time-end",
+               widget, "active-id",
+               G_SETTINGS_BIND_DEFAULT,
+               calendar_preferences_shorten_time_kind_to_object_cb,
+               calendar_preferences_shorten_time_kind_to_settings_cb,
+               NULL, NULL);
+
        widget = e_builder_get_widget (prefs->priv->builder, "confirm_delete");
        g_settings_bind (
                settings, "confirm-delete",
diff --git a/src/modules/calendar/e-calendar-preferences.ui b/src/modules/calendar/e-calendar-preferences.ui
index 5b4712bbf0..82050be702 100644
--- a/src/modules/calendar/e-calendar-preferences.ui
+++ b/src/modules/calendar/e-calendar-preferences.ui
@@ -358,12 +358,12 @@
                     <property name="can_focus">False</property>
                     <property name="spacing">12</property>
                     <child>
-                      <object class="GtkLabel" id="shorten_end_label">
+                      <object class="GtkLabel" id="shorten_time_label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="label" translatable="yes" comments="Translators: This is part of 
'Shorten event end time by [ X ] minutes'">Sh_orten event end time by</property>
+                        <property name="label" translatable="yes" comments="Translators: This is part of 
'Shorten event time by [ X ] minutes'">Sh_orten event time by</property>
                         <property name="use_underline">True</property>
-                        <property name="mnemonic_widget">shorten_end_time_interval</property>
+                        <property name="mnemonic_widget">shorten_time_interval</property>
                         <property name="xalign">0</property>
                       </object>
                       <packing>
@@ -373,7 +373,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkSpinButton" id="shorten_end_time_interval">
+                      <object class="GtkSpinButton" id="shorten_time_interval">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="adjustment">adjustment5</property>
@@ -386,10 +386,10 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="shorten_end_label_suffix">
+                      <object class="GtkLabel" id="shorten_time_label_suffix">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="label" translatable="yes" comments="Translators: This is part of 
'Shorten event end time by [ X ] minutes'">minutes</property>
+                        <property name="label" translatable="yes" comments="Translators: This is part of 
'Shorten event time by [ X ] minutes'">minutes</property>
                         <property name="use_underline">False</property>
                         <property name="xalign">0</property>
                       </object>
@@ -399,6 +399,21 @@
                         <property name="position">2</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkComboBoxText" id="shorten_time_kind">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <items>
+                          <item id="end" translatable="yes">End events earlier</item>
+                          <item id="start" translatable="yes">Start events later</item>
+                        </items>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">3</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]