]> git.babelmonkeys.de Git - jubjub.git/commitdiff
Open new chat windows when activating a roster row
authorFlorian Zeitz <florob@babelmonkeys.de>
Thu, 27 Dec 2012 01:52:33 +0000 (02:52 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Thu, 27 Dec 2012 01:52:33 +0000 (02:52 +0100)
src/core/main.m
src/gui/gtk/JubGtkRosterUI.h
src/gui/gtk/JubGtkRosterUI.m
src/gui/gtk/JubGtkUI.h
src/gui/gtk/JubGtkUI.m

index 62393b23ed964dd7e22bbdd2ed1fdba787a8908a..c01a5ccecfe3da16797eff965ab93177e74e0f93 100644 (file)
@@ -17,9 +17,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 @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];
@@ -28,7 +26,8 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        connection.username = @"alice";
        connection.password = @"test";
 
-       [connection asyncConnectAndHandle];
+       ui = [[JubGtkUI alloc] initWithConnection: connection];
+       rosterDelegate = [ui rosterDelegate];
 
        [connection addDelegate: rosterDelegate];
 
@@ -36,6 +35,8 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        [roster addDelegate: rosterDelegate];
        [roster addDelegate: self];
 
+       [connection asyncConnectAndHandle];
+
        [ui startUIThread];
 }
 
index 9bb08784326138f11a40f9c02b02134bc32d6852..1fd03946d4e626a6fd28f43ca2b67d6a23808af5 100644 (file)
@@ -2,6 +2,8 @@
 #import <ObjXMPP/ObjXMPP.h>
 #include <gtk/gtk.h>
 
+@class JubGtkChatUI;
+
 @interface JubGtkRosterUI: OFObject <XMPPRosterDelegate, XMPPConnectionDelegate>
 {
        GtkTreeStore *roster_model;
        OFMutableDictionary *contactMap;
        OFMutableDictionary *chatMap;
        OFCountedSet *presences;
+       XMPPConnection *connection;
        GtkBuilder *builder;
 }
-- initWithBuilder: (GtkBuilder*)builder;
+
+- initWithBuilder: (GtkBuilder*)builder
+       connection: (XMPPConnection*)connection;
+- (JubGtkChatUI*)chatForJID: (XMPPJID*)jid;
 @end
index 6fb8af0e86b62feb5ad72cea68c19693c73b4d36..7c81f9552f36e0728276ea3727b98e129162ebff 100644 (file)
@@ -3,6 +3,34 @@
 #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)
 {
@@ -32,16 +60,20 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
 
 @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_);
 
@@ -53,6 +85,12 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
 
                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;
@@ -66,6 +104,7 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
        [groupMap release];
        [contactMap release];
        [presences release];
+       [connection release];
 
        if (roster_model)
                g_object_unref(roster_model);
@@ -93,34 +132,42 @@ static gboolean filter_roster_by_presence(GtkTreeModel *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]];
 }
index a739e1a013d9c7ec0620f7b414b4ba3811cd9faf..add8d76c6fd72e5af0112e039061ff89af8418d3 100644 (file)
@@ -4,10 +4,13 @@
 #import "JubUI.h"
 
 @class JubGtkRosterUI;
+@class XMPPConnection;
 
 @interface JubGtkUI: OFObject <JubUI>
 {
        JubGtkRosterUI *rosterUI;
        GtkBuilder *builder;
 }
+
+- initWithConnection: (XMPPConnection*)connection;
 @end
index 000b483122d49402ab65fee6b73937354418c32b..26c2cbb978895d4f557942bb2b08ea4cd516b3b7 100644 (file)
@@ -10,7 +10,7 @@ void on_roster_window_destroy(GObject *object, gpointer user_data)
 }
 
 @implementation JubGtkUI
-- init
+- initWithConnection: (XMPPConnection*)connection
 {
        self = [super init];
 
@@ -26,7 +26,8 @@ void on_roster_window_destroy(GObject *object, gpointer user_data)
                builder = gtk_builder_new();
                gtk_builder_add_from_file(builder, "data/gtk/roster.ui", NULL);
 
-               rosterUI = [[JubGtkRosterUI alloc] initWithBuilder: builder];
+               rosterUI = [[JubGtkRosterUI alloc] initWithBuilder: builder
+                                                       connection: connection];
        } @catch (id e) {
                [self release];
                @throw e;