window: handle reissue of in-app notification

For now we throw the first one away, and show the second. Eventually we
could handle this better.
This commit is contained in:
Erick Pérez Castellanos
2015-02-16 09:31:21 -05:00
parent 15604b13d8
commit 91defe22de
2 changed files with 38 additions and 28 deletions
+1 -1
View File
@@ -162,7 +162,7 @@
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="relief">none</property> <property name="relief">none</property>
<property name="focus_on_click">False</property> <property name="focus_on_click">False</property>
<signal name="clicked" handler="hide_notification" object="GcalWindow" swapped="no"/> <signal name="clicked" handler="hide_notification" object="GcalWindow" swapped="yes"/>
<child> <child>
<object class="GtkImage"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
+37 -27
View File
@@ -53,6 +53,7 @@ typedef struct
{ {
/* timeout ids */ /* timeout ids */
guint save_geometry_timeout_id; guint save_geometry_timeout_id;
guint notification_timeout;
/* upper level widgets */ /* upper level widgets */
GtkWidget *main_box; GtkWidget *main_box;
@@ -171,8 +172,8 @@ static void create_notification (GcalWindow *w
gchar *message, gchar *message,
gchar *button_label); gchar *button_label);
static void hide_notification (GtkWidget *button, static void hide_notification (GcalWindow *window,
gpointer user_data); GtkWidget *button);
/* calendar management */ /* calendar management */
static void add_source (GcalManager *manager, static void add_source (GcalManager *manager,
@@ -705,16 +706,20 @@ create_notification (GcalWindow *window,
} }
static void static void
hide_notification (GtkWidget *button, hide_notification (GcalWindow *window,
gpointer user_data) GtkWidget *button)
{ {
GcalWindowPrivate *priv; GcalWindowPrivate *priv = gcal_window_get_instance_private (window);
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification), FALSE);
priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data)); priv->notification_timeout = 0;
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification),
FALSE);
} }
static gboolean
hide_notification_scheduled (gpointer window)
{
hide_notification (GCAL_WINDOW (window), NULL);
return FALSE;
}
static void static void
add_source (GcalManager *manager, add_source (GcalManager *manager,
@@ -1023,22 +1028,26 @@ edit_dialog_closed (GtkDialog *dialog,
break; break;
case GCAL_RESPONSE_DELETE_EVENT: case GCAL_RESPONSE_DELETE_EVENT:
/* delete the event */
create_notification (GCAL_WINDOW (user_data),
_("Event deleted"),
_("Undo"));
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification),
TRUE);
/* FIXME: this will crash if the notification is still open */
if (priv->event_to_delete != NULL) if (priv->event_to_delete != NULL)
g_free (priv->event_to_delete); {
gcal_manager_remove_event (priv->manager, priv->event_to_delete->source, priv->event_to_delete->event_component);
g_clear_pointer (&(priv->event_to_delete), g_free);
create_notification (GCAL_WINDOW (user_data), _("Another event deleted"), _("Undo"));
}
else
{
create_notification (GCAL_WINDOW (user_data), _("Event deleted"), _("Undo"));
}
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification), TRUE);
if (priv->notification_timeout != 0)
g_source_remove (priv->notification_timeout);
priv->notification_timeout = g_timeout_add_seconds (5, hide_notification_scheduled, user_data);
priv->event_to_delete = g_new0 (GcalEventData, 1); priv->event_to_delete = g_new0 (GcalEventData, 1);
priv->event_to_delete->source = priv->event_to_delete->source = gcal_edit_dialog_get_source (edit_dialog);
gcal_edit_dialog_get_source (edit_dialog); priv->event_to_delete->event_component = gcal_edit_dialog_get_component (edit_dialog);
priv->event_to_delete->event_component =
gcal_edit_dialog_get_component (edit_dialog);
uuid = gcal_edit_dialog_get_event_uuid (edit_dialog); uuid = gcal_edit_dialog_get_event_uuid (edit_dialog);
/* hide widget of the event */ /* hide widget of the event */
@@ -1112,9 +1121,9 @@ search_bar_revealer_toggled (GObject *object,
} }
static void static void
remove_event (GtkWidget *notification, remove_event (GtkWidget *notification,
GParamSpec *spec, GParamSpec *spec,
gpointer user_data) gpointer user_data)
{ {
GcalWindowPrivate *priv; GcalWindowPrivate *priv;
@@ -1149,12 +1158,13 @@ undo_remove_event (GtkButton *button,
widgets = gcal_view_get_children_by_uuid (GCAL_VIEW (priv->views[priv->active_view]), uuid); widgets = gcal_view_get_children_by_uuid (GCAL_VIEW (priv->views[priv->active_view]), uuid);
g_list_foreach (widgets, (GFunc) gtk_widget_show, NULL); g_list_foreach (widgets, (GFunc) gtk_widget_show, NULL);
g_object_unref (priv->event_to_delete->event_component);
g_clear_pointer (&(priv->event_to_delete), g_free); g_clear_pointer (&(priv->event_to_delete), g_free);
g_list_free (widgets); g_list_free (widgets);
g_free (uuid); g_free (uuid);
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification), g_source_remove (priv->notification_timeout);
FALSE); hide_notification (GCAL_WINDOW (user_data), NULL);
} }
} }