phosh-arch/gnome-contacts-mobile/0001-ContactSheet-Add-make-call-and-send-sms-button.patch
2024-08-13 08:17:11 -07:00

68 lines
2.4 KiB
Diff

From: Julian Sparber <julian@sparber.net>
Date: Wed, 13 Jul 2022 22:03:09 +0400
Subject: contact-sheet: Add call and send sms buttons
This adds a button to make calls via the default handler for tel:
and a button to send sms via the default handler for sms:
The buttons are hidden when no handler is available.
---
src/contacts-contact-sheet.vala | 15 +++++++++++++++
src/contacts-utils.vala | 18 ++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala
index e662ee0..c93370d 100644
--- a/src/contacts-contact-sheet.vala
+++ b/src/contacts-contact-sheet.vala
@@ -245,6 +245,21 @@ public class Contacts.ContactSheet : Gtk.Widget {
var row = new ContactSheetRow (chunk,
phone.raw_number,
phone.get_phone_type ().display_name);
+
+ // Show a call button when we have a handler for it
+ if (AppInfo.get_all_for_type ("x-scheme-handler/tel").length () > 0) {
+ var call_button = row.add_button ("call-start-symbolic");
+ call_button.clicked.connect (() => {
+ Utils.start_call (phone.raw_number, get_root () as Gtk.Window);
+ });
+ }
+ if (AppInfo.get_all_for_type ("x-scheme-handler/sms").length () > 0) {
+ var sms_button = row.add_button ("chat-message-new-symbolic");
+ sms_button.clicked.connect (() => {
+ Utils.send_sms (phone.raw_number, get_root () as Gtk.Window);
+ });
+ }
+
group.add (row);
}
diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala
index a457a2e..2e6aeef 100644
--- a/src/contacts-utils.vala
+++ b/src/contacts-utils.vala
@@ -19,6 +19,24 @@ using Folks;
namespace Contacts.Utils {
+ public void start_call (string number, Gtk.Window toplevel) {
+ var uri = "tel:" + Uri.escape_string (number, "+" , false);
+ try {
+ Gtk.show_uri (toplevel, uri, 0);
+ } catch (Error e) {
+ debug ("Couldn't launch URI \"%s\": %s", uri, e.message);
+ }
+ }
+
+ public void send_sms (string number, Gtk.Window toplevel) {
+ var uri = "sms:" + Uri.escape_string (number, "+" , false);
+ try {
+ Gtk.show_uri (toplevel, uri, 0);
+ } catch (Error e) {
+ debug ("Couldn't launch URI \"%s\": %s", uri, e.message);
+ }
+ }
+
public T? get_first<T> (Gee.Collection<T> collection) {
var i = collection.iterator();
if (i.next())