diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2007-06-10 17:18:19 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2007-06-10 17:18:19 +0800 |
commit | 3481670915dcd593d7156bda1aec970a42890e0b (patch) | |
tree | e32f211bc48bf2a97674077a07d2eed6a232b9bb /libempathy-gtk | |
parent | 7011153ce3fa6807677e1df874389085fd5f0971 (diff) | |
download | gsoc2013-empathy-3481670915dcd593d7156bda1aec970a42890e0b.tar gsoc2013-empathy-3481670915dcd593d7156bda1aec970a42890e0b.tar.gz gsoc2013-empathy-3481670915dcd593d7156bda1aec970a42890e0b.tar.bz2 gsoc2013-empathy-3481670915dcd593d7156bda1aec970a42890e0b.tar.lz gsoc2013-empathy-3481670915dcd593d7156bda1aec970a42890e0b.tar.xz gsoc2013-empathy-3481670915dcd593d7156bda1aec970a42890e0b.tar.zst gsoc2013-empathy-3481670915dcd593d7156bda1aec970a42890e0b.zip |
Adding spellcheck support.
2007-06-10 Xavier Claessens <xclaesse@gmail.com>
* libempathy-gtk/gossip-spell-dialog.glade:
* libempathy-gtk/gossip-spell-dialog.c:
* libempathy-gtk/gossip-spell-dialog.h:
* libempathy-gtk/gossip-chat.c:
* libempathy-gtk/Makefile.am:
* configure.ac: Adding spellcheck support.
* libempathy-gtk/gossip-spell.c:
* libempathy/gossip-conf.c: Remove useless debug messages.
svn path=/trunk/; revision=144
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/Makefile.am | 2 | ||||
-rw-r--r-- | libempathy-gtk/gossip-chat.c | 6 | ||||
-rw-r--r-- | libempathy-gtk/gossip-spell-dialog.c | 267 | ||||
-rw-r--r-- | libempathy-gtk/gossip-spell-dialog.glade | 205 | ||||
-rw-r--r-- | libempathy-gtk/gossip-spell-dialog.h | 39 | ||||
-rw-r--r-- | libempathy-gtk/gossip-spell.c | 5 |
6 files changed, 516 insertions, 8 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 009db7335..6a6c7203c 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -21,6 +21,7 @@ libempathy_gtk_la_SOURCES = \ gossip-cell-renderer-expander.c gossip-cell-renderer-expander.h \ gossip-cell-renderer-text.c gossip-cell-renderer-text.h \ gossip-spell.c gossip-spell.h \ + gossip-spell-dialog.c gossip-spell-dialog.h \ gossip-contact-groups.c gossip-contact-groups.h \ gossip-contact-list-store.c gossip-contact-list-store.h \ gossip-contact-list-view.c gossip-contact-list-view.h \ @@ -59,6 +60,7 @@ glade_DATA = \ gossip-new-chatroom-dialog.glade \ gossip-group-chat.glade \ gossip-chatrooms-window.glade \ + gossip-spell-dialog.glade \ gossip-chat.glade dtddir = $(datadir)/empathy diff --git a/libempathy-gtk/gossip-chat.c b/libempathy-gtk/gossip-chat.c index 80bfc17f0..0f6335617 100644 --- a/libempathy-gtk/gossip-chat.c +++ b/libempathy-gtk/gossip-chat.c @@ -47,7 +47,7 @@ #include "gossip-geometry.h" #include "gossip-preferences.h" #include "gossip-spell.h" -//#include "gossip-spell-dialog.h" +#include "gossip-spell-dialog.h" #include "gossip-ui-utils.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CHAT, GossipChatPriv)) @@ -936,10 +936,10 @@ static void chat_text_check_word_spelling_cb (GtkMenuItem *menuitem, GossipChatSpell *chat_spell) { -/*FIXME: gossip_spell_dialog_show (chat_spell->chat, + gossip_spell_dialog_show (chat_spell->chat, chat_spell->start, chat_spell->end, - chat_spell->word);*/ + chat_spell->word); } static GossipChatSpell * diff --git a/libempathy-gtk/gossip-spell-dialog.c b/libempathy-gtk/gossip-spell-dialog.c new file mode 100644 index 000000000..b34a8860c --- /dev/null +++ b/libempathy-gtk/gossip-spell-dialog.c @@ -0,0 +1,267 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2004-2007 Imendio AB + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include <string.h> + +#include <glib/gi18n.h> +#include <gtk/gtkcellrenderertext.h> +#include <gtk/gtkdialog.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkliststore.h> +#include <gtk/gtktreeview.h> +#include <gtk/gtktreeselection.h> +#include <gtk/gtksizegroup.h> +#include <glade/glade.h> + +#include "gossip-chat.h" +#include "gossip-spell-dialog.h" +#include "gossip-ui-utils.h" + +typedef struct { + GtkWidget *window; + GtkWidget *button_replace; + GtkWidget *label_word; + GtkWidget *treeview_words; + + GossipChat *chat; + + gchar *word; + GtkTextIter start; + GtkTextIter end; +} GossipSpellDialog; + +enum { + COL_SPELL_WORD, + COL_SPELL_COUNT +}; + +static void spell_dialog_model_populate_columns (GossipSpellDialog *dialog); +static void spell_dialog_model_populate_suggestions (GossipSpellDialog *dialog); +static void spell_dialog_model_row_activated_cb (GtkTreeView *tree_view, + GtkTreePath *path, + GtkTreeViewColumn *column, + GossipSpellDialog *dialog); +static void spell_dialog_model_selection_changed_cb (GtkTreeSelection *treeselection, + GossipSpellDialog *dialog); +static void spell_dialog_model_setup (GossipSpellDialog *dialog); +static void spell_dialog_response_cb (GtkWidget *widget, + gint response, + GossipSpellDialog *dialog); +static void spell_dialog_destroy_cb (GtkWidget *widget, + GossipSpellDialog *dialog); + +static void +spell_dialog_model_populate_columns (GossipSpellDialog *dialog) +{ + GtkTreeModel *model; + GtkTreeViewColumn *column; + GtkCellRenderer *renderer; + guint col_offset; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_words)); + + renderer = gtk_cell_renderer_text_new (); + col_offset = gtk_tree_view_insert_column_with_attributes ( + GTK_TREE_VIEW (dialog->treeview_words), + -1, _("Word"), + renderer, + "text", COL_SPELL_WORD, + NULL); + + g_object_set_data (G_OBJECT (renderer), + "column", GINT_TO_POINTER (COL_SPELL_WORD)); + + column = gtk_tree_view_get_column (GTK_TREE_VIEW (dialog->treeview_words), col_offset - 1); + gtk_tree_view_column_set_sort_column_id (column, COL_SPELL_WORD); + gtk_tree_view_column_set_resizable (column, FALSE); + gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE); +} + +static void +spell_dialog_model_populate_suggestions (GossipSpellDialog *dialog) +{ + GtkTreeModel *model; + GtkListStore *store; + GList *suggestions, *l; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview_words)); + store = GTK_LIST_STORE (model); + + suggestions = gossip_spell_get_suggestions (dialog->word); + for (l = suggestions; l; l=l->next) { + GtkTreeIter iter; + gchar *word; + + word = l->data; + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + COL_SPELL_WORD, word, + -1); + } + + gossip_spell_free_suggestions (suggestions); +} + +static void +spell_dialog_model_row_activated_cb (GtkTreeView *tree_view, + GtkTreePath *path, + GtkTreeViewColumn *column, + GossipSpellDialog *dialog) +{ + spell_dialog_response_cb (dialog->window, GTK_RESPONSE_OK, dialog); +} + +static void +spell_dialog_model_selection_changed_cb (GtkTreeSelection *treeselection, + GossipSpellDialog *dialog) +{ + gint count; + + count = gtk_tree_selection_count_selected_rows (treeselection); + gtk_widget_set_sensitive (dialog->button_replace, (count == 1)); +} + +static void +spell_dialog_model_setup (GossipSpellDialog *dialog) +{ + GtkTreeView *view; + GtkListStore *store; + GtkTreeSelection *selection; + + view = GTK_TREE_VIEW (dialog->treeview_words); + + g_signal_connect (view, "row-activated", + G_CALLBACK (spell_dialog_model_row_activated_cb), + dialog); + + store = gtk_list_store_new (COL_SPELL_COUNT, + G_TYPE_STRING); /* word */ + + gtk_tree_view_set_model (view, GTK_TREE_MODEL (store)); + + selection = gtk_tree_view_get_selection (view); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); + + g_signal_connect (selection, "changed", + G_CALLBACK (spell_dialog_model_selection_changed_cb), + dialog); + + spell_dialog_model_populate_columns (dialog); + spell_dialog_model_populate_suggestions (dialog); + + g_object_unref (store); +} + +static void +spell_dialog_destroy_cb (GtkWidget *widget, + GossipSpellDialog *dialog) +{ + g_object_unref (dialog->chat); + g_free (dialog->word); + + g_free (dialog); +} + +static void +spell_dialog_response_cb (GtkWidget *widget, + gint response, + GossipSpellDialog *dialog) +{ + if (response == GTK_RESPONSE_OK) { + GtkTreeView *view; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreeIter iter; + + gchar *new_word; + + view = GTK_TREE_VIEW (dialog->treeview_words); + selection = gtk_tree_view_get_selection (view); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { + return; + } + + gtk_tree_model_get (model, &iter, COL_SPELL_WORD, &new_word, -1); + + gossip_chat_correct_word (dialog->chat, + dialog->start, + dialog->end, + new_word); + + g_free (new_word); + } + + gtk_widget_destroy (dialog->window); +} + +void +gossip_spell_dialog_show (GossipChat *chat, + GtkTextIter start, + GtkTextIter end, + const gchar *word) +{ + GossipSpellDialog *dialog; + GladeXML *gui; + gchar *str; + + g_return_if_fail (chat != NULL); + g_return_if_fail (word != NULL); + + dialog = g_new0 (GossipSpellDialog, 1); + + dialog->chat = g_object_ref (chat); + + dialog->word = g_strdup (word); + + dialog->start = start; + dialog->end = end; + + gui = gossip_glade_get_file ("gossip-spell-dialog.glade", + "spell_dialog", + NULL, + "spell_dialog", &dialog->window, + "button_replace", &dialog->button_replace, + "label_word", &dialog->label_word, + "treeview_words", &dialog->treeview_words, + NULL); + + gossip_glade_connect (gui, + dialog, + "spell_dialog", "response", spell_dialog_response_cb, + "spell_dialog", "destroy", spell_dialog_destroy_cb, + NULL); + + g_object_unref (gui); + + str = g_strdup_printf ("%s:\n<b>%s</b>", + _("Suggestions for the word"), + word); + + gtk_label_set_markup (GTK_LABEL (dialog->label_word), str); + g_free (str); + + spell_dialog_model_setup (dialog); + + gtk_widget_show (dialog->window); +} diff --git a/libempathy-gtk/gossip-spell-dialog.glade b/libempathy-gtk/gossip-spell-dialog.glade new file mode 100644 index 000000000..502fb0d13 --- /dev/null +++ b/libempathy-gtk/gossip-spell-dialog.glade @@ -0,0 +1,205 @@ +<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> +<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> + +<glade-interface> + +<widget class="GtkDialog" id="spell_dialog"> + <property name="border_width">5</property> + <property name="title" translatable="yes">Spell Checker</property> + <property name="type">GTK_WINDOW_TOPLEVEL</property> + <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property> + <property name="modal">True</property> + <property name="default_width">275</property> + <property name="default_height">225</property> + <property name="resizable">True</property> + <property name="destroy_with_parent">False</property> + <property name="decorated">True</property> + <property name="skip_taskbar_hint">False</property> + <property name="skip_pager_hint">False</property> + <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> + <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> + <property name="focus_on_map">True</property> + <property name="urgency_hint">False</property> + <property name="has_separator">False</property> + + <child internal-child="vbox"> + <widget class="GtkVBox" id="dialog-vbox7"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">2</property> + + <child internal-child="action_area"> + <widget class="GtkHButtonBox" id="dialog-action_area7"> + <property name="visible">True</property> + <property name="layout_style">GTK_BUTTONBOX_END</property> + + <child> + <widget class="GtkButton" id="button_cancel"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-cancel</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <property name="response_id">-6</property> + </widget> + </child> + + <child> + <widget class="GtkButton" id="button_replace"> + <property name="visible">True</property> + <property name="sensitive">False</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <property name="response_id">-5</property> + + <child> + <widget class="GtkAlignment" id="alignment6"> + <property name="visible">True</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xscale">0</property> + <property name="yscale">0</property> + <property name="top_padding">0</property> + <property name="bottom_padding">0</property> + <property name="left_padding">0</property> + <property name="right_padding">0</property> + + <child> + <widget class="GtkHBox" id="hbox135"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">2</property> + + <child> + <widget class="GtkImage" id="image245"> + <property name="visible">True</property> + <property name="stock">gtk-convert</property> + <property name="icon_size">4</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label594"> + <property name="visible">True</property> + <property name="label">_Replace</property> + <property name="use_underline">True</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + </child> + </widget> + </child> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">GTK_PACK_END</property> + </packing> + </child> + + <child> + <widget class="GtkVBox" id="vbox128"> + <property name="border_width">5</property> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">6</property> + + <child> + <widget class="GtkLabel" id="label_word"> + <property name="visible">True</property> + <property name="label" translatable="yes">Suggestions for the word:</property> + <property name="use_underline">False</property> + <property name="use_markup">True</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">True</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkScrolledWindow" id="scrolledwindow9"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="shadow_type">GTK_SHADOW_IN</property> + <property name="window_placement">GTK_CORNER_TOP_LEFT</property> + + <child> + <widget class="GtkTreeView" id="treeview_words"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="headers_visible">False</property> + <property name="rules_hint">False</property> + <property name="reorderable">False</property> + <property name="enable_search">True</property> + <property name="fixed_height_mode">False</property> + <property name="hover_selection">False</property> + <property name="hover_expand">False</property> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + </widget> + </child> +</widget> + +</glade-interface> diff --git a/libempathy-gtk/gossip-spell-dialog.h b/libempathy-gtk/gossip-spell-dialog.h new file mode 100644 index 000000000..2f71033f0 --- /dev/null +++ b/libempathy-gtk/gossip-spell-dialog.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2004-2007 Imendio AB + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Martyn Russell <martyn@imendio.com> + * Richard Hult <richard@imendio.com> + */ + +#ifndef __GOSSIP_SPELL_DIALOG_H__ +#define __GOSSIP_SPELL_DIALOG_H__ + +#include <gtk/gtktextiter.h> +#include "gossip-chat.h" + +G_BEGIN_DECLS + +void gossip_spell_dialog_show (GossipChat *chat, + GtkTextIter start, + GtkTextIter end, + const gchar *word); + +G_END_DECLS + +#endif /* __GOSSIP_SPELL_DIALOG_H__ */ diff --git a/libempathy-gtk/gossip-spell.c b/libempathy-gtk/gossip-spell.c index db06e9f1d..8d595f4c2 100644 --- a/libempathy-gtk/gossip-spell.c +++ b/libempathy-gtk/gossip-spell.c @@ -204,7 +204,6 @@ spell_setup_languages (void) } if (languages) { - gossip_debug (DEBUG_DOMAIN, "No languages to setup"); return; } @@ -393,8 +392,6 @@ gossip_spell_supported (void) return FALSE; } - gossip_debug (DEBUG_DOMAIN, "Support enabled"); - return TRUE; } @@ -403,8 +400,6 @@ gossip_spell_supported (void) gboolean gossip_spell_supported (void) { - gossip_debug (DEBUG_DOMAIN, "Support disabled"); - return FALSE; } |