comparison src/conversation.c @ 2499:933e139fd0d3

[gaim-migrate @ 2512] buddy icons are very leaky committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 14 Oct 2001 03:54:40 +0000
parents 43a75ca5b909
children a452084e1636
comparison
equal deleted inserted replaced
2498:bd66482296f9 2499:933e139fd0d3
249 gtk_widget_destroy(c->smiley_dialog); 249 gtk_widget_destroy(c->smiley_dialog);
250 if (c->link_dialog) 250 if (c->link_dialog)
251 gtk_widget_destroy(c->link_dialog); 251 gtk_widget_destroy(c->link_dialog);
252 if (c->log_dialog) 252 if (c->log_dialog)
253 gtk_widget_destroy(c->log_dialog); 253 gtk_widget_destroy(c->log_dialog);
254 if (c->save_icon)
255 gtk_widget_destroy(c->save_icon);
254 g_string_free(c->history, TRUE); 256 g_string_free(c->history, TRUE);
255 g_free(c); 257 g_free(c);
256 } 258 }
257 259
258 void update_log_convs() 260 void update_log_convs()
2656 delay = MAX(gdk_pixbuf_frame_get_delay_time(frame), 13); 2658 delay = MAX(gdk_pixbuf_frame_get_delay_time(frame), 13);
2657 c->icon_timer = gtk_timeout_add(delay * 10, redraw_icon, c); 2659 c->icon_timer = gtk_timeout_add(delay * 10, redraw_icon, c);
2658 2660
2659 return FALSE; 2661 return FALSE;
2660 } 2662 }
2663
2664 static void stop_anim(GtkObject *obj, struct conversation *c)
2665 {
2666 if (c->icon_timer)
2667 gtk_timeout_remove(c->icon_timer);
2668 c->icon_timer = 0;
2669 }
2670
2671 static int des_save_icon(GtkObject *obj, GdkEvent *e, struct conversation *c)
2672 {
2673 gtk_widget_destroy(c->save_icon);
2674 c->save_icon = NULL;
2675 return TRUE;
2676 }
2677
2678 static void do_save_icon(GtkObject *obj, struct conversation *c)
2679 {
2680 FILE *file;
2681 char *f = gtk_file_selection_get_filename(GTK_FILE_SELECTION(c->save_icon));
2682 if (file_is_dir(f, c->save_icon))
2683 return;
2684
2685 file = fopen(f, "w");
2686 if (file) {
2687 int len;
2688 void *data = get_icon_data(c->gc, normalize(c->name), &len);
2689 if (data)
2690 fwrite(data, 1, len, file);
2691 fclose(file);
2692 } else {
2693 do_error_dialog("Can't open file for writing", "Error");
2694 }
2695
2696 gtk_widget_destroy(c->save_icon);
2697 c->save_icon = NULL;
2698 }
2699
2700 static void cancel_save_icon(GtkObject *obj, struct conversation *c)
2701 {
2702 gtk_widget_destroy(c->save_icon);
2703 c->save_icon = NULL;
2704 }
2705
2706 static void save_icon(GtkObject *obj, struct conversation *c)
2707 {
2708 char buf[BUF_LEN];
2709
2710 if (c->save_icon) {
2711 gdk_window_raise(c->save_icon->window);
2712 return;
2713 }
2714
2715 c->save_icon = gtk_file_selection_new(_("Gaim - Save Icon"));
2716 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(c->save_icon));
2717 g_snprintf(buf, BUF_LEN - 1, "%s/%s.icon", g_get_home_dir(), c->name);
2718 gtk_file_selection_set_filename(GTK_FILE_SELECTION(c->save_icon), buf);
2719 gtk_signal_connect(GTK_OBJECT(c->save_icon), "delete_event",
2720 GTK_SIGNAL_FUNC(des_save_icon), c);
2721 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(c->save_icon)->ok_button), "clicked",
2722 GTK_SIGNAL_FUNC(do_save_icon), c);
2723 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(c->save_icon)->cancel_button), "clicked",
2724 GTK_SIGNAL_FUNC(cancel_save_icon), c);
2725
2726 gtk_widget_show(c->save_icon);
2727 }
2728
2729 static gboolean icon_menu(GtkObject *obj, GdkEventButton *e, struct conversation *c)
2730 {
2731 GtkWidget *menu;
2732 GtkWidget *button;
2733
2734 if (e->button != 3)
2735 return FALSE;
2736 if (e->type != GDK_BUTTON_PRESS)
2737 return FALSE;
2738
2739 menu = gtk_menu_new();
2740
2741 if (c->icon_timer) {
2742 button = gtk_menu_item_new_with_label(_("Disable Animation"));
2743 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(stop_anim), c);
2744 gtk_menu_append(GTK_MENU(menu), button);
2745 gtk_widget_show(button);
2746 }
2747
2748 button = gtk_menu_item_new_with_label(_("Hide Icon"));
2749 gtk_signal_connect_object(GTK_OBJECT(button), "activate",
2750 GTK_SIGNAL_FUNC(remove_icon), (void *)c);
2751 gtk_menu_append(GTK_MENU(menu), button);
2752 gtk_widget_show(button);
2753
2754 button = gtk_menu_item_new_with_label(_("Save Icon As..."));
2755 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(save_icon), c);
2756 gtk_menu_append(GTK_MENU(menu), button);
2757 gtk_widget_show(button);
2758
2759 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time);
2760
2761 return TRUE;
2762 }
2661 #endif 2763 #endif
2662 2764
2663 void remove_icon(struct conversation *c) 2765 void remove_icon(struct conversation *c)
2664 { 2766 {
2665 #if USE_PIXBUF 2767 #if USE_PIXBUF
2666 if (c->icon) 2768 if (c->icon)
2667 gtk_container_remove(GTK_CONTAINER(c->bbox), c->icon); 2769 gtk_container_remove(GTK_CONTAINER(c->bbox), c->icon->parent);
2668 c->icon = NULL; 2770 c->icon = NULL;
2669 if (c->anim) 2771 if (c->anim)
2670 gdk_pixbuf_animation_unref(c->anim); 2772 gdk_pixbuf_animation_unref(c->anim);
2671 c->anim = NULL; 2773 c->anim = NULL;
2672 if (c->unanim) 2774 if (c->unanim)
2683 { 2785 {
2684 #if USE_PIXBUF 2786 #if USE_PIXBUF
2685 void *data; 2787 void *data;
2686 int len; 2788 int len;
2687 2789
2790 GtkWidget *event;
2688 GdkPixbufLoader *load; 2791 GdkPixbufLoader *load;
2689 GdkPixbuf *scale; 2792 GdkPixbuf *scale;
2690 GdkPixmap *pm; 2793 GdkPixmap *pm;
2691 GdkBitmap *bm; 2794 GdkBitmap *bm;
2692 int sf = 0; 2795 int sf = 0;
2737 } 2840 }
2738 2841
2739 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 0); 2842 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 0);
2740 gdk_pixbuf_unref(scale); 2843 gdk_pixbuf_unref(scale);
2741 2844
2845 event = gtk_event_box_new();
2846 gtk_box_pack_start(GTK_BOX(c->bbox), event, FALSE, FALSE, 5);
2847 gtk_signal_connect(GTK_OBJECT(event), "button-press-event", GTK_SIGNAL_FUNC(icon_menu), c);
2848 gtk_widget_show(event);
2849
2742 c->icon = gtk_pixmap_new(pm, bm); 2850 c->icon = gtk_pixmap_new(pm, bm);
2743 gtk_widget_set_usize(c->icon, sf, sf); 2851 gtk_widget_set_usize(c->icon, sf, sf);
2744 gtk_box_pack_start(GTK_BOX(c->bbox), c->icon, FALSE, FALSE, 5); 2852 gtk_container_add(GTK_CONTAINER(event), c->icon);
2745 gtk_widget_show(c->icon); 2853 gtk_widget_show(c->icon);
2746 gdk_pixmap_unref(pm); 2854 gdk_pixmap_unref(pm);
2747 if (bm) 2855 if (bm)
2748 gdk_bitmap_unref(bm); 2856 gdk_bitmap_unref(bm);
2749 2857