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