#import "JubGtkChatUI.h"
-
-struct add_text_params {
- OFString *name;
- OFString *text;
- GtkTextBuffer *buffer;
- BOOL first;
-};
-
-static gboolean add_text(gpointer data)
-{
- GtkTextIter endIter;
- struct add_text_params *params = data;
-
- if (OF_LIKELY(!params->first))
- gtk_text_buffer_insert_at_cursor(params->buffer, "\n", 1);
-
- gtk_text_buffer_get_end_iter(params->buffer, &endIter);
- gtk_text_buffer_insert_with_tags_by_name(params->buffer, &endIter,
- [params->name UTF8String], [params->name UTF8StringLength], "bold",
- NULL);
- gtk_text_buffer_get_end_iter(params->buffer, &endIter);
- gtk_text_buffer_insert_with_tags_by_name(params->buffer, &endIter,
- ": ", 2, "bold", NULL);
-
- gtk_text_buffer_insert_at_cursor(params->buffer,
- [params->text UTF8String], [params->text UTF8StringLength]);
-
- [params->name release];
- [params->text release];
- g_object_unref(params->buffer);
- free(params);
-
- return FALSE;
-}
+#import "JubGtkHelper.h"
struct call_send_block_params {
jub_send_block_t block;
self = [super init];
@try {
-
closeBlock = [closeBlock_ copy];
sendBlock = [sendBlock_ copy];
bufferEmpty = YES;
}
- (void)addMessage: (OFString*)text
- sender: (OFString*)sender;
+ sender: (OFString*)sender
{
- struct add_text_params *params = malloc(sizeof(*params));
- params->name = [sender retain];
- params->text = [text retain];
- params->buffer = g_object_ref(chat_buffer);
- params->first = bufferEmpty;
- g_idle_add(add_text, params);
+ BOOL first = bufferEmpty;
if (OF_UNLIKELY(bufferEmpty)) bufferEmpty = NO;
+
+ g_object_ref(chat_buffer);
+ g_idle_add_block(^{
+ GtkTextIter endIter;
+ if (OF_LIKELY(!first))
+ gtk_text_buffer_insert_at_cursor(chat_buffer, "\n", 1);
+
+ gtk_text_buffer_get_end_iter(chat_buffer, &endIter);
+ gtk_text_buffer_insert_with_tags_by_name(chat_buffer, &endIter,
+ [sender UTF8String], [sender UTF8StringLength], "bold",
+ NULL);
+ gtk_text_buffer_get_end_iter(chat_buffer, &endIter);
+ gtk_text_buffer_insert_with_tags_by_name(chat_buffer, &endIter,
+ ": ", 2, "bold", NULL);
+
+ gtk_text_buffer_insert_at_cursor(chat_buffer, [text UTF8String],
+ [text UTF8StringLength]);
+ g_object_unref(chat_buffer);
+ });
}
@end