diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/gui/ContactList.vala (renamed from src/gui/Roster.vala) | 98 | ||||
-rw-r--r-- | src/gui/Ephraim.vala | 2 |
3 files changed, 53 insertions, 49 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 42b7734..65ecbe7 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -4,9 +4,9 @@ vala_precompile(VALA_C "Ephraim.vala" "CellRendererContact.vala" "Contact.vala" + "ContactList.vala" "Conversation.vala" "CoreConnector.vala" - "Roster.vala" "String.vala" PACKAGES gtk+-2.0 diff --git a/src/gui/Roster.vala b/src/gui/ContactList.vala index ade3161..8696f93 100644 --- a/src/gui/Roster.vala +++ b/src/gui/ContactList.vala @@ -1,23 +1,23 @@ -public class Roster { - private Gtk.TreeView rosterView; +public class ContactList { + private Gtk.TreeView contactView; private ContactListModel contactList; - private RosterModel model; + private ContactGroupModel model; private Gee.Map<string, Gee.Map<string, Contact>> groups = new Gee.HashMap<string, Gee.Map<string, Contact>>(); public signal void start_conversation(string jid); - public Roster(Gtk.TreeView rosterView0) { - rosterView = rosterView0; + public ContactList(Gtk.TreeView contactView0) { + contactView = contactView0; contactList = new ContactListModel(this); - model = new RosterModel(contactList); + model = new ContactGroupModel(contactList); - rosterView.set_model(new RosterFilter(this, new RosterSorter(model))); + contactView.set_model(new ContactListFilter(this, new ContactListSorter(model))); - rosterView.query_tooltip.connect((x, y, keyboard_tip, tooltip) => { + contactView.query_tooltip.connect((x, y, keyboard_tip, tooltip) => { Gtk.TreeModel model; Gtk.TreeIter iter; - if(!rosterView.get_tooltip_context(out x, out y, keyboard_tip, out model, null, out iter)) + if(!contactView.get_tooltip_context(out x, out y, keyboard_tip, out model, null, out iter)) return false; Value value; @@ -36,9 +36,9 @@ public class Roster { return true; }); - rosterView.has_tooltip = true; + contactView.has_tooltip = true; - rosterView.row_activated.connect((view, path, column) => { + contactView.row_activated.connect((view, path, column) => { Gtk.TreeIter iter; view.model.get_iter(out iter, path); @@ -56,12 +56,12 @@ public class Roster { start_conversation(contact.jid + "/" + res.key); }); - rosterView.model.row_has_child_toggled.connect((path, iter) => { - rosterView.expand_row(path, true); + contactView.model.row_has_child_toggled.connect((path, iter) => { + contactView.expand_row(path, true); }); Gtk.TreeViewColumn contactColumn = new Gtk.TreeViewColumn.with_attributes(null, new CellRendererContact(), "data", 0, null); - rosterView.append_column(contactColumn); + contactView.append_column(contactColumn); } public void update_contact(Contact c) { @@ -88,7 +88,7 @@ public class Roster { return groups[group]; } - private class RosterModel : Object, Gtk.TreeModel { + private class ContactGroupModel : Object, Gtk.TreeModel { private int stamp = 0; private Gee.Map<String, Gtk.TreeModel> groupModels = new Gee.TreeMap<String, Gtk.TreeModel>(); private Gee.ArrayList<Gtk.TreeIter?> childIters = new Gee.ArrayList<Gtk.TreeIter?>(); @@ -100,7 +100,7 @@ public class Roster { childIters.clear(); } - public RosterModel(ContactListModel contactList0) { + public ContactGroupModel(ContactListModel contactList0) { contactList = contactList0; } @@ -246,7 +246,11 @@ public class Roster { assert_not_reached(); } - private long child_iter_index(Gtk.TreeIter iter) { + private int pointer_to_int(void* ptr) { + return (int)(long)ptr; + } + + private int child_iter_index(Gtk.TreeIter iter) { for(int index = 0; index < childIters.size; ++index) { if(childIters[index].stamp != iter.stamp) continue; @@ -264,14 +268,14 @@ public class Roster { return childIters.size-1; } - private Gtk.TreeIter get_nth_child_iter(long n) { - return childIters[(int)n]; + private Gtk.TreeIter get_nth_child_iter(int n) { + return childIters[n]; } private Gtk.TreeIter? get_child_iter(Gtk.TreeIter iter) { assert(iter.stamp == stamp && iter.user_data == this); - if((long)iter.user_data3 != -1) - return get_nth_child_iter((long)iter.user_data3); + if(pointer_to_int(iter.user_data3) != -1) + return get_nth_child_iter(pointer_to_int(iter.user_data3)); else return null; } @@ -311,7 +315,7 @@ public class Roster { iter.stamp = stamp; iter.user_data = this; iter.user_data2 = it.get_key(); - iter.user_data3 = (void*)(-1); + iter.user_data3 = (-1).to_pointer(); if(path.get_depth() > 1) { Gtk.TreePath subpath = new Gtk.TreePath(); @@ -324,7 +328,7 @@ public class Roster { if(!it.get_value().get_iter(out subiter, subpath)) return false; - iter.user_data3 = (void*)child_iter_index(subiter); + iter.user_data3 = child_iter_index(subiter).to_pointer(); } return true; @@ -348,7 +352,7 @@ public class Roster { Gtk.TreePath subpath = new Gtk.TreePath(); - if((long)iter.user_data3 != -1) { + if(pointer_to_int(iter.user_data3) != -1) { Gtk.TreeIter subiter = get_child_iter(iter); subpath = get_child_model(iter).get_path(subiter); } @@ -359,7 +363,7 @@ public class Roster { public void get_value(Gtk.TreeIter iter, int column, out Value value) { assert (column == 0 && iter.stamp == stamp && iter.user_data == this); - if((long)iter.user_data3 == -1) { + if(pointer_to_int(iter.user_data3) == -1) { value = Value(typeof(String)); value.take_object(iter.user_data2 as String); } @@ -382,7 +386,7 @@ public class Roster { iter.stamp = stamp; iter.user_data = this; iter.user_data2 = parent.user_data2; - iter.user_data3 = (void*)child_iter_index(childIter); + iter.user_data3 = child_iter_index(childIter).to_pointer(); return true; } @@ -405,7 +409,7 @@ public class Roster { public bool iter_next(ref Gtk.TreeIter iter) { assert(iter.stamp == stamp && iter.user_data == this); - if((long)iter.user_data3 == -1) { + if(pointer_to_int(iter.user_data3) == -1) { bool next = false; foreach(String group in groupModels.keys) { if(next) { @@ -429,7 +433,7 @@ public class Roster { return false; } - iter.user_data3 = (void*)child_iter_index(subiter); + iter.user_data3 = child_iter_index(subiter).to_pointer(); return true; } } @@ -448,7 +452,7 @@ public class Roster { public bool iter_parent(out Gtk.TreeIter iter, Gtk.TreeIter child) { assert(child.stamp == stamp && child.user_data == this); - if((long)child.user_data3 == -1) { + if(pointer_to_int(child.user_data3) == -1) { iter.stamp = -1; return false; } @@ -459,10 +463,10 @@ public class Roster { Gtk.TreeIter childParent; if(get_child_model(child).iter_parent(out childParent, get_child_iter(child))) { - iter.user_data3 = (void*)child_iter_index(childParent); + iter.user_data3 = child_iter_index(childParent).to_pointer(); } else { - iter.user_data3 = (void*)(-1); + iter.user_data3 = (-1).to_pointer(); } return true; @@ -473,13 +477,13 @@ public class Roster { } private class ContactListModel : Object, Gtk.TreeModel { - private unowned Roster roster; + private unowned ContactList contactList; private int stamp = 0; private Gee.TreeMap<string, Contact> entries = new Gee.TreeMap<string, Contact>(); - public ContactListModel(Roster roster0) { - roster = roster0; + public ContactListModel(ContactList contactList0) { + contactList = contactList0; } public void update_contact(Contact c) { @@ -489,12 +493,12 @@ public class Roster { added = false; foreach(string group in entries[c.jid].get_groups()) { - roster.groups[group].unset(c.jid); + contactList.groups[group].unset(c.jid); } } entries[c.jid] = c; - + Gtk.TreeIter iter = Gtk.TreeIter(); iter.stamp = stamp; iter.user_data = this; @@ -509,14 +513,14 @@ public class Roster { row_changed(path, iter); foreach(string group in c.get_groups()) { - if(!(group in roster.groups.keys)) { - roster.groups[group] = new Gee.HashMap<string, Contact>(); + if(!(group in contactList.groups.keys)) { + contactList.groups[group] = new Gee.HashMap<string, Contact>(); } - roster.groups[group][c.jid] = c; + contactList.groups[group][c.jid] = c; } - roster.update_groups(); + contactList.update_groups(); } public Contact get_contact(string jid) { @@ -664,16 +668,16 @@ public class Roster { } } - private class RosterFilter : Gtk.TreeModelFilter { - private unowned Roster roster; + private class ContactListFilter : Gtk.TreeModelFilter { + private unowned ContactList contactList; private bool show_contact(Contact c) { return (c.get_resource_with_highest_priority() != null); } - public RosterFilter(Roster roster0, Gtk.TreeModel childModel) { + public ContactListFilter(ContactList contactList0, Gtk.TreeModel childModel) { Object(child_model: childModel); - roster = roster0; + contactList = contactList0; set_visible_func((model, iter) => { Value value; @@ -688,7 +692,7 @@ public class Roster { assert(value.get_object() is String); string group = (value.get_object() as String).data; - foreach(Gee.Map.Entry<string, Contact> contact in roster.get_group(group)) { + foreach(Gee.Map.Entry<string, Contact> contact in contactList.get_group(group)) { if(show_contact(contact.value)) return true; } @@ -699,8 +703,8 @@ public class Roster { } } - private class RosterSorter : Gtk.TreeModelSort { - public RosterSorter(Gtk.TreeModel childModel) { + private class ContactListSorter : Gtk.TreeModelSort { + public ContactListSorter(Gtk.TreeModel childModel) { Object(model: childModel); set_sort_column_id(0, Gtk.SortType.ASCENDING); diff --git a/src/gui/Ephraim.vala b/src/gui/Ephraim.vala index b0e2571..5801966 100644 --- a/src/gui/Ephraim.vala +++ b/src/gui/Ephraim.vala @@ -20,7 +20,7 @@ public class Ephraim { Gee.TreeMap<string, Conversation> conversations = new Gee.TreeMap<string, Conversation>(); unowned Gtk.Notebook conversationNotebook = builder.get_object("Conversations") as Gtk.Notebook; - Roster roster = new Roster(rosterView); + ContactList roster = new ContactList(rosterView); CoreConnector coreconn = new CoreConnector(); |