summaryrefslogtreecommitdiffstats
path: root/src/gui/Ephraim.vala
blob: 50f83e1d91c4c6c6180b67862bf4a9d7d965ae61 (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
64
65
66
67
68
69
70
71
72
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.VBox rosterView  = builder.get_object("Roster") as Gtk.VBox;
    
    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);
    
    // FIXME
    string me = "/me";
    
    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, me, jid, contact.display_string);
        }
        else {
          conversations[jid] = new Conversation(conversationNotebook, me, jid, null);
        }
        
        conversations[jid].send_message.connect((type, message) => coreconn.send_message(jid, type, message));
      });
    
    coreconn.receive_message.connect((jid, type, message) => {
        if(!(jid in conversations))
          return;
        
        conversations[jid].receive_message(type, message);
      });
    coreconn.sent_message.connect((jid, type, message) => {
        if(!(jid in conversations))
          return;
        
        conversations[jid].sent_message(type, message);
      });
    
    //if(!coreconn.start())
    //  return 1;
    coreconn.start();
    
    window.visible = true;
    
    Gtk.main();
    
    coreconn.stop();
    
    return 0;
  }
}