comparison pidgin/gtkimhtml.c @ 23131:ac567757d236

propagate from branch 'im.pidgin.pidgin' (head 6be4a11c3e1bf403bbb6e1a7a754e4b99e7d9a44) to branch 'im.pidgin.pidgin.custom_smiley' (head fb801dc3cb44bc81a383a9e0a44ba099a3e99d1e)
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 07 May 2008 03:32:43 +0000
parents 900c7b5660d5 2f4b10ee752b
children 9aa105267f46
comparison
equal deleted inserted replaced
22832:4409f8a0d7aa 23131:ac567757d236
5264 buttons &= ~GTK_IMHTML_IMAGE; 5264 buttons &= ~GTK_IMHTML_IMAGE;
5265 5265
5266 gtk_imhtml_set_format_functions(imhtml, buttons); 5266 gtk_imhtml_set_format_functions(imhtml, buttons);
5267 } 5267 }
5268 5268
5269 5269 /*******
5270 * GtkIMHtmlSmiley functions
5271 *******/
5272 static void gtk_custom_smiley_allocated(GdkPixbufLoader *loader, gpointer user_data)
5273 {
5274 GtkIMHtmlSmiley *smiley;
5275
5276 smiley = (GtkIMHtmlSmiley *)user_data;
5277 smiley->icon = gdk_pixbuf_loader_get_animation(loader);
5278
5279 if (smiley->icon)
5280 g_object_ref(G_OBJECT(smiley->icon));
5281 #ifdef DEBUG_CUSTOM_SMILEY
5282 purple_debug_info("custom-smiley", "gtk_custom_smiley_allocated(): got GdkPixbufAnimation %p for smiley '%s'\n", smiley->icon, smiley->smile);
5283 #endif
5284 }
5285
5286 static void gtk_custom_smiley_closed(GdkPixbufLoader *loader, gpointer user_data)
5287 {
5288 GtkIMHtmlSmiley *smiley;
5289 GtkWidget *icon = NULL;
5290 GtkTextChildAnchor *anchor = NULL;
5291 GSList *current = NULL;
5292
5293 smiley = (GtkIMHtmlSmiley *)user_data;
5294 if (!smiley->imhtml) {
5295 #ifdef DEBUG_CUSTOM_SMILEY
5296 purple_debug_error("custom-smiley", "gtk_custom_smiley_closed(): orphan smiley found: %p\n", smiley);
5297 #endif
5298 g_object_unref(G_OBJECT(loader));
5299 smiley->loader = NULL;
5300 return;
5301 }
5302
5303 for (current = smiley->anchors; current; current = g_slist_next(current)) {
5304
5305 icon = gtk_image_new_from_animation(smiley->icon);
5306
5307 #ifdef DEBUG_CUSTOM_SMILEY
5308 purple_debug_info("custom-smiley", "gtk_custom_smiley_closed(): got GtkImage %p from GtkPixbufAnimation %p for smiley '%s'\n",
5309 icon, smiley->icon, smiley->smile);
5310 #endif
5311 if (icon) {
5312 GList *wids;
5313 gtk_widget_show(icon);
5314
5315 anchor = GTK_TEXT_CHILD_ANCHOR(current->data);
5316 wids = gtk_text_child_anchor_get_widgets(anchor);
5317
5318 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", purple_unescape_html(smiley->smile), g_free);
5319 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley->smile), g_free);
5320
5321 if (smiley->imhtml) {
5322 if (wids) {
5323 GList *children = gtk_container_get_children(GTK_CONTAINER(wids->data));
5324 g_list_foreach(children, (GFunc)gtk_widget_destroy, NULL);
5325 g_list_free(children);
5326 gtk_container_add(GTK_CONTAINER(wids->data), icon);
5327 } else
5328 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(smiley->imhtml), icon, anchor);
5329 }
5330 g_list_free(wids);
5331 }
5332
5333 }
5334
5335 g_slist_free(smiley->anchors);
5336 smiley->anchors = NULL;
5337
5338 g_object_unref(G_OBJECT(loader));
5339 smiley->loader = NULL;
5340 }
5341
5342 void
5343 gtk_imhtml_smiley_reload(GtkIMHtmlSmiley *smiley)
5344 {
5345 if (smiley->icon)
5346 g_object_unref(smiley->icon);
5347 if (smiley->loader)
5348 g_object_unref(smiley->loader); /* XXX: does this crash? */
5349
5350 smiley->icon = NULL;
5351 smiley->loader = NULL;
5352
5353 if (smiley->file) {
5354 /* We do not use the pixbuf loader for a smiley that can be loaded
5355 * from a file. (e.g., local custom smileys)
5356 */
5357 return;
5358 }
5359
5360 smiley->loader = gdk_pixbuf_loader_new();
5361
5362 g_signal_connect(smiley->loader, "area_prepared", G_CALLBACK(gtk_custom_smiley_allocated), smiley);
5363 g_signal_connect(smiley->loader, "closed", G_CALLBACK(gtk_custom_smiley_closed), smiley);
5364 }
5365
5366 GtkIMHtmlSmiley *gtk_imhtml_smiley_create(const char *file, const char *shortcut, gboolean hide,
5367 GtkIMHtmlSmileyFlags flags)
5368 {
5369 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1);
5370 smiley->file = g_strdup(file);
5371 smiley->smile = g_strdup(shortcut);
5372 smiley->hidden = hide;
5373 smiley->flags = flags;
5374 gtk_imhtml_smiley_reload(smiley);
5375 return smiley;
5376 }
5377
5378 void gtk_imhtml_smiley_destroy(GtkIMHtmlSmiley *smiley)
5379 {
5380 g_free(smiley->smile);
5381 g_free(smiley->file);
5382 if (smiley->icon)
5383 g_object_unref(smiley->icon);
5384 if (smiley->loader)
5385 g_object_unref(smiley->loader);
5386 g_free(smiley);
5387 }
5388