Commit c8908d74 authored by Julian Sparber's avatar Julian Sparber

ContactSheet: Add make call and send sms button

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
parent 6b2a190c
Pipeline #26494 failed with stage
......@@ -45,7 +45,7 @@ public class Contacts.ContactSheet : ContactForm {
return button;
}
void add_row_with_label (string label_value, string value, Widget? buttons = null) {
void add_row_with_label (string label_value, string value, Widget? btn1 = null, Widget? btn2 =null) {
var type_label = new Label (label_value);
type_label.xalign = 1.0f;
type_label.set_halign (Align.END);
......@@ -61,10 +61,14 @@ public class Contacts.ContactSheet : ContactForm {
value_label.wrap_mode = Pango.WrapMode.CHAR;
value_label.set_selectable (true);
if (buttons != null) {
if (btn1 != null || btn2 !=null) {
var value_box = new Box(Orientation.HORIZONTAL, 12);
value_box.pack_start(value_label, false, false, 0);
value_box.pack_end(buttons, false, false, 0);
if (btn1 != null)
value_box.pack_end(btn1, false, false, 0);
if (btn2 != null)
value_box.pack_end(btn2, false, false, 0);
this.container_grid.attach (value_box, 1, this.last_row, 1, 1);
} else {
this.container_grid.attach (value_label, 1, this.last_row, 1, 1);
......@@ -201,7 +205,23 @@ public class Contacts.ContactSheet : ContactForm {
add_row_with_label (TypeSet.phone.format_type (phone), phone.value);
}
#else
add_row_with_label (TypeSet.phone.format_type (phone), phone.value);
// Show a call button when we have a hanlder for it
Button call_button = null;
Button sms_button = null;
if (AppInfo.get_all_for_type ("x-scheme-handler/tel").length () > 0) {
call_button = create_button ("call-start-symbolic");
call_button.clicked.connect (() => {
Utils.start_call (phone.value);
});
}
if (AppInfo.get_all_for_type ("x-scheme-handler/sms").length () > 0) {
sms_button = create_button ("mail-unread-symbolic");
sms_button.clicked.connect (() => {
Utils.send_sms (phone.value);
});
}
add_row_with_label (TypeSet.phone.format_type (phone), phone.value, call_button, sms_button);
#endif
}
}
......
......@@ -112,6 +112,24 @@ namespace Contacts.Utils {
var request = new TelepathyGLib.AccountChannelRequest(account, request_dict, int64.MAX);
request.ensure_channel_async.begin ("org.freedesktop.Telepathy.Client.Empathy.Call", null);
}
#else
public void start_call (string number) {
var uri = "tel:" + Uri.escape_string (number, "+" , false);
try {
Gtk.show_uri_on_window (null, uri, 0);
} catch (Error e) {
debug ("Couldn't launch URI \"%s\": %s", uri, e.message);
}
}
public void send_sms (string number) {
var uri = "sms:" + Uri.escape_string (number, "+" , false);
try {
Gtk.show_uri_on_window (null, uri, 0);
} catch (Error e) {
debug ("Couldn't launch URI \"%s\": %s", uri, e.message);
}
}
#endif
public T? get_first<T> (Collection<T> collection) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment