event-editor-dialog: Stop using response type
Using dialog responses to communicate intent to GcalWindow was always
a hack, and as the code is cleaned, it's getting increasingly annoying.
Replace this with a proper 'remove-event' signal ('delete-event' would
conflict with the equally named GTK signal), remove the custom response
types, and cleanup the code.
This commit is contained in:
@@ -102,6 +102,13 @@ enum
|
|||||||
N_PROPS
|
N_PROPS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
REMOVE_EVENT,
|
||||||
|
NUM_SIGNALS,
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[NUM_SIGNALS] = { 0, };
|
||||||
static GParamSpec* properties[N_PROPS] = { NULL, };
|
static GParamSpec* properties[N_PROPS] = { NULL, };
|
||||||
|
|
||||||
static const GActionEntry action_entries[] =
|
static const GActionEntry action_entries[] =
|
||||||
@@ -198,6 +205,13 @@ set_writable (GcalEventEditorDialog *self,
|
|||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WRITABLE]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WRITABLE]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clear_and_hide_dialog (GcalEventEditorDialog *self)
|
||||||
|
{
|
||||||
|
gcal_event_editor_dialog_set_event (self, NULL);
|
||||||
|
gtk_widget_hide (GTK_WIDGET (self));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Callbacks
|
* Callbacks
|
||||||
@@ -264,59 +278,90 @@ transient_size_allocate_cb (GcalEventEditorDialog *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_action_button_clicked_cb (GtkWidget *widget,
|
on_cancel_button_clicked_cb (GtkButton *button,
|
||||||
gpointer user_data)
|
GcalEventEditorDialog *self)
|
||||||
{
|
{
|
||||||
GcalEventEditorDialog *self;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
|
clear_and_hide_dialog (self);
|
||||||
|
|
||||||
|
GCAL_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_delete_button_clicked_cb (GtkButton *button,
|
||||||
|
GcalEventEditorDialog *self)
|
||||||
|
{
|
||||||
|
GcalRecurrenceModType mod = GCAL_RECURRENCE_MOD_THIS_ONLY;
|
||||||
|
GcalCalendar *calendar;
|
||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
self = GCAL_EVENT_EDITOR_DIALOG (user_data);
|
calendar = gcal_event_get_calendar (self->event);
|
||||||
|
if (!gcal_event_has_recurrence (self->event) ||
|
||||||
if (widget == self->cancel_button || (widget == self->done_button && !self->writable))
|
ask_recurrence_modification_type (GTK_WIDGET (self), &mod, calendar))
|
||||||
{
|
{
|
||||||
gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CANCEL);
|
g_signal_emit (self, signals[REMOVE_EVENT], 0, self->event, mod);
|
||||||
}
|
}
|
||||||
else if (widget == self->delete_button)
|
|
||||||
|
clear_and_hide_dialog (self);
|
||||||
|
|
||||||
|
GCAL_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_done_button_clicked_cb (GtkButton *button,
|
||||||
|
GcalEventEditorDialog *self)
|
||||||
|
{
|
||||||
|
GcalCalendar *selected_calendar;
|
||||||
|
GcalCalendar *calendar;
|
||||||
|
GcalManager *manager;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (self->sections); i++)
|
||||||
|
gcal_event_editor_section_apply (self->sections[i]);
|
||||||
|
|
||||||
|
manager = gcal_context_get_manager (self->context);
|
||||||
|
calendar = gcal_event_get_calendar (self->event);
|
||||||
|
|
||||||
|
if (gcal_calendar_is_read_only (calendar))
|
||||||
|
GCAL_GOTO (out);
|
||||||
|
|
||||||
|
selected_calendar = g_steal_pointer (&self->selected_calendar);
|
||||||
|
if (selected_calendar && calendar != selected_calendar)
|
||||||
{
|
{
|
||||||
gtk_dialog_response (GTK_DIALOG (self), GCAL_RESPONSE_DELETE_EVENT);
|
if (self->event_is_new)
|
||||||
|
{
|
||||||
|
gcal_event_set_calendar (self->event, selected_calendar);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESource *source = gcal_calendar_get_source (selected_calendar);
|
||||||
|
|
||||||
|
gcal_manager_move_event_to_source (manager, self->event, source);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->event_is_new)
|
||||||
|
{
|
||||||
|
gcal_manager_create_event (manager, self->event);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GcalCalendar *calendar;
|
GcalRecurrenceModType mod = GCAL_RECURRENCE_MOD_THIS_ONLY;
|
||||||
gint response;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (self->sections); i++)
|
if (gcal_event_has_recurrence (self->event) &&
|
||||||
gcal_event_editor_section_apply (self->sections[i]);
|
!ask_recurrence_modification_type (GTK_WIDGET (self), &mod, calendar))
|
||||||
|
|
||||||
response = self->event_is_new ? GCAL_RESPONSE_CREATE_EVENT : GCAL_RESPONSE_SAVE_EVENT;
|
|
||||||
|
|
||||||
/* Update the source if needed */
|
|
||||||
calendar = gcal_event_get_calendar (self->event);
|
|
||||||
|
|
||||||
if (self->selected_calendar && calendar != self->selected_calendar)
|
|
||||||
{
|
{
|
||||||
if (self->event_is_new)
|
goto out;
|
||||||
{
|
|
||||||
gcal_event_set_calendar (self->event, self->selected_calendar);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gcal_manager_move_event_to_source (gcal_context_get_manager (self->context),
|
|
||||||
self->event,
|
|
||||||
gcal_calendar_get_source (self->selected_calendar));
|
|
||||||
response = GTK_RESPONSE_CANCEL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self->selected_calendar = NULL;
|
gcal_manager_update_event (manager, self->event, mod);
|
||||||
|
|
||||||
/* Send the response */
|
|
||||||
gtk_dialog_response (GTK_DIALOG (self), response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GCAL_EXIT;
|
out:
|
||||||
|
clear_and_hide_dialog (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -448,6 +493,15 @@ gcal_event_editor_dialog_class_init (GcalEventEditorDialogClass *klass)
|
|||||||
object_class->get_property = gcal_event_editor_dialog_get_property;
|
object_class->get_property = gcal_event_editor_dialog_get_property;
|
||||||
object_class->set_property = gcal_event_editor_dialog_set_property;
|
object_class->set_property = gcal_event_editor_dialog_set_property;
|
||||||
|
|
||||||
|
signals[REMOVE_EVENT] = g_signal_new ("remove-event",
|
||||||
|
GCAL_TYPE_EVENT_EDITOR_DIALOG,
|
||||||
|
G_SIGNAL_RUN_FIRST,
|
||||||
|
0, NULL, NULL, NULL,
|
||||||
|
G_TYPE_NONE,
|
||||||
|
2,
|
||||||
|
GCAL_TYPE_EVENT,
|
||||||
|
G_TYPE_INT);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GcalEventEditorDialog::event:
|
* GcalEventEditorDialog::event:
|
||||||
*
|
*
|
||||||
@@ -503,7 +557,9 @@ gcal_event_editor_dialog_class_init (GcalEventEditorDialogClass *klass)
|
|||||||
|
|
||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
gtk_widget_class_bind_template_callback (widget_class, on_action_button_clicked_cb);
|
gtk_widget_class_bind_template_callback (widget_class, on_cancel_button_clicked_cb);
|
||||||
|
gtk_widget_class_bind_template_callback (widget_class, on_delete_button_clicked_cb);
|
||||||
|
gtk_widget_class_bind_template_callback (widget_class, on_done_button_clicked_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -554,22 +610,6 @@ gcal_event_editor_dialog_set_event_is_new (GcalEventEditorDialog *self,
|
|||||||
gtk_widget_set_visible (self->delete_button, !event_is_new);
|
gtk_widget_set_visible (self->delete_button, !event_is_new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* gcal_event_editor_dialog_get_event:
|
|
||||||
* @dialog: a #GcalDialog
|
|
||||||
*
|
|
||||||
* Retrieves the current event being edited by the @dialog.
|
|
||||||
*
|
|
||||||
* Returns: (transfer none)(nullable): a #GcalEvent
|
|
||||||
*/
|
|
||||||
GcalEvent*
|
|
||||||
gcal_event_editor_dialog_get_event (GcalEventEditorDialog *self)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (GCAL_IS_EVENT_EDITOR_DIALOG (self), NULL);
|
|
||||||
|
|
||||||
return self->event;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gcal_event_editor_dialog_set_event:
|
* gcal_event_editor_dialog_set_event:
|
||||||
* @dialog: a #GcalDialog
|
* @dialog: a #GcalDialog
|
||||||
@@ -644,11 +684,3 @@ out:
|
|||||||
|
|
||||||
GCAL_EXIT;
|
GCAL_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
gcal_event_editor_dialog_get_recurrence_changed (GcalEventEditorDialog *self)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (GCAL_IS_EVENT_EDITOR_DIALOG (self), FALSE);
|
|
||||||
|
|
||||||
return self->recurrence_changed;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,10 +25,6 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GCAL_RESPONSE_DELETE_EVENT 2
|
|
||||||
#define GCAL_RESPONSE_SAVE_EVENT 4
|
|
||||||
#define GCAL_RESPONSE_CREATE_EVENT 6
|
|
||||||
|
|
||||||
#define GCAL_TYPE_EVENT_EDITOR_DIALOG (gcal_event_editor_dialog_get_type ())
|
#define GCAL_TYPE_EVENT_EDITOR_DIALOG (gcal_event_editor_dialog_get_type ())
|
||||||
G_DECLARE_FINAL_TYPE (GcalEventEditorDialog, gcal_event_editor_dialog, GCAL, EVENT_EDITOR_DIALOG, GtkDialog);
|
G_DECLARE_FINAL_TYPE (GcalEventEditorDialog, gcal_event_editor_dialog, GCAL, EVENT_EDITOR_DIALOG, GtkDialog);
|
||||||
|
|
||||||
@@ -37,13 +33,7 @@ GtkWidget* gcal_event_editor_dialog_new (void);
|
|||||||
void gcal_event_editor_dialog_set_event_is_new (GcalEventEditorDialog *dialog,
|
void gcal_event_editor_dialog_set_event_is_new (GcalEventEditorDialog *dialog,
|
||||||
gboolean event_is_new);
|
gboolean event_is_new);
|
||||||
|
|
||||||
GcalEvent* gcal_event_editor_dialog_get_event (GcalEventEditorDialog *self);
|
|
||||||
|
|
||||||
void gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
|
void gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
|
||||||
GcalEvent *event);
|
GcalEvent *event);
|
||||||
|
|
||||||
gboolean gcal_event_editor_dialog_get_recurrence_changed (GcalEventEditorDialog *self);
|
|
||||||
|
|
||||||
GcalRecurrenceModType gcal_event_editor_dialog_get_recurrence_mod_type (GcalEventEditorDialog *self);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<property name="label" translatable="yes">Cancel</property>
|
<property name="label" translatable="yes">Cancel</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<signal name="clicked" handler="on_action_button_clicked_cb" object="GcalEventEditorDialog" swapped="no"/>
|
<signal name="clicked" handler="on_cancel_button_clicked_cb" object="GcalEventEditorDialog" swapped="no"/>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@@ -109,7 +109,7 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<signal name="clicked" handler="on_action_button_clicked_cb" object="GcalEventEditorDialog" swapped="no"/>
|
<signal name="clicked" handler="on_done_button_clicked_cb" object="GcalEventEditorDialog" swapped="no"/>
|
||||||
<style>
|
<style>
|
||||||
<class name="suggested-action"/>
|
<class name="suggested-action"/>
|
||||||
</style>
|
</style>
|
||||||
@@ -218,7 +218,7 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="halign">end</property>
|
<property name="halign">end</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<signal name="clicked" handler="on_action_button_clicked_cb" object="GcalEventEditorDialog" swapped="no"/>
|
<signal name="clicked" handler="on_delete_button_clicked_cb" object="GcalEventEditorDialog" swapped="no"/>
|
||||||
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
|
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="delete_label">
|
<object class="GtkLabel" id="delete_label">
|
||||||
|
|||||||
+25
-72
@@ -657,91 +657,44 @@ event_activated (GcalView *view,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
edit_dialog_closed (GtkDialog *dialog,
|
on_event_editor_dialog_remove_event_cb (GcalEventEditorDialog *edit_dialog,
|
||||||
gint response,
|
GcalEvent *event,
|
||||||
gpointer user_data)
|
GcalRecurrenceModType modifier,
|
||||||
|
GcalWindow *self)
|
||||||
{
|
{
|
||||||
GcalEventEditorDialog *edit_dialog;
|
g_autoptr (GList) widgets = NULL;
|
||||||
GcalRecurrenceModType mod;
|
|
||||||
GcalCalendar *calendar;
|
|
||||||
GcalManager *manager;
|
GcalManager *manager;
|
||||||
GcalWindow *window;
|
|
||||||
GcalEvent *event;
|
|
||||||
GcalView *view;
|
GcalView *view;
|
||||||
GList *widgets;
|
|
||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
window = GCAL_WINDOW (user_data);
|
manager = gcal_context_get_manager (self->context);
|
||||||
manager = gcal_context_get_manager (window->context);
|
view = GCAL_VIEW (self->views[self->active_view]);
|
||||||
edit_dialog = GCAL_EVENT_EDITOR_DIALOG (dialog);
|
|
||||||
event = gcal_event_editor_dialog_get_event (edit_dialog);
|
|
||||||
view = GCAL_VIEW (window->views[window->active_view]);
|
|
||||||
mod = GCAL_RECURRENCE_MOD_THIS_ONLY;
|
|
||||||
calendar = gcal_event_get_calendar (event);
|
|
||||||
|
|
||||||
if (!gcal_event_editor_dialog_get_recurrence_changed (edit_dialog) &&
|
if (self->event_to_delete)
|
||||||
gcal_event_has_recurrence (event) &&
|
|
||||||
(response != GCAL_RESPONSE_CREATE_EVENT &&
|
|
||||||
response != GTK_RESPONSE_CANCEL &&
|
|
||||||
response != GTK_RESPONSE_DELETE_EVENT &&
|
|
||||||
gcal_event_has_recurrence (event) &&
|
|
||||||
!ask_recurrence_modification_type (GTK_WIDGET (dialog), &mod, calendar)))
|
|
||||||
{
|
{
|
||||||
return;
|
gcal_manager_remove_event (manager, self->event_to_delete, self->event_to_delete_mod);
|
||||||
|
g_clear_object (&self->event_to_delete);
|
||||||
|
|
||||||
|
create_notification (self, _("Another event deleted"), _("Undo"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
create_notification (self, _("Event deleted"), _("Undo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gtk_revealer_set_reveal_child (GTK_REVEALER (self->notification), TRUE);
|
||||||
|
|
||||||
switch (response)
|
g_clear_handle_id (&self->notification_timeout, g_source_remove);
|
||||||
{
|
self->notification_timeout = g_timeout_add_seconds (5, hide_notification_scheduled, self);
|
||||||
case GCAL_RESPONSE_CREATE_EVENT:
|
|
||||||
gcal_manager_create_event (manager, event);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GCAL_RESPONSE_SAVE_EVENT:
|
g_set_object (&self->event_to_delete, event);
|
||||||
gcal_manager_update_event (manager, event, mod);
|
self->event_to_delete_mod = modifier;
|
||||||
break;
|
|
||||||
|
|
||||||
case GCAL_RESPONSE_DELETE_EVENT:
|
/* hide widget of the event */
|
||||||
if (window->event_to_delete != NULL)
|
widgets = gcal_view_get_children_by_uuid (view, modifier, gcal_event_get_uid (event));
|
||||||
{
|
|
||||||
gcal_manager_remove_event (manager, window->event_to_delete, window->event_to_delete_mod);
|
|
||||||
g_clear_object (&window->event_to_delete);
|
|
||||||
|
|
||||||
create_notification (GCAL_WINDOW (user_data), _("Another event deleted"), _("Undo"));
|
g_list_foreach (widgets, (GFunc) gtk_widget_hide, NULL);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
create_notification (GCAL_WINDOW (user_data), _("Event deleted"), _("Undo"));
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_revealer_set_reveal_child (GTK_REVEALER (window->notification), TRUE);
|
|
||||||
|
|
||||||
if (window->notification_timeout != 0)
|
|
||||||
g_source_remove (window->notification_timeout);
|
|
||||||
|
|
||||||
window->notification_timeout = g_timeout_add_seconds (5, hide_notification_scheduled, user_data);
|
|
||||||
|
|
||||||
g_set_object (&window->event_to_delete, event);
|
|
||||||
|
|
||||||
window->event_to_delete_mod = mod;
|
|
||||||
|
|
||||||
/* hide widget of the event */
|
|
||||||
widgets = gcal_view_get_children_by_uuid (view, mod, gcal_event_get_uid (event));
|
|
||||||
|
|
||||||
g_list_foreach (widgets, (GFunc) gtk_widget_hide, NULL);
|
|
||||||
g_list_free (widgets);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_hide (GTK_WIDGET (dialog));
|
|
||||||
|
|
||||||
gcal_event_editor_dialog_set_event (edit_dialog, NULL);
|
|
||||||
|
|
||||||
GCAL_EXIT;
|
GCAL_EXIT;
|
||||||
}
|
}
|
||||||
@@ -1102,7 +1055,7 @@ gcal_window_class_init (GcalWindowClass *klass)
|
|||||||
gtk_widget_class_bind_template_callback (widget_class, window_state_changed);
|
gtk_widget_class_bind_template_callback (widget_class, window_state_changed);
|
||||||
|
|
||||||
/* Edit dialog related */
|
/* Edit dialog related */
|
||||||
gtk_widget_class_bind_template_callback (widget_class, edit_dialog_closed);
|
gtk_widget_class_bind_template_callback (widget_class, on_event_editor_dialog_remove_event_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -299,7 +299,7 @@
|
|||||||
<object class="GcalEventEditorDialog" id="event_editor">
|
<object class="GcalEventEditorDialog" id="event_editor">
|
||||||
<property name="visible">False</property>
|
<property name="visible">False</property>
|
||||||
<property name="transient_for">GcalWindow</property>
|
<property name="transient_for">GcalWindow</property>
|
||||||
<signal name="response" handler="edit_dialog_closed" object="GcalWindow" swapped="no"/>
|
<signal name="remove-event" handler="on_event_editor_dialog_remove_event_cb" object="GcalWindow" swapped="no"/>
|
||||||
<signal name="delete-event" handler="gtk_widget_hide_on_delete" object="GcalWindow" swapped="no"/>
|
<signal name="delete-event" handler="gtk_widget_hide_on_delete" object="GcalWindow" swapped="no"/>
|
||||||
</object>
|
</object>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user