comparison src/gtkconv.c @ 8677:cc2ce209cc46

[gaim-migrate @ 9430] marv's patch for GtkIMHtml. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 17 Apr 2004 13:58:29 +0000
parents 69a1b2a7a0d8
children b3b3384bc1e6
comparison
equal deleted inserted replaced
8676:e096d797d958 8677:cc2ce209cc46
272 c->bg_color.green / 256, 272 c->bg_color.green / 256,
273 c->bg_color.blue / 256); 273 c->bg_color.blue / 256);
274 gtk_imhtml_toggle_backcolor(GTK_IMHTML(c->entry), color); 274 gtk_imhtml_toggle_backcolor(GTK_IMHTML(c->entry), color);
275 g_free(color); 275 g_free(color);
276 } 276 }
277
278 if (gc->flags & GAIM_CONNECTION_FORMATTING_WBFO)
279 gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(c->entry), TRUE);
280 else
281 gtk_imhtml_set_whole_buffer_formatting_only(GTK_IMHTML(c->entry), FALSE);
277 } 282 }
278 } 283 }
279 284
280 static void 285 static void
281 send_cb(GtkWidget *widget, GaimConversation *conv) 286 send_cb(GtkWidget *widget, GaimConversation *conv)
282 { 287 {
283 GaimGtkConversation *gtkconv; 288 GaimGtkConversation *gtkconv;
284 GaimAccount *account; 289 GaimAccount *account;
290 GaimConnection *gc;
285 char *buf, *clean; 291 char *buf, *clean;
286 292
287 gtkconv = GAIM_GTK_CONVERSATION(conv); 293 gtkconv = GAIM_GTK_CONVERSATION(conv);
288 account = gaim_conversation_get_account(conv); 294 account = gaim_conversation_get_account(conv);
289 295
295 301
296 gtk_widget_grab_focus(gtkconv->entry); 302 gtk_widget_grab_focus(gtkconv->entry);
297 303
298 if (strlen(clean) == 0) { 304 if (strlen(clean) == 0) {
299 g_free(clean); 305 g_free(clean);
300 g_free(buf);
301 return; 306 return;
302 } 307 }
303 308
304 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) 309 gc = gaim_account_get_connection(account);
305 gaim_conv_im_send(GAIM_CONV_IM(conv), buf); 310 if (gc && (gc->flags & GAIM_CONNECTION_NO_NEWLINES)) {
306 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) 311 char **bufs;
307 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), buf); 312 int i;
313
314 bufs = gtk_imhtml_get_markup_lines(GTK_IMHTML(gtkconv->entry));
315 for (i = 0; bufs[i]; i++) {
316 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM)
317 gaim_conv_im_send(GAIM_CONV_IM(conv), bufs[i]);
318 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)
319 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), bufs[i]);
320 }
321
322 g_strfreev(bufs);
323
324 } else {
325 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM)
326 gaim_conv_im_send(GAIM_CONV_IM(conv), buf);
327 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)
328 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), buf);
329 }
308 330
309 if (gaim_prefs_get_bool("/gaim/gtk/conversations/im/hide_on_send")) 331 if (gaim_prefs_get_bool("/gaim/gtk/conversations/im/hide_on_send"))
310 gaim_conv_window_hide(gaim_conversation_get_window(conv)); 332 gaim_conv_window_hide(gaim_conversation_get_window(conv));
311 333
334 g_free(clean);
312 g_free(buf); 335 g_free(buf);
313 g_free(clean);
314 336
315 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); 337 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
316 default_formatize(conv); 338 default_formatize(conv);
317 } 339 }
318 340
1287 gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end); 1309 gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end);
1288 1310
1289 conv->send_history->data = 1311 conv->send_history->data =
1290 gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry)); 1312 gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry));
1291 } 1313 }
1292 1314
1293 if (conv->send_history->next && 1315 if (conv->send_history->next &&
1294 conv->send_history->next->data) { 1316 conv->send_history->next->data) {
1317 GtkTextIter iter;
1318 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
1295 1319
1296 conv->send_history = conv->send_history->next; 1320 conv->send_history = conv->send_history->next;
1297 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); 1321 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
1298 gtk_imhtml_append_text_with_images( 1322 gtk_imhtml_append_text_with_images(
1299 GTK_IMHTML(gtkconv->entry), conv->send_history->data, 1323 GTK_IMHTML(gtkconv->entry), conv->send_history->data,
1300 0, NULL); 1324 0, NULL);
1325 /* this is mainly just a hack so the formatting at the
1326 * cursor gets picked up. */
1327 gtk_text_buffer_get_end_iter(buffer, &iter);
1328 gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter);
1301 } 1329 }
1302 1330
1303 return TRUE; 1331 return TRUE;
1304 break; 1332 break;
1305 1333
1307 if (!conv->send_history) 1335 if (!conv->send_history)
1308 break; 1336 break;
1309 1337
1310 if (conv->send_history->prev && 1338 if (conv->send_history->prev &&
1311 conv->send_history->prev->data) { 1339 conv->send_history->prev->data) {
1340 GtkTextIter iter;
1341 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
1312 1342
1313 conv->send_history = conv->send_history->prev; 1343 conv->send_history = conv->send_history->prev;
1314 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); 1344 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
1315 gtk_imhtml_append_text_with_images( 1345 gtk_imhtml_append_text_with_images(
1316 GTK_IMHTML(gtkconv->entry), conv->send_history->data, 1346 GTK_IMHTML(gtkconv->entry), conv->send_history->data,
1317 0, NULL); 1347 0, NULL);
1348 /* this is mainly just a hack so the formatting at the
1349 * cursor gets picked up. */
1350 gtk_text_buffer_get_end_iter(buffer, &iter);
1351 gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter);
1318 } 1352 }
1319 1353
1320 return TRUE; 1354 return TRUE;
1321 break; 1355 break;
1322 1356
2327 } 2361 }
2328 2362
2329 /* Deal with the toolbar */ 2363 /* Deal with the toolbar */
2330 2364
2331 if (gc->flags & GAIM_CONNECTION_HTML) { 2365 if (gc->flags & GAIM_CONNECTION_HTML) {
2332 buttons = -1; /* Everything on */ 2366 buttons = GTK_IMHTML_ALL; /* Everything on */
2333 if (!(prpl_info->options & OPT_PROTO_IM_IMAGE)) 2367 if (!(prpl_info->options & OPT_PROTO_IM_IMAGE))
2334 buttons &= ~GTK_IMHTML_IMAGE; 2368 buttons &= ~GTK_IMHTML_IMAGE;
2335 if (gc->flags & GAIM_CONNECTION_NO_BGCOLOR) 2369 if (gc->flags & GAIM_CONNECTION_NO_BGCOLOR)
2336 buttons &= ~GTK_IMHTML_BACKCOLOR; 2370 buttons &= ~GTK_IMHTML_BACKCOLOR;
2337 } else { 2371 } else {
4497 } 4531 }
4498 4532
4499 if (flags & GAIM_MESSAGE_IMAGES) 4533 if (flags & GAIM_MESSAGE_IMAGES)
4500 gaim_gtk_find_images(message, &images); 4534 gaim_gtk_find_images(message, &images);
4501 4535
4536 if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml))))
4537 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", 0);
4538
4502 if(time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */ 4539 if(time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */
4503 strftime(mdate, sizeof(mdate), "%Y-%m-%d %H:%M:%S", localtime(&mtime)); 4540 strftime(mdate, sizeof(mdate), "%Y-%m-%d %H:%M:%S", localtime(&mtime));
4504 else 4541 else
4505 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); 4542 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime));
4506 4543
4647 with_font_tag = g_memdup(new_message, length); 4684 with_font_tag = g_memdup(new_message, length);
4648 4685
4649 gtk_imhtml_append_text_with_images(GTK_IMHTML(gtkconv->imhtml), 4686 gtk_imhtml_append_text_with_images(GTK_IMHTML(gtkconv->imhtml),
4650 with_font_tag, gtk_font_options, images); 4687 with_font_tag, gtk_font_options, images);
4651 4688
4652 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", 0); 4689 //gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", 0);
4653 4690
4654 conv->history = g_string_append(conv->history, buf); 4691 conv->history = g_string_append(conv->history, buf);
4655 conv->history = g_string_append(conv->history, new_message); 4692 conv->history = g_string_append(conv->history, new_message);
4656 conv->history = g_string_append(conv->history, "<BR>\n"); 4693 conv->history = g_string_append(conv->history, "<BR>\n");
4657 4694