]> cgit.babelmonkeys.de Git - jubjub.git/blob - src/core/main.m
Add User Avatar support
[jubjub.git] / src / core / main.m
1 #import <ObjFW/ObjFW.h>
2 #import <ObjXMPP/ObjXMPP.h>
3
4 #import "JubGtkUI.h"
5 #import "JubCLIUI.h"
6 #import "JubConfig.h"
7 #import "JubChatClient.h"
8
9 @interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
10 {
11         JubChatClient *_client;
12         id<JubUI> _ui;
13 }
14 @end
15
16 OF_APPLICATION_DELEGATE(AppDelegate)
17
18 @implementation AppDelegate
19 - (void)applicationDidFinishLaunching
20 {
21         JubConfig *config = [[[JubConfig alloc] initWithFile: @"config.xml"]
22             autorelease];
23
24         _client = [[JubChatClient alloc] initWithConfig: config];
25
26         if ([config.frontend isEqual: @"gtk"])
27                 _ui = [[JubGtkUI alloc] initWithClient: _client];
28         else if ([config.frontend isEqual: @"cli"])
29                 _ui = [[JubCLIUI alloc] initWithClient: _client];
30         else {
31                 [of_stderr writeFormat: @"Unknown frontend '%@', known "
32                     @"frontends are 'gtk' and 'cli'\n", config.frontend];
33                 [OFApplication terminate];
34         }
35
36         _client.ui = _ui;
37         [_client.connection addDelegate: self];
38
39         [_ui startUIThread];
40         [_client.connection asyncConnectAndHandle];
41 }
42
43 -  (void)connection: (XMPPConnection*)connection
44   didReceiveElement: (OFXMLElement*)element
45 {
46         of_log(@"In:  %@", element);
47 }
48
49 - (void)connection: (XMPPConnection*)connection
50     didSendElement: (OFXMLElement*)element
51 {
52         of_log(@"Out: %@", element);
53 }
54
55 -  (void)connection: (XMPPConnection*)connection
56   didThrowException: (id)e
57 {
58         @throw e;
59 }
60 @end