From e7980c8d1a40175b56fad21082291152e214825d Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Sun, 6 Jan 2013 20:15:01 +0100 Subject: [PATCH] Track current presence --- data/gtk/roster.ui | 2 +- src/core/JubChatClient.h | 2 ++ src/core/JubChatClient.m | 18 ++++++++++++++++-- src/gui/common/JubUI.h | 5 +++-- src/gui/gtk/JubGtkRosterUI.h | 3 +++ src/gui/gtk/JubGtkRosterUI.m | 37 +++++++++++++++++++++++++++++++++--- src/gui/gtk/JubGtkUI.m | 7 +++++++ 7 files changed, 66 insertions(+), 8 deletions(-) diff --git a/data/gtk/roster.ui b/data/gtk/roster.ui index 302ef0a..cde8b89 100644 --- a/data/gtk/roster.ui +++ b/data/gtk/roster.ui @@ -265,7 +265,7 @@ False PresenceListStore 0 - available + unavailable diff --git a/src/core/JubChatClient.h b/src/core/JubChatClient.h index bd418f4..a73082d 100644 --- a/src/core/JubChatClient.h +++ b/src/core/JubChatClient.h @@ -9,10 +9,12 @@ XMPPConnection *connection; XMPPRoster *roster; XMPPStreamManagement *streamManagement; + XMPPPresence *presence; id ui; } @property (readonly) XMPPConnection *connection; @property (readonly) XMPPRoster *roster; +@property (readonly) XMPPPresence *presence; @property (assign) id ui; - initWithConfig: (JubConfig*)config; diff --git a/src/core/JubChatClient.m b/src/core/JubChatClient.m index a31bdb5..d539d90 100644 --- a/src/core/JubChatClient.m +++ b/src/core/JubChatClient.m @@ -3,6 +3,7 @@ @implementation JubChatClient @synthesize connection; @synthesize roster; +@synthesize presence; @synthesize ui; - initWithConfig: (JubConfig*)config @@ -38,11 +39,12 @@ [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]); @@ -50,8 +52,20 @@ [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 diff --git a/src/gui/common/JubUI.h b/src/gui/common/JubUI.h index 05cacc1..5d76aad 100644 --- a/src/gui/common/JubUI.h +++ b/src/gui/common/JubUI.h @@ -1,8 +1,9 @@ -#import - @class JubChatClient; +@class XMPPPresence; @protocol JubUI - initWithClient: (JubChatClient*)client; - (void)startUIThread; +- (void)client: (JubChatClient*)client + didChangePresence: (XMPPPresence*)presence; @end diff --git a/src/gui/gtk/JubGtkRosterUI.h b/src/gui/gtk/JubGtkRosterUI.h index cfcdd47..be03945 100644 --- a/src/gui/gtk/JubGtkRosterUI.h +++ b/src/gui/gtk/JubGtkRosterUI.h @@ -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 diff --git a/src/gui/gtk/JubGtkRosterUI.m b/src/gui/gtk/JubGtkRosterUI.m index c27142f..90bad6f 100644 --- a/src/gui/gtk/JubGtkRosterUI.m +++ b/src/gui/gtk/JubGtkRosterUI.m @@ -1,10 +1,11 @@ +#import +#include + #import "JubGtkRosterUI.h" #import "JubGObjectMap.h" #import "JubGtkChatUI.h" #import "JubGtkHelper.h" -#include - 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 = [@"Status: " 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 diff --git a/src/gui/gtk/JubGtkUI.m b/src/gui/gtk/JubGtkUI.m index b70e3df..7aef46c 100644 --- a/src/gui/gtk/JubGtkUI.m +++ b/src/gui/gtk/JubGtkUI.m @@ -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 -- 2.39.5