]> cgit.babelmonkeys.de Git - jubjub.git/blob - src/core/main.m
Split GTK roster delegate into separate class
[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 connect];
32         [connection handleConnection];
33
34         [connection addDelegate: rosterDelegate];
35
36         roster = [[XMPPRoster alloc] initWithConnection: connection];
37         [roster addDelegate: rosterDelegate];
38         [roster addDelegate: self];
39
40         [ui startUIThread];
41 }
42
43 - (void)connection: (XMPPConnection*)conn_
44      wasBoundToJID: (XMPPJID*)jid
45 {
46         of_log(@"Bound to JID: %@", [jid fullJID]);
47
48         [roster requestRoster];
49 }
50
51 - (void)rosterWasReceived: (XMPPRoster*)roster
52 {
53         [connection sendStanza: [XMPPPresence presence]];
54 }
55
56 -  (void)connection: (XMPPConnection*)conn
57   didReceiveElement: (OFXMLElement*)element
58 {
59         of_log(@"In:  %@", element);
60 }
61
62 - (void)connection: (XMPPConnection*)conn
63     didSendElement: (OFXMLElement*)element
64 {
65         of_log(@"Out: %@", element);
66 }
67 @end