forked from ueno/ibus-skk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# ibus-skk - The SKK engine for IBus | ||
# | ||
# Copyright (c) 2007-2008 Huang Peng <[email protected]> | ||
# Copyright (C) 2009-2017 Daiki Ueno <[email protected]> | ||
# Copyright (C) 2009-2018 Daiki Ueno <[email protected]> | ||
# | ||
# 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 | ||
|
@@ -80,6 +80,9 @@ GETTEXT_PACKAGE=ibus-skk | |
AC_SUBST(GETTEXT_PACKAGE) | ||
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Define to the read-only architecture-independent data directory.]) | ||
|
||
# glib stuff | ||
GLIB_GSETTINGS | ||
|
||
# OUTPUT files | ||
AC_CONFIG_FILES([ po/Makefile.in | ||
Makefile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2011-2017 Daiki Ueno <[email protected]> | ||
* Copyright (C) 2011-2017 Red Hat, Inc. | ||
* Copyright (C) 2011-2018 Daiki Ueno <[email protected]> | ||
* Copyright (C) 2011-2018 Red Hat, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
|
@@ -302,35 +302,35 @@ class SkkEngine : IBus.Engine { | |
void apply_preferences () { | ||
Variant? variant; | ||
|
||
variant = preferences.get ("auto_start_henkan_keywords"); | ||
variant = preferences.get ("auto-start-henkan-keywords"); | ||
assert (variant != null); | ||
context.auto_start_henkan_keywords = variant.get_strv (); | ||
|
||
variant = preferences.get ("period_style"); | ||
variant = preferences.get ("period-style"); | ||
assert (variant != null); | ||
context.period_style = (Skk.PeriodStyle) variant.get_int32 (); | ||
|
||
variant = preferences.get ("page_size"); | ||
variant = preferences.get ("page-size"); | ||
assert (variant != null); | ||
lookup_table.set_page_size (variant.get_int32 ()); | ||
|
||
variant = preferences.get ("pagination_start"); | ||
variant = preferences.get ("pagination-start"); | ||
assert (variant != null); | ||
page_start = (uint) variant.get_int32 (); | ||
|
||
variant = preferences.get ("initial_input_mode"); | ||
variant = preferences.get ("initial-input-mode"); | ||
assert (variant != null); | ||
context.input_mode = (Skk.InputMode) variant.get_int32 (); | ||
|
||
variant = preferences.get ("show_annotation"); | ||
variant = preferences.get ("show-annotation"); | ||
assert (variant != null); | ||
show_annotation = variant.get_boolean (); | ||
|
||
variant = preferences.get ("egg_like_newline"); | ||
variant = preferences.get ("egg-like-newline"); | ||
assert (variant != null); | ||
context.egg_like_newline = variant.get_boolean (); | ||
|
||
variant = preferences.get ("typing_rule"); | ||
variant = preferences.get ("typing-rule"); | ||
assert (variant != null); | ||
try { | ||
context.typing_rule = new Skk.Rule (variant.get_string ()); | ||
|
@@ -555,8 +555,7 @@ class SkkEngine : IBus.Engine { | |
|
||
bus.disconnected.connect (() => { IBus.quit (); }); | ||
|
||
var config = bus.get_config (); | ||
SkkEngine.preferences = new Preferences (config); | ||
SkkEngine.preferences = new Preferences (); | ||
SkkEngine.dictionaries = new ArrayList<Skk.Dict> (); | ||
SkkEngine.reload_dictionaries (); | ||
SkkEngine.preferences.value_changed.connect ((name, value) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schemalist> | ||
<schema gettext-domain="ibus-skk" id="org.freedesktop.ibus.engine.skk" path="/org/freedesktop/ibus/engine/skk/"> | ||
<key name="dictionaries" type="as"> | ||
<default>[]</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
<key name="auto-start-henkan-keywords" type="as"> | ||
<default>["を", "、", "。", ".", ",", "?", "」", | ||
"!", ";", ":", ")", ";", ":", ")", | ||
"”", "】", "』", "》", "〉", "}", "]", | ||
"〕", "}", "]", "?", ".", ",", "!"] | ||
</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
<key name="period-style" type="i"> | ||
<default>0</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
<key name="page-size" type="i"> | ||
<default>7</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
<key name="pagination-start" type="i"> | ||
<default>4</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
<key name="show-annotation" type="b"> | ||
<default>false</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
<key name="initial-input-mode" type="i"> | ||
<default>0</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
<key name="egg-like-newline" type="b"> | ||
<default>false</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
<key name="typing-rule" type="s"> | ||
<default>'default'</default> | ||
<summary></summary> | ||
<description></description> | ||
</key> | ||
</schema> | ||
</schemalist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2011-2017 Daiki Ueno <[email protected]> | ||
* Copyright (C) 2011-2017 Red Hat, Inc. | ||
* Copyright (C) 2011-2018 Daiki Ueno <[email protected]> | ||
* Copyright (C) 2011-2018 Red Hat, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
|
@@ -20,32 +20,33 @@ | |
using Gee; | ||
|
||
public class Preferences : Object { | ||
IBus.Config config; | ||
Settings settings; | ||
|
||
Map<string,Variant> _default = new HashMap<string,Variant> (); | ||
Map<string,Variant> current = new HashMap<string,Variant> (); | ||
|
||
public void load () { | ||
Variant? values = config.get_values ("engine/skk"); | ||
if (values != null) { | ||
var iter = values.iterator (); | ||
Variant? entry = null; | ||
while ((entry = iter.next_value ()) != null) { | ||
string name; | ||
Variant value; | ||
entry.get ("{sv}", out name, out value); | ||
current.set (name, value); | ||
public void load (bool is_default) { | ||
SettingsSchemaSource schema_source = SettingsSchemaSource.get_default (); | ||
string schema_id = settings.schema_id; | ||
SettingsSchema schema = schema_source.lookup (schema_id, false); | ||
foreach (unowned string key in schema.list_keys()) { | ||
if (is_default) { | ||
_default.set (key, settings.get_default_value (key)); | ||
} else { | ||
Variant? value = settings.get_user_value (key); | ||
if (value != null) | ||
current.set (key, value); | ||
} | ||
} | ||
} | ||
|
||
public void save () { | ||
var iter = current.map_iterator (); | ||
while (iter.next ()) { | ||
config.set_value ("engine/skk", | ||
iter.get_key (), | ||
iter.get_value ()); | ||
settings.set_value (iter.get_key (), | ||
iter.get_value ()); | ||
} | ||
Settings.sync (); | ||
} | ||
|
||
public new Variant? @get (string name) { | ||
|
@@ -57,17 +58,15 @@ public class Preferences : Object { | |
} | ||
|
||
public new void @set (string name, Variant value) { | ||
current.set (name, value); | ||
Variant? _value = current.get (name); | ||
if (_value == null || !_value.equal (value)) | ||
current.set (name, value); | ||
} | ||
|
||
static const string[] AUTO_START_HENKAN_KEYWORDS = { | ||
"を", "、", "。", ".", ",", "?", "」", | ||
"!", ";", ":", ")", ";", ":", ")", | ||
"”", "】", "』", "》", "〉", "}", "]", | ||
"〕", "}", "]", "?", ".", ",", "!" | ||
}; | ||
public Preferences () { | ||
settings = new Settings ("org.freedesktop.ibus.engine.skk"); | ||
load (true); | ||
|
||
public Preferences (IBus.Config config) { | ||
ArrayList<string> dictionaries = new ArrayList<string> (); | ||
dictionaries.add ( | ||
"type=file,file=%s/ibus-skk/user.dict,mode=readwrite".printf ( | ||
|
@@ -78,38 +77,26 @@ public class Preferences : Object { | |
"type=server,host=localhost,port=1178"); | ||
_default.set ("dictionaries", | ||
new Variant.strv (dictionaries.to_array ())); | ||
_default.set ("auto_start_henkan_keywords", | ||
new Variant.strv (AUTO_START_HENKAN_KEYWORDS)); | ||
_default.set ("period_style", | ||
new Variant.int32 ((int32) Skk.PeriodStyle.JA_JA)); | ||
_default.set ("page_size", | ||
new Variant.int32 (7)); | ||
_default.set ("pagination_start", | ||
new Variant.int32 (4)); | ||
_default.set ("show_annotation", | ||
new Variant.boolean (true)); | ||
_default.set ("initial_input_mode", | ||
new Variant.int32 (Skk.InputMode.HIRAGANA)); | ||
_default.set ("egg_like_newline", | ||
new Variant.boolean (false)); | ||
_default.set ("typing_rule", | ||
new Variant.string ("default")); | ||
|
||
this.config = config; | ||
load (); | ||
config.value_changed.connect (value_changed_cb); | ||
load (false); | ||
settings.changed.connect (value_changed_cb); | ||
} | ||
|
||
public signal void value_changed (string name, Variant value); | ||
|
||
void value_changed_cb (IBus.Config config, | ||
string section, | ||
string name, | ||
Variant value) | ||
void value_changed_cb (Settings settings, | ||
string name) | ||
{ | ||
if (section == "engine/skk") { | ||
current.set (name, value); | ||
value_changed (name, value); | ||
Variant? value = settings.get_user_value (name); | ||
if (value == null) { | ||
current.unset (name); | ||
value = _default.get (name); | ||
} else { | ||
// save() will call this callback and should not change the current. | ||
Variant? _value = current.get (name); | ||
if (_value == null || !_value.equal (value)) | ||
current.set (name, value); | ||
} | ||
value_changed (name, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2011-2017 Daiki Ueno <[email protected]> | ||
* Copyright (C) 2011-2017 Red Hat, Inc. | ||
* Copyright (C) 2011-2018 Daiki Ueno <[email protected]> | ||
* Copyright (C) 2011-2018 Red Hat, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
|
@@ -392,34 +392,34 @@ class Setup : Object { | |
|
||
Variant? variant; | ||
|
||
variant = preferences.get ("auto_start_henkan_keywords"); | ||
variant = preferences.get ("auto-start-henkan-keywords"); | ||
assert (variant != null); | ||
auto_start_henkan_keywords_entry.text = string.joinv ("", variant.dup_strv ()); | ||
|
||
variant = preferences.get ("egg_like_newline"); | ||
variant = preferences.get ("egg-like-newline"); | ||
assert (variant != null); | ||
egg_like_newline_checkbutton.active = variant.get_boolean (); | ||
|
||
variant = preferences.get ("page_size"); | ||
variant = preferences.get ("page-size"); | ||
assert (variant != null); | ||
page_size_spinbutton.set_range (7.0, 16.0); | ||
page_size_spinbutton.set_increments (1.0, 1.0); | ||
page_size_spinbutton.value = (double) variant.get_int32 (); | ||
|
||
variant = preferences.get ("pagination_start"); | ||
variant = preferences.get ("pagination-start"); | ||
assert (variant != null); | ||
pagination_start_spinbutton.set_range (0.0, 7.0); | ||
pagination_start_spinbutton.set_increments (1.0, 1.0); | ||
pagination_start_spinbutton.value = (double) variant.get_int32 (); | ||
|
||
variant = preferences.get ("show_annotation"); | ||
variant = preferences.get ("show-annotation"); | ||
assert (variant != null); | ||
show_annotation_checkbutton.active = variant.get_boolean (); | ||
|
||
load_combobox ("period_style", period_style_combobox, 1); | ||
load_combobox ("initial_input_mode", initial_input_mode_combobox, 1); | ||
load_combobox ("period-style", period_style_combobox, 1); | ||
load_combobox ("initial-input-mode", initial_input_mode_combobox, 1); | ||
|
||
variant = preferences.get ("typing_rule"); | ||
variant = preferences.get ("typing-rule"); | ||
assert (variant != null); | ||
var model = (Gtk.ListStore) typing_rule_combobox.get_model (); | ||
Gtk.TreeIter iter; | ||
|
@@ -473,27 +473,27 @@ class Setup : Object { | |
out uc)) { | ||
keywords.add (uc.to_string ()); | ||
} | ||
preferences.set ("auto_start_henkan_keywords", | ||
preferences.set ("auto-start-henkan-keywords", | ||
keywords.to_array ()); | ||
preferences.set ("egg_like_newline", | ||
preferences.set ("egg-like-newline", | ||
egg_like_newline_checkbutton.active); | ||
preferences.set ("page_size", | ||
preferences.set ("page-size", | ||
(int) page_size_spinbutton.value); | ||
preferences.set ("pagination_start", | ||
preferences.set ("pagination-start", | ||
(int) pagination_start_spinbutton.value); | ||
preferences.set ("show_annotation", | ||
preferences.set ("show-annotation", | ||
show_annotation_checkbutton.active); | ||
save_combobox ("period_style", | ||
save_combobox ("period-style", | ||
period_style_combobox, 1); | ||
save_combobox ("initial_input_mode", | ||
save_combobox ("initial-input-mode", | ||
initial_input_mode_combobox, 1); | ||
|
||
Gtk.TreeIter iter; | ||
if (typing_rule_combobox.get_active_iter (out iter)) { | ||
var model = (Gtk.ListStore) typing_rule_combobox.get_model (); | ||
string rule; | ||
model.get (iter, 0, out rule, -1); | ||
preferences.set ("typing_rule", rule); | ||
preferences.set ("typing-rule", rule); | ||
} | ||
preferences.save (); | ||
} | ||
|
@@ -546,15 +546,14 @@ class Setup : Object { | |
} | ||
|
||
public static int main (string[] args) { | ||
Gtk.init (ref args); | ||
IBus.init (); | ||
Gtk.init (ref args); | ||
IBus.init (); | ||
Skk.init (); | ||
|
||
var bus = new IBus.Bus (); | ||
var config = bus.get_config (); | ||
var setup = new Setup (new Preferences (config)); | ||
var setup = new Setup (new Preferences ()); | ||
|
||
setup.run (); | ||
return 0; | ||
} | ||
setup.run (); | ||
return 0; | ||
} | ||
} |