diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-06-25 04:36:06 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-06-25 04:36:06 +0200 |
commit | 3eb7e7688dea39fa83f41c1f9aba79a962ef1a15 (patch) | |
tree | 91d91bfb779f2d502d88af1e5dec53f5fab23905 /src/gui | |
parent | d5adf274c137bef22d5695d4a280e10068edcb0e (diff) | |
download | ephraim-3eb7e7688dea39fa83f41c1f9aba79a962ef1a15.tar ephraim-3eb7e7688dea39fa83f41c1f9aba79a962ef1a15.zip |
Create conversation tabs for new conversations
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/gui/Conversation.vala | 51 | ||||
-rw-r--r-- | src/gui/CoreConnector.vala | 17 | ||||
-rw-r--r-- | src/gui/Ephraim.vala | 24 | ||||
-rw-r--r-- | src/gui/Roster.vala | 8 |
5 files changed, 93 insertions, 8 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 6208e62..dc65a0c 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -6,6 +6,7 @@ vala_precompile(VALA_C "CellRendererContact.vala" "CellRendererPresence.vala" "Contact.vala" + "Conversation.vala" "CoreConnector.vala" "Roster.vala" PACKAGES diff --git a/src/gui/Conversation.vala b/src/gui/Conversation.vala new file mode 100644 index 0000000..321fba9 --- /dev/null +++ b/src/gui/Conversation.vala @@ -0,0 +1,51 @@ +public class Conversation { + private Gtk.Notebook conversations; + private Gtk.Widget widget; + private string jid; + private string display_name; + + + private class TabLabel : Gtk.HBox { + public TabLabel(string label) { + pack_start(new Gtk.Label(label), false, true, 0); + + Gtk.Button closeButton = new Gtk.Button(); + Gdk.Pixbuf closeImage = render_icon(Gtk.STOCK_CLOSE, (Gtk.IconSize)(-1), null); + //Gtk.Image closeImage = new Gtk.Image.from_stock(Gtk.STOCK_CLOSE, (Gtk.IconSize)4); + closeButton.image = new Gtk.Image.from_pixbuf(closeImage.scale_simple(16, 16, Gdk.InterpType.BILINEAR)); + //closeButton.width_request = 20; + closeButton.height_request = 20; + pack_end(closeButton, false, false, 0); + + show_all(); + } + } + + public Conversation(Gtk.Notebook conversations0, string jid0, string? display_name0) { + conversations = conversations0; + jid = jid0; + + if(display_name0 != null) + display_name = display_name0; + else + display_name = jid; + + Gtk.Builder builder = new Gtk.Builder(); + try { + builder.add_objects_from_file("ephraim.glade", {"Conversation"}); + } catch(Error e) { + + } + + widget = builder.get_object("Conversation") as Gtk.Widget; + unowned Gtk.Label title = builder.get_object("ConversationTitle") as Gtk.Label; + + title.set_text("Conversation with " + display_name); + + conversations.append_page(widget, new TabLabel(display_name)); + } + + ~Conversation() { + conversations.remove(widget); + } +} diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala index 9c492b7..18cef2d 100644 --- a/src/gui/CoreConnector.vala +++ b/src/gui/CoreConnector.vala @@ -6,7 +6,8 @@ public class CoreConnector { Erl.Connection con; Erl.Term self; - Roster roster; + public signal void update_contact(Contact contact); + public signal void new_conversation(string jid); private class TermStore { public Erl.Term term; @@ -16,9 +17,8 @@ public class CoreConnector { Erl.init(); } - public CoreConnector(Roster roster0) { + public CoreConnector() { running = false; - roster = roster0; } public bool start() { @@ -166,7 +166,16 @@ public class CoreConnector { } } - roster.update_contact(contact); + update_contact(contact); + } + else if((match_term = match("{new_conversation,JID}", 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()); + + new_conversation(jid); } else { Erl.print_term(stdout, term); diff --git a/src/gui/Ephraim.vala b/src/gui/Ephraim.vala index 5130247..9d3083c 100644 --- a/src/gui/Ephraim.vala +++ b/src/gui/Ephraim.vala @@ -4,16 +4,15 @@ public class Ephraim { Gtk.Builder builder = new Gtk.Builder(); try { - builder.add_from_file("ephraim.glade"); + builder.add_objects_from_file("ephraim.glade", {"MainWindow"}); } catch(Error e) { return 1; } Roster roster = new Roster(); - CoreConnector coreconn = new CoreConnector(roster); + CoreConnector coreconn = new CoreConnector(); - if(!coreconn.start()) - return 1; + coreconn.update_contact.connect(roster.update_contact); unowned Gtk.Window window = builder.get_object("MainWindow") as Gtk.Window; window.hide.connect(Gtk.main_quit); @@ -24,6 +23,23 @@ public class Ephraim { unowned Gtk.TreeView rosterView = builder.get_object("Roster") as Gtk.TreeView; rosterView.set_model(roster); + Gee.TreeMap<string, Conversation> conversations = new Gee.TreeMap<string, Conversation>(); + unowned Gtk.Notebook conversationNotebook = builder.get_object("Conversations") as Gtk.Notebook; + + coreconn.new_conversation.connect((jid) => { + Contact contact = roster.get_contact(jid); + + if(contact != null) { + conversations[jid] = new Conversation(conversationNotebook, jid, contact.display_string); + } + else { + conversations[jid] = new Conversation(conversationNotebook, jid, null); + } + }); + + if(!coreconn.start()) + return 1; + rosterView.query_tooltip.connect((x, y, keyboard_tip, tooltip) => { Gtk.TreeModel model; Gtk.TreeIter iter; diff --git a/src/gui/Roster.vala b/src/gui/Roster.vala index f25584c..72134e6 100644 --- a/src/gui/Roster.vala +++ b/src/gui/Roster.vala @@ -25,7 +25,15 @@ public class Roster : Object, Gtk.TreeModel { else row_changed(path, iter); } + + public Contact get_contact(string jid) { + string bareJID = jid.split("/", 2)[0]; + + stdout.printf("Getting Contact for %s\n", bareJID); + return entries[bareJID]; + } + public Type get_column_type (int index) { switch(index) { case 0: |