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