Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Define to the read-only
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION(0.16.1)

AC_ARG_ENABLE(opencc,
AC_HELP_STRING([--enable-opencc],
[Use opencc for simplified Chinese conversion]),
[enable_opencc=$enableval],
[enable_opencc=yes]
)
if test x"$enable_opencc" = x"yes"; then
# check opencc
PKG_CHECK_MODULES(OPENCC, [opencc >= 1.0.0], [
AC_DEFINE(HAVE_OPENCC, 1, [Define if found opencc])
CFLAGS="$CFLAGS $OPENCC_CFLAGS"
LDFLAGS="$LDFLAGS $OPENCC_LIBS"
])
fi

# OUTPUT files
AC_CONFIG_FILES(po/Makefile.in
Expand Down
1 change: 1 addition & 0 deletions ibus-array.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Source0: https://github.com/lexical/ibus-array/archive/release-%{version}.tar

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: gettext-devel
BuildRequires: opencc-devel

Requires: ibus

Expand Down
12 changes: 8 additions & 4 deletions po/zh_TW.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: ibus-array 0.2.2\n"
"Report-Msgid-Bugs-To: https://github.com/lexical/ibus-array/issues\n"
"POT-Creation-Date: 2023-03-18 17:29+0800\n"
"POT-Creation-Date: 2023-03-28 19:12+0800\n"
"PO-Revision-Date: 2019-12-10 22:12+0800\n"
"Last-Translator: Anthony Fok <foka@debian.org>\n"
"Language-Team: Chinese (traditional)\n"
Expand All @@ -27,15 +27,15 @@ msgstr "行列"
msgid "Array 30 Input Method 行列30輸入法"
msgstr "行列30輸入法 Array 30 Input Method"

#: src/engine.c:198
#: src/engine.c:219
msgid "Setup"
msgstr "設定"

#: src/engine.c:199
#: src/engine.c:220
msgid "Configure Array 30 engine"
msgstr "設定行列輸入法"

#: src/engine.c:464
#: src/engine.c:504
msgid ""
"1.comma 2.bracket 3.symbol 4.math 5.arrow 6.unit 7.table 8.roman 9.greek 0."
"bopomo"
Expand All @@ -52,3 +52,7 @@ msgstr "當有特別碼時,顯示提示"
#: setup/main.py:56
msgid "Special Code Only Mode"
msgstr "當有特別碼時,只能用特別碼輸入 (特別碼練習模式)"

#: setup/main.py:58
msgid "Convert output to simplified Chinese"
msgstr "出字時轉為簡體中文"
25 changes: 21 additions & 4 deletions setup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import sys
import os
import gi
Expand All @@ -34,7 +34,7 @@

class Setup:
def __init__(self, bus):
self.__bus = bus
self.__bus = bus
self.__config = self.__bus.get_config()
self.__config.connect("value-changed", self.on_value_changed, None)
self.__create_ui()
Expand All @@ -55,14 +55,19 @@ def __create_ui(self):
self.__window.vbox.pack_start(self.__special_notify_button, True, True, 10)
self.__special_only_button = Gtk.CheckButton(label=_("Special Code Only Mode"))
self.__window.vbox.pack_start(self.__special_only_button, True, True ,10)
self.__output_simplified_button = Gtk.CheckButton(label=_("Convert output to simplified Chinese"))
self.__window.vbox.pack_start(self.__output_simplified_button, True, True, 10)

current_special_mode = self.__read("SpecialOnly", False)
current_special_notify = self.__read("SpecialNotify", False)
current_output_simplified = self.__read("OutputSimplified", False)

if current_special_notify:
self.__special_notify_button.set_active(True)
if current_special_mode:
self.__special_only_button.set_active(True)
if current_output_simplified:
self.__output_simplified_button.set_active(True)

self.__window.show_all()

Expand All @@ -75,6 +80,7 @@ def run(self):
def apply(self):
select_special_notify = self.__special_notify_button.get_active()
select_special_mode = self.__special_only_button.get_active()
select_output_simplified = self.__output_simplified_button.get_active()

if select_special_notify:
self.__write("SpecialNotify", GLib.Variant.new_boolean(True))
Expand All @@ -86,6 +92,11 @@ def apply(self):
else:
self.__write("SpecialOnly", GLib.Variant.new_boolean(False))

if select_output_simplified:
self.__write("OutputSimplified", GLib.Variant.new_boolean(True))
else:
self.__write("OutputSimplified", GLib.Variant.new_boolean(False))

def on_value_changed(self, config, section, name, value, data):
if section == 'engine/Array':
if name == 'SpecialNotify':
Expand All @@ -96,9 +107,15 @@ def on_value_changed(self, config, section, name, value, data):

elif name == 'SpecialOnly':
if value:
self.__special_notify_button.set_active(True)
self.__special_only_button.set_active(True)
else:
self.__special_notify_button.set_active(False)
self.__special_only_button.set_active(False)

elif name == 'OutputSimplified':
if value:
self.__output_simplified_button.set_active(True)
else:
self.__output_simplified_button.set_active(False)

def __read(self, name, v):
value = self.__config.get_value("engine/Array", name)
Expand Down
43 changes: 42 additions & 1 deletion src/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "array.h"
#include "config.h"

#ifdef HAVE_OPENCC
# include <opencc.h>
#endif

#define _(String) gettext(String)
#define ARRAY_SHORT_CODE_EMPTY_STRING "⎔"

Expand Down Expand Up @@ -100,8 +104,12 @@ static IBusEngineClass *parent_class = NULL;
static IBusConfig *config = NULL;
static gboolean is_special_notify;
static gboolean is_special_only;
static gboolean is_output_simplified;
static gboolean is_aux_shown = FALSE;
static ArrayContext *array_context = NULL;
#ifdef HAVE_OPENCC
static opencc_t cc_handle;
#endif

GType ibus_array_engine_get_type (void) {
static GType type = 0;
Expand Down Expand Up @@ -135,6 +143,7 @@ void ibus_array_init (IBusBus *bus) {

is_special_notify = FALSE;
is_special_only = FALSE;
is_output_simplified = FALSE;

/* load config */
GVariant* value;
Expand All @@ -147,14 +156,26 @@ void ibus_array_init (IBusBus *bus) {
if (value && g_variant_classify(value) == G_VARIANT_CLASS_BOOLEAN)
is_special_only = g_variant_get_boolean(value);

value = ibus_config_get_value (config, "engine/Array", "OutputSimplified");
if (value && g_variant_classify(value) == G_VARIANT_CLASS_BOOLEAN)
is_output_simplified = g_variant_get_boolean(value);

/* gettext preparation */
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);

#ifdef HAVE_OPENCC
cc_handle = opencc_open("tw2s.json");
#endif
}

void ibus_array_exit (void)
{
#ifdef HAVE_OPENCC
opencc_close(cc_handle);
#endif

array_release_context(array_context);

if (g_object_is_floating (config))
Expand Down Expand Up @@ -419,7 +440,25 @@ static gboolean ibus_array_engine_commit_current_candidate (IBusArrayEngine *arr
return FALSE;
}
}
ibus_engine_commit_text((IBusEngine*)arrayeng, text);

#ifdef HAVE_OPENCC
if (is_output_simplified) {
char *converted = opencc_convert_utf8(cc_handle,
text->text,
strlen(text->text));
if(converted) {
IBusText* newtext = ibus_text_new_from_string(converted);
ibus_engine_commit_text((IBusEngine*)arrayeng, newtext);
opencc_convert_utf8_free(converted);
} else {
ibus_engine_commit_text((IBusEngine*)arrayeng, text);
}
} else {
#endif
ibus_engine_commit_text((IBusEngine*)arrayeng, text);
#ifdef HAVE_OPENCC
}
#endif

ibus_array_engine_reset((IBusEngine*)arrayeng);

Expand Down Expand Up @@ -741,5 +780,7 @@ static void ibus_config_value_changed_cb (IBusConfig *config, const gchar *secti
is_special_notify = g_variant_get_boolean (value);
else if (g_strcmp0(name, "specialonly") == 0)
is_special_only = g_variant_get_boolean (value);
else if (g_strcmp0(name, "outputsimplified") == 0)
is_output_simplified = g_variant_get_boolean (value);
}