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 Folks;
using Gee;
using TelepathyGLib;
using DBus;
using GLib;
using Gdk;
@ -49,8 +48,7 @@ namespace Contacts {
return provider;
}
public void add_separator (ListBoxRow row,
ListBoxRow? before_row) {
public void add_separator (ListBoxRow row, ListBoxRow? before_row) {
row.set_header (new Separator (Orientation.HORIZONTAL));
}
@ -78,9 +76,8 @@ namespace Contacts {
context.set_timestamp (timestamp);
Variant[] param_array = {};
if (parameter != null) {
if (parameter != null)
param_array += parameter;
}
var startup_id = context.get_startup_notify_id (info,
new GLib.List<File>());
@ -146,19 +143,24 @@ public class Center : Bin {
public class Contacts.Utils : Object {
public static void compose_mail (string email) {
var mailto_uri = "mailto:" + Uri.escape_string (email, "@" , false);
try {
Gtk.show_uri_on_window (null, "mailto:" + Uri.escape_string (email, "@" , false), 0);
} catch {
Gtk.show_uri_on_window (null, mailto_uri, 0);
} 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) {
var im_persona = contact.find_im_persona (protocol, id);
var account = (im_persona.store as Tpf.PersonaStore).account;
var request_dict = new HashTable<weak string,GLib.Value?>(str_hash, str_equal);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE, TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE, (int) TelepathyGLib.HandleType.CONTACT);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID, id);
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_TARGET_HANDLE_TYPE,
(int) TelepathyGLib.HandleType.CONTACT);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID,
id);
// TODO: Should really use the event time like:
// 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,
Gee.HashMap<string, Account> accounts) {
Gee.HashMap<string, TelepathyGLib.Account> accounts) {
// TODO: prompt for which account to use
var account = accounts.values.to_array ()[0];
Utils.start_call_with_account (contact_id, account);
}
public static void start_call_with_account (string contact_id,
Account account) {
var request_dict = new HashTable<weak string,GLib.Value?>(str_hash,
str_equal);
public static void start_call_with_account (string contact_id, TelepathyGLib.Account account) {
var request_dict = new HashTable<weak string,GLib.Value?>(str_hash, str_equal);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE,
TelepathyGLib.IFACE_CHANNEL_TYPE_CALL);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE,
(int) TelepathyGLib.HandleType.CONTACT);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID, contact_id);
request_dict.insert (
TelepathyGLib.PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO,
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TARGET_ID,
contact_id);
request_dict.insert (TelepathyGLib.PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO,
true);
var request = new TelepathyGLib.AccountChannelRequest(account,
request_dict, int64.MAX);
request.ensure_channel_async.begin (
"org.freedesktop.Telepathy.Client.Empathy.Call", null);
var request = new TelepathyGLib.AccountChannelRequest(account, request_dict, int64.MAX);
request.ensure_channel_async.begin ("org.freedesktop.Telepathy.Client.Empathy.Call", null);
}
public static T? get_first<T> (Collection<T> collection) {
@ -200,33 +198,6 @@ public class Contacts.Utils : Object {
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,
double xc, double yc,
double xradius, double yradius,
@ -319,14 +290,6 @@ public class Contacts.Utils : Object {
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) {
int start, end;
if (!entry.get_selection_bounds (out start, out end)) {
@ -369,14 +332,14 @@ public class Contacts.Utils : Object {
try {
Process.spawn_async (null, args, null, SpawnFlags.SEARCH_PATH, null, null);
}
catch {
} catch (Error e) {
debug ("Couldn't spawn process \"%s\": %s", string.joinv(" ", args), e.message);
}
} else {
try {
spawn_app (calendar_settings);
}
catch {
} catch (Error e) {
debug ("Couldn't spawn calendar app: %s", e.message);
}
}
}
@ -389,7 +352,8 @@ public class Contacts.Utils : Object {
Dir? dir = null;
try {
dir = Dir.open (path);
} catch {
} catch (Error e) {
debug ("Couldn't open stock avatars folder \"%s\": %s", path, e.message);
}
if (dir != null) {
string? face;