@interface JubChatClient : OFObject <XMPPConnectionDelegate, XMPPRosterDelegate>
{
- OFMutableDictionary *chatMap;
- XMPPConnection *connection;
- XMPPRoster *roster;
- XMPPStreamManagement *streamManagement;
- XMPPContactManager *contactManager;
- XMPPPresence *presence;
- id<JubUI> ui;
+ OFMutableDictionary *_chatMap;
+ XMPPConnection *_connection;
+ XMPPRoster *_roster;
+ XMPPStreamManagement *_streamManagement;
+ XMPPContactManager *_contactManager;
+ XMPPPresence *_presence;
+ id<JubUI> _ui;
}
@property (readonly) XMPPConnection *connection;
@property (readonly) XMPPRoster *roster;
#import "JubChatClient.h"
@implementation JubChatClient
-@synthesize connection;
-@synthesize roster;
-@synthesize contactManager;
-@synthesize presence;
-@synthesize ui;
+@synthesize connection = _connection;
+@synthesize roster = _roster;
+@synthesize contactManager = _contactManager;
+@synthesize presence = _presence;
+@synthesize ui = _ui;
- initWithConfig: (JubConfig*)config
{
self = [super init];
@try {
- chatMap = [[OFMutableDictionary alloc] init];
+ _chatMap = [[OFMutableDictionary alloc] init];
- connection = [XMPPConnection new];
- connection.username = config.username;
- connection.domain = config.domain;
- connection.server = config.server;
- connection.password = config.password;
- [connection addDelegate: self];
+ _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];
+ _roster = [[XMPPRoster alloc] initWithConnection: _connection];
+ [_roster addDelegate: self];
- contactManager = [[XMPPContactManager alloc]
- initWithConnection: connection
- roster: roster];
+ _contactManager = [[XMPPContactManager alloc]
+ initWithConnection: _connection
+ roster: _roster];
- streamManagement = [[XMPPStreamManagement alloc]
- initWithConnection: connection];
+ _streamManagement = [[XMPPStreamManagement alloc]
+ initWithConnection: _connection];
- [connection asyncConnectAndHandle];
+ [_connection asyncConnectAndHandle];
} @catch (id e) {
[self release];
@throw e;
- (void)dealloc
{
- [roster release];
- [contactManager release];
- [streamManagement release];
- [connection release];
- [presence release];
- [chatMap release];
+ [_roster release];
+ [_contactManager release];
+ [_streamManagement release];
+ [_connection release];
+ [_presence release];
+ [_chatMap release];
[super dealloc];
}
OFAutoreleasePool *pool = [OFAutoreleasePool new];
OFString *bareJID = [contact.rosterItem.JID bareJID];
- id<JubChatUI> chat = [chatMap objectForKey: bareJID];
+ id<JubChatUI> chat = [_chatMap objectForKey: bareJID];
if (chat == nil) {
OFString * title =
[@"Chat with " stringByAppendingString: bareJID];
- chat = [[[[ui chatUIClass] alloc]
+ chat = [[[[_ui chatUIClass] alloc]
initWithTitle: title
closeBlock: ^{
- [chatMap removeObjectForKey: bareJID];
+ [_chatMap removeObjectForKey: bareJID];
}
sendBlock: ^(OFString *text) {
XMPPMessage *msg =
[XMPPMessage messageWithType: @"chat"];
msg.body = text;
[contact sendMessage: msg
- connection: connection];
+ connection: _connection];
}
] autorelease];
- [chatMap setObject: chat
- forKey: bareJID];
+ [_chatMap setObject: chat
+ forKey: bareJID];
}
[pool release];
return chat;
}
-- (void)connection: (XMPPConnection*)connection_
+- (void)connection: (XMPPConnection*)connection
wasBoundToJID: (XMPPJID*)jid
{
of_log(@"Bound to JID: %@", [jid fullJID]);
- [roster requestRoster];
+ [_roster requestRoster];
}
-- (void)connection: (XMPPConnection*)connection_
- didReceivePresence: (XMPPPresence*)presence_
+- (void)connection: (XMPPConnection*)connection
+ didReceivePresence: (XMPPPresence*)presence
{
- if ([presence_.from isEqual: connection.JID]) {
- [ui client: self
- didChangePresence: presence_];
- OF_SETTER(presence, presence_, YES, 0);
+ if ([presence.from isEqual: connection.JID]) {
+ [_ui client: self
+ didChangePresence: presence];
+ OF_SETTER(_presence, presence, YES, 0);
}
}
{
XMPPPresence *pres = [XMPPPresence presence];
[pres setStatus: @"Hello from JubJub"];
- [connection sendStanza: pres];
+ [_connection sendStanza: pres];
}
@end
@interface JubConfig : OFObject
{
- OFString *domain, *server;
- OFString *username;
- OFString *password;
+ OFString *_domain, *_server;
+ OFString *_username;
+ OFString *_password;
}
@property (readonly) OFString *domain, *server;
@property (readonly) OFString *username;
#import "JubConfig.h"
@implementation JubConfig
-@synthesize domain, server;
-@synthesize username;
-@synthesize password;
+@synthesize domain = _domain;
+@synthesize server = _server;;
+@synthesize username = _username;
+@synthesize password = _password;
- initWithFile: (OFString*)file
{
// TODO: Add error handling for missing elements
of_log(@"Parsed file: %@", element);
- domain = [[[element
+ _domain = [[[element
elementForName: @"domain"
namespace: CONFIG_NS] stringValue] copy];
- server = [[[element
+ _server = [[[element
elementForName: @"server"
namespace: CONFIG_NS] stringValue] copy];
- username = [[[element
+ _username = [[[element
elementForName: @"username"
namespace: CONFIG_NS] stringValue] copy];
- password = [[[element
+ _password = [[[element
elementForName: @"password"
namespace: CONFIG_NS] stringValue] copy];
- (void)dealloc
{
- [domain release];
- [server release];
- [username release];
- [password release];
+ [_domain release];
+ [_server release];
+ [_username release];
+ [_password release];
[super dealloc];
}
@interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
{
- JubChatClient *client;
- id<JubUI> ui;
+ JubChatClient *_client;
+ id<JubUI> _ui;
}
@end
JubConfig *config = [[[JubConfig alloc] initWithFile: @"config.xml"]
autorelease];
- client = [[JubChatClient alloc] initWithConfig: config];
+ _client = [[JubChatClient alloc] initWithConfig: config];
- ui = [[JubGtkUI alloc] initWithClient: client];
+ _ui = [[JubGtkUI alloc] initWithClient: _client];
- client.ui = ui;
- [client.connection addDelegate: self];
+ _client.ui = _ui;
+ [_client.connection addDelegate: self];
- [ui startUIThread];
+ [_ui startUIThread];
}
-- (void)connection: (XMPPConnection*)conn
+- (void)connection: (XMPPConnection*)connection
didReceiveElement: (OFXMLElement*)element
{
of_log(@"In: %@", element);
}
-- (void)connection: (XMPPConnection*)conn
+- (void)connection: (XMPPConnection*)connection
didSendElement: (OFXMLElement*)element
{
of_log(@"Out: %@", element);
}
-- (void)connection: (XMPPConnection*)connection_
+- (void)connection: (XMPPConnection*)connection
didThrowException: (id)e
{
@throw e;
@interface JubGtkChatUI: OFObject <JubChatUI>
{
- GtkWidget *chat_window;
- GtkTextView *chat_view;
- GtkTextBuffer *chat_buffer;
- jub_send_block_t sendBlock;
- jub_close_block_t closeBlock;
- BOOL bufferEmpty;
+ GtkWidget *_chat_window;
+ GtkTextView *_chat_view;
+ GtkTextBuffer *_chat_buffer;
+ jub_send_block_t _sendBlock;
+ jub_close_block_t _closeBlock;
+ BOOL _bufferEmpty;
}
@end
@implementation JubGtkChatUI
- initWithTitle: (OFString*)title
- closeBlock: (jub_close_block_t)closeBlock_
- sendBlock: (jub_send_block_t)sendBlock_
+ closeBlock: (jub_close_block_t)closeBlock
+ sendBlock: (jub_send_block_t)sendBlock
{
self = [super init];
@try {
__block volatile BOOL initialized = NO;
- __block GtkWidget *chat_window_;
- __block GtkTextBuffer *chat_buffer_;
+ __block GtkWidget *chat_window;
+ __block GtkTextBuffer *chat_buffer;
- closeBlock = [closeBlock_ copy];
- sendBlock = [sendBlock_ copy];
- bufferEmpty = YES;
+ _closeBlock = [closeBlock copy];
+ _sendBlock = [sendBlock copy];
+ _bufferEmpty = YES;
g_idle_add_block(^{
GtkEntry *chat_entry;
gtk_builder_add_from_file(builder, "data/gtk/chat.ui",
NULL);
- chat_window_ = GTK_WIDGET(
+ chat_window = GTK_WIDGET(
gtk_builder_get_object(builder, "ChatWindow"));
- g_signal_connect(chat_window_, "destroy",
+ g_signal_connect(chat_window, "destroy",
G_CALLBACK(call_close_block), closeBlock);
- chat_view = GTK_TEXT_VIEW(
+ _chat_view = GTK_TEXT_VIEW(
gtk_builder_get_object(builder, "ChatTextView"));
- chat_buffer_ = gtk_text_view_get_buffer(chat_view);
- gtk_text_buffer_create_tag(chat_buffer_, "bold",
+ chat_buffer = gtk_text_view_get_buffer(_chat_view);
+ gtk_text_buffer_create_tag(chat_buffer, "bold",
"weight", PANGO_WEIGHT_BOLD, NULL);
chat_entry = GTK_ENTRY(
g_signal_connect(chat_entry, "key_release_event",
G_CALLBACK(call_send_block), send_params);
- gtk_window_set_title(GTK_WINDOW(chat_window_),
+ gtk_window_set_title(GTK_WINDOW(chat_window),
[title UTF8String]);
- gtk_widget_show(chat_window_);
+ gtk_widget_show(chat_window);
initialized = YES;
while (!initialized);
- chat_buffer = chat_buffer_;
- chat_window = chat_window_;
+ _chat_buffer = chat_buffer;
+ _chat_window = chat_window;
} @catch (id e) {
[self release];
@throw e;
- (void)dealloc
{
- gtk_widget_destroy(chat_window);
- [sendBlock release];
- [closeBlock release];
+ gtk_widget_destroy(_chat_window);
+ [_sendBlock release];
+ [_closeBlock release];
[super dealloc];
}
- (void)addMessage: (OFString*)text
sender: (OFString*)sender
{
- BOOL first = bufferEmpty;
- if (OF_UNLIKELY(bufferEmpty)) bufferEmpty = NO;
+ BOOL first = _bufferEmpty;
+ if (OF_UNLIKELY(_bufferEmpty)) _bufferEmpty = NO;
g_idle_add_block(^{
GtkTextIter end_iter;
GtkTextMark *insert_mark =
- gtk_text_buffer_get_insert(chat_buffer);
+ gtk_text_buffer_get_insert(_chat_buffer);
if (OF_LIKELY(!first))
- gtk_text_buffer_insert_at_cursor(chat_buffer, "\n", 1);
+ gtk_text_buffer_insert_at_cursor(_chat_buffer, "\n", 1);
- gtk_text_buffer_get_end_iter(chat_buffer, &end_iter);
- gtk_text_buffer_insert_with_tags_by_name(chat_buffer, &end_iter,
- [sender UTF8String], [sender UTF8StringLength], "bold",
- NULL);
- gtk_text_buffer_get_end_iter(chat_buffer, &end_iter);
- gtk_text_buffer_insert_with_tags_by_name(chat_buffer, &end_iter,
- ": ", 2, "bold", NULL);
+ gtk_text_buffer_get_end_iter(_chat_buffer, &end_iter);
+ gtk_text_buffer_insert_with_tags_by_name(_chat_buffer,
+ &end_iter, [sender UTF8String], [sender UTF8StringLength],
+ "bold", NULL);
+ gtk_text_buffer_get_end_iter(_chat_buffer, &end_iter);
+ gtk_text_buffer_insert_with_tags_by_name(_chat_buffer,
+ &end_iter, ": ", 2, "bold", NULL);
- gtk_text_buffer_insert_at_cursor(chat_buffer, [text UTF8String],
- [text UTF8StringLength]);
+ gtk_text_buffer_insert_at_cursor(_chat_buffer,
+ [text UTF8String], [text UTF8StringLength]);
- gtk_text_view_scroll_to_mark(chat_view, insert_mark, 0,
+ gtk_text_view_scroll_to_mark(_chat_view, insert_mark, 0,
FALSE, 0, 0);
});
}
@interface JubGtkRosterUI: OFObject <XMPPContactManagerDelegate>
{
- GtkWidget *roster_window;
- GtkTreeStore *roster_model;
- GtkTreeModelFilter *roster_filter;
- GtkComboBox *presence_combo;
- gulong presence_combo_changed_handler_id;
- OFMapTable *groupMap;
- OFMutableDictionary *contactMap;
- JubChatClient *client;
+ GtkWidget *_roster_window;
+ GtkTreeStore *_roster_model;
+ GtkTreeModelFilter *_roster_filter;
+ GtkComboBox *_presence_combo;
+ gulong _presence_combo_changed_handler_id;
+ OFMapTable *_groupMap;
+ OFMutableDictionary *_contactMap;
+ JubChatClient *_client;
}
- initWithClient: (JubChatClient*)client;
}
@implementation JubGtkRosterUI
-- initWithClient: (JubChatClient*)client_
+- initWithClient: (JubChatClient*)client
{
self = [super init];
GtkTreeView *roster_view;
GtkBuilder *builder;
- groupMap = [[OFMapTable alloc]
+ _groupMap = [[OFMapTable alloc]
initWithKeyFunctions: keyFunctions
valueFunctions: rowRefFunctions];
- contactMap = [[OFMutableDictionary alloc] init];
- client = [client_ retain];
+ _contactMap = [[OFMutableDictionary alloc] init];
+ _client = [client retain];
- [client.contactManager addDelegate: self];
+ [_client.contactManager addDelegate: self];
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "data/gtk/roster.ui", NULL);
gtk_builder_connect_signals(builder, NULL);
- roster_window =
+ _roster_window =
GTK_WIDGET(gtk_builder_get_object(builder, "RosterWindow"));
- gtk_widget_show(roster_window);
+ gtk_widget_show(_roster_window);
- roster_model = GTK_TREE_STORE(gtk_builder_get_object(builder,
+ _roster_model = GTK_TREE_STORE(gtk_builder_get_object(builder,
"RosterTreeStore"));
- roster_filter = GTK_TREE_MODEL_FILTER(
+ _roster_filter = GTK_TREE_MODEL_FILTER(
gtk_builder_get_object(builder, "RosterTreeModelFilter"));
- gtk_tree_model_filter_set_visible_func(roster_filter,
+ gtk_tree_model_filter_set_visible_func(_roster_filter,
filter_roster_by_presence, NULL, NULL);
roster_view = GTK_TREE_VIEW(gtk_builder_get_object(builder,
g_signal_connect(roster_view, "row_activated",
G_CALLBACK(roster_row_activated), client);
- presence_combo = GTK_COMBO_BOX(gtk_builder_get_object(builder,
+ _presence_combo = GTK_COMBO_BOX(gtk_builder_get_object(builder,
"PresenceComboBox"));
- presence_combo_changed_handler_id =
- g_signal_connect(presence_combo, "changed",
+ _presence_combo_changed_handler_id =
+ g_signal_connect(_presence_combo, "changed",
G_CALLBACK(presence_changed), client.connection);
g_object_unref(G_OBJECT(builder));
- (void)dealloc
{
- [client.contactManager removeDelegate: self];
- [groupMap release];
- [contactMap release];
- [client release];
+ [_client.contactManager removeDelegate: self];
+ [_groupMap release];
+ [_contactMap release];
+ [_client release];
- gtk_widget_destroy(roster_window);
+ gtk_widget_destroy(_roster_window);
[super dealloc];
}
if (message.body == nil || ![message.type isEqual: @"chat"])
return;
- id<JubChatUI> chat = [client chatForContact: contact];
+ id<JubChatUI> chat = [_client chatForContact: contact];
[chat addMessage: message.body
sender: [message.from bareJID]];
}
OFString *bareJID = [item.JID bareJID];
OFMapTable *contactRows;
- if (!(contactRows = [contactMap objectForKey: bareJID])) {
+ if (!(contactRows = [_contactMap objectForKey: bareJID])) {
contactRows = [OFMapTable
mapTableWithKeyFunctions: keyFunctions
valueFunctions: rowRefFunctions];
- [contactMap setObject: contactRows
- forKey: bareJID];
+ [_contactMap setObject: contactRows
+ forKey: bareJID];
}
- group_ref = [groupMap valueForKey: group];
+ group_ref = [_groupMap valueForKey: group];
if (!group_ref) {
// Create new group row
- gtk_tree_store_append(roster_model, &group_iter, NULL);
- gtk_tree_store_set(roster_model, &group_iter,
+ gtk_tree_store_append(_roster_model, &group_iter, NULL);
+ gtk_tree_store_set(_roster_model, &group_iter,
0, [group UTF8String], -1);
group_path = gtk_tree_model_get_path(GTK_TREE_MODEL(
- roster_model), &group_iter);
+ _roster_model), &group_iter);
group_ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(
- roster_model), group_path);
+ _roster_model), group_path);
- [groupMap setValue: group_ref
- forKey: group];
+ [_groupMap setValue: group_ref
+ forKey: group];
} else {
// Get iter for existing group row
group_path = gtk_tree_row_reference_get_path(group_ref);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(roster_model),
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(_roster_model),
&group_iter, group_path);
}
gtk_tree_path_free(group_path);
// Create new contact row
- gtk_tree_store_append(roster_model, &contact_iter, &group_iter);
+ gtk_tree_store_append(_roster_model, &contact_iter,
+ &group_iter);
if (item.name)
- gtk_tree_store_set(roster_model, &contact_iter,
+ gtk_tree_store_set(_roster_model, &contact_iter,
0, [item.name UTF8String],
1, [bareJID UTF8String],
2, "unavailable", -1);
else if (item.JID.node)
- gtk_tree_store_set(roster_model, &contact_iter,
+ gtk_tree_store_set(_roster_model, &contact_iter,
0, [item.JID.node UTF8String],
1, [bareJID UTF8String],
2, "unavailable", -1);
else
- gtk_tree_store_set(roster_model, &contact_iter,
+ gtk_tree_store_set(_roster_model, &contact_iter,
0, [item.JID.domain UTF8String],
1, [bareJID UTF8String],
2, "unavailable", -1);
contact_path = gtk_tree_model_get_path(GTK_TREE_MODEL(
- roster_model), &contact_iter);
+ _roster_model), &contact_iter);
contact_ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(
- roster_model), contact_path);
+ _roster_model), contact_path);
gtk_tree_path_free(contact_path);
GtkTreePath *contact_path, *group_path;
GtkTreeRowReference *contact_ref, *group_ref;
OFString *bareJID = [item.JID bareJID];
- OFMapTable *contactRows = [contactMap objectForKey: bareJID];
+ OFMapTable *contactRows = [_contactMap objectForKey: bareJID];
contact_ref = [contactRows valueForKey: group];
contact_path = gtk_tree_row_reference_get_path(contact_ref);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(roster_model),
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(_roster_model),
&contact_iter, contact_path);
gtk_tree_path_free(contact_path);
- gtk_tree_store_remove(roster_model, &contact_iter);
+ gtk_tree_store_remove(_roster_model, &contact_iter);
- group_ref = [groupMap valueForKey: group];
+ group_ref = [_groupMap valueForKey: group];
group_path = gtk_tree_row_reference_get_path(group_ref);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(roster_model),
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(_roster_model),
&group_iter, group_path);
- if (!gtk_tree_model_iter_has_child(GTK_TREE_MODEL(roster_model),
- &group_iter)) {
- gtk_tree_store_remove(roster_model, &group_iter);
- [groupMap removeValueForKey: group];
+ if (!gtk_tree_model_iter_has_child(GTK_TREE_MODEL(
+ _roster_model), &group_iter)) {
+ gtk_tree_store_remove(_roster_model, &group_iter);
+ [_groupMap removeValueForKey: group];
}
gtk_tree_path_free(group_path);
[contactRows removeValueForKey: group];
if([contactRows count] == 0)
- [contactMap removeObjectForKey: bareJID];
+ [_contactMap removeObjectForKey: bareJID];
});
}
GtkTreePath *path;
GtkTreeRowReference *ref;
OFString *bareJID = [contact.rosterItem.JID bareJID];
- OFMapTable *contactRows = [contactMap objectForKey: bareJID];
+ OFMapTable *contactRows = [_contactMap objectForKey: bareJID];
for (OFString *group in contact.rosterItem.groups) {
ref = [contactRows valueForKey: group];
path = gtk_tree_row_reference_get_path(ref);
- gtk_tree_model_get_iter(GTK_TREE_MODEL(roster_model),
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(_roster_model),
&iter, path);
gtk_tree_path_free(path);
if ([highPresence.type isEqual: @"available"]) {
if (highPresence.show != nil)
- gtk_tree_store_set(roster_model, &iter,
+ gtk_tree_store_set(_roster_model, &iter,
2, [highPresence.show UTF8String],
-1);
else
- gtk_tree_store_set(roster_model, &iter,
+ gtk_tree_store_set(_roster_model, &iter,
2, "available", -1);
} else
- gtk_tree_store_set(roster_model, &iter,
+ gtk_tree_store_set(_roster_model, &iter,
2, "unavailable", -1);
- gtk_tree_store_set(roster_model, &iter,
+ gtk_tree_store_set(_roster_model, &iter,
3, [tooltip UTF8String], -1);
}
- gtk_tree_model_filter_refilter(roster_filter);
+ gtk_tree_model_filter_refilter(_roster_filter);
});
}
g_idle_add_block(^{
// Block the PresenceComboBox's changed handler, so it doesn't
// fire and resend presence
- g_signal_handler_block(presence_combo,
- presence_combo_changed_handler_id);
+ g_signal_handler_block(_presence_combo,
+ _presence_combo_changed_handler_id);
if ([presence.type isEqual: @"unavailable"])
- gtk_combo_box_set_active_id(presence_combo,
+ gtk_combo_box_set_active_id(_presence_combo,
"unavailable");
else if (show == nil)
- gtk_combo_box_set_active_id(presence_combo,
+ gtk_combo_box_set_active_id(_presence_combo,
"available");
else
- gtk_combo_box_set_active_id(presence_combo,
+ gtk_combo_box_set_active_id(_presence_combo,
[show UTF8String]);
// Unblock the changed handler
- g_signal_handler_unblock(presence_combo,
- presence_combo_changed_handler_id);
+ g_signal_handler_unblock(_presence_combo,
+ _presence_combo_changed_handler_id);
- gtk_widget_set_tooltip_markup(GTK_WIDGET(presence_combo),
+ gtk_widget_set_tooltip_markup(GTK_WIDGET(_presence_combo),
[tooltip UTF8String]);
});
}
@interface JubGtkUI: OFObject <JubUI>
{
- JubGtkRosterUI *rosterUI;
+ JubGtkRosterUI *_rosterUI;
}
@end
gtk_init(argc, argv);
- rosterUI = [[JubGtkRosterUI alloc]
+ _rosterUI = [[JubGtkRosterUI alloc]
initWithClient: client];
} @catch (id e) {
[self release];
- (void)dealloc
{
- [rosterUI release];
+ [_rosterUI release];
[super dealloc];
}
- (void)client: (JubChatClient*)client
didChangePresence: (XMPPPresence*)presence
{
- [rosterUI client: client
+ [_rosterUI client: client
didChangePresence: presence];
}
@end