almanah r127 - in trunk: . data src



Author: pwithnall
Date: Wed Jan 14 23:13:33 2009
New Revision: 127
URL: http://svn.gnome.org/viewvc/almanah?rev=127&view=rev

Log:
2009-01-14  Philip Withnall  <philip tecnocode co uk>

	* data/almanah.schemas.in:
	* src/main-window.c (almanah_main_window_new),
	(mw_preferences_activate_cb),
	(almanah_main_window_enable_spell_checking),
	(almanah_main_window_disable_spell_checking):
	* src/main-window.h:
	* src/main.c (main):
	* src/preferences-dialog.c (almanah_preferences_dialog_init),
	(almanah_preferences_dialog_dispose),
	(almanah_preferences_dialog_new),
	(spell_checking_enabled_notify_cb),
	(pd_spell_checking_enabled_check_button_toggled_cb):
	Allow spell checking to be disabled at runtime with a GConf 
option.
	(Closes: #567359)



Modified:
   trunk/ChangeLog
   trunk/data/almanah.schemas.in
   trunk/src/main-window.c
   trunk/src/main-window.h
   trunk/src/main.c
   trunk/src/preferences-dialog.c

Modified: trunk/data/almanah.schemas.in
==============================================================================
--- trunk/data/almanah.schemas.in	(original)
+++ trunk/data/almanah.schemas.in	Wed Jan 14 23:13:33 2009
@@ -23,6 +23,17 @@
 			</locale>
 		</schema>
 		<schema>
+			<key>/schemas/apps/almanah/spell_checking_enabled</key>
+			<applyto>/apps/almanah/spell_checking_enabled</applyto>
+			<owner>almanah</owner>
+			<type>bool</type>
+			<default>true</default>
+			<locale name="C">
+				<short>Spell checking enabled?</short>
+				<long>Whether spell checking of entries is enabled.</long>
+			</locale>
+		</schema>
+		<schema>
 			<key>/schemas/apps/almanah/state/main_window_maximized</key>
 			<applyto>/apps/almanah/state/main_window_maximized</applyto>
 			<owner>almanah</owner>

Modified: trunk/src/main-window.c
==============================================================================
--- trunk/src/main-window.c	(original)
+++ trunk/src/main-window.c	Wed Jan 14 23:13:33 2009
@@ -123,10 +123,6 @@
 	AlmanahMainWindow *main_window;
 	AlmanahMainWindowPrivate *priv;
 	GError *error = NULL;
-#ifdef ENABLE_SPELL_CHECKING
-	GtkSpell *gtkspell;
-	gchar *spelling_language;
-#endif /* ENABLE_SPELL_CHECKING */
 	const gchar *interface_filename = almanah_get_interface_filename ();
 	const gchar *object_names[] = {
 		"almanah_main_window",
@@ -189,28 +185,9 @@
 	almanah_interface_create_text_tags (priv->entry_buffer, TRUE);
 
 #ifdef ENABLE_SPELL_CHECKING
-	/* Set up spell checking */
-	spelling_language = gconf_client_get_string (almanah->gconf_client, "/apps/almanah/spelling_language", NULL);
-
-	/* Make sure it's either NULL or a proper locale specifier */
-	if (spelling_language != NULL && spelling_language[0] == '\0') {
-		g_free (spelling_language);
-		spelling_language = NULL;
-	}
-
-	gtkspell = gtkspell_new_attach (priv->entry_view, spelling_language, &error);
-	g_free (spelling_language);
-
-	if (gtkspell == NULL) {
-		GtkWidget *dialog = gtk_message_dialog_new (NULL,
-							    GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
-							    _("Spelling checker could not be initialized"));
-		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
-		gtk_dialog_run (GTK_DIALOG (dialog));
-		gtk_widget_destroy (dialog);
-
-		g_error_free (error);
-	}
+	/* Set up spell checking, if it's enabled */
+	if (gconf_client_get_bool (almanah->gconf_client, "/apps/almanah/spell_checking_enabled", NULL) == TRUE)
+		almanah_main_window_enable_spell_checking (main_window, NULL);
 #endif /* ENABLE_SPELL_CHECKING */
 
 	/* Make sure we're notified if the cursor moves position so we can check the tag stack */
@@ -251,8 +228,10 @@
 	almanah_interface_embolden_label (GTK_LABEL (gtk_builder_get_object (builder, "almanah_mw_events_label")));
 
 #ifndef ENABLE_ENCRYPTION
+#ifndef ENABLE_SPELL_CHECKING
 	/* Remove the "Preferences" entry from the menu */
 	gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_preferences")), FALSE);
+#endif /* !ENABLE_SPELL_CHECKING */
 #endif /* !ENABLE_ENCRYPTION */
 
 	g_object_unref (builder);
@@ -735,10 +714,8 @@
 void
 mw_preferences_activate_cb (GtkAction *action, gpointer user_data)
 {
-#ifdef ENABLE_ENCRYPTION
 	gtk_widget_show_all (almanah->preferences_dialog);
 	gtk_dialog_run (GTK_DIALOG (almanah->preferences_dialog));
-#endif /* ENABLE_ENCRYPTION */
 }
 
 static void
@@ -1086,3 +1063,39 @@
 	 * probably easier to just reload the current entry, though. */
 	mw_calendar_day_selected_cb (main_window->priv->calendar, main_window);
 }
+
+#ifdef ENABLE_SPELL_CHECKING
+gboolean
+almanah_main_window_enable_spell_checking (AlmanahMainWindow *self, GError **error)
+{
+	GtkSpell *gtkspell;
+	gchar *spelling_language;
+
+	spelling_language = gconf_client_get_string (almanah->gconf_client, "/apps/almanah/spelling_language", NULL);
+
+	/* Make sure it's either NULL or a proper locale specifier */
+	if (spelling_language != NULL && spelling_language[0] == '\0') {
+		g_free (spelling_language);
+		spelling_language = NULL;
+	}
+
+	gtkspell = gtkspell_new_attach (self->priv->entry_view, spelling_language, error);
+	g_free (spelling_language);
+
+	if (gtkspell == NULL)
+		return FALSE;
+	return TRUE;
+}
+
+void
+almanah_main_window_disable_spell_checking (AlmanahMainWindow *self)
+{
+	GtkSpell *gtkspell;
+
+	gtkspell = gtkspell_get_from_text_view (self->priv->entry_view);
+	if (gtkspell != NULL) {
+		gtkspell_detach (gtkspell);
+		g_object_unref (gtkspell);
+	}
+}
+#endif /* ENABLE_SPELL_CHECKING */

Modified: trunk/src/main-window.h
==============================================================================
--- trunk/src/main-window.h	(original)
+++ trunk/src/main-window.h	Wed Jan 14 23:13:33 2009
@@ -20,6 +20,7 @@
 #ifndef ALMANAH_MAIN_WINDOW_H
 #define ALMANAH_MAIN_WINDOW_H
 
+#include <config.h>
 #include <glib.h>
 #include <glib-object.h>
 
@@ -45,7 +46,12 @@
 
 GType almanah_main_window_get_type (void);
 AlmanahMainWindow *almanah_main_window_new (void);
+
 void almanah_main_window_select_date (AlmanahMainWindow *self, GDate *date);
+#ifdef ENABLE_SPELL_CHECKING
+gboolean almanah_main_window_enable_spell_checking (AlmanahMainWindow *self, GError **error);
+void almanah_main_window_disable_spell_checking (AlmanahMainWindow *self);
+#endif /* ENABLE_SPELL_CHECKING */
 
 G_END_DECLS
 

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Wed Jan 14 23:13:33 2009
@@ -131,6 +131,7 @@
 
 	/* Open GConf */
 	almanah->gconf_client = gconf_client_get_default ();
+	gconf_client_add_dir (almanah->gconf_client, "/apps/almanah", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
 
 	/* Ensure the DB directory exists */
 	if (g_file_test (g_get_user_data_dir (), G_FILE_TEST_IS_DIR) == FALSE)

Modified: trunk/src/preferences-dialog.c
==============================================================================
--- trunk/src/preferences-dialog.c	(original)
+++ trunk/src/preferences-dialog.c	Wed Jan 14 23:13:33 2009
@@ -40,7 +40,11 @@
 static void pd_key_combo_changed_cb (GtkComboBox *combo_box, AlmanahPreferencesDialog *preferences_dialog);
 static void pd_new_key_button_clicked_cb (GtkButton *button, AlmanahPreferencesDialog *preferences_dialog);
 #endif /* ENABLE_ENCRYPTION */
+#ifdef ENABLE_SPELL_CHECKING
 static void pd_response_cb (GtkDialog *dialog, gint response_id, AlmanahPreferencesDialog *preferences_dialog);
+static void spell_checking_enabled_notify_cb (GConfClient *client, guint connection_id, GConfEntry *entry, AlmanahPreferencesDialog *self);
+static void pd_spell_checking_enabled_check_button_toggled_cb (GtkToggleButton *toggle_button, gpointer user_data);
+#endif /* ENABLE_SPELL_CHECKING */
 
 struct _AlmanahPreferencesDialogPrivate {
 #ifdef ENABLE_ENCRYPTION
@@ -48,6 +52,10 @@
 	CryptUIKeyStore *key_store;
 	GtkComboBox *key_combo;
 #endif /* ENABLE_ENCRYPTION */
+#ifdef ENABLE_SPELL_CHECKING
+	guint spell_checking_enabled_id;
+	GtkCheckButton *spell_checking_enabled_check_button;
+#endif /* ENABLE_SPELL_CHECKING */
 };
 
 G_DEFINE_TYPE (AlmanahPreferencesDialog, almanah_preferences_dialog, GTK_TYPE_DIALOG)
@@ -70,7 +78,8 @@
 	gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
 	gtk_window_set_modal (GTK_WINDOW (self), FALSE);
 	gtk_window_set_title (GTK_WINDOW (self), _("Almanah Preferences"));
-	gtk_widget_set_size_request (GTK_WIDGET (self), 400, 100);
+	gtk_widget_set_size_request (GTK_WIDGET (self), 400, -1);
+	gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
 }
 
 static void
@@ -89,6 +98,9 @@
 		priv->key_store = NULL;
 	}
 #endif /* ENABLE_ENCRYPTION */
+#ifdef ENABLE_SPELL_CHECKING
+	gconf_client_notify_remove (almanah->gconf_client, priv->spell_checking_enabled_id);
+#endif /* ENABLE_SPELL_CHECKING */
 
 	/* Chain up to the parent class */
 	G_OBJECT_CLASS (almanah_preferences_dialog_parent_class)->dispose (object);
@@ -98,10 +110,10 @@
 almanah_preferences_dialog_new (void)
 {
 	GtkBuilder *builder;
+	GtkTable *table;
 #ifdef ENABLE_ENCRYPTION
 	GtkWidget *label, *button;
 	AtkObject *a11y_label, *a11y_key_combo;
-	GtkTable *table;
 	gchar *key;
 #endif /* ENABLE_ENCRYPTION */
 	AlmanahPreferencesDialog *preferences_dialog;
@@ -142,10 +154,10 @@
 	}
 
 	priv = ALMANAH_PREFERENCES_DIALOG (preferences_dialog)->priv;
+	table = GTK_TABLE (gtk_builder_get_object (builder, "almanah_pd_table"));
 
 #ifdef ENABLE_ENCRYPTION
 	/* Grab our child widgets */
-	table = GTK_TABLE (gtk_builder_get_object (builder, "almanah_pd_table"));
 	label = gtk_label_new (_("Encryption Key"));
 	almanah_interface_embolden_label (GTK_LABEL (label));
 	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
@@ -180,6 +192,18 @@
 	g_signal_connect (button, "clicked", G_CALLBACK (pd_new_key_button_clicked_cb), preferences_dialog);
 #endif /* ENABLE_ENCRYPTION */
 
+#ifdef ENABLE_SPELL_CHECKING
+	/* Set up the "Enable spell checking" check button */
+	priv->spell_checking_enabled_check_button = GTK_CHECK_BUTTON (gtk_check_button_new_with_mnemonic (_("Enable _spell checking")));
+	gtk_table_attach_defaults (table, GTK_WIDGET (priv->spell_checking_enabled_check_button), 1, 4, 2, 3);
+
+	spell_checking_enabled_notify_cb (NULL, 0, NULL, preferences_dialog);
+	g_signal_connect (priv->spell_checking_enabled_check_button, "toggled", G_CALLBACK (pd_spell_checking_enabled_check_button_toggled_cb), preferences_dialog);
+	priv->spell_checking_enabled_id = gconf_client_notify_add (almanah->gconf_client, "/apps/almanah/spell_checking_enabled",
+								   (GConfClientNotifyFunc) spell_checking_enabled_notify_cb, preferences_dialog,
+								   NULL, NULL);
+#endif /* ENABLE_SPELL_CHECKING */
+
 	g_object_unref (builder);
 
 	return preferences_dialog;
@@ -234,3 +258,44 @@
 {
 	gtk_widget_hide_all (GTK_WIDGET (dialog));
 }
+
+static void
+spell_checking_enabled_notify_cb (GConfClient *client, guint connection_id, GConfEntry *entry, AlmanahPreferencesDialog *self)
+{
+	gboolean enabled;
+
+	enabled = gconf_client_get_bool (almanah->gconf_client, "/apps/almanah/spell_checking_enabled", NULL);
+
+	if (almanah->debug)
+		g_debug ("spell_checking_enabled_notify_cb called with %u.", enabled);
+
+	g_signal_handlers_block_by_func (self->priv->spell_checking_enabled_check_button, pd_spell_checking_enabled_check_button_toggled_cb, self);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->spell_checking_enabled_check_button), enabled);
+	g_signal_handlers_unblock_by_func (self->priv->spell_checking_enabled_check_button, pd_spell_checking_enabled_check_button_toggled_cb, self);
+
+	if (enabled == TRUE) {
+		GError *error = NULL;
+
+		almanah_main_window_enable_spell_checking (ALMANAH_MAIN_WINDOW (almanah->main_window), &error);
+
+		if (error != NULL) {
+			GtkWidget *dialog = gtk_message_dialog_new (NULL,
+								    GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+								    _("Spelling checker could not be initialized"));
+			gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+			gtk_dialog_run (GTK_DIALOG (dialog));
+			gtk_widget_destroy (dialog);
+
+			g_error_free (error);
+		}
+	} else {
+		almanah_main_window_disable_spell_checking (ALMANAH_MAIN_WINDOW (almanah->main_window));
+	}
+}
+
+static void
+pd_spell_checking_enabled_check_button_toggled_cb (GtkToggleButton *toggle_button, gpointer user_data)
+{
+	gconf_client_set_bool (almanah->gconf_client, "/apps/almanah/spell_checking_enabled",
+			       gtk_toggle_button_get_active (toggle_button), NULL);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]