[evolution] Bug #703899 - Moving a meeting does not ask for confirmation



commit 09e7cfcd0d578ea88b31ce39d50f27ad76974ba2
Author: Fabiano Fidêncio <fidencio redhat com>
Date:   Fri Jul 12 14:48:38 2013 +0200

    Bug #703899 - Moving a meeting does not ask for confirmation

 calendar/calendar.error.xml      |   15 ++++++
 calendar/gui/dialogs/send-comp.c |   85 +++++++++++++++++++++++++++++++
 calendar/gui/dialogs/send-comp.h |    1 +
 calendar/gui/e-calendar-view.c   |  103 ++++++++++++++++++++++++--------------
 calendar/gui/e-calendar-view.h   |   12 ++++-
 calendar/gui/e-day-view.c        |   85 ++++++++++++++++++++++++++-----
 6 files changed, 248 insertions(+), 53 deletions(-)
---
diff --git a/calendar/calendar.error.xml b/calendar/calendar.error.xml
index d506a21..ee526b6 100644
--- a/calendar/calendar.error.xml
+++ b/calendar/calendar.error.xml
@@ -99,6 +99,13 @@
     <button stock="gtk-delete" response="GTK_RESPONSE_YES"/>
   </error>
 
+  <error id="prompt-save-meeting-dragged-or-resized" type="warning" default="GTK_RESPONSE_CANCEL">
+    <_primary>Would you like to save your changes to this meeting?</_primary>
+    <_secondary>You have changed this meeting, but not yet saved it.</_secondary>
+    <button stock="gtk-cancel" response="GTK_RESPONSE_CANCEL"/>
+    <button _label="_Save Changes" response="GTK_RESPONSE_YES"/>
+  </error>
+
   <error id="prompt-save-meeting" type="warning" default="GTK_RESPONSE_YES">
     <_primary>Would you like to save your changes to this meeting?</_primary>
     <_secondary>You have changed this meeting, but not yet saved it.</_secondary>
@@ -145,6 +152,14 @@
     <button _label="_Send" response="GTK_RESPONSE_YES"/>
   </error>
 
+  <error id="prompt-send-updated-meeting-info-dragged-or-resized" type="question" 
default="GTK_RESPONSE_CANCEL">
+    <_primary>Would you like to send updated meeting information to participants?</_primary>
+    <_secondary>Sending updated information allows other participants to keep their calendars up to 
date.</_secondary>
+    <button stock="gtk-cancel" response="GTK_RESPONSE_CANCEL"/>
+    <button _label="Do _not Send" response="GTK_RESPONSE_NO"/>
+    <button _label="_Send" response="GTK_RESPONSE_YES"/>
+  </error>
+
   <error id="prompt-send-task" type="question" default="GTK_RESPONSE_YES">
     <_primary>Would you like to send this task to participants?</_primary>
     <_secondary>Email invitations will be sent to all participants and allow them to accept this 
task.</_secondary>
diff --git a/calendar/gui/dialogs/send-comp.c b/calendar/gui/dialogs/send-comp.c
index b69e6ea..5f76785 100644
--- a/calendar/gui/dialogs/send-comp.c
+++ b/calendar/gui/dialogs/send-comp.c
@@ -236,6 +236,91 @@ send_component_dialog (GtkWindow *parent,
        return res;
 }
 
+/**
+ * send_dragged_or_resized_component_dialog:
+ *
+ * Pops up a dialog box asking the user whether he wants to send a
+ * iTip/iMip message or cancel the drag/resize operations
+ *
+ * Return value: GTK_RESPONSE_YES if the user clicked Yes,
+ *              GTK_RESPONSE_NO if the user clicked No and
+ *              GTK_RESPONSE_CANCEL otherwise.
+ **/
+GtkResponseType
+send_dragged_or_resized_component_dialog (GtkWindow *parent,
+                                         ECalClient *client,
+                                         ECalComponent *comp,
+                                         gboolean *strip_alarms,
+                                         gboolean *only_new_attendees)
+{
+       ECalComponentVType vtype;
+       const gchar *id;
+       GtkWidget *dialog, *sa_checkbox = NULL, *ona_checkbox = NULL;
+       GtkWidget *content_area;
+       gboolean save_schedules = FALSE;
+       GtkResponseType res;
+
+       if (strip_alarms)
+               *strip_alarms = TRUE;
+
+       if (e_cal_client_check_save_schedules (client) || !component_has_recipients (comp))
+               save_schedules = TRUE;
+
+       vtype = e_cal_component_get_vtype (comp);
+
+       switch (vtype) {
+       case E_CAL_COMPONENT_EVENT:
+               id = save_schedules ? "calendar:prompt-save-meeting-dragged-or-resized" :
+                                     "calendar:prompt-send-updated-meeting-info-dragged-or-resized";
+               break;
+       default:
+               g_message (
+                       "send_component_dialog(): "
+                       "Cannot handle object of type %d", vtype);
+               return GTK_RESPONSE_CANCEL;
+       }
+
+       if (only_new_attendees && !component_has_new_attendees (comp)) {
+               /* do not show the check if there is no new attendee and
+                * set as all attendees are required to be notified */
+               *only_new_attendees = FALSE;
+
+               /* pretend it as being passed NULL to simplify code below */
+               only_new_attendees = NULL;
+       }
+
+       if (strip_alarms && !have_nonprocedural_alarm (comp)) {
+               /* pretend it as being passed NULL to simplify code below */
+               strip_alarms = NULL;
+       }
+
+       dialog = e_alert_dialog_new_for_args (parent, id, NULL);
+       content_area = e_alert_dialog_get_content_area (E_ALERT_DIALOG (dialog));
+
+       if (strip_alarms)
+               sa_checkbox = add_checkbox (GTK_BOX (content_area), _("Send my reminders with this event"));
+       if (only_new_attendees)
+               ona_checkbox = add_checkbox (GTK_BOX (content_area), _("Notify new attendees _only"));
+
+       res = gtk_dialog_run (GTK_DIALOG (dialog));
+
+       /*
+        * When the Escape key is pressed a GTK_RESPONSE_DELETE_EVENT is generated.
+        * We should treat this event as the user cancelling the operation
+        */
+       if (res == GTK_RESPONSE_DELETE_EVENT)
+               res = GTK_RESPONSE_CANCEL;
+
+       if (res == GTK_RESPONSE_YES && strip_alarms)
+               *strip_alarms = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (sa_checkbox));
+       if (only_new_attendees)
+               *only_new_attendees = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ona_checkbox));
+
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+
+       return res;
+}
+
 gboolean
 send_component_prompt_subject (GtkWindow *parent,
                                ECalClient *client,
diff --git a/calendar/gui/dialogs/send-comp.h b/calendar/gui/dialogs/send-comp.h
index 154f523..5f4aef1 100644
--- a/calendar/gui/dialogs/send-comp.h
+++ b/calendar/gui/dialogs/send-comp.h
@@ -29,5 +29,6 @@
 
 gboolean send_component_dialog (GtkWindow *parent, ECalClient *client, ECalComponent *comp, gboolean new, 
gboolean *strip_alarms, gboolean *only_new_attendees);
 gboolean send_component_prompt_subject (GtkWindow *parent, ECalClient *client, ECalComponent *comp);
+GtkResponseType send_dragged_or_resized_component_dialog (GtkWindow *parent, ECalClient *client, 
ECalComponent *comp, gboolean *strip_alarms, gboolean *only_new_attendees);
 
 #endif
diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c
index 93734c9..70c4dd5 100644
--- a/calendar/gui/e-calendar-view.c
+++ b/calendar/gui/e-calendar-view.c
@@ -1776,61 +1776,88 @@ e_calendar_view_modify_and_send (ECalendarView *cal_view,
        ECalModel *model;
        ESourceRegistry *registry;
        gboolean only_new_attendees = FALSE;
+       gboolean strip_alarms = TRUE;
+
+       if (e_calendar_view_modify (cal_view, comp, client, mod)) {
+               model = e_calendar_view_get_model (cal_view);
+               registry = e_cal_model_get_registry (model);
+
+               if ((itip_organizer_is_user (registry, comp, client) ||
+                    itip_sentby_is_user (registry, comp, client)) &&
+                   send_component_dialog (toplevel, client, comp, new, &strip_alarms, &only_new_attendees))
+                       e_calendar_view_send (cal_view, comp, client, mod, toplevel, strip_alarms, 
only_new_attendees);
+       }
+}
+
+gboolean
+e_calendar_view_modify (ECalendarView *cal_view,
+                       ECalComponent *comp,
+                       ECalClient *client,
+                       CalObjModType mod)
+{
        GError *error = NULL;
+       gboolean ret;
 
        g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view));
 
-       model = e_calendar_view_get_model (cal_view);
-       registry = e_cal_model_get_registry (model);
-
        e_cal_component_commit_sequence (comp);
 
-       e_cal_client_modify_object_sync (
+       ret = e_cal_client_modify_object_sync (
                client, e_cal_component_get_icalcomponent (comp),
                mod, NULL, &error);
 
-       if (error == NULL) {
-               gboolean strip_alarms = TRUE;
+       if (error != NULL) {
+               g_message (
+                       G_STRLOC ": Could not update the object! %s",
+                       error->message);
 
-               if ((itip_organizer_is_user (registry, comp, client) ||
-                    itip_sentby_is_user (registry, comp, client)) &&
-                   send_component_dialog (toplevel, client, comp, new, &strip_alarms, &only_new_attendees)) {
-                       ECalComponent *send_comp = NULL;
+               g_error_free (error);
+       }
 
-                       if (mod == CALOBJ_MOD_ALL && e_cal_component_is_instance (comp)) {
-                               /* Ensure we send the master object, not the instance only */
-                               icalcomponent *icalcomp = NULL;
-                               const gchar *uid = NULL;
+       return ret;
+}
 
-                               e_cal_component_get_uid (comp, &uid);
-                               if (e_cal_client_get_object_sync (client, uid, NULL, &icalcomp, NULL, NULL) 
&& icalcomp) {
-                                       send_comp = e_cal_component_new ();
-                                       if (!e_cal_component_set_icalcomponent (send_comp, icalcomp)) {
-                                               icalcomponent_free (icalcomp);
-                                               g_object_unref (send_comp);
-                                               send_comp = NULL;
-                                       } else if (only_new_attendees) {
-                                               /* copy new-attendees information too if required for later 
use */
-                                               comp_editor_copy_new_attendees (send_comp, comp);
-                                       }
-                               }
-                       }
+void
+e_calendar_view_send (ECalendarView *cal_view,
+                     ECalComponent *comp,
+                     ECalClient *client,
+                     CalObjModType mod,
+                     GtkWindow *toplevel,
+                     gboolean strip_alarms,
+                     gboolean only_new_attendees)
+{
+       ESourceRegistry *registry;
+       ECalModel *model;
+       ECalComponent *send_comp = NULL;
 
-                       itip_send_comp (
-                               registry, E_CAL_COMPONENT_METHOD_REQUEST,
-                               send_comp ? send_comp : comp, client, NULL,
-                               NULL, NULL, strip_alarms, only_new_attendees);
+       if (mod == CALOBJ_MOD_ALL && e_cal_component_is_instance (comp)) {
+               /* Ensure we send the master object, not the instance only */
+               icalcomponent *icalcomp = NULL;
+               const gchar *uid = NULL;
 
-                       if (send_comp)
+               e_cal_component_get_uid (comp, &uid);
+               if (e_cal_client_get_object_sync (client, uid, NULL, &icalcomp, NULL, NULL) && icalcomp) {
+                       send_comp = e_cal_component_new ();
+                       if (!e_cal_component_set_icalcomponent (send_comp, icalcomp)) {
+                               icalcomponent_free (icalcomp);
                                g_object_unref (send_comp);
+                               send_comp = NULL;
+                       } else if (only_new_attendees) {
+                               /* copy new-attendees information too if required for later use */
+                               comp_editor_copy_new_attendees (send_comp, comp);
+                       }
                }
-       } else {
-               g_message (
-                       G_STRLOC ": Could not update the object! %s",
-                       error->message);
-
-               g_error_free (error);
        }
+
+       model = e_calendar_view_get_model (cal_view);
+       registry = e_cal_model_get_registry (model);
+       itip_send_comp (
+               registry, E_CAL_COMPONENT_METHOD_REQUEST,
+               send_comp ? send_comp : comp, client, NULL,
+               NULL, NULL, strip_alarms, only_new_attendees);
+
+       if (send_comp)
+               g_object_unref (send_comp);
 }
 
 static gboolean
diff --git a/calendar/gui/e-calendar-view.h b/calendar/gui/e-calendar-view.h
index 8e55587..3e58f14 100644
--- a/calendar/gui/e-calendar-view.h
+++ b/calendar/gui/e-calendar-view.h
@@ -249,7 +249,17 @@ void               e_calendar_view_modify_and_send (ECalendarView *cal_view,
                                                 CalObjModType mod,
                                                 GtkWindow *toplevel,
                                                 gboolean new);
-
+gboolean       e_calendar_view_modify          (ECalendarView *cal_view,
+                                                ECalComponent *comp,
+                                                ECalClient *client,
+                                                CalObjModType mod);
+void           e_calendar_view_send            (ECalendarView *cal_view,
+                                                ECalComponent *comp,
+                                                ECalClient *client,
+                                                CalObjModType mod,
+                                                GtkWindow *toplevel,
+                                                gboolean strip_alarms,
+                                                gboolean only_new_attendees);
 gboolean       e_calendar_view_get_tooltips    (const ECalendarViewEventData *data);
 
 void           e_calendar_view_move_tip        (GtkWidget *widget,
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index 6dae27f..6ad72a5 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -42,6 +42,7 @@
 #include "dialogs/cancel-comp.h"
 #include "dialogs/recur-comp.h"
 #include "dialogs/goto-dialog.h"
+#include "dialogs/save-comp.h"
 
 #include "calendar-config.h"
 #include "comp-util.h"
@@ -4788,6 +4789,10 @@ e_day_view_finish_resize (EDayView *day_view)
        ESourceRegistry *registry;
        CalObjModType mod = CALOBJ_MOD_ALL;
        GtkWindow *toplevel;
+       GtkResponseType send = GTK_RESPONSE_NO;
+       gboolean modified;
+       gboolean only_new_attendees = FALSE;
+       gboolean strip_alarms = TRUE;
 
        model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view));
        registry = e_cal_model_get_registry (model);
@@ -4822,6 +4827,18 @@ e_day_view_finish_resize (EDayView *day_view)
                return;
        }
 
+       toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (day_view)));
+
+       if ((itip_organizer_is_user (registry, comp, client) ||
+            itip_sentby_is_user (registry, comp, client)))
+               send = send_dragged_or_resized_component_dialog (
+                               toplevel, client, comp, &strip_alarms, &only_new_attendees);
+
+       if (send == GTK_RESPONSE_CANCEL) {
+               e_day_view_abort_resize (day_view);
+               goto out;
+       }
+
        date.value = &itt;
        date.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 
@@ -4854,7 +4871,7 @@ e_day_view_finish_resize (EDayView *day_view)
 
        if (e_cal_component_has_recurrences (comp)) {
                if (!recur_component_dialog (client, comp, &mod, NULL, FALSE)) {
-                       gtk_widget_queue_draw (day_view->top_canvas);
+                       gtk_widget_queue_draw (day_view->main_canvas);
                        goto out;
                }
 
@@ -4883,13 +4900,14 @@ e_day_view_finish_resize (EDayView *day_view)
        } else if (e_cal_component_is_instance (comp))
                mod = CALOBJ_MOD_THIS;
 
-       toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (day_view)));
-
        e_cal_component_commit_sequence (comp);
 
-       e_calendar_view_modify_and_send (
-               E_CALENDAR_VIEW (day_view),
-               comp, client, mod, toplevel, TRUE);
+       modified = e_calendar_view_modify (E_CALENDAR_VIEW (day_view), comp, client, mod);
+
+       if (modified && send == GTK_RESPONSE_YES)
+               e_calendar_view_send (
+                               E_CALENDAR_VIEW (day_view),
+                               comp, client, mod, toplevel, strip_alarms, only_new_attendees);
 
  out:
        g_object_unref (comp);
@@ -8339,6 +8357,10 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget,
        const guchar *data;
        gint format, length;
        gint days_shown;
+       GtkResponseType send = GTK_RESPONSE_NO;
+       gboolean modified;
+       gboolean only_new_attendees = FALSE;
+       gboolean strip_alarms = TRUE;
 
        data = gtk_selection_data_get_data (selection_data);
        format = gtk_selection_data_get_format (selection_data);
@@ -8426,6 +8448,19 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget,
                                return;
                        }
 
+                       toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (day_view)));
+
+                       if ((itip_organizer_is_user (registry, comp, client) ||
+                            itip_sentby_is_user (registry, comp, client)))
+                               send = send_dragged_or_resized_component_dialog (
+                                               toplevel, client, comp, &strip_alarms, &only_new_attendees);
+
+                       if (send == GTK_RESPONSE_CANCEL) {
+                               e_day_view_abort_resize (day_view);
+                               g_object_unref (comp);
+                               return;
+                       }
+
                        if (start_offset == 0 && end_offset == 0)
                                all_day_event = TRUE;
                        else
@@ -8477,6 +8512,7 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget,
                        e_cal_component_commit_sequence (comp);
                        if (e_cal_component_has_recurrences (comp)) {
                                if (!recur_component_dialog (client, comp, &mod, NULL, FALSE)) {
+                                       gtk_widget_queue_draw (day_view->top_canvas);
                                        g_object_unref (comp);
                                        return;
                                }
@@ -8493,11 +8529,13 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget,
                        } else if (e_cal_component_is_instance (comp))
                                mod = CALOBJ_MOD_THIS;
 
-                       toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (day_view)));
 
-                       e_calendar_view_modify_and_send (
-                               E_CALENDAR_VIEW (day_view),
-                               comp, client, mod, toplevel, FALSE);
+                       modified = e_calendar_view_modify (E_CALENDAR_VIEW (day_view), comp, client, mod);
+
+                       if (modified && send == GTK_RESPONSE_YES)
+                               e_calendar_view_send (
+                                       E_CALENDAR_VIEW (day_view),
+                                       comp, client, mod, toplevel, strip_alarms, only_new_attendees);
 
                        g_object_unref (comp);
 
@@ -8603,6 +8641,10 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget,
        gboolean drag_from_same_window;
        const guchar *data;
        gint format, length;
+       GtkResponseType send = GTK_RESPONSE_NO;
+       gboolean modified;
+       gboolean only_new_attendees = FALSE;
+       gboolean strip_alarms = TRUE;
 
        cal_view = E_CALENDAR_VIEW (day_view);
        model = e_calendar_view_get_model (cal_view);
@@ -8693,6 +8735,19 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget,
                                return;
                        }
 
+                       toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (day_view)));
+
+                       if ((itip_organizer_is_user (registry, comp, client) ||
+                            itip_sentby_is_user (registry, comp, client)))
+                               send = send_dragged_or_resized_component_dialog (
+                                               toplevel, client, comp, &strip_alarms, &only_new_attendees);
+
+                       if (send == GTK_RESPONSE_CANCEL) {
+                               e_day_view_abort_resize (day_view);
+                               g_object_unref (comp);
+                               return;
+                       }
+
                        date.value = &itt;
                        date.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW 
(day_view)));
 
@@ -8719,6 +8774,7 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget,
                        e_cal_component_commit_sequence (comp);
                        if (e_cal_component_has_recurrences (comp)) {
                                if (!recur_component_dialog (client, comp, &mod, NULL, FALSE)) {
+                                       gtk_widget_queue_draw (day_view->main_canvas);
                                        g_object_unref (comp);
                                        return;
                                }
@@ -8735,11 +8791,12 @@ e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget,
                        } else if (e_cal_component_is_instance (comp))
                                mod = CALOBJ_MOD_THIS;
 
-                       toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (day_view)));
+                       modified = e_calendar_view_modify (E_CALENDAR_VIEW (day_view), comp, client, mod);
 
-                       e_calendar_view_modify_and_send (
-                               E_CALENDAR_VIEW (day_view),
-                               comp, client, mod, toplevel, FALSE);
+                       if (modified && send == GTK_RESPONSE_YES)
+                               e_calendar_view_send (
+                                       E_CALENDAR_VIEW (day_view),
+                                       comp, client, mod, toplevel, strip_alarms, only_new_attendees);
 
                        g_object_unref (comp);
 


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