--- /dev/null
+#import <ObjXMPP/ObjXMPP.h>
+#import <ObjFW/ObjFW.h>
+
+#import "JubUI.h"
+#import "JubConfig.h"
+
+@interface JubChatClient : OFObject <XMPPConnectionDelegate, XMPPRosterDelegate>
+{
+ XMPPConnection *connection;
+ XMPPRoster *roster;
+ XMPPStreamManagement *streamManagement;
+ id<JubUI> ui;
+}
+@property (readonly) XMPPConnection *connection;
+@property (readonly) XMPPRoster *roster;
+@property (assign) id<JubUI> ui;
+
+- initWithConfig: (JubConfig*)config;
+@end
--- /dev/null
+#import "JubChatClient.h"
+
+@implementation JubChatClient
+@synthesize connection;
+@synthesize roster;
+@synthesize ui;
+
+- initWithConfig: (JubConfig*)config
+{
+ self = [super init];
+
+ @try {
+ connection = [XMPPConnection new];
+
+ connection.username = config.username;
+ connection.domain = config.domain;
+ connection.server = config.server;
+ connection.password = config.password;
+ [connection addDelegate: self];
+
+ roster = [[XMPPRoster alloc] initWithConnection: connection];
+ [roster addDelegate: self];
+
+ streamManagement = [[XMPPStreamManagement alloc]
+ initWithConnection: connection];
+
+ [connection asyncConnectAndHandle];
+ } @catch (id e) {
+ [self release];
+ @throw e;
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [roster release];
+ [streamManagement release];
+ [connection release];
+
+ [super dealloc];
+}
+
+- (void)connection: (XMPPConnection*)conn_
+ wasBoundToJID: (XMPPJID*)jid
+{
+ of_log(@"Bound to JID: %@", [jid fullJID]);
+
+ [roster requestRoster];
+}
+
+- (void)rosterWasReceived: (XMPPRoster*)roster
+{
+ [connection sendStanza: [XMPPPresence presence]];
+}
+@end
STATIC_LIB_NOINST = core.a
SRCS = main.m \
+ JubChatClient.m \
JubConfig.m
include ../../buildsys.mk
#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
@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
{
#import <ObjXMPP/XMPPRoster.h>
+@class JubChatClient;
+
@protocol JubUI
+- initWithClient: (JubChatClient*)client;
- (void)startUIThread;
-- (id<XMPPRosterDelegate, XMPPConnectionDelegate>)rosterDelegate;
@end
#import <ObjXMPP/ObjXMPP.h>
#include <gtk/gtk.h>
+#import "JubChatClient.h"
+
@class JubGtkChatUI;
@interface JubGtkRosterUI: OFObject <XMPPRosterDelegate, XMPPConnectionDelegate>
XMPPConnection *connection;
}
-- initWithConnection: (XMPPConnection*)connection;
+- initWithClient: (JubChatClient*)client;
- (JubGtkChatUI*)chatForJID: (XMPPJID*)jid;
@end
}
@implementation JubGtkRosterUI
-- initWithConnection: (XMPPConnection*)connection_
+- initWithClient: (JubChatClient*)client;
{
self = [super init];
contactMap = [[OFMutableDictionary alloc] init];
chatMap = [[OFMutableDictionary alloc] init];
presences = [[OFCountedSet alloc] init];
- connection = [connection_ retain];
+ connection = [client.connection retain];
+
+ [connection addDelegate: self];
+ [client.roster addDelegate: self];
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "data/gtk/roster.ui", NULL);
{
JubGtkRosterUI *rosterUI;
}
-
-- initWithConnection: (XMPPConnection*)connection;
@end
}
@implementation JubGtkUI
-- initWithConnection: (XMPPConnection*)connection
+- initWithClient: (JubChatClient*)client;
{
self = [super init];
gtk_init(argc, argv);
rosterUI = [[JubGtkRosterUI alloc]
- initWithConnection: connection];
+ initWithClient: client];
} @catch (id e) {
[self release];
@throw e;
return nil;
}] start];
}
-
-- (id<XMPPRosterDelegate>)rosterDelegate
-{
- return rosterUI;
-}
@end
SRCS = JubGtkUI.m \
JubGtkChatUI.m \
JubGtkRosterUI.m \
- JubGtkHelper.m \
+ JubGtkHelper.m \
JubGObjectMap.m
include ../../../buildsys.mk
-CPPFLAGS += -I../common
+CPPFLAGS += -I../common -I../../core