changeset 7538:357eb1c39b72

[gaim-migrate @ 8151] Robot101 made a nice patch (which I modified just slightly) to put our gtkspell attachment function that we use all throughout gaim into a utility function, which handles error checking and only does anything if gtkspell support is compiled in. It lets us remove a lot of #ifdef USE_GTKSPELL from places, and doesn't change any functionality. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 17 Nov 2003 06:48:01 +0000
parents 083427fd8ba8
children d519d7940db5
files ChangeLog src/buddy_chat.c src/dialogs.c src/gtkconv.c src/gtkrequest.c src/gtkutils.c src/gtkutils.h src/main.c
diffstat 8 files changed, 65 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Nov 17 06:44:05 2003 +0000
+++ b/ChangeLog	Mon Nov 17 06:48:01 2003 +0000
@@ -13,6 +13,7 @@
 	* The border on the close buttons on inactive tabs are no longer shown,
 	  thanks to a fix used by Galeon.
 	* Compatible with autoconf 2.58.
+	* Cleaned up gtkspell-related code (Robert McQueen)
 	* Changed the parameters for the received-chat-msg signal.
 	* Chinese (Simplified) translation updated (Funda Wang)
 	* Chinese (Traditional) translation updated (Ambrose C. Li)
--- a/src/buddy_chat.c	Mon Nov 17 06:44:05 2003 +0000
+++ b/src/buddy_chat.c	Mon Nov 17 06:48:01 2003 +0000
@@ -30,10 +30,6 @@
 #include "gtkutils.h"
 #include "ui.h"
 
-#ifdef _WIN32
-# include "wspell.h"
-#endif
-
 static GList *chatentries = NULL;
 static GtkWidget *joinchat = NULL;
 static GtkWidget *jc_vbox = NULL;
--- a/src/dialogs.c	Mon Nov 17 06:44:05 2003 +0000
+++ b/src/dialogs.c	Mon Nov 17 06:48:01 2003 +0000
@@ -38,17 +38,9 @@
 
 #include "ui.h"
 
-#ifdef USE_GTKSPELL
-# include <gtkspell/gtkspell.h>
-#endif
-
 /* XXX */
 #include "gaim.h"
 
-#ifdef _WIN32
-# include "wspell.h"
-#endif
-
 static GtkWidget *imdialog = NULL;	/*I only want ONE of these :) */
 static GList *dialogwindows = NULL;
 static GtkWidget *importdialog;
@@ -871,10 +863,10 @@
 
 	b->text = gtk_text_view_new();
 	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(b->text), GTK_WRAP_WORD_CHAR);
-#ifdef USE_GTKSPELL
+
 	if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
-		gtkspell_new_attach(GTK_TEXT_VIEW(b->text), NULL, NULL);
-#endif
+		gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(b->text));
+
 	gtk_widget_set_size_request(b->text, 300, 200);
 
 	if ((user_info = gaim_account_get_user_info(account)) != NULL) {
@@ -1517,10 +1509,8 @@
 	ca->text = gtk_text_view_new();
 	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(ca->text), GTK_WRAP_WORD_CHAR);
 
-#ifdef USE_GTKSPELL
- 	if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
-		gtkspell_new_attach(GTK_TEXT_VIEW(ca->text), NULL, NULL);
-#endif
+	if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
+		gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(ca->text));
 
 	gtk_container_add(GTK_CONTAINER(frame), ca->text);
 
--- a/src/gtkconv.c	Mon Nov 17 06:44:05 2003 +0000
+++ b/src/gtkconv.c	Mon Nov 17 06:48:01 2003 +0000
@@ -27,6 +27,9 @@
 
 #ifdef USE_GTKSPELL
 # include <gtkspell/gtkspell.h>
+# ifdef _WIN32
+#  include "wspell.h"
+# endif
 #endif
 
 #include <gdk/gdkkeysyms.h>
@@ -58,10 +61,6 @@
 /* XXX */
 #include "gaim.h"
 
-#ifdef _WIN32
-# include "wspell.h"
-#endif
-
 #define AUTO_RESPONSE "&lt;AUTO-REPLY&gt; : "
 
 static char nick_colors[][8] = {
@@ -3652,10 +3651,8 @@
 	g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event",
 					 G_CALLBACK(entry_key_pressed_cb_2), conv);
 
-#ifdef USE_GTKSPELL
 	if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
-		gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL);
-#endif
+		gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry));
 
 	gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(gtkconv->entry));
 	gtk_widget_show(gtkconv->entry);
@@ -3757,10 +3754,8 @@
 	g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "delete_range",
 					 G_CALLBACK(delete_text_cb), conv);
 
-#ifdef USE_GTKSPELL
 	if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
-		gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL);
-#endif
+		gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry));
 
 	gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(gtkconv->entry));
 	gtk_widget_show(gtkconv->entry);
@@ -5895,7 +5890,7 @@
 		gtkconv = GAIM_GTK_CONVERSATION(conv);
 
 		if (value)
-			gtkspell_new_attach(GTK_TEXT_VIEW(gtkconv->entry), NULL, NULL);
+			gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(gtkconv->entry));
 		else {
 			spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(gtkconv->entry));
 			gtkspell_detach(spell);
--- a/src/gtkrequest.c	Mon Nov 17 06:44:05 2003 +0000
+++ b/src/gtkrequest.c	Mon Nov 17 06:48:01 2003 +0000
@@ -30,13 +30,6 @@
 #include "stock.h"
 #include "ui.h"
 
-#ifdef USE_GTKSPELL
-# include <gtkspell/gtkspell.h>
-# ifdef _WIN32
-#  include "wspell.h"
-# endif
-#endif
-
 typedef struct
 {
 	GaimRequestType type;
@@ -307,10 +300,8 @@
 		gtk_text_view_set_editable(GTK_TEXT_VIEW(entry), TRUE);
 		gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(entry), GTK_WRAP_WORD_CHAR);
 
-#ifdef USE_GTKSPELL
 		if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
-			gtkspell_new_attach(GTK_TEXT_VIEW(entry), NULL, NULL);
-#endif
+			gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(entry));
 
 		gtk_container_add(GTK_CONTAINER(sw), entry);
 
@@ -648,14 +639,11 @@
 						gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview),
 													GTK_WRAP_WORD_CHAR);
 
-#ifdef USE_GTKSPELL
 						if (gaim_prefs_get_bool(
 								"/gaim/gtk/conversations/spellcheck"))
 						{
-							gtkspell_new_attach(GTK_TEXT_VIEW(textview),
-												NULL, NULL);
+							gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(textview));
 						}
-#endif
 
 						gtk_container_add(GTK_CONTAINER(widget), textview);
 						gtk_widget_show(textview);
--- a/src/gtkutils.c	Mon Nov 17 06:44:05 2003 +0000
+++ b/src/gtkutils.c	Mon Nov 17 06:48:01 2003 +0000
@@ -30,6 +30,13 @@
 # endif
 #endif /*_WIN32*/
 
+#ifdef USE_GTKSPELL
+# include <gtkspell/gtkspell.h>
+# ifdef _WIN32
+#  include "wspell.h"
+# endif
+#endif
+
 #include <gdk/gdkkeysyms.h>
 
 #include "debug.h"
@@ -45,10 +52,6 @@
 #include "gtkutils.h"
 #include "ui.h"
 
-#ifdef _WIN32
-#include "wspell.h"
-#endif
-
 guint accels_save_timer = 0;
 
 static void
@@ -1029,7 +1032,9 @@
 	return buf;
 }
 
-void gaim_gtk_find_images(const char *message, GSList **list) {
+void
+gaim_gtk_find_images(const char *message, GSList **list)
+{
 	GData *attribs;
 	const char *tmp, *start, *end;
 
@@ -1081,6 +1086,25 @@
 }
 
 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)
+	{
+		gaim_debug_warning("gtkspell", "Failed to setup GtkSpell: %s\n",
+						   error->message);
+		g_error_free(error);
+	}
+#endif /* USE_GTKSPELL */
+}
+
+void
 gaim_gtk_save_accels_cb(GtkAccelGroup *accel_group, guint arg1,
 														 GdkModifierType arg2, GClosure *arg3,
 														 gpointer data)
--- a/src/gtkutils.h	Mon Nov 17 06:44:05 2003 +0000
+++ b/src/gtkutils.h	Mon Nov 17 06:48:01 2003 +0000
@@ -273,6 +273,16 @@
 void gaim_gtk_find_images(const char *message, GSList **list);
 
 /**
+ * Sets up GtkSpell for the given GtkTextView, reporting errors
+ * if encountered.
+ *
+ * This does nothing if Gaim is not compiled with GtkSpell support.
+ *
+ * @param textview The textview widget to setup spellchecking for.
+ */
+void gaim_gtk_setup_gtkspell(GtkTextView *textview);
+
+/**
  * Stylizes the specified text using HTML, according to the current
  * font options.
  *
@@ -290,8 +300,8 @@
  * Save menu accelerators callback
  */
 void gaim_gtk_save_accels_cb(GtkAccelGroup *accel_group, guint arg1,
-														 GdkModifierType arg2, GClosure *arg3,
-														 gpointer data);
+							 GdkModifierType arg2, GClosure *arg3,
+							 gpointer data);
 
 /**
  * Save menu accelerators
--- a/src/main.c	Mon Nov 17 06:44:05 2003 +0000
+++ b/src/main.c	Mon Nov 17 06:48:01 2003 +0000
@@ -501,8 +501,9 @@
 	gaim_privacy_set_ui_ops(gaim_gtk_privacy_get_ui_ops());
 	gaim_request_set_ui_ops(gaim_gtk_request_get_ui_ops());
 	gaim_sound_set_ui_ops(gaim_gtk_sound_get_ui_ops());
-       	gaim_connections_set_ui_ops(gaim_gtk_connections_get_ui_ops());
+	gaim_connections_set_ui_ops(gaim_gtk_connections_get_ui_ops());
 
+	gaim_gtk_stock_init();
 	gaim_gtk_prefs_init();
 	gaim_gtk_blist_init();
 	gaim_gtk_conversations_init();
@@ -759,8 +760,7 @@
 	   }
 	 */
 
-	gtk_set_locale();
-	gui_check=gtk_init_check(&argc, &argv);
+	gui_check = gtk_init_check(&argc, &argv);
 
 	/* scan command-line options */
 	opterr = 1;
@@ -816,15 +816,14 @@
 		return 0;
 	}
 
-#if GTK_CHECK_VERSION(2,2,0)
-	if(! gui_check) {
-	    const char *display_name_arg = gdk_get_display_arg_name ();
-	    g_warning ("cannot open display: %s", display_name_arg ? display_name_arg : " ");
-	    return 1;
+	if (!gui_check) {
+		char *display = gdk_get_display();
+
+		g_warning("cannot open display: %s", display ? display : "unset");
+		g_free(display);
+
+		return 1;
 	}
-#endif
-
-	gaim_gtk_stock_init();
 
 #ifdef _WIN32
         wgaim_init(hint);