[gnome-contacts/wip/map-widget] WIP: Add map widget to sheet



commit d6d39fdf5abc16cbfe4005e37b2f950543049b31
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Fri Dec 5 08:18:46 2014 -0500

    WIP: Add map widget to sheet

 configure.ac                    |    4 ++-
 src/contacts-contact-sheet.vala |   69 ++++++++++++++++++++++++++++++++-------
 src/contacts-contact.vala       |   34 +++++++++++++++++++
 3 files changed, 94 insertions(+), 13 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a7702fa..72c4f3b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,10 +50,12 @@ pkg_modules="gtk+-3.0 >= 3.12.0
             libedataserver-1.2 >= 3.5.3
             goa-1.0
             gee-0.8
+            champlain-gtk-0.12
+            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 clutter-1.0 --pkg champlain-0.12 --pkg champlain-gtk-0.12 --pkg 
geocode-glib-1.0"
 AC_SUBST(CONTACTS_PACKAGES)
 
 # Optional dependency for the user accounts panel
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala
index 0582615..4a61e0e 100644
--- a/src/contacts-contact-sheet.vala
+++ b/src/contacts-contact-sheet.vala
@@ -19,11 +19,24 @@
 using Gtk;
 using Folks;
 using Gee;
+using Geocode;
+using Champlain;
+using GtkChamplain;
+using Clutter;
 
 public class Contacts.ContactSheet : Grid {
 
+  Revealer add_row_with_revealer (ref int row, Widget widget) {
+    var revealer = new Revealer ();
+    revealer.add (widget);
+
+    attach (revealer, 1, row, 1, 1);
+    row++;
+    return revealer;
+  }
+
   Button add_row_with_button (ref int row, string label_value, string value) {
-    var type_label = new Label (label_value);
+    var type_label = new Gtk.Label (label_value);
     type_label.xalign = 1.0f;
     type_label.set_halign (Align.END);
     type_label.get_style_context ().add_class ("dim-label");
@@ -37,14 +50,14 @@ public class Contacts.ContactSheet : Grid {
     attach (value_button, 1, row, 1, 1);
     row++;
 
-    (value_button.get_child () as Label).set_ellipsize (Pango.EllipsizeMode.END);
-    (value_button.get_child () as Label).wrap_mode = Pango.WrapMode.CHAR;
+    (value_button.get_child () as Gtk.Label).set_ellipsize (Pango.EllipsizeMode.END);
+    (value_button.get_child () as Gtk.Label).wrap_mode = Pango.WrapMode.CHAR;
 
     return value_button;
   }
 
   void add_row_with_link_button (ref int row, string label_value, string value) {
-    var type_label = new Label (label_value);
+    var type_label = new Gtk.Label (label_value);
     type_label.xalign = 1.0f;
     type_label.set_halign (Align.END);
     type_label.get_style_context ().add_class ("dim-label");
@@ -58,19 +71,19 @@ public class Contacts.ContactSheet : Grid {
     attach (value_button, 1, row, 1, 1);
     row++;
 
-    (value_button.get_child () as Label).set_ellipsize (Pango.EllipsizeMode.END);
-    (value_button.get_child () as Label).wrap_mode = Pango.WrapMode.CHAR;
+    (value_button.get_child () as Gtk.Label).set_ellipsize (Pango.EllipsizeMode.END);
+    (value_button.get_child () as Gtk.Label).wrap_mode = Pango.WrapMode.CHAR;
   }
 
   void add_row_with_label (ref int row, string label_value, string value) {
-    var type_label = new Label (label_value);
+    var type_label = new Gtk.Label (label_value);
     type_label.xalign = 1.0f;
     type_label.set_halign (Align.END);
     type_label.set_valign (Align.START);
     type_label.get_style_context ().add_class ("dim-label");
     attach (type_label, 0, row, 1, 1);
 
-    var value_label = new Label (value);
+    var value_label = new Gtk.Label (value);
     value_label.set_line_wrap (true);
     value_label.xalign = 0.0f;
     value_label.set_halign (Align.START);
@@ -90,7 +103,7 @@ public class Contacts.ContactSheet : Grid {
   public ContactSheet () {
     set_row_spacing (12);
     set_column_spacing (16);
-    set_orientation (Orientation.VERTICAL);
+    set_orientation (Gtk.Orientation.VERTICAL);
   }
 
   public void update (Contact c) {
@@ -104,7 +117,7 @@ public class Contacts.ContactSheet : Grid {
       });
     attach (image_frame,  0, 0, 1, 3);
 
-    var name_label = new Label (null);
+    var name_label = new Gtk.Label (null);
     name_label.set_hexpand (true);
     name_label.set_halign (Align.START);
     name_label.set_valign (Align.CENTER);
@@ -113,7 +126,7 @@ public class Contacts.ContactSheet : Grid {
     name_label.xalign = 0.0f;
 
     c.keep_widget_uptodate (name_label, (w) => {
-       (w as Label).set_markup (Markup.printf_escaped ("<span font='16'>%s</span>", c.display_name));
+        (w as Gtk.Label).set_markup (Markup.printf_escaped ("<span font='16'>%s</span>", c.display_name));
       });
     attach (name_label,  1, 0, 1, 3);
 
@@ -125,7 +138,7 @@ public class Contacts.ContactSheet : Grid {
     /* Cause personas are sorted properly I can do this */
     foreach (var p in personas) {
       if (!is_first_persona) {
-       var store_name = new Label("");
+        var store_name = new Gtk.Label("");
        store_name.set_markup (Markup.printf_escaped ("<span font='16px bold'>%s</span>",
                                                      Contact.format_persona_store_name_for_contact (p)));
        store_name.set_halign (Align.START);
@@ -220,6 +233,38 @@ public class Contacts.ContactSheet : Grid {
            all_strs += s + "\n";
          }
          add_row_with_label (ref i, TypeSet.general.format_type (addr), all_strs);
+
+          var map = new Embed();
+          var revealer = add_row_with_revealer (ref i, map);
+
+          map.set_size_request (200, 200);
+          map.expand = false;
+          Contact.geocode_address.begin (addr.value, (obj, res) => {
+              var place = Contact.geocode_address.end (res);
+
+              if (place != null) {
+                var view = map.champlain_view;
+                var stage = view.get_stage ();
+                var layer = new MarkerLayer ();
+                var point = new Champlain.Point ();
+                var color = new Clutter.Color ();
+
+                color.init (74, 144, 217, 255);
+                point.color = color;
+                point.latitude = place.location.latitude;
+                point.longitude = place.location.longitude;
+                layer.add_marker (point);
+                view.add_layer (layer);
+
+                /* Ensure we cannot scroll around on the map */
+                stage.captured_event.connect (() => { return true; });
+
+                view.zoom_level = view.max_zoom_level - 2;
+                view.center_on (place.location.latitude,
+                                place.location.longitude);
+                revealer.reveal_child = true;
+              }
+            });
        }
       }
 
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index b3c14da..4078a75 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -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 = {};
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]