manager: Delay UI Call removal and adjust to changes

This was handled explicitly in the Call window.
By changing the logic to delay the emission of "ui-call-removed" we make sure
that the Call UI and the exported DBus object is consistent.

We also need to change the test cases to use run a GMainLoop because we now have
to wait until signal comes in.
This commit is contained in:
Evangelos Ribeiro Tzaras
2022-02-03 07:49:55 +01:00
parent cde517096b
commit 3fe976505c
4 changed files with 141 additions and 98 deletions

View File

@@ -39,7 +39,6 @@
#include <glib-object.h>
#include <handy.h>
#define CALLS_WINDOW_HIDE_DELAY 3
struct _CallsCallWindow
{
@@ -56,8 +55,6 @@ struct _CallsCallWindow
GtkFlowBox *call_selector;
guint inhibit_cookie;
guint hideout_id;
};
G_DEFINE_TYPE (CallsCallWindow, calls_call_window, GTK_TYPE_APPLICATION_WINDOW);
@@ -86,41 +83,19 @@ session_inhibit (CallsCallWindow *self, gboolean inhibit)
}
static gboolean
on_delayed_window_hide (gpointer user_data)
{
CallsCallWindow *self = user_data;
g_assert (CALLS_IS_CALL_WINDOW (self));
gtk_widget_set_visible (GTK_WIDGET (self), FALSE);
gtk_stack_set_visible_child_name (self->main_stack, "calls");
self->hideout_id = 0;
return G_SOURCE_REMOVE;
}
static void
update_visibility (CallsCallWindow *self)
{
guint calls = g_list_model_get_n_items (G_LIST_MODEL (self->calls));
if (calls == 0) {
self->hideout_id =
g_timeout_add_seconds (CALLS_WINDOW_HIDE_DELAY,
G_SOURCE_FUNC (on_delayed_window_hide),
self);
} else {
g_clear_handle_id (&self->hideout_id, g_source_remove);
gtk_widget_set_visible (GTK_WIDGET (self), TRUE);
if (calls == 1)
gtk_stack_set_visible_child_name (self->main_stack, "active-call");
}
gtk_widget_set_visible (GTK_WIDGET (self), calls > 0);
gtk_widget_set_sensitive (GTK_WIDGET (self->show_calls), calls > 1);
if (calls == 0)
gtk_stack_set_visible_child_name (self->main_stack, "calls");
else if (calls == 1)
gtk_stack_set_visible_child_name (self->main_stack, "active-call");
session_inhibit (self, !!calls);
}
@@ -233,23 +208,6 @@ add_call (CallsCallWindow *self,
self);
}
struct DisplayData
{
GtkStack *call_stack;
CuiCallDisplay *display;
};
static gboolean
on_remove_delayed (gpointer user_data)
{
struct DisplayData *display_data = user_data;
gtk_container_remove (GTK_CONTAINER (display_data->call_stack),
GTK_WIDGET (display_data->display));
g_free (display_data);
return G_SOURCE_REMOVE;
}
static void
remove_call (CallsCallWindow *self,
@@ -272,15 +230,9 @@ remove_call (CallsCallWindow *self,
CALLS_UI_CALL_DATA (cui_call_display_get_call (display));
if (display_call_data == ui_call_data) {
struct DisplayData *display_data = g_new0 (struct DisplayData, 1);
g_list_store_remove (self->calls, i);
display_data->call_stack = self->call_stack;
display_data->display = display;
g_timeout_add_seconds (CALLS_WINDOW_HIDE_DELAY,
G_SOURCE_FUNC (on_remove_delayed),
display_data);
gtk_container_remove (GTK_CONTAINER (self->call_stack),
GTK_WIDGET (display));
break;
}
}
@@ -399,4 +351,3 @@ calls_call_window_new (GtkApplication *application)
NULL);
}
#undef CALLS_WINDOW_HIDE_DELAY

View File

@@ -246,27 +246,62 @@ add_call (CallsManager *self, CallsCall *call, CallsOrigin *origin)
}
struct CallsRemoveData
{
CallsManager *manager;
CallsCall *call;
};
static gboolean
on_remove_delayed (struct CallsRemoveData *data)
{
CallsUiCallData *call_data;
g_assert (CALLS_IS_MANAGER (data->manager));
g_assert (CALLS_IS_CALL (data->call));
call_data = g_hash_table_lookup (data->manager->calls, data->call);
if (!call_data) {
g_warning ("Could not find call %s in UI call hash table",
calls_call_get_id (data->call));
} else {
g_signal_emit (data->manager, signals[UI_CALL_REMOVED], 0, call_data);
g_hash_table_remove (data->manager->calls, data->call);
}
g_free (data);
return G_SOURCE_REMOVE;
}
#define DELAY_CALL_REMOVE_MS 3000
static void
remove_call (CallsManager *self, CallsCall *call, gchar *reason, CallsOrigin *origin)
{
CallsUiCallData *call_data;
struct CallsRemoveData *data;
g_return_if_fail (CALLS_IS_MANAGER (self));
g_return_if_fail (CALLS_IS_ORIGIN (origin));
g_return_if_fail (CALLS_IS_CALL (call));
call_data = g_hash_table_lookup (self->calls, call);
if (!call_data) {
g_warning ("Could not remove call %s from hash table", calls_call_get_id (call));
} else {
g_signal_emit (self, signals[UI_CALL_REMOVED], 0, call_data);
g_hash_table_remove (self->calls, call);
}
data = g_new (struct CallsRemoveData, 1);
data->manager = self;
data->call = call;
/** Having the delay centrally managed makes sure our UI
* and the DBus side stays consistent
*/
g_timeout_add (DELAY_CALL_REMOVE_MS,
G_SOURCE_FUNC (on_remove_delayed),
data);
/* TODO get rid of SIGNAL_CALL_REMOVE signal */
/* We ignore the reason for now, because it doesn't give any usefull information */
g_signal_emit (self, signals[SIGNAL_CALL_REMOVE], 0, call, origin);
}
#undef DELAY_CALL_REMOVE_MS
static void