[gnome-contacts] Display persona stores in link dialog



commit dd460467d6b1eba8efbbf968ed410c1e241d75c1
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Sep 6 13:46:35 2011 +0200

    Display persona stores in link dialog

 src/contacts-cell-renderer-shape.vala |   55 +++++++++++++++++----------------
 src/contacts-link-dialog.vala         |    2 +-
 src/contacts-view.vala                |   41 +++++++++++++++++++++---
 3 files changed, 65 insertions(+), 33 deletions(-)
---
diff --git a/src/contacts-cell-renderer-shape.vala b/src/contacts-cell-renderer-shape.vala
index 953d5be..9896f3c 100644
--- a/src/contacts-cell-renderer-shape.vala
+++ b/src/contacts-cell-renderer-shape.vala
@@ -28,6 +28,7 @@ public class Contacts.CellRendererShape : Gtk.CellRenderer {
   public PresenceType presence { get;  set; }
   public string message { get;  set; }
   public bool is_phone  { get;  set; }
+  public bool show_presence  { get;  set; }
   const int default_width = 60;
 
   private struct IconShape {
@@ -121,15 +122,15 @@ public class Contacts.CellRendererShape : Gtk.CellRenderer {
 					    CellRendererState flags) {
     Pango.Layout layout;
     int xpad;
+    Pango.Rectangle r = { 0, -CellRendererShape.IMAGE_SIZE*1024*7/10,
+			  CellRendererShape.IMAGE_SIZE*1024, CellRendererShape.IMAGE_SIZE*1024 };
 
     var attr_list = new Pango.AttrList ();
 
-    string? str = null;
+    string? str = "";
     string? iconname = Contact.presence_to_icon (presence);
-    if (iconname != null) {
-      str = "*";
-      Pango.Rectangle r = { 0, -CellRendererShape.IMAGE_SIZE*1024*7/10,
-			    CellRendererShape.IMAGE_SIZE*1024, CellRendererShape.IMAGE_SIZE*1024 };
+    if (iconname != null && show_presence) {
+      str += "*";
       IconShape icon_shape = IconShape();
       icon_shape.icon = iconname;
       icon_shape.colorize = true;
@@ -137,28 +138,28 @@ public class Contacts.CellRendererShape : Gtk.CellRenderer {
       a.start_index = 0;
       a.end_index = 1;
       attr_list.insert ((owned) a);
-      if (message != null) {
-	string m = message;
-	if (m.length == 0)
-	  m = Contact.presence_to_string (presence);
-	str += " ";
-
-	var attr = new Pango.AttrSize (9 * Pango.SCALE);
-	attr.absolute = 1;
-	attr.start_index = str.length;
-	attr.end_index = attr.start_index + m.length;
-	attr_list.insert ((owned) attr);
-	str += m;
-
-	if (is_phone) {
-	  icon_shape = IconShape();
-	  icon_shape.icon = "phone-symbolic";
-	  a = new Pango.AttrShape<IconShape?>.with_data (r, r, icon_shape, (s) => { return s;});
-	  a.start_index = str.length;
-	  str += "*";
-	  a.end_index = str.length;
-	  attr_list.insert ((owned) a);
-	}
+      str += " ";
+    }
+    if (message != null && (!show_presence || iconname != null)) {
+      string m = message;
+      if (m.length == 0)
+	m = Contact.presence_to_string (presence);
+
+      var attr = new Pango.AttrSize (9 * Pango.SCALE);
+      attr.absolute = 1;
+      attr.start_index = str.length;
+      attr.end_index = attr.start_index + m.length;
+      attr_list.insert ((owned) attr);
+      str += m;
+
+      if (is_phone && show_presence) {
+	var icon_shape = IconShape();
+	icon_shape.icon = "phone-symbolic";
+	var a = new Pango.AttrShape<IconShape?>.with_data (r, r, icon_shape, (s) => { return s;});
+	a.start_index = str.length;
+	str += "*";
+	a.end_index = str.length;
+	attr_list.insert ((owned) a);
       }
     }
 
diff --git a/src/contacts-link-dialog.vala b/src/contacts-link-dialog.vala
index 5831dc1..8251d09 100644
--- a/src/contacts-link-dialog.vala
+++ b/src/contacts-link-dialog.vala
@@ -87,7 +87,7 @@ public class Contacts.LinkDialog : Dialog {
 
     view = new View (contact.store);
     view.hide_contact (contact);
-    list = new ViewWidget (view);
+    list = new ViewWidget (view, ViewWidget.TextDisplay.STORES);
 
     var grid = new Grid ();
     var container = (get_content_area () as Container);
diff --git a/src/contacts-view.vala b/src/contacts-view.vala
index bd42208..2178051 100644
--- a/src/contacts-view.vala
+++ b/src/contacts-view.vala
@@ -233,11 +233,18 @@ public class Contacts.View : GLib.Object {
 public class Contacts.ViewWidget : TreeView {
   public View view;
   private CellRendererShape shape;
+  public enum TextDisplay {
+    NONE,
+    PRESENCE,
+    STORES
+  }
+  private TextDisplay text_display;
 
   public signal void selection_changed (Contact? contact);
 
-  public ViewWidget (View view) {
+  public ViewWidget (View view, TextDisplay text_display = TextDisplay.PRESENCE) {
     this.view = view;
+    this.text_display = text_display;
 
     set_model (view.model);
     set_headers_visible (false);
@@ -292,10 +299,34 @@ public class Contacts.ViewWidget : TreeView {
 	var name = contact.display_name;
 	if (name == "" && contact.is_new)
 	  name = _("New contact");
-	cell.set ("name", name,
-		  "presence", contact.presence_type,
-		  "message", contact.presence_message,
-		  "is_phone", contact.is_phone);
+	switch (text_display) {
+	default:
+	case TextDisplay.NONE:
+	  cell.set ("name", name,
+		    "show_presence", false,
+		    "message", "");
+	  break;
+	case TextDisplay.PRESENCE:
+	  cell.set ("name", name,
+		    "show_presence", true,
+		    "presence", contact.presence_type,
+		    "message", contact.presence_message,
+		    "is_phone", contact.is_phone);
+	  break;
+	case TextDisplay.STORES:
+	  string stores = "";
+	  bool first = true;
+	  foreach (var p in contact.individual.personas) {
+	    if (!first)
+	      stores += ", ";
+	    stores += Contact.format_persona_store_name (p.store);
+	    first = false;
+	  }
+	  cell.set ("name", name,
+		    "show_presence", false,
+		    "message", stores);
+	  break;
+	}
       });
 
     append_column (column);



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