]> git.babelmonkeys.de Git - jubjub.git/commitdiff
Track current presence
authorFlorian Zeitz <florob@babelmonkeys.de>
Sun, 6 Jan 2013 19:15:01 +0000 (20:15 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Sun, 6 Jan 2013 19:15:01 +0000 (20:15 +0100)
data/gtk/roster.ui
src/core/JubChatClient.h
src/core/JubChatClient.m
src/gui/common/JubUI.h
src/gui/gtk/JubGtkRosterUI.h
src/gui/gtk/JubGtkRosterUI.m
src/gui/gtk/JubGtkUI.m

index 302ef0afd726a8628b067c367de8e16ddabd135b..cde8b89fcc380913f214205c0b4ea6ef8c523d56 100644 (file)
             <property name="can_focus">False</property>
             <property name="model">PresenceListStore</property>
             <property name="id_column">0</property>
-            <property name="active_id">available</property>
+            <property name="active_id">unavailable</property>
             <child>
               <object class="GtkCellRendererText" id="cellrenderertext3"/>
               <attributes>
index bd418f4315726c200b5aab3aa860da9a99268170..a73082dde1b475a5f77c7311594b7eee580578c3 100644 (file)
@@ -9,10 +9,12 @@
        XMPPConnection *connection;
        XMPPRoster *roster;
        XMPPStreamManagement *streamManagement;
+       XMPPPresence *presence;
        id<JubUI> ui;
 }
 @property (readonly) XMPPConnection *connection;
 @property (readonly) XMPPRoster *roster;
+@property (readonly) XMPPPresence *presence;
 @property (assign) id<JubUI> ui;
 
 - initWithConfig: (JubConfig*)config;
index a31bdb598efcaee9b881955bd58cb3b5d6961a93..d539d9025c615152e38e1cc832cfe6a3e4f7623d 100644 (file)
@@ -3,6 +3,7 @@
 @implementation JubChatClient
 @synthesize connection;
 @synthesize roster;
+@synthesize presence;
 @synthesize ui;
 
 - initWithConfig: (JubConfig*)config
        [roster release];
        [streamManagement release];
        [connection release];
+       [presence release];
 
        [super dealloc];
 }
 
-- (void)connection: (XMPPConnection*)conn_
+- (void)connection: (XMPPConnection*)connection_
      wasBoundToJID: (XMPPJID*)jid
 {
        of_log(@"Bound to JID: %@", [jid fullJID]);
        [roster requestRoster];
 }
 
+-   (void)connection: (XMPPConnection*)connection_
+  didReceivePresence: (XMPPPresence*)presence_
+{
+       if ([presence_.from isEqual: connection.JID]) {
+               [ui          client: self
+                 didChangePresence: presence_];
+               OF_SETTER(presence, presence_, YES, 0);
+       }
+}
+
 - (void)rosterWasReceived: (XMPPRoster*)roster
 {
-       [connection sendStanza: [XMPPPresence presence]];
+       XMPPPresence *pres = [XMPPPresence presence];
+       [pres addStatus: @"Hello from JubJub"];
+       [connection sendStanza: pres];
 }
 @end
index 05cacc1046f42066211a24b6344e483761c84dbd..5d76aadbec2ecc5c1cbbefb9e506df1089855528 100644 (file)
@@ -1,8 +1,9 @@
-#import <ObjXMPP/XMPPRoster.h>
-
 @class JubChatClient;
+@class XMPPPresence;
 
 @protocol JubUI
 - initWithClient: (JubChatClient*)client;
 - (void)startUIThread;
+-      (void)client: (JubChatClient*)client
+  didChangePresence: (XMPPPresence*)presence;
 @end
index cfcdd471f6cdc54bb714d968712d10a573fa830e..be0394596d0e719c131a64871cbe4172dfc0a4f3 100644 (file)
@@ -11,6 +11,7 @@
        GtkWidget *roster_window;
        GtkTreeStore *roster_model;
        GtkTreeModelFilter *roster_filter;
+       GtkComboBox *presence_combo;
        OFMapTable *groupMap;
        OFMutableDictionary *contactMap;
        OFMutableDictionary *chatMap;
@@ -20,4 +21,6 @@
 
 - initWithClient: (JubChatClient*)client;
 - (JubGtkChatUI*)chatForJID: (XMPPJID*)jid;
+-      (void)client: (JubChatClient*)client
+  didChangePresence: (XMPPPresence*)presence;
 @end
index c27142f2f68fa0bf4b697ae8c121fae2cbd3e704..90bad6fa50c53abd97a0c916afa7c816e5405610 100644 (file)
@@ -1,10 +1,11 @@
+#import <ObjXMPP/namespaces.h>
+#include <string.h>
+
 #import "JubGtkRosterUI.h"
 #import "JubGObjectMap.h"
 #import "JubGtkChatUI.h"
 #import "JubGtkHelper.h"
 
-#include <string.h>
-
 static void roster_row_activated(GtkTreeView *tree_view, GtkTreePath *path,
     GtkTreeViewColumn *column, gpointer data)
 {
@@ -86,7 +87,6 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
 
        @try {
                GtkTreeView *roster_view;
-               GtkComboBox *presence_combo;
                GtkBuilder *builder;
 
                groupMap = [[OFMapTable alloc]
@@ -362,4 +362,35 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
        }
 }
 
+-      (void)client: (JubChatClient*)client
+  didChangePresence: (XMPPPresence*)presence
+{
+       OFString *tooltip = @"";
+       OFString *show =
+           [[presence elementForName: @"show"
+                           namespace: XMPP_NS_CLIENT] stringValue];
+       OFString *status =
+           [[presence elementForName: @"status"
+                           namespace: XMPP_NS_CLIENT] stringValue];
+
+       if (status != nil)
+               tooltip = [@"<b>Status:</b> " stringByAppendingString: status];
+
+       // FIXME: Changing the active id will send another presence
+       g_idle_add_block(^{
+               if ([presence.type isEqual: @"unavailable"])
+                       gtk_combo_box_set_active_id(presence_combo,
+                           "unavailable");
+               else if (show == nil)
+                       gtk_combo_box_set_active_id(presence_combo,
+                           "available");
+               else
+                       gtk_combo_box_set_active_id(presence_combo,
+                           [show UTF8String]);
+
+
+               gtk_widget_set_tooltip_markup(GTK_WIDGET(presence_combo),
+                   [tooltip UTF8String]);
+       });
+}
 @end
index b70e3df923c0ea3c47fc5e3972bebf169de540bc..7aef46c052503fe510ebf1cdf74683c1ce3765b2 100644 (file)
@@ -49,4 +49,11 @@ void on_roster_window_destroy(GObject *object, gpointer user_data)
                return nil;
        }] start];
 }
+
+-      (void)client: (JubChatClient*)client
+  didChangePresence: (XMPPPresence*)presence
+{
+       [rosterUI    client: client
+         didChangePresence: presence];
+}
 @end