summaryrefslogtreecommitdiffstats
path: root/src/gui/Ephraim.vala
blob: b0e257189fd5edd191ac87f0a1f76a3957f2fd23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public class Ephraim {
  public static int main(string[] args) {
    Gtk.init(ref args);
    
    Gtk.Builder builder = new Gtk.Builder();
    try {
      builder.add_objects_from_file("ephraim.glade", {"MainWindow"});
    } catch(Error e) {
      return 1;
    }
    
    unowned Gtk.Window window = builder.get_object("MainWindow") as Gtk.Window;
    window.hide.connect(Gtk.main_quit);
    
    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;
    
    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);
    
    CoreConnector coreconn = new CoreConnector();
    
    roster.start_conversation.connect((jid) => coreconn.start_conversation(jid));
    
    coreconn.update_contact.connect(roster.update_contact);
    
    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);
        }
        
        conversations[jid].send_message.connect((type, message) => coreconn.send_message(jid, type, message));
      });
    
    coreconn.chat_message.connect((jid, type, from, message) => {
        if(!(jid in conversations.keys))
          return;
        
        conversations[jid].chat_message(type, from, message);
      });
    
    //if(!coreconn.start())
    //  return 1;
    coreconn.start();
    
    window.visible = true;
    
    Gtk.main();
    
    coreconn.stop();
    
    return 0;
  }
}