Clean up contacts-utils.vala

* Remove some dead code
* Always log in case of an error (use `debug()` for that reason)
* Clean up some mixed indent
This commit is contained in:
Niels De Graef 2017-07-18 13:14:36 +02:00
parent 51de2b085b
commit 4a1b2ff85d

View file

@ -18,7 +18,6 @@
using Gtk; using Gtk;
using Folks; using Folks;
using Gee; using Gee;
using TelepathyGLib;
using DBus; using DBus;
using GLib; using GLib;
using Gdk; using Gdk;
@ -49,8 +48,7 @@ namespace Contacts {
return provider; return provider;
} }
public void add_separator (ListBoxRow row, public void add_separator (ListBoxRow row, ListBoxRow? before_row) {
ListBoxRow? before_row) {
row.set_header (new Separator (Orientation.HORIZONTAL)); row.set_header (new Separator (Orientation.HORIZONTAL));
} }
@ -78,9 +76,8 @@ namespace Contacts {
context.set_timestamp (timestamp); context.set_timestamp (timestamp);
Variant[] param_array = {}; Variant[] param_array = {};
if (parameter != null) { if (parameter != null)
param_array += parameter; param_array += parameter;
}
var startup_id = context.get_startup_notify_id (info, var startup_id = context.get_startup_notify_id (info,
new GLib.List<File>()); new GLib.List<File>());
@ -146,19 +143,24 @@ public class Center : Bin {
public class Contacts.Utils : Object { public class Contacts.Utils : Object {
public static void compose_mail (string email) { public static void compose_mail (string email) {
var mailto_uri = "mailto:" + Uri.escape_string (email, "@" , false);
try { try {
Gtk.show_uri_on_window (null, "mailto:" + Uri.escape_string (email, "@" , false), 0); Gtk.show_uri_on_window (null, mailto_uri, 0);
} catch { } catch (Error e) {
debug ("Couldn't launch URI \"%s\": %s", mailto_uri, e.message);
} }
} }
public static void start_chat (Contact contact, string protocol, string id) { public static void start_chat (Contact contact, string protocol, string id) {
var im_persona = contact.find_im_persona (protocol, id); var im_persona = contact.find_im_persona (protocol, id);
var account = (im_persona.store as Tpf.PersonaStore).account; var account = (im_persona.store as Tpf.PersonaStore).account;
var request_dict = new HashTable<weak string,GLib.Value?>(str_hash, str_equal); var request_dict = new HashTable<weak string, Value?>(str_hash, str_equal);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE, TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT); request_dict.insert (TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE,
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE, (int) TelepathyGLib.HandleType.CONTACT); TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID, id); request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE,
(int) TelepathyGLib.HandleType.CONTACT);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID,
id);
// TODO: Should really use the event time like: // TODO: Should really use the event time like:
// tp_user_action_time_from_x11(gtk_get_current_event_time()) // tp_user_action_time_from_x11(gtk_get_current_event_time())
@ -167,30 +169,26 @@ public class Contacts.Utils : Object {
} }
public static void start_call (string contact_id, public static void start_call (string contact_id,
Gee.HashMap<string, Account> accounts) { Gee.HashMap<string, TelepathyGLib.Account> accounts) {
// TODO: prompt for which account to use // TODO: prompt for which account to use
var account = accounts.values.to_array ()[0]; var account = accounts.values.to_array ()[0];
Utils.start_call_with_account (contact_id, account); Utils.start_call_with_account (contact_id, account);
} }
public static void start_call_with_account (string contact_id, public static void start_call_with_account (string contact_id, TelepathyGLib.Account account) {
Account account) { var request_dict = new HashTable<weak string,GLib.Value?>(str_hash, str_equal);
var request_dict = new HashTable<weak string,GLib.Value?>(str_hash,
str_equal);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE, request_dict.insert (TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE,
TelepathyGLib.IFACE_CHANNEL_TYPE_CALL); TelepathyGLib.IFACE_CHANNEL_TYPE_CALL);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE, request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE,
(int) TelepathyGLib.HandleType.CONTACT); (int) TelepathyGLib.HandleType.CONTACT);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID, contact_id); request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID,
request_dict.insert ( contact_id);
TelepathyGLib.PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, request_dict.insert (TelepathyGLib.PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO,
true); true);
var request = new TelepathyGLib.AccountChannelRequest(account, var request = new TelepathyGLib.AccountChannelRequest(account, request_dict, int64.MAX);
request_dict, int64.MAX); request.ensure_channel_async.begin ("org.freedesktop.Telepathy.Client.Empathy.Call", null);
request.ensure_channel_async.begin (
"org.freedesktop.Telepathy.Client.Empathy.Call", null);
} }
public static T? get_first<T> (Collection<T> collection) { public static T? get_first<T> (Collection<T> collection) {
@ -200,33 +198,6 @@ public class Contacts.Utils : Object {
return null; return null;
} }
public static Gtk.MenuItem add_menu_item (Gtk.Menu menu, string label) {
var mi = new Gtk.MenuItem.with_label (label);
menu.append (mi);
mi.show ();
return mi;
}
public static void grid_insert_row_after (Grid grid, Widget widget, bool expand_intersecting) {
int y, h;
grid.child_get (widget,
"top-attach", out y,
"height", out h);
int start = y + h;
foreach (var child in grid.get_children ()) {
grid.child_get (child,
"top-attach", out y,
"height", out h);
if (y >= start) {
grid.child_set (child,
"top-attach", y + 1);
} else if (y + h > start && expand_intersecting) {
grid.child_set (child,
"height", h + 1);
}
}
}
public static void cairo_ellipsis (Cairo.Context cr, public static void cairo_ellipsis (Cairo.Context cr,
double xc, double yc, double xc, double yc,
double xradius, double yradius, double xradius, double yradius,
@ -319,14 +290,6 @@ public class Contacts.Utils : Object {
return res.str; return res.str;
} }
public static void grab_widget_later (Widget widget) {
ulong id = 0;
id = widget.size_allocate.connect ( () => {
widget.grab_focus ();
widget.disconnect (id);
});
}
public static void grab_entry_focus_no_select (Entry entry) { public static void grab_entry_focus_no_select (Entry entry) {
int start, end; int start, end;
if (!entry.get_selection_bounds (out start, out end)) { if (!entry.get_selection_bounds (out start, out end)) {
@ -369,14 +332,14 @@ public class Contacts.Utils : Object {
try { try {
Process.spawn_async (null, args, null, SpawnFlags.SEARCH_PATH, null, null); Process.spawn_async (null, args, null, SpawnFlags.SEARCH_PATH, null, null);
} } catch (Error e) {
catch { debug ("Couldn't spawn process \"%s\": %s", string.joinv(" ", args), e.message);
} }
} else { } else {
try { try {
spawn_app (calendar_settings); spawn_app (calendar_settings);
} } catch (Error e) {
catch { debug ("Couldn't spawn calendar app: %s", e.message);
} }
} }
} }
@ -389,7 +352,8 @@ public class Contacts.Utils : Object {
Dir? dir = null; Dir? dir = null;
try { try {
dir = Dir.open (path); dir = Dir.open (path);
} catch { } catch (Error e) {
debug ("Couldn't open stock avatars folder \"%s\": %s", path, e.message);
} }
if (dir != null) { if (dir != null) {
string? face; string? face;