@implementation AppDelegate
- (void)applicationDidFinishLaunching
{
- ui = [[JubGtkUI alloc] init];
- id<XMPPRosterDelegate, XMPPConnectionDelegate> rosterDelegate =
- [ui rosterDelegate];
+ id<XMPPRosterDelegate, XMPPConnectionDelegate> rosterDelegate;
connection = [[XMPPConnection alloc] init];
[connection addDelegate: self];
connection.username = @"alice";
connection.password = @"test";
- [connection asyncConnectAndHandle];
+ ui = [[JubGtkUI alloc] initWithConnection: connection];
+ rosterDelegate = [ui rosterDelegate];
[connection addDelegate: rosterDelegate];
[roster addDelegate: rosterDelegate];
[roster addDelegate: self];
+ [connection asyncConnectAndHandle];
+
[ui startUIThread];
}
#import "JubGtkChatUI.h"
#import "JubGtkHelper.h"
+static gboolean roster_row_activated(GtkTreeView *tree_view, GtkTreePath *path,
+ GtkTreeViewColumn *column, gpointer data)
+{
+ JubGtkRosterUI *roster = data;
+ GtkTreeIter row_iter;
+ GtkTreeModel *tree_model;
+ gchar *jid_s;
+ XMPPJID *jid;
+ OFAutoreleasePool *pool;
+
+ tree_model = gtk_tree_view_get_model(tree_view);
+ gtk_tree_model_get_iter(tree_model, &row_iter, path);
+ gtk_tree_model_get(tree_model, &row_iter, 1, &jid_s, -1);
+
+ // This was a group row
+ if (!jid_s) return TRUE;
+
+ pool = [OFAutoreleasePool new];
+ jid = [XMPPJID JIDWithString: [OFString stringWithUTF8String: jid_s]];
+
+ [roster performSelectorOnMainThread: @selector(chatForJID:)
+ withObject: jid
+ waitUntilDone: NO];
+ [pool release];
+
+ return TRUE;
+}
+
static gboolean filter_roster_by_presence(GtkTreeModel *model,
GtkTreeIter *iter, gpointer data)
{
@implementation JubGtkRosterUI
- initWithBuilder: (GtkBuilder*)builder_
+ connection: (XMPPConnection*)connection_
{
self = [super init];
@try {
+ GtkTreeView *roster_view;
+
groupMap = [[OFMapTable alloc]
initWithKeyFunctions: keyFunctions
valueFunctions: rowRefFunctions];
contactMap = [[OFMutableDictionary alloc] init];
chatMap = [[OFMutableDictionary alloc] init];
presences = [[OFCountedSet alloc] init];
+ connection = [connection_ retain];
builder = g_object_ref(builder_);
gtk_tree_model_filter_set_visible_func(roster_filter,
filter_roster_by_presence, presences, NULL);
+
+ roster_view = GTK_TREE_VIEW(gtk_builder_get_object(builder,
+ "RosterTreeView"));
+
+ g_signal_connect(roster_view, "row_activated",
+ G_CALLBACK(roster_row_activated), self);
} @catch (id e) {
[self release];
@throw e;
[groupMap release];
[contactMap release];
[presences release];
+ [connection release];
if (roster_model)
g_object_unref(roster_model);
}
// FIXME: This needs to move somewhere else
-- (void)connection: (XMPPConnection*)connection
- didReceiveMessage: (XMPPMessage*)message
+- (JubGtkChatUI*)chatForJID: (XMPPJID*)jid
{
+ OFAutoreleasePool *pool = [OFAutoreleasePool new];
JubGtkChatUI *chat =
- [chatMap objectForKey: [message.from bareJID]];
+ [chatMap objectForKey: [jid bareJID]];
if (chat == nil) {
OFString * title = [@"Chat with " stringByAppendingString:
- [message.from bareJID]];
+ [jid bareJID]];
chat = [[[JubGtkChatUI alloc]
initWithTitle: title
closeBlock: ^{
- [chatMap removeObjectForKey:
- [message.from bareJID]];
+ [chatMap removeObjectForKey: [jid bareJID]];
}
sendBlock: ^(OFString *text) {
XMPPMessage *msg =
[XMPPMessage messageWithType: @"chat"];
- msg.to = message.from;
+ msg.to = jid;
msg.body = text;
[connection sendStanza: msg];
}
] autorelease];
[chatMap setObject: chat
- forKey: [message.from bareJID]];
+ forKey: [jid bareJID]];
}
+ [pool release];
+
+ return chat;
+}
+
+- (void)connection: (XMPPConnection*)connection
+ didReceiveMessage: (XMPPMessage*)message
+{
+ JubGtkChatUI *chat = [self chatForJID: message.from];
[chat addMessage: message.body
sender: [message.from bareJID]];
}