summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2022-06-29 12:21:02 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2022-06-29 20:15:33 +0200
commitab6c9c5d3bcc2f9f98aa1b4338b6893174e3ce91 (patch)
tree0012387e04d12f14699a236574cf7f47afac5367
parent0401dfa8966badab873d816b97ecbb42de5daa09 (diff)
downloadgnome-contacts-nielsdg/phones.tar.gz
sheet: Add a button to start a phone callnielsdg/phones
evolution-data-server provides a class `E.PhoneNumber` which -amongst other things- allows us to parse freeform strings as phone numbers. If successful, it also allows to generate a `tel:` URI which we can use to start a call with the user's preferred application. Note however that it's only really supported if E-D-S was compiled with support for libphonenumber (which provides the underlying implementation).
-rw-r--r--src/contacts-contact-sheet.vala28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala
index 5c6677e..b9f2295 100644
--- a/src/contacts-contact-sheet.vala
+++ b/src/contacts-contact-sheet.vala
@@ -280,25 +280,39 @@ public class Contacts.ContactSheet : Gtk.Grid {
if (phone_details == null)
return;
+ bool ephonenr_support = E.PhoneNumber.is_supported ();
+ debug ("Support for E.PhoneNumber: %s", ephonenr_support.to_string ());
+
var phones = Utils.sort_fields<PhoneFieldDetails>(phone_details.phone_numbers);
var rows = new GLib.List<Gtk.ListBoxRow> ();
foreach (var phone in phones) {
if (phone.value == "")
continue;
+ string phonenr = phone.value;
+ E.PhoneNumber? ephone = null;
+ if (ephonenr_support) {
+ try {
+ ephone = E.PhoneNumber.from_string (phone.value, null);
+ } catch (Error e) {
+ debug ("Can't parse phone number: %s", e.message);
+ }
+ }
+
var row = new ContactSheetRow (property,
- phone.value,
+ phonenr,
TypeSet.phone.format_type (phone));
-#if HAVE_TELEPATHY
- if (this.store.caller_account != null) {
+ if (ephone != null) {
var button = row.add_button ("call-start-symbolic");
- button.tooltip_text = _("Start a call");
- button.clicked.connect (() => {
- Utils.start_call (phone.value, this.store.caller_account);
+ var tel_uri = ephone.to_string (E.PhoneNumberFormat.RFC3966);
+ button.tooltip_text = _("Call %s").printf (tel_uri[4:]);
+ button.clicked.connect ((b) => {
+ unowned var window = button.get_root () as Gtk.Window;
+ // FIXME: use show_uri_full so we can show errors
+ Gtk.show_uri (window, tel_uri, Gdk.CURRENT_TIME);
});
}
-#endif
rows.append (row);
}