Codebase list ibus-array / upstream/0.1.0
Imported Upstream version 0.1.0 Keng-Yu Lin 9 years ago
8 changed file(s) with 140 addition(s) and 174 deletion(s). Raw diff Collapse all Expand all
1919
2020 SUBDIRS = \
2121 src \
22 setup \
22 setup \
2323 icons \
24 data \
24 data \
2525 m4 \
2626 po \
2727 $(NULL)
0
0 zh_TW
1717 # or entity, or to disclaim their copyright. The empty string stands for
1818 # the public domain; in this case the translators are expected to disclaim
1919 # their copyright.
20 COPYRIGHT_HOLDER = Huang Peng <shawn.p.huang@gmail.com>
20 COPYRIGHT_HOLDER = Keng-Yu Lin <kengyu@lexical.tw>
2121
2222 # This is the email address or URL to which the translators shall report
2323 # bugs in the untranslated strings:
0 src/engine.c
1 setup/main.py
0 # ibus-array Traditional Chinese Translation
1 # Copyright (C) 2014 Keng-Yu Lin <kengyu@lexical.tw>
2 # This file is distributed under the same license as the ibus-package package.
3 # Keng-Yu Lin <kengyu@lexical.tw>, 2014
4 #
5 msgid ""
6 msgstr ""
7 "Project-Id-Version: 0.0.4\n"
8 "Report-Msgid-Bugs-To: http://code.google.com/p/ibus/issues/entry\n"
9 "POT-Creation-Date: 2014-11-01 18:21+0800\n"
10 "PO-Revision-Date: 2014-11-01 16:44+0800\n"
11 "Last-Translator: Keng-Yu Lin <kengyu@lexical.tw>\n"
12 "Language-Team: Chinese (traditional)\n"
13 "Language: zh_TW\n"
14 "MIME-Version: 1.0\n"
15 "Content-Type: text/plain; charset=UTF-8\n"
16 "Content-Transfer-Encoding: 8bit\n"
17
18 #: src/engine.c:179
19 msgid "Setup"
20 msgstr "設定"
21
22 #: src/engine.c:180
23 msgid "Configure Array 30 engine"
24 msgstr "設定行列輸入法"
25
26 #: src/engine.c:422
27 msgid ""
28 "1.comma 2.bracket 3.symbol 4.math 5.arrow 6.unit 7.table 8.roman 9.greek 0."
29 "bopomo"
30 msgstr "1.標點 2.括弧 3.符號 4.數學 5.箭頭 6.單位 7.圖表 8.羅馬 9.希臘 0.注音"
31
32 #: setup/main.py:43
33 msgid "ibus-array setup"
34 msgstr "行列輸入法設定"
35
36 #: setup/main.py:50
37 msgid "Special Code Notification"
38 msgstr "當有特別碼時,顯示提示"
39
40 #: setup/main.py:52
41 msgid "Speical Code Only Mode"
42 msgstr "當有特別碼時,只能用特別碼輸入 (特別碼練習模式)"
2222
2323 import sys
2424 import os
25 import gobject
26 import gtk
27 import ibus
25 from gi.repository import GLib
26 from gi.repository import Gtk
27 from gi.repository import IBus
28 from gettext import gettext as _
2829 import gettext
2930 import config
3031
3132 class Setup:
32 def __init__(self):
33 self.__bus = ibus.Bus()
33 def __init__(self, bus):
34 self.__bus = bus
3435 self.__config = self.__bus.get_config()
3536 self.__config.connect("value-changed", self.on_value_changed, None)
3637 self.__create_ui()
3738
3839 def __create_ui(self):
39 self.__window = gtk.Dialog('ibus-array setup', None,
40 gtk.DIALOG_MODAL,
41 (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
42 gtk.STOCK_OK, gtk.RESPONSE_OK)
40 gettext.bindtextdomain("ibus-array")
41 gettext.textdomain("ibus-array")
42 self.__window = Gtk.Dialog(_('ibus-array setup'), None,
43 Gtk.DialogFlags.MODAL,
44 (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
45 Gtk.STOCK_OK, Gtk.ResponseType.OK)
4346 )
4447 icon_file = os.path.join(config.datadir, "ibus-array", "icons", "ibus-array.png")
4548 self.__window.set_icon_from_file(icon_file)
46 self.__special_notify_button = gtk.CheckButton("Special Code Notification")
49 self.__special_notify_button = Gtk.CheckButton(_("Special Code Notification"))
4750 self.__window.vbox.pack_start(self.__special_notify_button, True, True, 10)
48 self.__special_only_button = gtk.CheckButton("Speical Code Only Mode")
51 self.__special_only_button = Gtk.CheckButton(_("Speical Code Only Mode"))
4952 self.__window.vbox.pack_start(self.__special_only_button, True, True ,10)
5053
51 current_special_mode = self.__read("SpecialOnly", "0")
52 current_special_notify = self.__read("SpecialNotify", "0")
54 current_special_mode = self.__read("SpecialOnly", False)
55 current_special_notify = self.__read("SpecialNotify", False)
5356
54 if current_special_notify == "1":
57 if current_special_notify:
5558 self.__special_notify_button.set_active(True)
56 if current_special_mode == "1":
59 if current_special_mode:
5760 self.__special_only_button.set_active(True)
5861
5962 self.__window.show_all()
6063
6164 def run(self):
6265 res = self.__window.run()
63 if res == gtk.RESPONSE_OK:
66 if res == Gtk.ResponseType.OK:
6467 self.apply()
6568 self.__window.destroy()
6669
6972 select_special_mode = self.__special_only_button.get_active()
7073
7174 if select_special_notify:
72 self.__write("SpecialNotify", "1")
75 self.__write("SpecialNotify", GLib.Variant.new_boolean(True))
7376 else:
74 self.__write("SpecialNotify", "0")
77 self.__write("SpecialNotify", GLib.Variant.new_boolean(False))
78
7579 if select_special_mode:
76 self.__write("SpecialOnly", "1")
80 self.__write("SpecialOnly", GLib.Variant.new_boolean(True))
7781 else:
78 self.__write("SpecialOnly", "0")
82 self.__write("SpecialOnly", GLib.Variant.new_boolean(False))
7983
8084 def on_value_changed(self, config, section, name, value, data):
8185 if section == 'engine/Array':
8286 if name == 'SpecialNotify':
83 if value == '1':
87 if value:
8488 self.__special_notify_button.set_active(True)
8589 else:
8690 self.__special_notify_button.set_active(False)
91
8792 elif name == 'SpecialOnly':
88 if value == '1':
93 if value:
8994 self.__special_notify_button.set_active(True)
9095 else:
9196 self.__special_notify_button.set_active(False)
9297
9398 def __read(self, name, v):
94 return self.__config.get_value("engine/Array", name, v)
99 value = self.__config.get_value("engine/Array", name)
100 if value is None:
101 return v
102 return value
95103
96104 def __write(self, name, v):
97105 return self.__config.set_value("engine/Array", name, v)
98106
99107 if __name__ == '__main__':
100 Setup().run()
108 bus = IBus.Bus()
109 if bus.is_connected():
110 Setup(bus).run()
2424 main.c \
2525 engine.c \
2626 engine.h \
27 array.c \
28 array.h \
27 array.c \
28 array.h \
2929 $(NULL)
3030 ibus_engine_array_CFLAGS = \
3131 @IBUS_CFLAGS@ \
3232 @SQLITE3_CFLAGS@ \
33 -DLOCALEDIR=\"$(localedir)\" \
3334 -DPKGDATADIR=\"$(pkgdatadir)\" \
34 -DLIBEXECDIR=\"$(libexecdir)\" \
35 -DLIBEXECDIR=\"$(libexecdir)\" \
3536 $(NULL)
3637 ibus_engine_array_LDFLAGS = \
3738 @IBUS_LIBS@ \
3839 @SQLITE3_LIBS@ \
40 @LIBINTL@ \
3941 $(NULL)
4042
4143 component_DATA = \
00 /* vim:set et sts=4: */
11
2 #include <locale.h>
3 #include <libintl.h>
24 #include "engine.h"
35 #include "array.h"
4
6 #include "config.h"
7
8 #define _(String) gettext(String)
59 #define ARRAY_SHORT_CODE_EMPTY_STRING "⎔"
610
711 typedef struct _IBusArrayEngine IBusArrayEngine;
812 typedef struct _IBusArrayEngineClass IBusArrayEngineClass;
913
10 struct _IBusArrayEngine {
14 struct _IBusArrayEngine
15 {
1116 IBusEngine parent;
1217
1318 /* members */
1924 IBusPropList *prop_list;
2025 };
2126
22 struct _IBusArrayEngineClass {
27 struct _IBusArrayEngineClass
28 {
2329 IBusEngineClass parent;
2430 };
2531
6773 static void ibus_array_engine_show_special_code(IBusArrayEngine *arrayeng);
6874 static void ibus_array_engine_show_special_code_for_char(IBusArrayEngine *arrayeng, gchar *ch);
6975
70 static void ibus_config_value_changed (IBusConfig *config, const gchar *section, const gchar *name,
71 #if IBUS_CHECK_VERSION(1,3,99)
72 GVariant *value,
73 #else
74 GValue *value,
75 #endif /* !IBUS_CHECK_VERSION(1,3,99) */
76 gpointer user_data);
77
78 static gboolean config_get_string (IBusConfig *config, const gchar *section, const gchar *name, gchar **result);
76 static void ibus_config_value_changed_cb (IBusConfig *config, const gchar *section, const gchar *name, GVariant *value, gpointer unused);
7977
8078 static IBusEngineClass *parent_class = NULL;
8179 static IBusConfig *config = NULL;
8280 static gboolean is_special_notify;
8381 static gboolean is_special_only;
8482 static gboolean is_aux_shown = FALSE;
85
8683 static ArrayContext *array_context = NULL;
8784
88 GType
89 ibus_array_engine_get_type (void)
85 GType ibus_array_engine_get_type (void)
9086 {
9187 static GType type = 0;
9288
10399 };
104100
105101 if (type == 0)
106 {
107102 type = g_type_register_static (IBUS_TYPE_ENGINE, "IBusArrayEngine", &type_info, (GTypeFlags) 0);
108 }
109103
110104 return type;
111105 }
113107 void ibus_array_init (IBusBus *bus)
114108 {
115109 gboolean res;
116 gchar *str;
117110
118111 array_context = array_create_context();
119112
120113 config = ibus_bus_get_config (bus);
114 if (config)
115 g_object_ref_sink (config);
121116
122117 is_special_notify = FALSE;
123118 is_special_only = FALSE;
124119
125 str = NULL;
126 res = config_get_string (config, "engine/Array", "SpecialNotify", &str);
127 if (res)
128 {
129 if (g_strcmp0(str, "1") == 0)
130 is_special_notify = TRUE;
131 g_free (str);
132 }
133
134 res = config_get_string (config, "engine/Array", "SpecialOnly", &str);
135 if (res)
136 {
137 if (g_strcmp0(str, "1") == 0)
138 is_special_only = TRUE;
139 g_free (str);
140 }
120 /* load config */
121 GVariant* value;
122
123 value = ibus_config_get_value (config, "engine/Array", "SpecialNotify");
124 if (value && g_variant_classify(value) == G_VARIANT_CLASS_BOOLEAN)
125 is_special_notify = g_variant_get_boolean(value);
126
127 value = ibus_config_get_value (config, "engine/Array", "SpecialOnly");
128 if (value && g_variant_classify(value) == G_VARIANT_CLASS_BOOLEAN)
129 is_special_only = g_variant_get_boolean(value);
130
131 /* gettext preparation */
132 setlocale (LC_ALL, "");
133 bindtextdomain (PACKAGE, LOCALEDIR);
134 textdomain (PACKAGE);
141135 }
142136
143137 void ibus_array_exit (void)
146140
147141 if (g_object_is_floating (config))
148142 g_object_unref(config);
149 config = NULL;
150143 }
151144
152145 static void ibus_array_engine_class_init (IBusArrayEngineClass *klass)
182175
183176 arrayeng->table = ibus_lookup_table_new (10, 0, FALSE, TRUE);
184177 g_object_ref_sink (arrayeng->table);
185 setup_label = ibus_text_new_from_string("Setup");
186 setup_tooltip = ibus_text_new_from_string("Configure Array 30 engine");
178 setup_label = ibus_text_new_from_string (_("Setup"));
179 setup_tooltip = ibus_text_new_from_string (_("Configure Array 30 engine"));
187180 setup_prop = ibus_property_new("setup", PROP_TYPE_NORMAL, setup_label, "gtk-preferences", setup_tooltip, TRUE, TRUE, 0, NULL);
188181 g_object_ref_sink (setup_prop);
189182
192185
193186 ibus_prop_list_append(arrayeng->prop_list, setup_prop);
194187
195 g_signal_connect (config, "value-changed", G_CALLBACK(ibus_config_value_changed), arrayeng);
188 g_signal_connect (config, "value-changed", G_CALLBACK(ibus_config_value_changed_cb), NULL);
196189 }
197190
198191 static void ibus_array_engine_destroy (IBusArrayEngine *arrayeng)
201194 g_object_unref(arrayeng->prop_list);
202195 arrayeng->prop_list = NULL;
203196 }
197
204198 if (arrayeng->preedit) {
205199 g_string_free (arrayeng->preedit, TRUE);
206200 arrayeng->preedit = NULL;
220214 g_string_assign (arrayeng->preedit, "");
221215 arrayeng->cursor_pos = 0;
222216 arrayeng->space_press_count = 0;
217
223218 ibus_array_engine_update_preedit (arrayeng);
224219 ibus_engine_hide_lookup_table (engine);
225220 ibus_engine_hide_auxiliary_text (engine);
226
227221 parent_class->reset(engine);
228222 }
229223
240234 static void ibus_array_engine_focus_in (IBusEngine *engine)
241235 {
242236 IBusArrayEngine *arrayeng = (IBusArrayEngine*)engine;
243
244237 ibus_engine_register_properties (engine, arrayeng->prop_list);
245
246238 parent_class->focus_in (engine);
247239 }
248240
267259 GArray *candidates = NULL;
268260
269261 if (arrayeng->preedit->len <= 2 && arrayeng->space_press_count == 0)
270 {
271262 candidates = array_get_candidates_from_short(array_context, arrayeng->preedit->str);
272 }
273263 else
274 {
275264 candidates = array_get_candidates_from_main(array_context, arrayeng->preedit->str);
276 }
277265
278266 if (candidates == NULL)
279267 {
288276 }
289277
290278 for (i = 0; i < candidates->len; i++)
291 {
292279 ibus_lookup_table_append_candidate (arrayeng->table, ibus_text_new_from_string (g_array_index(candidates, gchar*, i)));
293 }
294280
295281 array_release_candidates(candidates);
296282
315301 {
316302 retval = 0;
317303 if (retval != 0)
318 {
319 ibus_attr_list_append (text->attrs,
320 ibus_attr_foreground_new (0xff0000, 0, array_preedit->len));
321 }
304 ibus_attr_list_append (text->attrs, ibus_attr_foreground_new (0xff0000, 0, array_preedit->len));
322305 }
323306
324307 ibus_engine_update_preedit_text ((IBusEngine *)arrayeng, text, array_preedit->len, TRUE);
308
325309 if (G_IS_OBJECT (text) && g_object_is_floating (text))
326310 g_object_unref (text);
327311
358342 }
359343
360344 for (i = 0; i < candidates->len; i++)
361 {
362345 ibus_lookup_table_append_candidate (arrayeng->table, ibus_text_new_from_string (g_array_index(candidates, gchar*, i)));
363 }
364346
365347 array_release_candidates(candidates);
366348
388370 if (check_special)
389371 {
390372 if (is_special_notify)
391 {
392373 ibus_array_engine_show_special_code_for_char (arrayeng, text->text);
393 }
394 if (is_special_only) {
374
375 if (is_special_only)
395376 return FALSE;
396 }
397377 }
398378 }
399379 ibus_engine_commit_text((IBusEngine*)arrayeng, text);
401381 ibus_array_engine_reset((IBusEngine*)arrayeng);
402382
403383 if (is_special_notify && check_special)
404 {
405384 ibus_array_engine_show_special_code_for_char(arrayeng, temptext);
406 }
407385
408386 g_free(temptext);
409387
440418
441419 if (g_strcmp0(arrayeng->preedit->str, "w") == 0)
442420 {
443 ibus_array_engine_update_auxiliary_text(arrayeng, "1.標點 2.括弧 3.符號 4.數學 5.方向 6.單位 7.圖表 8.羅馬 9.希臘 0.注音");
421 ibus_array_engine_update_auxiliary_text(arrayeng, _("1.comma 2.bracket 3.symbol 4.math 5.arrow 6.unit 7.table 8.roman 9.greek 0.bopomo"));
444422 is_aux_shown = TRUE;
445423 }
446424 else if (is_aux_shown)
460438 return FALSE;
461439
462440
463 switch (keyval) {
441 switch (keyval)
442 {
464443 case IBUS_space:
465444 if (arrayeng->preedit->len == 0)
466445 return FALSE;
467446 ibus_array_engine_space_press(arrayeng);
468447 return TRUE;
448
469449 case IBUS_Return:
470450 if (arrayeng->preedit->len == 0)
471451 return FALSE;
523503
524504 if (is_alpha (keyval) || keyval == IBUS_period || keyval == IBUS_comma || keyval == IBUS_slash || keyval == IBUS_semicolon)
525505 {
526 if (arrayeng->space_press_count == 1) {
506 if (arrayeng->space_press_count == 1)
527507 if (arrayeng->table->candidates->len > 0)
528508 {
529509 gboolean commit_rev;
534514 } else {
535515 ibus_array_engine_reset((IBusEngine*)arrayeng);
536516 }
537 }
538517
539518 if (arrayeng->preedit->len >= 5)
540 {
541519 return TRUE;
542 }
543520
544521 g_string_insert_c (arrayeng->preedit, arrayeng->cursor_pos, keyval);
545522
611588
612589 if (arrayeng->table->candidates->len > 0)
613590 {
614
615591 ibus_lookup_table_set_cursor_pos (arrayeng->table, 0);
616
617592 commit_rev = ibus_array_engine_commit_current_candidate(arrayeng);
618593 }
619594 else
620 {
621595 ibus_array_engine_reset((IBusEngine*)arrayeng);
622 }
623596 }
624597 }
625598
631604 {
632605 text = ibus_text_new_from_string(aux_string);
633606 ibus_engine_update_auxiliary_text((IBusEngine*)arrayeng, text, TRUE);
634
635 if (g_object_is_floating (text))
636 g_object_unref (text);
637607 }
638608 }
639609
660630 g_string_free(keystr, TRUE);
661631 g_free(show_str);
662632 }
663 else {
633 else
664634 ibus_engine_hide_auxiliary_text((IBusEngine*)arrayeng);
665 }
666635
667636 array_release_candidates(candidates);
668637 }
687656 g_free(show_str);
688657 }
689658 else
690 {
691659 ibus_engine_hide_auxiliary_text((IBusEngine*)arrayeng);
692 }
693660
694661 array_release_candidates(candidates);
695662 }
716683 }
717684 }
718685
719 static gboolean config_get_string (IBusConfig *config, const gchar *section, const gchar *name, gchar **result)
720 {
721 #if IBUS_CHECK_VERSION(1,3,99)
722 GVariant *value = NULL;
723
724 g_return_val_if_fail (result != NULL, FALSE);
725
726 value = ibus_config_get_value (config, section, name);
727 if (value)
728 {
729 *result = g_strdup (g_variant_get_string (value, NULL));
730 g_variant_unref (value);
731 return TRUE;
732 }
733 return FALSE;
734 #else
735 GValue value = { 0 };
736
737 g_return_val_if_fail (result != NULL, FALSE);
738
739 if (ibus_config_get_value (config, section, name, &value)) {
740 *result = g_strdup (g_value_get_string (&value));
741 g_value_unset (&value);
742 return TRUE;
743 }
744 return FALSE;
745 #endif /* !IBUS_CHECK_VERSION(1,3,99) */
746 }
747
748 #if IBUS_CHECK_VERSION(1,3,99)
749 #define _g_variant_get_string g_variant_get_string
750 #else
751 #define _g_variant_get_string(value, length) g_value_get_string(value)
752 #endif /* !IBUS_CHECK_VERSION(1,3,99) */
753
754 static void ibus_config_value_changed (IBusConfig *config, const gchar *section, const gchar *name,
755 #if IBUS_CHECK_VERSION(1,3,99)
756 GVariant *value,
757 #else
758 GValue *value,
759 #endif /* !IBUS_CHECK_VERSION(1,3,99) */
760 gpointer user_data)
761 {
762 IBusArrayEngine *arrayeng = (IBusArrayEngine*)user_data;
763
764 if (g_strcmp0(section, "engine/Array") == 0)
765 {
766 if (g_strcmp0(name, "SpecialNotify") == 0) {
767 const gchar* str = _g_variant_get_string(value, NULL);
768 if (g_strcmp0(str, "1") == 0) {
769 is_special_notify = TRUE;
770 }
771 else {
772 is_special_notify = FALSE;
773 }
774 }
775 else if (g_strcmp0(name, "SpecialOnly") == 0) {
776 const gchar* str = _g_variant_get_string(value, NULL);
777 if (g_strcmp0(str, "1") == 0) {
778 is_special_only = TRUE;
779 }
780 else {
781 is_special_only = FALSE;
782 }
783 }
784 }
785 }
686 static void ibus_config_value_changed_cb (IBusConfig *config, const gchar *section, const gchar *name, GVariant *value, gpointer unused)
687 {
688 if (g_strcmp0(section, "engine/array") == 0)
689 if (g_strcmp0(name, "specialnotify") == 0)
690 is_special_notify = g_variant_get_boolean (value);
691 else if (g_strcmp0(name, "specialonly") == 0)
692 is_special_only = g_variant_get_boolean (value);
693 }
694