comparison src/gtkutils.c @ 12061:29dc8fc0dd6c

[gaim-migrate @ 14356] SF Patch #1351190 from Michael Hearn "This allows Linux binaries of Gaim to operate even when GTKspell is not available at runtime. Useful for the autopackages." I made a number of changes to this, so blame me first if it's busted. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sun, 13 Nov 2005 00:19:12 +0000
parents f672349cfc1c
children cb9d1a005aef
comparison
equal deleted inserted replaced
12060:f7d2f637ff03 12061:29dc8fc0dd6c
145 imhtml = gtk_imhtml_new(NULL, NULL); 145 imhtml = gtk_imhtml_new(NULL, NULL);
146 gtk_imhtml_set_editable(GTK_IMHTML(imhtml), editable); 146 gtk_imhtml_set_editable(GTK_IMHTML(imhtml), editable);
147 gtk_imhtml_set_format_functions(GTK_IMHTML(imhtml), GTK_IMHTML_ALL ^ GTK_IMHTML_IMAGE); 147 gtk_imhtml_set_format_functions(GTK_IMHTML(imhtml), GTK_IMHTML_ALL ^ GTK_IMHTML_IMAGE);
148 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); 148 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR);
149 if (editable && gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck")) 149 if (editable && gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
150 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(imhtml)); 150 gaim_gtk_gtkspell_setup(GTK_TEXT_VIEW(imhtml));
151 gtk_widget_show(imhtml); 151 gtk_widget_show(imhtml);
152 152
153 if (editable) { 153 if (editable) {
154 gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(toolbar), imhtml); 154 gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(toolbar), imhtml);
155 gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(toolbar), "default"); 155 gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(toolbar), "default");
895 895
896 g_free(tmp); 896 g_free(tmp);
897 return buf; 897 return buf;
898 } 898 }
899 899
900 #ifdef USE_GTKSPELL
901 static GtkSpell* (*gtkspell_get_from_text_view_ptr)(GtkTextView *view);
902 static void (*gtkspell_detach_ptr)(GtkSpell *spell);
903 static GtkSpell* (*gtkspell_new_attach_ptr)(GtkTextView *view, const gchar *lang, GError **error);
904 static int gtkspell_available = -1; /* -1 unknown, 0 false, 1 true */
905
906 static void
907 setup_gtkspell()
908 {
909 #if GLIB_CHECK_VERSION(2,3,3)
910 GModule *handle = g_module_open("libgtkspell", G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
911 #else
912 GModule *handle = g_module_open("libgtkspell", G_MODULE_BIND_LAZY);
913 #endif
914 if (handle != NULL)
915 {
916 gpointer ptr; /* squash GCC strict aliasing warnings */
917
918 g_module_symbol(handle, "gtkspell_new_attach", &ptr);
919 gtkspell_new_attach_ptr = ptr;
920
921 g_module_symbol(handle, "gtkspell_detach", &ptr);
922 gtkspell_detach_ptr = ptr;
923
924 g_module_symbol(handle, "gtkspell_get_from_text_view", &ptr);
925 gtkspell_get_from_text_view_ptr = ptr;
926
927 gtkspell_available = TRUE;
928 }
929 else
930 {
931 gaim_debug_warning("gtkspell", "Failed to load libgtkspell.so.0: %s\n", dlerror());
932 gtkspell_available = FALSE;
933 }
934 }
935
936 gboolean
937 gaim_gtk_gtkspell_is_available()
938 {
939 if (gtkspell_available == -1)
940 setup_gtkspell();
941
942 return gtkspell_available;
943 }
944
900 void 945 void
901 gaim_gtk_setup_gtkspell(GtkTextView *textview) 946 gaim_gtk_gtkspell_setup(GtkTextView *textview)
902 { 947 {
903 #ifdef USE_GTKSPELL
904 GError *error = NULL; 948 GError *error = NULL;
905 char *locale = NULL; 949 char *locale = NULL;
906 950
907 g_return_if_fail(textview != NULL); 951 g_return_if_fail(textview != NULL);
908 g_return_if_fail(GTK_IS_TEXT_VIEW(textview)); 952 g_return_if_fail(GTK_IS_TEXT_VIEW(textview));
909 953
910 if (gtkspell_new_attach(textview, locale, &error) == NULL && error) 954 if (!gaim_gtk_gtkspell_is_available())
911 { 955 return;
912 gaim_debug_warning("gtkspell", "Failed to setup GtkSpell: %s\n", 956
913 error->message); 957 if (gtkspell_new_attach_ptr(textview, locale, &error) == NULL && error)
958 {
959 gaim_debug_warning("gtkspell", "Failed to setup GtkSpell: %s\n", error->message);
914 g_error_free(error); 960 g_error_free(error);
915 } 961 }
916 #endif /* USE_GTKSPELL */ 962 }
917 } 963
964 void
965 gaim_gtk_gtkspell_unsetup(GtkTextView *textview)
966 {
967 GtkSpell *spell;
968
969 if (!gtkspell_available)
970 return;
971
972 spell = gtkspell_get_from_text_view_ptr(textview);
973 gtkspell_detach_ptr(spell);
974 }
975
976 #else /* !USE_GTKSPELL */
977
978 gboolean
979 gaim_gtk_gtkspell_is_available()
980 {
981 return FALSE;
982 }
983
984 void
985 gaim_gtk_gtkspell_setup(GtkTextView *textview)
986 {
987 }
988
989 void
990 gaim_gtk_gtkspell_unsetup(GtkTextView *textview)
991 {
992 }
993
994 #endif /* !USE_GTKSPELL */
918 995
919 void 996 void
920 gaim_gtk_save_accels_cb(GtkAccelGroup *accel_group, guint arg1, 997 gaim_gtk_save_accels_cb(GtkAccelGroup *accel_group, guint arg1,
921 GdkModifierType arg2, GClosure *arg3, 998 GdkModifierType arg2, GClosure *arg3,
922 gpointer data) 999 gpointer data)