[gnome-contacts] Add merged presence in card
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Add merged presence in card
- Date: Wed, 8 Jun 2011 20:35:01 +0000 (UTC)
commit 174dae84722c47a5daeed363f20cb3ee4e8c1370
Author: Alexander Larsson <alexl redhat com>
Date: Wed Jun 8 11:25:34 2011 +0200
Add merged presence in card
src/contacts-app.vala | 30 ++++++++++++------
src/contacts-contact.vala | 73 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 10 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 72e307b..499eb27 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -204,6 +204,10 @@ public class Contacts.App : Window {
private void display_contact (Contact contact) {
+ var card_grid = new Grid ();
+ fields_grid.attach (card_grid, 0, 0, 1, 1);
+ card_grid.set_row_spacing (8);
+
var image_frame = new Frame (null);
label_size_group.add_widget (image_frame);
image_frame.get_style_context ().add_class ("contact-frame");
@@ -231,30 +235,36 @@ public class Contacts.App : Window {
image.set_from_pixbuf (pixbuf);
}
- var card_grid = new Grid ();
- card_grid.set_row_spacing (8);
-
- fields_grid.attach (card_grid, 0, 0, 1, 1);
-
card_grid.attach (image_frame, 0, 0, 1, 1);
-
- var g = new Grid ();
+ card_grid.set_vexpand (false);
+ var g = new Grid();
card_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.set_valign (Align.START);
+ g.attach (l, 0, 0, 1, 1);
var nick = contact.individual.nickname;
if (nick != null && nick.length > 0) {
l = new Label ("\xE2\x80\x9C" + nick + "\xE2\x80\x9D");
l.set_halign (Align.START);
- g.attach (l, 1, 1, 1, 1);
+ l.set_valign (Align.START);
+ g.attach (l, 0, 1, 1, 1);
}
+
l = new Label ("<title>, <Company>");
l.set_halign (Align.START);
- g.attach (l, 1, 2, 1, 1);
+ l.set_valign (Align.START);
+ g.attach (l, 0, 2, 1, 1);
+
+ var merged_presence = contact.create_merged_presence_widget ();
+ merged_presence.set_halign (Align.START);
+ merged_presence.set_valign (Align.END);
+ merged_presence.set_vexpand (true);
+ g.attach (merged_presence, 0, 3, 1, 1);
+
DetailsRow row;
var emails = contact.individual.email_addresses;
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 6c77b54..50ff788 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -85,6 +85,30 @@ public class Contacts.Contact : GLib.Object {
return true;
}
+ public static string presence_to_string (PresenceType presence) {
+ switch (presence) {
+ default:
+ case PresenceType.UNKNOWN:
+ return _("Unknown status");
+ case PresenceType.OFFLINE:
+ return _("Offline");
+ case PresenceType.UNSET:
+ return "";
+ case PresenceType.ERROR:
+ return _("Error");
+ case PresenceType.AVAILABLE:
+ return _("Availible");
+ case PresenceType.AWAY:
+ return _("Away");
+ case PresenceType.EXTENDED_AWAY:
+ return _("Extended away");
+ case PresenceType.BUSY:
+ return _("Busy");
+ case PresenceType.HIDDEN:
+ return _("Hidden");
+ }
+ }
+
public static string presence_to_icon (PresenceType presence) {
string? iconname = null;
switch (presence) {
@@ -169,6 +193,55 @@ public class Contacts.Contact : GLib.Object {
return null;
}
+ private void update_presence_widgets (Image image, Label label) {
+ if (individual.presence_type == PresenceType.UNSET) {
+ image.clear ();
+ image.hide ();
+ label.hide ();
+ label.set_text ("");
+ return;
+ }
+
+ image.set_from_icon_name (presence_to_icon_full (individual.presence_type), IconSize.MENU);
+ image.show ();
+ label.show ();
+ if (individual.presence_message == null ||
+ individual.presence_message.length == 0) {
+ label.set_text (presence_to_string (individual.presence_type));
+ } else {
+ label.set_text (individual.presence_message);
+ }
+ }
+
+ public Widget? create_merged_presence_widget () {
+ var grid = new Grid ();
+ grid.set_row_spacing (4);
+ var image = new Image ();
+ image.set_no_show_all (true);
+ grid.add (image);
+ var label = new Label ("");
+ label.set_no_show_all (true);
+ grid.add (label);
+
+
+ update_presence_widgets (image, label);
+
+ var id1 = individual.notify["presence-type"].connect ((pspec) => {
+ update_presence_widgets (image, label);
+ });
+
+ var id2 = individual.notify["presence-message"].connect ( (pspec) => {
+ update_presence_widgets (image, label);
+ });
+
+ grid.destroy.connect (() => {
+ individual.disconnect(id1);
+ individual.disconnect(id2);
+ });
+
+ return grid;
+ }
+
public Widget? create_presence_widget (string protocol, string im_address) {
var tp = find_im_persona (protocol, im_address);
if (tp == null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]