contacts-contact: Add method to geocode a contact

https://bugzilla.gnome.org/show_bug.cgi?id=658553
This commit is contained in:
Jonas Danielsson 2014-12-16 05:32:17 -05:00
parent 988a7ef959
commit 1153339f02
2 changed files with 36 additions and 1 deletions

View file

@ -50,10 +50,11 @@ pkg_modules="gtk+-3.0 >= 3.12.0
libedataserver-1.2 >= 3.5.3
goa-1.0
gee-0.8
geocode-glib-1.0
"
PKG_CHECK_MODULES(CONTACTS, [$pkg_modules])
CONTACTS_PACKAGES="--pkg gtk+-3.0 --pkg gio-2.0 --pkg gio-unix-2.0 --pkg folks --pkg folks-telepathy --pkg folks-eds --pkg libnotify"
CONTACTS_PACKAGES="--pkg gtk+-3.0 --pkg gio-2.0 --pkg gio-unix-2.0 --pkg folks --pkg folks-telepathy --pkg folks-eds --pkg libnotify --pkg geocode-glib-1.0"
AC_SUBST(CONTACTS_PACKAGES)
# Optional dependency for the user accounts panel

View file

@ -20,6 +20,7 @@ using Gtk;
using Folks;
using Gee;
using TelepathyGLib;
using Geocode;
public errordomain ContactError {
NOT_IMPLEMENTED,
@ -672,6 +673,39 @@ public class Contacts.Contact : GLib.Object {
return res;
}
public static async Place geocode_address (PostalAddress addr) {
SourceFunc callback = geocode_address.callback;
var params = new HashTable<string, GLib.Value?>(str_hash, str_equal);
if (is_set (addr.street))
params.insert("street", addr.street);
if (is_set (addr.locality))
params.insert("locality", addr.locality);
if (is_set (addr.region))
params.insert("region", addr.region);
if (is_set (addr.country))
params.insert("country", addr.country);
Place? place = null;
var forward = new Forward.for_params (params);
forward.search_async.begin (null, (object, res) => {
try {
var places = forward.search_async.end (res);
place = places.nth_data (0);
callback ();
} catch (GLib.Error e) {
debug ("No geocode result found for contact");
callback ();
}
});
yield;
return place;
}
public static string[] format_address (PostalAddress addr) {
string[] lines = {};