From: Mike H. <mi...@pl...> - 2005-11-08 13:05:35
|
Hi, Changes since the last patch: * Improve checking (it didn't seem to be necessary in my tests, but can't hurt) * Make the pref disabled when gtkspell isn't found * Add a new API to see if gtkspell is available or not * Re-arrange the spelling code a bit * Use GModule instead of dlopen The last item is worth a note: the GModule API seems not so well designed, and required making the patch a bit uglier to avoid GCC strict aliasing warnings. The patch is in the tracker, here: https://sourceforge.net/tracker/index.php?func=detail&aid=1351190&group_id=235&atid=300235 thanks -mike ------------------------------------------------------------------------- Index: configure.ac =================================================================== RCS file: /cvsroot/gaim/gaim/configure.ac,v retrieving revision 1.333 diff -u -p -d -r1.333 configure.ac --- configure.ac 2 Nov 2005 13:43:50 -0000 1.333 +++ configure.ac 8 Nov 2005 13:00:05 -0000 @@ -1274,7 +1274,6 @@ if test "$enable_gtkspell" = yes ; then PKG_CHECK_MODULES(GTKSPELL, gtkspell-2.0 >= 2.0.2, , enable_gtkspell=no) if test "$enable_gtkspell" = "yes" ; then AC_SUBST(GTKSPELL_CFLAGS) - AC_SUBST(GTKSPELL_LIBS) AC_DEFINE(USE_GTKSPELL,,[do we have gtkspell?]) fi fi Index: src/Makefile.am =================================================================== RCS file: /cvsroot/gaim/gaim/src/Makefile.am,v retrieving revision 1.218 diff -u -p -d -r1.218 Makefile.am --- src/Makefile.am 30 Oct 2005 23:00:47 -0000 1.218 +++ src/Makefile.am 8 Nov 2005 13:00:05 -0000 @@ -340,7 +340,6 @@ gaim_LDADD = \ $(XSS_LIBS) \ $(SM_LIBS) \ $(INTLLIBS) \ - $(GTKSPELL_LIBS) \ $(STARTUP_NOTIFICATION_LIBS) AM_CPPFLAGS = \ Index: src/gtkconv.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkconv.c,v retrieving revision 1.648 diff -u -p -d -r1.648 gtkconv.c --- src/gtkconv.c 31 Oct 2005 22:55:16 -0000 1.648 +++ src/gtkconv.c 8 Nov 2005 13:00:07 -0000 @@ -5386,10 +5386,8 @@ spellcheck_pref_cb(const char *name, Gai if (value) gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry)); - else { - spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(gtkconv->entry)); - gtkspell_detach(spell); - } + else + gaim_gtk_unsetup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry)); } #endif } Index: src/gtkprefs.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkprefs.c,v retrieving revision 1.297 diff -u -p -d -r1.297 gtkprefs.c --- src/gtkprefs.c 5 Nov 2005 23:42:35 -0000 1.297 +++ src/gtkprefs.c 8 Nov 2005 13:00:08 -0000 @@ -798,6 +798,7 @@ conv_page() GtkWidget *vbox2; GtkWidget *iconpref1; GtkWidget *iconpref2; + GtkWidget *spellpref; ret = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); gtk_container_set_border_width(GTK_CONTAINER(ret), GAIM_HIG_BORDER); @@ -820,10 +821,15 @@ conv_page() gaim_gtk_prefs_checkbox(_("_Notify buddies that you are typing to them"), "/core/conversations/im/send_typing", vbox); -#ifdef USE_GTKSPELL - gaim_gtk_prefs_checkbox(_("_Highlight misspelled words"), - "/gaim/gtk/conversations/spellcheck", vbox); -#endif + + spellpref = gaim_gtk_prefs_checkbox(_("_Highlight misspelled words"), + "/gaim/gtk/conversations/spellcheck", vbox); + + if (!gaim_gtk_is_gtkspell_available()) + { + gtk_widget_set_sensitive(spellpref, FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(spellpref), FALSE); + } frame = gaim_gtk_create_imhtml(TRUE, &imhtml, &toolbar); gtk_widget_set_name(imhtml, "gaim_gtkprefs_font_imhtml"); Index: src/gtkutils.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkutils.c,v retrieving revision 1.122 diff -u -p -d -r1.122 gtkutils.c --- src/gtkutils.c 28 Oct 2005 23:12:04 -0000 1.122 +++ src/gtkutils.c 8 Nov 2005 13:00:08 -0000 @@ -897,25 +897,94 @@ char *stylize(const gchar *text, int len return buf; } + +#ifdef USE_GTKSPELL +static GtkSpell* (*gtkspell_get_from_text_view_ptr)(GtkTextView *view); +static void (*gtkspell_detach_ptr)(GtkSpell *spell); +static GtkSpell* (*gtkspell_new_attach_ptr)(GtkTextView *view, const gchar *lang, GError **error); +static int gtkspell_available = -1; /* -1 unknown, 0 false, 1 true */ + +static void +setup_gtkspell() +{ + GModule *handle = g_module_open("libgtkspell.so.0", G_MODULE_BIND_LAZY); + if (handle) + { + gpointer ptr; /* squash GCC strict aliasing warnings */ + + g_module_symbol(handle, "gtkspell_new_attach", &ptr); + gtkspell_new_attach_ptr = ptr; + + g_module_symbol(handle, "gtkspell_detach", &ptr); + gtkspell_detach_ptr = ptr; + + g_module_symbol(handle, "gtkspell_get_from_text_view", &ptr); + gtkspell_get_from_text_view_ptr = ptr; + + gtkspell_available = TRUE; + } + else + { + gaim_debug_warning("gtkspell", "Failed to load libgtkspell.so.0: %s\n", dlerror()); + gtkspell_available = FALSE; + } +} + +gboolean +gaim_gtk_is_gtkspell_available() +{ + if (gtkspell_available == -1) setup_gtkspell(); + return gtkspell_available; +} + +void +gaim_gtk_unsetup_gtkspell(GtkTextView *textview) +{ + GtkSpell *spell; + + if (!gtkspell_available) return; + + spell = gtkspell_get_from_text_view_ptr(textview); + gtkspell_detach_ptr(spell); +} + void gaim_gtk_setup_gtkspell(GtkTextView *textview) { -#ifdef USE_GTKSPELL GError *error = NULL; char *locale = NULL; g_return_if_fail(textview != NULL); g_return_if_fail(GTK_IS_TEXT_VIEW(textview)); - if (gtkspell_new_attach(textview, locale, &error) == NULL && error) + if (!gaim_gtk_is_gtkspell_available()) return; + + if (gtkspell_new_attach_ptr(textview, locale, &error) == NULL && error) { - gaim_debug_warning("gtkspell", "Failed to setup GtkSpell: %s\n", - error->message); + gaim_debug_warning("gtkspell", "Failed to setup GtkSpell: %s\n", error->message); g_error_free(error); } -#endif /* USE_GTKSPELL */ } +#else /* USE_GTKSPELL */ + +void +gaim_gtk_unsetup_gtkspell(GtkTextView *textview) +{ +} + +void +gaim_gtk_setup_gtkspell(GtkTextView *textview) +{ +} + +gboolean +gaim_gtk_is_gtkspell_available() +{ + return FALSE; +} +#endif + void gaim_gtk_save_accels_cb(GtkAccelGroup *accel_group, guint arg1, GdkModifierType arg2, GClosure *arg3, Index: src/gtkutils.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkutils.h,v retrieving revision 1.50 diff -u -p -d -r1.50 gtkutils.h --- src/gtkutils.h 28 Oct 2005 23:16:37 -0000 1.50 +++ src/gtkutils.h 8 Nov 2005 13:00:08 -0000 @@ -263,12 +263,30 @@ gboolean gaim_gtk_check_if_dir(const cha * if encountered. * * This does nothing if Gaim is not compiled with GtkSpell support. + * It also does nothing if libgtkspell.so.0 cannot be located at runtime. * * @param textview The textview widget to setup spellchecking for. */ void gaim_gtk_setup_gtkspell(GtkTextView *textview); /** + * Returns TRUE if Gaim was compiled with GtkSpell support and the + * library is available at runtime. + */ +gboolean gaim_gtk_is_gtkspell_available(); + +/** + * Does the inverse of gaim_gtk_setup_gtkspell, detaching the spelling + * checker from the text view widget. + * + * Does nothing if Gaim is not compiled with GtkSpell support, or + * the GtkSpell library cannot be located at runtime. + * + * @param textview The textview widget to unsetup spellchecking for. + */ +void gaim_gtk_unsetup_gtkspell(GtkTextView *textview); + +/** * Stylizes the specified text using HTML, according to the current * font options. * |