aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui')
-rw-r--r--main/src/ui/chat_input/spell_checker.vala58
-rw-r--r--main/src/ui/settings_dialog.vala3
2 files changed, 51 insertions, 10 deletions
diff --git a/main/src/ui/chat_input/spell_checker.vala b/main/src/ui/chat_input/spell_checker.vala
index a05d9251..8359b1b4 100644
--- a/main/src/ui/chat_input/spell_checker.vala
+++ b/main/src/ui/chat_input/spell_checker.vala
@@ -9,26 +9,64 @@ namespace Dino.Ui {
public class SpellChecker {
private Conversation? conversation;
- private TextView gspell_view;
- private HashMap<Conversation, Language> language_cache = new HashMap<Conversation, Language>(Conversation.hash_func, Conversation.equals_func);
+ private TextView text_view;
+ private TextBuffer text_buffer;
public SpellChecker(Gtk.TextView text_input) {
- this.gspell_view = TextView.get_from_gtk_text_view(text_input);
- gspell_view.basic_setup();
+ this.text_view = TextView.get_from_gtk_text_view(text_input);
+ this.text_buffer = TextBuffer.get_from_gtk_text_buffer(text_view.view.buffer);
+
+ text_view.basic_setup();
+ text_buffer.spell_checker.notify["language"].connect(lang_changed);
+
+ // Enable/Disable spell checking live
+ Dino.Application.get_default().settings.notify["check-spelling"].connect((obj, _) => {
+ if (((Dino.Entities.Settings) obj).check_spelling) {
+ initialize_for_conversation(this.conversation);
+ } else {
+ text_buffer.set_spell_checker(null);
+ }
+ });
}
public void initialize_for_conversation(Conversation conversation) {
- Checker spell_checker = TextBuffer.get_from_gtk_text_buffer(gspell_view.view.buffer).spell_checker;
+ this.conversation = conversation;
- if (this.conversation != null) language_cache[this.conversation] = spell_checker.language;
+ if (!Dino.Application.get_default().settings.check_spelling) {
+ text_buffer.set_spell_checker(null);
+ return;
+ }
+ if (text_buffer.spell_checker == null) text_buffer.spell_checker = new Checker(null);
- this.conversation = conversation;
+ // Set the conversation language (from cache or db)
+ text_buffer.spell_checker.notify["language"].disconnect(lang_changed);
- if (language_cache.has_key(this.conversation)) {
- spell_checker.language = language_cache[conversation];
+ var db = Dino.Application.get_default().db;
+ Qlite.RowOption row_option = db.conversation_settings.select()
+ .with(db.conversation_settings.conversation_id, "=", conversation.id)
+ .with(db.conversation_settings.key, "=", "lang")
+ .single().row();
+ if (row_option.is_present()) {
+ string lang_code = row_option.inner[db.conversation_settings.value];
+ Language? lang = Language.lookup(lang_code);
+ text_buffer.spell_checker.language = lang;
} else {
- spell_checker.language = null;
+ text_buffer.spell_checker.language = null;
}
+
+ text_buffer.spell_checker.notify["language"].connect(lang_changed);
+ }
+
+ private void lang_changed() {
+ var db = Dino.Application.get_default().db;
+
+ Checker spell_checker = text_buffer.spell_checker;
+ if (spell_checker.language.get_code() == null) return;
+ db.conversation_settings.upsert()
+ .value(db.conversation_settings.conversation_id, conversation.id, true)
+ .value(db.conversation_settings.key, "lang", true)
+ .value(db.conversation_settings.value, spell_checker.language.get_code())
+ .perform();
}
}
diff --git a/main/src/ui/settings_dialog.vala b/main/src/ui/settings_dialog.vala
index 68c711dc..a24b9c22 100644
--- a/main/src/ui/settings_dialog.vala
+++ b/main/src/ui/settings_dialog.vala
@@ -9,6 +9,7 @@ class SettingsDialog : Dialog {
[GtkChild] private CheckButton marker_checkbutton;
[GtkChild] private CheckButton notification_checkbutton;
[GtkChild] private CheckButton emoji_checkbutton;
+ [GtkChild] private CheckButton check_spelling_checkbutton;
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
@@ -19,11 +20,13 @@ class SettingsDialog : Dialog {
marker_checkbutton.active = settings.send_marker;
notification_checkbutton.active = settings.notifications;
emoji_checkbutton.active = settings.convert_utf8_smileys;
+ check_spelling_checkbutton.active = settings.check_spelling;
typing_checkbutton.toggled.connect(() => { settings.send_typing = typing_checkbutton.active; } );
marker_checkbutton.toggled.connect(() => { settings.send_marker = marker_checkbutton.active; } );
notification_checkbutton.toggled.connect(() => { settings.notifications = notification_checkbutton.active; } );
emoji_checkbutton.toggled.connect(() => { settings.convert_utf8_smileys = emoji_checkbutton.active; });
+ check_spelling_checkbutton.toggled.connect(() => { settings.check_spelling = check_spelling_checkbutton.active; });
}
}