comparison src/gtkimhtml.c @ 14035:8bda65b88e49

[gaim-migrate @ 16638] A bunch of small changes. Mostly remove "if not null" checks before calling g_free, g_list_free, g_slist_free and g_strdup. Also use g_list_foreach() to call g_free to free strings in an array. And some whitespace changes here and there. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 05 Aug 2006 08:27:39 +0000
parents 11434fa0ca22
children 5e6d4c36630a
comparison
equal deleted inserted replaced
14034:0839a7b71325 14035:8bda65b88e49
1246 g_free(imhtml->clipboard_html_string); 1246 g_free(imhtml->clipboard_html_string);
1247 } 1247 }
1248 1248
1249 g_list_free(imhtml->scalables); 1249 g_list_free(imhtml->scalables);
1250 g_slist_free(imhtml->im_images); 1250 g_slist_free(imhtml->im_images);
1251 if (imhtml->protocol_name) 1251 g_free(imhtml->protocol_name);
1252 g_free(imhtml->protocol_name); 1252 g_free(imhtml->search_string);
1253 if (imhtml->search_string)
1254 g_free(imhtml->search_string);
1255 G_OBJECT_CLASS(parent_class)->finalize (object); 1253 G_OBJECT_CLASS(parent_class)->finalize (object);
1256 } 1254 }
1257 1255
1258 /* Boring GTK+ stuff */ 1256 /* Boring GTK+ stuff */
1259 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass) 1257 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass)
2735 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); 2733 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR=");
2736 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { 2734 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
2737 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); 2735 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
2738 ws[0] = '\0'; wpos = 0; 2736 ws[0] = '\0'; wpos = 0;
2739 /* NEW_BIT(NEW_TEXT_BIT); */ 2737 /* NEW_BIT(NEW_TEXT_BIT); */
2740 if (bg) 2738 g_free(bg);
2741 g_free(bg);
2742 bg = bgcolor; 2739 bg = bgcolor;
2743 gtk_imhtml_toggle_background(imhtml, bg); 2740 gtk_imhtml_toggle_background(imhtml, bg);
2744 } 2741 }
2745 } 2742 }
2746 break; 2743 break;
2750 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) { 2747 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) {
2751 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); 2748 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
2752 ws[0] = '\0'; wpos = 0; 2749 ws[0] = '\0'; wpos = 0;
2753 gtk_imhtml_toggle_link(imhtml, href); 2750 gtk_imhtml_toggle_link(imhtml, href);
2754 } 2751 }
2755 if (href) 2752 g_free(href);
2756 g_free(href);
2757 } 2753 }
2758 break; 2754 break;
2759 case 46: /* IMG (opt) */ 2755 case 46: /* IMG (opt) */
2760 case 59: /* IMG */ 2756 case 59: /* IMG */
2761 { 2757 {
3035 /* NEW_BIT(NEW_TEXT_BIT); */ 3031 /* NEW_BIT(NEW_TEXT_BIT); */
3036 3032
3037 while (fonts) { 3033 while (fonts) {
3038 GtkIMHtmlFontDetail *font = fonts->data; 3034 GtkIMHtmlFontDetail *font = fonts->data;
3039 fonts = g_slist_remove (fonts, font); 3035 fonts = g_slist_remove (fonts, font);
3040 if (font->face) 3036 g_free (font->face);
3041 g_free (font->face); 3037 g_free (font->fore);
3042 if (font->fore) 3038 g_free (font->back);
3043 g_free (font->fore); 3039 g_free (font->sml);
3044 if (font->back)
3045 g_free (font->back);
3046 if (font->sml)
3047 g_free (font->sml);
3048 g_free (font); 3040 g_free (font);
3049 } 3041 }
3050 3042
3051 g_free(ws); 3043 g_free(ws);
3052 g_free(bg); 3044 g_free(bg);
3080 return imhtml->protocol_name; 3072 return imhtml->protocol_name;
3081 } 3073 }
3082 3074
3083 void 3075 void
3084 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name) { 3076 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name) {
3085 if (imhtml->protocol_name) 3077 g_free(imhtml->protocol_name);
3086 g_free(imhtml->protocol_name); 3078 imhtml->protocol_name = g_strdup(protocol_name);
3087 imhtml->protocol_name = protocol_name ? g_strdup(protocol_name) : NULL;
3088 } 3079 }
3089 3080
3090 void 3081 void
3091 gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) { 3082 gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) {
3092 GList *l; 3083 GList *l;
3172 im_image->pixbuf = img; 3163 im_image->pixbuf = img;
3173 im_image->image = image; 3164 im_image->image = image;
3174 im_image->width = gdk_pixbuf_get_width(img); 3165 im_image->width = gdk_pixbuf_get_width(img);
3175 im_image->height = gdk_pixbuf_get_height(img); 3166 im_image->height = gdk_pixbuf_get_height(img);
3176 im_image->mark = NULL; 3167 im_image->mark = NULL;
3177 im_image->filename = filename ? g_strdup(filename) : NULL; 3168 im_image->filename = g_strdup(filename);
3178 im_image->id = id; 3169 im_image->id = id;
3179 im_image->filesel = NULL; 3170 im_image->filesel = NULL;
3180 3171
3181 g_object_ref(img); 3172 g_object_ref(img);
3182 return GTK_IMHTML_SCALABLE(im_image); 3173 return GTK_IMHTML_SCALABLE(im_image);
3439 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) 3430 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale)
3440 { 3431 {
3441 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; 3432 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
3442 3433
3443 g_object_unref(image->pixbuf); 3434 g_object_unref(image->pixbuf);
3444 if (image->filename) 3435 g_free(image->filename);
3445 g_free(image->filename);
3446 if (image->filesel) 3436 if (image->filesel)
3447 gtk_widget_destroy(image->filesel); 3437 gtk_widget_destroy(image->filesel);
3448 g_free(scale); 3438 g_free(scale);
3449 } 3439 }
3450 3440
3557 3547
3558 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); 3548 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
3559 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); 3549 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
3560 3550
3561 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); 3551 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end);
3562 if (imhtml->search_string) 3552 g_free(imhtml->search_string);
3563 g_free(imhtml->search_string);
3564 imhtml->search_string = NULL; 3553 imhtml->search_string = NULL;
3565 } 3554 }
3566 3555
3567 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color) 3556 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color)
3568 { 3557 {
3823 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, start, end); 3812 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, start, end);
3824 if (tag->name && 3813 if (tag->name &&
3825 strncmp(tag->name, "LINK ", 5) == 0 && imhtml->edit.link) { 3814 strncmp(tag->name, "LINK ", 5) == 0 && imhtml->edit.link) {
3826 gtk_imhtml_toggle_link(imhtml, NULL); 3815 gtk_imhtml_toggle_link(imhtml, NULL);
3827 } 3816 }
3828 } 3817 }
3829 } 3818 }
3830 g_slist_free(tags); 3819 g_slist_free(tags);
3831 } 3820 }
3832 3821
3833 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) 3822 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end)
3942 } 3931 }
3943 3932
3944 char * 3933 char *
3945 gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml) 3934 gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml)
3946 { 3935 {
3947 if (imhtml->edit.fontface) 3936 return g_strdup(imhtml->edit.fontface);
3948 return g_strdup(imhtml->edit.fontface);
3949 else
3950 return NULL;
3951 } 3937 }
3952 3938
3953 char * 3939 char *
3954 gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml) 3940 gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml)
3955 { 3941 {
3956 if (imhtml->edit.forecolor) 3942 return g_strdup(imhtml->edit.forecolor);
3957 return g_strdup(imhtml->edit.forecolor);
3958 else
3959 return NULL;
3960 } 3943 }
3961 3944
3962 char * 3945 char *
3963 gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml) 3946 gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml)
3964 { 3947 {
3965 if (imhtml->edit.backcolor) 3948 return g_strdup(imhtml->edit.backcolor);
3966 return g_strdup(imhtml->edit.backcolor);
3967 else
3968 return NULL;
3969 } 3949 }
3970 3950
3971 char * 3951 char *
3972 gtk_imhtml_get_current_background(GtkIMHtml *imhtml) 3952 gtk_imhtml_get_current_background(GtkIMHtml *imhtml)
3973 { 3953 {
3974 if (imhtml->edit.background) 3954 return g_strdup(imhtml->edit.background);
3975 return g_strdup(imhtml->edit.background);
3976 else
3977 return NULL;
3978 } 3955 }
3979 3956
3980 gint 3957 gint
3981 gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml) 3958 gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml)
3982 { 3959 {
4027 4004
4028 if (!gtk_text_buffer_get_char_count(buffer)) 4005 if (!gtk_text_buffer_get_char_count(buffer))
4029 return; 4006 return;
4030 4007
4031 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = imhtml->edit.strike = FALSE; 4008 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = imhtml->edit.strike = FALSE;
4032 if (imhtml->edit.forecolor) 4009 g_free(imhtml->edit.forecolor);
4033 g_free(imhtml->edit.forecolor);
4034 imhtml->edit.forecolor = NULL; 4010 imhtml->edit.forecolor = NULL;
4035 if (imhtml->edit.backcolor) 4011
4036 g_free(imhtml->edit.backcolor); 4012 g_free(imhtml->edit.backcolor);
4037 imhtml->edit.backcolor = NULL; 4013 imhtml->edit.backcolor = NULL;
4038 if (imhtml->edit.fontface) 4014
4039 g_free(imhtml->edit.fontface); 4015 g_free(imhtml->edit.fontface);
4040 imhtml->edit.fontface = NULL; 4016 imhtml->edit.fontface = NULL;
4017
4041 imhtml->edit.fontsize = 0; 4018 imhtml->edit.fontsize = 0;
4042 imhtml->edit.link = NULL; 4019 imhtml->edit.link = NULL;
4043 4020
4044 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); 4021 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
4045 4022