Mercurial > pidgin.yaz
comparison pidgin/gtkutils.c @ 24396:38a2f78f80a7
Allow plugins to specify custom link types to the GtkIMHtml widget.
Currently, the custom link types are added for all GtkIMHtml widgets. If
we wanted, it should be possible to add custom links to particular
widgets only too. If everything looks OK, I might merge this in before
2.6.0
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 16 Nov 2008 09:58:48 +0000 |
parents | fae699fece1f |
children | 284fd17c6020 |
comparison
equal
deleted
inserted
replaced
24394:fae699fece1f | 24396:38a2f78f80a7 |
---|---|
54 #include "prpl.h" | 54 #include "prpl.h" |
55 #include "request.h" | 55 #include "request.h" |
56 #include "signals.h" | 56 #include "signals.h" |
57 #include "util.h" | 57 #include "util.h" |
58 | 58 |
59 #include "gtkaccount.h" | |
60 #include "gtkprefs.h" | |
61 | |
59 #include "gtkconv.h" | 62 #include "gtkconv.h" |
60 #include "gtkdialogs.h" | 63 #include "gtkdialogs.h" |
61 #include "gtkimhtml.h" | 64 #include "gtkimhtml.h" |
62 #include "gtkimhtmltoolbar.h" | 65 #include "gtkimhtmltoolbar.h" |
63 #include "pidginstock.h" | 66 #include "pidginstock.h" |
78 purple_notify_uri(NULL, data); | 81 purple_notify_uri(NULL, data); |
79 g_free(data); | 82 g_free(data); |
80 return FALSE; | 83 return FALSE; |
81 } | 84 } |
82 | 85 |
83 static void | 86 static gboolean |
84 url_clicked_cb(GtkWidget *w, const char *uri) | 87 url_clicked_cb(GtkIMHtml *imhtml, const char *uri) |
85 { | 88 { |
86 g_idle_add(url_clicked_idle_cb, g_strdup(uri)); | 89 g_idle_add(url_clicked_idle_cb, g_strdup(uri)); |
90 return TRUE; | |
87 } | 91 } |
88 | 92 |
89 static GtkIMHtmlFuncs gtkimhtml_cbs = { | 93 static GtkIMHtmlFuncs gtkimhtml_cbs = { |
90 (GtkIMHtmlGetImageFunc)purple_imgstore_find_by_id, | 94 (GtkIMHtmlGetImageFunc)purple_imgstore_find_by_id, |
91 (GtkIMHtmlGetImageDataFunc)purple_imgstore_get_data, | 95 (GtkIMHtmlGetImageDataFunc)purple_imgstore_get_data, |
99 pidgin_setup_imhtml(GtkWidget *imhtml) | 103 pidgin_setup_imhtml(GtkWidget *imhtml) |
100 { | 104 { |
101 PangoFontDescription *desc = NULL; | 105 PangoFontDescription *desc = NULL; |
102 g_return_if_fail(imhtml != NULL); | 106 g_return_if_fail(imhtml != NULL); |
103 g_return_if_fail(GTK_IS_IMHTML(imhtml)); | 107 g_return_if_fail(GTK_IS_IMHTML(imhtml)); |
104 | |
105 g_signal_connect(G_OBJECT(imhtml), "url_clicked", | |
106 G_CALLBACK(url_clicked_cb), NULL); | |
107 | 108 |
108 pidgin_themes_smiley_themeize(imhtml); | 109 pidgin_themes_smiley_themeize(imhtml); |
109 | 110 |
110 gtk_imhtml_set_funcs(GTK_IMHTML(imhtml), >kimhtml_cbs); | 111 gtk_imhtml_set_funcs(GTK_IMHTML(imhtml), >kimhtml_cbs); |
111 | 112 |
3478 g_object_ref(pixbuf); | 3479 g_object_ref(pixbuf); |
3479 g_object_unref(loader); | 3480 g_object_unref(loader); |
3480 return pixbuf; | 3481 return pixbuf; |
3481 } | 3482 } |
3482 | 3483 |
3484 /* XXX: The following two functions are for demonstration purposes only! */ | |
3485 static gboolean | |
3486 open_dialog(GtkIMHtml *imhtml, const char *url) | |
3487 { | |
3488 const char *str; | |
3489 | |
3490 if (strlen(url) < sizeof("open://")) | |
3491 return FALSE; | |
3492 | |
3493 str = url + sizeof("open://") - 1; | |
3494 | |
3495 if (strcmp(str, "accounts") == 0) | |
3496 pidgin_accounts_window_show(); | |
3497 else if (strcmp(str, "prefs") == 0) | |
3498 pidgin_prefs_show(); | |
3499 else | |
3500 return FALSE; | |
3501 return TRUE; | |
3502 } | |
3503 | |
3504 static gboolean | |
3505 dummy(GtkIMHtml *imhtml, const char *text, GtkWidget *menu) | |
3506 { | |
3507 return TRUE; | |
3508 } | |
3509 | |
3510 void pidgin_utils_init(void) | |
3511 { | |
3512 gtk_imhtml_class_register_protocol("http://", url_clicked_cb, NULL); | |
3513 gtk_imhtml_class_register_protocol("https://", url_clicked_cb, NULL); | |
3514 gtk_imhtml_class_register_protocol("ftp://", url_clicked_cb, NULL); | |
3515 | |
3516 gtk_imhtml_class_register_protocol("open://", open_dialog, dummy); | |
3517 } | |
3518 | |
3519 void pidgin_utils_uninit(void) | |
3520 { | |
3521 gtk_imhtml_class_register_protocol("http://", NULL, NULL); | |
3522 gtk_imhtml_class_register_protocol("https://", NULL, NULL); | |
3523 gtk_imhtml_class_register_protocol("ftp://", NULL, NULL); | |
3524 | |
3525 gtk_imhtml_class_register_protocol("open://", NULL, NULL); | |
3526 } | |
3527 |