2018-08-01 10:51:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Purism SPC
|
|
|
|
*
|
|
|
|
* This file is part of Calls.
|
|
|
|
*
|
|
|
|
* Calls is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calls is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bob Ham <bob.ham@puri.sm>
|
|
|
|
* Adrien Plazas <adrien.plazas@puri.sm>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-06-18 09:10:36 +00:00
|
|
|
#define G_LOG_DOMAIN "CallsCallWindow"
|
|
|
|
|
2018-08-01 10:51:55 +00:00
|
|
|
#include "calls-call-window.h"
|
|
|
|
#include "calls-origin.h"
|
|
|
|
#include "calls-call-selector-item.h"
|
|
|
|
#include "calls-new-call-box.h"
|
2020-03-02 18:11:37 +00:00
|
|
|
#include "calls-in-app-notification.h"
|
2020-03-17 20:50:39 +00:00
|
|
|
#include "calls-manager.h"
|
2021-10-09 07:02:54 +00:00
|
|
|
#include "calls-ui-call-data.h"
|
2023-01-21 15:42:39 +00:00
|
|
|
#include "calls-util.h"
|
2018-08-01 10:51:55 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <glib-object.h>
|
|
|
|
#include <handy.h>
|
|
|
|
|
2021-10-27 11:03:47 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
struct _CallsCallWindow {
|
|
|
|
GtkApplicationWindow parent_instance;
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
GListStore *calls;
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2020-03-02 18:11:37 +00:00
|
|
|
CallsInAppNotification *in_app_notification;
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
GtkStack *main_stack;
|
|
|
|
GtkStack *header_bar_stack;
|
|
|
|
GtkButton *show_calls;
|
|
|
|
GtkStack *call_stack;
|
|
|
|
GtkFlowBox *call_selector;
|
2019-08-13 10:38:40 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
guint inhibit_cookie;
|
2018-08-01 10:51:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (CallsCallWindow, calls_call_window, GTK_TYPE_APPLICATION_WINDOW);
|
|
|
|
|
|
|
|
|
2020-08-06 20:28:37 +00:00
|
|
|
static void
|
|
|
|
session_inhibit (CallsCallWindow *self, gboolean inhibit)
|
|
|
|
{
|
2021-10-27 09:03:27 +00:00
|
|
|
if (inhibit) {
|
|
|
|
if (self->inhibit_cookie == 0)
|
|
|
|
self->inhibit_cookie =
|
|
|
|
gtk_application_inhibit (gtk_window_get_application (GTK_WINDOW (self)),
|
|
|
|
GTK_WINDOW (self),
|
|
|
|
GTK_APPLICATION_INHIBIT_SUSPEND |
|
|
|
|
GTK_APPLICATION_INHIBIT_IDLE |
|
|
|
|
GTK_APPLICATION_INHIBIT_LOGOUT |
|
|
|
|
GTK_APPLICATION_INHIBIT_SWITCH,
|
|
|
|
"call active");
|
|
|
|
} else {
|
|
|
|
if (self->inhibit_cookie != 0)
|
|
|
|
gtk_application_uninhibit (gtk_window_get_application (GTK_WINDOW (self)),
|
|
|
|
self->inhibit_cookie);
|
|
|
|
self->inhibit_cookie = 0;
|
|
|
|
}
|
2020-08-06 20:28:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-01 10:51:55 +00:00
|
|
|
static void
|
|
|
|
update_visibility (CallsCallWindow *self)
|
|
|
|
{
|
2021-01-28 11:46:19 +00:00
|
|
|
guint calls = g_list_model_get_n_items (G_LIST_MODEL (self->calls));
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self), calls > 0);
|
2021-10-27 11:03:47 +00:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->show_calls), calls > 1);
|
2020-08-06 20:28:37 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
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");
|
|
|
|
|
2020-08-06 20:28:37 +00:00
|
|
|
session_inhibit (self, !!calls);
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
2021-01-28 11:46:19 +00:00
|
|
|
calls_create_widget_cb (CallsCallSelectorItem *item,
|
|
|
|
gpointer user_data)
|
2018-08-01 10:51:55 +00:00
|
|
|
{
|
2018-10-10 09:07:13 +00:00
|
|
|
return GTK_WIDGET (item);
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-10-09 07:02:54 +00:00
|
|
|
set_focus (CallsCallWindow *self,
|
|
|
|
CuiCallDisplay *display)
|
2018-08-01 10:51:55 +00:00
|
|
|
{
|
|
|
|
gtk_stack_set_visible_child_name (self->main_stack, "active-call");
|
2018-11-30 15:07:35 +00:00
|
|
|
gtk_stack_set_visible_child (self->call_stack, GTK_WIDGET (display));
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_calls_clicked_cb (GtkButton *button,
|
|
|
|
CallsCallWindow *self)
|
|
|
|
{
|
|
|
|
gtk_stack_set_visible_child_name (self->main_stack, "calls");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
call_selector_child_activated_cb (GtkFlowBox *box,
|
|
|
|
GtkFlowBoxChild *child,
|
|
|
|
CallsCallWindow *self)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = gtk_bin_get_child (GTK_BIN (child));
|
|
|
|
CallsCallSelectorItem *item = CALLS_CALL_SELECTOR_ITEM (widget);
|
2021-10-09 07:02:54 +00:00
|
|
|
CuiCallDisplay *display = calls_call_selector_item_get_display (item);
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2018-11-30 15:07:35 +00:00
|
|
|
set_focus (self, display);
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-02 17:42:25 +00:00
|
|
|
static void
|
2022-02-01 08:58:45 +00:00
|
|
|
add_call_to_window (CallsCallWindow *self,
|
|
|
|
CallsUiCallData *ui_call_data)
|
2018-08-01 10:51:55 +00:00
|
|
|
{
|
2022-01-31 15:30:39 +00:00
|
|
|
CuiCall *call = (CuiCall *) ui_call_data;
|
2021-10-09 07:02:54 +00:00
|
|
|
CuiCallDisplay *display;
|
2021-01-28 11:46:19 +00:00
|
|
|
CallsCallSelectorItem *item;
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2021-12-14 13:57:14 +00:00
|
|
|
g_assert (CALLS_IS_CALL_WINDOW (self));
|
2022-01-31 15:30:39 +00:00
|
|
|
g_assert (CUI_IS_CALL (call));
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2022-01-31 15:30:39 +00:00
|
|
|
display = cui_call_display_new (CUI_CALL (ui_call_data));
|
2021-01-28 11:46:19 +00:00
|
|
|
item = calls_call_selector_item_new (display);
|
2018-08-01 10:51:55 +00:00
|
|
|
gtk_stack_add_named (self->call_stack, GTK_WIDGET (display),
|
2022-01-31 15:30:39 +00:00
|
|
|
cui_call_get_id (call));
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2021-01-28 11:46:19 +00:00
|
|
|
g_list_store_append (self->calls, item);
|
2018-08-01 10:51:55 +00:00
|
|
|
|
|
|
|
update_visibility (self);
|
2018-11-30 15:07:35 +00:00
|
|
|
set_focus (self, display);
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 08:58:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
on_call_notify_active_ui (CallsUiCallData *call,
|
|
|
|
GParamSpec *unused,
|
|
|
|
CallsCallWindow *self)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_CALL_WINDOW (self));
|
|
|
|
g_assert (CALLS_IS_UI_CALL_DATA (call));
|
|
|
|
|
|
|
|
if (!calls_ui_call_data_get_ui_active (call)) {
|
|
|
|
g_warning ("UI for a call should never switch back to being inactive");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_call_to_window (self, call);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_call (CallsCallWindow *self,
|
|
|
|
CallsUiCallData *call)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_CALL_WINDOW (self));
|
|
|
|
g_assert (CALLS_IS_UI_CALL_DATA (call));
|
|
|
|
|
|
|
|
if (calls_ui_call_data_get_ui_active (call)) {
|
|
|
|
add_call_to_window (self, call);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (call,
|
|
|
|
"notify::ui-active",
|
|
|
|
G_CALLBACK (on_call_notify_active_ui),
|
|
|
|
self);
|
|
|
|
}
|
|
|
|
|
2021-10-27 11:03:47 +00:00
|
|
|
|
2021-06-02 17:42:25 +00:00
|
|
|
static void
|
2018-10-08 10:40:02 +00:00
|
|
|
remove_call (CallsCallWindow *self,
|
2022-01-31 15:30:39 +00:00
|
|
|
CallsUiCallData *ui_call_data,
|
2018-10-08 10:40:02 +00:00
|
|
|
const gchar *reason)
|
2018-08-01 10:51:55 +00:00
|
|
|
{
|
2021-10-28 12:58:34 +00:00
|
|
|
guint n_calls;
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2021-12-14 13:57:14 +00:00
|
|
|
g_assert (CALLS_IS_CALL_WINDOW (self));
|
2022-01-31 15:30:39 +00:00
|
|
|
g_assert (CALLS_IS_UI_CALL_DATA (ui_call_data));
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2022-02-01 08:58:45 +00:00
|
|
|
g_signal_handlers_disconnect_by_data (ui_call_data, self);
|
|
|
|
|
2021-10-28 12:58:34 +00:00
|
|
|
n_calls = g_list_model_get_n_items (G_LIST_MODEL (self->calls));
|
|
|
|
for (guint i = 0; i < n_calls; i++) {
|
|
|
|
g_autoptr (CallsCallSelectorItem) item =
|
|
|
|
g_list_model_get_item (G_LIST_MODEL (self->calls), i);
|
2021-10-09 07:02:54 +00:00
|
|
|
CuiCallDisplay *display = calls_call_selector_item_get_display (item);
|
2022-01-31 15:30:39 +00:00
|
|
|
CallsUiCallData *display_call_data =
|
2021-10-09 07:02:54 +00:00
|
|
|
CALLS_UI_CALL_DATA (cui_call_display_get_call (display));
|
2021-01-28 11:46:19 +00:00
|
|
|
|
2022-01-31 15:30:39 +00:00
|
|
|
if (display_call_data == ui_call_data) {
|
2021-10-28 12:58:34 +00:00
|
|
|
g_list_store_remove (self->calls, i);
|
2022-02-03 06:49:55 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (self->call_stack),
|
|
|
|
GTK_WIDGET (display));
|
2021-01-28 11:46:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update_visibility (self);
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_calls (CallsCallWindow *self)
|
|
|
|
{
|
|
|
|
GList *children, *child;
|
|
|
|
|
2018-11-01 11:05:45 +00:00
|
|
|
/* Safely remove the call stack's children. */
|
2018-08-01 10:51:55 +00:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (self->call_stack));
|
|
|
|
for (child = children; child != NULL; child = child->next)
|
|
|
|
gtk_container_remove (GTK_CONTAINER (self->call_stack),
|
|
|
|
GTK_WIDGET (child->data));
|
|
|
|
g_list_free (children);
|
|
|
|
|
2021-01-28 11:46:19 +00:00
|
|
|
g_list_store_remove_all (self->calls);
|
2018-08-01 10:51:55 +00:00
|
|
|
|
|
|
|
update_visibility (self);
|
|
|
|
}
|
|
|
|
|
2019-08-13 10:38:40 +00:00
|
|
|
|
2018-08-01 10:51:55 +00:00
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
CallsCallWindow *self = CALLS_CALL_WINDOW (object);
|
|
|
|
|
|
|
|
gtk_flow_box_bind_model (self->call_selector,
|
2021-01-28 11:46:19 +00:00
|
|
|
G_LIST_MODEL (self->calls),
|
|
|
|
(GtkFlowBoxCreateWidgetFunc) calls_create_widget_cb,
|
2018-08-01 10:51:55 +00:00
|
|
|
NULL, NULL);
|
|
|
|
|
2019-08-13 10:38:40 +00:00
|
|
|
update_visibility (self);
|
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_call_window_parent_class)->constructed (object);
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_call_window_init (CallsCallWindow *self)
|
|
|
|
{
|
2020-03-17 20:50:39 +00:00
|
|
|
g_autoptr (GList) calls = NULL;
|
|
|
|
GList *c;
|
2022-04-24 10:24:55 +00:00
|
|
|
|
2018-08-01 10:51:55 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
|
|
|
|
2021-01-28 11:46:19 +00:00
|
|
|
self->calls = g_list_store_new (CALLS_TYPE_CALL_SELECTOR_ITEM);
|
2020-03-17 20:50:39 +00:00
|
|
|
|
|
|
|
// Show errors in in-app-notification
|
2023-01-16 08:15:24 +00:00
|
|
|
g_signal_connect_object (calls_manager_get_default (),
|
|
|
|
"message",
|
|
|
|
G_CALLBACK (calls_in_app_notification_show),
|
|
|
|
self->in_app_notification,
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
|
|
|
g_signal_connect_object (calls_manager_get_default (),
|
|
|
|
"ui-call-added",
|
|
|
|
G_CALLBACK (add_call),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
|
|
|
g_signal_connect_object (calls_manager_get_default (),
|
|
|
|
"ui-call-removed",
|
|
|
|
G_CALLBACK (remove_call),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2020-03-17 20:50:39 +00:00
|
|
|
|
|
|
|
calls = calls_manager_get_calls (calls_manager_get_default ());
|
|
|
|
for (c = calls; c != NULL; c = c->next) {
|
|
|
|
add_call (self, c->data);
|
|
|
|
}
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CallsCallWindow *self = CALLS_CALL_WINDOW (object);
|
|
|
|
|
2021-01-28 11:46:19 +00:00
|
|
|
if (self->calls)
|
2021-10-27 09:03:27 +00:00
|
|
|
remove_calls (self);
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2021-01-28 11:46:19 +00:00
|
|
|
g_clear_object (&self->calls);
|
2018-08-01 10:51:55 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_call_window_parent_class)->dispose (object);
|
2018-08-01 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_call_window_class_init (CallsCallWindowClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructed = constructed;
|
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
2021-07-10 02:15:22 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/call-window.ui");
|
2020-03-02 18:11:37 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, in_app_notification);
|
2018-08-01 10:51:55 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, main_stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, header_bar_stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, show_calls);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, call_stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, call_selector);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, call_selector_child_activated_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, show_calls_clicked_cb);
|
|
|
|
}
|
2018-10-08 10:40:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
CallsCallWindow *
|
2020-03-17 20:50:39 +00:00
|
|
|
calls_call_window_new (GtkApplication *application)
|
2018-10-08 10:40:02 +00:00
|
|
|
{
|
|
|
|
return g_object_new (CALLS_TYPE_CALL_WINDOW,
|
|
|
|
"application", application,
|
|
|
|
NULL);
|
|
|
|
}
|