2018-05-17 13:16:51 +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/>.
|
|
|
|
*
|
|
|
|
* Author: Bob Ham <bob.ham@puri.sm>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "calls-call-selector-item.h"
|
2021-10-09 07:02:54 +00:00
|
|
|
#include "calls-call.h"
|
|
|
|
#include "calls-ui-call-data.h"
|
2023-01-21 15:42:39 +00:00
|
|
|
#include "calls-util.h"
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <glib-object.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
struct _CallsCallSelectorItem {
|
|
|
|
GtkEventBox parent_instance;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-10-09 07:02:54 +00:00
|
|
|
CuiCallDisplay *display;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
GtkBox *main_box;
|
|
|
|
GtkLabel *name;
|
|
|
|
GtkLabel *status;
|
2018-05-17 13:16:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (CallsCallSelectorItem, calls_call_selector_item, GTK_TYPE_EVENT_BOX);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2021-01-28 11:46:19 +00:00
|
|
|
PROP_DISPLAY,
|
2018-05-17 13:16:51 +00:00
|
|
|
PROP_LAST_PROP,
|
|
|
|
};
|
|
|
|
static GParamSpec *props[PROP_LAST_PROP];
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
call_state_changed_cb (CallsCallSelectorItem *self,
|
2022-01-31 15:30:39 +00:00
|
|
|
CuiCallState state)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2022-01-31 15:30:39 +00:00
|
|
|
const char * state_str = cui_call_state_to_string (state);
|
2021-10-09 07:02:54 +00:00
|
|
|
|
2022-01-31 15:30:39 +00:00
|
|
|
gtk_label_set_text (self->status, state_str);
|
2021-10-09 07:02:54 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 15:30:39 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2021-01-28 11:46:19 +00:00
|
|
|
set_party (CallsCallSelectorItem *self)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2022-01-31 15:30:39 +00:00
|
|
|
CuiCall *call;
|
2021-01-28 16:08:36 +00:00
|
|
|
// FIXME: use HdyAvatar and the contact avatar
|
|
|
|
GtkWidget *image = gtk_image_new_from_icon_name ("avatar-default-symbolic", GTK_ICON_SIZE_DIALOG);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
gtk_box_pack_start (self->main_box, image, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2022-01-31 15:30:39 +00:00
|
|
|
call = cui_call_display_get_call (self->display);
|
2021-01-28 16:08:36 +00:00
|
|
|
|
2022-02-03 05:39:31 +00:00
|
|
|
g_object_bind_property (call, "display-name",
|
2021-01-28 16:08:36 +00:00
|
|
|
self->name, "label",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-10-09 07:02:54 +00:00
|
|
|
set_call_display (CallsCallSelectorItem *self, CuiCallDisplay *display)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2022-01-31 15:30:39 +00:00
|
|
|
CuiCall *call;
|
2021-01-28 11:46:19 +00:00
|
|
|
|
2021-10-09 07:02:54 +00:00
|
|
|
g_assert (CALLS_IS_CALL_SELECTOR_ITEM (self));
|
|
|
|
g_assert (CUI_IS_CALL_DISPLAY (display));
|
2021-01-28 11:46:19 +00:00
|
|
|
|
2022-01-31 15:30:39 +00:00
|
|
|
call = cui_call_display_get_call (display);
|
|
|
|
g_signal_connect_object (call, "notify::state",
|
2021-01-28 11:46:19 +00:00
|
|
|
G_CALLBACK (call_state_changed_cb),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2022-01-31 15:30:39 +00:00
|
|
|
call_state_changed_cb (self, cui_call_get_state (call));
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-01-28 11:46:19 +00:00
|
|
|
g_set_object (&self->display, display);
|
|
|
|
set_party (self);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsCallSelectorItem *self = CALLS_CALL_SELECTOR_ITEM (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
2021-01-28 11:46:19 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
set_call_display
|
2021-10-09 07:02:54 +00:00
|
|
|
(self, CUI_CALL_DISPLAY (g_value_get_object (value)));
|
2018-05-17 13:16:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_call_selector_item_init (CallsCallSelectorItem *self)
|
|
|
|
{
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CallsCallSelectorItem *self = CALLS_CALL_SELECTOR_ITEM (object);
|
|
|
|
|
2018-11-30 15:07:35 +00:00
|
|
|
g_clear_object (&self->display);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_call_selector_item_parent_class)->dispose (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 15:07:35 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
calls_call_selector_item_class_init (CallsCallSelectorItemClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
2021-01-28 11:46:19 +00:00
|
|
|
props[PROP_DISPLAY] =
|
|
|
|
g_param_spec_object ("display",
|
|
|
|
"Call display",
|
|
|
|
"The display for this call",
|
2021-10-09 07:02:54 +00:00
|
|
|
CUI_TYPE_CALL_DISPLAY,
|
2018-11-30 15:07:35 +00:00
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
2021-10-09 07:02:54 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
|
|
|
|
|
|
|
|
2021-07-10 02:15:22 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/call-selector-item.ui");
|
2018-05-17 13:16:51 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallSelectorItem, main_box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallSelectorItem, name);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsCallSelectorItem, status);
|
|
|
|
}
|
2022-01-14 06:35:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
CallsCallSelectorItem *
|
|
|
|
calls_call_selector_item_new (CuiCallDisplay *display)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CUI_IS_CALL_DISPLAY (display), NULL);
|
|
|
|
|
|
|
|
return g_object_new (CALLS_TYPE_CALL_SELECTOR_ITEM,
|
|
|
|
"display", display,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CuiCallDisplay *
|
|
|
|
calls_call_selector_item_get_display (CallsCallSelectorItem *item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_CALL_SELECTOR_ITEM (item), NULL);
|
|
|
|
return item->display;
|
|
|
|
}
|