1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-06-25 05:09:30 +00:00

record-row: Add context menu entry for adding a new contact

Fixes #157
This commit is contained in:
Evangelos Ribeiro Tzaras 2022-01-06 18:24:46 +01:00
parent 5588bd934a
commit 827594dc2e
2 changed files with 55 additions and 3 deletions

View file

@ -296,10 +296,30 @@ setup_time (CallsCallRecordRow *self,
}
static void
on_notify_can_add_contacts (CallsCallRecordRow *self)
{
CallsContactsProvider *contacts_provider;
GAction *action_new_contact = g_action_map_lookup_action (self->action_map, "new-contact");
contacts_provider = calls_manager_get_contacts_provider (calls_manager_get_default ());
if (!calls_contacts_provider_get_can_add_contacts (contacts_provider))
return;
g_object_bind_property (self->contact, "has-individual",
action_new_contact, "enabled",
G_BINDING_SYNC_CREATE |
G_BINDING_INVERT_BOOLEAN);
g_signal_handlers_disconnect_by_data(contacts_provider, self);
}
static void
setup_contact (CallsCallRecordRow *self)
{
GAction *act = g_action_map_lookup_action (self->action_map, "copy-number");
GAction *action_copy = g_action_map_lookup_action (self->action_map, "copy-number");
GAction *action_new_contact = g_action_map_lookup_action (self->action_map, "new-contact");
g_autofree gchar *target = NULL;
CallsContactsProvider *contacts_provider;
@ -324,12 +344,23 @@ setup_contact (CallsCallRecordRow *self)
self->avatar, "loadable-icon",
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 (act), FALSE);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_copy), FALSE);
} else {
gtk_actionable_set_action_name (GTK_ACTIONABLE (self->button), "app.dial");
g_simple_action_set_enabled (G_SIMPLE_ACTION (act), TRUE);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_copy), TRUE);
}
}
@ -545,10 +576,26 @@ copy_number_activated (GSimpleAction *action,
}
static void
new_contact_activated (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
CallsCallRecordRow *self = CALLS_CALL_RECORD_ROW (data);
CallsContactsProvider *contacts_provider;
contacts_provider = calls_manager_get_contacts_provider (calls_manager_get_default ());
calls_contacts_provider_add_new_contact (contacts_provider,
calls_best_match_get_phone_number (self->contact));
}
static GActionEntry entries[] =
{
{ "delete-call", delete_call_activated, NULL, NULL, NULL},
{ "copy-number", copy_number_activated, NULL, NULL, NULL},
{ "new-contact", new_contact_activated, NULL, NULL, NULL},
};

View file

@ -109,6 +109,11 @@
<attribute name="action">copy-number</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Add contact</attribute>
<attribute name="action">new-contact</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
</section>
</menu>
</interface>