]> cgit.babelmonkeys.de Git - jubjub.git/blob - src/core/main.m
Add basic config file support
[jubjub.git] / src / core / main.m
1 #import <ObjFW/ObjFW.h>
2 #import <ObjXMPP/ObjXMPP.h>
3
4 #import "JubGtkUI.h"
5 #import "JubConfig.h"
6
7 @interface AppDelegate: OFObject
8     <OFApplicationDelegate, XMPPConnectionDelegate, XMPPRosterDelegate>
9 {
10         XMPPConnection *connection;
11         XMPPRoster *roster;
12         id<JubUI> ui;
13 }
14 @end
15
16 OF_APPLICATION_DELEGATE(AppDelegate)
17
18 @implementation AppDelegate
19 - (void)applicationDidFinishLaunching
20 {
21         id<XMPPRosterDelegate, XMPPConnectionDelegate> rosterDelegate;
22         JubConfig *config = [[JubConfig alloc] initWithFile: @"config.xml"];
23
24         connection = [[XMPPConnection alloc] init];
25         [connection addDelegate: self];
26
27         connection.domain = config.domain;
28         connection.server = config.server;
29         connection.username = config.username;
30         connection.password = config.password;
31
32         ui = [[JubGtkUI alloc] initWithConnection: connection];
33         rosterDelegate = [ui rosterDelegate];
34
35         [connection addDelegate: rosterDelegate];
36
37         roster = [[XMPPRoster alloc] initWithConnection: connection];
38         [roster addDelegate: rosterDelegate];
39         [roster addDelegate: self];
40
41         [connection asyncConnectAndHandle];
42
43         [ui startUIThread];
44 }
45
46 - (void)connection: (XMPPConnection*)conn_
47      wasBoundToJID: (XMPPJID*)jid
48 {
49         of_log(@"Bound to JID: %@", [jid fullJID]);
50
51         [roster requestRoster];
52 }
53
54 - (void)rosterWasReceived: (XMPPRoster*)roster
55 {
56         [connection sendStanza: [XMPPPresence presence]];
57 }
58
59 -  (void)connection: (XMPPConnection*)conn
60   didReceiveElement: (OFXMLElement*)element
61 {
62         of_log(@"In:  %@", element);
63 }
64
65 - (void)connection: (XMPPConnection*)conn
66     didSendElement: (OFXMLElement*)element
67 {
68         of_log(@"Out: %@", element);
69 }
70 @end