From a20742c57995b3dc4cc264585ab3b79ca142261b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 23 Jun 2010 03:38:37 +0200 Subject: Show resource in tooltip --- src/core/ephraim_roster.erl | 3 ++- src/gui/Contact.vala | 45 ++++++++++++++++++++++++++++-------- src/gui/CoreConnector.vala | 56 ++++++++++++++++++++++++++++++++++++++++++--- src/gui/Ephraim.vala | 24 +++++++++++++++++++ 4 files changed, 114 insertions(+), 14 deletions(-) diff --git a/src/core/ephraim_roster.erl b/src/core/ephraim_roster.erl index 6360a34..9cc91f8 100644 --- a/src/core/ephraim_roster.erl +++ b/src/core/ephraim_roster.erl @@ -47,7 +47,8 @@ updateResource(Roster, JID, Priority, Type, Show, Status) -> if RosterEntry#roster_entry.subscription =:= undefined -> ok; true -> - ephraim ! {ui_update, {roster_update, BareJID, dict:to_list(Resources)}} + ephraim ! {ui_update, {roster_update, BareJID, RosterEntry#roster_entry.name, RosterEntry#roster_entry.subscription, + sets:to_list(RosterEntry#roster_entry.groups), dict:to_list(Resources)}} end, Roster#roster{entries=Entries}. diff --git a/src/gui/Contact.vala b/src/gui/Contact.vala index 1db1e62..d79cfff 100644 --- a/src/gui/Contact.vala +++ b/src/gui/Contact.vala @@ -9,26 +9,51 @@ public class Contact : Object { public Contact(string jid0, string? name0) { Object(jid: jid0, name: name0); + + update_display_string(); } public class Resource : Object { + public Resource(int prio0, Show show0, string? status0) { + Object(priority: prio0, show: show0, status: status0); + } + public int priority {get; construct;} public Show show {get; construct;} - public string status {get; construct;} + public string? status {get; construct;} } public string jid {get; construct;} public string? name {get; construct;} public Subscription subscription {get; set;} - public Gee.TreeSet groups; - public Gee.HashMap resources {get; private set;} - - public string display_string { - get { - if (name != null) - return name; - else - return jid; + public Gee.TreeSet groups = new Gee.TreeSet(); + public string display_string {get; private set;} + + private Gee.HashMap resources = new Gee.HashMap(); + + private void update_display_string() { + if (name != null) + display_string = name; + else + display_string = jid; + } + + public Gee.Map.Entry? get_resource_with_highest_priority() { + int max_prio = int.MIN; + Gee.Map.Entry ret = null; + + foreach(Gee.Map.Entry res in resources) { + if(res.value.priority > max_prio) { + max_prio = res.value.priority; + ret = res; + } } + + return ret; + } + + public void update_resource(string resource_name, Resource resource) { + resources[resource_name] = resource; + update_display_string(); } } diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala index 7486aec..1030428 100644 --- a/src/gui/CoreConnector.vala +++ b/src/gui/CoreConnector.vala @@ -69,7 +69,7 @@ public class CoreConnector { // Do nothing break; case Erl.ReceiveType.MSG: - Idle.add(() => {handleTerm(response); return false;}); + Idle.add(() => {handle_term(response); return false;}); break; } } @@ -86,12 +86,15 @@ public class CoreConnector { return null; } - private void handleTerm(TermStore store) { + private void handle_term(TermStore store) { unowned Erl.Term term = store.term; Erl.Term match_term; if((match_term = match("{roster_update,JID,Name,Subscription,Groups,Resources}", term)) != null) { Erl.Term jid_term = match_term.var_content("JID"); + if(!jid_term.is_binary()) + // TODO Debug output + return; string jid = ((string)jid_term.bin_ptr()).ndup(jid_term.bin_size()); Erl.Term name_term = match_term.var_content("Name"); @@ -101,7 +104,54 @@ public class CoreConnector { else name = null; - roster.update_contact(new Contact(jid, name)); + Contact contact = new Contact(jid, name); + + Erl.Term resources = match_term.var_content("Resources"); + + while(resources.is_cons()) { + Erl.Term r; + + if((r = match("{Name,{resource_entry,Priority,Show,Status}}", resources.hd())) != null) { + Erl.Term rname_term = r.var_content("Name"); + Erl.Term prio_term = r.var_content("Priority"); + Erl.Term show_term = r.var_content("Show"); + Erl.Term status_term = r.var_content("Status"); + + if(rname_term.is_binary() && prio_term.is_integer() && show_term.is_atom()) { + string rname = ((string)rname_term.bin_ptr()).ndup(rname_term.bin_size()); + int prio = prio_term.int_value(); + + Contact.Show show = Contact.Show.UNDEFINED; + switch((string)show_term.atom_ptr()) { + case "online": + show = Contact.Show.ONLINE; + break; + case "away": + show = Contact.Show.AWAY; + break; + case "chat": + show = Contact.Show.CHAT; + break; + case "dnd": + show = Contact.Show.DND; + break; + case "xa": + show = Contact.Show.XA; + break; + } + + string? status = null; + if(status_term.is_binary()) + status = ((string)status_term.bin_ptr()).ndup(status_term.bin_size()); + + contact.update_resource(rname, new Contact.Resource(prio, show, status)); + } + } + + resources = resources.tl(); + } + + roster.update_contact(contact); } else { Erl.print_term(stdout, term); diff --git a/src/gui/Ephraim.vala b/src/gui/Ephraim.vala index 0b50ff4..998439d 100644 --- a/src/gui/Ephraim.vala +++ b/src/gui/Ephraim.vala @@ -24,6 +24,30 @@ public class Ephraim { unowned Gtk.TreeView rosterView = builder.get_object("Roster") as Gtk.TreeView; rosterView.set_model(roster); + rosterView.query_tooltip.connect((x, y, keyboard_tip, tooltip) => { + Gtk.TreeIter iter; + + if(!rosterView.get_tooltip_context(out x, out y, keyboard_tip, null, null, out iter)) + return false; + + Value value; + roster.get_value(iter, 0, out value); + + Contact? c = value.get_object() as Contact; + if(c == null) + return false; + + Gee.Map.Entry? r = c.get_resource_with_highest_priority(); + + if(r == null) + return false; + + tooltip.set_text("Resource: " + r.key); + + return true; + }); + rosterView.has_tooltip = true; + rosterView.append_column(new Gtk.TreeViewColumn.with_attributes("Contact", new CellRendererContact(), "contact", 0, null)); window.visible = true; -- cgit v1.2.3