]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/core/main.m
Add User Avatar support
[jubjub.git] / src / core / main.m
index 9ec84951de2042dbace938b3e7411768e11e2efe..6de6785be8ec4378c4dfaa02bff19294a789038d 100644 (file)
@@ -2,14 +2,14 @@
 #import <ObjXMPP/ObjXMPP.h>
 
 #import "JubGtkUI.h"
+#import "JubCLIUI.h"
 #import "JubConfig.h"
+#import "JubChatClient.h"
 
-@interface AppDelegate: OFObject
-    <OFApplicationDelegate, XMPPConnectionDelegate, XMPPRosterDelegate>
+@interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
 {
-       XMPPConnection *connection;
-       XMPPRoster *roster;
-       id<JubUI> ui;
+       JubChatClient *_client;
+       id<JubUI> _ui;
 }
 @end
 
@@ -18,53 +18,43 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 @implementation AppDelegate
 - (void)applicationDidFinishLaunching
 {
-       id<XMPPRosterDelegate, XMPPConnectionDelegate> rosterDelegate;
-       JubConfig *config = [[JubConfig alloc] initWithFile: @"config.xml"];
-
-       connection = [[XMPPConnection alloc] init];
-       [connection addDelegate: self];
-
-       connection.domain = config.domain;
-       connection.server = config.server;
-       connection.username = config.username;
-       connection.password = config.password;
-
-       ui = [[JubGtkUI alloc] initWithConnection: connection];
-       rosterDelegate = [ui rosterDelegate];
-
-       [connection addDelegate: rosterDelegate];
-
-       roster = [[XMPPRoster alloc] initWithConnection: connection];
-       [roster addDelegate: rosterDelegate];
-       [roster addDelegate: self];
-
-       [connection asyncConnectAndHandle];
-
-       [ui startUIThread];
+       JubConfig *config = [[[JubConfig alloc] initWithFile: @"config.xml"]
+           autorelease];
+
+       _client = [[JubChatClient alloc] initWithConfig: config];
+
+       if ([config.frontend isEqual: @"gtk"])
+               _ui = [[JubGtkUI alloc] initWithClient: _client];
+       else if ([config.frontend isEqual: @"cli"])
+               _ui = [[JubCLIUI alloc] initWithClient: _client];
+       else {
+               [of_stderr writeFormat: @"Unknown frontend '%@', known "
+                   @"frontends are 'gtk' and 'cli'\n", config.frontend];
+               [OFApplication terminate];
+       }
+
+       _client.ui = _ui;
+       [_client.connection addDelegate: self];
+
+       [_ui startUIThread];
+       [_client.connection asyncConnectAndHandle];
 }
 
-- (void)connection: (XMPPConnection*)conn_
-     wasBoundToJID: (XMPPJID*)jid
-{
-       of_log(@"Bound to JID: %@", [jid fullJID]);
-
-       [roster requestRoster];
-}
-
-- (void)rosterWasReceived: (XMPPRoster*)roster
-{
-       [connection sendStanza: [XMPPPresence presence]];
-}
-
--  (void)connection: (XMPPConnection*)conn
+-  (void)connection: (XMPPConnection*)connection
   didReceiveElement: (OFXMLElement*)element
 {
        of_log(@"In:  %@", element);
 }
 
-- (void)connection: (XMPPConnection*)conn
+- (void)connection: (XMPPConnection*)connection
     didSendElement: (OFXMLElement*)element
 {
        of_log(@"Out: %@", element);
 }
+
+-  (void)connection: (XMPPConnection*)connection
+  didThrowException: (id)e
+{
+       @throw e;
+}
 @end