comparison pidgin/gtkconv.c @ 16953:ab45289d2c36

Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 09 May 2007 01:21:15 +0000
parents bd0b946e6309
children 563a42d98e3a
comparison
equal deleted inserted replaced
16952:919515748253 16953:ab45289d2c36
4976 char *displaying; 4976 char *displaying;
4977 gboolean plugin_return; 4977 gboolean plugin_return;
4978 char *bracket; 4978 char *bracket;
4979 int tag_count = 0; 4979 int tag_count = 0;
4980 gboolean is_rtl_message = FALSE; 4980 gboolean is_rtl_message = FALSE;
4981 GtkSmileyTree *tree = NULL;
4982 GHashTable *smiley_data = NULL;
4981 4983
4982 g_return_if_fail(conv != NULL); 4984 g_return_if_fail(conv != NULL);
4983 gtkconv = PIDGIN_CONVERSATION(conv); 4985 gtkconv = PIDGIN_CONVERSATION(conv);
4984 g_return_if_fail(gtkconv != NULL); 4986 g_return_if_fail(gtkconv != NULL);
4985 4987
5119 if (PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(conv->account)))->options & 5121 if (PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(conv->account)))->options &
5120 OPT_PROTO_USE_POINTSIZE) { 5122 OPT_PROTO_USE_POINTSIZE) {
5121 gtk_font_options |= GTK_IMHTML_USE_POINTSIZE; 5123 gtk_font_options |= GTK_IMHTML_USE_POINTSIZE;
5122 } 5124 }
5123 5125
5126 if (!(flags & PURPLE_MESSAGE_RECV))
5127 {
5128 /* Temporarily revert to the original smiley-data to avoid showing up
5129 * custom smileys of the buddy when sending message
5130 */
5131 tree = GTK_IMHTML(gtkconv->imhtml)->default_smilies;
5132 GTK_IMHTML(gtkconv->imhtml)->default_smilies =
5133 GTK_IMHTML(gtkconv->entry)->default_smilies;
5134 smiley_data = GTK_IMHTML(gtkconv->imhtml)->smiley_data;
5135 GTK_IMHTML(gtkconv->imhtml)->smiley_data = GTK_IMHTML(gtkconv->entry)->smiley_data;
5136 }
5124 5137
5125 /* TODO: These colors should not be hardcoded so log.c can use them */ 5138 /* TODO: These colors should not be hardcoded so log.c can use them */
5126 if (flags & PURPLE_MESSAGE_RAW) { 5139 if (flags & PURPLE_MESSAGE_RAW) {
5127 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), message, gtk_font_options_all); 5140 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), message, gtk_font_options_all);
5128 } else if (flags & PURPLE_MESSAGE_SYSTEM) { 5141 } else if (flags & PURPLE_MESSAGE_SYSTEM) {
5150 char *alias_escaped = (alias ? g_markup_escape_text(alias, strlen(alias)) : g_strdup("")); 5163 char *alias_escaped = (alias ? g_markup_escape_text(alias, strlen(alias)) : g_strdup(""));
5151 /* The initial offset is to deal with 5164 /* The initial offset is to deal with
5152 * escaped entities making the string longer */ 5165 * escaped entities making the string longer */
5153 int tag_start_offset = alias ? (strlen(alias_escaped) - strlen(alias)) : 0; 5166 int tag_start_offset = alias ? (strlen(alias_escaped) - strlen(alias)) : 0;
5154 int tag_end_offset = 0; 5167 int tag_end_offset = 0;
5155 GtkSmileyTree *tree = NULL;
5156 GHashTable *smiley_data = NULL;
5157 5168
5158 /* Enforce direction on alias */ 5169 /* Enforce direction on alias */
5159 if (is_rtl_message) 5170 if (is_rtl_message)
5160 str_embed_direction_chars(&alias_escaped); 5171 str_embed_direction_chars(&alias_escaped);
5161
5162 if (flags & PURPLE_MESSAGE_SEND)
5163 {
5164 /* Temporarily revert to the original smiley-data to avoid showing up
5165 * custom smileys of the buddy when sending message
5166 */
5167 tree = GTK_IMHTML(gtkconv->imhtml)->default_smilies;
5168 GTK_IMHTML(gtkconv->imhtml)->default_smilies =
5169 GTK_IMHTML(gtkconv->entry)->default_smilies;
5170 smiley_data = GTK_IMHTML(gtkconv->imhtml)->smiley_data;
5171 GTK_IMHTML(gtkconv->imhtml)->smiley_data = GTK_IMHTML(gtkconv->entry)->smiley_data;
5172 }
5173 5172
5174 if (flags & PURPLE_MESSAGE_WHISPER) { 5173 if (flags & PURPLE_MESSAGE_WHISPER) {
5175 str = g_malloc(1024); 5174 str = g_malloc(1024);
5176 5175
5177 /* If we're whispering, it's not an autoresponse. */ 5176 /* If we're whispering, it's not an autoresponse. */
5310 with_font_tag = g_memdup(new_message, length); 5309 with_font_tag = g_memdup(new_message, length);
5311 5310
5312 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), 5311 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml),
5313 with_font_tag, gtk_font_options | gtk_font_options_all); 5312 with_font_tag, gtk_font_options | gtk_font_options_all);
5314 5313
5315 if (flags & PURPLE_MESSAGE_SEND)
5316 {
5317 /* Restore the smiley-data */
5318 GTK_IMHTML(gtkconv->imhtml)->default_smilies = tree;
5319 GTK_IMHTML(gtkconv->imhtml)->smiley_data = smiley_data;
5320 }
5321
5322 g_free(with_font_tag); 5314 g_free(with_font_tag);
5323 g_free(new_message); 5315 g_free(new_message);
5324 } 5316 }
5325 5317
5326 g_free(mdate); 5318 g_free(mdate);
5340 unseen = PIDGIN_UNSEEN_NO_LOG; 5332 unseen = PIDGIN_UNSEEN_NO_LOG;
5341 else 5333 else
5342 unseen = PIDGIN_UNSEEN_TEXT; 5334 unseen = PIDGIN_UNSEEN_TEXT;
5343 5335
5344 gtkconv_set_unseen(gtkconv, unseen); 5336 gtkconv_set_unseen(gtkconv, unseen);
5337 }
5338
5339 if (!(flags & PURPLE_MESSAGE_RECV))
5340 {
5341 /* Restore the smiley-data */
5342 GTK_IMHTML(gtkconv->imhtml)->default_smilies = tree;
5343 GTK_IMHTML(gtkconv->imhtml)->smiley_data = smiley_data;
5345 } 5344 }
5346 5345
5347 purple_signal_emit(pidgin_conversations_get_handle(), 5346 purple_signal_emit(pidgin_conversations_get_handle(),
5348 (type == PURPLE_CONV_TYPE_IM ? "displayed-im-msg" : "displayed-chat-msg"), 5347 (type == PURPLE_CONV_TYPE_IM ? "displayed-im-msg" : "displayed-chat-msg"),
5349 account, name, displaying, conv, flags); 5348 account, name, displaying, conv, flags);
5605 #ifdef DEBUG_CUSTOM_SMILEY 5604 #ifdef DEBUG_CUSTOM_SMILEY
5606 purple_debug_info("custom-smiley", "pidgin_conv_custom_smiley_closed(): got GtkImage %p from GtkPixbufAnimation %p for smiley '%s'\n", 5605 purple_debug_info("custom-smiley", "pidgin_conv_custom_smiley_closed(): got GtkImage %p from GtkPixbufAnimation %p for smiley '%s'\n",
5607 icon, smiley->icon, smiley->smile); 5606 icon, smiley->icon, smiley->smile);
5608 #endif 5607 #endif
5609 if (icon) { 5608 if (icon) {
5609 GList *wids;
5610 gtk_widget_show(icon); 5610 gtk_widget_show(icon);
5611 5611
5612 anchor = GTK_TEXT_CHILD_ANCHOR(current->data); 5612 anchor = GTK_TEXT_CHILD_ANCHOR(current->data);
5613 wids = gtk_text_child_anchor_get_widgets(anchor);
5613 5614
5614 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", purple_unescape_html(smiley->smile), g_free); 5615 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", purple_unescape_html(smiley->smile), g_free);
5615 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley->smile), g_free); 5616 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley->smile), g_free);
5616 5617
5617 if (smiley->imhtml) 5618 if (smiley->imhtml) {
5618 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(smiley->imhtml), icon, anchor); 5619 if (wids) {
5620 GList *children = gtk_container_get_children(GTK_CONTAINER(wids->data));
5621 g_list_foreach(children, (GFunc)gtk_widget_destroy, NULL);
5622 g_list_free(children);
5623 gtk_container_add(GTK_CONTAINER(wids->data), icon);
5624 } else
5625 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(smiley->imhtml), icon, anchor);
5626 }
5627 g_list_free(wids);
5619 } 5628 }
5620 5629
5621 } 5630 }
5622 5631
5623 g_slist_free(smiley->anchors); 5632 g_slist_free(smiley->anchors);