]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/core/main.m
Add a minimal JubChatClient class and refactor other code to use it
[jubjub.git] / src / core / main.m
index 9ec84951de2042dbace938b3e7411768e11e2efe..659414bf349d4d2e886d0eb793b2956cbac51668 100644 (file)
@@ -3,12 +3,11 @@
 
 #import "JubGtkUI.h"
 #import "JubConfig.h"
+#import "JubChatClient.h"
 
-@interface AppDelegate: OFObject
-    <OFApplicationDelegate, XMPPConnectionDelegate, XMPPRosterDelegate>
+@interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
 {
-       XMPPConnection *connection;
-       XMPPRoster *roster;
+       JubChatClient *client;
        id<JubUI> ui;
 }
 @end
@@ -18,44 +17,19 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 @implementation AppDelegate
 - (void)applicationDidFinishLaunching
 {
-       id<XMPPRosterDelegate, XMPPConnectionDelegate> rosterDelegate;
-       JubConfig *config = [[JubConfig alloc] initWithFile: @"config.xml"];
+       JubConfig *config = [[[JubConfig alloc] initWithFile: @"config.xml"]
+           autorelease];
 
-       connection = [[XMPPConnection alloc] init];
-       [connection addDelegate: self];
+       client = [[JubChatClient alloc] initWithConfig: config];
 
-       connection.domain = config.domain;
-       connection.server = config.server;
-       connection.username = config.username;
-       connection.password = config.password;
+       ui = [[JubGtkUI alloc] initWithClient: client];
 
-       ui = [[JubGtkUI alloc] initWithConnection: connection];
-       rosterDelegate = [ui rosterDelegate];
-
-       [connection addDelegate: rosterDelegate];
-
-       roster = [[XMPPRoster alloc] initWithConnection: connection];
-       [roster addDelegate: rosterDelegate];
-       [roster addDelegate: self];
-
-       [connection asyncConnectAndHandle];
+       client.ui = ui;
+       [client.connection addDelegate: self];
 
        [ui startUIThread];
 }
 
-- (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
   didReceiveElement: (OFXMLElement*)element
 {