[gnome-contacts] Initial work on contact info pane



commit 86a2f3532b9da862a07eac8491a779c1a311f463
Author: Alexander Larsson <alexl redhat com>
Date:   Fri May 13 14:16:27 2011 +0200

    Initial work on contact info pane

 data/gnome-contacts.css          |    9 +++-
 src/Makefile.am                  |    1 +
 src/contacts-app.vala            |  102 ++++++++++++++++++++++++++++++++++++++
 src/contacts-contact.vala        |    8 ++--
 src/contacts-starred-button.vala |   44 ++++++++++++++++
 5 files changed, 159 insertions(+), 5 deletions(-)
---
diff --git a/data/gnome-contacts.css b/data/gnome-contacts.css
index 2883a40..3282d4f 100644
--- a/data/gnome-contacts.css
+++ b/data/gnome-contacts.css
@@ -1,5 +1,12 @@
-ContactsApp GtkFrame.frame {
+ContactsApp > GtkFrame.frame {
     border-style: solid;
     border-width: 0 1 1 1;
     padding: 0 1 1 1;
 }
+
+.contactframe {
+    border-style: solid;
+    border-radius: 2;
+    border-width: 2;
+    padding: 1;
+}
diff --git a/src/Makefile.am b/src/Makefile.am
index 19489bc..0443ee6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,6 +18,7 @@ bin_PROGRAMS = gnome-contacts
 gnome_contacts_SOURCES = \
 	contacts-app.vala \
 	contacts-contact.vala \
+	contacts-starred-button.vala \
 	main.vala \
 	$(NULL)
 
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index cd566f5..2acc2ff 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -37,6 +37,7 @@ public class Contacts.App : Window {
 
     var selection = tree_view.get_selection ();
     selection.set_mode (SelectionMode.BROWSE);
+    selection.changed.connect (contacts_selected_changed);
 
     var column = new TreeViewColumn ();
     column.set_spacing (10);
@@ -131,6 +132,106 @@ public class Contacts.App : Window {
     filter_model.refilter ();
   }
 
+  private void add_label (string label, int i) {
+    var l = new Label (label);
+    l.get_style_context ().add_class ("dim-label");
+    l.set_valign (Align.CENTER);
+    l.set_halign (Align.END);
+    contacts_grid.attach (l,  0, i, 1, 1);
+  }
+
+  private void add_string_label (Contact contact, string label, string pname, ref int i) {
+    Value prop_value;
+    prop_value = Value (typeof (string));
+    contact.individual.get_property (pname, ref prop_value);
+    string val = prop_value.get_string ();
+
+    if (val != null) {
+      add_label(label, i);
+      var v = new Label (val);
+      v.set_valign (Align.CENTER);
+      v.set_halign (Align.START);
+      contacts_grid.attach (v,  1, i, 2, 1);
+      i++;
+    }
+  }
+
+  /* Format:
+
+      col 1      col 2                 col 3
+
+     +-------+  Full Name             <starred>
+     | image |  "nick1", "nick2"
+     +-------+  Job title, company
+
+	 label  Data that spans two columns
+
+   */
+
+  private void display_contact (Contact contact) {
+
+    var image_frame = new Frame (null);
+    image_frame.get_style_context ().add_class ("contactframe");
+    image_frame.set_shadow_type (ShadowType.OUT);
+    var image = new Image ();
+    image.set_size_request (100, 100);
+    image_frame.add (image);
+
+    if (contact.individual.avatar != null &&
+	contact.individual.avatar.get_path () != null) {
+      image.set_from_file (contact.individual.avatar.get_path ());
+    } else {
+      /* TODO: Set fallback image */
+    }
+
+    contacts_grid.attach (image_frame, 0, 0, 1, 1);
+
+    var g = new Grid ();
+    contacts_grid.attach (g, 1, 0, 1, 1);
+
+    var l = new Label (null);
+    l.set_markup ("<big><b>" + contact.display_name + "</b></big>");
+    l.set_hexpand (true);
+    l.set_halign (Align.START);
+    g.attach (l,  1, 0, 1, 1);
+    l = new Label ("\xE2\x80\x9Cnick\xE2\x80\x9D");
+    l.set_halign (Align.START);
+    g.attach (l,  1, 1, 1, 1);
+    l = new Label ("Consultant, Company Inc");
+    l.set_halign (Align.START);
+    g.attach (l,  1, 2, 1, 1);
+
+    var starred = new StarredButton ();
+    starred.set_active (contact.individual.is_favourite);
+    starred.set_hexpand (false);
+    starred.set_vexpand (false);
+    starred.set_valign (Align.START);
+    contacts_grid.attach (starred, 2, 0, 1, 1);
+    int i = 1;
+
+    add_string_label (contact, _("Alias"), "alias", ref i);
+    add_string_label (contact, _("Full name"), "full-name", ref i);
+
+    contacts_grid.show_all ();
+  }
+
+  private void contacts_selected_changed (TreeSelection selection) {
+    TreeIter iter;
+    TreeModel model;
+
+    if (selection.get_selected (out model, out iter)) {
+      Contact contact;
+      model.get (iter, 0, out contact);
+      foreach (var w in contacts_grid.get_children ()) {
+	w.destroy ();
+      }
+      if (contact != null) {
+	display_contact (contact);
+      }
+    }
+  }
+
+
   public App () {
     contacts_store = new ContactStore ();
     filter_model = new TreeModelFilter (contacts_store, null);
@@ -219,6 +320,7 @@ public class Contacts.App : Window {
     ebox.add (right_grid);
 
     contacts_grid = new Grid ();
+    contacts_grid.set_row_spacing (8);
     contacts_grid.set_hexpand (true);
     contacts_grid.set_vexpand (true);
     right_grid.attach (contacts_grid, 0, 0, 1, 1);
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 0743336..1934c93 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -23,7 +23,7 @@ using Folks;
 public class Contacts.ContactStore : ListStore  {
   public ContactStore () {
     GLib.Type[] types = { typeof (Contact) };
-    
+
     set_column_types (types);
   }
   public Contact insert_individual (Individual i) {
@@ -48,7 +48,7 @@ public class Contacts.Contact : GLib.Object  {
   ulong changed_id;
 
   private Gdk.Pixbuf? _avatar;
-  public Gdk.Pixbuf avatar { 
+  public Gdk.Pixbuf avatar {
     get {
       if (_avatar == null)
 	_avatar = load_icon (individual.avatar);
@@ -56,7 +56,7 @@ public class Contacts.Contact : GLib.Object  {
     }
   }
 
-  public string display_name { 
+  public string display_name {
     get {
       unowned string name = individual.full_name;
       if (name != null)
@@ -76,7 +76,7 @@ public class Contacts.Contact : GLib.Object  {
   static construct {
     fallback_avatar = draw_fallback_avatar ();
   }
-   
+
   public Contact(Individual i, ContactStore s) {
     individual = i;
     store = s;
diff --git a/src/contacts-starred-button.vala b/src/contacts-starred-button.vala
new file mode 100644
index 0000000..92aa985
--- /dev/null
+++ b/src/contacts-starred-button.vala
@@ -0,0 +1,44 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
+/*
+ * Copyright (C) 2011 Alexander Larsson <alexl redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+using Gtk;
+
+public class Contacts.StarredButton : ToggleButton  {
+  public StarredButton () {
+    var i = new Image.from_icon_name ("non-starred", IconSize.BUTTON);
+    set_image (i);
+    set_relief (ReliefStyle.NONE);
+  }
+
+  public override void toggled () {
+    Image image = (Image) get_image ();
+    if (get_active ()) {
+      image.set_from_icon_name ("starred", IconSize.BUTTON);
+    } else {
+      image.set_from_icon_name ("non-starred", IconSize.BUTTON);
+    }
+  }
+
+  /* TODO: This isn't exactly right, as it doesn't paint the focus and stuff.
+     But its a good simple start. */
+  public override bool draw (Cairo.Context cr) {
+    propagate_draw (get_child (), cr);
+    return false;
+  }
+}



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