Hi all,
I've tinkered a bit with Pan's source code and I've managed to implement
support for custom, per-newsgroup spellchecker language.
At the moment GtkSpell v2 doesn't offer a way to produce a list of all
available languages, so it isn't possible to set the language through a nifty
combo box. Fortunately GtkSpell still supports non-system locales as long as
a valid language tag (i.e., "pt_PT") of an available dictionary is specified.
That means that, with this patch, we only need to edit a group's preferences
and manually add the desired language tag in a text entry widget and all is
well. If the user manages to screw things up and enter an invalid language
tag then Pan just goes on with the system locale.
Nonetheless, once GtkSpell v3 is released or if Enchant is added as a
dependency then the whole combo box thingy can be quickly implemented.
Hope this helps,
Rui Maciel
Index: pan/gui/group-prefs-dialog.cc
===================================================================
--- pan/gui/group-prefs-dialog.cc (revision 360)
+++ pan/gui/group-prefs-dialog.cc (working copy)
@@ -73,6 +73,10 @@
// save path...
const char * pch (file_entry_get (_save_path));
_group_prefs.set_string (_group, "default-group-save-path", pch);
+
+ // spellchecker language
+ pch = (const char*)gtk_entry_get_text(GTK_ENTRY(_spellchecker_language));
+ _group_prefs.set_string (_group, "spellcheck-language", pch);
}
void
@@ -118,8 +122,29 @@
return w;
}
+
+ GtkWidget*
+ create_spellcheck_combo_box ( const Quark & group,
+ const GroupPrefs & group_prefs)
+ {
+ /*TODO:
+ * get a list of all the available spellchecking languages (
+ - This depends on GtkSpell or adding enchant as a dependency
+ * list them in a combo box
+ */
+
+ GtkWidget * e = gtk_entry_new ();
+
+ // get the custom spell checking language from the group preferences
+ std::string lang;
+ lang = group_prefs.get_string(group, "spellcheck-language","");
+ gtk_entry_set_text(GTK_ENTRY(e),lang.c_str());
+
+ return e;
}
+}
+
GroupPrefsDialog :: GroupPrefsDialog (Data & data,
const Quark & group,
GroupPrefs & group_prefs,
@@ -144,20 +169,31 @@
g_snprintf (buf, sizeof(buf), _("Properties for %s"), group.c_str());
HIG::workarea_add_section_title (t, &row, buf);
HIG :: workarea_add_section_spacer (t, row, 3);
+
+ /* Character encoding widget */
_charset = e_charset_picker_new (_group_prefs.get_string (group, "character-encoding", "UTF-8").c_str());
w = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (w), _charset);
HIG :: workarea_add_row (t, &row, _("Character _encoding:"), w);
+
+ /* Save path widget */
w = _save_path = file_entry_new (_("Directory for Saving Attachments"));
char * pch = g_build_filename (g_get_home_dir(), "News", NULL);
const std::string dir (_group_prefs.get_string (_group, "default-group-save-path", pch));
g_free (pch);
file_entry_set (w, dir.c_str());
HIG :: workarea_add_row (t, &row, _("Directory for _saving attachments:"), w);
+
+ /* profile widget */
w = _profile = create_profiles_combo_box (data, group, group_prefs);
l = HIG :: workarea_add_row (t, &row, _("Posting _profile:"), w);
gtk_widget_set_sensitive (l, GTK_WIDGET_SENSITIVE(w));
+ /* spellchecker languages widget */
+ w = _spellchecker_language = create_spellcheck_combo_box ( group, group_prefs);
+ l = HIG :: workarea_add_row (t, &row, _("Spellchecker _language:"), w);
+ gtk_widget_set_sensitive (l, GTK_WIDGET_SENSITIVE(w));
+
gtk_widget_show_all (t);
gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), t, true, true, 0);
_root = dialog;
Index: pan/gui/post-ui.h
===================================================================
--- pan/gui/post-ui.h (revision 360)
+++ pan/gui/post-ui.h (working copy)
@@ -112,6 +112,7 @@
std::string _unchanged_body;
int _wrap_pixels;
GtkTooltips * _ttips;
+ std::string _spellcheck_language;
private:
void add_actions (GtkWidget* box);
Index: pan/gui/group-prefs-dialog.h
===================================================================
--- pan/gui/group-prefs-dialog.h (revision 360)
+++ pan/gui/group-prefs-dialog.h (working copy)
@@ -44,6 +44,7 @@
GtkWidget * _root;
GtkWidget * _charset;
GtkWidget * _profile;
+ GtkWidget * _spellchecker_language;
GtkWidget * _save_path;
private:
Index: pan/gui/post-ui.cc
===================================================================
--- pan/gui/post-ui.cc (revision 360)
+++ pan/gui/post-ui.cc (working copy)
@@ -88,12 +88,33 @@
#ifdef HAVE_GTKSPELL
GtkTextView * view = GTK_TEXT_VIEW(_body_view);
GError * err (0);
- const char * locale = NULL;
- gtkspell_new_attach (view, locale, &err);
+
+ // set the language
+ if(!_spellcheck_language.empty()) // some language was set
+ {
+ g_debug("custom spellchecker\n");
+ gtkspell_new_attach (view, _spellcheck_language.c_str(), &err); // sets custom spell checker
if (err) {
+ g_debug("custom spellchecker failed. defaulted to system locale.\n");
+ Log::add_err_va (_("Error setting custom spellchecker: %s"), err->message);
+ g_clear_error (&err);
+ // custom spellchecker failed. defaults to env spellchecker
+ gtkspell_new_attach (view, NULL, &err); // tries default env language
+ if (err) {
Log::add_err_va (_("Error setting spellchecker: %s"), err->message);
g_clear_error (&err);
}
+ }
+ }
+ else
+ {
+ g_debug("default spellchecker\n");
+ gtkspell_new_attach (view, NULL, &err); // tries default env language
+ if (err) {
+ Log::add_err_va (_("Error setting spellchecker: %s"), err->message);
+ g_clear_error (&err);
+ }
+ }
#else
GtkWidget * w = gtk_message_dialog_new_with_markup (
GTK_WINDOW(_root),
@@ -1874,6 +1895,21 @@
g_assert (profiles.has_profiles());
g_return_if_fail (message != 0);
+ // set the spellchecker language according to the first destination newsgroup's options
+ StringView line (g_mime_message_get_header (message, "Newsgroups"));
+ StringView groupname;
+ // get the first newsgroup
+ while (line.pop_token (groupname, ',')) {
+ groupname.trim ();
+ if (groupname.empty())
+ continue;
+ // set the language as defined in the newsgroup's options or, if it doesn't have one, the system locale
+ _spellcheck_language = group_prefs.get_string (groupname, "spellcheck-language", "");
+
+ if (!_spellcheck_language.empty())
+ break;
+ }
+
// create the window
_root = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (_root, "delete-event", G_CALLBACK(delete_event_cb), this);
_______________________________________________
Pan-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/pan-users