#include <prefs_common.h>
#include <utils.h>
+#include <dirent.h>
+
+#include <gtk/gtkoptionmenu.h>
+#include <gtk/gtkmenu.h>
+#include <gtk/gtkmenuitem.h>
+
#include "gtkxtext.h"
+#include "gtkspell.h"
+
/* size of the text buffer used in various word-processing routines. */
#define BUFSIZE 1024
signal(SIGCHLD, sigchld);
#endif
}
+
+/*** Sylpheed (Claws) ***/
+
+static GSList *create_empty_dictionary_list(void)
+{
+ GSList *list = NULL;
+ Dictionary *dict;
+
+ dict = g_new0(Dictionary, 1);
+ dict->name = g_strdup(_("None"));
+ dict->path = NULL;
+ return g_slist_append(list, dict);
+}
+
+/* gtkspell_get_dictionary_list() - returns list of dictionary names and the full
+ * path of file names. */
+GSList *gtkspell_get_dictionary_list(const gchar *ispell_path)
+{
+ GSList *list;
+ gchar *dict_path, *tmp, *prevdir;
+ GSList *walk;
+ Dictionary *dict;
+ DIR *dir;
+ struct dirent *ent;
+
+ list = NULL;
+
+ /* ASSUME: ispell_path is full path */
+ dict_path = strstr(ispell_path + 1, G_DIR_SEPARATOR_S);
+ tmp = g_strndup(ispell_path, dict_path - ispell_path);
+
+ /* ASSUME: ispell dictionaries in PREFIX/lib/ispell */
+ dict_path = g_strconcat(tmp, G_DIR_SEPARATOR_S, "lib", G_DIR_SEPARATOR_S, "ispell", NULL);
+ g_free(tmp);
+
+#ifdef USE_THREADS
+#warning TODO: no directory change
+#endif
+
+ prevdir = g_get_current_dir();
+ if (chdir(dict_path) <0) {
+ FILE_OP_ERROR(dict_path, "chdir");
+ g_free(prevdir);
+ g_free(dict_path);
+ return create_empty_dictionary_list();
+ }
+
+ debug_print(_("Checking for dictionaries in %s\n"), dict_path);
+
+ if (NULL != (dir = opendir("."))) {
+ while (NULL != (ent = readdir(dir))) {
+ /* search for hash table */
+ if (NULL != (tmp = strstr(ent->d_name, ".hash"))) {
+ dict = g_new0(Dictionary, 1);
+ dict->name = g_strndup(ent->d_name, tmp - ent->d_name);
+ dict->path = g_strconcat(dict_path, G_DIR_SEPARATOR_S, ent->d_name, NULL);
+ debug_print(_("Found dictionary %s\n"), dict->path);
+ list = g_slist_append(list, dict);
+ }
+ }
+ closedir(dir);
+ }
+ else {
+ FILE_OP_ERROR(dict_path, "opendir");
+ debug_print(_("No dictionary found\n"));
+ list = create_empty_dictionary_list();
+ }
+ chdir(prevdir);
+ g_free(dict_path);
+ g_free(prevdir);
+ return list;
+}
+
+void gtkspell_free_dictionary_list(GSList *list)
+{
+ Dictionary *dict;
+ GSList *walk;
+ for (walk = list; walk != NULL; walk = g_slist_next(walk))
+ if (walk->data) {
+ dict = (Dictionary *) walk->data;
+ if (dict->name)
+ g_free(dict->name);
+ if (dict->path)
+ g_free(dict->path);
+ g_free(dict);
+ }
+ g_slist_free(list);
+}
+
+static void dictionary_option_menu_item_data_destroy(gpointer data)
+{
+ gchar *str = (gchar *) data;
+
+ if (str)
+ g_free(str);
+}
+
+GtkWidget *gtkspell_dictionary_option_menu_new(const gchar *ispell_path)
+{
+ GSList *dict_list, *tmp;
+ GtkWidget *item;
+ GtkWidget *menu;
+ Dictionary *dict;
+
+ dict_list = gtkspell_get_dictionary_list(ispell_path);
+ g_return_val_if_fail(dict_list, NULL);
+
+ menu = gtk_menu_new();
+
+ for (tmp = dict_list; tmp != NULL; tmp = g_slist_next(tmp)) {
+ dict = (Dictionary *) tmp->data;
+ item = gtk_menu_item_new_with_label(dict->name);
+ if (dict->path)
+ gtk_object_set_data_full(GTK_OBJECT(item), "full_path",
+ g_strdup(dict->path),
+ dictionary_option_menu_item_data_destroy);
+ gtk_menu_append(GTK_MENU(menu), item);
+ gtk_widget_show(item);
+ }
+
+ gtk_widget_show(menu);
+
+ gtkspell_free_dictionary_list(dict_list);
+
+ return menu;
+}
+
+gchar *gtkspell_get_dictionary_menu_active_item(GtkWidget *menu)
+{
+ GtkWidget *menuitem;
+ gchar *result;
+
+ g_return_val_if_fail(GTK_IS_MENU(menu), NULL);
+ menuitem = gtk_menu_get_active(GTK_MENU(menu));
+
+ result = gtk_object_get_data(GTK_OBJECT(menuitem), "full_path");
+ g_return_val_if_fail(result, NULL);
+
+ return g_strdup(result);
+}
+
#include "gtkutils.h"
#include "alertpanel.h"
#include "folder.h"
+#include "gtkspell.h"
+#include "filesel.h"
#include "folderview.h"
PrefsCommon prefs_common;
GtkWidget * checkbtn_forward_as_attachment;
GtkWidget * checkbtn_smart_wrapping;
+
+ /* spelling */
+ GtkWidget *checkbtn_enable_ispell;
+ GtkWidget *entry_ispell_path;
+ GtkWidget *btn_ispell_path;
+ GtkWidget *optmenu_dictionary_path;
} compose;
static struct Display {
static void prefs_recvdialog_set_data_from_optmenu(PrefParam *pparam);
static void prefs_recvdialog_set_optmenu(PrefParam *pparam);
+static void prefs_dictionary_set_data_from_optmenu(PrefParam *param);
+static void prefs_dictionary_set_optmenu(PrefParam *pparam);
+
+
/*
parameter name, default value, pointer to the prefs variable, data type,
pointer to the widget pointer,
{"smart_wrapping", "TRUE", &prefs_common.smart_wrapping,
P_BOOL, &compose.checkbtn_smart_wrapping,
prefs_set_data_from_toggle, prefs_set_toggle},
+ {"enable_ispell", "TRUE", &prefs_common.enable_ispell,
+ P_BOOL, &compose.checkbtn_enable_ispell,
+ prefs_set_data_from_toggle, prefs_set_toggle},
+ {"ispell_path", ISPELL_PATH, &prefs_common.ispell_path,
+ P_STRING, &compose.entry_ispell_path,
+ prefs_set_data_from_entry, prefs_set_entry},
+ {"dictionary_path", "", &prefs_common.dictionary_path,
+ P_STRING, &compose.optmenu_dictionary_path,
+ prefs_dictionary_set_data_from_optmenu, prefs_dictionary_set_optmenu },
{"show_ruler", "TRUE", &prefs_common.show_ruler, P_BOOL,
NULL, NULL, NULL},
send.optmenu_charset = optmenu;
}
+static void prefs_dictionary_set_data_from_optmenu(PrefParam *param)
+{
+ gchar *str;
+ gchar *dict_path;
+
+ g_return_if_fail(param);
+ g_return_if_fail(param->data);
+ g_return_if_fail(param->widget);
+ g_return_if_fail(*(param->widget));
+
+ dict_path = gtkspell_get_dictionary_menu_active_item
+ (gtk_option_menu_get_menu(GTK_OPTION_MENU(*(param->widget))));
+ str = *((gchar **) param->data);
+ if (str)
+ g_free(str);
+ *((gchar **) param->data) = dict_path;
+}
+
+static void prefs_dictionary_set_optmenu(PrefParam *pparam)
+{
+ GList *cur;
+ GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
+ GtkWidget *menu;
+ GtkWidget *menuitem;
+ gchar *dict_path;
+ gint n = 0;
+
+ g_return_if_fail(optmenu != NULL);
+ g_return_if_fail(pparam->data != NULL);
+
+ if (*(gchar **) pparam->data) {
+ menu = gtk_option_menu_get_menu(optmenu);
+ for (cur = GTK_MENU_SHELL(menu)->children;
+ cur != NULL; cur = cur->next) {
+ menuitem = GTK_WIDGET(cur->data);
+ dict_path = gtk_object_get_data(GTK_OBJECT(menuitem), "full_path");
+ if (!strcmp(dict_path, *((gchar **)pparam->data))) {
+ gtk_option_menu_set_history(optmenu, n);
+ return;
+ }
+ n++;
+ }
+ }
+
+ gtk_option_menu_set_history(optmenu, 0);
+ prefs_dictionary_set_data_from_optmenu(pparam);
+}
+
+static void prefs_compose_checkbtn_enable_ispell_toggle_cb
+ (GtkWidget *widget,
+ gpointer data)
+{
+ gboolean toggled;
+
+ toggled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+ gtk_widget_set_sensitive(compose.entry_ispell_path, toggled);
+ gtk_widget_set_sensitive(compose.optmenu_dictionary_path, toggled);
+ gtk_widget_set_sensitive(compose.btn_ispell_path, toggled);
+}
+
+static void prefs_compose_btn_ispell_path_clicked_cb(GtkWidget *widget,
+ gpointer data)
+{
+ gchar *file_path;
+ GtkWidget *new_menu;
+
+ file_path = filesel_select_file(_("Select spelling checker location"),
+ prefs_common.ispell_path);
+ if (file_path == NULL) {
+ /* don't change */
+ }
+ else {
+ if (prefs_common.ispell_path)
+ g_free(prefs_common.ispell_path);
+ prefs_common.ispell_path = file_path;
+
+ new_menu = gtkspell_dictionary_option_menu_new(file_path);
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(compose.optmenu_dictionary_path),
+ new_menu);
+
+ gtk_entry_set_text(GTK_ENTRY(compose.entry_ispell_path), file_path);
+ /* select first one */
+ gtk_option_menu_set_history(GTK_OPTION_MENU(compose.optmenu_dictionary_path), 0);
+
+ prefs_common.dictionary_path = gtkspell_get_dictionary_menu_active_item(
+ gtk_option_menu_get_menu(GTK_OPTION_MENU(compose.optmenu_dictionary_path)));
+ }
+
+}
+
static void prefs_compose_create(void)
{
GtkWidget *vbox1;
GtkWidget *checkbtn_forward_as_attachment;
GtkWidget *checkbtn_smart_wrapping;
+ GtkWidget *frame_spell;
+ GtkWidget *hbox_spell;
+ GtkWidget *vbox_spell;
+ GtkWidget *hbox_ispell_path;
+ GtkWidget *checkbtn_enable_ispell;
+ GtkWidget *label_ispell_path;
+ GtkWidget *entry_ispell_path;
+ GtkWidget *btn_ispell_path;
+ GtkWidget *hbox_dictionary_path;
+ GtkWidget *label_dictionary_path;
+ GtkWidget *optmenu_dictionary_path;
+
vbox1 = gtk_vbox_new (FALSE, VSPACING);
gtk_widget_show (vbox1);
gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
PACK_CHECK_BUTTON (vbox1, checkbtn_smart_wrapping,
_("Smart wrapping (EXPERIMENTAL)"));
+ /* spell checker defaults */
+ PACK_FRAME(vbox1, frame_spell, _("Global spelling checker settings"));
+ vbox_spell = gtk_vbox_new(FALSE, VSPACING_NARROW);
+ gtk_widget_show (vbox_spell);
+ gtk_container_add(GTK_CONTAINER(frame_spell), vbox_spell);
+ gtk_container_set_border_width(GTK_CONTAINER(vbox_spell), 8);
+
+ PACK_CHECK_BUTTON(vbox_spell, checkbtn_enable_ispell,
+ _("Enable spell checker"));
+
+ gtk_signal_connect(GTK_OBJECT(checkbtn_enable_ispell), "toggled",
+ GTK_SIGNAL_FUNC(prefs_compose_checkbtn_enable_ispell_toggle_cb),
+ NULL);
+
+ hbox_ispell_path = gtk_hbox_new (FALSE, 8);
+ gtk_widget_show(hbox_ispell_path);
+ gtk_box_pack_start(GTK_BOX(vbox_spell), hbox_ispell_path, TRUE, TRUE, 0);
+
+ label_ispell_path = gtk_label_new (_("Ispelll path"));
+ gtk_widget_show(label_ispell_path);
+ gtk_box_pack_start(GTK_BOX(hbox_ispell_path), label_ispell_path, FALSE, FALSE, 0);
+
+ entry_ispell_path = gtk_entry_new();
+ gtk_widget_show(entry_ispell_path);
+ gtk_box_pack_start(GTK_BOX(hbox_ispell_path), entry_ispell_path, FALSE, FALSE, 0);
+ gtk_widget_set_usize(entry_ispell_path, 150, -1);
+ gtk_widget_set_sensitive(entry_ispell_path, prefs_common.enable_ispell);
+
+ btn_ispell_path = gtk_button_new_with_label(_("..."));
+ gtk_widget_show(btn_ispell_path);
+ gtk_box_pack_start(GTK_BOX(hbox_ispell_path), btn_ispell_path, FALSE, FALSE, 0);
+ gtk_widget_set_sensitive(btn_ispell_path, prefs_common.enable_ispell);
+
+ gtk_signal_connect(GTK_OBJECT(btn_ispell_path), "clicked",
+ GTK_SIGNAL_FUNC(prefs_compose_btn_ispell_path_clicked_cb),
+ NULL);
+
+ hbox_dictionary_path = gtk_hbox_new(FALSE, 8);
+ gtk_widget_show(hbox_dictionary_path);
+ gtk_box_pack_start(GTK_BOX(vbox_spell), hbox_dictionary_path, TRUE, TRUE, 0);
+
+ label_dictionary_path = gtk_label_new(_("Dictionaries"));
+ gtk_widget_show(label_dictionary_path);
+ gtk_box_pack_start(GTK_BOX(hbox_dictionary_path), label_dictionary_path, FALSE, FALSE, 0);
+
+ optmenu_dictionary_path = gtk_option_menu_new();
+ gtk_widget_show(optmenu_dictionary_path);
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_dictionary_path),
+ gtkspell_dictionary_option_menu_new(prefs_common.ispell_path));
+ gtk_box_pack_start(GTK_BOX(hbox_dictionary_path), optmenu_dictionary_path, FALSE, FALSE, 0);
+ gtk_widget_set_sensitive(optmenu_dictionary_path, prefs_common.enable_ispell);
+
/*
compose.checkbtn_quote = checkbtn_quote;
compose.entry_quotemark = entry_quotemark;
checkbtn_forward_as_attachment;
compose.checkbtn_smart_wrapping =
checkbtn_smart_wrapping;
+
+ compose.checkbtn_enable_ispell = checkbtn_enable_ispell;
+ compose.entry_ispell_path = entry_ispell_path;
+ compose.btn_ispell_path = btn_ispell_path;
+ compose.optmenu_dictionary_path = optmenu_dictionary_path;
}
static void prefs_display_create(void)