call-record-row: Improve event handling

Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/714>
This commit is contained in:
Anton Lazarev
2024-01-12 16:38:25 -08:00
parent caecf10cc1
commit eef5b33ad4
2 changed files with 67 additions and 58 deletions

View File

@@ -46,7 +46,6 @@ struct _CallsCallRecordRow {
GtkLabel *time;
GtkButton *button;
GtkPopover *popover;
GtkBox *event_box;
GMenu *context_menu;
@@ -508,6 +507,19 @@ dispose (GObject *object)
}
static void
finalize (GObject *object)
{
CallsCallRecordRow *self = CALLS_CALL_RECORD_ROW (object);
GtkWidget *popover = GTK_WIDGET (self->popover);
g_clear_pointer (&popover, gtk_widget_unparent);
G_OBJECT_CLASS (calls_call_record_row_parent_class)->dispose (object);
}
static void
calls_call_record_row_class_init (CallsCallRecordRowClass *klass)
{
@@ -518,6 +530,7 @@ calls_call_record_row_class_init (CallsCallRecordRowClass *klass)
object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
props[PROP_RECORD] =
g_param_spec_object ("record",
@@ -536,7 +549,6 @@ calls_call_record_row_class_init (CallsCallRecordRowClass *klass)
gtk_widget_class_bind_template_child (widget_class, CallsCallRecordRow, time);
gtk_widget_class_bind_template_child (widget_class, CallsCallRecordRow, button);
gtk_widget_class_bind_template_child (widget_class, CallsCallRecordRow, event_box);
gtk_widget_class_bind_template_child (widget_class, CallsCallRecordRow, context_menu);
}
@@ -616,10 +628,10 @@ new_sms_activated (GSimpleAction *action,
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},
{ "new-sms", new_sms_activated, NULL, NULL, NULL},
{ "delete-call", delete_call_activated },
{ "copy-number", copy_number_activated },
{ "new-contact", new_contact_activated },
{ "new-sms", new_sms_activated },
};
@@ -644,13 +656,14 @@ calls_call_record_row_init (CallsCallRecordRow *self)
g_simple_action_set_enabled (G_SIMPLE_ACTION (act), TRUE);
gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
g_signal_connect (gesture, "pressed", G_CALLBACK (calls_call_record_row_button_press_event), self);
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
gesture = gtk_gesture_long_press_new ();
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), TRUE);
g_signal_connect (gesture, "pressed", G_CALLBACK (on_long_pressed), self);
gtk_widget_add_controller (GTK_WIDGET (self->event_box), GTK_EVENT_CONTROLLER (gesture));
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
}

View File

@@ -5,8 +5,6 @@
<property name="activatable">False</property>
<property name="selectable">False</property>
<property name="child">
<object class="GtkBox" id="event_box">
<child>
<object class="GtkBox">
<child>
<object class="AdwAvatar" id="avatar">
@@ -54,29 +52,27 @@
</object>
</child>
</object>
</child>
</object>
</property>
</template>
<menu id="context_menu">
<section>
<item>
<attribute name="label" translatable="yes">_Delete Call</attribute>
<attribute name="action">delete-call</attribute>
<attribute name="action">row-history.delete-call</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Copy number</attribute>
<attribute name="action">copy-number</attribute>
<attribute name="action">row-history.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="action">row-history.new-contact</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Send SMS</attribute>
<attribute name="action">new-sms</attribute>
<attribute name="action">row-history.new-sms</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
</section>