comparison src/gtkconv.c @ 12618:204bd8fac61f

[gaim-migrate @ 14954] SF Patch #1355796 from Sadrul This fixes the custom smiley bug where your text gets smilies from the other party in the conversation. This is a bit of a hack, but it fix things until such time as the smiley tree stuff can be reworked. " From the kwiki: If someone uses an MSN smiley, it shows up when I type the textual representation of it. For example, someone set a smiley (a rainbow flashy question mark) for ? and it showed up (on my side, I have no idea about theirs) for every ? I typed. /luke as I understand this report, the problem is that the custom smiley should be restricted to exactly one conversation but is in fact spanning the account/ * (sadrul) It appears what happens is, the custom smiley is added to the smiley-tree for that conversation-imhtml. So whenever any new message is going to be added to the imhtml, it looks up the smiley-tree first, and since the "?" (or anything else) matches the smiley, it converts it to the smiley. At first glance, it seems the fix would be non-trivial. It will probably be necessary to distinguish between custom-smileys (and also messages added to the imhtml) of the sender and the receiver. ==== end ==== What this patch does is, it temporarily replaces the smiley-tree for the conversation-imhtml with the smiley-tree of the conversation-entrybox. I think this will work because the smiley-trees of both these imhtml-s are initially the same. When a custom smiley is received, it is added the smiley-tree of the conversation-imhtml. So temporarily restoring the smiley-tree with the original smiley-tree (that in conv-entrybox) should fix the problem." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 22 Dec 2005 04:07:21 +0000
parents eee2042ad4f4
children 851b0bd7eb52
comparison
equal deleted inserted replaced
12617:49499dec9346 12618:204bd8fac61f
4471 char *alias_escaped = (alias ? g_markup_escape_text(alias, strlen(alias)) : g_strdup("")); 4471 char *alias_escaped = (alias ? g_markup_escape_text(alias, strlen(alias)) : g_strdup(""));
4472 /* The initial offset is to deal with 4472 /* The initial offset is to deal with
4473 * escaped entities making the string longer */ 4473 * escaped entities making the string longer */
4474 int tag_start_offset = alias ? (strlen(alias_escaped) - strlen(alias)) : 0; 4474 int tag_start_offset = alias ? (strlen(alias_escaped) - strlen(alias)) : 0;
4475 int tag_end_offset = 0; 4475 int tag_end_offset = 0;
4476 GtkSmileyTree *tree = NULL;
4477 GHashTable *smiley_data = NULL;
4478
4479 if (flags & GAIM_MESSAGE_SEND)
4480 {
4481 /* Temporarily revert to the original smiley-data to avoid showing up
4482 * custom smileys of the buddy when sending message
4483 */
4484 tree = GTK_IMHTML(gtkconv->imhtml)->default_smilies;
4485 GTK_IMHTML(gtkconv->imhtml)->default_smilies =
4486 GTK_IMHTML(gtkconv->entry)->default_smilies;
4487 smiley_data = GTK_IMHTML(gtkconv->imhtml)->smiley_data;
4488 GTK_IMHTML(gtkconv->imhtml)->smiley_data = GTK_IMHTML(gtkconv->entry)->smiley_data;
4489 }
4476 4490
4477 if (flags & GAIM_MESSAGE_WHISPER) { 4491 if (flags & GAIM_MESSAGE_WHISPER) {
4478 str = g_malloc(1024); 4492 str = g_malloc(1024);
4479 4493
4480 /* If we're whispering, it's not an autoresponse. */ 4494 /* If we're whispering, it's not an autoresponse. */
4614 with_font_tag = g_memdup(new_message, length); 4628 with_font_tag = g_memdup(new_message, length);
4615 4629
4616 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), 4630 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml),
4617 with_font_tag, gtk_font_options | gtk_font_options_all); 4631 with_font_tag, gtk_font_options | gtk_font_options_all);
4618 4632
4633 if (flags & GAIM_MESSAGE_SEND)
4634 {
4635 /* Restore the smiley-data */
4636 GTK_IMHTML(gtkconv->imhtml)->default_smilies = tree;
4637 GTK_IMHTML(gtkconv->imhtml)->smiley_data = smiley_data;
4638 }
4639
4619 g_free(with_font_tag); 4640 g_free(with_font_tag);
4620 g_free(new_message); 4641 g_free(new_message);
4621 } 4642 }
4622 4643
4623 if(sml_attrib) 4644 if(sml_attrib)
4957 g_object_unref(G_OBJECT(loader)); 4978 g_object_unref(G_OBJECT(loader));
4958 smiley->loader = NULL; 4979 smiley->loader = NULL;
4959 } 4980 }
4960 4981
4961 static gboolean 4982 static gboolean
4962 gaim_gtkconv_custom_smiley_add(GaimConversation *conv, const char *smile) 4983 add_custom_smiley_for_imhtml(GtkIMHtml *imhtml, const char *sml, const char *smile)
4963 { 4984 {
4964 GaimGtkConversation *gtkconv;
4965 GtkIMHtmlSmiley *smiley; 4985 GtkIMHtmlSmiley *smiley;
4966 GdkPixbufLoader *loader; 4986 GdkPixbufLoader *loader;
4967 struct smiley_list *list; 4987
4968 const char *sml = NULL, *conv_sml; 4988 smiley = gtk_imhtml_smiley_get(imhtml, sml, smile);
4969
4970 if (!conv || !smile || !*smile) {
4971 return FALSE;
4972 }
4973
4974 /* If smileys are off, return false */
4975 if (gaim_gtkthemes_smileys_disabled())
4976 return FALSE;
4977
4978 /* If possible add this smiley to the current theme.
4979 * The addition is only temporary: custom smilies aren't saved to disk. */
4980 conv_sml = gaim_account_get_protocol_name(conv->account);
4981 gtkconv = GAIM_GTK_CONVERSATION(conv);
4982
4983 for (list = (struct smiley_list *)current_smiley_theme->list; list; list = list->next) {
4984 if (!strcmp(list->sml, conv_sml)) {
4985 sml = list->sml;
4986 break;
4987 }
4988 }
4989
4990 smiley = gtk_imhtml_smiley_get(GTK_IMHTML(gtkconv->imhtml), sml, smile);
4991 4989
4992 if (smiley) { 4990 if (smiley) {
4993 4991
4994 if (!(smiley->flags & GTK_IMHTML_SMILEY_CUSTOM)) { 4992 if (!(smiley->flags & GTK_IMHTML_SMILEY_CUSTOM)) {
4995 return FALSE; 4993 return FALSE;
4997 4995
4998 /* Close the old GdkPixbufAnimation, then create a new one for 4996 /* Close the old GdkPixbufAnimation, then create a new one for
4999 * the smiley we are about to receive */ 4997 * the smiley we are about to receive */
5000 g_object_unref(G_OBJECT(smiley->icon)); 4998 g_object_unref(G_OBJECT(smiley->icon));
5001 4999
5000 /* XXX: Is it necessary to _unref the loader first? */
5002 smiley->loader = gdk_pixbuf_loader_new(); 5001 smiley->loader = gdk_pixbuf_loader_new();
5003 smiley->icon = NULL; 5002 smiley->icon = NULL;
5004 5003
5005 g_signal_connect(smiley->loader, "area_prepared", G_CALLBACK(gaim_gtkconv_custom_smiley_allocated), smiley); 5004 g_signal_connect(smiley->loader, "area_prepared", G_CALLBACK(gaim_gtkconv_custom_smiley_allocated), smiley);
5006 g_signal_connect(smiley->loader, "closed", G_CALLBACK(gaim_gtkconv_custom_smiley_closed), smiley); 5005 g_signal_connect(smiley->loader, "closed", G_CALLBACK(gaim_gtkconv_custom_smiley_closed), smiley);
5020 smiley->flags = smiley->flags | GTK_IMHTML_SMILEY_CUSTOM; 5019 smiley->flags = smiley->flags | GTK_IMHTML_SMILEY_CUSTOM;
5021 5020
5022 g_signal_connect(smiley->loader, "area_prepared", G_CALLBACK(gaim_gtkconv_custom_smiley_allocated), smiley); 5021 g_signal_connect(smiley->loader, "area_prepared", G_CALLBACK(gaim_gtkconv_custom_smiley_allocated), smiley);
5023 g_signal_connect(smiley->loader, "closed", G_CALLBACK(gaim_gtkconv_custom_smiley_closed), smiley); 5022 g_signal_connect(smiley->loader, "closed", G_CALLBACK(gaim_gtkconv_custom_smiley_closed), smiley);
5024 5023
5025 gtk_imhtml_associate_smiley(GTK_IMHTML(gtkconv->imhtml), sml, smiley); 5024 gtk_imhtml_associate_smiley(imhtml, sml, smiley);
5025
5026 return TRUE;
5027 }
5028
5029 static gboolean
5030 gaim_gtkconv_custom_smiley_add(GaimConversation *conv, const char *smile, gboolean remote)
5031 {
5032 GaimGtkConversation *gtkconv;
5033 struct smiley_list *list;
5034 const char *sml = NULL, *conv_sml;
5035
5036 if (!conv || !smile || !*smile) {
5037 return FALSE;
5038 }
5039
5040 /* If smileys are off, return false */
5041 if (gaim_gtkthemes_smileys_disabled())
5042 return FALSE;
5043
5044 /* If possible add this smiley to the current theme.
5045 * The addition is only temporary: custom smilies aren't saved to disk. */
5046 conv_sml = gaim_account_get_protocol_name(conv->account);
5047 gtkconv = GAIM_GTK_CONVERSATION(conv);
5048
5049 for (list = (struct smiley_list *)current_smiley_theme->list; list; list = list->next) {
5050 if (!strcmp(list->sml, conv_sml)) {
5051 sml = list->sml;
5052 break;
5053 }
5054 }
5055
5056 if (!add_custom_smiley_for_imhtml(GTK_IMHTML(gtkconv->imhtml), sml, smile))
5057 return FALSE;
5058
5059 if (!remote) /* If it's a local custom smiley, then add it for the entry */
5060 if (!add_custom_smiley_for_imhtml(GTK_IMHTML(gtkconv->entry), sml, smile))
5061 return FALSE;
5026 5062
5027 return TRUE; 5063 return TRUE;
5028 } 5064 }
5029 5065
5030 static void 5066 static void