Mercurial > pidgin
comparison src/conversation.c @ 4184:af2eeb7f7cf8
[gaim-migrate @ 4415]
Moves most of the logging functions into their own file, log.c.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Fri, 03 Jan 2003 07:53:15 +0000 |
| parents | cee489d38059 |
| children | 511c2b63caa4 |
comparison
equal
deleted
inserted
replaced
| 4183:e6810f691393 | 4184:af2eeb7f7cf8 |
|---|---|
| 298 } | 298 } |
| 299 g_free(cuser); | 299 g_free(cuser); |
| 300 return NULL; | 300 return NULL; |
| 301 } | 301 } |
| 302 | 302 |
| 303 /* --------------------------------------------------- | |
| 304 * Function to remove a log file entry | |
| 305 * --------------------------------------------------- | |
| 306 */ | |
| 307 | |
| 308 void rm_log(struct log_conversation *a) | |
| 309 { | |
| 310 struct conversation *cnv = find_conversation(a->name); | |
| 311 | |
| 312 log_conversations = g_list_remove(log_conversations, a); | |
| 313 | |
| 314 save_prefs(); | |
| 315 | |
| 316 if (cnv && !(im_options & OPT_IM_ONE_WINDOW)) | |
| 317 set_convo_title(cnv); | |
| 318 } | |
| 319 | |
| 320 struct log_conversation *find_log_info(const char *name) | |
| 321 { | |
| 322 char *pname = g_malloc(BUF_LEN); | |
| 323 GList *lc = log_conversations; | |
| 324 struct log_conversation *l; | |
| 325 | |
| 326 | |
| 327 strcpy(pname, normalize(name)); | |
| 328 | |
| 329 while (lc) { | |
| 330 l = (struct log_conversation *)lc->data; | |
| 331 if (!g_strcasecmp(pname, normalize(l->name))) { | |
| 332 g_free(pname); | |
| 333 return l; | |
| 334 } | |
| 335 lc = lc->next; | |
| 336 } | |
| 337 g_free(pname); | |
| 338 return NULL; | |
| 339 } | |
| 340 | |
| 341 void delete_conversation(struct conversation *c) | 303 void delete_conversation(struct conversation *c) |
| 342 { | 304 { |
| 343 plugin_event(event_del_conversation, c); | 305 plugin_event(event_del_conversation, c); |
| 344 conversations = g_list_remove(conversations, c); | 306 conversations = g_list_remove(conversations, c); |
| 345 if (c->fg_color_dialog) | 307 if (c->fg_color_dialog) |
| 369 g_source_remove(c->type_again_timeout); | 331 g_source_remove(c->type_again_timeout); |
| 370 g_string_free(c->history, TRUE); | 332 g_string_free(c->history, TRUE); |
| 371 g_free(c); | 333 g_free(c); |
| 372 } | 334 } |
| 373 | 335 |
| 374 void update_log_convs() | |
| 375 { | |
| 376 GSList *C = connections; | |
| 377 struct gaim_connection *g; | |
| 378 GSList *bcs; | |
| 379 GList *cnv = conversations; | |
| 380 struct conversation *c; | |
| 381 | |
| 382 while (cnv) { | |
| 383 c = (struct conversation *)cnv->data; | |
| 384 if (c->log_button) { | |
| 385 if (c->is_chat) | |
| 386 gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), | |
| 387 ((logging_options & OPT_LOG_CHATS)) ? FALSE : TRUE); | |
| 388 else | |
| 389 gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), | |
| 390 ((logging_options & OPT_LOG_CONVOS)) ? FALSE : TRUE); | |
| 391 } | |
| 392 | |
| 393 cnv = cnv->next; | |
| 394 } | |
| 395 | |
| 396 while (C) { | |
| 397 g = (struct gaim_connection *)C->data; | |
| 398 bcs = g->buddy_chats; | |
| 399 while (bcs) { | |
| 400 c = (struct conversation *)bcs->data; | |
| 401 if (c->log_button) { | |
| 402 if (c->is_chat) | |
| 403 gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), | |
| 404 ((logging_options & OPT_LOG_CHATS)) ? FALSE : | |
| 405 TRUE); | |
| 406 else | |
| 407 gtk_widget_set_sensitive(GTK_WIDGET(c->log_button), | |
| 408 ((logging_options & OPT_LOG_CONVOS)) ? FALSE : | |
| 409 TRUE); | |
| 410 } | |
| 411 | |
| 412 bcs = bcs->next; | |
| 413 } | |
| 414 C = C->next; | |
| 415 } | |
| 416 } | |
| 417 | |
| 418 void update_font_buttons() | 336 void update_font_buttons() |
| 419 { | 337 { |
| 420 GList *cnv = conversations; | 338 GList *cnv = conversations; |
| 421 struct conversation *c; | 339 struct conversation *c; |
| 422 | 340 |
| 481 { | 399 { |
| 482 if (state_lock) | 400 if (state_lock) |
| 483 return; | 401 return; |
| 484 | 402 |
| 485 c->makesound = !c->makesound; | 403 c->makesound = !c->makesound; |
| 486 } | |
| 487 | |
| 488 static void do_save_convo(GtkObject *obj, GtkWidget *wid) | |
| 489 { | |
| 490 struct conversation *c = gtk_object_get_user_data(obj); | |
| 491 const char *filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); | |
| 492 FILE *f; | |
| 493 if (file_is_dir(filename, wid)) | |
| 494 return; | |
| 495 if (!((!c->is_chat && g_list_find(conversations, c)) || | |
| 496 (c->is_chat && g_slist_find(connections, c->gc) && g_slist_find(c->gc->buddy_chats, c)))) | |
| 497 filename = NULL; | |
| 498 gtk_widget_destroy(wid); | |
| 499 if (!filename) | |
| 500 return; | |
| 501 f = fopen(filename, "w+"); | |
| 502 if (!f) | |
| 503 return; | |
| 504 fprintf(f, "%s", c->history->str); | |
| 505 fclose(f); | |
| 506 } | |
| 507 | |
| 508 void save_convo(GtkWidget *save, struct conversation *c) | |
| 509 { | |
| 510 char buf[BUF_LONG]; | |
| 511 GtkWidget *window = gtk_file_selection_new(_("Gaim - Save Conversation")); | |
| 512 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S "%s.log", gaim_home_dir(), normalize(c->name)); | |
| 513 gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); | |
| 514 gtk_object_set_user_data(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), c); | |
| 515 g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), | |
| 516 "clicked", G_CALLBACK(do_save_convo), window); | |
| 517 g_signal_connect_swapped(GTK_OBJECT(GTK_FILE_SELECTION(window)->cancel_button), | |
| 518 "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer)window); | |
| 519 gtk_widget_show(window); | |
| 520 } | 404 } |
| 521 | 405 |
| 522 static void do_insert_image(GtkObject *obj, GtkWidget *wid) | 406 static void do_insert_image(GtkObject *obj, GtkWidget *wid) |
| 523 { | 407 { |
| 524 struct conversation *c = gtk_object_get_user_data(obj); | 408 struct conversation *c = gtk_object_get_user_data(obj); |
| 1546 gtk_text_buffer_get_selection_bounds(c->entry_buffer, &start, &end); | 1430 gtk_text_buffer_get_selection_bounds(c->entry_buffer, &start, &end); |
| 1547 } | 1431 } |
| 1548 } | 1432 } |
| 1549 } | 1433 } |
| 1550 | 1434 |
| 1551 static char *html_logize(char *p) | |
| 1552 { | |
| 1553 | |
| 1554 char *temp_p = p; | |
| 1555 char *buffer_p; | |
| 1556 char *buffer_start; | |
| 1557 int num_cr = 0; | |
| 1558 int char_len = 0; | |
| 1559 | |
| 1560 while (*temp_p != '\0') { | |
| 1561 char_len++; | |
| 1562 if ((*temp_p == '\n') || ((*temp_p == '<') && (*(temp_p + 1) == '!'))) | |
| 1563 num_cr++; | |
| 1564 ++temp_p; | |
| 1565 } | |
| 1566 | |
| 1567 temp_p = p; | |
| 1568 buffer_p = g_malloc(char_len + (4 * num_cr) + 1); | |
| 1569 buffer_start = buffer_p; | |
| 1570 | |
| 1571 while (*temp_p != '\0') { | |
| 1572 if (*temp_p == '\n') { | |
| 1573 *buffer_p++ = '<'; | |
| 1574 *buffer_p++ = 'B'; | |
| 1575 *buffer_p++ = 'R'; | |
| 1576 *buffer_p++ = '>'; | |
| 1577 *buffer_p++ = '\n'; | |
| 1578 } else if ((*temp_p == '<') && (*(temp_p + 1) == '!')) { | |
| 1579 *buffer_p++ = '&'; | |
| 1580 *buffer_p++ = 'l'; | |
| 1581 *buffer_p++ = 't'; | |
| 1582 *buffer_p++ = ';'; | |
| 1583 } else | |
| 1584 *buffer_p++ = *temp_p; | |
| 1585 ++temp_p; | |
| 1586 } | |
| 1587 *buffer_p = '\0'; | |
| 1588 | |
| 1589 return buffer_start; | |
| 1590 } | |
| 1591 | |
| 1592 void surround(struct conversation *c, char *pre, char *post) | 1435 void surround(struct conversation *c, char *pre, char *post) |
| 1593 { | 1436 { |
| 1594 GtkTextIter start, end; | 1437 GtkTextIter start, end; |
| 1595 GtkTextMark *mark_start, *mark_end; | 1438 GtkTextMark *mark_start, *mark_end; |
| 1596 | 1439 |
