[evolution] Calendar: Add option to shorten event end time for new events



commit b18ace783dd9399ce4ed0092ed69ed6c451def30
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 20 10:22:12 2022 +0200

    Calendar: Add option to shorten event end time for new events
    
    This can be used to have predefined some time between events to move
    between rooms and such things, without a need to modify the end time
    for every single new event manually.

 data/org.gnome.evolution.calendar.gschema.xml.in |  5 ++
 src/calendar/gui/comp-util.c                     | 11 +++++
 src/calendar/gui/e-cal-ops.c                     |  9 ++++
 src/calendar/gui/e-calendar-view.c               | 14 ++++++
 src/calendar/gui/e-comp-editor-property-parts.c  | 16 ++++++
 src/e-util/e-dateedit.c                          | 59 +++++++++++++++++++++-
 src/e-util/e-dateedit.h                          |  4 ++
 src/modules/calendar/e-calendar-preferences.c    |  6 +++
 src/modules/calendar/e-calendar-preferences.ui   | 63 ++++++++++++++++++++++++
 9 files changed, 186 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.evolution.calendar.gschema.xml.in 
b/data/org.gnome.evolution.calendar.gschema.xml.in
index 1c9724eb09..b4142699b4 100644
--- a/data/org.gnome.evolution.calendar.gschema.xml.in
+++ b/data/org.gnome.evolution.calendar.gschema.xml.in
@@ -504,6 +504,11 @@
       <_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">
+      <default>5</default>
+      <_summary>Shorten event end time by minutes</_summary>
+      <_description>By how many minutes to shorted new event end time</_description>
+    </key>
 
     <!-- The following keys are deprecated. -->
 
diff --git a/src/calendar/gui/comp-util.c b/src/calendar/gui/comp-util.c
index 4c1319d88c..41a71414b7 100644
--- a/src/calendar/gui/comp-util.c
+++ b/src/calendar/gui/comp-util.c
@@ -462,6 +462,9 @@ cal_comp_event_new_with_current_time_sync (ECalClient *client,
                e_cal_component_set_dtstart (comp, dt);
                e_cal_component_set_dtend (comp, dt);
        } else {
+               GSettings *settings;
+               gint shorten_by;
+
                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));
 
@@ -470,6 +473,14 @@ cal_comp_event_new_with_current_time_sync (ECalClient *client,
                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);
+
+               if (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 7ec9b1a6ae..a80e687018 100644
--- a/src/calendar/gui/e-cal-ops.c
+++ b/src/calendar/gui/e-cal-ops.c
@@ -1686,6 +1686,15 @@ e_cal_ops_new_component_ex (EShellWindow *shell_window,
        if (for_client_uid)
                for_client_source = e_source_registry_ref_source (registry, for_client_uid);
 
+       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");
+               g_clear_object (&settings);
+
+               if (shorten_by && (dtend - dtstart) / 60 > shorten_by)
+                       dtend -= shorten_by * 60;
+       }
+
        ncd = new_component_data_new ();
        ncd->is_new_component = TRUE;
        ncd->shell = g_object_ref (shell);
diff --git a/src/calendar/gui/e-calendar-view.c b/src/calendar/gui/e-calendar-view.c
index c9480a0507..e1be54f174 100644
--- a/src/calendar/gui/e-calendar-view.c
+++ b/src/calendar/gui/e-calendar-view.c
@@ -782,6 +782,20 @@ e_calendar_view_add_event_sync (ECalModel *model,
        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);
+               }
+       }
        btime = i_cal_time_add (itime, ic_dur);
        if (all_day_event)
                i_cal_time_set_is_date (btime, TRUE);
diff --git a/src/calendar/gui/e-comp-editor-property-parts.c b/src/calendar/gui/e-comp-editor-property-parts.c
index b14c2c7fd6..42b6074e08 100644
--- a/src/calendar/gui/e-comp-editor-property-parts.c
+++ b/src/calendar/gui/e-comp-editor-property-parts.c
@@ -1432,6 +1432,7 @@ e_comp_editor_property_part_dtend_new (const gchar *label,
                                       gboolean allow_no_date_set)
 {
        ECompEditorPropertyPart *part;
+       GtkWidget *edit_widget;
 
        part = g_object_new (E_TYPE_COMP_EDITOR_PROPERTY_PART_DTEND,
                "label", label,
@@ -1441,6 +1442,21 @@ e_comp_editor_property_part_dtend_new (const gchar *label,
                E_COMP_EDITOR_PROPERTY_PART_DATETIME_LABELED (part),
                date_only, allow_no_date_set);
 
+       edit_widget = e_comp_editor_property_part_get_edit_widget (part);
+       if (E_IS_DATE_EDIT (edit_widget)) {
+               GSettings *settings;
+
+               settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+
+               g_settings_bind (settings, "shorten-end-time",
+                       edit_widget, "shorten-time",
+                       G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
+
+               g_object_unref (settings);
+       } else {
+               g_warn_if_reached ();
+       }
+
        return part;
 }
 
diff --git a/src/e-util/e-dateedit.c b/src/e-util/e-dateedit.c
index ab7dd6d572..8026313644 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;
+       gint shorten_time_minutes;
 };
 
 enum {
@@ -127,7 +128,8 @@ enum {
        PROP_USE_24_HOUR_FORMAT,
        PROP_WEEK_START_DAY,
        PROP_TWODIGIT_YEAR_CAN_FUTURE,
-       PROP_SET_NONE
+       PROP_SET_NONE,
+       PROP_SHORTEN_TIME
 };
 
 enum {
@@ -269,6 +271,12 @@ date_edit_set_property (GObject *object,
                        if (g_value_get_boolean (value))
                                e_date_edit_set_time (E_DATE_EDIT (object), -1);
                        return;
+
+               case PROP_SHORTEN_TIME:
+                       e_date_edit_set_shorten_time (
+                               E_DATE_EDIT (object),
+                               g_value_get_int (value));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -322,6 +330,12 @@ date_edit_get_property (GObject *object,
                                value, e_date_edit_get_twodigit_year_can_future (
                                E_DATE_EDIT (object)));
                        return;
+
+               case PROP_SHORTEN_TIME:
+                       g_value_set_int (
+                               value, e_date_edit_get_shorten_time (
+                               E_DATE_EDIT (object)));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -457,6 +471,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,
+               g_param_spec_int (
+                       "shorten-time",
+                       "Shorten Time",
+                       NULL,
+                       0, 29, 0,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS |
+                       G_PARAM_EXPLICIT_NOTIFY));
+
        signals[CHANGED] = g_signal_new (
                "changed",
                G_OBJECT_CLASS_TYPE (object_class),
@@ -492,6 +518,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_minutes = 0;
 
        gtk_orientable_set_orientation (GTK_ORIENTABLE (dedit), GTK_ORIENTATION_HORIZONTAL);
        gtk_box_set_spacing (GTK_BOX (dedit), 3);
@@ -1792,6 +1819,14 @@ 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 (tmp_tm.tm_min >= 60) {
+                                       tmp_tm.tm_min -= 60;
+                                       tmp_tm.tm_hour++;
+                               }
+                       }
+
                        e_time_format_time (
                                &tmp_tm, use_24_hour_format, 0,
                                buffer, sizeof (buffer));
@@ -2624,3 +2659,25 @@ e_date_edit_has_focus (EDateEdit *dedit)
                (gtk_widget_has_focus (dedit->priv->time_combo) ||
                 gtk_widget_has_focus (gtk_bin_get_child (GTK_BIN (dedit->priv->time_combo)))));
 }
+
+gint
+e_date_edit_get_shorten_time (EDateEdit *self)
+{
+       g_return_val_if_fail (E_IS_DATE_EDIT (self), 0);
+
+       return self->priv->shorten_time_minutes;
+}
+
+void
+e_date_edit_set_shorten_time (EDateEdit *self,
+                             gint minutes)
+{
+       g_return_if_fail (E_IS_DATE_EDIT (self));
+
+       if (self->priv->shorten_time_minutes != minutes && minutes >= 0 && minutes < 30) {
+               self->priv->shorten_time_minutes = minutes;
+               rebuild_time_popup (self);
+
+               g_object_notify (G_OBJECT (self), "shorten-time");
+       }
+}
diff --git a/src/e-util/e-dateedit.h b/src/e-util/e-dateedit.h
index 26fc20993b..824737de67 100644
--- a/src/e-util/e-dateedit.h
+++ b/src/e-util/e-dateedit.h
@@ -213,6 +213,10 @@ GtkWidget *        e_date_edit_get_entry           (EDateEdit *dedit);
 
 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);
+
 G_END_DECLS
 
 #endif /* E_DATE_EDIT_H */
diff --git a/src/modules/calendar/e-calendar-preferences.c b/src/modules/calendar/e-calendar-preferences.c
index 7440f09d6e..4b763506e9 100644
--- a/src/modules/calendar/e-calendar-preferences.c
+++ b/src/modules/calendar/e-calendar-preferences.c
@@ -856,6 +856,12 @@ calendar_preferences_construct (ECalendarPreferences *prefs,
                widget, "active",
                G_SETTINGS_BIND_DEFAULT);
 
+       widget = e_builder_get_widget (prefs->priv->builder, "shorten_end_time_interval");
+       g_settings_bind (
+               settings, "shorten-end-time",
+               widget, "value",
+               G_SETTINGS_BIND_DEFAULT);
+
        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 10806c032b..c0cfc593fb 100644
--- a/src/modules/calendar/e-calendar-preferences.ui
+++ b/src/modules/calendar/e-calendar-preferences.ui
@@ -25,6 +25,13 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkAdjustment" id="adjustment5">
+    <property name="upper">29</property>
+    <property name="lower">0</property>
+    <property name="value">5</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkListStore" id="model2">
     <columns>
       <!-- column-name gchararray -->
@@ -345,6 +352,62 @@
                     <property name="y_options">GTK_FILL</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkHBox" id="hbox16">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">12</property>
+                    <child>
+                      <object class="GtkLabel" id="shorten_end_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="use_underline">True</property>
+                        <property name="mnemonic_widget">shorten_end_time_interval</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkSpinButton" id="shorten_end_time_interval">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="adjustment">adjustment5</property>
+                        <property name="climb_rate">1</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="shorten_end_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="use_underline">False</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                    <property name="y_options">GTK_FILL</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">True</property>


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