summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/CMakeLists.txt4
-rw-r--r--src/gui/CellRendererContact.vala13
-rw-r--r--src/gui/Contact.vala24
-rw-r--r--src/gui/CoreConnector.vala53
-rw-r--r--src/gui/Ephraim.vala14
-rw-r--r--src/gui/Roster.vala166
-rw-r--r--src/gui/ephraim.glade86
7 files changed, 264 insertions, 96 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 8839e16..d2a464c 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -2,9 +2,13 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ephraim_BINARY_DIR})
vala_precompile(VALA_C
"Ephraim.vala"
+ "CellRendererContact.vala"
+ "Contact.vala"
"CoreConnector.vala"
+ "Roster.vala"
PACKAGES
gtk+-2.0
+ gee-1.0
erl_interface
OPTIONS
--thread
diff --git a/src/gui/CellRendererContact.vala b/src/gui/CellRendererContact.vala
new file mode 100644
index 0000000..f8aa6a1
--- /dev/null
+++ b/src/gui/CellRendererContact.vala
@@ -0,0 +1,13 @@
+public class CellRendererContact : Gtk.CellRendererText {
+ private Contact _contact;
+
+ public Contact contact {
+ get {
+ return _contact;
+ }
+ set {
+ _contact = value;
+ text = contact.jid;
+ }
+ }
+}
diff --git a/src/gui/Contact.vala b/src/gui/Contact.vala
new file mode 100644
index 0000000..2eb40ae
--- /dev/null
+++ b/src/gui/Contact.vala
@@ -0,0 +1,24 @@
+public class Contact : Object {
+ public enum Show {
+ ONLINE, AWAY, CHAT, DND, XA, UNDEFINED
+ }
+
+ public enum Subscription {
+ BOTH
+ }
+
+ public Contact(string jid0) {
+ Object(jid: jid0);
+ }
+
+ public class Resource : Object {
+ public int priority {get; construct;}
+ public Show show {get; construct;}
+ public string status {get; construct;}
+ }
+
+ public string jid {get; construct;}
+ public Subscription subscription {get; set;}
+ public string name {get; set;}
+ public Gee.HashMap<string, Resource> resources {get; private set;}
+}
diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala
index 9edbc7d..fdd74ee 100644
--- a/src/gui/CoreConnector.vala
+++ b/src/gui/CoreConnector.vala
@@ -2,6 +2,12 @@ public class CoreConnector {
unowned Thread thread;
bool running;
+ Erl.Node node;
+ Erl.Connection con;
+ Erl.Term self;
+
+ Roster roster;
+
private class TermStore {
public Erl.Term term;
}
@@ -10,8 +16,9 @@ public class CoreConnector {
Erl.init();
}
- public CoreConnector() {
+ public CoreConnector(Roster roster0) {
running = false;
+ roster = roster0;
}
public bool start() {
@@ -20,6 +27,13 @@ public class CoreConnector {
running = true;
+ node = Erl.Node("ephraim-gtk", "magiccookie", 0);
+ con = node.connect("ephraim-core@avalon.local");
+
+ self = Erl.mk_self_pid(node);
+
+ con.reg_send("ephraim", Erl.format("{register_ui,~w}", self));
+
try {
thread = Thread.create(receive, true);
return true;
@@ -34,16 +48,12 @@ public class CoreConnector {
running = false;
thread.join();
+
+ con.reg_send("ephraim", Erl.format("{unregister_ui,~w}", self));
}
+
private void* receive() {
- Erl.Node node = Erl.Node("ephraim-gtk", "magiccookie", 0);
- Erl.Connection con = node.connect("ephraim-core@avalon.local");
-
- Erl.Term self = Erl.mk_self_pid(node);
-
- con.reg_send("ephraim", Erl.format("{register_ui,~w}", self));
-
while(running) {
TermStore response = new TermStore();
Erl.ReceiveType ret = con.receive(out response.term, 1000);
@@ -64,14 +74,31 @@ public class CoreConnector {
}
}
- con.reg_send("ephraim", Erl.format("{unregister_ui,~w}", self));
-
return null;
}
+ private Erl.Term? match(string pattern, Erl.Term term) {
+ Erl.Term pattern_term = Erl.format(pattern);
+
+ if(pattern_term.match(term) != 0)
+ return pattern_term;
+ else
+ return null;
+ }
+
private void handleTerm(TermStore store) {
- unowned Erl.Term term = store.term;
- Erl.print_term(stdout, term);
- stdout.printf("\n");
+ unowned Erl.Term term = store.term;
+ Erl.Term match_term;
+
+ if((match_term = match("{roster_update,JID,Resources}", term)) != null) {
+ Erl.Term JID_term = match_term.var_content("JID");
+ string JID = ((string)JID_term.bin_ptr()).ndup(JID_term.bin_size());
+
+ roster.update_contact(new Contact(JID));
+ }
+ else {
+ Erl.print_term(stdout, term);
+ stdout.printf("\n");
+ }
}
}
diff --git a/src/gui/Ephraim.vala b/src/gui/Ephraim.vala
index a52c4df..cf87965 100644
--- a/src/gui/Ephraim.vala
+++ b/src/gui/Ephraim.vala
@@ -9,14 +9,24 @@ public class Ephraim {
return 1;
}
- CoreConnector coreconn = new CoreConnector();
+ Roster roster = new Roster();
+ CoreConnector coreconn = new CoreConnector(roster);
if(!coreconn.start())
return 1;
unowned Gtk.Window window = builder.get_object("MainWindow") as Gtk.Window;
window.hide.connect(Gtk.main_quit);
- window.show();
+
+ unowned Gtk.MenuItem quitItem = builder.get_object("MenuItemQuit") as Gtk.MenuItem;
+ quitItem.activate.connect(() => window.visible = false);
+
+ unowned Gtk.TreeView rosterView = builder.get_object("Roster") as Gtk.TreeView;
+ rosterView.set_model(roster.get_default_group());
+
+ rosterView.append_column(new Gtk.TreeViewColumn.with_attributes("Contact", new CellRendererContact(), "contact", 0, null));
+
+ window.visible = true;
Gtk.main();
diff --git a/src/gui/Roster.vala b/src/gui/Roster.vala
new file mode 100644
index 0000000..2ef4618
--- /dev/null
+++ b/src/gui/Roster.vala
@@ -0,0 +1,166 @@
+public class Roster : Object {
+ private int stamp;
+ private Gee.TreeMap<string, Contact> entries = new Gee.TreeMap<string, Contact>();
+ private Gee.TreeMap<string, RosterGroup> groups = new Gee.TreeMap<string, RosterGroup>();
+
+
+ public Roster() {
+ stamp = 0;
+ groups["default"] = new RosterGroup(this);
+ }
+
+ public Gtk.TreeModel get_default_group() {
+ return groups["default"];
+ }
+
+ public void update_contact(Contact c) {
+ entries[c.jid] = c;
+ groups["default"].update_contact(c);
+ }
+
+ private class RosterGroup : Object, Gtk.TreeModel {
+ private unowned Roster roster {get; set;}
+ private Gee.TreeMap<string, Contact> entries = new Gee.TreeMap<string, Contact>();
+
+
+ public RosterGroup(Roster roster0) {
+ roster = roster0;
+ }
+
+ public void update_contact(Contact c) {
+ bool added = !entries.has_key(c.jid);
+
+ entries[c.jid] = c;
+
+ Gtk.TreeIter iter = Gtk.TreeIter();
+ iter.stamp = roster.stamp;
+ iter.user_data = this;
+ iter.user_data2 = c;
+
+ Gtk.TreePath path = get_path(iter);
+
+ if (added)
+ row_inserted(path, iter);
+ else
+ row_changed(path, iter);
+ }
+
+ public Type get_column_type (int index) {
+ switch(index) {
+ case 0:
+ return typeof(Contact);
+ }
+
+ return Type.INVALID;
+ }
+
+ public Gtk.TreeModelFlags get_flags () {
+ return Gtk.TreeModelFlags.LIST_ONLY;
+ }
+
+ public bool get_iter (out Gtk.TreeIter iter, Gtk.TreePath path) {
+ if(path.get_depth() != 1)
+ return false;
+
+ int index = path.get_indices()[0];
+ if(index < 0 || index >= entries.size)
+ return false;
+
+ Gee.MapIterator<string, Contact> it = entries.map_iterator();
+ it.first();
+ for(int i = 0; i < index; ++i)
+ it.next();
+
+ iter.stamp = roster.stamp;
+ iter.user_data = this;
+ iter.user_data2 = it.get_value();
+
+ return true;
+ }
+
+ public int get_n_columns () {
+ return 1;
+ }
+
+ public Gtk.TreePath get_path (Gtk.TreeIter iter) {
+ if(iter.stamp != roster.stamp || iter.user_data != this)
+ return (Gtk.TreePath)null;
+
+ int index = 0;
+
+ foreach(Contact c in entries.values) {
+ if(c == iter.user_data2)
+ break;
+
+ ++index;
+ }
+
+ return new Gtk.TreePath.from_indices(index, -1);
+ }
+
+ public void get_value (Gtk.TreeIter iter, int column, out Value value) {
+ if (column != 0 || iter.stamp != roster.stamp || iter.user_data != this)
+ return;
+
+ Contact c = iter.user_data2 as Contact;
+ value = Value(typeof(Contact));
+ value.take_object(c);
+ }
+
+ public bool iter_children (out Gtk.TreeIter iter, Gtk.TreeIter? parent) {
+ if (parent != null) {
+ iter.stamp = -1;
+ return false;
+ }
+
+ return get_iter(out iter, new Gtk.TreePath.from_indices(0, -1));
+ }
+
+ public bool iter_has_child (Gtk.TreeIter iter) {
+ return false;
+ }
+
+ public int iter_n_children (Gtk.TreeIter? iter) {
+ if (iter == null)
+ return entries.size;
+ else
+ return 0;
+ }
+
+ public bool iter_next (ref Gtk.TreeIter iter) {
+ if(iter.stamp != roster.stamp || iter.user_data != this)
+ return false;
+
+ bool next = false;
+ foreach(Contact c in entries.values) {
+ if(next) {
+ iter.user_data2 = c;
+ return true;
+ }
+
+ if(c == iter.user_data2)
+ next = true;
+ }
+
+ iter.stamp = -1;
+ return false;
+ }
+
+ public bool iter_nth_child (out Gtk.TreeIter iter, Gtk.TreeIter? parent, int n) {
+ if (parent != null) {
+ iter.stamp = -1;
+ return false;
+ }
+
+ return get_iter(out iter, new Gtk.TreePath.from_indices(n, -1));
+ }
+
+ public bool iter_parent (out Gtk.TreeIter iter, Gtk.TreeIter child) {
+ iter.stamp = -1;
+ return false;
+ }
+
+ public void ref_node (Gtk.TreeIter iter) {}
+ public void unref_node (Gtk.TreeIter iter) {}
+ }
+}
diff --git a/src/gui/ephraim.glade b/src/gui/ephraim.glade
index b1b3455..629e2de 100644
--- a/src/gui/ephraim.glade
+++ b/src/gui/ephraim.glade
@@ -13,50 +13,18 @@
<child>
<object class="GtkMenuItem" id="menuitem1">
<property name="visible">True</property>
- <property name="label" translatable="yes">_Datei</property>
+ <property name="label" translatable="yes">_Aktionen</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu1">
<property name="visible">True</property>
<child>
- <object class="GtkImageMenuItem" id="imagemenuitem1">
- <property name="label">gtk-new</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- <child>
- <object class="GtkImageMenuItem" id="imagemenuitem2">
- <property name="label">gtk-open</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- <child>
- <object class="GtkImageMenuItem" id="imagemenuitem3">
- <property name="label">gtk-save</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- <child>
- <object class="GtkImageMenuItem" id="imagemenuitem4">
- <property name="label">gtk-save-as</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- <child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
</object>
</child>
<child>
- <object class="GtkImageMenuItem" id="imagemenuitem5">
+ <object class="GtkImageMenuItem" id="MenuItemQuit">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
@@ -68,53 +36,9 @@
</object>
</child>
<child>
- <object class="GtkMenuItem" id="menuitem2">
- <property name="visible">True</property>
- <property name="label" translatable="yes">_Bearbeiten</property>
- <property name="use_underline">True</property>
- <child type="submenu">
- <object class="GtkMenu" id="menu2">
- <property name="visible">True</property>
- <child>
- <object class="GtkImageMenuItem" id="imagemenuitem6">
- <property name="label">gtk-cut</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- <child>
- <object class="GtkImageMenuItem" id="imagemenuitem7">
- <property name="label">gtk-copy</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- <child>
- <object class="GtkImageMenuItem" id="imagemenuitem8">
- <property name="label">gtk-paste</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- <child>
- <object class="GtkImageMenuItem" id="imagemenuitem9">
- <property name="label">gtk-delete</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
<object class="GtkMenuItem" id="menuitem3">
<property name="visible">True</property>
- <property name="label" translatable="yes">_Ansicht</property>
+ <property name="label" translatable="yes">A_nsicht</property>
<property name="use_underline">True</property>
</object>
</child>
@@ -148,11 +72,12 @@
<object class="GtkHPaned" id="RosterPane">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="position">160</property>
<child>
<object class="GtkTreeView" id="Roster">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="model">RosterStore</property>
+ <property name="headers_visible">False</property>
</object>
<packing>
<property name="resize">False</property>
@@ -196,5 +121,4 @@
</object>
</child>
</object>
- <object class="GtkListStore" id="RosterStore"/>
</interface>