]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/core/main.m
Add basic config file support
[jubjub.git] / src / core / main.m
index e40a02f328fe7ed2b0ea14bd1420c0ac3a082e8b..9ec84951de2042dbace938b3e7411768e11e2efe 100644 (file)
@@ -2,9 +2,10 @@
 #import <ObjXMPP/ObjXMPP.h>
 
 #import "JubGtkUI.h"
+#import "JubConfig.h"
 
 @interface AppDelegate: OFObject
-    <OFApplicationDelegate, XMPPConnectionDelegate>
+    <OFApplicationDelegate, XMPPConnectionDelegate, XMPPRosterDelegate>
 {
        XMPPConnection *connection;
        XMPPRoster *roster;
@@ -17,20 +18,27 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 @implementation AppDelegate
 - (void)applicationDidFinishLaunching
 {
-       ui = [[JubGtkUI alloc] init];
+       id<XMPPRosterDelegate, XMPPConnectionDelegate> rosterDelegate;
+       JubConfig *config = [[JubConfig alloc] initWithFile: @"config.xml"];
 
        connection = [[XMPPConnection alloc] init];
        [connection addDelegate: self];
 
-       connection.domain = @"localhost";
-       connection.username = @"alice";
-       connection.password = @"test";
+       connection.domain = config.domain;
+       connection.server = config.server;
+       connection.username = config.username;
+       connection.password = config.password;
 
-       [connection connect];
-       [connection handleConnection];
+       ui = [[JubGtkUI alloc] initWithConnection: connection];
+       rosterDelegate = [ui rosterDelegate];
+
+       [connection addDelegate: rosterDelegate];
 
        roster = [[XMPPRoster alloc] initWithConnection: connection];
-       [roster addDelegate: [ui rosterDelegate]];
+       [roster addDelegate: rosterDelegate];
+       [roster addDelegate: self];
+
+       [connection asyncConnectAndHandle];
 
        [ui startUIThread];
 }
@@ -43,6 +51,11 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        [roster requestRoster];
 }
 
+- (void)rosterWasReceived: (XMPPRoster*)roster
+{
+       [connection sendStanza: [XMPPPresence presence]];
+}
+
 -  (void)connection: (XMPPConnection*)conn
   didReceiveElement: (OFXMLElement*)element
 {