[pan2] * https://bugzilla.gnome.org/show_bug.cgi?id=527688 * cleanups
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2] * https://bugzilla.gnome.org/show_bug.cgi?id=527688 * cleanups
- Date: Sat, 17 Dec 2011 04:13:24 +0000 (UTC)
commit aac97b24238a7d6ecfce850ef004694c25dc137a
Author: Heinrich MÃller <henmull src gnome org>
Date: Sat Dec 17 05:12:38 2011 +0100
* https://bugzilla.gnome.org/show_bug.cgi?id=527688
* cleanups
configure.in | 2 +-
pan/gui/Makefile.am | 4 +-
pan/gui/group-prefs-dialog.cc | 119 +++++++++++++++++++++++++++++++++++++++--
pan/gui/group-prefs-dialog.h | 1 +
pan/gui/post-ui.cc | 45 ++++++++++++++--
pan/gui/post-ui.h | 3 +-
pan/gui/prefs-ui.cc | 15 +++---
pan/gui/prefs.cc | 1 +
pan/gui/prefs.h | 1 +
pan/gui/profiles-dialog.cc | 6 ++-
10 files changed, 175 insertions(+), 22 deletions(-)
---
diff --git a/configure.in b/configure.in
index 6a29f68..9ad975e 100644
--- a/configure.in
+++ b/configure.in
@@ -93,7 +93,7 @@ fi
gtkspell_msg=no
AC_ARG_WITH(gtkspell, AC_HELP_STRING([--with-gtkspell], [Enable gtkspell support]), [want_gtkspell=$withval], [want_gtkspell=yes])
if test "x$want_gtkspell" = "xyes" ; then
- PKG_CHECK_MODULES([GTKSPELL], [gtkspell-2.0 >= $GTKSPELL_REQUIRED],
+ PKG_CHECK_MODULES([GTKSPELL], [gtkspell3-2.0 >= $GTKSPELL_REQUIRED],
[gtkspell_msg=yes
AC_DEFINE(HAVE_GTKSPELL,[1],[Spellcheck Library])],
[gtkspell_msg=no
diff --git a/pan/gui/Makefile.am b/pan/gui/Makefile.am
index 9eef8cf..c36242d 100644
--- a/pan/gui/Makefile.am
+++ b/pan/gui/Makefile.am
@@ -91,9 +91,9 @@ else
WINRC =
WINRCOBJ =
endif
-
+
pan_SOURCES = gui.cc pan.cc $(WINRC)
-pan_LDADD = ./libpangui.a $(WINRCOBJ) ../data-impl/libpandata.a ../tasks/libtasks.a ../data/libdata.a ../usenet-utils/libusenetutils.a ../general/libgeneralutils.a ../../uulib/libuu.a @GTKSPELL_LIBS@ @GTK_LIBS@ @GMIME_LIBS@ @GLIB_LIBS@
+pan_LDADD = ./libpangui.a $(WINRCOBJ) -lenchant ../data-impl/libpandata.a ../tasks/libtasks.a ../data/libdata.a ../usenet-utils/libusenetutils.a ../general/libgeneralutils.a ../../uulib/libuu.a @GTKSPELL_LIBS@ @GTK_LIBS@ @GMIME_LIBS@ @GLIB_LIBS@
if HAVE_WIN32
pan_LDFLAGS = -mwindows
diff --git a/pan/gui/group-prefs-dialog.cc b/pan/gui/group-prefs-dialog.cc
index be50369..926082c 100644
--- a/pan/gui/group-prefs-dialog.cc
+++ b/pan/gui/group-prefs-dialog.cc
@@ -20,7 +20,12 @@
#include <config.h>
extern "C" {
#include <glib/gi18n.h>
+ #include <glib.h>
#include <gtk/gtk.h>
+#ifdef HAVE_GTKSPELL
+ #include <gtkspell/gtkspell.h>
+ #include <enchant/enchant.h>
+#endif
}
#include <pan/general/debug.h>
#include <pan/general/macros.h>
@@ -34,14 +39,54 @@ extern "C" {
using namespace pan;
+
namespace
{
+
+ struct Langs
+ {
+ GList* langs;
+ };
+
+ static void
+ dict_describe_cb(const char * const lang_tag,
+ const char * const provider_name,
+ const char * const provider_desc,
+ const char * const provider_file,
+ void * user_data)
+ {
+ Langs *langs = (Langs *)user_data;
+ langs->langs = g_list_insert_sorted(langs->langs, g_strdup(lang_tag), (GCompareFunc) strcmp);
+ }
+
+ static EnchantBroker *broker = NULL;
+ static GList *langs = NULL;
+ static GtkSpell * spell = NULL;
+ static GtkTextView* view = NULL;
+ Langs l;
+
+ void init_spell()
+ {
+ view = GTK_TEXT_VIEW(gtk_text_view_new());
+ spell = gtkspell_get_from_text_view (view);
+ broker = enchant_broker_init();
+ l.langs = langs;
+ enchant_broker_list_dicts(broker, dict_describe_cb, &l);
+ }
+
+ void deinit_spell()
+ {
+ if (view) g_object_ref_sink(view);
+ if (spell) gtkspell_detach (spell);
+ if (broker) enchant_broker_free(broker);
+ }
+
void delete_dialog (gpointer castme)
{
delete static_cast<GroupPrefsDialog*>(castme);
}
}
-
+
void
GroupPrefsDialog :: save_from_gui ()
{
@@ -60,6 +105,18 @@ GroupPrefsDialog :: save_from_gui ()
// save path...
const char * pch (file_entry_get (_save_path));
_group_prefs.set_string (_group, "default-group-save-path", pch);
+
+ // spellchecker language
+ GtkTreeIter iter;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX(_spellchecker_language), &iter))
+ return;
+
+ gchar* name(0);
+ GtkTreeModel* model = gtk_combo_box_get_model (GTK_COMBO_BOX(_spellchecker_language));
+ gtk_tree_model_get (model, &iter, 0, &name, -1);
+
+ if (name) _group_prefs.set_string (_group, "spellcheck-language", name);
+ g_free(name);
}
void
@@ -105,8 +162,52 @@ namespace
return w;
}
+
+ GtkWidget*
+ create_spellcheck_combo_box ( const Quark & group,
+ const GroupPrefs & group_prefs)
+ {
+
+ init_spell();
+ deinit_spell();
+
+ GtkWidget * w;
+ GtkTreeModel *model;
+ GtkListStore * store = gtk_list_store_new (1, G_TYPE_STRING);
+ GtkTreeIter iter, storeit;
+ bool valid(false);
+
+
+ std::string lang = group_prefs.get_string(group, "spellcheck-language","");
+
+ while (l.langs)
+ {
+ gchar* data = (gchar*)l.langs->data;
+ if (data)
+ {
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, 0, data, -1);
+ if (g_strcmp0 ((const char*)l.langs->data,lang.c_str())==0) { storeit = iter; valid=true; }
+ }
+ l.langs = l.langs->next;
+ }
+ model = GTK_TREE_MODEL(store);
+ w = gtk_combo_box_new_with_model (model);
+
+ GtkCellRenderer * renderer (gtk_cell_renderer_text_new ());
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (w), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (w), renderer, "text", 0, NULL);
+
+ if (valid) gtk_combo_box_set_active_iter (GTK_COMBO_BOX(w), &storeit);
+
+ if (l.langs) g_list_free(l.langs);
+
+ return w;
+ }
+
}
+
GroupPrefsDialog :: GroupPrefsDialog (Data & data,
const Quark & group,
GroupPrefs & group_prefs,
@@ -132,19 +233,29 @@ GroupPrefsDialog :: GroupPrefsDialog (Data & data,
HIG::workarea_add_section_title (t, &row, buf);
HIG :: workarea_add_section_spacer (t, row, 3);
_charset = w = e_charset_combo_box_new( );
- e_charset_combo_box_set_charset( E_CHARSET_COMBO_BOX(_charset), _group_prefs.get_string (group, "character-encoding", "UTF-8").c_str());
+ e_charset_combo_box_set_charset( E_CHARSET_COMBO_BOX(_charset),
+ _group_prefs.get_string (group, "character-encoding", "UTF-8").c_str());
+
HIG :: workarea_add_row (t, &row, _("Character _encoding:"), w);
+ gtk_widget_set_sensitive (w, gtk_widget_get_sensitive(w));
+
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);
+ gtk_widget_set_sensitive (w, gtk_widget_get_sensitive(w));
+
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_get_sensitive(w));
+ gtk_widget_set_sensitive (w, gtk_widget_get_sensitive(w));
+
+ w = _spellchecker_language = create_spellcheck_combo_box ( group, group_prefs);
+ l = HIG :: workarea_add_row (t, &row, _("Spellchecker _language:"), w);
+ gtk_widget_set_sensitive (w, gtk_widget_get_sensitive(w));
- gtk_widget_show_all (t);
gtk_box_pack_start ( GTK_BOX( gtk_dialog_get_content_area( GTK_DIALOG( dialog))), t, true, true, 0);
+ gtk_widget_show_all (t);
_root = dialog;
}
diff --git a/pan/gui/group-prefs-dialog.h b/pan/gui/group-prefs-dialog.h
index 3f5f9de..2d8a671 100644
--- a/pan/gui/group-prefs-dialog.h
+++ b/pan/gui/group-prefs-dialog.h
@@ -44,6 +44,7 @@ namespace pan
GtkWidget * _root;
GtkWidget * _charset;
GtkWidget * _profile;
+ GtkWidget * _spellchecker_language;
GtkWidget * _save_path;
private:
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index f8a416e..6810e6e 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -91,11 +91,29 @@ PostUI :: set_spellcheck_enabled (bool enabled)
#ifdef HAVE_GTKSPELL
GtkTextView * view = GTK_TEXT_VIEW(_body_view);
GError * err (0);
- const char * locale = NULL;
- gtkspell_new_attach (view, locale, &err);
- if (err) {
- Log::add_err_va (_("Error setting spellchecker: %s"), err->message);
- g_clear_error (&err);
+
+ // set the language
+ if(!_spellcheck_language.empty()) // some language was set
+ {
+ gtkspell_new_attach (view, _spellcheck_language.c_str(), &err); // sets custom spell checker
+ if (err) {
+ 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
+ {
+ 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 (
@@ -1957,6 +1975,23 @@ PostUI :: PostUI (GtkWindow * parent,
ua_extra = prefs.get_flag(USER_AGENT_EXTRA_PREFS_KEY, false);
+ #ifdef HAVE_GTKSPELL
+ // set the spellchecker language according to the first destination newsgroup's options
+ StringView line (g_mime_object_get_header ((GMimeObject *) 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;
+ }
+ #endif
+
// create the window
_root = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (_root, "delete-event", G_CALLBACK(delete_event_cb), this);
diff --git a/pan/gui/post-ui.h b/pan/gui/post-ui.h
index 29d1f7b..8e1b130 100644
--- a/pan/gui/post-ui.h
+++ b/pan/gui/post-ui.h
@@ -41,7 +41,7 @@ namespace pan
public:
static PostUI* create_window (GtkWindow*, Data&, Queue&, GroupServer&, Profiles&,
GMimeMessage*, Prefs&, GroupPrefs&);
-
+
protected:
PostUI (GtkWindow*, Data&, Queue&, GroupServer&, Profiles&,
GMimeMessage*, Prefs&, GroupPrefs&);
@@ -112,6 +112,7 @@ namespace pan
str2str_t _profile_headers;
std::string _unchanged_body;
int _wrap_pixels;
+ std::string _spellcheck_language;
private:
void add_actions (GtkWidget* box);
diff --git a/pan/gui/prefs-ui.cc b/pan/gui/prefs-ui.cc
index c88cf4b..2f7cce5 100644
--- a/pan/gui/prefs-ui.cc
+++ b/pan/gui/prefs-ui.cc
@@ -287,7 +287,7 @@ PrefsDialog :: update_default_charset_label(const StringView& value)
g_snprintf(buf, sizeof(buf),_(" Select default <u>global</u> charset. Current setting : <b>%s</b> ."),
value.str);
gtk_label_set_markup(GTK_LABEL(charset_label), buf);
- gtk_widget_show(charset_label);
+ gtk_widget_show_all(charset_label);
}
void
@@ -307,12 +307,13 @@ namespace
void select_prefs_charset_cb (GtkButton *, gpointer user_data)
{
PrefsDialog* pd (static_cast<PrefsDialog*>(user_data));
- char * tmp = e_charset_dialog (_("Character Encoding"),
- _("Global Charset Settings"),
- NULL, GTK_WINDOW(pd->root()));
+ std::string def = pd->prefs().get_string("default-charset", "UTF-8");
+ char * tmp = e_charset_dialog (_("Character Encoding"),
+ _("Global Charset Settings"),
+ def.c_str(), GTK_WINDOW(pd->root()));
- g_return_if_fail(tmp);
- pd->prefs().set_string("default-charset", tmp);
+ if (!tmp) return;
+ pd->prefs().set_string("default-charset", tmp);
}
}
@@ -529,7 +530,7 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
w = gtk_button_new_from_stock (GTK_STOCK_SELECT_FONT);
l = charset_label = gtk_label_new (NULL);
gtk_misc_set_alignment (GTK_MISC(l), 0.0, 0.0);
- update_default_charset_label(_prefs.get_string("default_charset","UTF-8"));
+ update_default_charset_label(_prefs.get_string("default-charset","UTF-8"));
g_signal_connect (w, "clicked", G_CALLBACK(select_prefs_charset_cb), this);
HIG::workarea_add_row (t, &row, w, l);
HIG :: workarea_finish (t, &row);
diff --git a/pan/gui/prefs.cc b/pan/gui/prefs.cc
index 971a1dc..4b2930e 100644
--- a/pan/gui/prefs.cc
+++ b/pan/gui/prefs.cc
@@ -298,6 +298,7 @@ Prefs :: set_string (const StringView& key, const StringView& value)
std::string& lvalue = _strings[key];
const std::string old (lvalue);
lvalue.assign (value.str, value.len);
+
if (old != lvalue)
fire_string_changed (key, value);
}
diff --git a/pan/gui/prefs.h b/pan/gui/prefs.h
index 0969fca..317a573 100644
--- a/pan/gui/prefs.h
+++ b/pan/gui/prefs.h
@@ -22,6 +22,7 @@
#include <map>
#include <set>
+#include <iostream>
#include <string>
#include <vector>
#include <pan/general/string-view.h>
diff --git a/pan/gui/profiles-dialog.cc b/pan/gui/profiles-dialog.cc
index 0b5da19..9ed3742 100644
--- a/pan/gui/profiles-dialog.cc
+++ b/pan/gui/profiles-dialog.cc
@@ -77,7 +77,7 @@ namespace
int port;
std::string addr;
data.get_server_addr (server, addr, port);
-
+
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, addr.c_str(), 1, server.c_str(), -1);
@@ -102,7 +102,7 @@ ProfileDialog :: ProfileDialog (const Data & data,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_APPLY, GTK_RESPONSE_OK,
NULL);
- gtk_dialog_set_default_response (GTK_DIALOG(_root), GTK_RESPONSE_OK);
+ gtk_dialog_set_default_response (GTK_DIALOG(_root), GTK_RESPONSE_OK);
gtk_window_set_role (GTK_WINDOW(_root), "pan-edit-profile-dialog");
int row (0);
@@ -148,9 +148,11 @@ ProfileDialog :: ProfileDialog (const Data & data,
gtk_list_store_set (store, &iter, 0, _("Command"), 1, Profile::COMMAND, -1);
w = _signature_file_combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL(store));
g_signal_connect (_signature_file_check, "toggled", G_CALLBACK(on_sig_file_toggled), w);
+
GtkCellRenderer * renderer (gtk_cell_renderer_text_new ());
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (w), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (w), renderer, "text", 0, NULL);
+
int active = 0;
if (profile.sig_type == profile.TEXT) active = 1;
if (profile.sig_type == profile.COMMAND) active = 2;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]