event-editor-dialog: Port to new callback-based ask API

This commit is contained in:
Georges Basile Stavracas Neto
2022-02-12 13:08:50 -03:00
parent ee5acbd493
commit 47a72f8156
3 changed files with 46 additions and 110 deletions
+46 -15
View File
@@ -280,25 +280,56 @@ on_cancel_button_clicked_cb (GtkButton *button,
GCAL_EXIT;
}
static void
on_ask_recurrence_response_delete_cb (GcalEvent *event,
GcalRecurrenceModType mod_type,
gpointer user_data)
{
GcalEventEditorDialog *self = GCAL_EVENT_EDITOR_DIALOG (user_data);
g_signal_emit (self, signals[REMOVE_EVENT], 0, event, mod_type);
clear_and_hide_dialog (self);
}
static void
on_delete_button_clicked_cb (GtkButton *button,
GcalEventEditorDialog *self)
{
GcalRecurrenceModType mod = GCAL_RECURRENCE_MOD_THIS_ONLY;
GcalCalendar *calendar;
GCAL_ENTRY;
calendar = gcal_event_get_calendar (self->event);
if (!gcal_event_has_recurrence (self->event) ||
ask_recurrence_modification_type (GTK_WIDGET (self), &mod, calendar))
if (gcal_event_has_recurrence (self->event))
{
gcal_utils_ask_recurrence_modification_type (GTK_WIDGET (self),
self->event,
on_ask_recurrence_response_delete_cb,
self);
}
else
{
g_signal_emit (self, signals[REMOVE_EVENT], 0, self->event, mod);
clear_and_hide_dialog (self);
}
GCAL_EXIT;
}
static void
on_ask_recurrence_response_save_cb (GcalEvent *event,
GcalRecurrenceModType mod_type,
gpointer user_data)
{
GcalEventEditorDialog *self = GCAL_EVENT_EDITOR_DIALOG (user_data);
if (mod_type != GCAL_RECURRENCE_MOD_NONE)
{
GcalManager *manager = gcal_context_get_manager (self->context);
gcal_manager_update_event (manager, self->event, GCAL_RECURRENCE_MOD_THIS_ONLY);
}
clear_and_hide_dialog (self);
GCAL_EXIT;
}
static void
@@ -339,17 +370,17 @@ on_done_button_clicked_cb (GtkButton *button,
{
gcal_manager_create_event (manager, self->event);
}
else if (gcal_event_has_recurrence (self->event))
{
gcal_utils_ask_recurrence_modification_type (GTK_WIDGET (self),
self->event,
on_ask_recurrence_response_save_cb,
self);
return;
}
else
{
GcalRecurrenceModType mod = GCAL_RECURRENCE_MOD_THIS_ONLY;
if (gcal_event_has_recurrence (self->event) &&
!ask_recurrence_modification_type (GTK_WIDGET (self), &mod, calendar))
{
goto out;
}
gcal_manager_update_event (manager, self->event, mod);
gcal_manager_update_event (manager, self->event, GCAL_RECURRENCE_MOD_THIS_ONLY);
}
out:
-91
View File
@@ -943,97 +943,6 @@ is_source_enabled (ESource *source)
return e_source_selectable_get_selected (selectable);
}
static void
on_dialog_response_cb (GtkDialog *dialog,
gint response,
gint *out_response)
{
*out_response = response;
}
/**
* ask_recurrence_modification_type:
* @parent: a #GtkWidget
* @modtype: an #ECalObjModType
* @source: an #ESource
*
* Assigns the appropriate modtype while modifying an event
* based on user's choice in the GtkMessageDialog that pops up.
* The modtype helps the user choose the part of recurrent events
* to modify. Such as Only This Event, Subsequent events
* or All events.
*
* Returns: %TRUE if user chooses appropriate option and
* @modtype is assigned, %FALSE otherwise.
*/
gboolean
ask_recurrence_modification_type (GtkWidget *parent,
GcalRecurrenceModType *modtype,
GcalCalendar *calendar)
{
GtkDialogFlags flags;
ECalClient *client;
GtkWidget *dialog;
gboolean is_set;
gint result = 0;
flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
*modtype = GCAL_RECURRENCE_MOD_THIS_ONLY;
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_native (parent)),
flags,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
_("The event you are trying to modify is recurring. The changes you have selected should be applied to:"));
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
_("_Cancel"),
GTK_RESPONSE_CANCEL,
_("_Only This Event"),
GTK_RESPONSE_ACCEPT,
NULL);
client = gcal_calendar_get_client (calendar);
if (!e_client_check_capability (E_CLIENT (client), E_CAL_STATIC_CAPABILITY_NO_THISANDFUTURE))
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Subsequent events"), GTK_RESPONSE_OK);
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_All events"), GTK_RESPONSE_YES);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_native (parent)));
g_signal_connect (dialog, "response", G_CALLBACK (on_dialog_response_cb), &result);
gtk_window_present (GTK_WINDOW (dialog));
while (result == 0)
g_main_context_iteration (NULL, TRUE);
switch (result)
{
case GTK_RESPONSE_CANCEL:
is_set = FALSE;
break;
case GTK_RESPONSE_ACCEPT:
*modtype = GCAL_RECURRENCE_MOD_THIS_ONLY;
is_set = TRUE;
break;
case GTK_RESPONSE_OK:
*modtype = GCAL_RECURRENCE_MOD_THIS_AND_FUTURE;
is_set = TRUE;
break;
case GTK_RESPONSE_YES:
*modtype = GCAL_RECURRENCE_MOD_ALL;
is_set = TRUE;
break;
default:
is_set = FALSE;
break;
}
gtk_window_destroy (GTK_WINDOW (dialog));
return is_set;
}
struct
{
const gchar *territory;
-4
View File
@@ -114,10 +114,6 @@ gboolean should_change_date_for_scroll (gdouble
gboolean is_source_enabled (ESource *source);
gboolean ask_recurrence_modification_type (GtkWidget *parent,
GcalRecurrenceModType *modtype,
GcalCalendar *calendar);
gboolean is_workday (guint day);
GList* filter_children_by_uid_and_modtype (GtkWidget *widget,