window: use a GcalEvent to delete events
Instead of using the GcalEventData struct, use the deleted event. It holds a reference until the event gets destroyed. With this commit, we can safely drop GcalEventData structure, since it's not used anymore.
This commit is contained in:
+1
-1
@@ -1506,7 +1506,7 @@ gcal_manager_move_event_to_source (GcalManager *manager,
|
|||||||
/**
|
/**
|
||||||
* gcal_manager_get_events:
|
* gcal_manager_get_events:
|
||||||
*
|
*
|
||||||
* Returns a list with {@link GcalEventData} objects owned by the caller, the list and the objects.
|
* Returns a list with {@link GcalEvent} objects owned by the caller, the list and the objects.
|
||||||
* The components inside the list are owned by the caller as well. So, don't ref the component.
|
* The components inside the list are owned by the caller as well. So, don't ref the component.
|
||||||
*
|
*
|
||||||
* Returns: An {@link GList} object
|
* Returns: An {@link GList} object
|
||||||
|
|||||||
@@ -32,12 +32,6 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
G_DECLARE_FINAL_TYPE (GcalManager, gcal_manager, GCAL, MANAGER, GObject)
|
G_DECLARE_FINAL_TYPE (GcalManager, gcal_manager, GCAL, MANAGER, GObject)
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
ESource *source;
|
|
||||||
ECalComponent *event_component;
|
|
||||||
} GcalEventData;
|
|
||||||
|
|
||||||
GcalManager* gcal_manager_new_with_settings (GSettings *settings);
|
GcalManager* gcal_manager_new_with_settings (GSettings *settings);
|
||||||
|
|
||||||
ESource* gcal_manager_get_source (GcalManager *manager,
|
ESource* gcal_manager_get_source (GcalManager *manager,
|
||||||
|
|||||||
+25
-27
@@ -108,7 +108,7 @@ struct _GcalWindow
|
|||||||
|
|
||||||
NewEventData *event_creation_data;
|
NewEventData *event_creation_data;
|
||||||
|
|
||||||
GcalEventData *event_to_delete;
|
GcalEvent *event_to_delete;
|
||||||
|
|
||||||
/* calendar management */
|
/* calendar management */
|
||||||
GtkWidget *calendar_popover;
|
GtkWidget *calendar_popover;
|
||||||
@@ -1146,13 +1146,10 @@ edit_dialog_closed (GtkDialog *dialog,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GcalWindow *window;
|
GcalWindow *window;
|
||||||
|
|
||||||
GcalEditDialog *edit_dialog;
|
GcalEditDialog *edit_dialog;
|
||||||
GcalEvent *event;
|
GcalEvent *event;
|
||||||
GcalView *view;
|
GcalView *view;
|
||||||
|
|
||||||
GList *widgets;
|
GList *widgets;
|
||||||
const gchar *uuid;
|
|
||||||
|
|
||||||
window = GCAL_WINDOW (user_data);
|
window = GCAL_WINDOW (user_data);
|
||||||
edit_dialog = GCAL_EDIT_DIALOG (dialog);
|
edit_dialog = GCAL_EDIT_DIALOG (dialog);
|
||||||
@@ -1180,8 +1177,11 @@ edit_dialog_closed (GtkDialog *dialog,
|
|||||||
case GCAL_RESPONSE_DELETE_EVENT:
|
case GCAL_RESPONSE_DELETE_EVENT:
|
||||||
if (window->event_to_delete != NULL)
|
if (window->event_to_delete != NULL)
|
||||||
{
|
{
|
||||||
gcal_manager_remove_event (window->manager, window->event_to_delete->source, window->event_to_delete->event_component);
|
gcal_manager_remove_event (window->manager,
|
||||||
g_clear_pointer (&(window->event_to_delete), g_free);
|
gcal_event_get_source (window->event_to_delete),
|
||||||
|
gcal_event_get_component (window->event_to_delete));
|
||||||
|
|
||||||
|
g_clear_object (&window->event_to_delete);
|
||||||
|
|
||||||
create_notification (GCAL_WINDOW (user_data), _("Another event deleted"), _("Undo"));
|
create_notification (GCAL_WINDOW (user_data), _("Another event deleted"), _("Undo"));
|
||||||
}
|
}
|
||||||
@@ -1191,18 +1191,16 @@ edit_dialog_closed (GtkDialog *dialog,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gtk_revealer_set_reveal_child (GTK_REVEALER (window->notification), TRUE);
|
gtk_revealer_set_reveal_child (GTK_REVEALER (window->notification), TRUE);
|
||||||
|
|
||||||
if (window->notification_timeout != 0)
|
if (window->notification_timeout != 0)
|
||||||
g_source_remove (window->notification_timeout);
|
g_source_remove (window->notification_timeout);
|
||||||
|
|
||||||
window->notification_timeout = g_timeout_add_seconds (5, hide_notification_scheduled, user_data);
|
window->notification_timeout = g_timeout_add_seconds (5, hide_notification_scheduled, user_data);
|
||||||
|
|
||||||
window->event_to_delete = g_new0 (GcalEventData, 1);
|
g_set_object (&window->event_to_delete, event);
|
||||||
window->event_to_delete->source = gcal_event_get_source (event);
|
|
||||||
window->event_to_delete->event_component = gcal_event_get_component (event);
|
|
||||||
|
|
||||||
uuid = gcal_event_get_uid (event);
|
|
||||||
|
|
||||||
/* hide widget of the event */
|
/* hide widget of the event */
|
||||||
widgets = gcal_view_get_children_by_uuid (view, uuid);
|
widgets = gcal_view_get_children_by_uuid (view, gcal_event_get_uid (event));
|
||||||
|
|
||||||
g_list_foreach (widgets, (GFunc) gtk_widget_hide, NULL);
|
g_list_foreach (widgets, (GFunc) gtk_widget_hide, NULL);
|
||||||
g_list_free (widgets);
|
g_list_free (widgets);
|
||||||
@@ -1253,10 +1251,10 @@ remove_event (GtkWidget *notification,
|
|||||||
if (window->event_to_delete != NULL)
|
if (window->event_to_delete != NULL)
|
||||||
{
|
{
|
||||||
gcal_manager_remove_event (window->manager,
|
gcal_manager_remove_event (window->manager,
|
||||||
window->event_to_delete->source,
|
gcal_event_get_source (window->event_to_delete),
|
||||||
window->event_to_delete->event_component);
|
gcal_event_get_component (window->event_to_delete));
|
||||||
|
|
||||||
g_clear_pointer (&window->event_to_delete, g_free);
|
g_clear_object (&window->event_to_delete);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1265,22 +1263,22 @@ undo_remove_action (GtkButton *button,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GcalWindow *window;
|
GcalWindow *window;
|
||||||
gchar *uuid;
|
GList *widgets;
|
||||||
|
|
||||||
window = GCAL_WINDOW (user_data);
|
window = GCAL_WINDOW (user_data);
|
||||||
|
widgets = gcal_view_get_children_by_uuid (GCAL_VIEW (window->views[window->active_view]),
|
||||||
|
gcal_event_get_uid (window->event_to_delete));
|
||||||
|
|
||||||
if (window->event_to_delete != NULL)
|
/* Show the hidden to-be-deleted events */
|
||||||
{
|
g_list_foreach (widgets, (GFunc) gtk_widget_show, NULL);
|
||||||
GList *widgets;
|
|
||||||
uuid = get_uuid_from_component (window->event_to_delete->source, window->event_to_delete->event_component);
|
|
||||||
widgets = gcal_view_get_children_by_uuid (GCAL_VIEW (window->views[window->active_view]), uuid);
|
|
||||||
g_list_foreach (widgets, (GFunc) gtk_widget_show, NULL);
|
|
||||||
|
|
||||||
g_object_unref (window->event_to_delete->event_component);
|
/* Clear the event to delete */
|
||||||
g_clear_pointer (&window->event_to_delete, g_free);
|
g_clear_object (&window->event_to_delete);
|
||||||
g_list_free (widgets);
|
|
||||||
g_free (uuid);
|
/* Hide the notification */
|
||||||
}
|
hide_notification (window, NULL);
|
||||||
|
|
||||||
|
g_list_free (widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|||||||
Reference in New Issue
Block a user