[evolution] Derive date from selected day when creating event/meeting in To Do bar
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Derive date from selected day when creating event/meeting in To Do bar
- Date: Wed, 12 Jul 2017 14:26:14 +0000 (UTC)
commit 9ad64b64c044025d37cc77c551ea21950dcda3eb
Author: Milan Crha <mcrha redhat com>
Date: Wed Jul 12 16:26:02 2017 +0200
Derive date from selected day when creating event/meeting in To Do bar
Right-click and create new event or task already derives the calendar/task
list of the selected component. This derives also selected date, thus for
example creating a new event and right-clicking on the 'Tomorrow' row
the event will be prefilled with the Tomorrow date and the nearest
future time of the current time according to set time division for
the Day and Work Week views.
src/calendar/gui/e-cal-ops.c | 18 ++++++--
src/calendar/gui/e-cal-ops.h | 4 +-
src/calendar/gui/e-to-do-pane.c | 64 +++++++++++++++++++++++++++-
src/modules/calendar/e-cal-shell-backend.c | 3 +-
4 files changed, 81 insertions(+), 8 deletions(-)
---
diff --git a/src/calendar/gui/e-cal-ops.c b/src/calendar/gui/e-cal-ops.c
index facb874..b885aa6 100644
--- a/src/calendar/gui/e-cal-ops.c
+++ b/src/calendar/gui/e-cal-ops.c
@@ -29,6 +29,7 @@
#include "e-comp-editor-memo.h"
#include "e-comp-editor-task.h"
#include "e-cal-dialogs.h"
+#include "calendar-config.h"
#include "comp-util.h"
#include "itip-utils.h"
@@ -1466,12 +1467,15 @@ new_component_data_free (gpointer ptr)
}
if (ncd->source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS) {
- if (ncd->is_new_component && ncd->model && ncd->dtstart > 0 && ncd->dtend >
0) {
+ if (ncd->is_new_component && ncd->dtstart > 0 && ncd->dtend > 0) {
ECalComponentDateTime dt;
struct icaltimetype itt;
icaltimezone *zone;
- zone = e_cal_model_get_timezone (ncd->model);
+ if (ncd->model)
+ zone = e_cal_model_get_timezone (ncd->model);
+ else
+ zone = calendar_config_get_icaltimezone ();
dt.value = &itt;
if (ncd->all_day)
@@ -1745,11 +1749,15 @@ e_cal_ops_new_component_editor (EShellWindow *shell_window,
* if #FALSE, then the next two reminded arguments are ignored
* @default_reminder_interval: reminder interval for the default reminder
* @default_reminder_units: reminder uints for the default reminder
+ * @dtstart: a time_t of DTSTART to use, or 0 to use the default value
+ * @dtend: a time_t of DTEND to use, or 0 to use the default value
*
* This is a fine-grained version of e_cal_ops_new_component_editor(), suitable
* for events with predefined alarms. The e_cal_ops_new_component_editor()
* accepts events as well.
*
+ * The @dtend is ignored, when @dtstart is zero or a negative value.
+ *
* Since: 3.16
**/
void
@@ -1759,10 +1767,12 @@ e_cal_ops_new_event_editor (EShellWindow *shell_window,
gboolean all_day,
gboolean use_default_reminder,
gint default_reminder_interval,
- EDurationType default_reminder_units)
+ EDurationType default_reminder_units,
+ time_t dtstart,
+ time_t dtend)
{
e_cal_ops_new_component_ex (shell_window, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, for_client_uid,
is_meeting,
- all_day, 0, 0, use_default_reminder, default_reminder_interval, default_reminder_units);
+ all_day, dtstart, dtstart <= 0 ? 0 : dtend, use_default_reminder, default_reminder_interval,
default_reminder_units);
}
/**
diff --git a/src/calendar/gui/e-cal-ops.h b/src/calendar/gui/e-cal-ops.h
index 66ca22e..f465a8d 100644
--- a/src/calendar/gui/e-cal-ops.h
+++ b/src/calendar/gui/e-cal-ops.h
@@ -87,7 +87,9 @@ void e_cal_ops_new_event_editor (EShellWindow *shell_window,
gboolean all_day,
gboolean use_default_reminder,
gint default_reminder_interval,
- EDurationType default_reminder_units);
+ EDurationType default_reminder_units,
+ time_t dtstart,
+ time_t dtend);
void e_cal_ops_new_component_editor_from_model
(ECalModel *model,
const gchar *for_client_uid,
diff --git a/src/calendar/gui/e-to-do-pane.c b/src/calendar/gui/e-to-do-pane.c
index 8943aed..973d6a6 100644
--- a/src/calendar/gui/e-to-do-pane.c
+++ b/src/calendar/gui/e-to-do-pane.c
@@ -1578,6 +1578,7 @@ etdp_new_common (EToDoPane *to_do_pane,
{
ECalClient *client = NULL;
EShellView *shell_view;
+ EShellWindow *shell_window;
gchar *client_source_uid = NULL;
g_return_if_fail (E_IS_TO_DO_PANE (to_do_pane));
@@ -1615,9 +1616,68 @@ etdp_new_common (EToDoPane *to_do_pane,
g_clear_object (&client);
shell_view = e_to_do_pane_ref_shell_view (to_do_pane);
+ shell_window = shell_view ? e_shell_view_get_shell_window (shell_view) : NULL;
- e_cal_ops_new_component_editor (shell_view ? e_shell_view_get_shell_window (shell_view) : NULL,
- source_type, client_source_uid, is_assigned);
+ if (source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS) {
+ GSettings *settings;
+ time_t dtstart = 0, dtend = 0;
+ GtkTreeSelection *selection;
+ GList *rows;
+ GtkTreeIter iter;
+ GtkTreeModel *model = NULL;
+
+ settings = e_util_ref_settings ("org.gnome.evolution.calendar");
+
+ selection = gtk_tree_view_get_selection (to_do_pane->priv->tree_view);
+ rows = gtk_tree_selection_get_selected_rows (selection, &model);
+
+ if (rows && gtk_tree_model_get_iter (model, &iter, rows->data)) {
+ GtkTreeIter parent;
+ guint date_mark = 0;
+
+ while (gtk_tree_model_iter_parent (model, &parent, &iter))
+ iter = parent;
+
+ gtk_tree_model_get (model, &iter, COLUMN_DATE_MARK, &date_mark, -1);
+
+ if (date_mark > 0) {
+ struct icaltimetype now;
+ gint time_divisions_secs;
+ icaltimezone *zone;
+
+ time_divisions_secs = g_settings_get_int (settings, "time-divisions") * 60;
+ zone = e_cal_data_model_get_timezone (to_do_pane->priv->events_data_model);
+ now = icaltime_current_time_with_zone (zone);
+
+ now.year = date_mark / 10000;
+ now.month = (date_mark / 100) % 100;
+ now.day = date_mark % 100;
+
+ /* The date_mark is the next day, not the day it belongs to */
+ icaltime_adjust (&now, -1, 0, 0, 0);
+
+ dtstart = icaltime_as_timet_with_zone (now, zone);
+ if (dtstart > 0 && time_divisions_secs > 0) {
+ dtstart = dtstart + time_divisions_secs - (dtstart %
time_divisions_secs);
+ dtend = dtstart + time_divisions_secs;
+ } else {
+ dtstart = 0;
+ }
+ }
+ }
+
+ g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free);
+
+ e_cal_ops_new_event_editor (shell_window, client_source_uid, is_assigned, FALSE,
+ g_settings_get_boolean (settings, "use-default-reminder"),
+ g_settings_get_int (settings, "default-reminder-interval"),
+ g_settings_get_enum (settings, "default-reminder-units"),
+ dtstart, dtend);
+
+ g_clear_object (&settings);
+ } else {
+ e_cal_ops_new_component_editor (shell_window, source_type, client_source_uid, is_assigned);
+ }
g_clear_object (&shell_view);
g_free (client_source_uid);
diff --git a/src/modules/calendar/e-cal-shell-backend.c b/src/modules/calendar/e-cal-shell-backend.c
index 36a042d..0f52032 100644
--- a/src/modules/calendar/e-cal-shell-backend.c
+++ b/src/modules/calendar/e-cal-shell-backend.c
@@ -93,7 +93,8 @@ action_event_new_cb (GtkAction *action,
e_cal_ops_new_event_editor (shell_window, NULL, is_meeting, is_all_day,
g_settings_get_boolean (settings, "use-default-reminder"),
g_settings_get_int (settings, "default-reminder-interval"),
- g_settings_get_enum (settings, "default-reminder-units"));
+ g_settings_get_enum (settings, "default-reminder-units"),
+ 0, 0);
g_clear_object (&settings);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]