1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-12-14 00:17:35 +00:00

record-row: Handle calls with NULL id gracefully

Shuffles some code around so that the property bindings are at the end.
This allows us to return early if there is a NULL contact (as is the case
for anonymous callers).
This commit is contained in:
Evangelos Ribeiro Tzaras 2022-02-17 11:57:14 +01:00
parent cd075d9269
commit 5b171bf2c5

View file

@ -310,15 +310,40 @@ setup_contact (CallsCallRecordRow *self)
g_autofree gchar *target = NULL; g_autofree gchar *target = NULL;
CallsContactsProvider *contacts_provider; CallsContactsProvider *contacts_provider;
contacts_provider = calls_manager_get_contacts_provider (calls_manager_get_default ());
if (calls_contacts_provider_get_can_add_contacts (contacts_provider)) {
on_notify_can_add_contacts (self);
} else {
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_new_contact), FALSE);
g_signal_connect_swapped (contacts_provider,
"notify::can-add-contacts",
G_CALLBACK (on_notify_can_add_contacts),
self);
}
// Get the target number // Get the target number
g_object_get (G_OBJECT (self->record), g_object_get (G_OBJECT (self->record),
"target", &target, "target", &target,
NULL); NULL);
if (!target || target[0] == '\0') {
gtk_actionable_set_action_name (GTK_ACTIONABLE (self->button), NULL);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_copy), FALSE);
} else {
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_copy), TRUE);
}
// Look up the best match object // Look up the best match object
contacts_provider = calls_manager_get_contacts_provider (calls_manager_get_default ());
self->contact = calls_contacts_provider_lookup_id (contacts_provider, target); self->contact = calls_contacts_provider_lookup_id (contacts_provider, target);
if (!self->contact) {
gtk_label_set_text (self->target, calls_best_match_get_primary_info (NULL));
return;
}
g_object_bind_property (self->contact, "primary-info", g_object_bind_property (self->contact, "primary-info",
self->target, "label", self->target, "label",
G_BINDING_SYNC_CREATE); G_BINDING_SYNC_CREATE);
@ -331,23 +356,6 @@ setup_contact (CallsCallRecordRow *self)
self->avatar, "loadable-icon", self->avatar, "loadable-icon",
G_BINDING_SYNC_CREATE); G_BINDING_SYNC_CREATE);
if (calls_contacts_provider_get_can_add_contacts (contacts_provider)) {
on_notify_can_add_contacts (self);
} else {
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_new_contact), FALSE);
g_signal_connect_swapped (contacts_provider,
"notify::can-add-contacts",
G_CALLBACK (on_notify_can_add_contacts),
self);
}
if (target[0] == '\0') {
gtk_actionable_set_action_name (GTK_ACTIONABLE (self->button), NULL);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_copy), FALSE);
} else {
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_copy), TRUE);
}
} }
@ -453,8 +461,11 @@ constructed (GObject *object)
gtk_actionable_set_action_name (GTK_ACTIONABLE (self->button), action_name); gtk_actionable_set_action_name (GTK_ACTIONABLE (self->button), action_name);
/* TODO add origin ID to action target */ /* TODO add origin ID to action target */
gtk_actionable_set_action_target (GTK_ACTIONABLE (self->button), if (target && *target)
"(ss)", target, ""); gtk_actionable_set_action_target (GTK_ACTIONABLE (self->button),
"(ss)", target, "");
else
;
setup_time (self, inbound, answered, end); setup_time (self, inbound, answered, end);
calls_date_time_unref (answered); calls_date_time_unref (answered);