]> cgit.babelmonkeys.de Git - jubjub.git/blob - src/core/main.m
Add a zxcv-like CLI frontend
[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         [_client.connection asyncConnectAndHandle];
40
41         [_ui startUIThread];
42 }
43
44 -  (void)connection: (XMPPConnection*)connection
45   didReceiveElement: (OFXMLElement*)element
46 {
47         of_log(@"In:  %@", element);
48 }
49
50 - (void)connection: (XMPPConnection*)connection
51     didSendElement: (OFXMLElement*)element
52 {
53         of_log(@"Out: %@", element);
54 }
55
56 -  (void)connection: (XMPPConnection*)connection
57   didThrowException: (id)e
58 {
59         @throw e;
60 }
61 @end