Mercurial > pidgin.yaz
comparison src/dialogs.c @ 7757:72727edb37ef
[gaim-migrate @ 8402]
More code cleanup. I removed the old logging dialog stuff from
dialogs.c, that was a nice chunk of code.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 05 Dec 2003 05:22:18 +0000 |
parents | 17deab169114 |
children | 0fb10479a6a3 |
comparison
equal
deleted
inserted
replaced
7756:17deab169114 | 7757:72727edb37ef |
---|---|
70 struct getuserinfo { | 70 struct getuserinfo { |
71 GtkWidget *window; | 71 GtkWidget *window; |
72 GtkWidget *entry; | 72 GtkWidget *entry; |
73 GtkWidget *account; | 73 GtkWidget *account; |
74 GaimConnection *gc; | 74 GaimConnection *gc; |
75 }; | |
76 | |
77 struct set_info_dlg { | |
78 GtkWidget *window; | |
79 GtkWidget *menu; | |
80 GaimAccount *account; | |
81 GtkWidget *text; | |
82 GtkWidget *save; | |
83 GtkWidget *cancel; | |
84 }; | 75 }; |
85 | 76 |
86 struct linkdlg { | 77 struct linkdlg { |
87 GtkWidget *ok; | 78 GtkWidget *ok; |
88 GtkWidget *cancel; | 79 GtkWidget *cancel; |
408 | 399 |
409 g_free(text); | 400 g_free(text); |
410 } | 401 } |
411 } | 402 } |
412 | 403 |
413 /*------------------------------------------------------------------------*/ | 404 static gboolean show_ee_dialog(const char *ee) |
414 /* The dialog for getting an error */ | |
415 /*------------------------------------------------------------------------*/ | |
416 static void do_im(GtkWidget *dialog, int id, struct getuserinfo *info) | |
417 { | |
418 const char *who; | |
419 GaimConversation *conv; | |
420 GaimAccount *account; | |
421 | |
422 switch(id) { | |
423 case GTK_RESPONSE_OK: | |
424 who = gtk_entry_get_text(GTK_ENTRY(info->entry)); | |
425 | |
426 if (!who || !*who) { | |
427 /* this shouldn't ever happen */ | |
428 return; | |
429 } | |
430 | |
431 account = (info->gc ? info->gc->account : NULL); | |
432 | |
433 conv = gaim_find_conversation_with_account(who, account); | |
434 | |
435 if (conv == NULL) | |
436 conv = gaim_conversation_new(GAIM_CONV_IM, account, who); | |
437 else | |
438 gaim_conv_window_raise(gaim_conversation_get_window(conv)); | |
439 break; | |
440 } | |
441 | |
442 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
443 g_free(info); | |
444 } | |
445 | |
446 static void do_info(GtkWidget *dialog, int id, struct getuserinfo *info) | |
447 { | |
448 char *who; | |
449 | |
450 switch(id) { | |
451 case GTK_RESPONSE_OK: | |
452 who = g_strdup(gaim_normalize(info->gc->account, gtk_entry_get_text(GTK_ENTRY(info->entry)))); | |
453 | |
454 if (!g_ascii_strcasecmp(who, "")) { | |
455 g_free(who); | |
456 return; | |
457 } | |
458 | |
459 /* what do we want to do about this case? */ | |
460 if (info->gc) | |
461 serv_get_info(info->gc, who); | |
462 g_free(who); | |
463 break; | |
464 } | |
465 | |
466 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
467 g_free(info); | |
468 } | |
469 | |
470 void show_ee_dialog(int ee) | |
471 { | 405 { |
472 GtkWidget *window; | 406 GtkWidget *window; |
473 GtkWidget *hbox; | 407 GtkWidget *hbox; |
474 GtkWidget *label; | 408 GtkWidget *label; |
475 GaimGtkBuddyList *gtkblist; | 409 GaimGtkBuddyList *gtkblist; |
476 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_COOL, GTK_ICON_SIZE_DIALOG); | 410 GtkWidget *img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_COOL, GTK_ICON_SIZE_DIALOG); |
411 gchar *norm = gaim_strreplace(ee, "rocksmyworld", ""); | |
477 | 412 |
478 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | 413 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); |
479 | 414 |
480 label = gtk_label_new(NULL); | 415 label = gtk_label_new(NULL); |
481 if (ee == 0) | 416 if (!strcmp(norm, "zilding")) |
482 gtk_label_set_markup(GTK_LABEL(label), | 417 gtk_label_set_markup(GTK_LABEL(label), |
483 "<span weight=\"bold\" size=\"large\" foreground=\"purple\">Amazing! Simply Amazing!</span>"); | 418 "<span weight=\"bold\" size=\"large\" foreground=\"purple\">Amazing! Simply Amazing!</span>"); |
484 else if (ee == 1) | 419 else if (!strcmp(norm, "robflynn")) |
485 gtk_label_set_markup(GTK_LABEL(label), | 420 gtk_label_set_markup(GTK_LABEL(label), |
486 "<span weight=\"bold\" size=\"large\" foreground=\"#1f6bad\">Pimpin\' Penguin Style! *Waddle Waddle*</span>"); | 421 "<span weight=\"bold\" size=\"large\" foreground=\"#1f6bad\">Pimpin\' Penguin Style! *Waddle Waddle*</span>"); |
487 else if (ee == 2) | 422 else if (!strcmp(norm, "flynorange")) |
488 gtk_label_set_markup(GTK_LABEL(label), | 423 gtk_label_set_markup(GTK_LABEL(label), |
489 "<span weight=\"bold\" size=\"large\" foreground=\"blue\">You should be me. I'm so cute!</span>"); | 424 "<span weight=\"bold\" size=\"large\" foreground=\"blue\">You should be me. I'm so cute!</span>"); |
490 else if (ee == 3) | 425 else if (!strcmp(norm, "ewarmenhoven")) |
491 gtk_label_set_markup(GTK_LABEL(label), | 426 gtk_label_set_markup(GTK_LABEL(label), |
492 "<span weight=\"bold\" size=\"large\" foreground=\"orange\">Now that's what I like!</span>"); | 427 "<span weight=\"bold\" size=\"large\" foreground=\"orange\">Now that's what I like!</span>"); |
493 else if (ee == 4) | 428 else if (!strcmp(norm, "markster97")) |
494 gtk_label_set_markup(GTK_LABEL(label), | 429 gtk_label_set_markup(GTK_LABEL(label), |
495 "<span weight=\"bold\" size=\"large\" foreground=\"brown\">Ahh, and excellent choice!</span>"); | 430 "<span weight=\"bold\" size=\"large\" foreground=\"brown\">Ahh, and excellent choice!</span>"); |
496 else if (ee == 5) | 431 else if (!strcmp(norm, "seanegn")) |
497 gtk_label_set_markup(GTK_LABEL(label), | 432 gtk_label_set_markup(GTK_LABEL(label), |
498 "<span weight=\"bold\" size=\"large\" foreground=\"#009900\">Everytime you click my name, an angel gets its wings.</span>"); | 433 "<span weight=\"bold\" size=\"large\" foreground=\"#009900\">Everytime you click my name, an angel gets its wings.</span>"); |
499 else if (ee == 6) | 434 else if (!strcmp(norm, "chipx86")) |
500 gtk_label_set_markup(GTK_LABEL(label), | 435 gtk_label_set_markup(GTK_LABEL(label), |
501 "<span weight=\"bold\" size=\"large\" foreground=\"red\">This sunflower seed taste like pizza.</span>"); | 436 "<span weight=\"bold\" size=\"large\" foreground=\"red\">This sunflower seed taste like pizza.</span>"); |
502 else if (ee == 7) | 437 else if (!strcmp(norm, "markdoliner")) |
503 gtk_label_set_markup(GTK_LABEL(label), | 438 gtk_label_set_markup(GTK_LABEL(label), |
504 "<span weight=\"bold\" size=\"large\" foreground=\"#6364B1\">Hey! I was in that tumbleweed!</span>"); | 439 "<span weight=\"bold\" size=\"large\" foreground=\"#6364B1\">Hey! I was in that tumbleweed!</span>"); |
505 else | 440 else if (!strcmp(norm, "lschiere")) |
506 gtk_label_set_markup(GTK_LABEL(label), | 441 gtk_label_set_markup(GTK_LABEL(label), |
507 "<span weight=\"bold\" size=\"large\" foreground=\"gray\">I'm not anything.</span>"); | 442 "<span weight=\"bold\" size=\"large\" foreground=\"gray\">I'm not anything.</span>"); |
443 g_free(norm); | |
444 | |
445 if (strlen(gtk_label_get_label(GTK_LABEL(label))) <= 0) | |
446 return FALSE; | |
508 | 447 |
509 window = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, GTK_WINDOW(gtkblist->window), 0, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); | 448 window = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, GTK_WINDOW(gtkblist->window), 0, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); |
510 gtk_dialog_set_default_response (GTK_DIALOG(window), GTK_RESPONSE_OK); | 449 gtk_dialog_set_default_response (GTK_DIALOG(window), GTK_RESPONSE_OK); |
511 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(gtk_widget_destroy), NULL); | 450 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(gtk_widget_destroy), NULL); |
512 | 451 |
523 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | 462 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
524 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 463 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
525 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | 464 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
526 | 465 |
527 gtk_widget_show_all(window); | 466 gtk_widget_show_all(window); |
467 return TRUE; | |
468 } | |
469 | |
470 static void do_im(GtkWidget *dialog, int id, struct getuserinfo *info) | |
471 { | |
472 const char *who; | |
473 GaimConversation *conv; | |
474 GaimAccount *account; | |
475 | |
476 switch(id) { | |
477 case GTK_RESPONSE_OK: | |
478 who = gtk_entry_get_text(GTK_ENTRY(info->entry)); | |
479 | |
480 if (who && *who) { | |
481 account = (info->gc ? info->gc->account : NULL); | |
482 | |
483 conv = gaim_find_conversation_with_account(who, account); | |
484 | |
485 if (conv == NULL) | |
486 conv = gaim_conversation_new(GAIM_CONV_IM, account, who); | |
487 else | |
488 gaim_conv_window_raise(gaim_conversation_get_window(conv)); | |
489 } | |
490 | |
491 break; | |
492 } | |
493 | |
494 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
495 g_free(info); | |
496 } | |
497 | |
498 static void do_info(GtkWidget *dialog, int id, struct getuserinfo *info) | |
499 { | |
500 char *who; | |
501 gboolean found = FALSE; | |
502 | |
503 switch(id) { | |
504 case GTK_RESPONSE_OK: | |
505 who = g_strdup(gaim_normalize(info->gc->account, gtk_entry_get_text(GTK_ENTRY(info->entry)))); | |
506 | |
507 if (who && gaim_str_has_suffix(who, "rocksmyworld")) { | |
508 found = show_ee_dialog(who); | |
509 } | |
510 | |
511 if (!found && who && *who && info->gc) | |
512 serv_get_info(info->gc, who); | |
513 | |
514 g_free(who); | |
515 break; | |
516 } | |
517 | |
518 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
519 g_free(info); | |
528 } | 520 } |
529 | 521 |
530 static void | 522 static void |
531 show_info_select_account(GObject *w, GaimAccount *account, | 523 show_info_select_account(GObject *w, GaimAccount *account, |
532 struct getuserinfo *info) | 524 struct getuserinfo *info) |
605 } | 597 } |
606 | 598 |
607 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(do_im), info); | 599 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(do_im), info); |
608 | 600 |
609 gtk_widget_show_all(window); | 601 gtk_widget_show_all(window); |
610 // if (info->entry) | 602 gtk_widget_grab_focus(GTK_WIDGET(info->entry)); |
611 gtk_widget_grab_focus(GTK_WIDGET(info->entry)); | |
612 } | 603 } |
613 | 604 |
614 void show_info_dialog() | 605 void show_info_dialog() |
615 { | 606 { |
616 GtkWidget *window, *hbox, *vbox; | 607 GtkWidget *window, *hbox, *vbox; |
681 } | 672 } |
682 | 673 |
683 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(do_info), info); | 674 g_signal_connect(G_OBJECT(window), "response", G_CALLBACK(do_info), info); |
684 | 675 |
685 gtk_widget_show_all(window); | 676 gtk_widget_show_all(window); |
686 // if (info->entry) | 677 gtk_widget_grab_focus(GTK_WIDGET(info->entry)); |
687 gtk_widget_grab_focus(GTK_WIDGET(info->entry)); | |
688 } | 678 } |
689 | 679 |
690 | 680 |
691 static void | 681 static void |
692 free_dialog(GtkWidget *w, void *data) | 682 free_dialog(GtkWidget *w, void *data) |
693 { | 683 { |
694 g_free(data); | 684 g_free(data); |
695 } | 685 } |
696 | |
697 /*------------------------------------------------------------------------*/ | |
698 /* The dialog for SET INFO / SET DIR INFO */ | |
699 /*------------------------------------------------------------------------*/ | |
700 | |
701 void do_save_info(GtkWidget *widget, struct set_info_dlg *b) | |
702 { | |
703 gchar *junk; | |
704 GaimConnection *gc; | |
705 | |
706 junk = gtk_text_view_get_text(GTK_TEXT_VIEW(b->text), FALSE); | |
707 | |
708 if (b->account) { | |
709 gaim_account_set_user_info(b->account, junk); | |
710 gc = b->account->gc; | |
711 | |
712 if (gc) | |
713 serv_set_info(gc, gaim_account_get_user_info(b->account)); | |
714 } | |
715 g_free(junk); | |
716 destroy_dialog(NULL, b->window); | |
717 g_free(b); | |
718 } | |
719 | |
720 void show_set_info(GaimConnection *gc) | |
721 { | |
722 GtkWidget *buttons; | |
723 GtkWidget *label; | |
724 GtkWidget *vbox; | |
725 GtkTextBuffer *buffer; | |
726 GtkWidget *frame; | |
727 gchar *buf; | |
728 GaimAccount *account; | |
729 const char *user_info; | |
730 | |
731 struct set_info_dlg *b = g_new0(struct set_info_dlg, 1); | |
732 account = gc->account; | |
733 b->account = account; | |
734 | |
735 GAIM_DIALOG(b->window); | |
736 gtk_window_set_role(GTK_WINDOW(b->window), "set_info"); | |
737 dialogwindows = g_list_prepend(dialogwindows, b->window); | |
738 gtk_window_set_title(GTK_WINDOW(b->window), _("Set User Info")); | |
739 g_signal_connect(G_OBJECT(b->window), "destroy", G_CALLBACK(destroy_dialog), b->window); | |
740 gtk_widget_realize(b->window); | |
741 | |
742 vbox = gtk_vbox_new(FALSE, 5); | |
743 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | |
744 gtk_container_add(GTK_CONTAINER(b->window), vbox); | |
745 | |
746 buf = g_malloc(256); | |
747 g_snprintf(buf, 256, _("Changing info for %s:"), | |
748 gaim_account_get_username(account)); | |
749 label = gtk_label_new(buf); | |
750 g_free(buf); | |
751 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5); | |
752 | |
753 frame = gtk_frame_new(NULL); | |
754 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
755 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); | |
756 | |
757 b->text = gtk_text_view_new(); | |
758 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(b->text), GTK_WRAP_WORD_CHAR); | |
759 | |
760 if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck")) | |
761 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(b->text)); | |
762 | |
763 gtk_widget_set_size_request(b->text, 300, 200); | |
764 | |
765 if ((user_info = gaim_account_get_user_info(account)) != NULL) { | |
766 buf = g_malloc(strlen(user_info) + 1); | |
767 gaim_strncpy_nohtml(buf, user_info, strlen(user_info) + 1); | |
768 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(b->text)); | |
769 gtk_text_buffer_set_text(buffer, buf, -1); | |
770 g_free(buf); | |
771 } | |
772 | |
773 gtk_container_add(GTK_CONTAINER(frame), b->text); | |
774 gtk_window_set_focus(GTK_WINDOW(b->window), b->text); | |
775 | |
776 buttons = gtk_hbox_new(FALSE, 5); | |
777 gtk_box_pack_start(GTK_BOX(vbox), buttons, FALSE, FALSE, 0); | |
778 | |
779 b->save = gaim_pixbuf_button_from_stock(_("Save"), GTK_STOCK_SAVE, GAIM_BUTTON_HORIZONTAL); | |
780 gtk_box_pack_end(GTK_BOX(buttons), b->save, FALSE, FALSE, 0); | |
781 g_signal_connect(G_OBJECT(b->save), "clicked", G_CALLBACK(do_save_info), b); | |
782 | |
783 b->cancel = gaim_pixbuf_button_from_stock(_("Cancel"), GTK_STOCK_CANCEL, GAIM_BUTTON_HORIZONTAL); | |
784 gtk_box_pack_end(GTK_BOX(buttons), b->cancel, FALSE, FALSE, 0); | |
785 g_signal_connect(G_OBJECT(b->cancel), "clicked", G_CALLBACK(destroy_dialog), b->window); | |
786 | |
787 gtk_widget_show_all(b->window); | |
788 } | |
789 | |
790 | 686 |
791 /*------------------------------------------------------*/ | 687 /*------------------------------------------------------*/ |
792 /* Link Dialog */ | 688 /* Link Dialog */ |
793 /*------------------------------------------------------*/ | 689 /*------------------------------------------------------*/ |
794 | 690 |
1655 fields, | 1551 fields, |
1656 _("OK"), G_CALLBACK(alias_buddy_cb), | 1552 _("OK"), G_CALLBACK(alias_buddy_cb), |
1657 _("Cancel"), NULL, | 1553 _("Cancel"), NULL, |
1658 b); | 1554 b); |
1659 } | 1555 } |
1660 | |
1661 static gboolean dont_destroy(gpointer a, gpointer b, gpointer c) | |
1662 { | |
1663 return TRUE; | |
1664 } | |
1665 | |
1666 static void do_save_log(GtkWidget *w, GtkWidget *filesel) | |
1667 { | |
1668 const char *file; | |
1669 char path[PATHSIZE]; | |
1670 char buf[BUF_LONG]; | |
1671 char error[BUF_LEN]; | |
1672 FILE *fp_old, *fp_new; | |
1673 char filename[PATHSIZE]; | |
1674 char *name; | |
1675 char *tmp; | |
1676 | |
1677 name = g_object_get_data(G_OBJECT(filesel), "name"); | |
1678 tmp = gaim_user_dir(); | |
1679 g_snprintf(filename, PATHSIZE, "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s%s", tmp, | |
1680 name ? gaim_normalize(NULL, name) : "system", name ? ".log" : ""); | |
1681 | |
1682 file = (const char*)gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel)); | |
1683 strncpy(path, file, PATHSIZE - 1); | |
1684 if (gaim_gtk_check_if_dir(path, GTK_FILE_SELECTION(filesel))) | |
1685 return; | |
1686 | |
1687 if ((fp_new = fopen(path, "w")) == NULL) { | |
1688 g_snprintf(error, BUF_LONG, | |
1689 _("Couldn't write to %s."), path); | |
1690 gaim_notify_error(NULL, NULL, error, strerror(errno)); | |
1691 return; | |
1692 } | |
1693 | |
1694 if ((fp_old = fopen(filename, "r")) == NULL) { | |
1695 g_snprintf(error, BUF_LONG, | |
1696 _("Couldn't write to %s."), filename); | |
1697 gaim_notify_error(NULL, NULL, error, strerror(errno)); | |
1698 fclose(fp_new); | |
1699 return; | |
1700 } | |
1701 | |
1702 while (fgets(buf, BUF_LONG, fp_old)) | |
1703 fputs(buf, fp_new); | |
1704 fclose(fp_old); | |
1705 fclose(fp_new); | |
1706 | |
1707 gtk_widget_destroy(filesel); | |
1708 | |
1709 return; | |
1710 } | |
1711 | |
1712 static void show_save_log(GtkWidget *w, gchar *name) | |
1713 { | |
1714 GtkWidget *filesel; | |
1715 gchar buf[BUF_LEN]; | |
1716 | |
1717 g_snprintf(buf, BUF_LEN - 1, "%s" G_DIR_SEPARATOR_S "%s%s", gaim_home_dir(), | |
1718 name ? gaim_normalize(NULL, name) : "system", name ? ".log" : ""); | |
1719 | |
1720 filesel = gtk_file_selection_new(_("Save Log File")); | |
1721 g_signal_connect(G_OBJECT(filesel), "delete_event", | |
1722 G_CALLBACK(destroy_dialog), filesel); | |
1723 | |
1724 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(filesel)); | |
1725 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), buf); | |
1726 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), | |
1727 "clicked", G_CALLBACK(do_save_log), filesel); | |
1728 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), | |
1729 "clicked", G_CALLBACK(destroy_dialog), filesel); | |
1730 g_object_set_data(G_OBJECT(filesel), "name", name); | |
1731 | |
1732 gtk_widget_realize(filesel); | |
1733 gtk_widget_show(filesel); | |
1734 | |
1735 return; | |
1736 } | |
1737 | |
1738 static void do_clear_log_file(struct view_log *view) | |
1739 { | |
1740 gchar *filename, *buf; | |
1741 char *tmp; | |
1742 | |
1743 tmp = gaim_user_dir(); | |
1744 filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s%s", tmp, | |
1745 view ? gaim_normalize(NULL, view->name) : "system", view ? ".log" : ""); | |
1746 | |
1747 if ((remove(filename)) == -1) { | |
1748 buf = g_strdup_printf(_("Couldn't remove file %s." ), filename); | |
1749 gaim_notify_error(NULL, NULL, buf, strerror(errno)); | |
1750 g_free(buf); | |
1751 } | |
1752 | |
1753 g_free(filename); | |
1754 | |
1755 if(view) | |
1756 gtk_widget_destroy(view->window); | |
1757 } | |
1758 | |
1759 static void show_clear_log(GtkWidget *w, struct view_log *view) | |
1760 { | |
1761 char *text; | |
1762 void *clear_handle; | |
1763 | |
1764 if ((view != NULL ) && (view->clear_handle != NULL)) | |
1765 return; | |
1766 | |
1767 text = g_strdup_printf(_("You are about to remove the log file for %s. Do you want to continue?"), | |
1768 view ? view->name : _("System Log")); | |
1769 clear_handle = gaim_request_action(NULL, NULL, _("Remove Log"), | |
1770 text, -1, view, 2, | |
1771 _("Remove Log"), | |
1772 G_CALLBACK(do_clear_log_file), | |
1773 _("Cancel"), NULL); | |
1774 if(view) | |
1775 view->clear_handle = clear_handle; | |
1776 g_free(text); | |
1777 } | |
1778 | |
1779 static void log_show_convo(struct view_log *view) | |
1780 { | |
1781 gchar buf[BUF_LONG]; | |
1782 FILE *fp; | |
1783 char filename[256]; | |
1784 int i=0; | |
1785 GString *string; | |
1786 guint block; | |
1787 | |
1788 string = g_string_new(""); | |
1789 | |
1790 if (view->name) { | |
1791 char *tmp = gaim_user_dir(); | |
1792 g_snprintf(filename, 256, "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s.log", tmp, gaim_normalize(NULL, view->name)); | |
1793 } else { | |
1794 char *tmp = gaim_user_dir(); | |
1795 g_snprintf(filename, 256, "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "system", tmp); | |
1796 } | |
1797 if ((fp = fopen(filename, "r")) == NULL) { | |
1798 if (view->name) { | |
1799 g_snprintf(buf, BUF_LONG, _("Couldn't open log file %s."), filename); | |
1800 gaim_notify_error(NULL, NULL, buf, strerror(errno)); | |
1801 } | |
1802 /* If the system log doesn't exist.. no message just show empty system log window. | |
1803 That way user knows that the log is empty :) | |
1804 */ | |
1805 return; | |
1806 } | |
1807 | |
1808 gtk_widget_set_sensitive(view->bbox, FALSE); | |
1809 g_signal_handlers_disconnect_by_func(G_OBJECT(view->window), | |
1810 G_CALLBACK(destroy_dialog), view->window); | |
1811 block = g_signal_connect(G_OBJECT(view->window), "delete_event", | |
1812 G_CALLBACK(dont_destroy), view->window); | |
1813 | |
1814 fseek(fp, view->offset, SEEK_SET); | |
1815 gtk_imhtml_clear(GTK_IMHTML(view->layout)); | |
1816 /* | |
1817 while (gtk_events_pending()) | |
1818 gtk_main_iteration(); | |
1819 */ | |
1820 | |
1821 while (fgets(buf, BUF_LONG, fp) && !strstr(buf, "---- New C")) { | |
1822 i++; | |
1823 if (strlen(buf) >= 5 && (!strncmp(buf + strlen(buf) - 5, "<BR>\n", 5))) | |
1824 /* take off the \n */ | |
1825 buf[strlen(buf) - 1] = '\0'; | |
1826 | |
1827 /* don't lose the thirtieth line of conversation. thanks FeRD */ | |
1828 g_string_append(string, buf); | |
1829 | |
1830 if (i == 30) { | |
1831 gtk_imhtml_append_text(GTK_IMHTML(view->layout), string->str, view->options); | |
1832 g_string_free(string, TRUE); | |
1833 string = g_string_new(""); | |
1834 /* you can't have these anymore. if someone clicks on another item while one is | |
1835 * drawing, it will try to move to that item, and that causes problems here. | |
1836 while (gtk_events_pending()) | |
1837 gtk_main_iteration(); | |
1838 */ | |
1839 i = 0; | |
1840 } | |
1841 | |
1842 } | |
1843 gtk_imhtml_append_text(GTK_IMHTML(view->layout), string->str, view->options); | |
1844 gtk_imhtml_append_text(GTK_IMHTML(view->layout), "<BR>", view->options); | |
1845 | |
1846 gtk_widget_set_sensitive(view->bbox, TRUE); | |
1847 g_signal_handler_disconnect(G_OBJECT(view->window), block); | |
1848 g_signal_connect(G_OBJECT(view->window), "delete_event", | |
1849 G_CALLBACK(destroy_dialog), view->window); | |
1850 g_string_free(string, TRUE); | |
1851 fclose(fp); | |
1852 } | |
1853 | |
1854 static void log_select_convo(GtkTreeSelection *sel, GtkTreeModel *model) | |
1855 { | |
1856 GValue val = { 0, }; | |
1857 GtkTreeIter iter; | |
1858 | |
1859 if(!gtk_tree_selection_get_selected(sel, &model, &iter)) | |
1860 return; | |
1861 gtk_tree_model_get_value(model, &iter, 1, &val); | |
1862 log_show_convo(g_value_get_pointer(&val)); | |
1863 } | |
1864 | |
1865 static void des_view_item(GtkObject *obj, struct view_log *view) | |
1866 { | |
1867 if (view->name) | |
1868 g_free(view->name); | |
1869 if (view->clear_handle) | |
1870 gaim_request_close(GAIM_REQUEST_ACTION, view->clear_handle); | |
1871 g_free(view); | |
1872 } | |
1873 | |
1874 static void des_log_win(GObject *win, gpointer data) | |
1875 { | |
1876 char *x = g_object_get_data(win, "log_window"); | |
1877 if (x) | |
1878 g_free(x); | |
1879 x = g_object_get_data(win, "name"); | |
1880 if (x) | |
1881 g_free(x); | |
1882 } | |
1883 | |
1884 | |
1885 static void | |
1886 url_clicked_cb(GtkWidget *widget, const char *uri) | |
1887 { | |
1888 gaim_notify_uri(NULL, uri); | |
1889 } | |
1890 | |
1891 void show_log(char *nm) | |
1892 { | |
1893 gchar filename[256]; | |
1894 gchar buf[BUF_LONG]; | |
1895 FILE *fp; | |
1896 GtkWidget *window; | |
1897 GtkWidget *box; | |
1898 GtkWidget *hbox; | |
1899 GtkWidget *bbox; | |
1900 GtkWidget *sw; | |
1901 GtkWidget *layout; | |
1902 GtkWidget *close_button; | |
1903 GtkWidget *clear_button; | |
1904 GtkWidget *save_button; | |
1905 GtkListStore *list_store; | |
1906 GtkWidget *tree_view; | |
1907 GtkTreeSelection *sel = NULL; | |
1908 GtkTreePath *path; | |
1909 GtkWidget *item = NULL; | |
1910 GtkWidget *last = NULL; | |
1911 GtkWidget *frame; | |
1912 struct view_log *view = NULL; | |
1913 char *name = nm ? g_strdup(nm) : NULL; | |
1914 | |
1915 int options; | |
1916 guint block; | |
1917 char convo_start[32]; | |
1918 long offset = 0; | |
1919 | |
1920 options = GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_TITLE | GTK_IMHTML_NO_SCROLL; | |
1921 | |
1922 if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_colors")) | |
1923 options ^= GTK_IMHTML_NO_COLOURS; | |
1924 | |
1925 if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_fonts")) | |
1926 options ^= GTK_IMHTML_NO_FONTS; | |
1927 | |
1928 if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_font_sizes")) | |
1929 options ^= GTK_IMHTML_NO_SIZES; | |
1930 | |
1931 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1932 g_object_set_data(G_OBJECT(window), "name", name); | |
1933 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(des_log_win), NULL); | |
1934 gtk_window_set_role(GTK_WINDOW(window), "log"); | |
1935 if (name) | |
1936 g_snprintf(buf, BUF_LONG, _("Conversations with %s"), name); | |
1937 else | |
1938 g_snprintf(buf, BUF_LONG, _("System Log")); | |
1939 gtk_window_set_title(GTK_WINDOW(window), buf); | |
1940 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
1941 gtk_window_set_resizable(GTK_WINDOW(window), TRUE); | |
1942 block = g_signal_connect(G_OBJECT(window), "delete_event", | |
1943 G_CALLBACK(dont_destroy), window); | |
1944 gtk_widget_realize(window); | |
1945 | |
1946 layout = gtk_imhtml_new(NULL, NULL); | |
1947 bbox = gtk_hbox_new(FALSE, 0); | |
1948 | |
1949 box = gtk_vbox_new(FALSE, 5); | |
1950 gtk_container_add(GTK_CONTAINER(window), box); | |
1951 | |
1952 hbox = gtk_hbox_new(FALSE, 5); | |
1953 gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, TRUE, 0); | |
1954 | |
1955 if (name) { | |
1956 char *tmp = gaim_user_dir(); | |
1957 g_snprintf(filename, 256, "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s.log", tmp, gaim_normalize(NULL, name)); | |
1958 if ((fp = fopen(filename, "r")) == NULL) { | |
1959 g_snprintf(buf, BUF_LONG, _("Couldn't open log file %s."), filename); | |
1960 gaim_notify_error(NULL, NULL, buf, strerror(errno)); | |
1961 return; | |
1962 } | |
1963 | |
1964 list_store = gtk_list_store_new(2, | |
1965 G_TYPE_STRING, | |
1966 G_TYPE_POINTER); | |
1967 | |
1968 tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store)); | |
1969 | |
1970 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), FALSE); | |
1971 | |
1972 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view), | |
1973 -1, "", gtk_cell_renderer_text_new(), "text", 0, NULL); | |
1974 | |
1975 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); | |
1976 g_signal_connect(G_OBJECT(sel), "changed", | |
1977 G_CALLBACK(log_select_convo), | |
1978 NULL); | |
1979 | |
1980 frame = gtk_frame_new(_("Date")); | |
1981 gtk_widget_show(frame); | |
1982 | |
1983 sw = gtk_scrolled_window_new(NULL, NULL); | |
1984 gtk_container_set_border_width(GTK_CONTAINER(sw), 5); | |
1985 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), tree_view); | |
1986 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
1987 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1988 gtk_widget_set_size_request(sw, 220, 220); | |
1989 gtk_container_add(GTK_CONTAINER(frame), sw); | |
1990 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); | |
1991 | |
1992 while (fgets(buf, BUF_LONG, fp)) { | |
1993 if (strstr(buf, "---- New C")) { | |
1994 int length; | |
1995 char *temp = strchr(buf, '@'); | |
1996 GtkTreeIter iter; | |
1997 | |
1998 if (temp == NULL || strlen(temp) < 2) | |
1999 continue; | |
2000 | |
2001 temp++; | |
2002 length = strcspn(temp, "-"); | |
2003 if (length > 31) length = 31; | |
2004 | |
2005 offset = ftell(fp); | |
2006 g_snprintf(convo_start, length, "%s", temp); | |
2007 gtk_list_store_append(list_store, &iter); | |
2008 view = g_new0(struct view_log, 1); | |
2009 view->options = options; | |
2010 view->offset = offset; | |
2011 view->name = g_strdup(name); | |
2012 view->bbox = bbox; | |
2013 view->window = window; | |
2014 view->layout = layout; | |
2015 gtk_list_store_set(list_store, &iter, | |
2016 0, convo_start, | |
2017 1, view, | |
2018 -1); | |
2019 g_signal_connect(G_OBJECT(window), "destroy", | |
2020 G_CALLBACK(des_view_item), view); | |
2021 last = item; | |
2022 } | |
2023 } | |
2024 fclose(fp); | |
2025 | |
2026 path = gtk_tree_path_new_first(); | |
2027 gtk_tree_selection_select_path(sel, path); | |
2028 gtk_tree_path_free(path); | |
2029 | |
2030 g_object_unref(G_OBJECT(list_store)); | |
2031 } | |
2032 | |
2033 | |
2034 g_signal_handler_disconnect(G_OBJECT(window), block); | |
2035 g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(destroy_dialog), window); | |
2036 | |
2037 frame = gtk_frame_new(_("Log")); | |
2038 gtk_widget_show(frame); | |
2039 | |
2040 sw = gtk_scrolled_window_new(NULL, NULL); | |
2041 gtk_container_set_border_width(GTK_CONTAINER(sw), 5); | |
2042 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
2043 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
2044 gtk_widget_set_size_request(sw, 390, 220); | |
2045 gtk_container_add(GTK_CONTAINER(frame), sw); | |
2046 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); | |
2047 | |
2048 g_signal_connect(G_OBJECT(layout), "url_clicked", | |
2049 G_CALLBACK(url_clicked_cb), NULL); | |
2050 gtk_container_add(GTK_CONTAINER(sw), layout); | |
2051 gaim_setup_imhtml(layout); | |
2052 | |
2053 gtk_box_pack_start(GTK_BOX(box), bbox, FALSE, FALSE, 0); | |
2054 gtk_widget_set_sensitive(bbox, FALSE); | |
2055 | |
2056 close_button = gaim_pixbuf_button_from_stock(_("Close"), GTK_STOCK_CLOSE, GAIM_BUTTON_HORIZONTAL); | |
2057 gtk_box_pack_end(GTK_BOX(bbox), close_button, FALSE, FALSE, 5); | |
2058 g_signal_connect(G_OBJECT(close_button), "clicked", G_CALLBACK(destroy_dialog), window); | |
2059 | |
2060 clear_button = gaim_pixbuf_button_from_stock(_("Clear"), GTK_STOCK_CLEAR, GAIM_BUTTON_HORIZONTAL); | |
2061 g_object_set_data(G_OBJECT(clear_button), "log_window", window); | |
2062 gtk_box_pack_end(GTK_BOX(bbox), clear_button, FALSE, FALSE, 5); | |
2063 g_signal_connect(G_OBJECT(clear_button), "clicked", G_CALLBACK(show_clear_log), view); | |
2064 | |
2065 save_button = gaim_pixbuf_button_from_stock(_("Save"), GTK_STOCK_SAVE, GAIM_BUTTON_HORIZONTAL); | |
2066 gtk_box_pack_end(GTK_BOX(bbox), save_button, FALSE, FALSE, 5); | |
2067 g_signal_connect(G_OBJECT(save_button), "clicked", G_CALLBACK(show_save_log), name); | |
2068 | |
2069 gtk_widget_show_all(window); | |
2070 | |
2071 if (!name) { | |
2072 view = g_new0(struct view_log, 1); | |
2073 view->options = options; | |
2074 view->name = NULL; | |
2075 view->bbox = bbox; | |
2076 view->window = window; | |
2077 view->layout = layout; | |
2078 log_show_convo(view); | |
2079 g_signal_connect(G_OBJECT(layout), "destroy", G_CALLBACK(des_view_item), view); | |
2080 } | |
2081 | |
2082 gtk_widget_set_sensitive(bbox, TRUE); | |
2083 | |
2084 return; | |
2085 } | |
2086 |