[calls] call-window: Switch to CallsUiCallData



commit fa5969892e227891c9c74ade8383a2639f2efb82
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Mon Jan 31 16:30:39 2022 +0100

    call-window: Switch to CallsUiCallData
    
    By connecting to the "ui-call-added" and "ui-call-removed" signals instead of
    "call-add" and "call-remove".
    
    This allows us to shave off a few lines of code.

 src/calls-call-selector-item.c | 37 +++++++++++--------------------------
 src/calls-call-window.c        | 23 +++++++++++------------
 2 files changed, 22 insertions(+), 38 deletions(-)
---
diff --git a/src/calls-call-selector-item.c b/src/calls-call-selector-item.c
index ac3000e6..4c5ac6cd 100644
--- a/src/calls-call-selector-item.c
+++ b/src/calls-call-selector-item.c
@@ -37,7 +37,6 @@ struct _CallsCallSelectorItem
   GtkEventBox parent_instance;
 
   CuiCallDisplay *display;
-  CallsBestMatch *contact;
 
   GtkBox *main_box;
   GtkLabel *name;
@@ -56,40 +55,27 @@ static GParamSpec *props[PROP_LAST_PROP];
 
 static void
 call_state_changed_cb (CallsCallSelectorItem *self,
-                       CallsCallState         state)
+                       CuiCallState           state)
 {
-  GString *state_str = g_string_new("");
-  calls_call_state_to_string (state_str, state);
-  gtk_label_set_text (self->status, state_str->str);
-  g_string_free (state_str, TRUE);
-}
-
-
-static CallsCall *
-display_get_call (CuiCallDisplay *display)
-{
-  CuiCall *call_data;
+  const char * state_str = cui_call_state_to_string (state);
 
-  g_assert (CUI_IS_CALL_DISPLAY (display));
-
-  call_data = cui_call_display_get_call (display);
-  return calls_ui_call_data_get_call (CALLS_UI_CALL_DATA (call_data));
+  gtk_label_set_text (self->status, state_str);
 }
 
+
 static void
 set_party (CallsCallSelectorItem *self)
 {
-  CallsCall *call;
+  CuiCall *call;
   // FIXME: use HdyAvatar and the contact avatar
   GtkWidget *image = gtk_image_new_from_icon_name ("avatar-default-symbolic", GTK_ICON_SIZE_DIALOG);
 
   gtk_box_pack_start (self->main_box, image, TRUE, TRUE, 0);
   gtk_widget_show (image);
 
-  call = display_get_call (self->display);
-  self->contact = calls_call_get_contact (call);
+  call = cui_call_display_get_call (self->display);
 
-  g_object_bind_property (self->contact, "name",
+  g_object_bind_property (call, "name",
                           self->name, "label",
                           G_BINDING_SYNC_CREATE);
 }
@@ -98,18 +84,18 @@ set_party (CallsCallSelectorItem *self)
 static void
 set_call_display (CallsCallSelectorItem *self, CuiCallDisplay *display)
 {
-  CallsCall *call;
+  CuiCall *call;
 
   g_assert (CALLS_IS_CALL_SELECTOR_ITEM (self));
   g_assert (CUI_IS_CALL_DISPLAY (display));
 
-  call = display_get_call (display);
-  g_signal_connect_object (call, "state-changed",
+  call = cui_call_display_get_call (display);
+  g_signal_connect_object (call, "notify::state",
                            G_CALLBACK (call_state_changed_cb),
                            self,
                            G_CONNECT_SWAPPED);
 
-  call_state_changed_cb (self, calls_call_get_state (call));
+  call_state_changed_cb (self, cui_call_get_state (call));
 
   g_set_object (&self->display, display);
   set_party (self);
@@ -150,7 +136,6 @@ dispose (GObject *object)
   CallsCallSelectorItem *self = CALLS_CALL_SELECTOR_ITEM (object);
 
   g_clear_object (&self->display);
-  g_clear_object (&self->contact);
 
   G_OBJECT_CLASS (calls_call_selector_item_parent_class)->dispose (object);
 }
diff --git a/src/calls-call-window.c b/src/calls-call-window.c
index df127a36..ba2e0872 100644
--- a/src/calls-call-window.c
+++ b/src/calls-call-window.c
@@ -177,20 +177,19 @@ call_selector_child_activated_cb (GtkFlowBox      *box,
 
 static void
 add_call (CallsCallWindow *self,
-          CallsCall       *call)
+          CallsUiCallData *ui_call_data)
 {
-  CallsUiCallData *call_data;
+  CuiCall *call = (CuiCall *) ui_call_data;
   CuiCallDisplay *display;
   CallsCallSelectorItem *item;
 
   g_assert (CALLS_IS_CALL_WINDOW (self));
-  g_assert (CALLS_IS_CALL (call));
+  g_assert (CUI_IS_CALL (call));
 
-  call_data = calls_ui_call_data_new (call);
-  display = cui_call_display_new (CUI_CALL (call_data));
+  display = cui_call_display_new (CUI_CALL (ui_call_data));
   item = calls_call_selector_item_new (display);
   gtk_stack_add_named (self->call_stack, GTK_WIDGET (display),
-                       calls_call_get_id (call));
+                       cui_call_get_id (call));
 
   g_list_store_append (self->calls, item);
 
@@ -218,23 +217,23 @@ on_remove_delayed (gpointer user_data)
 
 static void
 remove_call (CallsCallWindow *self,
-             CallsCall       *call,
+             CallsUiCallData *ui_call_data,
              const gchar     *reason)
 {
   guint n_calls;
 
   g_assert (CALLS_IS_CALL_WINDOW (self));
-  g_assert (CALLS_IS_CALL (call));
+  g_assert (CALLS_IS_UI_CALL_DATA (ui_call_data));
 
   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);
     CuiCallDisplay *display = calls_call_selector_item_get_display (item);
-    CallsUiCallData *call_data =
+    CallsUiCallData *display_call_data =
       CALLS_UI_CALL_DATA (cui_call_display_get_call (display));
 
-    if (calls_ui_call_data_get_call (call_data) == call) {
+    if (display_call_data == ui_call_data) {
       struct DisplayData *display_data = g_new0 (struct DisplayData, 1);
 
       g_list_store_remove (self->calls, i);
@@ -302,12 +301,12 @@ calls_call_window_init (CallsCallWindow *self)
                             self->in_app_notification);
 
   g_signal_connect_swapped (calls_manager_get_default (),
-                            "call-add",
+                            "ui-call-added",
                             G_CALLBACK (add_call),
                             self);
 
   g_signal_connect_swapped (calls_manager_get_default (),
-                            "call-remove",
+                            "ui-call-removed",
                             G_CALLBACK (remove_call),
                             self);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]