Skip to content

Commit fb5b40b

Browse files
committed
refactor: simplify utility functions
1 parent 362fdae commit fb5b40b

18 files changed

+117
-485
lines changed

po/POTFILES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ src/ibus-chewing-lookup-table.c
88
src/ibus-chewing-preedit.c
99
src/ibus-chewing-util.c
1010
src/main.c
11-
src/maker-dialog-util.c

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
add_library(common STATIC
22
ibus-chewing-lookup-table.c
3-
maker-dialog-util.c
43

54
ibus-chewing-lookup-table.h
6-
maker-dialog-util.h
75
ibus-chewing-engine.h
86
)
97
target_link_libraries(common PUBLIC

src/ibus-chewing-engine.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "ibus-chewing-preedit.h"
2424
#include "ibus-chewing-lookup-table.h"
2525
#include "ibus-chewing-util.h"
26-
#include "maker-dialog-util.h"
2726
#include "ibus-chewing-engine-private.h"
2827
#include <chewing.h>
2928
#include <glib.h>
@@ -569,7 +568,7 @@ void ibus_chewing_engine_refresh_property(IBusChewingEngine *self,
569568
#ifndef UNIT_TEST
570569
IBUS_CHEWING_LOG(DEBUG, "refresh_property(%s) status=%x", prop_name, self->statusFlags);
571570

572-
if (STRING_EQUALS(prop_name, "InputMode")) {
571+
if (g_strcmp0(prop_name, "InputMode") == 0) {
573572

574573
ibus_property_set_label(self->InputMode,
575574
ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit)
@@ -585,7 +584,7 @@ void ibus_chewing_engine_refresh_property(IBusChewingEngine *self,
585584

586585
ibus_engine_update_property(IBUS_ENGINE(self), self->InputMode);
587586

588-
} else if (STRING_EQUALS(prop_name, "AlnumSize")) {
587+
} else if (g_strcmp0(prop_name, "AlnumSize") == 0) {
589588

590589
ibus_property_set_label(self->AlnumSize, chewing_get_ShapeMode(self->icPreEdit->context)
591590
? self->AlnumSize_label_full
@@ -601,7 +600,7 @@ void ibus_chewing_engine_refresh_property(IBusChewingEngine *self,
601600
if (self->statusFlags & ENGINE_FLAG_PROPERTIES_REGISTERED)
602601
ibus_engine_update_property(IBUS_ENGINE(self), self->AlnumSize);
603602

604-
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
603+
} else if (g_strcmp0(prop_name, "setup_prop") == 0) {
605604
#if IBUS_CHECK_VERSION(1, 5, 0)
606605
ibus_property_set_symbol(self->setup_prop, self->setup_prop_symbol);
607606
#endif
@@ -650,11 +649,11 @@ static IBusProperty *ibus_chewing_engine_get_ibus_property_by_name(IBusChewingEn
650649
g_return_val_if_fail(self != NULL, (IBusProperty *)0);
651650
g_return_val_if_fail(IBUS_IS_CHEWING_ENGINE(self), (IBusProperty *)0);
652651
{
653-
if (STRING_EQUALS(prop_name, "InputMode")) {
652+
if (g_strcmp0(prop_name, "InputMode") == 0) {
654653
return self->InputMode;
655-
} else if (STRING_EQUALS(prop_name, "AlnumSize")) {
654+
} else if (g_strcmp0(prop_name, "AlnumSize") == 0) {
656655
return self->AlnumSize;
657-
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
656+
} else if (g_strcmp0(prop_name, "setup_prop") == 0) {
658657
return self->setup_prop;
659658
}
660659
IBUS_CHEWING_LOG(MSG, "get_ibus_property_by_name(%s): NULL is returned", prop_name);
@@ -1017,7 +1016,7 @@ void commit_text(IBusChewingEngine *self) {
10171016
gboolean ibus_chewing_engine_process_key_event(IBusEngine *engine, KSym keySym, guint keycode,
10181017
KeyModifiers unmaskedMod) {
10191018
IBUS_CHEWING_LOG(MSG, "******** process_key_event(-,%x(%s),%x,%x) %s", keySym,
1020-
key_sym_get_name(keySym), keycode, unmaskedMod,
1019+
ibus_keyval_name(keySym), keycode, unmaskedMod,
10211020
modifiers_to_string(unmaskedMod));
10221021

10231022
IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine);
@@ -1081,17 +1080,17 @@ void ibus_chewing_engine_property_activate(IBusEngine *engine, const gchar *prop
10811080
IBUS_CHEWING_LOG(INFO, "property_activate(-, %s, %u)", prop_name, prop_state);
10821081
IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine);
10831082

1084-
if (STRING_EQUALS(prop_name, "InputMode")) {
1083+
if (g_strcmp0(prop_name, "InputMode") == 0) {
10851084
/* Toggle Chinese <-> English */
10861085
ibus_chewing_pre_edit_toggle_chi_eng_mode(self->icPreEdit);
10871086
IBUS_CHEWING_LOG(INFO, "property_activate chinese=%d", is_chinese_mode(self));
10881087
ibus_chewing_engine_refresh_property(self, prop_name);
1089-
} else if (STRING_EQUALS(prop_name, "AlnumSize")) {
1088+
} else if (g_strcmp0(prop_name, "AlnumSize") == 0) {
10901089
/* Toggle Full <-> Half */
10911090
ibus_chewing_pre_edit_toggle_full_half_mode(self->icPreEdit);
10921091
IBUS_CHEWING_LOG(INFO, "property_activate fullwidth=%d", is_fullwidth_mode(self));
10931092
ibus_chewing_engine_refresh_property(self, prop_name);
1094-
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
1093+
} else if (g_strcmp0(prop_name, "setup_prop") == 0) {
10951094
/* open preferences window */
10961095
char *argv[] = {QUOTE_ME(LIBEXEC_DIR) "/ibus-setup-chewing", NULL};
10971096
g_spawn_async(NULL, argv, NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, NULL);
@@ -1103,15 +1102,15 @@ void ibus_chewing_engine_property_activate(IBusEngine *engine, const gchar *prop
11031102

11041103
char ibus_chewing_engine_get_default_english_case(IBusChewingEngine *self) {
11051104
char *prop = self->prop_default_english_case;
1106-
return STRING_EQUALS(prop, "lowercase") ? 'l' : STRING_EQUALS(prop, "uppercase") ? 'u' : 'n';
1105+
return g_strcmp0(prop, "lowercase") == 0 ? 'l' : g_strcmp0(prop, "uppercase") == 0 ? 'u' : 'n';
11071106
}
11081107

11091108
char ibus_chewing_engine_get_chinese_english_toggle_key(IBusChewingEngine *self) {
11101109
char *prop = self->prop_chi_eng_mode_toggle;
1111-
return STRING_EQUALS(prop, "caps_lock") ? 'c'
1112-
: STRING_EQUALS(prop, "shift") ? 's'
1113-
: STRING_EQUALS(prop, "shift_l") ? 'l'
1114-
: STRING_EQUALS(prop, "shift_r") ? 'r'
1110+
return g_strcmp0(prop, "caps_lock") == 0 ? 'c'
1111+
: g_strcmp0(prop, "shift") == 0 ? 's'
1112+
: g_strcmp0(prop, "shift_l") == 0 ? 'l'
1113+
: g_strcmp0(prop, "shift_r") == 0 ? 'r'
11151114
: 'n';
11161115
return 'n';
11171116
}

src/ibus-chewing-lookup-table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "ibus-chewing-lookup-table.h"
22
#include "ibus-chewing-util.h"
3-
#include "maker-dialog-util.h"
3+
#include <ctype.h>
44

55
IBusLookupTable *ibus_chewing_lookup_table_new(ChewingContext *context) {
66
guint size = 10;

src/ibus-chewing-preedit-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
#define handle_log(funcName) \
7878
IBUS_CHEWING_LOG(INFO, "* self_handle_%s(-,%x(%s),%x(%s))", funcName, kSym, \
79-
key_sym_get_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
79+
ibus_keyval_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
8080

8181
KSym self_key_sym_fix(IBusChewingPreEdit *self, KSym kSym, KeyModifiers unmaskedMod);
8282

src/ibus-chewing-preedit.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#include "ibus-chewing-preedit.h"
33
#include "ibus-chewing-lookup-table.h"
44
#include "ibus-chewing-util.h"
5-
#include "maker-dialog-util.h"
65
#include "ibus-chewing-preedit-private.h"
6+
#include "ibus.h"
7+
#include <ctype.h>
78
#include <chewing.h>
89
#include <glib.h>
910

@@ -258,7 +259,7 @@ EventResponse self_handle_key_sym_default(IBusChewingPreEdit *self, KSym kSym,
258259
KSym fixedKSym = self_key_sym_fix(self, kSym, unmaskedMod);
259260

260261
IBUS_CHEWING_LOG(DEBUG, "* self_handle_key_sym_default(): new kSym %x(%s), %x(%s)", fixedKSym,
261-
key_sym_get_name(fixedKSym), unmaskedMod, modifiers_to_string(unmaskedMod));
262+
ibus_keyval_name(fixedKSym), unmaskedMod, modifiers_to_string(unmaskedMod));
262263
gint ret = chewing_handle_Default(self->context, fixedKSym);
263264

264265
/* Handle quick commit */
@@ -770,7 +771,7 @@ gboolean is_shift_toggle(KSym keyLast, KSym kSym, KeyModifiers unmaskedMod) {
770771
gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit *self, KSym kSym,
771772
KeyModifiers unmaskedMod) {
772773
IBUS_CHEWING_LOG(INFO, "***** ibus_chewing_pre_edit_process_key(-,%x(%s),%x(%s))", kSym,
773-
key_sym_get_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
774+
ibus_keyval_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));
774775
process_key_debug("Before response");
775776

776777
/* Find corresponding rule */

0 commit comments

Comments
 (0)