From 8f664730dadbf40ce26410d6445993e23235e9c2 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 4 Feb 2024 00:40:07 +0900 Subject: [PATCH 01/24] feat!: removed deprecated GtkStatusIcon support --- icons/ibus-chewing-chi-full.svg | 237 ----------------------------- icons/ibus-chewing-chi-half.svg | 239 ----------------------------- icons/ibus-chewing-eng-full.svg | 237 ----------------------------- icons/ibus-chewing-eng-half.svg | 240 ------------------------------ icons/ibus-chewing-orig.png | Bin 4660 -> 0 bytes icons/ibus-chewing-template.svg | 193 ------------------------ src/CMakeLists.txt | 7 - src/IBusChewingSystray.c | 212 -------------------------- src/IBusChewingSystray.h | 135 ----------------- src/IBusChewingUtil.c | 2 +- src/ibus-chewing-engine-private.h | 1 - src/ibus-chewing-engine.c | 8 +- src/ibus-chewing-engine.h | 3 +- test/CMakeLists.txt | 2 - 14 files changed, 3 insertions(+), 1513 deletions(-) delete mode 100644 icons/ibus-chewing-chi-full.svg delete mode 100644 icons/ibus-chewing-chi-half.svg delete mode 100644 icons/ibus-chewing-eng-full.svg delete mode 100644 icons/ibus-chewing-eng-half.svg delete mode 100644 icons/ibus-chewing-orig.png delete mode 100644 icons/ibus-chewing-template.svg delete mode 100644 src/IBusChewingSystray.c delete mode 100644 src/IBusChewingSystray.h diff --git a/icons/ibus-chewing-chi-full.svg b/icons/ibus-chewing-chi-full.svg deleted file mode 100644 index 229651b..0000000 --- a/icons/ibus-chewing-chi-full.svg +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/icons/ibus-chewing-chi-half.svg b/icons/ibus-chewing-chi-half.svg deleted file mode 100644 index 5bbbec3..0000000 --- a/icons/ibus-chewing-chi-half.svg +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/icons/ibus-chewing-eng-full.svg b/icons/ibus-chewing-eng-full.svg deleted file mode 100644 index 200a87e..0000000 --- a/icons/ibus-chewing-eng-full.svg +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/icons/ibus-chewing-eng-half.svg b/icons/ibus-chewing-eng-half.svg deleted file mode 100644 index b71bda6..0000000 --- a/icons/ibus-chewing-eng-half.svg +++ /dev/null @@ -1,240 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/icons/ibus-chewing-orig.png b/icons/ibus-chewing-orig.png deleted file mode 100644 index 9b785b51965736e9dc1ff3ddd112aff109298fb3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4660 zcmV-463gw0P)N6L_t(&-nE)(bX?Vu$A53_MXheN zcFB?~+gP@Y@uC1`z+gxi2Mh@rz$bWE#zPh$A;WBUdv3+|={4ElF^v7cV(z8Wu)6ayHPXA4|CX4IX!pOvhW#(+EOp>lHlW5c? z8nyY$Uy>|a=I5^!+3zR4b0^k4_fv4z8F&}WJ7F8H>mVEp%S>RThOx{fvB-Nw_P$84 zbS@{Kb2AeF5($TgAC3}@+N@n$%$hafDF*xdEn+c;dGkDInsmg8g>94E`WBL`PkLKS!yl?Sq)j#%C7T|?NJTMH!(>xYY%7iHn1Dn!8D*$v2g7~4a{z2x zuwg@t=bnpm{q?2%;0IOsd=mZr7LkZWb90v6yR*FUMv_Rx;+kv1eCu1~l$EK|I+c9m zO-6tFdqS6efzq#k1=*vI19K3zjpWghq}&2{{ly&I^-I!YefWZv_=DAW1LgP&D+z?_ zDW7>3s_w@htVUKebYGZVf4qmD{hP@q2T(gYOn(0J5!SDdvT9X`MT@-Lbyq)o_GB3t zut}v{gb)-KDkPIGv6#(+4-S$@xNO`w169qBgdH1V@PYMs=FX+^?%Tj|Fb;NN_x3UN z;;Upn{D{!%FA%=sGGxD>aMfZe=bTG#>z_F5@=b)w8&Om*lB`UC{G@mT6$l}yoO3Sf ziWRN&^jK&bw6quu3|O3Wl85up4={JGhgq|9!eNzgSYdeB=E^I(*uFi5qQGSPZaRa} z(n@UOCX!pU|9p2 zCvbdwOjaqWUW(e+XH!$7v1Uz}OD_#EcdmzEP)3%gqAw~^Xl(SdYgdLfYl={m!(*cB zA7$`?^|*$Cr=bC@x(a{O5~6aFpB0oVdnwl z6B&HqfI&xx$@1j|c)j_mlBVIBCjIN~qwm{yk=eZmAp~Ye7k%sQ#g0ZPyX6~%KEG;; zUELc5z|4-Fcmz&l@aD}4TvxDS#q=9ZD=(w`+cy#2@FZPVT}Q$4GqC#mNpF9b;;XNu z?3S-1snbm<;aC~W%*fvlz`%gT^Usg6c(ISBrXz=2ub)ZvL*HfW#aD@Z^+v40UOe>; zl-~FilwfdrB_R;P#j&y{4B)s^=y$&xWAEN9S6mS$7*vir))^ilx#ca~WD5T&O*kVX zM80$*@n1fVYZz0;XHtWhnK}I7A{Qx7^apzI|D)zrKX3Ds5WB!WAU9{)Nuf z|3d1`?acV${Z#+wy=c{ylz#0?)IRwLN+?A1k&Q&Y{0*|rEfcyPe=(}&2gGsagM=ij zD5^Jq59qqYt+$rb(P6T7Z5N9d`!G$xhaYCR^2#t*T@{|zoIO0k(Bn@r^yE|cmMo&? z(TDJzwiHRut&gN>gs)tU?Dx_0Z?`h~@{2g}I5VI933^=(f$&WHp?d!B6^B2(Kf>v! z=`3C9L)WLza3LIYUzk8~Jxs^B+uIGXXi>9(9RhZU6)O&ijt*lgH@7U2*z%TWyWldh zzv&z?^wXaUJCQsxmv>z;_J`NS$2IfCPW+La)~@Xo zZEe|UY&c@at9OcbU%XY=wjnsuWIz1jpa=wZi%TwP7kl?+rW&$sF}UGz(YErRMD&p- zg*6zRc;{rY!tCx5R%}?ft~*6{IGT|Du8|NboJo!3TRpM|1GJo8N5wD*$9 zGVM7a9EXtC;#0HISVM!PTZXZE`f!GaF}u34x_hzv2eJD4v3mP)M&h{H41&p(LA&~q&+(dHX z(Vjh7uDv!wO^wEN*OjnxWg(g-;ql1${W;*}}U+nyp!-PU5uw;4q9b7&RCLz z7p*3}XBToXi2uxG2+Lylr~iZbN(9;OLoF>v_8vRbpTINDRwZm(;PXw5UUjvGs!Bv6 zCfl~9*|#r?EJIV1pYzTOj7JL8g0q(4Kl5}D0wgJq2Ft+^zE3S7y=O=6Js^8LXtgzf zz`N*V)UwhOavpN5c6itUVD;)EF1jekkz7~cy199}x=gpgIZMuAmLlI5J^=LwvEx+j@8?bZ{Y%zvXUd-XN3^F z_F59la`Ad)8XGQ`~v+fACA4L<%j3rK9+mSWqsB(f|M4lB%_?W3v5&lzXF)`CMP}c#x2AVnd8R z{~}g*FNw{s0}_J|Jd7~12-o6J6-w{iLFU8VjJ^B^s@H!X-zg_g*s^WGV~@q?>@+y@ z%mC}wRnXRE(AjBGR;E&0tMT;HBW&J0%G$MIZo94GnCYlOuI~5W`8_fp?xAqyr;&Z$ zT&*98ll|ypKq2|(w@Gb#583O%HL}RQ0*Y2&f^W$w$iX1OG)cVjN5)>-jBs5Ne|nwt zyC38M*t|KxGtZ1rSLfmW`>QzToT(S1*Ir8i;PD(E)6eYzML{kMkl6Y<$*q6RmD0ih zN?8dwE+7c5I-laN{407*HGQ|=M`q_oRNng^=rijkj0Mg;oAd{}uzI`k&TFLb(<>(4 zz58yOn{MhM6jIo7cNFED(j0I>S|kt7Yz z{Dw&zLjuP^Sa#kdve%0eE&{}%Vh=zn<#OSLK`y>H$lSRejwQ03(`jijXl*rUYcptW z&izFqCjI@nj-l&{!vNIcFj_@9X4}CDLryA%vF`wCRVCg9^CtlSduSM=wGGcnha0z& zrlHr>PI0KFM(5_6%O2}30swTZ=SA`y$;UW@j2ldi7ZN)8R#WHPw}%;%FSE>>8++(Su;LP<%k zGKE44vJ7=~I$rN#CyR14St;!SyITdWquYe^wQAap|n)RfYPOsl%jArt6g5@^y-?xC}R)KD+>RH4J?JAzUQtXX-q4S1r}^ zOPMoUqohQg(uzNt2q8$gN%mwvW=rx-3S>VQ1utNZK0A-5c#kj)l-1DsT6K{YPWe?`W-ezA7zF%gQdR3I5@Nz2WT-`X*Jr2 zSlx^|W5~#a)gtQknMBNPMx9aGjaKgLyN3@mAMvx=O$3yJNfB^e+-w#}*N_YR$Q}>r z(O&xZZXrF^kC}~=9_=PRu#fauFOF>>NfI^lF64|$H;(sprl#W*V8Uhd*sF}Xqezm5 zj6z5WQm&R$uh(%-U^xrD3ph!iL#;l8Qni$gu_w5*?;em85Ei{w4>tBEB9O`AjwSPG zwQZ${?0cD5_xrfEfvo6w{H2u4Xd)1vNuao%lIo?%iay18H=E57#81d+{!ejXXchlE z@(T*&0N<~?oAV3Lqf9L$C>Ns3`V^fKrT9>eQ=`x1?#eqTQbPFvoZ%7dXegmIY$59INd5Y#Kq^M%S6r)0j+$zUM5r&CcT7q2Q z$L#0?To52EYg&hv6`aN#&up5r`{}WIj_Q2I&9c|n2f}56w~;RvU6%KL0)Wxdikr>k zwZMhzB1{W0o(}e46sxBXv%Lf3KpRHeL9DKB+;kfMvQw$NcO6bD1qg&~Vs%EQb*f6O z?A|WHmI!H3{U;hTP{UA7D?AgZGDTu^^YL31`-MaCr2xfASZhp@ykKp zOuo&UuC>JMA-b&|qIQ&&o5mG3s-&Yx3gv1!x}||@|&FKLI&OMvx!;hkt6jOQM zop=|_%Q+tkB6&TztEF`0lQeM7nK&bHVoyAkJE(LI`t156j&JbHWwu_=$JxESpZ_bALO#MWYVWJ_M&5E9XUnlzR{(*39`>*;X ziP_U9TFzQ2cHk5HPCi{2k)ETDe>D1}IHmbCu_L`pjM)icyC*(xUU%9_XM~f@p0JV0 z5`W<(@lok)F}UH0V~))@8S!rFeUWi8$6WFU8GbZ8({Xk{QrNlj4iWF>9@0000G diff --git a/icons/ibus-chewing-template.svg b/icons/ibus-chewing-template.svg deleted file mode 100644 index fb0cf01..0000000 --- a/icons/ibus-chewing-template.svg +++ /dev/null @@ -1,193 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 631504f..f334a98 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,3 @@ -set(IBUS_CHEWING_ENGINE_SOURCE_INCLUDED_C_FILES - IBusChewingEngine-signal.c - IBusChewingEngine-input-events.c -) - add_library(common STATIC IBusChewingApplier.c IBusChewingProperties.c @@ -63,8 +58,6 @@ add_executable(ibus-engine-chewing IBusChewingLookupTable.h IBusChewingPreEdit.c IBusChewingPreEdit.h - IBusChewingSystray.c - IBusChewingSystray.h IBusChewingUtil.c IBusChewingUtil.h main.c diff --git a/src/IBusChewingSystray.c b/src/IBusChewingSystray.c deleted file mode 100644 index 2fe0a76..0000000 --- a/src/IBusChewingSystray.c +++ /dev/null @@ -1,212 +0,0 @@ -#include "IBusChewingSystray.h" -#include "ibus-chewing-engine.h" - -/*=== Internal functions start ===*/ - -void ibus_chewing_systray_left_click_callback_interface(GtkStatusIcon * - icon, gpointer userData) -{ - IBusChewingSystrayIcon *systrayIcon = (IBusChewingSystrayIcon *) userData; - - systrayIcon->leftClickFunc(systrayIcon, systrayIcon->leftClickData); -} - -void ibus_chewing_systray_right_click_callback_interface(GtkStatusIcon * - icon, - GdkEvent * event, - gpointer userData) -{ - IBusChewingSystrayIcon *systrayIcon = (IBusChewingSystrayIcon *) userData; - - if (event->type == GDK_BUTTON_RELEASE) { - if (((GdkEventButton *) event)->button == 3) { - /* Right Click release */ - systrayIcon->rightClickFunc(systrayIcon, - systrayIcon->rightClickData); - } - } -} - -/*=== Member functions start ===*/ -IBusChewingSystrayIcon - * ibus_chewing_systray_icon_new(guint defaultValue, - IBusChewingSystrayClickFunc - leftClickFunc, - gpointer leftClickData, - IBusChewingSystrayClickFunc - rightClickFunc, - gpointer rightClickData, ...) -{ - IBUS_CHEWING_LOG(DEBUG, "* ibus_chewing_systray_icon_new()"); - va_list argList; - const gchar *iconFile; - - IBusChewingSystrayIcon *self = g_new0(IBusChewingSystrayIcon, 1); - - self->icon = gtk_status_icon_new(); - self->iconFileArray = g_ptr_array_new(); - self->iconCacheArray = g_ptr_array_new(); - - va_start(argList, rightClickData); - for (gint i = 0; i < IBUS_CHEWING_SYSTRAY_ICON_COUNT_MAX; i++) { - iconFile = va_arg(argList, const gchar *); - - if (iconFile == NULL) { - break; - } - gtk_status_icon_set_from_file(self->icon, iconFile); - GdkPixbuf *pbuf = gtk_status_icon_get_pixbuf(self->icon); - GVariant *cacheGVar = g_icon_serialize(G_ICON(pbuf)); - - g_ptr_array_add(self->iconFileArray, (gpointer) iconFile); - g_ptr_array_add(self->iconCacheArray, (gpointer) cacheGVar); - } - va_end(argList); - - self->leftClickFunc = leftClickFunc; - self->leftClickData = leftClickData; - if (leftClickFunc != NULL) { - g_signal_connect(G_OBJECT(self->icon), "activate", - G_CALLBACK - (ibus_chewing_systray_left_click_callback_interface), - self); - } - self->rightClickFunc = rightClickFunc; - self->rightClickData = rightClickData; - if (rightClickFunc != NULL) { - g_signal_connect(G_OBJECT(self->icon), "button-release-event", - G_CALLBACK - (ibus_chewing_systray_right_click_callback_interface), - self); - } - ibus_chewing_systray_icon_set_value(self, defaultValue); - gtk_status_icon_set_visible(self->icon, TRUE); - return self; -} - -void ibus_chewing_systray_icon_free(IBusChewingSystrayIcon * self) -{ - gtk_status_icon_set_visible(self->icon, FALSE); - g_object_unref(self->icon); - g_ptr_array_free(self->iconCacheArray, TRUE); - g_ptr_array_free(self->iconFileArray, TRUE); - g_free(self); -} - -void ibus_chewing_systray_icon_set_value(IBusChewingSystrayIcon * - self, guint value) -{ - self->value = value; -} - -void ibus_chewing_systray_icon_set_visible(IBusChewingSystrayIcon * - self, gboolean visible) -{ - gtk_status_icon_set_visible(self->icon, visible); -} - - -void ibus_chewing_systray_icon_update(IBusChewingSystrayIcon * self) -{ - GVariant *cacheGVar = - (GVariant *) g_ptr_array_index(self->iconCacheArray, self->value); - GIcon *cachedIcon = g_icon_deserialize(g_variant_ref_sink(cacheGVar)); - - g_variant_unref(cacheGVar); - gtk_status_icon_set_from_gicon(self->icon, cachedIcon); - ibus_chewing_systray_icon_set_visible(self, TRUE); -} - -/*=== Chi_Eng systray Icon ===*/ -/** - * ibus_chewing_systray_chi_eng_toggle_callback: - */ -void ibus_chewing_systray_chi_eng_toggle_callback(IBusChewingSystrayIcon * - self, gpointer userData) -{ - IBusChewingEngine *iEngine = (IBusChewingEngine *) userData; - - ibus_chewing_pre_edit_toggle_chi_eng_mode(iEngine->icPreEdit); - ibus_chewing_systray_chi_eng_icon_refresh_value(iEngine); - ibus_chewing_engine_refresh_property_list(iEngine); -} - -/** - * ibus_chewing_systray_full_half_toggle_callback: - */ -void ibus_chewing_systray_full_half_toggle_callback(IBusChewingSystrayIcon - * self, gpointer userData) -{ - IBusChewingEngine *iEngine = (IBusChewingEngine *) userData; - - ibus_chewing_pre_edit_toggle_full_half_mode(iEngine->icPreEdit); - ibus_chewing_systray_chi_eng_icon_refresh_value(iEngine); - ibus_chewing_engine_refresh_property_list(iEngine); -} - -IBusChewingSystrayIcon - * ibus_chewing_systray_chi_eng_icon_new(IBusChewingEngine * iEngine) -{ - IBusChewingSystrayIcon *iChiEngSystrayIcon = - ibus_chewing_systray_icon_new(1, - ibus_chewing_systray_chi_eng_toggle_callback, - (gpointer) - iEngine, - ibus_chewing_systray_full_half_toggle_callback, - iEngine, - QUOTE_ME(PRJ_ICON_DIR) - "/ibus-chewing-eng-half.svg", - QUOTE_ME(PRJ_ICON_DIR) - "/ibus-chewing-chi-half.svg", - QUOTE_ME(PRJ_ICON_DIR) - "/ibus-chewing-eng-full.svg", - QUOTE_ME(PRJ_ICON_DIR) - "/ibus-chewing-chi-full.svg", - NULL); - - gtk_status_icon_set_tooltip_text(iChiEngSystrayIcon->icon, - _ - ("Left click to toggle Chi/Eng; Right click to toggle full/half shape")); - return iChiEngSystrayIcon; -} - -gboolean -ibus_chewing_systray_chi_eng_icon_create_or_hide(IBusChewingEngine * iEngine) -{ - if (ibus_chewing_pre_edit_get_property_boolean - (iEngine->icPreEdit, "show-systray")) { - if (iEngine->iChiEngSystrayIcon == NULL) { - iEngine->iChiEngSystrayIcon = - ibus_chewing_systray_chi_eng_icon_new(iEngine); - } - ibus_chewing_systray_icon_set_visible(iEngine->iChiEngSystrayIcon, - TRUE); - return TRUE; - } - if (iEngine->iChiEngSystrayIcon != NULL) { - ibus_chewing_systray_icon_set_visible(iEngine->iChiEngSystrayIcon, - FALSE); - } - return FALSE; -} - -void ibus_chewing_systray_chi_eng_icon_refresh_value(IBusChewingEngine * - iEngine) -{ - if (ibus_chewing_pre_edit_get_chi_eng_mode(iEngine->icPreEdit)) { - mkdg_set_flag(iEngine->iChiEngSystrayIcon->value, - IBUS_CHEWING_SYSTRAY_CHINESE_FLAG); - } else { - mkdg_clear_flag(iEngine->iChiEngSystrayIcon->value, - IBUS_CHEWING_SYSTRAY_CHINESE_FLAG); - } - - if (ibus_chewing_pre_edit_get_full_half_mode(iEngine->icPreEdit)) { - mkdg_set_flag(iEngine->iChiEngSystrayIcon->value, - IBUS_CHEWING_SYSTRAY_FULL_HALF_SHAPE_FLAG); - } else { - mkdg_clear_flag(iEngine->iChiEngSystrayIcon->value, - IBUS_CHEWING_SYSTRAY_FULL_HALF_SHAPE_FLAG); - } - ibus_chewing_systray_icon_update(iEngine->iChiEngSystrayIcon); -} diff --git a/src/IBusChewingSystray.h b/src/IBusChewingSystray.h deleted file mode 100644 index 30f69e5..0000000 --- a/src/IBusChewingSystray.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright © 2016 Red Hat, Inc. All rights reserved. - * Copyright © 2016 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -/** - * SECTION:IBusChewingSystray - * @short_description: Systray support - * @title: IBusChewingSystray - * @stability: Stable - * @include: IbusChewingSystray - * - * Systray support that shows: - * Chinese/English state - * - */ - -#ifndef _IBUS_CHEWING_SYSTRAY_H_ -# define _IBUS_CHEWING_SYSTRAY_H_ -# include -# include -# include -# include -# include -# include "MakerDialogUtil.h" -# include "IBusChewingPreEdit.h" -# define IBUS_CHEWING_SYSTRAY_ICON_COUNT_MAX 5 -typedef struct _IBusChewingSystrayIcon IBusChewingSystrayIcon; - -typedef void (*IBusChewingSystrayClickFunc) (IBusChewingSystrayIcon * - iSystrayIcon, gpointer userData); - -typedef enum { - IBUS_CHEWING_SYSTRAY_CHINESE_FLAG = 1, - IBUS_CHEWING_SYSTRAY_FULL_HALF_SHAPE_FLAG = 2, -} IBusChewingSystrayFlag; - -/** - * IBusChewingSystrayIcon: - * Systray Icon for ibus-chewin - * - * @icon: The actual systray object - * @value: An unsigned integer that hold the state of the systray icon. - * also the index (starting from 0) for icon file. Thus it should not exceed length - * of iconFileArray - * @iconFileArray: Array of icon files. - * @leftClickFunc: Callback function handles left click. NULL means do nothing - * @leftClickData: Data that passed to leftClickFunc - * @rightClickFunc: Callback function handles right click. NULL means do nothing - * @rightClickData: Data that passed to rightClickFunc - */ -struct _IBusChewingSystrayIcon { - GtkStatusIcon *icon; - guint value; - GPtrArray *iconFileArray; - GPtrArray *iconCacheArray; - IBusChewingSystrayClickFunc leftClickFunc; - gpointer leftClickData; - IBusChewingSystrayClickFunc rightClickFunc; - gpointer rightClickData; -}; - -void ibus_chewing_systray_icon_free(IBusChewingSystrayIcon * self); - -/** - * ibus_chewing_systray_icon_get_icon_file: - * @self: An IBusChewingSystrayIcon - * @index: File index that starts from 0 - */ -# define ibus_chewing_systray_icon_get_icon_file(self, index) (const gchar *) g_ptr_array_index(self->iconFileArray,index) - -/** - * ibus_chewing_systray_icon_set_value: - * @self: An IBusChewingSystrayIcon - * @value: The value to set. - * - * Sets value to IBusChewingSystrayIcon. - * This does not update display icon, see ibus_chewing_systray_icon_update for that. - */ -void ibus_chewing_systray_icon_set_value(IBusChewingSystrayIcon * - self, guint value); - -/** - * ibus_chewing_systray_icon_set_visible: - * @self: An IBusChewingSystrayIcon - * @visible: TRUE for visible, FALSE for not visible. - * - * Sets whether this SystrayIcon visible. - */ -void ibus_chewing_systray_icon_set_visible(IBusChewingSystrayIcon * - self, gboolean visible); - -/** - * ibus_chewing_systray_icon_update: - * @self: An IBusChewingSystrayIcon - * - * Updates display icon according to value. - */ -void ibus_chewing_systray_icon_update(IBusChewingSystrayIcon * self); - - -typedef struct _IBusChewingEngine IBusChewingEngine; - -IBusChewingSystrayIcon - * ibus_chewing_systray_chi_eng_icon_new(IBusChewingEngine * iEngine); - -/** - * ibus_chewing_systray_chi_eng_icon_create_or_hide: - * @iEngine: An IBusChewingEngine - * - * Create or destroy systray icon depending on property 'show-systray' - * @returns: TRUE if systray icon created; FALSE otherwise. - */ -gboolean -ibus_chewing_systray_chi_eng_icon_create_or_hide(IBusChewingEngine * iEngine); - -void ibus_chewing_systray_chi_eng_icon_refresh_value(IBusChewingEngine * - iEngine); -#endif diff --git a/src/IBusChewingUtil.c b/src/IBusChewingUtil.c index 852293f..1533002 100644 --- a/src/IBusChewingUtil.c +++ b/src/IBusChewingUtil.c @@ -3,7 +3,7 @@ * IBusChewingEngine */ -#include +#include "IBusChewingUtil.h" /*===================================== * Tone diff --git a/src/ibus-chewing-engine-private.h b/src/ibus-chewing-engine-private.h index 9a2e1f5..9401ac0 100644 --- a/src/ibus-chewing-engine-private.h +++ b/src/ibus-chewing-engine-private.h @@ -32,7 +32,6 @@ #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" #include "IBusChewingPreEdit.h" -#include "IBusChewingSystray.h" #ifdef USE_GSETTINGS #include "GSettingsBackend.h" #endif diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c index dc6799a..906e907 100644 --- a/src/ibus-chewing-engine.c +++ b/src/ibus-chewing-engine.c @@ -25,6 +25,7 @@ #include #include #define GETTEXT_PACKAGE "gtk30" +#include #include #include #include @@ -32,7 +33,6 @@ #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" #include "IBusChewingPreEdit.h" -#include "IBusChewingSystray.h" #ifdef USE_GSETTINGS #include "GSettingsBackend.h" #endif @@ -208,7 +208,6 @@ ___finalize(GObject *obj_self) if(self->preEditText) { g_object_unref ((gpointer) self->preEditText); self->preEditText = NULL; } if(self->auxText) { g_object_unref ((gpointer) self->auxText); self->auxText = NULL; } if(self->outgoingText) { g_object_unref ((gpointer) self->outgoingText); self->outgoingText = NULL; } - if(self->iChiEngSystrayIcon) { ibus_chewing_systray_icon_free ((gpointer) self->iChiEngSystrayIcon); self->iChiEngSystrayIcon = NULL; } if(self->InputMode) { g_object_unref ((gpointer) self->InputMode); self->InputMode = NULL; } if(self->AlnumSize) { g_object_unref ((gpointer) self->AlnumSize); self->AlnumSize = NULL; } if(self->setup_prop) { g_object_unref ((gpointer) self->setup_prop); self->setup_prop = NULL; } @@ -229,7 +228,6 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) self->preEditText = NULL; self->auxText = NULL; self->outgoingText = NULL; - self->iChiEngSystrayIcon = NULL; self->logFile = NULL; self->_priv->statusFlags = 0; self->_priv->capabilite = 0; @@ -519,10 +517,6 @@ ibus_chewing_engine_refresh_property (IBusChewingEngine * self, const gchar * pr IBUS_CHEWING_LOG(DEBUG, "refresh_property(%s) status=%x", prop_name, self->_priv->statusFlags); - if (ibus_chewing_systray_chi_eng_icon_create_or_hide(self)) { - ibus_chewing_systray_chi_eng_icon_refresh_value(self); - } - if (STRING_EQUALS(prop_name, "InputMode")) { ibus_property_set_label(self->InputMode, diff --git a/src/ibus-chewing-engine.h b/src/ibus-chewing-engine.h index b56e8c1..a4d9975 100644 --- a/src/ibus-chewing-engine.h +++ b/src/ibus-chewing-engine.h @@ -25,6 +25,7 @@ #include #include #define GETTEXT_PACKAGE "gtk30" +#include #include #include #include @@ -32,7 +33,6 @@ #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" #include "IBusChewingPreEdit.h" -#include "IBusChewingSystray.h" #ifdef USE_GSETTINGS #include "GSettingsBackend.h" #endif @@ -126,7 +126,6 @@ struct _IBusChewingEngine { IBusProperty * setup_prop; IBusPropList * prop_list; /*< private >*/ - IBusChewingSystrayIcon * iChiEngSystrayIcon; /* protected */ FILE * logFile; /* protected */ IBusKeymap * keymap_us; /* protected */ IBusChewingEnginePrivate *_priv; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 31a80f5..ea2d3e8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,8 +45,6 @@ add_executable(ibus-chewing-engine-test ibus-chewing-engine-test.c ../src/IBusChewingLookupTable.h ../src/IBusChewingPreEdit.c ../src/IBusChewingPreEdit.h - ../src/IBusChewingSystray.c - ../src/IBusChewingSystray.h ../src/IBusChewingUtil.c ../src/IBusChewingUtil.h ) From 1002c9a2538224b00293838c4253cd3d16f3df72 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 4 Feb 2024 01:41:48 +0900 Subject: [PATCH 02/24] feat(wip)!: use gtk4 --- .github/workflows/ci.yml | 4 ++-- CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- src/MakerDialogWidget.c | 44 +++++++++++++----------------------- src/ibus-setup-chewing.c | 31 ++++++++++++++++++-------- src/main.c | 2 +- src/maker-dialog.c | 48 ++++++++++++++++++++-------------------- 7 files changed, 66 insertions(+), 67 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6008450..1eee193 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v3 - name: Install build dependencies - run: sudo apt install -y libgtk-3-dev libibus-1.0-dev libx11-dev libchewing3-dev ibus gettext xvfb + run: sudo apt install -y libgtk-4-dev libibus-1.0-dev libx11-dev libchewing3-dev ibus gettext xvfb - name: Build run: | @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v3 - name: Install build dependencies - run: sudo apt install -y libgtk-3-dev libibus-1.0-dev libx11-dev libchewing3-dev ibus gettext xvfb + run: sudo apt install -y libgtk-4-dev libibus-1.0-dev libx11-dev libchewing3-dev ibus gettext xvfb - name: Install llvm run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 4caa625..bf78457 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ add_compile_definitions( ) pkg_check_modules(GLIB2 REQUIRED IMPORTED_TARGET glib-2.0) -pkg_check_modules(GTK3 REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GTK4 REQUIRED IMPORTED_TARGET gtk4) pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11) set(CMAKE_C_STANDARD 99) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f334a98..8afd623 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,7 +40,7 @@ endif() target_link_libraries(gui-core PUBLIC common PkgConfig::GLIB2 - PkgConfig::GTK3 + PkgConfig::GTK4 PkgConfig::X11 PkgConfig::IBUS PkgConfig::CHEWING diff --git a/src/MakerDialogWidget.c b/src/MakerDialogWidget.c index 2b00123..af9f637 100644 --- a/src/MakerDialogWidget.c +++ b/src/MakerDialogWidget.c @@ -179,7 +179,7 @@ static void on_entry_activate_wrap(GtkEntry * entry, gpointer userData) MkdgWidget *mWidget = (MkdgWidget *) userData; GValue gValue = { 0 }; g_value_init(&gValue, mWidget->ctx->spec->valueType); - g_value_set_string(&gValue, gtk_entry_get_text(entry)); + g_value_set_string(&gValue, gtk_editable_get_text(GTK_EDITABLE(entry))); mkdg_log(INFO, "on_entry_activate_wrap(), key=%s value=%s", mWidget->ctx->spec->key, g_value_get_string(&gValue)); on_value_change(mWidget, &gValue); @@ -234,10 +234,11 @@ static void on_toggleButton_toggled_wrap(GtkToggleButton * button, gint mkdg_wgt_get_width(MkdgWgt * wgt) { - GtkRequisition requisition; + GtkRequisition min_size; + GtkRequisition natural_size; - gtk_widget_size_request(wgt, &requisition); - return requisition.width; + gtk_widget_get_preferred_size(wgt, &min_size, &natural_size); + return natural_size.width; } void mkdg_wgt_set_width(MkdgWgt * wgt, gint width) @@ -247,7 +248,8 @@ void mkdg_wgt_set_width(MkdgWgt * wgt, gint width) void mkdg_wgt_set_alignment(MkdgWgt * wgt, gfloat xAlign, gfloat yAlign) { - gtk_misc_set_alignment(GTK_MISC(wgt), xAlign, yAlign); + gtk_widget_set_halign(wgt, xAlign); + gtk_widget_set_valign(wgt, yAlign); if (GTK_IS_LABEL(wgt)) { /* gtk_label_set_justify takes no effect on single line label, * but multi-lined label need this @@ -256,22 +258,6 @@ void mkdg_wgt_set_alignment(MkdgWgt * wgt, gfloat xAlign, gfloat yAlign) } } -void mkdg_wgt_show(MkdgWgt * wgt) -{ - gtk_widget_show(wgt); -} - -void mkdg_wgt_show_all(MkdgWgt * wgt) -{ - gtk_widget_show_all(wgt); -} - -void mkdg_wgt_destroy(MkdgWgt * wgt) -{ - gtk_widget_destroy(wgt); -} - - /*===================================== * MkdgWidgetContainer subroutines */ @@ -302,10 +288,10 @@ void mkdg_widget_container_add_widget(MkdgWidgetContainer * container, MkdgWgt *labelWgt = MKDG_WGT(mWidget->label); MkdgWgt *wgt = mWidget->wgt; - gtk_box_pack_start(GTK_BOX(hbox), labelWgt, FALSE, FALSE, 0); - mkdg_wgt_show(labelWgt); - gtk_box_pack_start(GTK_BOX(hbox), wgt, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + gtk_box_prepend(GTK_BOX(hbox), labelWgt); + // mkdg_wgt_show(labelWgt); + gtk_box_prepend(GTK_BOX(hbox), wgt); + gtk_box_prepend(GTK_BOX(vbox), hbox); g_ptr_array_add(container->children, mWidget); container->childrenLabelWidth = @@ -375,7 +361,7 @@ MkdgWidget *mkdg_widget_new(PropertyContext * ctx, MkdgWidgetFlag widgetFlags) switch (ctx->spec->valueType) { case G_TYPE_BOOLEAN: bValue = g_value_get_boolean(property_context_get(ctx)); - wgt = gtk_check_button_new(); + wgt = gtk_toggle_button_new(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wgt), bValue); g_signal_connect(wgt, "toggled", G_CALLBACK(on_toggleButton_toggled_wrap), mWidget); @@ -452,7 +438,7 @@ MkdgWidget *mkdg_widget_new(PropertyContext * ctx, MkdgWidgetFlag widgetFlags) if (ctx->spec->max >= 0) { gtk_entry_set_max_length(GTK_ENTRY(wgt), ctx->spec->max); } - gtk_entry_set_text(GTK_ENTRY(wgt), strValue); + gtk_editable_set_text(GTK_EDITABLE(wgt), strValue); gtk_editable_set_editable(GTK_EDITABLE(wgt), !(ctx->spec->propertyFlags & MKDG_PROPERTY_FLAG_NO_NEW)); @@ -525,7 +511,7 @@ GValue *mkdg_widget_get_widget_value(MkdgWidget * mWidget, GValue * value) g_value_unset(strValue); } else { g_value_set_string(value, - gtk_entry_get_text(GTK_ENTRY(mWidget->wgt))); + gtk_editable_get_text(GTK_EDITABLE(mWidget->wgt))); } break; default: @@ -571,7 +557,7 @@ gboolean mkdg_widget_set_widget_value(MkdgWidget * mWidget, GValue * value) gtk_combo_box_set_active(GTK_COMBO_BOX(mWidget->wgt), index); } else { g_value_set_string(value, - gtk_entry_get_text(GTK_ENTRY(mWidget->wgt))); + gtk_editable_get_text(GTK_EDITABLE(mWidget->wgt))); } break; default: diff --git a/src/ibus-setup-chewing.c b/src/ibus-setup-chewing.c index a65fb6f..1d25dbe 100644 --- a/src/ibus-setup-chewing.c +++ b/src/ibus-setup-chewing.c @@ -52,6 +52,15 @@ static const GOptionEntry entries[] = { {NULL}, }; + +void save_values(GtkDialog *sDialog, gint response_id, gpointer mDialog) +{ + if (response_id != GTK_RESPONSE_OK) { + return; + } + maker_dialog_save_all_widgets_values(mDialog, NULL); +} + gint start_dialog() { #ifdef USE_GSETTINGS @@ -76,14 +85,15 @@ gint start_dialog() MKDG_BUTTON_FLAG_OK | MKDG_BUTTON_FLAG_CANCEL); GtkWidget *sDialog = GTK_WIDGET(mDialog); - gtk_widget_show_all(sDialog); - gint result = gtk_dialog_run(GTK_DIALOG(sDialog)); + gtk_window_present(GTK_WINDOW(mDialog)); + g_signal_connect(sDialog, "response", G_CALLBACK(save_values), mDialog); + // gint result = gtk_dialog_run(GTK_DIALOG(sDialog)); - gtk_widget_hide(sDialog); - if (result != GTK_RESPONSE_OK) { - return 3; - } - maker_dialog_save_all_widgets_values(mDialog, NULL); + // gtk_widget_hide(sDialog); + // if (result != GTK_RESPONSE_OK) { + // return 3; + // } + // maker_dialog_save_all_widgets_values(mDialog, NULL); return 0; } @@ -92,7 +102,7 @@ gint main(gint argc, gchar * argv[]) GError *error = NULL; GOptionContext *context; - gtk_init(&argc, &argv); + gtk_init(); /* Init i18n messages */ setlocale(LC_ALL, ""); @@ -117,7 +127,10 @@ gint main(gint argc, gchar * argv[]) return 0; } mkdg_log_set_level(verbose); - return start_dialog(); + start_dialog(); + while (true) + g_main_context_iteration (NULL, TRUE); + return 0; } /* vim:set et sts=4: */ diff --git a/src/main.c b/src/main.c index 997044f..cc46588 100644 --- a/src/main.c +++ b/src/main.c @@ -166,7 +166,7 @@ int main(gint argc, gchar * argv[]) GError *error = NULL; GOptionContext *context; - gtk_init(&argc, &argv); + gtk_init(); /* Init i18n messages */ setlocale(LC_ALL, ""); diff --git a/src/maker-dialog.c b/src/maker-dialog.c index 4d0b636..df0a912 100644 --- a/src/maker-dialog.c +++ b/src/maker-dialog.c @@ -125,7 +125,7 @@ ___finalize(GObject *obj_self) #define __GOB_FUNCTION__ "Maker:Dialog::finalize" MakerDialog *self G_GNUC_UNUSED = MAKER_DIALOG (obj_self); gpointer priv G_GNUC_UNUSED = self->_priv; - if(self->notebookWgt) { mkdg_wgt_destroy ((gpointer) self->notebookWgt); self->notebookWgt = NULL; } + if(self->notebookWgt) { g_object_unref ((gpointer) self->notebookWgt); self->notebookWgt = NULL; } if(self->_priv->containerTable) { g_hash_table_destroy ((gpointer) self->_priv->containerTable); self->_priv->containerTable = NULL; } if(self->_priv->widgetTable) { g_hash_table_destroy ((gpointer) self->_priv->widgetTable); self->_priv->widgetTable = NULL; } if(self->_priv->notebookContentTable) { g_hash_table_destroy ((gpointer) self->_priv->notebookContentTable); self->_priv->notebookContentTable = NULL; } @@ -213,7 +213,7 @@ maker_dialog_new_full (MkdgProperties * properties, const gchar * title, MkdgWid GtkDialog * dialog = GTK_DIALOG(self); gtk_window_set_title(GTK_WINDOW(dialog), title); gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); - gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); + // gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); self->wFlags = wFlags; self->_priv->properties = properties; @@ -231,11 +231,11 @@ maker_dialog_new_full (MkdgProperties * properties, const gchar * title, MkdgWid /* Create Notebook */ self->notebookWgt = gtk_notebook_new(); - gtk_container_set_border_width(GTK_CONTAINER(self->notebookWgt), 5); - mkdg_wgt_show(self->notebookWgt); + // gtk_container_set_border_width(GTK_CONTAINER(self->notebookWgt), 5); + // mkdg_wgt_show(self->notebookWgt); GtkWidget *dialogVboxWgt = gtk_dialog_get_content_area(GTK_DIALOG(self)); - mkdg_wgt_show(dialogVboxWgt); - gtk_box_pack_start(GTK_BOX(dialogVboxWgt), self->notebookWgt, TRUE, TRUE, 0); + // mkdg_wgt_show(dialogVboxWgt); + gtk_box_prepend(GTK_BOX(dialogVboxWgt), self->notebookWgt); self_prepare(self); return self; @@ -280,15 +280,15 @@ maker_dialog_add_property (MakerDialog * self, PropertyContext * ctx) /* Do we need a new container/page? */ if (container == NULL) { MkdgWgt * vboxWgt = gtk_box_new(GTK_ORIENTATION_VERTICAL, MKDG_VBOX_SPACING_DEFAULT); - gtk_container_set_border_width(GTK_CONTAINER (vboxWgt), 10); - mkdg_wgt_show(vboxWgt); + // gtk_container_set_border_width(GTK_CONTAINER (vboxWgt), 10); + // mkdg_wgt_show(vboxWgt); container = mkdg_widget_container_new(vboxWgt); g_hash_table_insert(self->_priv->containerTable, (gpointer) pageName, (gpointer) container); /* new notebook page */ MkdgWgt * pageLabelWgt = gtk_label_new(_(pageName)); - mkdg_wgt_show(pageLabelWgt); + // mkdg_wgt_show(pageLabelWgt); gtk_notebook_append_page(GTK_NOTEBOOK(self->notebookWgt), vboxWgt, pageLabelWgt); } @@ -496,22 +496,22 @@ maker_dialog_set_widget_value (MakerDialog * self, const gchar * key, GValue * v }} #undef __GOB_FUNCTION__ -/** - * maker_dialog_show: - * @self: A MakerDialog. - * - **/ -void -maker_dialog_show (MakerDialog * self) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::show" - g_return_if_fail (self != NULL); - g_return_if_fail (MAKER_IS_DIALOG (self)); -{ +// /** +// * maker_dialog_show: +// * @self: A MakerDialog. +// * +// **/ +// void +// maker_dialog_show (MakerDialog * self) +// { +// #define __GOB_FUNCTION__ "Maker:Dialog::show" +// g_return_if_fail (self != NULL); +// g_return_if_fail (MAKER_IS_DIALOG (self)); +// { - mkdg_wgt_show_all(GTK_WIDGET(self)); - }} -#undef __GOB_FUNCTION__ +// mkdg_wgt_show_all(GTK_WIDGET(self)); +// }} +// #undef __GOB_FUNCTION__ MkdgWidget * maker_dialog_get_widget_by_key (MakerDialog * self, const gchar * key) From 19680e86d01b63fd2f9e760847f60dd9ca9ee9c0 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 4 Feb 2024 01:59:45 +0900 Subject: [PATCH 03/24] feat(setup): use libadwaita --- .github/workflows/ci.yml | 4 ++-- CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + src/ibus-setup-chewing.c | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1eee193..5d125e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v3 - name: Install build dependencies - run: sudo apt install -y libgtk-4-dev libibus-1.0-dev libx11-dev libchewing3-dev ibus gettext xvfb + run: sudo apt install -y libgtk-4-dev libibus-1.0-dev libadwaita-1-dev libx11-dev libchewing3-dev ibus gettext xvfb - name: Build run: | @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v3 - name: Install build dependencies - run: sudo apt install -y libgtk-4-dev libibus-1.0-dev libx11-dev libchewing3-dev ibus gettext xvfb + run: sudo apt install -y libgtk-4-dev libibus-1.0-dev libadwaita-1-dev libx11-dev libchewing3-dev ibus gettext xvfb - name: Install llvm run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index bf78457..e2f82ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ add_compile_definitions( pkg_check_modules(GLIB2 REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GTK4 REQUIRED IMPORTED_TARGET gtk4) +pkg_check_modules(LIBADWAITA REQUIRED IMPORTED_TARGET libadwaita-1) pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11) set(CMAKE_C_STANDARD 99) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8afd623..e8c8956 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,6 +41,7 @@ target_link_libraries(gui-core PUBLIC common PkgConfig::GLIB2 PkgConfig::GTK4 + PkgConfig::LIBADWAITA PkgConfig::X11 PkgConfig::IBUS PkgConfig::CHEWING diff --git a/src/ibus-setup-chewing.c b/src/ibus-setup-chewing.c index 1d25dbe..6cc0428 100644 --- a/src/ibus-setup-chewing.c +++ b/src/ibus-setup-chewing.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "MakerDialogUtil.h" #include "MakerDialogBackend.h" @@ -102,7 +103,7 @@ gint main(gint argc, gchar * argv[]) GError *error = NULL; GOptionContext *context; - gtk_init(); + adw_init(); /* Init i18n messages */ setlocale(LC_ALL, ""); From 362c7dfbf6b56da8cc530f6abfbaebd58226b796 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 4 Feb 2024 23:10:30 +0900 Subject: [PATCH 04/24] feat(setup)!: rewrite ibus-setup-chewing using libadwaita --- .clang-format | 2 + CMakeLists.txt | 12 +- src/CMakeLists.txt | 76 +-- src/GConf2Backend.c | 193 ------ src/GConf2Backend.h | 46 -- src/IBusChewingProperties.c | 12 +- src/MakerDialogWidget.c | 568 ------------------ src/MakerDialogWidget.h | 157 ----- src/generate-gconf-schemas.c | 213 ------- src/generate-gsettings-schemas.c | 94 --- src/ibus-chewing-engine-private.h | 6 - src/ibus-chewing-engine.c | 14 - src/ibus-chewing-engine.h | 5 - src/ibus-setup-chewing.c | 137 ----- src/main.c | 2 - src/maker-dialog-private.h | 45 -- src/maker-dialog.c | 526 ---------------- src/maker-dialog.h | 133 ---- src/setup/ibus-setup-chewing-application.c | 81 +++ src/setup/ibus-setup-chewing-application.h | 38 ++ src/setup/ibus-setup-chewing-window.c | 192 ++++++ src/setup/ibus-setup-chewing-window.h | 32 + src/setup/ibus-setup-chewing-window.ui | 231 +++++++ src/setup/ibus-setup-chewing.gresource.xml | 6 + src/setup/main.c | 38 ++ .../org.freedesktop.IBus.Chewing.gschema.xml | 137 +++++ test/IBusChewingPreEdit-test.c | 16 +- test/MakerDialogBackend-test.c | 49 +- 28 files changed, 800 insertions(+), 2261 deletions(-) create mode 100644 .clang-format delete mode 100644 src/GConf2Backend.c delete mode 100644 src/GConf2Backend.h delete mode 100644 src/MakerDialogWidget.c delete mode 100644 src/MakerDialogWidget.h delete mode 100644 src/generate-gconf-schemas.c delete mode 100644 src/generate-gsettings-schemas.c delete mode 100644 src/ibus-setup-chewing.c delete mode 100644 src/maker-dialog-private.h delete mode 100644 src/maker-dialog.c delete mode 100644 src/maker-dialog.h create mode 100644 src/setup/ibus-setup-chewing-application.c create mode 100644 src/setup/ibus-setup-chewing-application.h create mode 100644 src/setup/ibus-setup-chewing-window.c create mode 100644 src/setup/ibus-setup-chewing-window.h create mode 100644 src/setup/ibus-setup-chewing-window.ui create mode 100644 src/setup/ibus-setup-chewing.gresource.xml create mode 100644 src/setup/main.c create mode 100644 src/setup/org.freedesktop.IBus.Chewing.gschema.xml diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..80d3293 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: LLVM +IndentWidth: 4 diff --git a/CMakeLists.txt b/CMakeLists.txt index e2f82ce..d62a828 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,8 +34,6 @@ enable_testing() include(GNUInstallDirs) option(GNOME_SHELL "Enable GNOME Shell support" ON) -option(GCONF2_SUPPORT "Enable GConf2 support" OFF) -option(GSETTINGS_SUPPORT "Enable GSettings support" ON) find_package(PkgConfig REQUIRED) pkg_check_modules(IBUS REQUIRED IMPORTED_TARGET ibus-1.0>=1.3) @@ -53,14 +51,10 @@ pkg_check_modules(GTK4 REQUIRED IMPORTED_TARGET gtk4) pkg_check_modules(LIBADWAITA REQUIRED IMPORTED_TARGET libadwaita-1) pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11) +find_program(GLIB_COMPILE_RESOURCES NAMES glib-compile-resources REQUIRED) + set(CMAKE_C_STANDARD 99) add_compile_definitions(_XOPEN_SOURCE) -if(GSETTINGS_SUPPORT) - add_compile_definitions(USE_GSETTINGS) -endif() -if(GCONF2_SUPPORT) - add_compile_definitions(USE_GCONF2) -endif() # Directory that store ibus-chewing icons add_compile_definitions(PRJ_ICON_DIR="${CMAKE_INSTALL_DATADIR}/ibus-chewing/icons") @@ -73,8 +67,6 @@ add_compile_definitions( PROJECT_SCHEMA_BASE=/desktop/ibus/engine PROJECT_SCHEMA_SECTION=chewing PROJECT_SCHEMA_DIR=/desktop/ibus/engine/chewing - PROJECT_GCONF2_SCHEMA_SECTION=Chewing - PROJECT_GCONF2_SCHEMA_DIR=/desktop/ibus/engine/Chewing PROJECT_SCHEMA_PATH=/desktop/ibus/engine/chewing/ ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e8c8956..74588e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,20 +23,9 @@ target_link_libraries(common PUBLIC ) add_library(gui-core STATIC - maker-dialog.c - maker-dialog.h - maker-dialog-private.h - IBusConfigBackend.c - IBusConfigBackend.h - MakerDialogWidget.c - MakerDialogWidget.h + GSettingsBackend.c + GSettingsBackend.h ) -if(GSETTINGS_SUPPORT) - target_sources(gui-core PRIVATE - GSettingsBackend.c - GSettingsBackend.h - ) -endif() target_link_libraries(gui-core PUBLIC common PkgConfig::GLIB2 @@ -47,8 +36,37 @@ target_link_libraries(gui-core PUBLIC PkgConfig::CHEWING ) -add_executable(ibus-setup-chewing ibus-setup-chewing.c) -target_link_libraries(ibus-setup-chewing gui-core) +add_custom_command( + OUTPUT ibus-setup-chewing-window-ui.c + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/setup + COMMAND ${GLIB_COMPILE_RESOURCES} + ARGS + --generate + --target=${CMAKE_CURRENT_BINARY_DIR}/ibus-setup-chewing-window-ui.c + ibus-setup-chewing.gresource.xml + VERBATIM + MAIN_DEPENDENCY setup/ibus-setup-chewing.gresource.xml + DEPENDS + setup/ibus-setup-chewing-window.ui +) +set_source_files_properties( + ${CMAKE_CURRENT_BINARY_DIR}/ibus-setup-chewing-window-ui.c + PROPERTIES GENERATED TRUE +) +add_executable(ibus-setup-chewing + setup/ibus-setup-chewing-application.c + setup/ibus-setup-chewing-application.h + setup/ibus-setup-chewing-window.c + setup/ibus-setup-chewing-window.h + setup/main.c + ${CMAKE_CURRENT_BINARY_DIR}/ibus-setup-chewing-window-ui.c +) +target_compile_definitions(ibus-setup-chewing PRIVATE + GETTEXT_PACKAGE="ibus-setup-chewing" + LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}" +) +target_include_directories(ibus-setup-chewing PRIVATE setup) +target_link_libraries(ibus-setup-chewing PkgConfig::LIBADWAITA) add_executable(ibus-engine-chewing ibus-chewing-engine.c @@ -70,30 +88,12 @@ target_include_directories(ibus-engine-chewing target_link_libraries(ibus-engine-chewing gui-core) -if(GSETTINGS_SUPPORT) - set(PROJECT_GSCHEMA_XML ${PROJECT_SCHEMA_ID}.gschema.xml) - set(GSETTINGS_SCHEMAS_DIR ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas) - - add_executable(generate-gsettings-schemas - GSettingsBackend.c - GSettingsBackend.h - generate-gsettings-schemas.c - ) - target_link_libraries(generate-gsettings-schemas common) - - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_GSCHEMA_XML} - DESTINATION ${GSETTINGS_SCHEMAS_DIR} - ) +set(PROJECT_GSCHEMA_XML ${PROJECT_SCHEMA_ID}.gschema.xml) +set(GSETTINGS_SCHEMAS_DIR ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas) - add_custom_target(schemas_gsettings ALL - COMMAND G_MESSAGES_DEBUG=all "${CMAKE_CURRENT_BINARY_DIR}/generate-gsettings-schemas" -v 5 "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_GSCHEMA_XML}" - COMMAND G_MESSAGES_DEBUG=all glib-compile-schemas "${CMAKE_CURRENT_BINARY_DIR}" - COMMENT "Generating gsettings schemas ${PROJECT_GSCHEMA_XML}" - VERBATIM - ) - - add_dependencies(schemas_gsettings generate-gsettings-schemas) -endif() +install(FILES setup/${PROJECT_GSCHEMA_XML} + DESTINATION ${GSETTINGS_SCHEMAS_DIR} +) install(TARGETS ibus-engine-chewing ibus-setup-chewing DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) \ No newline at end of file diff --git a/src/GConf2Backend.c b/src/GConf2Backend.c deleted file mode 100644 index a753b0e..0000000 --- a/src/GConf2Backend.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright © 2014 Red Hat, Inc. All rights reserved. - * Copyright © 2014 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -#include -#include -#include -#include -#include "MakerDialogUtil.h" -#include "GConf2Backend.h" - -static GHashTable *camalCasedKeyTable = NULL; - -gchar *gconf2_backend_get_key(MkdgBackend * backend, - const gchar * section, const gchar * key, - gpointer userData); - -static GValue *gconf_value_to_g_value(GConfValue * confValue, GValue * value) -{ - GType gType = G_VALUE_TYPE(value); - - switch (confValue->type) { - case GCONF_VALUE_BOOL: - if (gType != G_TYPE_BOOLEAN) { - return NULL; - } - g_value_set_boolean(value, gconf_value_get_bool(confValue)); - break; - case GCONF_VALUE_INT: - if (gType != G_TYPE_INT && gType != G_TYPE_UINT) { - return NULL; - } else if (gType == G_TYPE_INT) { - g_value_set_int(value, gconf_value_get_int(confValue)); - } else { - g_value_set_uint(value, gconf_value_get_int(confValue)); - } - break; - case GCONF_VALUE_STRING: - if (gType != G_TYPE_STRING) { - return NULL; - } - g_value_set_string(value, gconf_value_get_string(confValue)); - break; - default: - return NULL; - } - return value; -} - -static GConfValue *gconf_value_new_g_value(GValue * value) -{ - GConfValue *confValue; - GType gType = G_VALUE_TYPE(value); - - switch (gType) { - case G_TYPE_BOOLEAN: - confValue = gconf_value_new(GCONF_VALUE_BOOL); - gconf_value_set_bool(confValue, g_value_get_boolean(value)); - break; - case G_TYPE_INT: - confValue = gconf_value_new(GCONF_VALUE_INT); - gconf_value_set_int(confValue, g_value_get_int(value)); - break; - case G_TYPE_UINT: - confValue = gconf_value_new(GCONF_VALUE_INT); - gconf_value_set_int(confValue, g_value_get_uint(value)); - break; - case G_TYPE_STRING: - confValue = gconf_value_new(GCONF_VALUE_STRING); - gconf_value_set_string(confValue, g_value_get_string(value)); - break; - default: - return NULL; - } - return confValue; -} - -#define KEY_BUFFER_SIZE 100 -static gchar *to_real_key(gchar * confKey, MkdgBackend * backend, - const gchar * section, const gchar * key) -{ - gchar *camalCasedKey = gconf2_backend_get_key(backend, section, key, NULL); - - if (!STRING_IS_EMPTY(backend->basePath)) { - g_strlcpy(confKey, backend->basePath, KEY_BUFFER_SIZE); - g_strlcat(confKey, "/", KEY_BUFFER_SIZE); - } else { - g_strlcpy(confKey, "/", KEY_BUFFER_SIZE); - } - - if (!STRING_IS_EMPTY(section)) { - g_strlcat(confKey, section, KEY_BUFFER_SIZE); - g_strlcat(confKey, "/", KEY_BUFFER_SIZE); - } - g_strlcat(confKey, camalCasedKey, KEY_BUFFER_SIZE); - return confKey; -} - -/*============================================ - * Interface routines - */ -gchar *gconf2_backend_get_key(MkdgBackend * backend, - const gchar * section, const gchar * key, - gpointer userData) -{ - gchar *camalCasedKey = - (gchar *) g_hash_table_lookup(camalCasedKeyTable, key); - if (camalCasedKey == NULL) { - camalCasedKey = mkdg_str_dash_to_camel(key); - g_hash_table_insert(camalCasedKeyTable, (gpointer) key, camalCasedKey); - } - return camalCasedKey; -} - -GValue *gconf2_backend_read_value(MkdgBackend * backend, - GValue * value, - const gchar * section, - const gchar * key, gpointer userData) -{ - mkdg_log(DEBUG, "gconf2_backend_read_value(-,-,%s,%s,-):", section, key); - GConfClient *config = (GConfClient *) backend->config; - GError *err = NULL; - gchar confKey[KEY_BUFFER_SIZE]; - - to_real_key(confKey, backend, section, key); - GConfValue *confValue = gconf_client_get(config, confKey, &err); - - if (confValue == NULL) { - mkdg_log(ERROR, - "gconf2_backend_read_value(-,-,%s,%s,-): Failed to retrieve confValue", - section, key); - return NULL; - } - if (err != NULL) { - mkdg_log(ERROR, "gconf2_backend_read_value(-,-,%s,%s,-): %s", - section, key, err->message); - return NULL; - } - return gconf_value_to_g_value(confValue, value); -} - -gboolean gconf2_backend_write_value(MkdgBackend * backend, - GValue * value, - const gchar * section, - const gchar * key, gpointer userData) -{ - GConfClient *config = (GConfClient *) backend->config; - GError *err = NULL; - gchar confKey[KEY_BUFFER_SIZE]; - - to_real_key(confKey, backend, section, key); - GConfValue *confValue = gconf_value_new_g_value(value); - - gconf_client_set(config, confKey, confValue, &err); - gconf_value_free(confValue); - if (err != NULL) { - mkdg_log(ERROR, "gconf2_backend_write_value(-,-,%s,%s,-): %s", - section, key, err->message); - return FALSE; - } - return TRUE; -} - -MkdgBackend *gconf2_backend_new(const gchar * basePath, gpointer auxData) -{ - GConfClient *client = gconf_client_get_default(); - MkdgBackend *result = mkdg_backend_new(GCONF2_BACKEND_ID, - (gpointer) client, basePath, - auxData); - - camalCasedKeyTable = g_hash_table_new(g_str_hash, g_str_equal); - result->getKeyFunc = gconf2_backend_get_key; - result->readFunc = gconf2_backend_read_value; - result->writeFunc = gconf2_backend_write_value; - return result; -} diff --git a/src/GConf2Backend.h b/src/GConf2Backend.h deleted file mode 100644 index 5db946c..0000000 --- a/src/GConf2Backend.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © 2014 Red Hat, Inc. All rights reserved. - * Copyright © 2014 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -/** - * SECTION:GConf2Backend - * @short_description: A GConf2 Backend - * @title: GConf2 Backend - * @stability: Stable - * @include: GConf2Backend.h - * - * GConf2 as MakerDialog backend. - */ - -#ifndef _G_CONF2_BACKEND_H_ -# define _G_CONF2_BACKEND_H_ -# include "MakerDialogBackend.h" -# define GCONF2_BACKEND_ID "gconf2" - -/** - * gconf2_backend_new: - * @basePath: All keys and sub-sections of this project should be put under here (with trailing '/'). - * @auxData: Auxiliary data. - * - * @returns: And GConf2 backend for this project. - */ -MkdgBackend *gconf2_backend_new(const gchar * basePath, gpointer auxData); - -#endif /* _G_CONF2_BACKEND_H_ */ diff --git a/src/IBusChewingProperties.c b/src/IBusChewingProperties.c index 09525fc..a37ba16 100644 --- a/src/IBusChewingProperties.c +++ b/src/IBusChewingProperties.c @@ -6,9 +6,7 @@ #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" #include "IBusConfigBackend.h" -#ifdef USE_GSETTINGS -# include "GSettingsBackend.h" -#endif +#include "GSettingsBackend.h" #define PAGE_EDITING N_("Editing") #define PAGE_SELECTING N_("Selecting") @@ -257,15 +255,10 @@ IBusChewingProperties *ibus_chewing_properties_new(MkdgBackend * backend, mkdg_properties_from_spec_array(propSpecs, backend, parent, auxData); /* In schema generation, backend is NULL */ -#ifdef USE_GSETTINGS self->confObjTable = g_hash_table_new(g_str_hash, g_str_equal); -#else - self->confObjTable = NULL; -#endif return self; } -#ifdef USE_GSETTINGS static GString *ibus_section_to_schema(const gchar * section) { GString *result = g_string_new("org.freedesktop"); @@ -278,7 +271,6 @@ static GString *ibus_section_to_schema(const gchar * section) g_strfreev(strArr); return result; } -#endif /* USE_GSETTINGS */ GValue *ibus_chewing_properties_read_general(IBusChewingProperties * self, GValue * value, @@ -288,7 +280,6 @@ GValue *ibus_chewing_properties_read_general(IBusChewingProperties * self, { g_assert(self); g_assert(value); -#ifdef USE_GSETTINGS if (STRING_EQUALS(self->properties->backend->id, GSETTINGS_BACKEND_ID)) { GSettings *confObj; @@ -307,7 +298,6 @@ GValue *ibus_chewing_properties_read_general(IBusChewingProperties * self, g_assert(confObj); return mkdg_g_settings_read_value(confObj, value, key); } -#endif /* USE_GSETTINGS */ return mkdg_backend_read(self->properties->backend, value, section, key, userData); } diff --git a/src/MakerDialogWidget.c b/src/MakerDialogWidget.c deleted file mode 100644 index af9f637..0000000 --- a/src/MakerDialogWidget.c +++ /dev/null @@ -1,568 +0,0 @@ -#define GETTEXT_PACKAGE "gtk30" -#include -#include "MakerDialogUtil.h" -#include "MakerDialogWidget.h" - -const gchar *mkdgButtonTextArray[MKDG_BUTTON_INDEX_INVALID + 1] = { - NC_("Configure", "Cancel"), - NC_("Configure", "Save"), - NC_("Configure", "Apply"), - NC_("Configure", "Close"), - NC_("Configure", "Ok"), - NULL -}; - -MkdgButtonResponse mkdg_button_get_response(MkdgButtonIndex index) -{ - switch (index) { - case MKDG_BUTTON_INDEX_CANCEL: - return MKDG_BUTTON_RESPONSE_CANCEL; - case MKDG_BUTTON_INDEX_SAVE: - return MKDG_BUTTON_RESPONSE_SAVE; - case MKDG_BUTTON_INDEX_APPLY: - return MKDG_BUTTON_RESPONSE_APPLY; - case MKDG_BUTTON_INDEX_CLOSE: - return MKDG_BUTTON_RESPONSE_CLOSE; - case MKDG_BUTTON_INDEX_OK: - return MKDG_BUTTON_RESPONSE_OK; - default: - break; - } - return MKDG_BUTTON_RESPONSE_INVALID; -} - -const gchar *mkdg_button_get_text(MkdgButtonIndex index) -{ - if (index < 0) { - return NULL; - } - if (index > MKDG_BUTTON_INDEX_INVALID) { - return NULL; - } - return g_dpgettext2(NULL, "Configure", mkdgButtonTextArray[index]); -} - -/*===================================== - * MkdgWidget - * - */ - -static void mkdg_list_store_append(GtkListStore * listStore, - const gchar * str, - const gchar * translationContext, - MkdgPropertyFlags propertyFlags) -{ - GtkTreeIter iter; - - gtk_list_store_append(listStore, &iter); - - if (propertyFlags & MKDG_PROPERTY_FLAG_HAS_TRANSLATION) { - if (STRING_IS_EMPTY(translationContext)) { - mkdg_log(DEBUG, "mkdg_list_store_append() str=%s, _(str)=%s", - str, _(str)); - gtk_list_store_set(listStore, &iter, 0, str, 1, _(str), -1); - } else { - mkdg_log(DEBUG, "mkdg_list_store_append() str=%s, _(str)=%s", - str, g_dpgettext2(NULL, translationContext, str)); - gtk_list_store_set(listStore, &iter, 0, str, 1, - g_dpgettext2(NULL, translationContext, str), -1); - } - } else { - mkdg_log(DEBUG, "mkdg_list_store_append() str=%s", str); - gtk_list_store_set(listStore, &iter, 0, str, -1); - } -} - -gint mkdg_list_store_find_string(GtkListStore * listStore, - const gchar * str, - const gchar * translationContext, - MkdgPropertyFlags propertyFlags) -{ - g_assert(str); - mkdg_log(INFO, "mkdg_list_store_find_string(%s,%u)", str, propertyFlags); - gint i = 0, index = -1; - GtkTreeIter iter; - GValue gValue = { 0 }; - if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(listStore), &iter)) { - do { - gtk_tree_model_get_value(GTK_TREE_MODEL(listStore), &iter, 0, - &gValue); - if (STRING_EQUALS(str, g_value_get_string(&gValue))) { - index = i; - break; - } - i++; - g_value_unset(&gValue); - } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(listStore), &iter)); - } - if (index < 0 && !(propertyFlags & MKDG_PROPERTY_FLAG_NO_NEW)) { - /* Add new item */ - mkdg_list_store_append(listStore, str, translationContext, - propertyFlags); - index = i; - } - mkdg_log(DEBUG, "mkdg_list_store_find_string(%s,%u) index=%d", str, - propertyFlags, index); - return index; -} - -gint mkdg_combo_find_string_index(GtkComboBox * combo, - const gchar * str, - const gchar * translationContext, - MkdgPropertyFlags propertyFlags) -{ - GtkListStore *listStore = GTK_LIST_STORE(gtk_combo_box_get_model(combo)); - - return mkdg_list_store_find_string(listStore, str, translationContext, - propertyFlags); -} - -static GValue *mkdg_combo_get_active_text(GtkComboBox * combo) -{ - GtkTreeIter iter; - - if (!gtk_combo_box_get_active_iter(combo, &iter)) { - return NULL; - } - GValue *value = g_new0(GValue, 1); - GtkListStore *listStore = GTK_LIST_STORE(gtk_combo_box_get_model(combo)); - - gtk_tree_model_get_value(GTK_TREE_MODEL(listStore), &iter, 0, value); - return value; -} - -/*===================================== - * Widget Callback function wraps - */ - -static void on_value_change(MkdgWidget * mWidget, GValue * value) -{ - if (!(mWidget->flags & MKDG_WIDGET_FLAG_SET_IMMEDIATELY)) { - if (mWidget->flags & MKDG_WIDGET_FLAG_WRITE_IMMEDIATELY) { - mkdg_log(ERROR, - "MKDG_WIDGET_FLAG_SET_IMMEDIATELY is needed for MKDG_WIDGET_FLAG_WRITE_IMMEDIATELY"); - return; - } else if (mWidget->flags & MKDG_WIDGET_FLAG_APPLY_IMMEDIATELY) { - mkdg_log(ERROR, - "MKDG_WIDGET_FLAG_SET_IMMEDIATELY is needed for MKDG_WIDGET_FLAG_APPLY_IMMEDIATELY"); - return; - } - } - if (mWidget->flags & MKDG_WIDGET_FLAG_SET_IMMEDIATELY) { - property_context_set(mWidget->ctx, value); - } - - if (mWidget->flags & MKDG_WIDGET_FLAG_WRITE_IMMEDIATELY) { - property_context_save(mWidget->ctx, value, NULL); - } - - if (mWidget->flags & MKDG_WIDGET_FLAG_APPLY_IMMEDIATELY) { - property_context_apply(mWidget->ctx, NULL); - } -} - -static void on_comboBox_changed_wrap(GtkComboBox * comboBox, gpointer userData) -{ - MkdgWidget *mWidget = (MkdgWidget *) userData; - - //GValue gValue = { 0 }; - GValue *value = mkdg_combo_get_active_text(comboBox); - - mkdg_log(INFO, "on_comboBox_changed_wrap(), key=%s value=%s", - mWidget->ctx->spec->key, mkdg_g_value_to_string(value)); - on_value_change(mWidget, value); - g_value_unset(value); -} - -static void on_entry_activate_wrap(GtkEntry * entry, gpointer userData) -{ - MkdgWidget *mWidget = (MkdgWidget *) userData; - GValue gValue = { 0 }; - g_value_init(&gValue, mWidget->ctx->spec->valueType); - g_value_set_string(&gValue, gtk_editable_get_text(GTK_EDITABLE(entry))); - mkdg_log(INFO, "on_entry_activate_wrap(), key=%s value=%s", - mWidget->ctx->spec->key, g_value_get_string(&gValue)); - on_value_change(mWidget, &gValue); -} - -static void on_spinButton_value_changed_wrap(GtkSpinButton * button, - gpointer userData) -{ - MkdgWidget *mWidget = (MkdgWidget *) userData; - GValue gValue = { 0 }; - g_value_init(&gValue, mWidget->ctx->spec->valueType); - switch (mWidget->ctx->spec->valueType) { - case G_TYPE_INT: - g_value_set_int(&gValue, (gint) gtk_spin_button_get_value(button)); - mkdg_log(INFO, - "on_spinButton_value_changed_wrap(), key=%s value=%d", - mWidget->ctx->spec->key, g_value_get_int(&gValue)); - break; - case G_TYPE_UINT: - g_value_set_uint(&gValue, (guint) gtk_spin_button_get_value(button)); - mkdg_log(INFO, - "on_spinButton_value_changed_wrap(), key=%s value=%u", - mWidget->ctx->spec->key, g_value_get_uint(&gValue)); - break; - case G_TYPE_DOUBLE: - g_value_set_double(&gValue, gtk_spin_button_get_value(button)); - mkdg_log(INFO, - "on_spinButton_value_changed_wrap(), key=%s value=%g", - mWidget->ctx->spec->key, g_value_get_double(&gValue)); - break; - default: - break; - } - on_value_change(mWidget, &gValue); -} - -static void on_toggleButton_toggled_wrap(GtkToggleButton * button, - gpointer userData) -{ - MkdgWidget *mWidget = (MkdgWidget *) userData; - GValue gValue = { 0 }; - g_value_init(&gValue, mWidget->ctx->spec->valueType); - g_value_set_boolean(&gValue, gtk_toggle_button_get_active(button)); - mkdg_log(INFO, "on_entry_activate_wrap(), key=%s value=%s", - mWidget->ctx->spec->key, mkdg_g_value_to_string(&gValue)); - on_value_change(mWidget, &gValue); -} - -/*===================================== - * MkdgWgt subroutines - */ - -gint mkdg_wgt_get_width(MkdgWgt * wgt) -{ - GtkRequisition min_size; - GtkRequisition natural_size; - - gtk_widget_get_preferred_size(wgt, &min_size, &natural_size); - return natural_size.width; -} - -void mkdg_wgt_set_width(MkdgWgt * wgt, gint width) -{ - gtk_widget_set_size_request(wgt, width, -1); -} - -void mkdg_wgt_set_alignment(MkdgWgt * wgt, gfloat xAlign, gfloat yAlign) -{ - gtk_widget_set_halign(wgt, xAlign); - gtk_widget_set_valign(wgt, yAlign); - if (GTK_IS_LABEL(wgt)) { - /* gtk_label_set_justify takes no effect on single line label, - * but multi-lined label need this - */ - gtk_label_set_justify(GTK_LABEL(wgt), GTK_JUSTIFY_RIGHT); - } -} - -/*===================================== - * MkdgWidgetContainer subroutines - */ - -MkdgWidgetContainer *mkdg_widget_container_new(MkdgWgt * wgt) -{ - if (wgt == NULL) { - return NULL; - } - MkdgWidgetContainer *container = g_new0(MkdgWidgetContainer, 1); - - container->wgt = wgt; - container->children = g_ptr_array_new(); - container->childrenLabelWidth = 0; - return container; -} - -void mkdg_widget_container_add_widget(MkdgWidgetContainer * container, - MkdgWidget * mWidget) -{ - if ((container == NULL) || (mWidget == NULL)) { - return; - } - MkdgWgt *vbox = container->wgt; - - /* Add widget to the vbox */ - MkdgWgt *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, MKDG_HBOX_SPACING_DEFAULT); - MkdgWgt *labelWgt = MKDG_WGT(mWidget->label); - MkdgWgt *wgt = mWidget->wgt; - - gtk_box_prepend(GTK_BOX(hbox), labelWgt); - // mkdg_wgt_show(labelWgt); - gtk_box_prepend(GTK_BOX(hbox), wgt); - gtk_box_prepend(GTK_BOX(vbox), hbox); - - g_ptr_array_add(container->children, mWidget); - container->childrenLabelWidth = - MAX(container->childrenLabelWidth, mkdg_wgt_get_width(labelWgt)); -} - -void mkdg_widget_container_align_all_children(MkdgWidgetContainer * - container, - gfloat labelXAlign, - gfloat labelYAlign, - gfloat wgtXAlign, - gfloat wgtYAlign) -{ - if ((container == NULL) || (container->children == NULL)) { - return; - } - - gint i; - - for (i = 0; i < mkdg_widget_container_count_children(container); i++) { - MkdgWidget *mWidget = g_ptr_array_index(container->children, i); - - /* Set Width and Aligning labels */ - MkdgWgt *labelWgt = MKDG_WGT(mWidget->label); - - mkdg_wgt_set_width(labelWgt, container->childrenLabelWidth); - mkdg_wgt_set_alignment(labelWgt, labelXAlign, labelYAlign); - mkdg_wgt_set_alignment(mWidget->wgt, wgtXAlign, wgtYAlign); - } -} - -gint mkdg_widget_container_count_children(MkdgWidgetContainer * container) -{ - if ((container == NULL) || (container->children == NULL)) { - return -1; - } - return container->children->len; -} - -void mkdg_widget_cointainer_free(MkdgWidgetContainer * container) -{ - g_ptr_array_free(container->children, TRUE); - g_free(container); -} - -/*===================================== - * MkdgWidget subroutines - */ - -MkdgWidget *mkdg_widget_new(PropertyContext * ctx, MkdgWidgetFlag widgetFlags) -{ - if (ctx == NULL) { - return NULL; - } - mkdg_log(INFO, "mkdg_widget_new(%s,%x)", ctx->spec->key, widgetFlags); - MkdgWidget *mWidget = g_new0(MkdgWidget, 1); - - MkdgWgt *wgt = NULL; - GtkAdjustment *gAdjust = NULL; - gboolean bValue; - const gchar *strValue; - gdouble numberValue; - gdouble stepInc = 1.0; - gdouble pageInc = 10.0; - gdouble pageSize = 0.0; - - switch (ctx->spec->valueType) { - case G_TYPE_BOOLEAN: - bValue = g_value_get_boolean(property_context_get(ctx)); - wgt = gtk_toggle_button_new(); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wgt), bValue); - g_signal_connect(wgt, "toggled", - G_CALLBACK(on_toggleButton_toggled_wrap), mWidget); - break; - case G_TYPE_UINT: - case G_TYPE_INT: - if (ctx->spec->valueType == G_TYPE_UINT) { - numberValue = (gdouble) g_value_get_uint(property_context_get(ctx)); - } else { - numberValue = (gdouble) g_value_get_int(property_context_get(ctx)); - } - gAdjust = (GtkAdjustment *) gtk_adjustment_new(numberValue, - ctx->spec->min, - ctx->spec->max, - stepInc, pageInc, - pageSize); - wgt = gtk_spin_button_new(gAdjust, 1.0, 0); - g_signal_connect(wgt, "value-changed", - G_CALLBACK(on_spinButton_value_changed_wrap), mWidget); - break; - case G_TYPE_STRING: - strValue = g_value_get_string(property_context_get(ctx)); - if (ctx->spec->validValues) { - GtkListStore *listStore = NULL; - - if (ctx->spec->propertyFlags & MKDG_PROPERTY_FLAG_HAS_TRANSLATION) { - listStore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); - } else { - listStore = gtk_list_store_new(1, G_TYPE_STRING); - } - int i; - - for (i = 0; ctx->spec->validValues[i] != NULL; i++) { - /* Add new item */ - mkdg_list_store_append(listStore, - ctx->spec->validValues[i], - ctx->spec->translationContext, - ctx->spec->propertyFlags); - } - int index = mkdg_list_store_find_string(listStore, strValue, - ctx->spec-> - translationContext, - ctx->spec->propertyFlags); - - if (ctx->spec->propertyFlags & MKDG_PROPERTY_FLAG_NO_NEW) { - wgt = gtk_combo_box_new_with_model(GTK_TREE_MODEL(listStore)); - GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); - - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(wgt), - renderer, FALSE); - if (ctx->spec->propertyFlags & - MKDG_PROPERTY_FLAG_HAS_TRANSLATION) { - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(wgt), - renderer, "text", 1, NULL); - } else { - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(wgt), - renderer, "text", 0, NULL); - } - } else { - wgt = - gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL - (listStore)); - gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX(wgt), - (ctx->spec-> - propertyFlags & - MKDG_PROPERTY_FLAG_HAS_TRANSLATION) - ? 1 : 0); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(wgt), index); - g_signal_connect(wgt, "changed", - G_CALLBACK(on_comboBox_changed_wrap), mWidget); - } else { - wgt = gtk_entry_new(); - if (ctx->spec->max >= 0) { - gtk_entry_set_max_length(GTK_ENTRY(wgt), ctx->spec->max); - } - gtk_editable_set_text(GTK_EDITABLE(wgt), strValue); - gtk_editable_set_editable(GTK_EDITABLE(wgt), - !(ctx->spec->propertyFlags & - MKDG_PROPERTY_FLAG_NO_NEW)); - g_signal_connect(wgt, "activate", - G_CALLBACK(on_entry_activate_wrap), mWidget); - } - break; - default: - break; - } - if (wgt == NULL) { - g_free(mWidget); - return NULL; - } - mWidget->ctx = ctx; - mWidget->wgt = wgt; - MkdgWgtLabel *label = GTK_LABEL(gtk_label_new(_(ctx->spec->label))); - - mWidget->label = label; - gtk_widget_set_tooltip_text(GTK_WIDGET(label), _(ctx->spec->tooltip)); - mWidget->flags = widgetFlags; - mWidget->container = NULL; - return mWidget; -} - -MkdgWidget *mkdg_widget_new_in_container(PropertyContext * ctx, - MkdgWidgetFlag widgetFlags, - MkdgWidgetContainer * container) -{ - MkdgWidget *mWidget = mkdg_widget_new(ctx, widgetFlags); - - if (mWidget == NULL) { - return NULL; - } - mkdg_widget_container_add_widget(container, mWidget); - return mWidget; -} - -GValue *mkdg_widget_get_widget_value(MkdgWidget * mWidget, GValue * value) -{ - if (mWidget == NULL) { - return NULL; - } - if (mWidget->wgt == NULL) { - return NULL; - } - switch (mWidget->ctx->spec->valueType) { - case G_TYPE_BOOLEAN: - g_value_set_boolean(value, - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON - (mWidget->wgt))); - break; - case G_TYPE_INT: - g_value_set_int(value, (gint) - gtk_spin_button_get_value(GTK_SPIN_BUTTON - (mWidget->wgt))); - break; - case G_TYPE_UINT: - g_value_set_uint(value, (guint) - gtk_spin_button_get_value(GTK_SPIN_BUTTON - (mWidget->wgt))); - break; - case G_TYPE_STRING: - if (mWidget->ctx->spec->validValues) { - GValue *strValue = - mkdg_combo_get_active_text(GTK_COMBO_BOX(mWidget->wgt)); - mkdg_log(INFO, "mkdg_widget_get_widget_value(%s) %s", - mWidget->ctx->spec->key, mkdg_g_value_to_string(strValue)); - g_value_copy(strValue, value); - g_value_unset(strValue); - } else { - g_value_set_string(value, - gtk_editable_get_text(GTK_EDITABLE(mWidget->wgt))); - } - break; - default: - return NULL; - } - return value; -} - -gboolean mkdg_widget_set_widget_value(MkdgWidget * mWidget, GValue * value) -{ - if (mWidget == NULL) { - return FALSE; - } - if (mWidget->ctx == NULL) { - return FALSE; - } - if (mWidget->wgt == NULL) { - return FALSE; - } - - switch (mWidget->ctx->spec->valueType) { - case G_TYPE_BOOLEAN: - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mWidget->wgt), - g_value_get_boolean(value)); - break; - case G_TYPE_INT: - gtk_spin_button_set_value(GTK_SPIN_BUTTON(mWidget->wgt), - (gdouble) g_value_get_int(value)); - break; - case G_TYPE_UINT: - gtk_spin_button_set_value(GTK_SPIN_BUTTON(mWidget->wgt), - (gdouble) g_value_get_uint(value)); - break; - case G_TYPE_STRING: - if (mWidget->ctx->spec->validValues) { - const gchar *str = g_value_get_string(value); - gint index = - mkdg_combo_find_string_index(GTK_COMBO_BOX(mWidget->wgt), str, - mWidget->ctx->spec-> - translationContext, - mWidget->ctx->spec->propertyFlags); - - gtk_combo_box_set_active(GTK_COMBO_BOX(mWidget->wgt), index); - } else { - g_value_set_string(value, - gtk_editable_get_text(GTK_EDITABLE(mWidget->wgt))); - } - break; - default: - /* Not supported */ - return FALSE; - } - return TRUE; -} diff --git a/src/MakerDialogWidget.h b/src/MakerDialogWidget.h deleted file mode 100644 index 6e3effb..0000000 --- a/src/MakerDialogWidget.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef _MAKER_DIALOG_WIDGET_H_ -# define _MAKER_DIALOG_WIDGET_H_ -# include -# include "MakerDialogProperty.h" - -# ifndef MKDG_HBOX_SPACING_DEFAULT -# define MKDG_HBOX_SPACING_DEFAULT 5 -# endif - -# ifndef MKDG_VBOX_SPACING_DEFAULT -# define MKDG_VBOX_SPACING_DEFAULT 10 -# endif - -typedef enum { - MKDG_WIDGET_FLAG_SET_IMMEDIATELY = 1, - MKDG_WIDGET_FLAG_WRITE_IMMEDIATELY = 1 << 1, - MKDG_WIDGET_FLAG_APPLY_IMMEDIATELY = 1 << 2 -} MkdgWidgetFlag; - -typedef enum { - MKDG_BUTTON_INDEX_CANCEL, - MKDG_BUTTON_INDEX_SAVE, - MKDG_BUTTON_INDEX_APPLY, - MKDG_BUTTON_INDEX_CLOSE, - MKDG_BUTTON_INDEX_OK, - MKDG_BUTTON_INDEX_INVALID, -} MkdgButtonIndex; - -/** - * MkdgButtonFlag: - * @MKDG_BUTTON_FLAG_CANCEL: Close dialog. - * @MKDG_BUTTON_FLAG_SAVE: Save. - * @MKDG_BUTTON_FLAG_APPLY: Apply. - * @MKDG_BUTTON_FLAG_OK: Save, Apply and Close dialog. - * - * Buttons of this dialog. - */ - -typedef enum { - MKDG_BUTTON_FLAG_CANCEL = 1 << MKDG_BUTTON_INDEX_CANCEL, - MKDG_BUTTON_FLAG_SAVE = 1 << MKDG_BUTTON_INDEX_SAVE, - MKDG_BUTTON_FLAG_APPLY = 1 << MKDG_BUTTON_INDEX_APPLY, - MKDG_BUTTON_FLAG_CLOSE = 1 << MKDG_BUTTON_INDEX_CLOSE, - MKDG_BUTTON_FLAG_OK = 1 << MKDG_BUTTON_INDEX_OK, - MKDG_BUTTON_FLAG_INVALID = 1 << MKDG_BUTTON_INDEX_INVALID, -} MkdgButtonFlag; - -typedef enum { - MKDG_BUTTON_RESPONSE_CANCEL = GTK_RESPONSE_CANCEL, - MKDG_BUTTON_RESPONSE_SAVE = MKDG_BUTTON_INDEX_SAVE, - MKDG_BUTTON_RESPONSE_APPLY = GTK_RESPONSE_APPLY, - MKDG_BUTTON_RESPONSE_CLOSE = GTK_RESPONSE_CLOSE, - MKDG_BUTTON_RESPONSE_OK = GTK_RESPONSE_OK, - MKDG_BUTTON_RESPONSE_INVALID = MKDG_BUTTON_INDEX_INVALID -} MkdgButtonResponse; - -MkdgButtonResponse mkdg_button_get_response(MkdgButtonIndex index); -const gchar *mkdg_button_get_text(MkdgButtonIndex index); - -/** - * MkdgWdt: - * - * The actual widget from the ToolKit. - */ -typedef GtkWidget MkdgWgt; - -/** - * MkdgWdtLabel: - * - * The actual label widget from the ToolKit. - */ -typedef GtkLabel MkdgWgtLabel; - -/** - * MKDG_WGT: - * @obj: Object to be casted. - * - * Cast the object as MkdgWgt. - */ -# define MKDG_WGT(obj) GTK_WIDGET(obj) - -gint mkdg_wgt_get_width(MkdgWgt * wgt); - -void mkdg_wgt_set_width(MkdgWgt * wgt, gint width); - -void mkdg_wgt_set_alignment(MkdgWgt * wgt, gfloat xAlign, gfloat yAlign); - -void mkdg_wgt_show(MkdgWgt * wgt); - -void mkdg_wgt_show_all(MkdgWgt * wgt); - -void mkdg_wgt_destroy(MkdgWgt * wgt); - -/*===================================== - * MkdgWidgetContainer subroutines - */ -typedef struct { - MkdgWgt *wgt; - GPtrArray *children; - gint childrenLabelWidth; -} MkdgWidgetContainer; - -typedef struct { - MkdgWgtLabel *label; - MkdgWgt *wgt; - PropertyContext *ctx; - MkdgWidgetFlag flags; - MkdgWidgetContainer *container; -} MkdgWidget; - -MkdgWidgetContainer *mkdg_widget_container_new(MkdgWgt * wgt); - - -void mkdg_widget_container_add_widget(MkdgWidgetContainer * container, - MkdgWidget * mWidget); - -void mkdg_widget_container_align_all_children(MkdgWidgetContainer * - container, - gfloat labelXAlign, - gfloat labelYAlign, - gfloat wgtXAlign, - gfloat wgtYAlign); - -gint mkdg_widget_container_count_children(MkdgWidgetContainer * container); - -void mkdg_widget_cointainer_free(MkdgWidgetContainer * container); - - -MkdgWidget *mkdg_widget_new(PropertyContext * ctx, MkdgWidgetFlag widgetFlags); - - -/** - * mkdg_widget_get_widget_value: - * @mWidget: Widget to be get. - * @value: Result value stores here. - * @returns: NULL if failed, otherwise return the address of value. - * - * Get value from display widget. - * This subroutine will not touch the property context. Use property_context_get() for that. - * @see_also: property_context_get(), mkdg_widget_set_widget_value() - * @returns: TRUE if success, FALSE if either mWidget or it's members are NULL - */ -GValue *mkdg_widget_get_widget_value(MkdgWidget * mWidget, GValue * value); - -/** - * mkdg_widget_set_widget_value: - * @mWidget: Widget to be set. - * @value: Set Widget with this value. - * - * Set widget value for display. - * This subroutine will not touch the property context. Use property_context_set() for that. - * @see_also: property_context_set(), mkdg_widget_get_widget_value() - * @returns: TRUE if success, FALSE if either mWidget or it's members are NULL - */ -gboolean mkdg_widget_set_widget_value(MkdgWidget * mWidget, GValue * value); - -#endif /* _MAKER_DIALOG_WIDGET_H_ */ diff --git a/src/generate-gconf-schemas.c b/src/generate-gconf-schemas.c deleted file mode 100644 index 18852b7..0000000 --- a/src/generate-gconf-schemas.c +++ /dev/null @@ -1,213 +0,0 @@ -#include -#include -#include -#include -#include - -/* - * Callback should be skipped - */ -#ifndef MKDG_SPEC_ONLY -# define MKDG_SPEC_ONLY -#endif - -#include "MakerDialogUtil.h" -#include "MakerDialogProperty.h" -#include "IBusConfigBackend.h" -#include "IBusChewingProperties.h" -#define XML_BUFFER_SIZE 1000 -#define DEFAULT_LOCALES "C;zh_TW" - -static gint verbose = WARN; -static gchar *schemasFilename = NULL; -static gchar *localeStr = NULL; -static gchar *localeOptStr = NULL; -static gchar **localeArray = NULL; - -static const GOptionEntry entries[] = { - {"verbose", 'v', 0, G_OPTION_ARG_INT, &verbose, - "Verbose level. The higher the level, the more the debug messages.", - "[integer]"}, - {"locale", 'l', 0, G_OPTION_ARG_STRING, &localeOptStr, - "Supported locales. Use ';' to separate locales.", - "[str]"}, - {NULL}, -}; - - -/*============================================ - * GConf Schemas routines - */ - -static void ctx_write_locale(PropertyContext * ctx, - FILE * outF, const gchar * locale) -{ - gchar buf[XML_BUFFER_SIZE]; - - mkdg_log(DEBUG, "ctx_write_locale(%s,-,%s)", ctx->spec->key, locale); - setlocale(LC_ALL, "locale"); - g_snprintf(buf, 50, "name=\"%s\"", locale); - setlocale(LC_MESSAGES, locale); - mkdg_xml_tags_write(outF, "locale", MKDG_XML_TAG_TYPE_BEGIN_ONLY, buf, - NULL); - mkdg_xml_tags_write(outF, "short", MKDG_XML_TAG_TYPE_SHORT, NULL, - gettext(ctx->spec->label)); - mkdg_xml_tags_write(outF, "long", MKDG_XML_TAG_TYPE_LONG, NULL, - gettext(ctx->spec->tooltip)); - mkdg_xml_tags_write(outF, "locale", MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); -} - -gboolean ctx_write(PropertyContext * ctx, const gchar * schemasHome, - const gchar * owner, FILE * outF) -{ - if (ctx->spec->propertyFlags & MKDG_PROPERTY_FLAG_NO_BACKEND) { - return TRUE; - } - mkdg_xml_tags_write(outF, "schema", MKDG_XML_TAG_TYPE_BEGIN_ONLY, NULL, - NULL); - gchar buf[XML_BUFFER_SIZE]; - gchar *camalCasedKey = mkdg_str_dash_to_camel(ctx->spec->key); - - g_snprintf(buf, XML_BUFFER_SIZE, "/schemas%s", schemasHome); - - if (!STRING_IS_EMPTY(ctx->spec->subSection)) { - g_strlcat(buf, "/", XML_BUFFER_SIZE); - g_strlcat(buf, ctx->spec->subSection, XML_BUFFER_SIZE); - } - g_strlcat(buf, "/", XML_BUFFER_SIZE); - g_strlcat(buf, camalCasedKey, XML_BUFFER_SIZE); - - mkdg_xml_tags_write(outF, "key", MKDG_XML_TAG_TYPE_SHORT, NULL, buf); - mkdg_xml_tags_write(outF, "applyto", MKDG_XML_TAG_TYPE_SHORT, NULL, - buf + strlen("/schemas")); - mkdg_xml_tags_write(outF, "owner", MKDG_XML_TAG_TYPE_SHORT, NULL, owner); - switch (ctx->spec->valueType) { - case G_TYPE_BOOLEAN: - mkdg_xml_tags_write(outF, "type", MKDG_XML_TAG_TYPE_SHORT, NULL, - "bool"); - break; - case G_TYPE_INT: - case G_TYPE_UINT: - mkdg_xml_tags_write(outF, "type", MKDG_XML_TAG_TYPE_SHORT, NULL, "int"); - break; - case G_TYPE_STRING: - mkdg_xml_tags_write(outF, "type", MKDG_XML_TAG_TYPE_SHORT, NULL, - "string"); - break; - default: - break; - } - if (ctx->spec->defaultValue) { - mkdg_xml_tags_write(outF, "default", MKDG_XML_TAG_TYPE_SHORT, NULL, - ctx->spec->defaultValue); - } - int i; - - for (i = 0; localeArray[i] != NULL; i++) { - ctx_write_locale(ctx, outF, localeArray[i]); - } - - setlocale(LC_ALL, NULL); - mkdg_xml_tags_write(outF, "schema", MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); - return TRUE; -} - -/** - * write_gconf_schemas_file: - * @filename: Filename for output. - * @owner: Owner of the schemas. - * @schemasHome: The "home direcory" of schemas. - * @localeStr: Supported localeStr, use ';' as delimiter. - * @returns: TRUE if succeed; FALSE otherwise. - * - * Output the parameters as GConf schemes file. - */ -gboolean write_gconf_schemas_file(const gchar * filename, - const gchar * owner, - const gchar * schemasHome, - const gchar * localeStr) -{ - mkdg_log(INFO, "write_gconf_schemes_file(%s,%s,%s,%s)", filename, - owner, schemasHome, localeStr); - FILE *outF = fopen(filename, "w"); - - if (outF == NULL) { - mkdg_log(DEBUG, - "write_gconf_schemas_file(%s) file %s cannot be written!", - filename, filename); - return FALSE; - } - localeArray = g_strsplit_set(localeStr, ":;", -1); - gchar **loc; - - for (loc = localeArray; *loc != NULL; loc++) { - mkdg_log(DEBUG, "write_gconf_schemas_file() locale=%s", *loc); - } - - /* Header */ - mkdg_xml_tags_write(outF, "gconfschemafile", - MKDG_XML_TAG_TYPE_BEGIN_ONLY, NULL, NULL); - mkdg_xml_tags_write(outF, "schemalist", - MKDG_XML_TAG_TYPE_BEGIN_ONLY, NULL, NULL); - /* Body */ - /* Backend is not needed for schema generation */ - IBusChewingProperties *iProperties = - ibus_chewing_properties_new(NULL, NULL, NULL); - gsize i; - - for (i = 0; i < mkdg_properties_size(iProperties->properties); i++) { - PropertyContext *ctx = - mkdg_properties_index(iProperties->properties, i); - ctx_write(ctx, schemasHome, owner, outF); - } - - /* Footer */ - mkdg_xml_tags_write(outF, "schemalist", MKDG_XML_TAG_TYPE_END_ONLY, - NULL, NULL); - mkdg_xml_tags_write(outF, "gconfschemafile", - MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); - if (fclose(outF)) - return FALSE; - mkdg_log(DEBUG, "write_gconf_schemas_file(%s) ... done.", filename); - return TRUE; -} - -int main(gint argc, gchar * argv[]) -{ - GError *error = NULL; - GOptionContext *context; - - /* Init i18n messages */ - setlocale(LC_ALL, ""); - bindtextdomain(QUOTE_ME(PROJECT_NAME), QUOTE_ME(DATA_DIR) "/locale"); - textdomain(QUOTE_ME(PROJECT_NAME)); - - context = g_option_context_new("schemasFile"); - - g_option_context_add_main_entries(context, entries, "ibus-chewing"); - - if (!g_option_context_parse(context, &argc, &argv, &error)) { - g_print("Option parsing failed: %s\n", error->message); - return 2; - } - g_option_context_free(context); - if (argc < 2) { - fprintf(stderr, "Specify output schemas file!\n"); - return 2; - } - mkdg_log_set_level(verbose); - schemasFilename = argv[1]; - - localeStr = (localeOptStr) ? localeOptStr : DEFAULT_LOCALES; - g_type_init(); - gboolean result = write_gconf_schemas_file(schemasFilename, "ibus-chewing", - QUOTE_ME(PROJECT_SCHEMA_BASE), - localeStr); - - if (localeOptStr) - g_free(localeOptStr); - if (!result) { - return 1; - } - return 0; -} diff --git a/src/generate-gsettings-schemas.c b/src/generate-gsettings-schemas.c deleted file mode 100644 index 2578783..0000000 --- a/src/generate-gsettings-schemas.c +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include -#include - -/* - * Callback should be skipped - */ -#ifndef MKDG_SPEC_ONLY -# define MKDG_SPEC_ONLY -#endif - -#include "MakerDialogUtil.h" -#include "MakerDialogProperty.h" -#include "GSettingsBackend.h" -#include "IBusChewingProperties.h" -#define XML_BUFFER_SIZE 1000 -#define DEFAULT_LOCALES "C;zh_TW" - -static gint verbose = WARN; -static gchar *schemasFilename = NULL; - -static const GOptionEntry entries[] = { - {"verbose", 'v', 0, G_OPTION_ARG_INT, &verbose, - "Verbose level. The higher the level, the more the debug messages.", - "[integer]"}, - {NULL}, -}; - -/** - * write_gconf_schemas_file: - * @filename: Filename for output. - * - * Output the parameters as GSettings schemes file. - */ -gboolean write_schemas_file(const gchar * filename) -{ - mkdg_log(INFO, "write_schemes_file(%s,)", filename); - FILE *outF = fopen(filename, "w"); - - if (outF == NULL) { - mkdg_log(DEBUG, - "write_gconf_schemas_file(%s) file %s cannot be written!", - filename, filename); - return FALSE; - } - - gboolean result = - mkdg_g_settings_write_schema_from_spec_array(QUOTE_ME - (PROJECT_SCHEMA_ID), - QUOTE_ME - (PROJECT_SCHEMA_PATH), - outF, propSpecs, - QUOTE_ME(PROJECT_NAME)); - - if (fclose(outF)) - return FALSE; - mkdg_log(DEBUG, "write_gconf_schemas_file(%s) ... done.", filename); - return result; -} - -int main(gint argc, gchar * argv[]) -{ - GError *error = NULL; - GOptionContext *context; - - /* Init i18n messages */ - setlocale(LC_ALL, ""); - bindtextdomain(QUOTE_ME(PROJECT_NAME), QUOTE_ME(DATA_DIR) "/locale"); - textdomain(QUOTE_ME(PROJECT_NAME)); - - context = g_option_context_new("schemasFile"); - - g_option_context_add_main_entries(context, entries, "ibus-chewing"); - - if (!g_option_context_parse(context, &argc, &argv, &error)) { - g_print("Option parsing failed: %s\n", error->message); - return 1; - } - g_option_context_free(context); - if (argc < 2) { - fprintf(stderr, "Specify filename of outputing schemas file!\n"); - return 1; - } - mkdg_log_set_level(verbose); - schemasFilename = argv[1]; - gboolean result = write_schemas_file(schemasFilename); - - if (!result) { - return 2; - } - return 0; -} diff --git a/src/ibus-chewing-engine-private.h b/src/ibus-chewing-engine-private.h index 9401ac0..5c253fc 100644 --- a/src/ibus-chewing-engine-private.h +++ b/src/ibus-chewing-engine-private.h @@ -32,12 +32,7 @@ #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" #include "IBusChewingPreEdit.h" -#ifdef USE_GSETTINGS #include "GSettingsBackend.h" -#endif -#ifdef USE_GCONF2 -#include "GConf2Backend.h" -#endif #ifndef __IBUS_CHEWING_ENGINE_PRIVATE_H__ #define __IBUS_CHEWING_ENGINE_PRIVATE_H__ @@ -50,7 +45,6 @@ extern "C" { -#include "maker-dialog.h" void ibus_chewing_engine_handle_Default(IBusChewingEngine * self, guint keyval, gboolean shiftPressed); diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c index 906e907..8188fa8 100644 --- a/src/ibus-chewing-engine.c +++ b/src/ibus-chewing-engine.c @@ -33,12 +33,7 @@ #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" #include "IBusChewingPreEdit.h" -#ifdef USE_GSETTINGS #include "GSettingsBackend.h" -#endif -#ifdef USE_GCONF2 -#include "GConf2Backend.h" -#endif #define GOB_VERSION_MAJOR 2 #define GOB_VERSION_MINOR 0 @@ -300,18 +295,9 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) if (self->icPreEdit == NULL) { -#ifdef USE_GSETTINGS MkdgBackend *backend = mkdg_g_settings_backend_new(QUOTE_ME(PROJECT_SCHEMA_ID), QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); -#elif defined USE_GCONF2 - MkdgBackend *backend = - gconf2_backend_new(QUOTE_ME(PROJECT_SCHEMA_BASE), NULL); -#else - MkdgBackend *backend = NULL; - g_error("Flag GSETTINGS_SUPPORT or GCONF2_SUPPORT are required!"); - return; -#endif /* USE_GSETTINGS */ self->icPreEdit = ibus_chewing_pre_edit_new(backend); } diff --git a/src/ibus-chewing-engine.h b/src/ibus-chewing-engine.h index a4d9975..2e83bc1 100644 --- a/src/ibus-chewing-engine.h +++ b/src/ibus-chewing-engine.h @@ -33,12 +33,7 @@ #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" #include "IBusChewingPreEdit.h" -#ifdef USE_GSETTINGS #include "GSettingsBackend.h" -#endif -#ifdef USE_GCONF2 -#include "GConf2Backend.h" -#endif #include #include diff --git a/src/ibus-setup-chewing.c b/src/ibus-setup-chewing.c deleted file mode 100644 index 6cc0428..0000000 --- a/src/ibus-setup-chewing.c +++ /dev/null @@ -1,137 +0,0 @@ -/* vim:set et sts=4: */ -/* - * Copyright © 2014 Red Hat, Inc. All rights reserved. - * Copyright © 2014 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -#include -#include -#include -#include -#include -#include -#include "MakerDialogUtil.h" -#include "MakerDialogBackend.h" -#ifdef USE_GSETTINGS -# include "GSettingsBackend.h" -#endif -#ifdef USE_GCONF2_SUPPORT -# include "GConf2Backend.h" -#endif -#include "GConf2Backend.h" -#include "IBusChewingProperties.h" -#include "IBusChewingUtil.h" -#include "maker-dialog.h" - - -/* options */ -static gboolean showFlags = FALSE; -gint verbose = 0; - -static const GOptionEntry entries[] = { - {"show_flags", 's', 0, G_OPTION_ARG_NONE, &showFlags, - "Show compile flag only", NULL}, - {"verbose", 'v', 0, G_OPTION_ARG_INT, &verbose, - "Verbose level. The higher the level, the more the debug messages.", - "[integer]"}, - {NULL}, -}; - - -void save_values(GtkDialog *sDialog, gint response_id, gpointer mDialog) -{ - if (response_id != GTK_RESPONSE_OK) { - return; - } - maker_dialog_save_all_widgets_values(mDialog, NULL); -} - -gint start_dialog() -{ -#ifdef USE_GSETTINGS - MkdgBackend *backend = - mkdg_g_settings_backend_new(QUOTE_ME(PROJECT_SCHEMA_ID), - QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); -#elif defined USE_GCONF2 - MkdgBackend *backend = - gconf2_backend_new(QUOTE_ME(PROJECT_SCHEMA_BASE), NULL); -#else - MkdgBackend *backend = NULL; - - g_error("Flag GSETTINGS_SUPPORT or GCONF2_SUPPORT are required!"); - return 1; -#endif /* GSETTINGS_SUPPORT */ - IBusChewingProperties *iProperties = - ibus_chewing_properties_new(backend, NULL, NULL); - - MakerDialog *mDialog = - maker_dialog_new_full(iProperties->properties, _("Setting"), - MKDG_WIDGET_FLAG_SET_IMMEDIATELY, - MKDG_BUTTON_FLAG_OK | MKDG_BUTTON_FLAG_CANCEL); - GtkWidget *sDialog = GTK_WIDGET(mDialog); - - gtk_window_present(GTK_WINDOW(mDialog)); - g_signal_connect(sDialog, "response", G_CALLBACK(save_values), mDialog); - // gint result = gtk_dialog_run(GTK_DIALOG(sDialog)); - - // gtk_widget_hide(sDialog); - // if (result != GTK_RESPONSE_OK) { - // return 3; - // } - // maker_dialog_save_all_widgets_values(mDialog, NULL); - return 0; -} - -gint main(gint argc, gchar * argv[]) -{ - GError *error = NULL; - GOptionContext *context; - - adw_init(); - - /* Init i18n messages */ - setlocale(LC_ALL, ""); - bindtextdomain(QUOTE_ME(PROJECT_NAME), QUOTE_ME(DATA_DIR) "/locale"); - textdomain(QUOTE_ME(PROJECT_NAME)); - - context = g_option_context_new("- ibus chewing engine setup"); - - g_option_context_add_main_entries(context, entries, QUOTE_ME(PROJECT_NAME)); - - if (!g_option_context_parse(context, &argc, &argv, &error)) { - g_print("Option parsing failed: %s\n", error->message); - exit(1); - } - - g_option_context_free(context); - if (showFlags) { - printf("PROJECT_NAME=" QUOTE_ME(PROJECT_NAME) "\n"); - printf("DATA_DIR=" QUOTE_ME(DATA_DIR) "\n"); - printf("CHEWING_DATADIR_REAL=" QUOTE_ME(CHEWING_DATADIR_REAL) - "\n"); - return 0; - } - mkdg_log_set_level(verbose); - start_dialog(); - while (true) - g_main_context_iteration (NULL, TRUE); - return 0; -} - -/* vim:set et sts=4: */ diff --git a/src/main.c b/src/main.c index cc46588..1be5dfd 100644 --- a/src/main.c +++ b/src/main.c @@ -27,9 +27,7 @@ #include #include "ibus-chewing-engine.h" #include "IBusChewingUtil.h" -#include "maker-dialog.h" -MakerDialog *makerDialog = NULL; static IBusBus *bus = NULL; static IBusFactory *factory = NULL; diff --git a/src/maker-dialog-private.h b/src/maker-dialog-private.h deleted file mode 100644 index e042511..0000000 --- a/src/maker-dialog-private.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2009 Red Hat, Inc. All rights reserved. - * Copyright © 2009 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -#ifndef __MAKER_DIALOG_PRIVATE_H__ -#define __MAKER_DIALOG_PRIVATE_H__ - -#include "maker-dialog.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -struct _MakerDialogPrivate { - GHashTable * containerTable; - GHashTable * widgetTable; - GHashTable * notebookContentTable; - GStringChunk * widgetIds; - GPtrArray * pageLabels; - MkdgProperties * properties; -}; -gboolean maker_dialog_prepare (MakerDialog * self); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/src/maker-dialog.c b/src/maker-dialog.c deleted file mode 100644 index df0a912..0000000 --- a/src/maker-dialog.c +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Copyright © 2009 Red Hat, Inc. All rights reserved. - * Copyright © 2009 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -#define GOB_VERSION_MAJOR 2 -#define GOB_VERSION_MINOR 0 -#define GOB_VERSION_PATCHLEVEL 20 - -#define selfp (self->_priv) - -#include /* memset() */ - -#include "maker-dialog.h" - -#include "maker-dialog-private.h" - -#ifdef G_LIKELY -#define ___GOB_LIKELY(expr) G_LIKELY(expr) -#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr) -#else /* ! G_LIKELY */ -#define ___GOB_LIKELY(expr) (expr) -#define ___GOB_UNLIKELY(expr) (expr) -#endif /* G_LIKELY */ - - -#define GETTEXT_PACKAGE "gtk30" -#include - -/* self casting macros */ -#define SELF(x) MAKER_DIALOG(x) -#define SELF_CONST(x) MAKER_DIALOG_CONST(x) -#define IS_SELF(x) MAKER_IS_DIALOG(x) -#define TYPE_SELF MAKER_TYPE_DIALOG -#define SELF_CLASS(x) MAKER_DIALOG_CLASS(x) - -#define SELF_GET_CLASS(x) MAKER_DIALOG_GET_CLASS(x) - -/* self typedefs */ -typedef MakerDialog Self; -typedef MakerDialogClass SelfClass; - -/* here are local prototypes */ -static void maker_dialog_class_init (MakerDialogClass * c) G_GNUC_UNUSED; -static void maker_dialog_init (MakerDialog * self) G_GNUC_UNUSED; - -/* pointer to the class of our parent */ -static GtkDialogClass *parent_class = NULL; - -/* Short form macros */ -#define self_new maker_dialog_new -#define self_new_full maker_dialog_new_full -#define self_add_property maker_dialog_add_property -#define self_add_all_properties maker_dialog_add_all_properties -#define self_prepare maker_dialog_prepare -#define self_assign_widget_value maker_dialog_assign_widget_value -#define self_assign_all_widgets_values maker_dialog_assign_all_widgets_values -#define self_save_all_widgets_values maker_dialog_save_all_widgets_values -#define self_get_widget_value maker_dialog_get_widget_value -#define self_set_widget_value maker_dialog_set_widget_value -#define self_show maker_dialog_show -#define self_get_widget_by_key maker_dialog_get_widget_by_key -GType -maker_dialog_get_type (void) -{ - static GType type = 0; - - if ___GOB_UNLIKELY(type == 0) { - static const GTypeInfo info = { - sizeof (MakerDialogClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) maker_dialog_class_init, - (GClassFinalizeFunc) NULL, - NULL /* class_data */, - sizeof (MakerDialog), - 0 /* n_preallocs */, - (GInstanceInitFunc) maker_dialog_init, - NULL - }; - - type = g_type_register_static (GTK_TYPE_DIALOG, "MakerDialog", &info, (GTypeFlags)0); - } - - return type; -} - -/* a macro for creating a new object of our type */ -#define GET_NEW ((MakerDialog *)g_object_new(maker_dialog_get_type(), NULL)) - -/* a function for creating a new object of our type */ -#include -static MakerDialog * GET_NEW_VARG (const char *first, ...) G_GNUC_UNUSED; -static MakerDialog * -GET_NEW_VARG (const char *first, ...) -{ - MakerDialog *ret; - va_list ap; - va_start (ap, first); - ret = (MakerDialog *)g_object_new_valist (maker_dialog_get_type (), first, ap); - va_end (ap); - return ret; -} - - -static void -___finalize(GObject *obj_self) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::finalize" - MakerDialog *self G_GNUC_UNUSED = MAKER_DIALOG (obj_self); - gpointer priv G_GNUC_UNUSED = self->_priv; - if(self->notebookWgt) { g_object_unref ((gpointer) self->notebookWgt); self->notebookWgt = NULL; } - if(self->_priv->containerTable) { g_hash_table_destroy ((gpointer) self->_priv->containerTable); self->_priv->containerTable = NULL; } - if(self->_priv->widgetTable) { g_hash_table_destroy ((gpointer) self->_priv->widgetTable); self->_priv->widgetTable = NULL; } - if(self->_priv->notebookContentTable) { g_hash_table_destroy ((gpointer) self->_priv->notebookContentTable); self->_priv->notebookContentTable = NULL; } - if(self->_priv->widgetIds) { g_string_chunk_free ((gpointer) self->_priv->widgetIds); self->_priv->widgetIds = NULL; } -#define pageLabels (self->_priv->pageLabels) -#define VAR pageLabels - { - - if (VAR) { - g_ptr_array_free(VAR, TRUE); - } - } - memset(&(pageLabels), 0, sizeof(pageLabels)); -#undef VAR -#undef pageLabels -#define properties (self->_priv->properties) -#define VAR properties - { - - if (VAR) { - mkdg_properties_free(VAR); - } - } - memset(&(properties), 0, sizeof(properties)); -#undef VAR -#undef properties - if(G_OBJECT_CLASS(parent_class)->finalize) \ - (* G_OBJECT_CLASS(parent_class)->finalize)(obj_self); -} -#undef __GOB_FUNCTION__ - -static void -maker_dialog_class_init (MakerDialogClass * c G_GNUC_UNUSED) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::class_init" - GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) c; - - g_type_class_add_private(c,sizeof(MakerDialogPrivate)); - - parent_class = g_type_class_ref (GTK_TYPE_DIALOG); - - g_object_class->finalize = ___finalize; -} -#undef __GOB_FUNCTION__ -static void -maker_dialog_init (MakerDialog * self G_GNUC_UNUSED) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::init" - self->_priv = G_TYPE_INSTANCE_GET_PRIVATE(self,MAKER_TYPE_DIALOG,MakerDialogPrivate); - self->notebookWgt = NULL; - self->_priv->containerTable = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL) ; - self->_priv->widgetTable = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL) ; - self->_priv->notebookContentTable = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL) ; - self->_priv->widgetIds = g_string_chunk_new(MAKER_DIALOG_ID_LENGTH) ; - self->_priv->pageLabels = NULL; - self->_priv->properties = NULL; - { - - /* initialize the object here */ - - } -} -#undef __GOB_FUNCTION__ - - - -MakerDialog * -maker_dialog_new (void) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::new" -{ - - Self * self = GET_NEW; - return self; - }} -#undef __GOB_FUNCTION__ - -MakerDialog * -maker_dialog_new_full (MkdgProperties * properties, const gchar * title, MkdgWidgetFlag wFlags, MkdgButtonFlag bFlags) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::new_full" -{ - - Self * self = GET_NEW; - GtkDialog * dialog = GTK_DIALOG(self); - gtk_window_set_title(GTK_WINDOW(dialog), title); - gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); - // gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); - self->wFlags = wFlags; - self->_priv->properties = properties; - - gint i; - /* Create Buttons */ - for (i = MKDG_BUTTON_INDEX_INVALID -1; i >= 0; i--) { - if ( bFlags & (1 << i)) { - const gchar *buttonText = mkdg_button_get_text(i); - mkdg_log(DEBUG, "new_full(-,%s,%X,%X) i=%d, buttonText=%s", - title, wFlags, bFlags, i, buttonText); - MkdgButtonResponse response = mkdg_button_get_response(i); - gtk_dialog_add_button(dialog, buttonText, response); - } - } - - /* Create Notebook */ - self->notebookWgt = gtk_notebook_new(); - // gtk_container_set_border_width(GTK_CONTAINER(self->notebookWgt), 5); - // mkdg_wgt_show(self->notebookWgt); - GtkWidget *dialogVboxWgt = gtk_dialog_get_content_area(GTK_DIALOG(self)); - // mkdg_wgt_show(dialogVboxWgt); - gtk_box_prepend(GTK_BOX(dialogVboxWgt), self->notebookWgt); - - self_prepare(self); - return self; - }} -#undef __GOB_FUNCTION__ - -/** - * maker_dialog_add_property: - * @self: A MakerDialog - * @ctx: A PropertyContext which contain the value to be set. - * @returns: TRUE if the property adding succeed; FALSE otherwise. - * - * Add a property to the dialog and corresponding Gtk widget will also be - * set. - **/ -gboolean -maker_dialog_add_property (MakerDialog * self, PropertyContext * ctx) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::add_property" - g_return_val_if_fail (self != NULL, (gboolean )0); - g_return_val_if_fail (MAKER_IS_DIALOG (self), (gboolean )0); -{ - - - if (ctx == NULL) { - return FALSE; - } - mkdg_log(INFO, "add_property(%s) %s", ctx->spec->key, - property_context_to_string(ctx)); - - /* Create the widget */ - MkdgWidget * mWidget = mkdg_widget_new(ctx, self->wFlags); - if (mWidget == NULL) - return FALSE; - - /* Find the container */ - const gchar *pageName = (STRING_IS_EMPTY(ctx->spec->pageName)) ? - MKDG_PAGE_NAME_DEFAULT : ctx->spec->pageName; - MkdgWidgetContainer *container = - MKDG_CONTAINER_TABLE_LOOKUP(self->_priv->containerTable, pageName); - - /* Do we need a new container/page? */ - if (container == NULL) { - MkdgWgt * vboxWgt = gtk_box_new(GTK_ORIENTATION_VERTICAL, MKDG_VBOX_SPACING_DEFAULT); - // gtk_container_set_border_width(GTK_CONTAINER (vboxWgt), 10); - // mkdg_wgt_show(vboxWgt); - container = mkdg_widget_container_new(vboxWgt); - g_hash_table_insert(self->_priv->containerTable, (gpointer) pageName, - (gpointer) container); - - /* new notebook page */ - MkdgWgt * pageLabelWgt = gtk_label_new(_(pageName)); - // mkdg_wgt_show(pageLabelWgt); - gtk_notebook_append_page(GTK_NOTEBOOK(self->notebookWgt), vboxWgt, - pageLabelWgt); - } - - /* Add the widget to container */ - mkdg_widget_container_add_widget(container, mWidget); - g_hash_table_insert(self->_priv->widgetTable, (gpointer) ctx->spec->key, - (gpointer) mWidget); - return TRUE; - }} -#undef __GOB_FUNCTION__ - -/** - * maker_dialog_add_all_properties: - * @self: A MakerDialog - * @returns: TRUE if all properties added successfully; FALSE otherwise. - * - * Add all properties to the dialog and corresponding Gtk widget will also be - * set. - * - **/ -gboolean -maker_dialog_add_all_properties (MakerDialog * self) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::add_all_properties" - g_return_val_if_fail (self != NULL, (gboolean )0); - g_return_val_if_fail (MAKER_IS_DIALOG (self), (gboolean )0); -{ - - gint i; - gboolean result = TRUE; - for(i = 0; i < mkdg_properties_size(self->_priv->properties); i++) { - PropertyContext * ctx = mkdg_properties_index(self->_priv->properties, i); - GValue * ret = property_context_load(ctx, NULL); - if (ret == NULL) - result = FALSE; - self_add_property(self, ctx); - } - return result; - }} -#undef __GOB_FUNCTION__ - -/** - * maker_dialog_prepare: - * @returns: TRUE if success; FALSE otherwise. - * - * Prepare the MakerDialog after new. This includes add_all_properties. - **/ -gboolean -maker_dialog_prepare (MakerDialog * self) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::prepare" - g_return_val_if_fail (self != NULL, (gboolean )0); - g_return_val_if_fail (MAKER_IS_DIALOG (self), (gboolean )0); -{ - - gboolean success; - success = self_add_all_properties(self); - if (!success) { - return FALSE; - } - - GList * containerList = g_hash_table_get_values(self->_priv->containerTable); - GList * node; - for(node = g_list_first(containerList); node != NULL; node = g_list_next(node)) { - MkdgWidgetContainer *container = (MkdgWidgetContainer *) node->data; - mkdg_widget_container_align_all_children(container, 1.0f, 0.5f, 0.0f, 0.5f); - } - g_list_free(containerList); - return TRUE; - }} -#undef __GOB_FUNCTION__ - -/** - * maker_dialog_assign_widget_value: - * @self: A MakerDialog. - * @ctx: The PropertyContext - * @userData: userData that pass through applyFunc. - * - * Assign the value shown in widget to the property. - * That is firstly save the value, then apply the value. - * - * @see_also: set_widget_value() - **/ -void -maker_dialog_assign_widget_value (MakerDialog * self, PropertyContext * ctx, gpointer userData) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::assign_widget_value" - g_return_if_fail (self != NULL); - g_return_if_fail (MAKER_IS_DIALOG (self)); -{ - - mkdg_log(INFO, "assign_widget_value(%s)", ctx->spec->key); - GValue gValue = { 0 }; - mkdg_g_value_reset(&gValue, ctx->spec->valueType, TRUE); - self_get_widget_value(self, ctx->spec->key, &gValue); - property_context_save(ctx, &gValue, userData); - property_context_apply(ctx, userData); - g_value_unset(&gValue); - }} -#undef __GOB_FUNCTION__ - -/** - * maker_dialog_assign_all_widgets_values: - * @self: A MakerDialog. - * @userData: userData that pass through applyFunc. - * - * Invoke assign_widget_value for all widgets. - * - * @see_also: assign_widget_value(), set_widget_value() - **/ -void -maker_dialog_assign_all_widgets_values (MakerDialog * self, gpointer userData) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::assign_all_widgets_values" - g_return_if_fail (self != NULL); - g_return_if_fail (MAKER_IS_DIALOG (self)); -{ - - gint i; - for (i = 0; i < mkdg_properties_size(self->_priv->properties); i++) { - PropertyContext *ctx = mkdg_properties_index(self->_priv->properties, i); - self_assign_widget_value(self, ctx, userData); - } - }} -#undef __GOB_FUNCTION__ - -/** - * maker_dialog_save_all_widgets_values: - * @self: A MakerDialog. - * @userData: userData that pass through property_context_save. - * - * Save all widget values to configuration backend. - * - **/ -void -maker_dialog_save_all_widgets_values (MakerDialog * self, gpointer userData) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::save_all_widgets_values" - g_return_if_fail (self != NULL); - g_return_if_fail (MAKER_IS_DIALOG (self)); -{ - - gint i; - for (i = 0; i < mkdg_properties_size(self->_priv->properties); i++) { - PropertyContext *ctx = mkdg_properties_index(self->_priv->properties,i); - GValue gValue= { 0 }; - mkdg_g_value_reset(&gValue, ctx->spec->valueType, TRUE); - self_get_widget_value(self, ctx->spec->key, &gValue); - property_context_save(ctx, &gValue, userData); - g_value_reset(&gValue); - } - }} -#undef __GOB_FUNCTION__ - -/** - * maker_dialog_get_widget_value: - * @self: A MakerDialog. - * @key: The key of a property. - * @value: GValue that store output. - * @returns: The address of value if success, NULL if failed. - * - * Get value as display in widget. - **/ -GValue * -maker_dialog_get_widget_value (MakerDialog * self, const gchar * key, GValue * value) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::get_widget_value" - g_return_val_if_fail (self != NULL, (GValue * )0); - g_return_val_if_fail (MAKER_IS_DIALOG (self), (GValue * )0); -{ - - mkdg_log(INFO, "get_widget_value(%s)", key); - MkdgWidget * mWidget = self_get_widget_by_key(self, key); - if (mWidget == NULL) { - /* Not fount */ - return NULL; - } - return mkdg_widget_get_widget_value(mWidget, value); - }} -#undef __GOB_FUNCTION__ - -/** - * maker_dialog_set_widget_value: - * @self: A MakerDialog. - * @key: The key of a property. - * @value: Value to be shown in widget. - * - * Set value for widget display. - * However, value in PropertyContext is not changed. - * Use assign_widget_value() to do it. - * @see_also: assign_widget_value() - **/ -void -maker_dialog_set_widget_value (MakerDialog * self, const gchar * key, GValue * value) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::set_widget_value" - g_return_if_fail (self != NULL); - g_return_if_fail (MAKER_IS_DIALOG (self)); -{ - - mkdg_log(INFO, "set_widget_value(%s, %s)", key, mkdg_g_value_to_string(value)); - MkdgWidget * mWidget = self_get_widget_by_key(self, key); - mkdg_widget_set_widget_value(mWidget, value); - }} -#undef __GOB_FUNCTION__ - -// /** -// * maker_dialog_show: -// * @self: A MakerDialog. -// * -// **/ -// void -// maker_dialog_show (MakerDialog * self) -// { -// #define __GOB_FUNCTION__ "Maker:Dialog::show" -// g_return_if_fail (self != NULL); -// g_return_if_fail (MAKER_IS_DIALOG (self)); -// { - -// mkdg_wgt_show_all(GTK_WIDGET(self)); -// }} -// #undef __GOB_FUNCTION__ - -MkdgWidget * -maker_dialog_get_widget_by_key (MakerDialog * self, const gchar * key) -{ -#define __GOB_FUNCTION__ "Maker:Dialog::get_widget_by_key" - g_return_val_if_fail (self != NULL, (MkdgWidget * )0); - g_return_val_if_fail (MAKER_IS_DIALOG (self), (MkdgWidget * )0); -{ - - return (MkdgWidget *) g_hash_table_lookup(self->_priv->widgetTable, key); - }} -#undef __GOB_FUNCTION__ diff --git a/src/maker-dialog.h b/src/maker-dialog.h deleted file mode 100644 index 2c94d0a..0000000 --- a/src/maker-dialog.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright © 2009 Red Hat, Inc. All rights reserved. - * Copyright © 2009 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -#include -#include - - -#ifndef MAKER_DIALOG_H_ -#define MAKER_DIALOG_H_ -#include -#include -#include -#include -#include -#include -#include "MakerDialogProperty.h" -#include "MakerDialogWidget.h" - - - -#define MKDG_PAGE_NAME_DEFAULT "..." -#ifndef WIDGET_ID_PREFIX -#define WIDGET_ID_PREFIX "+" -#endif - -#ifndef MAKER_DIALOG_ID_LENGTH -#define MAKER_DIALOG_ID_LENGTH 200 -#endif - -#define MKDG_CONTAINER_TABLE_LOOKUP(table,key) (MkdgWidgetContainer *) g_hash_table_lookup(table, (gconstpointer) key) - - - -#endif /* MAKER_DIALOG_H_ */ - -#ifndef __MAKER_DIALOG_H__ -#define __MAKER_DIALOG_H__ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -/* - * Type checking and casting macros - */ -#define MAKER_TYPE_DIALOG (maker_dialog_get_type()) -#define MAKER_DIALOG(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), maker_dialog_get_type(), MakerDialog) -#define MAKER_DIALOG_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), maker_dialog_get_type(), MakerDialog const) -#define MAKER_DIALOG_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), maker_dialog_get_type(), MakerDialogClass) -#define MAKER_IS_DIALOG(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), maker_dialog_get_type ()) - -#define MAKER_DIALOG_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), maker_dialog_get_type(), MakerDialogClass) - -/* Private structure type */ -typedef struct _MakerDialogPrivate MakerDialogPrivate; - -/* - * Main object structure - */ -#ifndef __TYPEDEF_MAKER_DIALOG__ -#define __TYPEDEF_MAKER_DIALOG__ -typedef struct _MakerDialog MakerDialog; -#endif -struct _MakerDialog { - GtkDialog __parent__; - /*< private >*/ - MkdgWgt * notebookWgt; /* protected */ - MkdgWidgetFlag wFlags; /* protected */ - MakerDialogPrivate *_priv; -}; - -/* - * Class definition - */ -typedef struct _MakerDialogClass MakerDialogClass; -struct _MakerDialogClass { - GtkDialogClass __parent__; -}; - - -/* - * Public methods - */ -GType maker_dialog_get_type (void) G_GNUC_CONST; -MakerDialog * maker_dialog_new (void); -MakerDialog * maker_dialog_new_full (MkdgProperties * properties, - const gchar * title, - MkdgWidgetFlag wFlags, - MkdgButtonFlag bFlags); -gboolean maker_dialog_add_property (MakerDialog * self, - PropertyContext * ctx); -gboolean maker_dialog_add_all_properties (MakerDialog * self); -void maker_dialog_assign_widget_value (MakerDialog * self, - PropertyContext * ctx, - gpointer userData); -void maker_dialog_assign_all_widgets_values (MakerDialog * self, - gpointer userData); -void maker_dialog_save_all_widgets_values (MakerDialog * self, - gpointer userData); -GValue * maker_dialog_get_widget_value (MakerDialog * self, - const gchar * key, - GValue * value); -void maker_dialog_set_widget_value (MakerDialog * self, - const gchar * key, - GValue * value); -void maker_dialog_show (MakerDialog * self); -MkdgWidget * maker_dialog_get_widget_by_key (MakerDialog * self, - const gchar * key); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/src/setup/ibus-setup-chewing-application.c b/src/setup/ibus-setup-chewing-application.c new file mode 100644 index 0000000..4eb837a --- /dev/null +++ b/src/setup/ibus-setup-chewing-application.c @@ -0,0 +1,81 @@ +/* ibus-setup-chewing-application.c + * + * Copyright 2024 Kan-Ru Chen + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "ibus-setup-chewing-application.h" +#include "ibus-setup-chewing-window.h" + +struct _IbusSetupChewingApplication { + AdwApplication parent_instance; +}; + +G_DEFINE_TYPE(IbusSetupChewingApplication, ibus_setup_chewing_application, + ADW_TYPE_APPLICATION) + +IbusSetupChewingApplication * +ibus_setup_chewing_application_new(const char *application_id, + GApplicationFlags flags) { + g_return_val_if_fail(application_id != NULL, NULL); + + return g_object_new(IBUS_SETUP_CHEWING_TYPE_APPLICATION, "application-id", + application_id, "flags", flags, NULL); +} + +static void ibus_setup_chewing_application_activate(GApplication *app) { + GtkWindow *window; + + g_assert(IBUS_SETUP_CHEWING_IS_APPLICATION(app)); + + window = gtk_application_get_active_window(GTK_APPLICATION(app)); + + if (window == NULL) + window = g_object_new(IBUS_SETUP_CHEWING_TYPE_WINDOW, "application", + app, NULL); + + gtk_window_present(window); +} + +static void ibus_setup_chewing_application_class_init( + IbusSetupChewingApplicationClass *klass) { + GApplicationClass *app_class = G_APPLICATION_CLASS(klass); + + app_class->activate = ibus_setup_chewing_application_activate; +} + +static void ibus_setup_chewing_application_quit_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + IbusSetupChewingApplication *self = user_data; + + g_assert(IBUS_SETUP_CHEWING_IS_APPLICATION(self)); + + g_application_quit(G_APPLICATION(self)); +} + +static const GActionEntry app_actions[] = { + {"quit", ibus_setup_chewing_application_quit_action}, +}; + +static void +ibus_setup_chewing_application_init(IbusSetupChewingApplication *self) { + g_action_map_add_action_entries(G_ACTION_MAP(self), app_actions, + G_N_ELEMENTS(app_actions), self); + gtk_application_set_accels_for_action(GTK_APPLICATION(self), "app.quit", + (const char *[]){"q", NULL}); +} diff --git a/src/setup/ibus-setup-chewing-application.h b/src/setup/ibus-setup-chewing-application.h new file mode 100644 index 0000000..0f37b4e --- /dev/null +++ b/src/setup/ibus-setup-chewing-application.h @@ -0,0 +1,38 @@ +/* ibus-setup-chewing-application.h + * + * Copyright 2024 Kan-Ru Chen + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define IBUS_SETUP_CHEWING_TYPE_APPLICATION \ + (ibus_setup_chewing_application_get_type()) + +G_DECLARE_FINAL_TYPE(IbusSetupChewingApplication, + ibus_setup_chewing_application, IBUS_SETUP_CHEWING, + APPLICATION, AdwApplication) + +IbusSetupChewingApplication * +ibus_setup_chewing_application_new(const char *application_id, + GApplicationFlags flags); + +G_END_DECLS diff --git a/src/setup/ibus-setup-chewing-window.c b/src/setup/ibus-setup-chewing-window.c new file mode 100644 index 0000000..ba2769a --- /dev/null +++ b/src/setup/ibus-setup-chewing-window.c @@ -0,0 +1,192 @@ +/* ibus-setup-chewing-window.c + * + * Copyright 2024 Kan-Ru Chen + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "ibus-setup-chewing-window.h" + +struct _IbusSetupChewingWindow { + AdwPreferencesWindow parent_instance; + + /* Template widgets */ + AdwComboRow *kb_type; + AdwComboRow *sel_keys; + AdwSwitchRow *plain_zhuyin; + AdwSwitchRow *show_systray; + AdwSwitchRow *auto_shift_cur; + AdwSwitchRow *add_phrase_direction; + AdwSwitchRow *clean_buffer_focus_out; + AdwSwitchRow *easy_symbol_input; + AdwSwitchRow *esc_clean_all_buf; + AdwSpinRow *max_chi_symbol_len; + AdwComboRow *chi_eng_mode_toggle; + AdwComboRow *sync_caps_lock; + AdwComboRow *default_english_case; + AdwSpinRow *cand_per_page; + AdwSwitchRow *show_page_number; + AdwSwitchRow *phrase_choice_from_last; + AdwSwitchRow *space_as_selection; + AdwSwitchRow *vertical_lookup_table; +}; + +G_DEFINE_FINAL_TYPE(IbusSetupChewingWindow, ibus_setup_chewing_window, + ADW_TYPE_PREFERENCES_WINDOW) + +#define bind_child(child_id) \ + gtk_widget_class_bind_template_child(widget_class, IbusSetupChewingWindow, \ + child_id) + +static void +ibus_setup_chewing_window_class_init(IbusSetupChewingWindowClass *klass) { + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + + gtk_widget_class_set_template_from_resource( + widget_class, + "/org/freedesktop/IBus/Chewing/Setup/ibus-setup-chewing-window.ui"); + + bind_child(kb_type); + bind_child(sel_keys); + bind_child(plain_zhuyin); + bind_child(show_systray); + bind_child(auto_shift_cur); + bind_child(add_phrase_direction); + bind_child(clean_buffer_focus_out); + bind_child(easy_symbol_input); + bind_child(esc_clean_all_buf); + bind_child(max_chi_symbol_len); + bind_child(chi_eng_mode_toggle); + bind_child(sync_caps_lock); + bind_child(default_english_case); + bind_child(cand_per_page); + bind_child(show_page_number); + bind_child(phrase_choice_from_last); + bind_child(space_as_selection); + bind_child(vertical_lookup_table); +} + +const gchar *kb_type_ids[] = { + "default", "hsu", "ibm", "gin_yieh", "eten", + "eten26", "dvorak", "dvorak_hsu", "dachen_26", "hanyu", + "thl_pinying", "mps2_pinyin", NULL}; + +const gchar *sel_key_ids[] = { + "1234567890", "asdfghjkl;", "asdfzxcv89", + "asdfjkl789", "aoeu;qjkix", /* Dvorak */ + "aoeuhtnsid", /* Dvorak */ + "aoeuidhtns", /* Dvorak */ + "1234qweras", NULL, +}; + +const gchar *chi_eng_mode_toggle_ids[] = { + "caps_lock", "shift", "shift_l", "shift_r", NULL, +}; + +const gchar *sync_caps_lock_ids[] = { + "disable", + "keyboard", + "input method", + NULL, +}; + +const gchar *default_english_case_ids[] = { + "no default", + "lowercase", + "uppercase", + NULL, +}; + +static gboolean id_get_mapping(GValue *value, GVariant *variant, + gpointer user_data) { + const gchar *saved; + gchar **ids_list = (gchar **)user_data; + + g_return_val_if_fail(g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING), + FALSE); + + saved = g_variant_get_string(variant, NULL); + for (int i = 0; ids_list[i] != NULL; i++) { + if (!g_strcmp0(ids_list[i], saved)) { + g_value_set_uint(value, i); + return TRUE; + } + } + return FALSE; +} + +static GVariant *id_set_mapping(const GValue *value, + const GVariantType *expected_type, + gpointer user_data) { + gchar **ids_list = (gchar **)user_data; + return g_variant_new_string(ids_list[g_value_get_uint(value)]); +} + +static void ibus_setup_chewing_window_init(IbusSetupChewingWindow *self) { + GSettings *settings; + + gtk_widget_init_template(GTK_WIDGET(self)); + + settings = g_settings_new("org.freedesktop.IBus.Chewing"); + + g_settings_bind_with_mapping(settings, "kb-type", self->kb_type, "selected", + G_SETTINGS_BIND_DEFAULT, id_get_mapping, + id_set_mapping, kb_type_ids, NULL); + g_settings_bind_with_mapping(settings, "sel-keys", self->sel_keys, + "selected", G_SETTINGS_BIND_DEFAULT, + id_get_mapping, id_set_mapping, sel_key_ids, + NULL); + g_settings_bind(settings, "plain-zhuyin", self->plain_zhuyin, "active", + G_SETTINGS_BIND_INVERT_BOOLEAN); + g_settings_bind(settings, "auto-shift-cur", self->auto_shift_cur, "active", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "add-phrase-direction", + self->add_phrase_direction, "active", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "clean-buffer-focus-out", + self->clean_buffer_focus_out, "active", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "easy-symbol-input", self->easy_symbol_input, + "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "esc-clean-all-buf", self->esc_clean_all_buf, + "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "max-chi-symbol-len", self->max_chi_symbol_len, + "value", G_SETTINGS_BIND_DEFAULT); + g_settings_bind_with_mapping(settings, "chi-eng-mode-toggle", + self->chi_eng_mode_toggle, "selected", + G_SETTINGS_BIND_DEFAULT, id_get_mapping, + id_set_mapping, chi_eng_mode_toggle_ids, NULL); + g_settings_bind_with_mapping(settings, "sync-caps-lock", + self->sync_caps_lock, "selected", + G_SETTINGS_BIND_DEFAULT, id_get_mapping, + id_set_mapping, sync_caps_lock_ids, NULL); + g_settings_bind_with_mapping( + settings, "default-english-case", self->default_english_case, + "selected", G_SETTINGS_BIND_DEFAULT, id_get_mapping, id_set_mapping, + default_english_case_ids, NULL); + g_settings_bind(settings, "cand-per-page", self->cand_per_page, "value", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "show-page-number", self->show_page_number, + "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "phrase-choice-from-last", + self->phrase_choice_from_last, "active", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "space-as-selection", self->space_as_selection, + "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "vertical-lookup-table", + self->vertical_lookup_table, "active", + G_SETTINGS_BIND_DEFAULT); +} diff --git a/src/setup/ibus-setup-chewing-window.h b/src/setup/ibus-setup-chewing-window.h new file mode 100644 index 0000000..112a119 --- /dev/null +++ b/src/setup/ibus-setup-chewing-window.h @@ -0,0 +1,32 @@ +/* ibus-setup-chewing-window.h + * + * Copyright 2024 Kan-Ru Chen + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define IBUS_SETUP_CHEWING_TYPE_WINDOW (ibus_setup_chewing_window_get_type()) + +G_DECLARE_FINAL_TYPE(IbusSetupChewingWindow, ibus_setup_chewing_window, + IBUS_SETUP_CHEWING, WINDOW, AdwPreferencesWindow) + +G_END_DECLS diff --git a/src/setup/ibus-setup-chewing-window.ui b/src/setup/ibus-setup-chewing-window.ui new file mode 100644 index 0000000..dcb8881 --- /dev/null +++ b/src/setup/ibus-setup-chewing-window.ui @@ -0,0 +1,231 @@ + + + + + + + + \ No newline at end of file diff --git a/src/setup/ibus-setup-chewing.gresource.xml b/src/setup/ibus-setup-chewing.gresource.xml new file mode 100644 index 0000000..6aab55f --- /dev/null +++ b/src/setup/ibus-setup-chewing.gresource.xml @@ -0,0 +1,6 @@ + + + + ibus-setup-chewing-window.ui + + \ No newline at end of file diff --git a/src/setup/main.c b/src/setup/main.c new file mode 100644 index 0000000..aa4afb6 --- /dev/null +++ b/src/setup/main.c @@ -0,0 +1,38 @@ +/* main.c + * + * Copyright 2024 Kan-Ru Chen + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include + +#include "ibus-setup-chewing-application.h" + +int main(int argc, char *argv[]) { + g_autoptr(IbusSetupChewingApplication) app = NULL; + int ret; + + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + + app = ibus_setup_chewing_application_new( + "org.freedesktop.IBus.Chewing.Setup", G_APPLICATION_DEFAULT_FLAGS); + ret = g_application_run(G_APPLICATION(app), argc, argv); + + return ret; +} diff --git a/src/setup/org.freedesktop.IBus.Chewing.gschema.xml b/src/setup/org.freedesktop.IBus.Chewing.gschema.xml new file mode 100644 index 0000000..6c448d3 --- /dev/null +++ b/src/setup/org.freedesktop.IBus.Chewing.gschema.xml @@ -0,0 +1,137 @@ + + + + "default" + Keyboard Type + + Select Zhuyin keyboard layout + + + + "1234567890" + Selection keys + + Keys used to select candidate. For example "asdfghjkl;", press 'a' to select the 1st candidate, 's' for 2nd, and so on. + + + + true + Show systray icons + + On: Show Chinese/English and Full/Half shape status as a systray icon + Off: Do not show the status icon + + + + true + Auto move cursor + + Automatically move the cursor to the next character after selection + + + + true + Add phrase before the cursor + + Use Ctrl + Numbers (2-9) to add new phrase before the cursor + + + + false + Clean pre-edit buffer when focus out + + On: Clean pre-edit buffer when focus out to prevent program crash + Off: Keep what you already type for convenience + + + + true + Easy symbol input + + Press shift to input Chinese punctuation symbols + + + + false + Esc clean all buffer + + Escape key cleans the text in pre-edit-buffer + + + + 20 + Maximum Chinese characters + + Maximum Chinese characters in pre-edit buffer, not including inputing Zhuyin symbols. + + + + "caps_lock" + Chinese/Alphanumeric Mode Toggle Key + + + + + "lowercase" + Default English letter case +(Only effective when Caps Lock is the toggle key) + + no control: No default letter case. Not recommend if you use multiple keyboards or synergy + lowercase: Default to lowercase, press shift for uppercase. + uppercase: Default to uppercase, press shift for lowercase. + + + + "keyboard" + Sync between CapsLock and IM + + Occasionally, the CapsLock status does not match the IM, this option determines how these status be synchronized. Valid values: + "disable": Do nothing + "keyboard": IM status follows keyboard status + "IM": Keyboard status follows IM status + + + + false + Plain Zhuyin mode + + In plain Zhuyin mode, automatic candidate selection and related options are disabled or ignored. + + + + 5 + Candidate per page + + Number of candidate per page. + + + + false + Show page number + + Display the page number of the candidate list. + + + + true + Choose phrases from backward + + Open candidate list from the back of a phrase, without moving the cursor to the front. + + + + false + Space to select + + Press Space to select the candidate. + + + + false + Vertical Lookup Table + + Use vertical lookup table. + + + + diff --git a/test/IBusChewingPreEdit-test.c b/test/IBusChewingPreEdit-test.c index 5308f7f..6b79a1f 100644 --- a/test/IBusChewingPreEdit-test.c +++ b/test/IBusChewingPreEdit-test.c @@ -3,11 +3,7 @@ #include "IBusChewingPreEdit.h" #include "IBusChewingPreEdit-private.h" #include "IBusChewingUtil.h" -#ifdef USE_GSETTINGS -# include "GSettingsBackend.h" -#elif defined USE_GCONF2 -# include "GConf2Backend.h" -#endif +#include "GSettingsBackend.h" #include "MakerDialogUtil.h" #include "test-util.h" #define TEST_RUN_THIS(f) add_test_case("IBusChewingPreEdit", f) @@ -916,19 +912,9 @@ void test_keypad() gint main(gint argc, gchar ** argv) { g_test_init(&argc, &argv, NULL); -#ifdef USE_GSETTINGS MkdgBackend *backend = mkdg_g_settings_backend_new(QUOTE_ME(PROJECT_SCHEMA_ID), QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); -#elif defined USE_GCONF2 - MkdgBackend *backend = - gconf2_backend_new(QUOTE_ME(PROJECT_SCHEMA_BASE), NULL); -#else - MkdgBackend *backend = NULL; - - g_error("Flag GSETTINGS_SUPPORT or GCONF2_SUPPORT are required!"); - return 1; -#endif /* USE_GSETTINGS */ mkdg_log_set_level(DEBUG); self = ibus_chewing_pre_edit_new(backend); ibus_chewing_pre_edit_use_all_configure(self); diff --git a/test/MakerDialogBackend-test.c b/test/MakerDialogBackend-test.c index 3e6200d..425296c 100644 --- a/test/MakerDialogBackend-test.c +++ b/test/MakerDialogBackend-test.c @@ -6,11 +6,7 @@ #include "test-util.h" #include "MakerDialogUtil.h" #include "MakerDialogBackend.h" -#ifdef USE_GSETTINGS -# include "GSettingsBackend.h" -#elif defined USE_GCONF2 -# include "GConf2Backend.h" -#endif +#include "GSettingsBackend.h" #define TEST_RUN_THIS(f) add_test_case("MakerDialogBackend", f) #define COMMAND_BUFFER_SIZE 200 #define FILE_BUFFER_SIZE 1024 @@ -44,23 +40,16 @@ GValue *backend_command_get_key_value(const gchar * key, GValue * value) gchar cmdBuf[COMMAND_BUFFER_SIZE]; gchar *cKey = mkdg_backend_get_key(backend, NULL, key, NULL); -#ifdef USE_GSETTINGS g_snprintf(cmdBuf, COMMAND_BUFFER_SIZE, "gsettings get %s %s", QUOTE_ME(PROJECT_SCHEMA_ID), cKey); -#else - g_snprintf(cmdBuf, COMMAND_BUFFER_SIZE, "gconftool-2 --get %s/%s", - QUOTE_ME(PROJECT_GCONF2_SCHEMA_DIR), cKey); -#endif gchar *retStr = command_run_obtain_output(cmdBuf); -#ifdef USE_GSETTINGS /* gsettings prepend 'uint32 ' before actual value */ if (G_VALUE_TYPE(value) == G_TYPE_UINT) { gint offset = strlen("uint32 "); retStr += offset; } -#endif mkdg_g_value_from_string(value, retStr); return value; } @@ -75,38 +64,9 @@ void backend_command_set_key_value(const gchar * key, GValue * value) gchar cmdBuf[COMMAND_BUFFER_SIZE]; gchar *cKey = mkdg_backend_get_key(backend, NULL, key, NULL); -#ifdef USE_GSETTINGS g_snprintf(cmdBuf, COMMAND_BUFFER_SIZE, "gsettings set %s %s %s", QUOTE_ME(PROJECT_SCHEMA_ID), cKey, valueStr); -#else - gchar *typeStr; - GType gType = G_VALUE_TYPE(value); - - switch (gType) { - case G_TYPE_BOOLEAN: - typeStr = "bool"; - break; - case G_TYPE_FLOAT: - case G_TYPE_DOUBLE: - typeStr = "float"; - break; - case G_TYPE_INT: - case G_TYPE_UINT: - case G_TYPE_LONG: - case G_TYPE_ULONG: - case G_TYPE_INT64: - case G_TYPE_UINT64: - typeStr = "int"; - break; - case G_TYPE_STRING: - typeStr = "string"; - break; - } - g_snprintf(cmdBuf, COMMAND_BUFFER_SIZE, - "gconftool-2 --set %s/%s --type %s '%s'", - QUOTE_ME(PROJECT_SCHEMA_DIR), cKey, typeStr, valueStr); -#endif command_run_obtain_output(cmdBuf); } @@ -248,15 +208,8 @@ void int_w_test() gint main(gint argc, gchar ** argv) { g_test_init(&argc, &argv, NULL); -#ifdef USE_GSETTINGS backend = mkdg_g_settings_backend_new(QUOTE_ME(PROJECT_SCHEMA_ID), QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); -#elif defined USE_GCONF2 - backend = gconf2_backend_new(QUOTE_ME(PROJECT_SCHEMA_BASE), NULL); -#else - g_error("Flag GSETTINGS_SUPPORT or GCONF2_SUPPORT are required!"); - return 2; -#endif /* USE_GSETTINGS */ mkdg_log_set_level(DEBUG); TEST_RUN_THIS(mkdg_g_value_from_string_boolean_test); From 268da46b8c88862e6e5cc158fb5092568706c24d Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 4 Feb 2024 23:45:45 +0900 Subject: [PATCH 05/24] ci: run workflows in a fedora container --- .github/workflows/ci.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d125e6..6920636 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,12 +11,13 @@ on: jobs: build: runs-on: ubuntu-latest + container: fedora:latest steps: - uses: actions/checkout@v3 - name: Install build dependencies - run: sudo apt install -y libgtk-4-dev libibus-1.0-dev libadwaita-1-dev libx11-dev libchewing3-dev ibus gettext xvfb + run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libX11-devel libchewing-devel ibus gettext xorg-x11-server-Xvfb dbus-x11 util-linux - name: Build run: | @@ -26,20 +27,24 @@ jobs: - name: Test run: | + glib-compile-schemas src/setup --targetdir=out/build/default/bin xvfb-run -a ctest --test-dir out/build/default --output-on-failure --verbose coverage: runs-on: ubuntu-latest + container: fedora:latest steps: - uses: actions/checkout@v3 - name: Install build dependencies - run: sudo apt install -y libgtk-4-dev libibus-1.0-dev libadwaita-1-dev libx11-dev libchewing3-dev ibus gettext xvfb + run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libX11-devel libchewing-devel ibus gettext xorg-x11-server-Xvfb dbus-x11 util-linux - name: Install llvm run: | - sudo apt install -y llvm + sudo dnf -y install llvm rustup bzip2 + rustup-init -y + source "$HOME/.cargo/env" rustup component add llvm-tools - name: Setup grcov @@ -55,6 +60,7 @@ jobs: - name: Test run: | + glib-compile-schemas src/setup --targetdir=out/build/c99-coverage/bin xvfb-run -a ctest --test-dir out/build/c99-coverage --output-on-failure --verbose ./grcov . -s . -b . --keep-only 'src/*' --llvm -t lcov -o coverage.lcov From acf4c6aaea394d72532dbbc93caf50047aa308fd Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 4 Feb 2024 23:53:02 +0900 Subject: [PATCH 06/24] build: commit pot files --- .gitignore | 1 - po/ibus-setup-chewing.pot | 258 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 po/ibus-setup-chewing.pot diff --git a/.gitignore b/.gitignore index 03aa460..0ada99e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ *.o *.old *.orig -*.pot *.rej *.rpm *.so diff --git a/po/ibus-setup-chewing.pot b/po/ibus-setup-chewing.pot new file mode 100644 index 0000000..adc3b2a --- /dev/null +++ b/po/ibus-setup-chewing.pot @@ -0,0 +1,258 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the ibus-setup-chewing package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: ibus-setup-chewing\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-02-04 22:11+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: data/org.freedesktop.IBus.Chewing.Setup.desktop.in:3 +msgid "ibus-setup-chewing" +msgstr "" + +#: data/org.freedesktop.IBus.Chewing.Setup.metainfo.xml.in:7 +msgid "No description" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:13 +msgid "Configure the input method" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:14 +msgid "Input Method" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:20 +msgid "Standard" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:21 +msgid "Hsu" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:22 +msgid "IBM" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:23 +msgid "Gin-Yieh" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:24 +msgid "Eten" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:25 +msgid "Eten 26" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:26 +msgid "Dvorak" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:27 +msgid "Dvorak-Hsu" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:28 +msgid "DaChen 26" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:29 +msgid "Hanyu Pinyin" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:30 +msgid "THL Pinyin" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:31 +msgid "MPS2 Pinyin" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:35 +msgid "Keyboard Type" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:54 +msgid "Selection Keys" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:55 +msgid "Keys used to select candidate" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:61 +msgid "Intelligent Phrasing" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:62 +msgid "Enable or disable automatic candidate selection" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:67 +msgid "Show Systray Icon" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:68 +msgid "Whether to show the systray icon" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:69 +msgid "This feature is currently not implemented." +msgstr "" + +#: src/ibus-setup-chewing-window.ui:77 +msgid "Editing" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:78 +msgid "Configure the input method behavior" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:82 +msgid "Auto Move Cursor" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:83 +msgid "Automatically move the cursor to the next character after selection" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:89 +msgid "Add Phrase Before Cursor" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:90 +msgid "Use Ctrl + Numbers (2-9) to save new phrase before or after the cursor" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:96 +msgid "Clear Pre-Edit Buffer When Focus Out" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:102 +msgid "Easy Symbol Input" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:103 +msgid "Press Shift + keys to input Chinese punctuation symbols" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:108 +msgid "Esc Clean All Buffer" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:109 +msgid "Escape key discards all uncommitted texts" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:122 +msgid "Maximum Chinese Characters" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:123 +msgid "Until how many characters should trigger auto-commit" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:128 +msgid "Chinese/Alphanumeric Mode Toggle Key" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:132 +msgid "Caps Lock" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:133 +msgid "Shift" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:134 +msgid "Shift_L" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:135 +msgid "Shift_R" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:146 +msgid "Disable Syncing" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:147 +msgid "Sync with Keyboard State" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:148 +msgid "Sync with IM State" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:152 +msgid "Sync Caps Lock and IM" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:160 +msgid "No Default" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:161 +msgid "Lower Case" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:162 +msgid "Upper Case" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:166 +msgid "Default English Letter Case" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:167 +msgid "The letter case without pressing the Shift key" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:174 +msgid "Selecting" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:175 +msgid "Configure the candidate selection behavior" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:186 +msgid "Candidates Per Page" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:192 +msgid "Show Page Number" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:198 +msgid "Choose Phrases Backwards" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:199 +msgid "Open candidate list from the last character of a phrase" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:205 +msgid "Use Space Key as Selection Key" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:211 +msgid "Use Vertical Candidate Panel" +msgstr "" + +#: src/ibus-setup-chewing-window.ui:212 +msgid "Choose from vertical or horizontal panel" +msgstr "" From a14c7d18a041d2644d8150765e27bee35a4a7f08 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 00:40:11 +0900 Subject: [PATCH 07/24] ci: install git for codecov --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6920636..1ff964a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: - name: Install llvm run: | - sudo dnf -y install llvm rustup bzip2 + sudo dnf -y install llvm rustup bzip2 git rustup-init -y source "$HOME/.cargo/env" rustup component add llvm-tools From 62ea4d2e2bc0e87316027823c98c82fc7ebeaba9 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 00:50:12 +0900 Subject: [PATCH 08/24] ci: find llvm-tools --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ff964a..d15cfc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,7 @@ jobs: - name: Test run: | + source "$HOME/.cargo/env" glib-compile-schemas src/setup --targetdir=out/build/c99-coverage/bin xvfb-run -a ctest --test-dir out/build/c99-coverage --output-on-failure --verbose ./grcov . -s . -b . --keep-only 'src/*' --llvm -t lcov -o coverage.lcov From 496270e6cdf4d41e578ab24c8710671596e78838 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 08:20:19 +0900 Subject: [PATCH 09/24] ci: test ibus-setup-chewing --- src/setup/main.c | 3 +++ test/CMakeLists.txt | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/setup/main.c b/src/setup/main.c index aa4afb6..77ddb89 100644 --- a/src/setup/main.c +++ b/src/setup/main.c @@ -32,6 +32,9 @@ int main(int argc, char *argv[]) { app = ibus_setup_chewing_application_new( "org.freedesktop.IBus.Chewing.Setup", G_APPLICATION_DEFAULT_FLAGS); +#ifdef UNIT_TEST + g_idle_add(G_SOURCE_FUNC(g_application_quit), G_APPLICATION(app)); +#endif ret = g_application_run(G_APPLICATION(app), argc, argv); return ret; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ea2d3e8..5d29a9e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -52,4 +52,24 @@ target_link_libraries(ibus-chewing-engine-test gui-core) add_test(NAME ibus-chewing-engine COMMAND gtester ${CMAKE_CURRENT_BINARY_DIR}/ibus-chewing-engine-test) set_tests_properties(ibus-chewing-engine PROPERTIES - ENVIRONMENT "GSETTINGS_SCHEMA_DIR=${CMAKE_BINARY_DIR}/bin") \ No newline at end of file + ENVIRONMENT "GSETTINGS_SCHEMA_DIR=${CMAKE_BINARY_DIR}/bin") + +# ================== +add_executable(ibus-setup-chewing-test + ../src/setup/ibus-setup-chewing-application.c + ../src/setup/ibus-setup-chewing-application.h + ../src/setup/ibus-setup-chewing-window.c + ../src/setup/ibus-setup-chewing-window.h + ../src/setup/main.c + ${CMAKE_CURRENT_BINARY_DIR}/../bin/ibus-setup-chewing-window-ui.c +) +target_compile_definitions(ibus-setup-chewing-test PRIVATE + GETTEXT_PACKAGE="ibus-setup-chewing" + LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}" +) +target_include_directories(ibus-setup-chewing-test PRIVATE ../src/setup) +target_link_libraries(ibus-setup-chewing-test PkgConfig::LIBADWAITA) +add_test(NAME ibus-setup-chewing + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ibus-setup-chewing-test) +set_tests_properties(ibus-setup-chewing PROPERTIES + ENVIRONMENT "GSETTINGS_SCHEMA_DIR=${CMAKE_BINARY_DIR}/bin") From 0141cd44f7339d1e26ca54955e3a212f1863861a Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 08:55:47 +0900 Subject: [PATCH 10/24] ci: test ibus-setup-chewing quite action --- src/setup/main.c | 31 ++++++++++++++++++++++++++++--- test/CMakeLists.txt | 16 +--------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/setup/main.c b/src/setup/main.c index 77ddb89..3599dea 100644 --- a/src/setup/main.c +++ b/src/setup/main.c @@ -22,19 +22,44 @@ #include "ibus-setup-chewing-application.h" +static gboolean quit = FALSE; + +static GOptionEntry entries[] = { + {"quit", 'q', 0, G_OPTION_ARG_NONE, &quit, + "Cause the application to quit immediately after launch", NULL}, + G_OPTION_ENTRY_NULL}; + +static void application_quit(gpointer user_data) { + IbusSetupChewingApplication *self = user_data; + GAction *quit_action; + + quit_action = g_action_map_lookup_action(G_ACTION_MAP(self), "quit"); + g_action_activate(G_ACTION(quit_action), NULL); +} + int main(int argc, char *argv[]) { + GError *error = NULL; + GOptionContext *context; g_autoptr(IbusSetupChewingApplication) app = NULL; int ret; + context = g_option_context_new("- chewing settings"); + g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); + + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_print("option parsing failed: %s\n", error->message); + exit(1); + } + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); app = ibus_setup_chewing_application_new( "org.freedesktop.IBus.Chewing.Setup", G_APPLICATION_DEFAULT_FLAGS); -#ifdef UNIT_TEST - g_idle_add(G_SOURCE_FUNC(g_application_quit), G_APPLICATION(app)); -#endif + if (quit) { + g_idle_add(G_SOURCE_FUNC(application_quit), app); + } ret = g_application_run(G_APPLICATION(app), argc, argv); return ret; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5d29a9e..93b1c52 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -55,21 +55,7 @@ set_tests_properties(ibus-chewing-engine PROPERTIES ENVIRONMENT "GSETTINGS_SCHEMA_DIR=${CMAKE_BINARY_DIR}/bin") # ================== -add_executable(ibus-setup-chewing-test - ../src/setup/ibus-setup-chewing-application.c - ../src/setup/ibus-setup-chewing-application.h - ../src/setup/ibus-setup-chewing-window.c - ../src/setup/ibus-setup-chewing-window.h - ../src/setup/main.c - ${CMAKE_CURRENT_BINARY_DIR}/../bin/ibus-setup-chewing-window-ui.c -) -target_compile_definitions(ibus-setup-chewing-test PRIVATE - GETTEXT_PACKAGE="ibus-setup-chewing" - LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}" -) -target_include_directories(ibus-setup-chewing-test PRIVATE ../src/setup) -target_link_libraries(ibus-setup-chewing-test PkgConfig::LIBADWAITA) add_test(NAME ibus-setup-chewing - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ibus-setup-chewing-test) + COMMAND ${CMAKE_BINARY_DIR}/bin/ibus-setup-chewing -q) set_tests_properties(ibus-setup-chewing PROPERTIES ENVIRONMENT "GSETTINGS_SCHEMA_DIR=${CMAKE_BINARY_DIR}/bin") From b49cc99ee39370705e8e8e94b14fcec61ddb3b57 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 18:05:04 +0900 Subject: [PATCH 11/24] build(coverage): make llvm profile file name unique --- CMakePresets.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakePresets.json b/CMakePresets.json index 83ef9ed..e0cffc1 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -23,6 +23,9 @@ "CMAKE_CXX_COMPILER": "/usr/bin/clang++", "CMAKE_BUILD_TYPE": "Debug", "CMAKE_C_FLAGS": "-fprofile-instr-generate -fcoverage-mapping" + }, + "environment": { + "LLVM_PROFILE_FILE": "default_%p_%m.profraw" } }, { From 0bc44f3d298612530721ced65a3ca3c2176b67fa Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 18:33:24 +0900 Subject: [PATCH 12/24] refactor: delete most unused code --- src/CMakeLists.txt | 2 - src/GSettingsBackend.c | 127 ------------------------------- src/GSettingsBackend.h | 10 --- src/IBusChewingProperties.c | 17 +---- src/IBusChewingProperties.h | 5 -- src/IBusChewingUtil.c | 49 +----------- src/IBusChewingUtil.h | 7 -- src/IBusConfigBackend.c | 145 ----------------------------------- src/IBusConfigBackend.h | 42 ----------- src/MakerDialogProperty.c | 89 ++-------------------- src/MakerDialogProperty.h | 6 -- src/MakerDialogUtil.c | 147 +----------------------------------- src/MakerDialogUtil.h | 25 ------ src/ibus-chewing-engine.c | 1 - test/MakerDialogUtil-test.c | 20 ----- 15 files changed, 11 insertions(+), 681 deletions(-) delete mode 100644 src/IBusConfigBackend.c delete mode 100644 src/IBusConfigBackend.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 74588e0..c29df19 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,14 +2,12 @@ add_library(common STATIC IBusChewingApplier.c IBusChewingProperties.c IBusChewingLookupTable.c - IBusConfigBackend.c MakerDialogBackend.c MakerDialogProperty.c MakerDialogUtil.c IBusChewingLookupTable.h IBusChewingProperties.h - IBusConfigBackend.h MakerDialogBackend.h MakerDialogProperty.h MakerDialogPropertySpec.h diff --git a/src/GSettingsBackend.c b/src/GSettingsBackend.c index 9e7129c..3976ee7 100644 --- a/src/GSettingsBackend.c +++ b/src/GSettingsBackend.c @@ -24,38 +24,6 @@ #include "MakerDialogUtil.h" #include "GSettingsBackend.h" -const gchar *mkdg_g_variant_type_string(GType gType) -{ - switch (gType) { - case G_TYPE_BOOLEAN: - return (const gchar *) G_VARIANT_TYPE_BOOLEAN; - case G_TYPE_UINT: - return (const gchar *) G_VARIANT_TYPE_UINT32; - case G_TYPE_UINT64: - return (const gchar *) G_VARIANT_TYPE_UINT64; - case G_TYPE_INT: - return (const gchar *) G_VARIANT_TYPE_INT32; - case G_TYPE_INT64: - return (const gchar *) G_VARIANT_TYPE_INT64; - case G_TYPE_STRING: - return (const gchar *) G_VARIANT_TYPE_STRING; - default: - break; - } - return NULL; -} - -gchar *mkdg_g_settings_attr_append(gchar * buf, gint bufferSize, - const gchar * attr, const gchar * value) -{ - if (STRING_IS_EMPTY(attr)) - return buf; - if (!STRING_IS_EMPTY(buf)) - g_strlcat(buf, " ", bufferSize); - - return buf; -} - gchar *mkdg_g_variant_to_string(GVariant * gVar) { static gchar result[MAKER_DIALOG_VALUE_LENGTH]; @@ -97,101 +65,6 @@ gchar *mkdg_g_variant_to_string(GVariant * gVar) #define KEY_BUFFER_SIZE 300 -/*=== Start Schema Writing ===*/ -gboolean mkdg_g_settings_write_schema_spec(FILE * file, MkdgPropertySpec * spec) -{ - if (spec->propertyFlags & MKDG_PROPERTY_FLAG_NO_BACKEND) { - return TRUE; - } - gchar attrBuf[KEY_BUFFER_SIZE]; - const gchar *typeString = mkdg_g_variant_type_string(spec->valueType); - - g_strlcpy(attrBuf, "", KEY_BUFFER_SIZE); - mkdg_xml_attr_append(attrBuf, KEY_BUFFER_SIZE, "name", spec->key); - mkdg_xml_attr_append(attrBuf, KEY_BUFFER_SIZE, "type", typeString); - mkdg_xml_tags_write(file, "key", - MKDG_XML_TAG_TYPE_BEGIN_ONLY, attrBuf, NULL); - /* tag default */ - g_strlcpy(attrBuf, "", KEY_BUFFER_SIZE); - if (spec->propertyFlags & MKDG_PROPERTY_FLAG_HAS_TRANSLATION) { - mkdg_xml_attr_append(attrBuf, KEY_BUFFER_SIZE, "l10n", "messages"); - if (!STRING_IS_EMPTY(spec->translationContext)) { - mkdg_xml_attr_append(attrBuf, KEY_BUFFER_SIZE, "context", - spec->translationContext); - } - } - - gchar *valueStr = NULL; - - switch (spec->valueType) { - case G_TYPE_BOOLEAN: - valueStr = - g_strdup_printf("%s", - (STRING_EQUALS(spec->defaultValue, "0")) ? - "false" : "true"); - break; - case G_TYPE_STRING: - valueStr = g_strdup_printf("\"%s\"", spec->defaultValue); - break; - default: - valueStr = g_strdup_printf("%s", spec->defaultValue); - break; - } - mkdg_xml_tags_write(file, "default", - MKDG_XML_TAG_TYPE_SHORT, attrBuf, valueStr); - g_free(valueStr); - mkdg_xml_tags_write(file, "summary", - MKDG_XML_TAG_TYPE_SHORT, NULL, spec->label); - mkdg_xml_tags_write(file, "description", - MKDG_XML_TAG_TYPE_LONG, NULL, spec->tooltip); - mkdg_xml_tags_write(file, "key", MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); - return TRUE; -} - -gboolean mkdg_g_settings_write_schema_from_spec_array(const gchar * - schemaId, - const gchar * - basePath, - FILE * file, - MkdgPropertySpec - specs[], - const gchar * - gettextDomain) -{ - mkdg_log(DEBUG, - "mkdg_g_settings_write_schema_from_spec_array(%s,%s,-,-,-,%s)", - schemaId, basePath, gettextDomain); - gchar attrBuf[KEY_BUFFER_SIZE]; - gchar path[KEY_BUFFER_SIZE]; - - g_snprintf(path, KEY_BUFFER_SIZE, "%s", basePath); - - /* Header */ - mkdg_xml_tags_write(file, "schemalist", - MKDG_XML_TAG_TYPE_BEGIN_ONLY, NULL, NULL); - g_strlcpy(attrBuf, "", KEY_BUFFER_SIZE); - mkdg_xml_attr_append(attrBuf, KEY_BUFFER_SIZE, "id", schemaId); - mkdg_xml_attr_append(attrBuf, KEY_BUFFER_SIZE, "path", path); - mkdg_xml_attr_append(attrBuf, KEY_BUFFER_SIZE, - "gettext-domain", gettextDomain); - mkdg_xml_tags_write(file, "schema", - MKDG_XML_TAG_TYPE_BEGIN_ONLY, attrBuf, NULL); - /* Body */ - gint i; - - for (i = 0; (&specs[i])->valueType != G_TYPE_INVALID; i++) { - mkdg_g_settings_write_schema_spec(file, &specs[i]); - } - - /* Footer */ - mkdg_xml_tags_write(file, "schema", MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); - mkdg_xml_tags_write(file, "schemalist", - MKDG_XML_TAG_TYPE_END_ONLY, NULL, NULL); - return TRUE; -} - -/*=== End Schema Writing ===*/ - GValue *mkdg_g_settings_read_value(GSettings * settings, GValue * value, const gchar * key) { diff --git a/src/GSettingsBackend.h b/src/GSettingsBackend.h index f3fe7fc..f8d725a 100644 --- a/src/GSettingsBackend.h +++ b/src/GSettingsBackend.h @@ -56,14 +56,4 @@ MkdgBackend *mkdg_g_settings_backend_new(const gchar * schemaId, const gchar * basePath, gpointer auxData); -gboolean mkdg_g_settings_write_schema_from_spec_array(const gchar * - schemaId, - const gchar * - basePath, - FILE * file, - MkdgPropertySpec - specs[], - const gchar * - gettextDomain); - #endif /* _MKDG_GSETTINGS_BACKEND_H_ */ diff --git a/src/IBusChewingProperties.c b/src/IBusChewingProperties.c index a37ba16..d2ce8ba 100644 --- a/src/IBusChewingProperties.c +++ b/src/IBusChewingProperties.c @@ -5,7 +5,6 @@ #include "MakerDialogProperty.h" #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" -#include "IBusConfigBackend.h" #include "GSettingsBackend.h" #define PAGE_EDITING N_("Editing") @@ -317,18 +316,4 @@ ibus_chewing_properties_read_boolean_general(IBusChewingProperties g_value_unset(&gValue); return result; -} - -gint -ibus_chewing_properties_read_int_general(IBusChewingProperties * self, - const gchar * section, - const gchar * key, gpointer userData) -{ - GValue gValue = { 0 }; - g_value_init(&gValue, G_TYPE_INT); - ibus_chewing_properties_read_general(self, &gValue, section, key, userData); - gint result = g_value_get_int(&gValue); - - g_value_unset(&gValue); - return result; -} +} \ No newline at end of file diff --git a/src/IBusChewingProperties.h b/src/IBusChewingProperties.h index a2a27ac..304d22c 100644 --- a/src/IBusChewingProperties.h +++ b/src/IBusChewingProperties.h @@ -30,11 +30,6 @@ gboolean ibus_chewing_properties_read_boolean_general(IBusChewingProperties const gchar * key, gpointer userData); -gint ibus_chewing_properties_read_int_general(IBusChewingProperties * self, - const gchar * section, - const gchar * key, - gpointer userData); - /*============================================ * Callback functions */ diff --git a/src/IBusChewingUtil.c b/src/IBusChewingUtil.c index 1533002..389e8ee 100644 --- a/src/IBusChewingUtil.c +++ b/src/IBusChewingUtil.c @@ -22,40 +22,6 @@ const gchar *toneKeys[] = { NULL }; -gint get_tone(ChewingKbType kbType, KSym kSym) -{ - int i = 0; - - if (kSym == ' ') - return 1; - for (i = 0; i < 4; i++) { - if (toneKeys[kbType][i] == kSym) { - return i + 2; - } - } - return -1; -} - -void add_tone(char *str, gint tone) -{ - switch (tone) { - case 2: - g_strlcat(str, "ˊ", ZHUYIN_BUFFER_SIZE); - break; - case 3: - g_strlcat(str, "ˇ", ZHUYIN_BUFFER_SIZE); - break; - case 4: - g_strlcat(str, "ˋ", ZHUYIN_BUFFER_SIZE); - break; - case 5: - g_strlcat(str, "˙", ZHUYIN_BUFFER_SIZE); - break; - default: - break; - } -} - /*===================================== * Key */ @@ -314,17 +280,4 @@ const gchar *modifiers_to_string(guint modifier) } } return modifierBuf; -} - -/*===================================== - * Misc - */ - -gboolean ibus_chewing_property_get_state(IBusProperty * prop) -{ -#if IBUS_CHECK_VERSION(1, 4, 0) - return ibus_property_get_state(prop); -#else - return prop->state; -#endif -} +} \ No newline at end of file diff --git a/src/IBusChewingUtil.h b/src/IBusChewingUtil.h index 3835237..fae991e 100644 --- a/src/IBusChewingUtil.h +++ b/src/IBusChewingUtil.h @@ -66,11 +66,6 @@ typedef enum { # endif } ChewingKbType; - -gint get_tone(ChewingKbType kbType, KSym k); - -void add_tone(char *str, gint tone); - KSym key_sym_KP_to_normal(KSym k); const char *key_sym_get_name(KSym k); @@ -83,6 +78,4 @@ const gchar *modifier_get_string(guint modifier); const gchar *modifiers_to_string(guint modifier); -gboolean ibus_chewing_property_get_state(IBusProperty * prop); - #endif /* _IBUS_CHEWING_UTIL_H_ */ diff --git a/src/IBusConfigBackend.c b/src/IBusConfigBackend.c deleted file mode 100644 index 00c2e49..0000000 --- a/src/IBusConfigBackend.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright © 2014 Red Hat, Inc. All rights reserved. - * Copyright © 2014 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -#include -#include "MakerDialogUtil.h" -#include "GSettingsBackend.h" -#include "IBusChewingUtil.h" -#include "IBusConfigBackend.h" -#include "IBusChewingProperties.h" - -/*============================================ - * Class methods - */ - - -#define KEY_BUFFER_SIZE 100 -static gchar *to_real_section(gchar * confSection, MkdgBackend * backend, - const gchar * section) -{ - - if (!STRING_IS_EMPTY(backend->basePath)) { - g_strlcpy(confSection, backend->basePath, KEY_BUFFER_SIZE); - } else { - g_strlcpy(confSection, "", KEY_BUFFER_SIZE); - } - - if (!STRING_IS_EMPTY(section)) { - g_strlcat(confSection, section, KEY_BUFFER_SIZE); - g_strlcat(confSection, "/", KEY_BUFFER_SIZE); - } - return confSection; -} - -GValue *ibus_config_backend_read_value(MkdgBackend * backend, - GValue * value, - const gchar * section, - const gchar * key, gpointer userData) -{ - IBusConfig *config = (IBusConfig *) backend->config; - gchar confSection[KEY_BUFFER_SIZE]; - - to_real_section(confSection, backend, section); - printf("confSection=%s\n", confSection); -#if IBUS_CHECK_VERSION(1, 4, 0) - GVariant *gVar = ibus_config_get_value(config, confSection, - key); - - if (gVar == NULL) { - return NULL; - } - g_variant_ref_sink(gVar); - mkdg_g_variant_to_g_value(gVar, value); - g_variant_unref(gVar); - return value; -#else - return ibus_config_get_value(config, confSection, key, value); -#endif -} - - -gboolean ibus_config_backend_write_value(MkdgBackend * backend, - GValue * value, - const gchar * section, - const gchar * key, gpointer userData) -{ - gboolean result = FALSE; - IBusConfig *config = (IBusConfig *) backend->config; - gchar confSection[KEY_BUFFER_SIZE]; - - to_real_section(confSection, backend, section); -#if IBUS_CHECK_VERSION(1, 4, 0) - GVariant *gVar = g_variant_ref_sink(mkdg_g_value_to_g_variant(value)); - - if (gVar != NULL) { - result = ibus_config_set_value(config, confSection, key, gVar); - } -#else - result = ibus_config_set_value(config, confSection, key, value); -#endif - - if (result == FALSE) { - mkdg_log(WARN, - "ibus_config_backend_write_value(-, %s, -) %s %s", - key, "Failed to set variable", key); - return FALSE; - } - - if (!config) { - mkdg_log(WARN, - "ibus_config_backend_write_value(-, %s, -) %s", - key, "Failed to connect to IBusService"); - return FALSE; - } - return TRUE; -} - -/* - * basePath is shorter that other backend, as ibus-config should provide ibus level base - */ -MkdgBackend *ibus_config_backend_new(IBusService * service, - const gchar * basePath, gpointer auxData) -{ - IBusConfig *config = NULL; - -#if IBUS_CHECK_VERSION(1, 4, 0) - GError *error = NULL; - GDBusConnection *connection = ibus_service_get_connection(service); - - config = g_object_ref_sink(ibus_config_new(connection, NULL, &error)); - g_assert(error == NULL); -#else - GList *connections_list = ibus_service_get_connections(service); - - g_assert(connections_list); - g_assert(connections_list->data); - IBusConnection *iConnection = (IBusConnection *) connections_list->data; - - config = g_object_ref_sink(ibus_config_new(iConnection)); -#endif - MkdgBackend *result = - mkdg_backend_new(IBUS_CONFIG_BACKEND_ID, (gpointer) config, - basePath, auxData); - - result->readFunc = ibus_config_backend_read_value; - result->writeFunc = ibus_config_backend_write_value; - return result; -} diff --git a/src/IBusConfigBackend.h b/src/IBusConfigBackend.h deleted file mode 100644 index 50bb53a..0000000 --- a/src/IBusConfigBackend.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2014 Red Hat, Inc. All rights reserved. - * Copyright © 2014 Ding-Yi Chen - * - * This file is part of the ibus-chewing Project. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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. - */ - -/** - * SECTION:IBusConfigBackend - * @short_description: An IBus-Config Backend - * @title: IBusConfig Backend - * @stability: Stable - * @include: IBusConfigBackend.h - * - * A MakerDialog backend provides an interface to configuration service - * like GConf2 or dconf - */ - -#ifndef _IBUS_CONFIG_BACKEND_H_ -# define _IBUS_CONFIG_BACKEND_H_ -# include "ibus.h" -# include "MakerDialogBackend.h" -# define IBUS_CONFIG_BACKEND_ID "ibus_config" - -MkdgBackend *ibus_config_backend_new(IBusService * service, - const gchar * baseDir, gpointer auxData); - -#endif /* _IBUS_CONFIG_BACKEND_H_ */ diff --git a/src/MakerDialogProperty.c b/src/MakerDialogProperty.c index 58ea32c..b0760c7 100644 --- a/src/MakerDialogProperty.c +++ b/src/MakerDialogProperty.c @@ -7,6 +7,14 @@ * PropertyContext Methods */ +static gboolean property_context_from_string(PropertyContext * ctx, const gchar * str) +{ + if (ctx == NULL) { + return FALSE; + } + return mkdg_g_value_from_string(&(ctx->value), str); +} + void property_context_default(PropertyContext * ctx) { if (ctx->spec->defaultValue == NULL) @@ -49,34 +57,6 @@ PropertyContext *property_context_new(MkdgPropertySpec * spec, return ctx; } -gchar *property_context_to_string(PropertyContext * ctx) -{ - if (ctx == NULL) { - return NULL; - } - return mkdg_g_value_to_string(&(ctx->value)); -} - -gboolean property_context_from_string(PropertyContext * ctx, const gchar * str) -{ - if (ctx == NULL) { - return FALSE; - } - return mkdg_g_value_from_string(&(ctx->value), str); -} - -gboolean property_context_from_gvalue(PropertyContext * ctx, GValue * value) -{ - if (ctx == NULL) { - return FALSE; - } - if (!G_IS_VALUE(value)) { - return FALSE; - } - g_value_copy(value, &(ctx->value)); - return TRUE; -} - /* read: backend -> Context */ /* write: Context -> backend */ /* get: Context -> GValue */ @@ -402,59 +382,6 @@ gsize mkdg_properties_size(MkdgProperties * properties) return properties->contexts->len; } -/* For setup interface */ -gboolean mkdg_properties_load_all(MkdgProperties * properties, - gpointer userData) -{ - gsize i; - gboolean result = TRUE; - - for (i = 0; i < mkdg_properties_size(properties); i++) { - PropertyContext *ctx = mkdg_properties_index(properties, i); - GValue *value = property_context_load(ctx, userData); - - if (value == NULL) { - result = FALSE; - } - } - return result; -} - -gboolean mkdg_properties_write_all(MkdgProperties * properties, - gpointer userData) -{ - gsize i; - gboolean result = TRUE; - - for (i = 0; i < mkdg_properties_size(properties); i++) { - PropertyContext *ctx = mkdg_properties_index(properties, i); - gboolean ret = property_context_write(ctx, userData); - - if (!ret) { - result = FALSE; - } - } - return result; -} - -/* For actual runtime */ -gboolean mkdg_properties_apply_all(MkdgProperties * properties, - gpointer userData) -{ - gsize i; - gboolean result = TRUE; - - for (i = 0; i < mkdg_properties_size(properties); i++) { - PropertyContext *ctx = mkdg_properties_index(properties, i); - gboolean ret = property_context_apply(ctx, userData); - - if (!ret) { - result = FALSE; - } - } - return result; -} - gboolean mkdg_properties_use_all(MkdgProperties * properties, gpointer userData) { gsize i; diff --git a/src/MakerDialogProperty.h b/src/MakerDialogProperty.h index 82be5fe..20ed1c2 100644 --- a/src/MakerDialogProperty.h +++ b/src/MakerDialogProperty.h @@ -86,12 +86,6 @@ PropertyContext *property_context_new(MkdgPropertySpec * spec, */ void property_context_default(PropertyContext * ctx); -gchar *property_context_to_string(PropertyContext * ctx); - -gboolean property_context_from_string(PropertyContext * ctx, const gchar * str); - -gboolean property_context_from_gvalue(PropertyContext * ctx, GValue * value); - GValue *property_context_read(PropertyContext * ctx, gpointer userData); gboolean property_context_write(PropertyContext * ctx, gpointer userData); diff --git a/src/MakerDialogUtil.c b/src/MakerDialogUtil.c index 5f44399..fab211d 100644 --- a/src/MakerDialogUtil.c +++ b/src/MakerDialogUtil.c @@ -13,11 +13,6 @@ void mkdg_log_set_level(MkdgLogLevel level) debugLevel = level; } -void mkdg_log_set_domain(const gchar * domain) -{ - g_strlcpy(mkdgLogDomain, domain, MKDG_LOG_DOMAIN_LEN); -} - void mkdg_log_set_file(FILE * file) { logFile = file; @@ -245,144 +240,4 @@ GVariant *mkdg_g_value_to_g_variant(GValue * value) break; } return gVar; -} - -/*============================================ - * MKDG Str functions - */ - -gchar *mkdg_str_dash_to_camel(const gchar * argStr) -{ - GString *string = g_string_new(NULL); - gboolean upper = FALSE; - int i; - - for (i = 0; i < strlen(argStr); i++) { - if (upper) { - g_string_append_c(string, g_ascii_toupper(argStr[i])); - upper = FALSE; - } else { - switch (argStr[i]) { - case '-': - case '_': - upper = TRUE; - break; - default: - g_string_append_c(string, argStr[i]); - break; - } - - } - } - return g_string_free(string, FALSE); -} - -/*============================================ - * MKDG XML functions - */ - -#define INDENT_SPACES 4 - -static void mkdg_xml_append_indent_space(GString * strBuf, gint indentLevel) -{ - int i, indentLen = indentLevel * INDENT_SPACES; - - for (i = 0; i < indentLen; i++) { - g_string_append_c(strBuf, ' '); - } -} - -static GString *mkdg_xml_tags_to_string(const gchar * tagName, - MkdgXmlTagType type, - const gchar * attribute, - const gchar * value, gint indentLevel) -{ - GString *strBuf = g_string_new(NULL); - - mkdg_xml_append_indent_space(strBuf, indentLevel); - - if (type != MKDG_XML_TAG_TYPE_NO_TAG) { - g_string_append_printf(strBuf, "<%s%s%s%s%s>", - (type == - MKDG_XML_TAG_TYPE_END_ONLY) ? "/" : "", - (!STRING_IS_EMPTY(tagName)) ? tagName : "", - (!STRING_IS_EMPTY(attribute)) ? " " : "", - (!STRING_IS_EMPTY(attribute)) ? attribute : - "", - (type == MKDG_XML_TAG_TYPE_EMPTY) ? "/" : ""); - } - if (type == MKDG_XML_TAG_TYPE_EMPTY) - return strBuf; - if (type == MKDG_XML_TAG_TYPE_BEGIN_ONLY) - return strBuf; - if (type == MKDG_XML_TAG_TYPE_END_ONLY) - return strBuf; - - if (type == MKDG_XML_TAG_TYPE_LONG) { - g_string_append_c(strBuf, '\n'); - } - - if (value) { - if (type == MKDG_XML_TAG_TYPE_LONG || type == MKDG_XML_TAG_TYPE_NO_TAG) { - mkdg_xml_append_indent_space(strBuf, indentLevel + 1); - int i, valueLen = strlen(value); - - for (i = 0; i < valueLen; i++) { - g_string_append_c(strBuf, value[i]); - if (value[i] == '\n') { - mkdg_xml_append_indent_space(strBuf, indentLevel + 1); - } - } - g_string_append_c(strBuf, '\n'); - if (type == MKDG_XML_TAG_TYPE_LONG) { - mkdg_xml_append_indent_space(strBuf, indentLevel); - } - } else { - g_string_append(strBuf, value); - } - } - - if (type == MKDG_XML_TAG_TYPE_LONG || type == MKDG_XML_TAG_TYPE_SHORT) { - g_string_append_printf(strBuf, "", tagName); - } - return strBuf; -} - -gchar *mkdg_xml_attr_append(gchar * buf, gint bufferSize, - const gchar * attr, const gchar * value) -{ - if (STRING_IS_EMPTY(attr)) - return buf; - if (!STRING_IS_EMPTY(buf)) - g_strlcat(buf, " ", bufferSize); - - g_strlcat(buf, attr, bufferSize); - if (STRING_IS_EMPTY(value)) - return buf; - - g_strlcat(buf, "=\"", bufferSize); - g_strlcat(buf, value, bufferSize); - g_strlcat(buf, "\"", bufferSize); - return buf; -} - -gboolean mkdg_xml_tags_write(FILE * outF, const gchar * tagName, - MkdgXmlTagType type, const gchar * attribute, - const gchar * value) -{ - static int indentLevel = 0; - - if (type == MKDG_XML_TAG_TYPE_END_ONLY) - indentLevel--; - - GString *strBuf = mkdg_xml_tags_to_string(tagName, type, attribute, value, - indentLevel); - - mkdg_log(INFO, "xml_tags_write:%s", strBuf->str); - fprintf(outF, "%s\n", strBuf->str); - - if (type == MKDG_XML_TAG_TYPE_BEGIN_ONLY) - indentLevel++; - g_string_free(strBuf, TRUE); - return TRUE; -} +} \ No newline at end of file diff --git a/src/MakerDialogUtil.h b/src/MakerDialogUtil.h index 3e70e63..c4b3eba 100644 --- a/src/MakerDialogUtil.h +++ b/src/MakerDialogUtil.h @@ -58,8 +58,6 @@ typedef enum { void mkdg_log_set_level(MkdgLogLevel level); -void mkdg_log_set_domain(const gchar * domain); - void mkdg_log_set_file(FILE * file); void mkdg_log(MkdgLogLevel level, const gchar * format, ...); @@ -105,8 +103,6 @@ GVariant *mkdg_g_value_to_g_variant(GValue * value); ((str1!=NULL && str2!=NULL) && strcmp(str1, str2)==0) \ ) -gchar *mkdg_str_dash_to_camel(const gchar * argStr); - /************************************** * Flag Utility Macros */ @@ -114,26 +110,5 @@ gchar *mkdg_str_dash_to_camel(const gchar * argStr); # define mkdg_clear_flag(flagSet, flag) (flagSet &= ~(flag)) # define mkdg_has_flag(flagSet, flag) ((flagSet & flag) == flag) # define mkdg_set_flag(flagSet, flag) (flagSet |= flag) - -/************************************** - * XML data structure and functions - */ - -typedef enum { - MKDG_XML_TAG_TYPE_NO_TAG, - MKDG_XML_TAG_TYPE_EMPTY, - MKDG_XML_TAG_TYPE_SHORT, - MKDG_XML_TAG_TYPE_LONG, - MKDG_XML_TAG_TYPE_BEGIN_ONLY, - MKDG_XML_TAG_TYPE_END_ONLY, -} MkdgXmlTagType; - -gchar *mkdg_xml_attr_append(gchar * buf, gint bufferSize, - const gchar * attr, const gchar * value); - -gboolean mkdg_xml_tags_write(FILE * outF, const gchar * tagName, - MkdgXmlTagType type, const gchar * attribute, - const gchar * value); - # define MAKER_DIALOG_VALUE_LENGTH 200 #endif /* _MAKER_DIALOG_UTIL_H_ */ diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c index 8188fa8..cadd374 100644 --- a/src/ibus-chewing-engine.c +++ b/src/ibus-chewing-engine.c @@ -92,7 +92,6 @@ engine_flag_get_type (void) extern gint ibus_chewing_verbose; #define IBUS_CHEWING_MAIN -#include "IBusConfigBackend.h" /* self casting macros */ #define SELF(x) IBUS_CHEWING_ENGINE(x) diff --git a/test/MakerDialogUtil-test.c b/test/MakerDialogUtil-test.c index 1df7011..a8b5fb1 100644 --- a/test/MakerDialogUtil-test.c +++ b/test/MakerDialogUtil-test.c @@ -119,25 +119,6 @@ void STRING_EQUALS_test() g_assert(STRING_EQUALS("YO\"", "YO\"")); } -void mkdg_xml_attr_append_test() -{ -#define BUFFER_SIZE 200 - gchar buf[BUFFER_SIZE]; - - buf[0] = '\0'; - mkdg_xml_attr_append(buf, BUFFER_SIZE, "", NULL); - g_assert_cmpstr("", ==, buf); - - mkdg_xml_attr_append(buf, BUFFER_SIZE, "foo", NULL); - g_assert_cmpstr("foo", ==, buf); - - mkdg_xml_attr_append(buf, BUFFER_SIZE, "animal", "sheep"); - g_assert_cmpstr("foo animal=\"sheep\"", ==, buf); - - mkdg_xml_attr_append(buf, BUFFER_SIZE, "lang", "zh_TW"); - g_assert_cmpstr("foo animal=\"sheep\" lang=\"zh_TW\"", ==, buf); -} - gint main(gint argc, gchar ** argv) { @@ -149,6 +130,5 @@ gint main(gint argc, gchar ** argv) #if 0 TEST_RUN_THIS(STRING_EQUALS_test); #endif - TEST_RUN_THIS(mkdg_xml_attr_append_test); return g_test_run(); } From 4120639393fd6b3602bc74c0c0755a4ee41559c4 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 21:00:11 +0900 Subject: [PATCH 13/24] refactor: address deprecation warnings --- src/CMakeLists.txt | 2 - src/IBusChewingEngine-input-events.c | 114 ------ src/IBusChewingEngine-signal.c | 341 ----------------- src/MakerDialogProperty.c | 2 - src/ibus-chewing-engine.c | 534 ++++++++++++++++++++++++--- src/ibus-chewing-engine.h | 15 - test/CMakeLists.txt | 2 - test/ibus-chewing-engine-test.c | 2 +- 8 files changed, 489 insertions(+), 523 deletions(-) delete mode 100644 src/IBusChewingEngine-input-events.c delete mode 100644 src/IBusChewingEngine-signal.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c29df19..d955fe2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,8 +69,6 @@ target_link_libraries(ibus-setup-chewing PkgConfig::LIBADWAITA) add_executable(ibus-engine-chewing ibus-chewing-engine.c ibus-chewing-engine.h - IBusChewingEngine-signal.c - IBusChewingEngine-input-events.c IBusChewingLookupTable.c IBusChewingLookupTable.h IBusChewingPreEdit.c diff --git a/src/IBusChewingEngine-input-events.c b/src/IBusChewingEngine-input-events.c deleted file mode 100644 index b1526cf..0000000 --- a/src/IBusChewingEngine-input-events.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "ibus-chewing-engine-private.h" -#include "ibus-chewing-engine.h" -#include "IBusChewingProperties.h" - -gboolean ibus_chewing_engine_process_key_event(IBusEngine * engine, - KSym keySym, guint keycode, - KeyModifiers unmaskedMod) -{ - IBUS_CHEWING_LOG(MSG, "******** process_key_event(-,%x(%s),%x,%x) %s", - keySym, key_sym_get_name(keySym), keycode, - unmaskedMod, modifiers_to_string(unmaskedMod)); - - IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); - - if (unmaskedMod & IBUS_MOD4_MASK) - return FALSE; - - if (is_password(self)) - return FALSE; - - KSym kSym = - ibus_chewing_pre_edit_key_code_to_key_sym(self->icPreEdit, keySym, - keycode, - unmaskedMod); - - gboolean result = ibus_chewing_pre_edit_process_key(self->icPreEdit, kSym, - unmaskedMod); - - IBUS_CHEWING_LOG(MSG, "process_key_event() result=%d", result); - ibus_chewing_engine_update(self); - - if (kSym == IBUS_KEY_Shift_L || kSym == IBUS_KEY_Shift_R || - kSym == IBUS_KEY_Caps_Lock) { - /* Refresh property list (language bar) only when users toggle - * Chi-Eng Mode or Shape Mode with Shift or Caps Lock, otherwise - * the bar will stick to the cursor and block the candidats list. - */ - ibus_chewing_engine_refresh_property_list(self); - } - - return result; -} - -/*=================================================== - * Mouse events - */ -void ibus_chewing_engine_candidate_clicked(IBusEngine * engine, - guint index, guint button, - guint state) -{ - IBUS_CHEWING_LOG(INFO, - "*** candidate_clicked(-, %x, %x, %x) ... proceed.", - index, button, state); - IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); - - if (is_password(self)) - return; - if (index >= chewing_get_candPerPage(self->icPreEdit->context)) { - IBUS_CHEWING_LOG(DEBUG, "candidate_clicked() index out of ranged"); - return; - } - if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_TABLE_SHOW)) { - gint *selKeys = chewing_get_selKey(self->icPreEdit->context); - KSym k = (KSym) selKeys[index]; - - ibus_chewing_pre_edit_process_key(self->icPreEdit, k, 0); - g_free(selKeys); - ibus_chewing_engine_update(self); - } else { - IBUS_CHEWING_LOG(DEBUG, - "candidate_clicked() ... candidates are not showing"); - } -} - -void ibus_chewing_engine_property_activate(IBusEngine * engine, - const gchar * prop_name, - guint prop_state) -{ - IBUS_CHEWING_LOG(INFO, "property_activate(-, %s, %u)", prop_name, - prop_state); - IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); - - if (STRING_EQUALS(prop_name, "InputMode")) { - /* Toggle Chinese <-> English */ - ibus_chewing_pre_edit_toggle_chi_eng_mode(self->icPreEdit); - IBUS_CHEWING_LOG(INFO, - "property_activate chinese=%d caps_lock=%d", - ibus_chewing_engine_is_chinese_mode(self), - is_caps_lock(self)); - - if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM) - || ibus_chewing_pre_edit_has_flag(self->icPreEdit, - FLAG_SYNC_FROM_KEYBOARD)) { - if (ibus_chewing_engine_is_chinese_mode(self) == is_caps_lock(self)) { - set_caps_led(!ibus_chewing_engine_is_chinese_mode(self), - self->_priv->pDisplay); - } - } - ibus_chewing_engine_refresh_property(self, prop_name); - } else if (STRING_EQUALS(prop_name, "AlnumSize")) { - /* Toggle Full <-> Half */ - chewing_set_ShapeMode(self->icPreEdit->context, - !chewing_get_ShapeMode(self->icPreEdit->context)); - ibus_chewing_engine_refresh_property(self, prop_name); - } else if (STRING_EQUALS(prop_name, "setup_prop")) { - /* open preferences window */ - system(QUOTE_ME(LIBEXEC_DIR) "/ibus-setup-chewing"); - } else { - IBUS_CHEWING_LOG(DEBUG, - "property_activate(-, %s, %u) not recognized", - prop_name, prop_state); - } - -} diff --git a/src/IBusChewingEngine-signal.c b/src/IBusChewingEngine-signal.c deleted file mode 100644 index 5fe58e0..0000000 --- a/src/IBusChewingEngine-signal.c +++ /dev/null @@ -1,341 +0,0 @@ -#include "ibus-chewing-engine-private.h" -#include "ibus-chewing-engine.h" - -/** - * ibus_chewing_engine_start: - * @self: IBusChewingEngine instance. - * - * This is different with init. This will be called in the beginning of - * reset, enable, and focus_in for setup. - */ -void ibus_chewing_engine_start(IBusChewingEngine * self) -{ -#ifndef UNIT_TEST - if (!ibus_chewing_engine_has_status_flag - (self, ENGINE_FLAG_PROPERTIES_REGISTERED)) { - IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self), - "InputMode"); - IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self), - "AlnumSize"); - IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self), - "setup_prop"); - ibus_engine_register_properties(IBUS_ENGINE(self), self->prop_list); - ibus_chewing_engine_set_status_flag(self, - ENGINE_FLAG_PROPERTIES_REGISTERED); - } -#endif - ibus_chewing_engine_use_setting(self); - ibus_chewing_engine_restore_mode(self); - ibus_chewing_engine_refresh_property_list(self); - -} - -/** - * ibus_chewing_engine_reset: - * @self: IBusChewingEngine instance. - * - * Reset the outgoing and pre_edit buffer and cursor - * chewing_reset will NOT called here, as it will chnage the KBType and input mode. - */ -void ibus_chewing_engine_reset(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* reset"); - - /* Always clean buffer */ - ibus_chewing_pre_edit_clear(self->icPreEdit); -#ifndef UNIT_TEST - IBusEngine *engine = IBUS_ENGINE(self); - - ibus_engine_hide_auxiliary_text(engine); - ibus_engine_hide_lookup_table(engine); - ibus_engine_update_preedit_text(engine, - IBUS_CHEWING_ENGINE_GET_CLASS(self)->emptyText, 0, FALSE); - -#endif -} - -void ibus_chewing_engine_enable(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* enable(): statusFlags=%x", - self->_priv->statusFlags); - ibus_chewing_engine_start(self); - ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_ENABLED); -} - -void ibus_chewing_engine_disable(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* disable(): statusFlags=%x", - self->_priv->statusFlags); - ibus_chewing_engine_clear_status_flag(self, ENGINE_FLAG_ENABLED); -} - -void ibus_chewing_engine_focus_in(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* focus_in(): statusFlags=%x", - self->_priv->statusFlags); - ibus_chewing_engine_start(self); - /* Shouldn't have anything to commit when Focus-in */ - ibus_chewing_pre_edit_clear(self->icPreEdit); - refresh_pre_edit_text(self); - refresh_aux_text(self); - refresh_outgoing_text(self); - - ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_FOCUS_IN); - IBUS_CHEWING_LOG(INFO, "focus_in() statusFlags=%x: return", - self->_priv->statusFlags); -} - -void ibus_chewing_engine_focus_out(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* focus_out(): statusFlags=%x", - self->_priv->statusFlags); - ibus_chewing_engine_clear_status_flag(self, - ENGINE_FLAG_FOCUS_IN | - ENGINE_FLAG_PROPERTIES_REGISTERED); - ibus_chewing_engine_hide_property_list(self); - - if (ibus_chewing_pre_edit_get_property_boolean - (self->icPreEdit, "clean-buffer-focus-out")) { - /* Clean the buffer when focus out */ - ibus_chewing_pre_edit_clear(self->icPreEdit); - refresh_pre_edit_text(self); - refresh_aux_text(self); - } - - IBUS_CHEWING_LOG(DEBUG, "focus_out(): return"); -} - - - -#if IBUS_CHECK_VERSION(1, 5, 4) -void ibus_chewing_engine_set_content_type(IBusEngine * engine, - guint purpose, guint hints) -{ - IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_set_content_type(%d, %d)", - purpose, hints); - - IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); - - if (purpose == IBUS_INPUT_PURPOSE_PASSWORD || - purpose == IBUS_INPUT_PURPOSE_PIN) { - ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_IS_PASSWORD); - } else { - ibus_chewing_engine_clear_status_flag(self, ENGINE_FLAG_IS_PASSWORD); - } -} -#endif - -/*================================================= - * Display text update routines - * - */ - -void parent_commit_text(IBusEngine * iEngine) -{ - IBusChewingEngine *self = IBUS_CHEWING_ENGINE(iEngine); - - IBUS_CHEWING_LOG(MSG, "* parent_commit_text(-): outgoingText=%s", - self->outgoingText->text); -#ifdef UNIT_TEST - printf("* parent_commit_text(-, %s)\n", self->outgoingText->text); -#else - ibus_engine_commit_text(iEngine, self->outgoingText); -#endif -} - -void parent_update_pre_edit_text(IBusEngine * iEngine, - IBusText * iText, guint cursor_pos, - gboolean visible) -{ -#ifdef UNIT_TEST - printf("* parent_update_pre_edit_text(-, %s, %u, %x)\n", - iText->text, cursor_pos, visible); -#else - ibus_engine_update_preedit_text(iEngine, iText, cursor_pos, visible); -#endif -} - -void parent_update_pre_edit_text_with_mode(IBusEngine * iEngine, - IBusText * iText, - guint cursor_pos, - gboolean visible, - IBusPreeditFocusMode mode) -{ -#ifdef UNIT_TEST - printf - ("* parent_update_pre_edit_text_with_mode(-, %s, %u, %x, %x)\n", - iText->text, cursor_pos, visible, mode); -#else - ibus_engine_update_preedit_text_with_mode - (iEngine, iText, cursor_pos, visible, mode); -#endif -} - -void parent_update_auxiliary_text(IBusEngine * iEngine, - IBusText * iText, gboolean visible) -{ -#ifdef UNIT_TEST - printf("* parent_update_auxiliary_text(-, %s, %x)\n", - (iText) ? iText->text : "NULL", visible); -#else - if (!visible || ibus_text_is_empty(iText)) { - ibus_engine_hide_auxiliary_text(iEngine); - return; - } - ibus_engine_update_auxiliary_text(iEngine, iText, visible); - ibus_engine_show_auxiliary_text(iEngine); -#endif -} - -IBusText *decorate_pre_edit(IBusChewingPreEdit * icPreEdit, - IBusCapabilite capabilite) -{ - gchar *preEdit = ibus_chewing_pre_edit_get_pre_edit(icPreEdit); - IBusText *iText = ibus_text_new_from_string(preEdit); - gint chiSymbolCursor = chewing_cursor_Current(icPreEdit->context); - gint charLen = (gint) g_utf8_strlen(preEdit, -1); - - IBUS_CHEWING_LOG(DEBUG, "decorate_pre_edit() cursor=%d preEdit=%s charLen=%d", - chiSymbolCursor, preEdit, charLen); - - /* Use single underline to mark whole pre-edit buffer */ - ibus_text_append_attribute(iText, - IBUS_ATTR_TYPE_UNDERLINE, - IBUS_ATTR_UNDERLINE_SINGLE, - 0, charLen); - - /* Use background color to show current cursor */ - if (chiSymbolCursor < charLen) { - ibus_text_append_attribute(iText, - IBUS_ATTR_TYPE_BACKGROUND, - 0x00c8c8f0, - chiSymbolCursor, chiSymbolCursor + 1); - ibus_text_append_attribute(iText, - IBUS_ATTR_TYPE_FOREGROUND, - 0x00000000, - chiSymbolCursor, chiSymbolCursor + 1); - } - - return iText; -} - -void refresh_pre_edit_text(IBusChewingEngine * self) -{ - IBusText *iText = - decorate_pre_edit(self->icPreEdit, self->_priv->capabilite); - if (self->preEditText) { - g_object_unref(self->preEditText); - } - self->preEditText = g_object_ref_sink(iText); -} - -void update_pre_edit_text(IBusChewingEngine * self) -{ - refresh_pre_edit_text(self); - gboolean visible = TRUE; - gint bpmfLen = self->icPreEdit->bpmfLen; - - IBusPreeditFocusMode mode; - - if (STRING_IS_EMPTY(self->preEditText->text)) { - mode = IBUS_ENGINE_PREEDIT_CLEAR; - visible = FALSE; - } else { - mode = IBUS_ENGINE_PREEDIT_COMMIT; - } - - parent_update_pre_edit_text_with_mode(IBUS_ENGINE(self), - self->preEditText, - cursor_current + bpmfLen, visible, mode); -} - -void refresh_aux_text(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(INFO, "refresh_aux_text()"); - - if (self->auxText != NULL) { - g_object_unref(self->auxText); - } - - /* Make auxText (text to be displayed in auxiliary candidate window). - * Use auxText to show messages from libchewing, such as "已有:". - */ - - gboolean showPageNumber = - ibus_chewing_pre_edit_get_property_boolean(self->icPreEdit, - "show-page-number"); - - if (chewing_aux_Length(self->icPreEdit->context) > 0) { - IBUS_CHEWING_LOG(INFO, "update_aux_text() chewing_aux_Length=%x", - chewing_aux_Length(self->icPreEdit->context)); - gchar *auxStr = chewing_aux_String(self->icPreEdit->context); - - IBUS_CHEWING_LOG(INFO, "update_aux_text() auxStr=%s", auxStr); - self->auxText = g_object_ref_sink(ibus_text_new_from_string(auxStr)); - g_free(auxStr); - } else if (showPageNumber && (chewing_cand_TotalPage(self->icPreEdit->context) > 0)) { - int TotalPage = chewing_cand_TotalPage(self->icPreEdit->context); - int currentPage = chewing_cand_CurrentPage(self->icPreEdit->context) + 1; - self->auxText = g_object_ref_sink(ibus_text_new_from_printf("(%i/%i)", currentPage, TotalPage)); - } else { - /* clear out auxText, otherwise it will be displayed continually. */ - self->auxText = g_object_ref_sink(ibus_text_new_from_static_string("")); - } -} - -void update_aux_text(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(DEBUG, "update_aux_text()"); - refresh_aux_text(self); - parent_update_auxiliary_text(IBUS_ENGINE(self), self->auxText, TRUE); -} - -void update_lookup_table(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(DEBUG, "update_lookup_table() CurrentPage=%d", - chewing_cand_CurrentPage(self->icPreEdit->context)); - - gboolean isShow = - ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_TABLE_SHOW); - - if (isShow) { -#ifndef UNIT_TEST - ibus_engine_update_lookup_table(IBUS_ENGINE(self), - self->icPreEdit->iTable, isShow); - ibus_engine_show_lookup_table(IBUS_ENGINE(self)); -#endif - } else { -#ifndef UNIT_TEST - ibus_engine_update_lookup_table(IBUS_ENGINE(self), - self->icPreEdit->iTable, isShow); - ibus_engine_hide_lookup_table(IBUS_ENGINE(self)); -#endif - } -} - -void refresh_outgoing_text(IBusChewingEngine * self) -{ - gchar *outgoingStr = ibus_chewing_pre_edit_get_outgoing(self->icPreEdit); - - IBUS_CHEWING_LOG(INFO, "refresh_outgoing_text() outgoingStr=|%s|", - outgoingStr); - - if (self->outgoingText) { - g_object_unref(self->outgoingText); - } - self->outgoingText = - g_object_ref_sink(ibus_text_new_from_string(outgoingStr)); - IBUS_CHEWING_LOG(DEBUG, "refresh_outgoing_text() outgoingText=|%s|", - self->outgoingText->text); -} - -void commit_text(IBusChewingEngine * self) -{ - refresh_outgoing_text(self); - if (!ibus_text_is_empty(self->outgoingText) - || !ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_FOCUS_IN)) { - parent_commit_text(IBUS_ENGINE(self)); - } - - ibus_chewing_pre_edit_clear_outgoing(self->icPreEdit); -} diff --git a/src/MakerDialogProperty.c b/src/MakerDialogProperty.c index b0760c7..1a55b91 100644 --- a/src/MakerDialogProperty.c +++ b/src/MakerDialogProperty.c @@ -17,8 +17,6 @@ static gboolean property_context_from_string(PropertyContext * ctx, const gchar void property_context_default(PropertyContext * ctx) { - if (ctx->spec->defaultValue == NULL) - return; mkdg_log(DEBUG, "property_context_default(%s)", ctx->spec->key); gboolean ret = property_context_from_string(ctx, ctx->spec->defaultValue); diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c index cadd374..94a8267 100644 --- a/src/ibus-chewing-engine.c +++ b/src/ibus-chewing-engine.c @@ -39,7 +39,7 @@ #define GOB_VERSION_MINOR 0 #define GOB_VERSION_PATCHLEVEL 20 -#define selfp (self->_priv) +#define selfp ((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private (self)) #include /* memset() */ @@ -106,9 +106,11 @@ extern gint ibus_chewing_verbose; typedef IBusChewingEngine Self; typedef IBusChewingEngineClass SelfClass; +G_DEFINE_TYPE_WITH_CODE(IBusChewingEngine, ibus_chewing_engine, IBUS_TYPE_ENGINE, G_ADD_PRIVATE(IBusChewingEngine)); + /* here are local prototypes */ -static void ibus_chewing_engine_init (IBusChewingEngine * self) G_GNUC_UNUSED; -static void ibus_chewing_engine_class_init (IBusChewingEngineClass * klass) G_GNUC_UNUSED; +// static void ibus_chewing_engine_init (IBusChewingEngine * self) G_GNUC_UNUSED; +// static void ibus_chewing_engine_class_init (IBusChewingEngineClass * klass) G_GNUC_UNUSED; static void ibus_chewing_engine_constructor (IBusChewingEngine * self) G_GNUC_UNUSED; static IBusProperty * ibus_chewing_engine_get_ibus_property_by_name (IBusChewingEngine * self, const gchar * prop_name) G_GNUC_UNUSED; static void ___b_ibus_chewing_engine_reset (IBusEngine * engine) G_GNUC_UNUSED; @@ -135,30 +137,16 @@ static IBusEngineClass *parent_class = NULL; #define self_refresh_property_list ibus_chewing_engine_refresh_property_list #define self_hide_property_list ibus_chewing_engine_hide_property_list #define self_get_ibus_property_by_name ibus_chewing_engine_get_ibus_property_by_name -GType -ibus_chewing_engine_get_type (void) -{ - static GType type = 0; - if ___GOB_UNLIKELY(type == 0) { - static const GTypeInfo info = { - sizeof (IBusChewingEngineClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) ibus_chewing_engine_class_init, - (GClassFinalizeFunc) NULL, - NULL /* class_data */, - sizeof (IBusChewingEngine), - 0 /* n_preallocs */, - (GInstanceInitFunc) ibus_chewing_engine_init, - NULL - }; - - type = g_type_register_static (IBUS_TYPE_ENGINE, "IBusChewingEngine", &info, (GTypeFlags)0); - } +#define ibus_chewing_engine_has_status_flag(self, f) mkdg_has_flag(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->statusFlags, f) +#define ibus_chewing_engine_set_status_flag(self, f) mkdg_set_flag(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->statusFlags, f) +#define ibus_chewing_engine_clear_status_flag(self, f) mkdg_clear_flag(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->statusFlags, f) - return type; -} +#define is_password(self) ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_IS_PASSWORD) +#define ibus_chewing_engine_is_chinese_mode(self) ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) +#define is_caps_lock(self) (is_caps_led_on(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->pDisplay)) + +#define ibus_text_is_empty(iText) ((iText == NULL) || STRING_IS_EMPTY(iText->text)) /* a macro for creating a new object of our type */ #define GET_NEW ((IBusChewingEngine *)g_object_new(ibus_chewing_engine_get_type(), NULL)) @@ -197,7 +185,7 @@ ___finalize(GObject *obj_self) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::finalize" IBusChewingEngine *self G_GNUC_UNUSED = IBUS_CHEWING_ENGINE (obj_self); - gpointer priv G_GNUC_UNUSED = self->_priv; + gpointer priv G_GNUC_UNUSED = selfp; if(self->icPreEdit) { ibus_chewing_pre_edit_free ((gpointer) self->icPreEdit); self->icPreEdit = NULL; } if(self->preEditText) { g_object_unref ((gpointer) self->preEditText); self->preEditText = NULL; } if(self->auxText) { g_object_unref ((gpointer) self->auxText); self->auxText = NULL; } @@ -206,7 +194,7 @@ ___finalize(GObject *obj_self) if(self->AlnumSize) { g_object_unref ((gpointer) self->AlnumSize); self->AlnumSize = NULL; } if(self->setup_prop) { g_object_unref ((gpointer) self->setup_prop); self->setup_prop = NULL; } if(self->prop_list) { g_object_unref ((gpointer) self->prop_list); self->prop_list = NULL; } - if(self->_priv->pDisplay) { XCloseDisplay ((gpointer) self->_priv->pDisplay); self->_priv->pDisplay = NULL; } + if(selfp->pDisplay) { XCloseDisplay ((gpointer) selfp->pDisplay); selfp->pDisplay = NULL; } if(G_OBJECT_CLASS(parent_class)->finalize) \ (* G_OBJECT_CLASS(parent_class)->finalize)(obj_self); } @@ -216,15 +204,15 @@ static void ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::init" - self->_priv = G_TYPE_INSTANCE_GET_PRIVATE(self,IBUS_TYPE_CHEWING_ENGINE,IBusChewingEnginePrivate); + // ibus_chewing_engine_get_instance_private (self) = G_TYPE_INSTANCE_GET_PRIVATE(self,IBUS_TYPE_CHEWING_ENGINE,IBusChewingEnginePrivate); self->icPreEdit = NULL; self->sDialog = NULL; self->preEditText = NULL; self->auxText = NULL; self->outgoingText = NULL; self->logFile = NULL; - self->_priv->statusFlags = 0; - self->_priv->capabilite = 0; + selfp->statusFlags = 0; + selfp->capabilite = 0; self->InputMode = g_object_ref_sink(ibus_property_new ("InputMode", @@ -265,15 +253,15 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) g_object_ref_sink(ibus_prop_list_new()) ; self->keymap_us = ibus_keymap_get("us") ; - self->_priv->pDisplay = + selfp->pDisplay = XOpenDisplay(NULL) ; { /* initialize the object here */ IBUS_CHEWING_LOG(INFO, "init() %sinitialized", - (self->_priv->statusFlags & ENGINE_FLAG_INITIALIZED) ? "" : "un"); - if (self->_priv->statusFlags & ENGINE_FLAG_INITIALIZED) { + (selfp->statusFlags & ENGINE_FLAG_INITIALIZED) ? "" : "un"); + if (selfp->statusFlags & ENGINE_FLAG_INITIALIZED) { return; } @@ -313,7 +301,7 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_INITIALIZED); /* In case we cannot open X display */ - if (self->_priv->pDisplay == NULL) { + if (selfp->pDisplay == NULL) { IBUS_CHEWING_LOG(WARN, "init() XOpenDisplay return NULL"); } @@ -329,7 +317,7 @@ ibus_chewing_engine_class_init (IBusChewingEngineClass * klass G_GNUC_UNUSED) GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) klass; IBusEngineClass *ibus_engine_class = (IBusEngineClass *)klass; - g_type_class_add_private(klass,sizeof(IBusChewingEnginePrivate)); + // g_type_class_add_private(klass,sizeof(IBusChewingEnginePrivate)); klass->InputMode_label_chi = g_object_ref_sink(ibus_text_new_from_static_string(_("Chinese Mode"))) ; @@ -436,9 +424,9 @@ ibus_chewing_engine_use_setting (IBusChewingEngine * self) /* Input style */ if (ibus_chewing_properties_read_boolean_general(self->icPreEdit->iProperties, "ibus/general", "embed-preedit-text", NULL)) { - self->_priv->inputStyle = CHEWING_INPUT_STYLE_IN_APPLICATION; + selfp->inputStyle = CHEWING_INPUT_STYLE_IN_APPLICATION; } else { - self->_priv->inputStyle = CHEWING_INPUT_STYLE_IN_CANDIDATE; + selfp->inputStyle = CHEWING_INPUT_STYLE_IN_CANDIDATE; } }} #undef __GOB_FUNCTION__ @@ -451,14 +439,14 @@ ibus_chewing_engine_restore_mode (IBusChewingEngine * self) g_return_if_fail (IBUS_IS_CHEWING_ENGINE (self)); { - IBUS_CHEWING_LOG(DEBUG, "restore_mode() statusFlags=%x", self->_priv->statusFlags); - if (self->_priv->pDisplay != NULL) { + IBUS_CHEWING_LOG(DEBUG, "restore_mode() statusFlags=%x", selfp->statusFlags); + if (selfp->pDisplay != NULL) { /* Restore Led Mode only make sense if pDisplay is available */ if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM)) { IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_IM"); if (ibus_chewing_engine_is_chinese_mode(self) == is_caps_lock(self)) { /* ChiEng mode does not agree each other */ - set_caps_led(!ibus_chewing_engine_is_chinese_mode(self), self->_priv->pDisplay); + set_caps_led(!ibus_chewing_engine_is_chinese_mode(self), selfp->pDisplay); } } else if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_KEYBOARD)) { IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_KEYBOARD"); @@ -477,7 +465,7 @@ ibus_chewing_engine_update (IBusChewingEngine * self) g_return_if_fail (IBUS_IS_CHEWING_ENGINE (self)); { - IBUS_CHEWING_LOG(DEBUG, "update() statusFlags=%x", self->_priv->statusFlags); + IBUS_CHEWING_LOG(DEBUG, "update() statusFlags=%x", selfp->statusFlags); commit_text(self); update_pre_edit_text(self); update_aux_text(self); @@ -485,7 +473,7 @@ ibus_chewing_engine_update (IBusChewingEngine * self) IBUS_CHEWING_LOG(DEBUG, "update() nPhoneSeq=%d statusFlags=%x", chewing_get_phoneSeqLen(self->icPreEdit->context), - self->_priv->statusFlags); + selfp->statusFlags); update_lookup_table(self); }} #undef __GOB_FUNCTION__ @@ -500,7 +488,7 @@ ibus_chewing_engine_refresh_property (IBusChewingEngine * self, const gchar * pr #ifndef UNIT_TEST IBUS_CHEWING_LOG(DEBUG, "refresh_property(%s) status=%x", - prop_name, self->_priv->statusFlags); + prop_name, selfp->statusFlags); if (STRING_EQUALS(prop_name, "InputMode")) { @@ -532,7 +520,7 @@ ibus_chewing_engine_refresh_property (IBusChewingEngine * self, const gchar * pr SELF_GET_CLASS(self)->AlnumSize_symbol_half); #endif - if (self->_priv->statusFlags & ENGINE_FLAG_PROPERTIES_REGISTERED) + if (selfp->statusFlags & ENGINE_FLAG_PROPERTIES_REGISTERED) ibus_engine_update_property(IBUS_ENGINE(self), self->AlnumSize); } else if (STRING_EQUALS(prop_name, "setup_prop")) { @@ -766,9 +754,9 @@ ___14_ibus_chewing_engine_set_capabilities (IBusEngine * engine G_GNUC_UNUSED, g { Self *self = SELF(engine); - self->_priv->capabilite = caps; + selfp->capabilite = caps; IBUS_CHEWING_LOG(MSG, "***** set_capabilities(%x): statusFlags=%x", - caps, self->_priv->statusFlags); + caps, selfp->statusFlags); }} #undef __GOB_FUNCTION__ #undef PARENT_HANDLER @@ -806,3 +794,457 @@ ___16_ibus_chewing_engine_property_hide (IBusEngine * engine G_GNUC_UNUSED, cons }} #undef __GOB_FUNCTION__ #undef PARENT_HANDLER + +/** + * ibus_chewing_engine_start: + * @self: IBusChewingEngine instance. + * + * This is different with init. This will be called in the beginning of + * reset, enable, and focus_in for setup. + */ +void ibus_chewing_engine_start(IBusChewingEngine * self) +{ +#ifndef UNIT_TEST + if (!ibus_chewing_engine_has_status_flag + (self, ENGINE_FLAG_PROPERTIES_REGISTERED)) { + IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self), + "InputMode"); + IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self), + "AlnumSize"); + IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self), + "setup_prop"); + ibus_engine_register_properties(IBUS_ENGINE(self), self->prop_list); + ibus_chewing_engine_set_status_flag(self, + ENGINE_FLAG_PROPERTIES_REGISTERED); + } +#endif + ibus_chewing_engine_use_setting(self); + ibus_chewing_engine_restore_mode(self); + ibus_chewing_engine_refresh_property_list(self); + +} + +/** + * ibus_chewing_engine_reset: + * @self: IBusChewingEngine instance. + * + * Reset the outgoing and pre_edit buffer and cursor + * chewing_reset will NOT called here, as it will chnage the KBType and input mode. + */ +void ibus_chewing_engine_reset(IBusChewingEngine * self) +{ + IBUS_CHEWING_LOG(MSG, "* reset"); + + /* Always clean buffer */ + ibus_chewing_pre_edit_clear(self->icPreEdit); +#ifndef UNIT_TEST + IBusEngine *engine = IBUS_ENGINE(self); + + ibus_engine_hide_auxiliary_text(engine); + ibus_engine_hide_lookup_table(engine); + ibus_engine_update_preedit_text(engine, + IBUS_CHEWING_ENGINE_GET_CLASS(self)->emptyText, 0, FALSE); + +#endif +} + +void ibus_chewing_engine_enable(IBusChewingEngine * self) +{ + IBUS_CHEWING_LOG(MSG, "* enable(): statusFlags=%x", + selfp->statusFlags); + ibus_chewing_engine_start(self); + ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_ENABLED); +} + +void ibus_chewing_engine_disable(IBusChewingEngine * self) +{ + IBUS_CHEWING_LOG(MSG, "* disable(): statusFlags=%x", + selfp->statusFlags); + ibus_chewing_engine_clear_status_flag(self, ENGINE_FLAG_ENABLED); +} + +void ibus_chewing_engine_focus_in(IBusChewingEngine * self) +{ + IBUS_CHEWING_LOG(MSG, "* focus_in(): statusFlags=%x", + selfp->statusFlags); + ibus_chewing_engine_start(self); + /* Shouldn't have anything to commit when Focus-in */ + ibus_chewing_pre_edit_clear(self->icPreEdit); + refresh_pre_edit_text(self); + refresh_aux_text(self); + refresh_outgoing_text(self); + + ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_FOCUS_IN); + IBUS_CHEWING_LOG(INFO, "focus_in() statusFlags=%x: return", + selfp->statusFlags); +} + +void ibus_chewing_engine_focus_out(IBusChewingEngine * self) +{ + IBUS_CHEWING_LOG(MSG, "* focus_out(): statusFlags=%x", + selfp->statusFlags); + ibus_chewing_engine_clear_status_flag(self, + ENGINE_FLAG_FOCUS_IN | + ENGINE_FLAG_PROPERTIES_REGISTERED); + ibus_chewing_engine_hide_property_list(self); + + if (ibus_chewing_pre_edit_get_property_boolean + (self->icPreEdit, "clean-buffer-focus-out")) { + /* Clean the buffer when focus out */ + ibus_chewing_pre_edit_clear(self->icPreEdit); + refresh_pre_edit_text(self); + refresh_aux_text(self); + } + + IBUS_CHEWING_LOG(DEBUG, "focus_out(): return"); +} + + + +#if IBUS_CHECK_VERSION(1, 5, 4) +void ibus_chewing_engine_set_content_type(IBusEngine * engine, + guint purpose, guint hints) +{ + IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_set_content_type(%d, %d)", + purpose, hints); + + IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); + + if (purpose == IBUS_INPUT_PURPOSE_PASSWORD || + purpose == IBUS_INPUT_PURPOSE_PIN) { + ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_IS_PASSWORD); + } else { + ibus_chewing_engine_clear_status_flag(self, ENGINE_FLAG_IS_PASSWORD); + } +} +#endif + +/*================================================= + * Display text update routines + * + */ + +void parent_commit_text(IBusEngine * iEngine) +{ + IBusChewingEngine *self = IBUS_CHEWING_ENGINE(iEngine); + + IBUS_CHEWING_LOG(MSG, "* parent_commit_text(-): outgoingText=%s", + self->outgoingText->text); +#ifdef UNIT_TEST + printf("* parent_commit_text(-, %s)\n", self->outgoingText->text); +#else + ibus_engine_commit_text(iEngine, self->outgoingText); +#endif +} + +void parent_update_pre_edit_text(IBusEngine * iEngine, + IBusText * iText, guint cursor_pos, + gboolean visible) +{ +#ifdef UNIT_TEST + printf("* parent_update_pre_edit_text(-, %s, %u, %x)\n", + iText->text, cursor_pos, visible); +#else + ibus_engine_update_preedit_text(iEngine, iText, cursor_pos, visible); +#endif +} + +void parent_update_pre_edit_text_with_mode(IBusEngine * iEngine, + IBusText * iText, + guint cursor_pos, + gboolean visible, + IBusPreeditFocusMode mode) +{ +#ifdef UNIT_TEST + printf + ("* parent_update_pre_edit_text_with_mode(-, %s, %u, %x, %x)\n", + iText->text, cursor_pos, visible, mode); +#else + ibus_engine_update_preedit_text_with_mode + (iEngine, iText, cursor_pos, visible, mode); +#endif +} + +void parent_update_auxiliary_text(IBusEngine * iEngine, + IBusText * iText, gboolean visible) +{ +#ifdef UNIT_TEST + printf("* parent_update_auxiliary_text(-, %s, %x)\n", + (iText) ? iText->text : "NULL", visible); +#else + if (!visible || ibus_text_is_empty(iText)) { + ibus_engine_hide_auxiliary_text(iEngine); + return; + } + ibus_engine_update_auxiliary_text(iEngine, iText, visible); + ibus_engine_show_auxiliary_text(iEngine); +#endif +} + +IBusText *decorate_pre_edit(IBusChewingPreEdit * icPreEdit, + IBusCapabilite capabilite) +{ + gchar *preEdit = ibus_chewing_pre_edit_get_pre_edit(icPreEdit); + IBusText *iText = ibus_text_new_from_string(preEdit); + gint chiSymbolCursor = chewing_cursor_Current(icPreEdit->context); + gint charLen = (gint) g_utf8_strlen(preEdit, -1); + + IBUS_CHEWING_LOG(DEBUG, "decorate_pre_edit() cursor=%d preEdit=%s charLen=%d", + chiSymbolCursor, preEdit, charLen); + + /* Use single underline to mark whole pre-edit buffer */ + ibus_text_append_attribute(iText, + IBUS_ATTR_TYPE_UNDERLINE, + IBUS_ATTR_UNDERLINE_SINGLE, + 0, charLen); + + /* Use background color to show current cursor */ + if (chiSymbolCursor < charLen) { + ibus_text_append_attribute(iText, + IBUS_ATTR_TYPE_BACKGROUND, + 0x00c8c8f0, + chiSymbolCursor, chiSymbolCursor + 1); + ibus_text_append_attribute(iText, + IBUS_ATTR_TYPE_FOREGROUND, + 0x00000000, + chiSymbolCursor, chiSymbolCursor + 1); + } + + return iText; +} + +void refresh_pre_edit_text(IBusChewingEngine * self) +{ + IBusText *iText = + decorate_pre_edit(self->icPreEdit, selfp->capabilite); + if (self->preEditText) { + g_object_unref(self->preEditText); + } + self->preEditText = g_object_ref_sink(iText); +} + +void update_pre_edit_text(IBusChewingEngine * self) +{ + refresh_pre_edit_text(self); + gboolean visible = TRUE; + gint bpmfLen = self->icPreEdit->bpmfLen; + + IBusPreeditFocusMode mode; + + if (STRING_IS_EMPTY(self->preEditText->text)) { + mode = IBUS_ENGINE_PREEDIT_CLEAR; + visible = FALSE; + } else { + mode = IBUS_ENGINE_PREEDIT_COMMIT; + } + + parent_update_pre_edit_text_with_mode(IBUS_ENGINE(self), + self->preEditText, + cursor_current + bpmfLen, visible, mode); +} + +void refresh_aux_text(IBusChewingEngine * self) +{ + IBUS_CHEWING_LOG(INFO, "refresh_aux_text()"); + + if (self->auxText != NULL) { + g_object_unref(self->auxText); + } + + /* Make auxText (text to be displayed in auxiliary candidate window). + * Use auxText to show messages from libchewing, such as "已有:". + */ + + gboolean showPageNumber = + ibus_chewing_pre_edit_get_property_boolean(self->icPreEdit, + "show-page-number"); + + if (chewing_aux_Length(self->icPreEdit->context) > 0) { + IBUS_CHEWING_LOG(INFO, "update_aux_text() chewing_aux_Length=%x", + chewing_aux_Length(self->icPreEdit->context)); + gchar *auxStr = chewing_aux_String(self->icPreEdit->context); + + IBUS_CHEWING_LOG(INFO, "update_aux_text() auxStr=%s", auxStr); + self->auxText = g_object_ref_sink(ibus_text_new_from_string(auxStr)); + g_free(auxStr); + } else if (showPageNumber && (chewing_cand_TotalPage(self->icPreEdit->context) > 0)) { + int TotalPage = chewing_cand_TotalPage(self->icPreEdit->context); + int currentPage = chewing_cand_CurrentPage(self->icPreEdit->context) + 1; + self->auxText = g_object_ref_sink(ibus_text_new_from_printf("(%i/%i)", currentPage, TotalPage)); + } else { + /* clear out auxText, otherwise it will be displayed continually. */ + self->auxText = g_object_ref_sink(ibus_text_new_from_static_string("")); + } +} + +void update_aux_text(IBusChewingEngine * self) +{ + IBUS_CHEWING_LOG(DEBUG, "update_aux_text()"); + refresh_aux_text(self); + parent_update_auxiliary_text(IBUS_ENGINE(self), self->auxText, TRUE); +} + +void update_lookup_table(IBusChewingEngine * self) +{ + IBUS_CHEWING_LOG(DEBUG, "update_lookup_table() CurrentPage=%d", + chewing_cand_CurrentPage(self->icPreEdit->context)); + + gboolean isShow = + ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_TABLE_SHOW); + + if (isShow) { +#ifndef UNIT_TEST + ibus_engine_update_lookup_table(IBUS_ENGINE(self), + self->icPreEdit->iTable, isShow); + ibus_engine_show_lookup_table(IBUS_ENGINE(self)); +#endif + } else { +#ifndef UNIT_TEST + ibus_engine_update_lookup_table(IBUS_ENGINE(self), + self->icPreEdit->iTable, isShow); + ibus_engine_hide_lookup_table(IBUS_ENGINE(self)); +#endif + } +} + +void refresh_outgoing_text(IBusChewingEngine * self) +{ + gchar *outgoingStr = ibus_chewing_pre_edit_get_outgoing(self->icPreEdit); + + IBUS_CHEWING_LOG(INFO, "refresh_outgoing_text() outgoingStr=|%s|", + outgoingStr); + + if (self->outgoingText) { + g_object_unref(self->outgoingText); + } + self->outgoingText = + g_object_ref_sink(ibus_text_new_from_string(outgoingStr)); + IBUS_CHEWING_LOG(DEBUG, "refresh_outgoing_text() outgoingText=|%s|", + self->outgoingText->text); +} + +void commit_text(IBusChewingEngine * self) +{ + refresh_outgoing_text(self); + if (!ibus_text_is_empty(self->outgoingText) + || !ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_FOCUS_IN)) { + parent_commit_text(IBUS_ENGINE(self)); + } + + ibus_chewing_pre_edit_clear_outgoing(self->icPreEdit); +} + +#include "ibus-chewing-engine-private.h" +#include "ibus-chewing-engine.h" +#include "IBusChewingProperties.h" + +gboolean ibus_chewing_engine_process_key_event(IBusEngine * engine, + KSym keySym, guint keycode, + KeyModifiers unmaskedMod) +{ + IBUS_CHEWING_LOG(MSG, "******** process_key_event(-,%x(%s),%x,%x) %s", + keySym, key_sym_get_name(keySym), keycode, + unmaskedMod, modifiers_to_string(unmaskedMod)); + + IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); + + if (unmaskedMod & IBUS_MOD4_MASK) + return FALSE; + + if (is_password(self)) + return FALSE; + + KSym kSym = + ibus_chewing_pre_edit_key_code_to_key_sym(self->icPreEdit, keySym, + keycode, + unmaskedMod); + + gboolean result = ibus_chewing_pre_edit_process_key(self->icPreEdit, kSym, + unmaskedMod); + + IBUS_CHEWING_LOG(MSG, "process_key_event() result=%d", result); + ibus_chewing_engine_update(self); + + if (kSym == IBUS_KEY_Shift_L || kSym == IBUS_KEY_Shift_R || + kSym == IBUS_KEY_Caps_Lock) { + /* Refresh property list (language bar) only when users toggle + * Chi-Eng Mode or Shape Mode with Shift or Caps Lock, otherwise + * the bar will stick to the cursor and block the candidats list. + */ + ibus_chewing_engine_refresh_property_list(self); + } + + return result; +} + +/*=================================================== + * Mouse events + */ +void ibus_chewing_engine_candidate_clicked(IBusEngine * engine, + guint index, guint button, + guint state) +{ + IBUS_CHEWING_LOG(INFO, + "*** candidate_clicked(-, %x, %x, %x) ... proceed.", + index, button, state); + IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); + + if (is_password(self)) + return; + if (index >= chewing_get_candPerPage(self->icPreEdit->context)) { + IBUS_CHEWING_LOG(DEBUG, "candidate_clicked() index out of ranged"); + return; + } + if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_TABLE_SHOW)) { + gint *selKeys = chewing_get_selKey(self->icPreEdit->context); + KSym k = (KSym) selKeys[index]; + + ibus_chewing_pre_edit_process_key(self->icPreEdit, k, 0); + g_free(selKeys); + ibus_chewing_engine_update(self); + } else { + IBUS_CHEWING_LOG(DEBUG, + "candidate_clicked() ... candidates are not showing"); + } +} + +void ibus_chewing_engine_property_activate(IBusEngine * engine, + const gchar * prop_name, + guint prop_state) +{ + IBUS_CHEWING_LOG(INFO, "property_activate(-, %s, %u)", prop_name, + prop_state); + IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); + + if (STRING_EQUALS(prop_name, "InputMode")) { + /* Toggle Chinese <-> English */ + ibus_chewing_pre_edit_toggle_chi_eng_mode(self->icPreEdit); + IBUS_CHEWING_LOG(INFO, + "property_activate chinese=%d caps_lock=%d", + ibus_chewing_engine_is_chinese_mode(self), + is_caps_lock(self)); + + if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM) + || ibus_chewing_pre_edit_has_flag(self->icPreEdit, + FLAG_SYNC_FROM_KEYBOARD)) { + if (ibus_chewing_engine_is_chinese_mode(self) == is_caps_lock(self)) { + set_caps_led(!ibus_chewing_engine_is_chinese_mode(self), + selfp->pDisplay); + } + } + ibus_chewing_engine_refresh_property(self, prop_name); + } else if (STRING_EQUALS(prop_name, "AlnumSize")) { + /* Toggle Full <-> Half */ + chewing_set_ShapeMode(self->icPreEdit->context, + !chewing_get_ShapeMode(self->icPreEdit->context)); + ibus_chewing_engine_refresh_property(self, prop_name); + } else if (STRING_EQUALS(prop_name, "setup_prop")) { + /* open preferences window */ + system(QUOTE_ME(LIBEXEC_DIR) "/ibus-setup-chewing"); + } else { + IBUS_CHEWING_LOG(DEBUG, + "property_activate(-, %s, %u) not recognized", + prop_name, prop_state); + } + +} diff --git a/src/ibus-chewing-engine.h b/src/ibus-chewing-engine.h index 2e83bc1..7c85759 100644 --- a/src/ibus-chewing-engine.h +++ b/src/ibus-chewing-engine.h @@ -70,20 +70,6 @@ extern const gchar *page_labels[]; extern const gchar *button_labels[]; extern GtkResponseType button_responses[]; -#define ibus_chewing_engine_has_status_flag(self, f) mkdg_has_flag(self->_priv->statusFlags, f) -#define ibus_chewing_engine_set_status_flag(self, f) mkdg_set_flag(self->_priv->statusFlags, f) -#define ibus_chewing_engine_clear_status_flag(self, f) mkdg_clear_flag(self->_priv->statusFlags, f) - -#define ibus_chewing_engine_has_capabilite(self, f) mkdg_has_flag(self->_priv->capabilite, f) -#define ibus_chewing_engine_set_capabilite(self, f) mkdg_set_flag(self->_priv->capabilite, f) -#define ibus_chewing_engine_clear_capabilite(self, f) mkdg_clear_flag(self->_priv->capabilite, f) - -#define is_password(self) ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_IS_PASSWORD) -#define ibus_chewing_engine_is_chinese_mode(self) ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) -#define is_caps_lock(self) (is_caps_led_on(self->_priv->pDisplay)) - -#define ibus_text_is_empty(iText) ((iText == NULL) || STRING_IS_EMPTY(iText->text)) -#define is_plain_chewing ibus_chewing_pre_edit_get_property_boolean(self->icPreEdit, "plain-zhuyin") #define cursor_current chewing_cursor_Current(self->icPreEdit->context) @@ -123,7 +109,6 @@ struct _IBusChewingEngine { /*< private >*/ FILE * logFile; /* protected */ IBusKeymap * keymap_us; /* protected */ - IBusChewingEnginePrivate *_priv; }; /* diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 93b1c52..0f14d21 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -39,8 +39,6 @@ add_test(NAME IBusChewingPreEdit add_executable(ibus-chewing-engine-test ibus-chewing-engine-test.c ../src/ibus-chewing-engine.c ../src/ibus-chewing-engine.h - ../src/IBusChewingEngine-signal.c - ../src/IBusChewingEngine-input-events.c ../src/IBusChewingLookupTable.c ../src/IBusChewingLookupTable.h ../src/IBusChewingPreEdit.c diff --git a/test/ibus-chewing-engine-test.c b/test/ibus-chewing-engine-test.c index 6324aef..b9ac647 100644 --- a/test/ibus-chewing-engine-test.c +++ b/test/ibus-chewing-engine-test.c @@ -33,7 +33,7 @@ void focus_out_then_focus_in_with_aux_text_test() ibus_chewing_pre_edit_save_property_boolean(engine->icPreEdit, "add-phrase-direction", TRUE); - ibus_chewing_engine_set_capabilite(engine, IBUS_CAP_AUXILIARY_TEXT); + g_signal_emit_by_name(engine, "set_capabilities", IBUS_CAP_AUXILIARY_TEXT); ibus_chewing_engine_focus_in(engine); ibus_chewing_engine_enable(engine); ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24, 0); From 10b9a3bb1492899d0dc8045818b45986611c0b90 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 21:19:52 +0900 Subject: [PATCH 14/24] ci(coverage): bump checkout to v4 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d15cfc7..6585c0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: container: fedora:latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install build dependencies run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libX11-devel libchewing-devel ibus gettext xorg-x11-server-Xvfb dbus-x11 util-linux @@ -35,7 +35,7 @@ jobs: container: fedora:latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install build dependencies run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libX11-devel libchewing-devel ibus gettext xorg-x11-server-Xvfb dbus-x11 util-linux From 9865a609e8243f58bddfa745d11282b3743f7177 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 21:44:57 +0900 Subject: [PATCH 15/24] refactor: delete another unused file --- src/MakerDialog-def.c | 60 ------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 src/MakerDialog-def.c diff --git a/src/MakerDialog-def.c b/src/MakerDialog-def.c deleted file mode 100644 index cf21ac2..0000000 --- a/src/MakerDialog-def.c +++ /dev/null @@ -1,60 +0,0 @@ - -static gchar *widget_get_id(gchar * buffer, gint buffer_size, - const gchar * widget_label, - const gchar * widget_type) -{ - g_snprintf(buffer, buffer_size, "%s%s%s%s", - WIDGET_ID_PREFIX, widget_label, - (widget_type) ? "_" : "", (widget_type) ? widget_type : ""); - return buffer; -} - - -typedef struct { - MakerDialog *self; - gint currentMaxWidth; - const gchar *pageName; - gfloat xalign; - gfloat yalign; -} WidgetAlignment; - -static void calculate_max_label_width_callback(gpointer key, - gpointer value, - gpointer widgetAlignment) -{ - gchar *wKey = (gchar *) key; - gchar *pageName = (gchar *) value; - WidgetAlignment *wAlignment = (WidgetAlignment *) widgetAlignment; - - if (!STRING_EQUALS(wAlignment->pageName, pageName)) { - /* Different Page */ - return; - } - - GtkWidget *widget = - maker_dialog_get_widget(wAlignment->self, wKey, "label"); - GtkRequisition requisition; - - gtk_widget_size_request(widget, &requisition); - wAlignment->currentMaxWidth = - MAX(wAlignment->currentMaxWidth, requisition.width); -} - -static void set_label_width_callback(gpointer key, gpointer value, - gpointer userData) -{ - WidgetAlignment *wAlignment = (WidgetAlignment *) userData; - gchar *wKey = (gchar *) key; - gchar *pageName = (gchar *) value; - - if (!STRING_EQUALS(wAlignment->pageName, pageName)) { - /* Different Page */ - return; - } - GtkWidget *widget = - maker_dialog_get_widget(wAlignment->self, wKey, "label"); - gtk_widget_set_size_request(widget, wAlignment->currentMaxWidth, -1); - gtk_misc_set_alignment(GTK_MISC(widget), wAlignment->xalign, - wAlignment->yalign); - gtk_widget_show(widget); -} From 8a85fcb8d8d4646f227b9fc56ad91dd059875b0f Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 21:55:05 +0900 Subject: [PATCH 16/24] ci(coverage): run test with cmake preset --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6585c0b..07065de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - name: Test run: | glib-compile-schemas src/setup --targetdir=out/build/default/bin - xvfb-run -a ctest --test-dir out/build/default --output-on-failure --verbose + xvfb-run -a cmake --build --preset default -t test --verbose coverage: runs-on: ubuntu-latest @@ -62,7 +62,7 @@ jobs: run: | source "$HOME/.cargo/env" glib-compile-schemas src/setup --targetdir=out/build/c99-coverage/bin - xvfb-run -a ctest --test-dir out/build/c99-coverage --output-on-failure --verbose + xvfb-run -a cmake --build --preset c99-coverage -t test --verbose ./grcov . -s . -b . --keep-only 'src/*' --llvm -t lcov -o coverage.lcov - name: Upload coverage reports to Codecov From 99fdb2b7d8da911de7728fa4bc76085d1984730e Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 22:36:10 +0900 Subject: [PATCH 17/24] feat!: deprecate sync IM state back to capslock and remove X11 dep --- CMakeLists.txt | 1 - INSTALL | 1 - src/CMakeLists.txt | 1 - src/IBusChewingUtil.c | 23 -------------- src/IBusChewingUtil.h | 6 ---- src/ibus-chewing-engine-private.h | 3 -- src/ibus-chewing-engine.c | 42 ++++++-------------------- src/ibus-chewing-engine.h | 2 -- src/setup/ibus-setup-chewing-window.ui | 34 +++++++-------------- 9 files changed, 21 insertions(+), 92 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d62a828..3758d0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,6 @@ add_compile_definitions( pkg_check_modules(GLIB2 REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GTK4 REQUIRED IMPORTED_TARGET gtk4) pkg_check_modules(LIBADWAITA REQUIRED IMPORTED_TARGET libadwaita-1) -pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11) find_program(GLIB_COMPILE_RESOURCES NAMES glib-compile-resources REQUIRED) diff --git a/INSTALL b/INSTALL index 28ee4a2..f5125b9 100644 --- a/INSTALL +++ b/INSTALL @@ -7,7 +7,6 @@ Installation Instructions gob >= 2.0.16 gtk >= 3 libchewing >= 0.5.1 - libX11 1. Remove the old build cache: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d955fe2..86a4057 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,7 +29,6 @@ target_link_libraries(gui-core PUBLIC PkgConfig::GLIB2 PkgConfig::GTK4 PkgConfig::LIBADWAITA - PkgConfig::X11 PkgConfig::IBUS PkgConfig::CHEWING ) diff --git a/src/IBusChewingUtil.c b/src/IBusChewingUtil.c index 389e8ee..50ab800 100644 --- a/src/IBusChewingUtil.c +++ b/src/IBusChewingUtil.c @@ -194,29 +194,6 @@ const char *key_sym_get_name(KSym k) * Modifiers */ -#define CAPS_LOCK_MASK 2 -gboolean is_caps_led_on(Display * pDisplay) -{ - XKeyboardState retState; - - XGetKeyboardControl(pDisplay, &retState); - XFlush(pDisplay); - return (retState.led_mask & 1) ? TRUE : FALSE; -} - -void set_caps_led(gboolean on, Display * pDisplay) -{ - XKeyboardControl control; - - control.led_mode = (on) ? LedModeOn : LedModeOff; - control.led = CAPS_LOCK_MASK; - guint flags = (on) ? CAPS_LOCK_MASK : 0; - - XChangeKeyboardControl(pDisplay, KBLedMode, &control); - XkbLockModifiers(pDisplay, XkbUseCoreKbd, control.led, flags); - XFlush(pDisplay); -} - const gchar *modifier_get_string(guint modifier) { switch (modifier) { diff --git a/src/IBusChewingUtil.h b/src/IBusChewingUtil.h index fae991e..835734c 100644 --- a/src/IBusChewingUtil.h +++ b/src/IBusChewingUtil.h @@ -26,8 +26,6 @@ # include # include # include -# include -# include # define ZHUYIN_BUFFER_SIZE 12 @@ -70,10 +68,6 @@ KSym key_sym_KP_to_normal(KSym k); const char *key_sym_get_name(KSym k); -gboolean is_caps_led_on(Display * pDisplay); - -void set_caps_led(gboolean on, Display * pDisplay); - const gchar *modifier_get_string(guint modifier); const gchar *modifiers_to_string(guint modifier); diff --git a/src/ibus-chewing-engine-private.h b/src/ibus-chewing-engine-private.h index 5c253fc..93667ff 100644 --- a/src/ibus-chewing-engine-private.h +++ b/src/ibus-chewing-engine-private.h @@ -26,8 +26,6 @@ #include #define GETTEXT_PACKAGE "gtk30" #include -#include -#include #include #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" @@ -71,7 +69,6 @@ struct _IBusChewingEnginePrivate { EngineFlag statusFlags; IBusCapabilite capabilite; ChewingInputStyle inputStyle; - Display * pDisplay; }; void ibus_chewing_engine_use_setting (IBusChewingEngine * self); void ibus_chewing_engine_restore_mode (IBusChewingEngine * self); diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c index 94a8267..59b2012 100644 --- a/src/ibus-chewing-engine.c +++ b/src/ibus-chewing-engine.c @@ -27,8 +27,6 @@ #define GETTEXT_PACKAGE "gtk30" #include #include -#include -#include #include #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" @@ -144,7 +142,6 @@ static IBusEngineClass *parent_class = NULL; #define is_password(self) ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_IS_PASSWORD) #define ibus_chewing_engine_is_chinese_mode(self) ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) -#define is_caps_lock(self) (is_caps_led_on(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->pDisplay)) #define ibus_text_is_empty(iText) ((iText == NULL) || STRING_IS_EMPTY(iText->text)) @@ -194,7 +191,6 @@ ___finalize(GObject *obj_self) if(self->AlnumSize) { g_object_unref ((gpointer) self->AlnumSize); self->AlnumSize = NULL; } if(self->setup_prop) { g_object_unref ((gpointer) self->setup_prop); self->setup_prop = NULL; } if(self->prop_list) { g_object_unref ((gpointer) self->prop_list); self->prop_list = NULL; } - if(selfp->pDisplay) { XCloseDisplay ((gpointer) selfp->pDisplay); selfp->pDisplay = NULL; } if(G_OBJECT_CLASS(parent_class)->finalize) \ (* G_OBJECT_CLASS(parent_class)->finalize)(obj_self); } @@ -253,9 +249,6 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) g_object_ref_sink(ibus_prop_list_new()) ; self->keymap_us = ibus_keymap_get("us") ; - selfp->pDisplay = - XOpenDisplay(NULL) - ; { /* initialize the object here */ @@ -300,11 +293,6 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_INITIALIZED); - /* In case we cannot open X display */ - if (selfp->pDisplay == NULL) { - IBUS_CHEWING_LOG(WARN, "init() XOpenDisplay return NULL"); - } - IBUS_CHEWING_LOG(DEBUG, "init() Done"); } @@ -440,17 +428,17 @@ ibus_chewing_engine_restore_mode (IBusChewingEngine * self) { IBUS_CHEWING_LOG(DEBUG, "restore_mode() statusFlags=%x", selfp->statusFlags); - if (selfp->pDisplay != NULL) { - /* Restore Led Mode only make sense if pDisplay is available */ + GdkDisplay *display = gdk_display_get_default(); + if (display != NULL) { + GdkSeat *seat = gdk_display_get_default_seat(display); + GdkDevice *keyboard = gdk_seat_get_keyboard(seat); + /* Restore Led Mode only make sense if display is available */ if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM)) { - IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_IM"); - if (ibus_chewing_engine_is_chinese_mode(self) == is_caps_lock(self)) { - /* ChiEng mode does not agree each other */ - set_caps_led(!ibus_chewing_engine_is_chinese_mode(self), selfp->pDisplay); - } + IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_IM (deprecated)"); } else if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_KEYBOARD)) { IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_KEYBOARD"); - chewing_set_ChiEngMode(self->icPreEdit->context, (is_caps_lock(self)) ? 0 : CHINESE_MODE); + gboolean caps_lock_on = gdk_device_get_caps_lock_state(keyboard); + chewing_set_ChiEngMode(self->icPreEdit->context, caps_lock_on ? 0 : CHINESE_MODE); } self_refresh_property(self, "InputMode"); } @@ -1220,18 +1208,8 @@ void ibus_chewing_engine_property_activate(IBusEngine * engine, /* Toggle Chinese <-> English */ ibus_chewing_pre_edit_toggle_chi_eng_mode(self->icPreEdit); IBUS_CHEWING_LOG(INFO, - "property_activate chinese=%d caps_lock=%d", - ibus_chewing_engine_is_chinese_mode(self), - is_caps_lock(self)); - - if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM) - || ibus_chewing_pre_edit_has_flag(self->icPreEdit, - FLAG_SYNC_FROM_KEYBOARD)) { - if (ibus_chewing_engine_is_chinese_mode(self) == is_caps_lock(self)) { - set_caps_led(!ibus_chewing_engine_is_chinese_mode(self), - selfp->pDisplay); - } - } + "property_activate chinese=%d", + ibus_chewing_engine_is_chinese_mode(self)); ibus_chewing_engine_refresh_property(self, prop_name); } else if (STRING_EQUALS(prop_name, "AlnumSize")) { /* Toggle Full <-> Half */ diff --git a/src/ibus-chewing-engine.h b/src/ibus-chewing-engine.h index 7c85759..32afc88 100644 --- a/src/ibus-chewing-engine.h +++ b/src/ibus-chewing-engine.h @@ -27,8 +27,6 @@ #define GETTEXT_PACKAGE "gtk30" #include #include -#include -#include #include #include "IBusChewingUtil.h" #include "IBusChewingProperties.h" diff --git a/src/setup/ibus-setup-chewing-window.ui b/src/setup/ibus-setup-chewing-window.ui index dcb8881..d92073d 100644 --- a/src/setup/ibus-setup-chewing-window.ui +++ b/src/setup/ibus-setup-chewing-window.ui @@ -59,16 +59,14 @@ True Intelligent Phrasing - Enable or disable automatic candidate - selection + Enable or disable automatic candidate selection Show Systray Icon Whether to show the systray icon - This feature is currently not - implemented. + This feature is currently not implemented. False @@ -82,16 +80,14 @@ True Auto Move Cursor - Automatically move the cursor to the - next character after selection + Automatically move the cursor to the next character after selection True Add Phrase Before Cursor - Use Ctrl + Numbers (2-9) to save new - phrase before or after the cursor + Use Ctrl + Numbers (2-9) to save new phrase before or after the cursor @@ -104,15 +100,13 @@ True Easy Symbol Input - Press Shift + keys to input Chinese - punctuation symbols + Press Shift + keys to input Chinese punctuation symbols Esc Clean All Buffer - Escape key discards all uncommitted - texts + Escape key discards all uncommitted texts @@ -126,8 +120,7 @@ Maximum Chinese Characters - Until how many characters should - trigger auto-commit + Until how many characters should trigger auto-commit @@ -152,7 +145,6 @@ Disable Syncing Sync with Keyboard State - Sync with IM State @@ -171,8 +163,7 @@ Default English Letter Case - The letter case without pressing the - Shift key + The letter case without pressing the Shift key @@ -180,8 +171,7 @@ Selecting - Configure the candidate selection - behavior + Configure the candidate selection behavior @@ -205,8 +195,7 @@ True Choose Phrases Backwards - Open candidate list from the last - character of a phrase + Open candidate list from the last character of a phrase @@ -219,8 +208,7 @@ True Use Vertical Candidate Panel - Choose from vertical or horizontal - panel + Choose from vertical or horizontal panel From fff61d1fab4361dc79f30d1c66648a3d9f90ced3 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 5 Feb 2024 22:50:01 +0900 Subject: [PATCH 18/24] fix: using Shift_L or Shift_R as toggle key --- src/IBusChewingPreEdit-private.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/IBusChewingPreEdit-private.h b/src/IBusChewingPreEdit-private.h index 03e50b8..8271c27 100644 --- a/src/IBusChewingPreEdit-private.h +++ b/src/IBusChewingPreEdit-private.h @@ -33,7 +33,8 @@ (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "default-english-case"), "uppercase") ? 'u' : 'n') # define chi_eng_toggle_key (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "caps_lock")) ? 'c' : \ (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "shift")) ? 's' : \ - (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "shift_l") ? 'l' : 'n') + (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "shift_l")) ? 'l' : \ + (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "shift_r") ? 'r' : 'n') /*== Conditional Expression Shortcut ==*/ # define is_plain_zhuyin ibus_chewing_pre_edit_get_property_boolean(self, "plain-zhuyin") From b306e33de15f06939883519bf6ec4f18d18057bc Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Tue, 6 Feb 2024 19:14:03 +0900 Subject: [PATCH 19/24] fix: null check for gdk_seat_get_keyboard --- src/ibus-chewing-engine.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c index 59b2012..4bcbd17 100644 --- a/src/ibus-chewing-engine.c +++ b/src/ibus-chewing-engine.c @@ -431,14 +431,16 @@ ibus_chewing_engine_restore_mode (IBusChewingEngine * self) GdkDisplay *display = gdk_display_get_default(); if (display != NULL) { GdkSeat *seat = gdk_display_get_default_seat(display); - GdkDevice *keyboard = gdk_seat_get_keyboard(seat); - /* Restore Led Mode only make sense if display is available */ - if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM)) { - IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_IM (deprecated)"); - } else if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_KEYBOARD)) { - IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_KEYBOARD"); - gboolean caps_lock_on = gdk_device_get_caps_lock_state(keyboard); - chewing_set_ChiEngMode(self->icPreEdit->context, caps_lock_on ? 0 : CHINESE_MODE); + if (seat != NULL) { + GdkDevice *keyboard = gdk_seat_get_keyboard(seat); + /* Restore Led Mode only make sense if display is available */ + if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM)) { + IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_IM (deprecated)"); + } else if (keyboard != NULL && ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_KEYBOARD)) { + IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_KEYBOARD"); + gboolean caps_lock_on = gdk_device_get_caps_lock_state(keyboard); + chewing_set_ChiEngMode(self->icPreEdit->context, caps_lock_on ? 0 : CHINESE_MODE); + } } self_refresh_property(self, "InputMode"); } From d7b74d751793e95a89ee2ba4586432342b3470c3 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Tue, 6 Feb 2024 08:20:24 +0900 Subject: [PATCH 20/24] ci: use headless wayland display to run test --- .github/workflows/ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07065de..c5819e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - name: Install build dependencies - run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libX11-devel libchewing-devel ibus gettext xorg-x11-server-Xvfb dbus-x11 util-linux + run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston - name: Build run: | @@ -28,7 +28,8 @@ jobs: - name: Test run: | glib-compile-schemas src/setup --targetdir=out/build/default/bin - xvfb-run -a cmake --build --preset default -t test --verbose + weston --no-config --socket=wl-headless --backend=headless & + WAYLAND_DISPLAY=wl-headless cmake --build --preset default -t test --verbose coverage: runs-on: ubuntu-latest @@ -38,7 +39,7 @@ jobs: - uses: actions/checkout@v4 - name: Install build dependencies - run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libX11-devel libchewing-devel ibus gettext xorg-x11-server-Xvfb dbus-x11 util-linux + run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston - name: Install llvm run: | @@ -62,7 +63,8 @@ jobs: run: | source "$HOME/.cargo/env" glib-compile-schemas src/setup --targetdir=out/build/c99-coverage/bin - xvfb-run -a cmake --build --preset c99-coverage -t test --verbose + weston --no-config --socket=wl-headless --backend=headless & + WAYLAND_DISPLAY=wl-headless cmake --build --preset c99-coverage -t test --verbose ./grcov . -s . -b . --keep-only 'src/*' --llvm -t lcov -o coverage.lcov - name: Upload coverage reports to Codecov From 57c9c8b8c9568863a0486625825ef77ba3a399d1 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Tue, 6 Feb 2024 08:31:05 +0900 Subject: [PATCH 21/24] ci: set XDG_RUNTIME_DIR --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5819e5..a4207df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,8 @@ jobs: cmake --build --preset default -t install --verbose - name: Test + env: + XDG_RUNTIME_DIR: /tmp run: | glib-compile-schemas src/setup --targetdir=out/build/default/bin weston --no-config --socket=wl-headless --backend=headless & @@ -60,6 +62,8 @@ jobs: cmake --build --preset c99-coverage --verbose - name: Test + env: + XDG_RUNTIME_DIR: /tmp run: | source "$HOME/.cargo/env" glib-compile-schemas src/setup --targetdir=out/build/c99-coverage/bin From a7a2dee8b0c70ff137f8a2120c1de038aad30a4d Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Tue, 6 Feb 2024 19:26:12 +0900 Subject: [PATCH 22/24] ci: install dbus-x11 for dbus-launch --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4207df..f5e70ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - name: Install build dependencies - run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston + run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston dbus-x11 - name: Build run: | @@ -41,7 +41,7 @@ jobs: - uses: actions/checkout@v4 - name: Install build dependencies - run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston + run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston dbus-x11 - name: Install llvm run: | From cc774e7b59e21260fac011eb32d7da75c3a7ba48 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Tue, 6 Feb 2024 21:00:19 +0900 Subject: [PATCH 23/24] ci: use keyfile gsettings backend instead of dconf --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5e70ed..57f6ad3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - name: Install build dependencies - run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston dbus-x11 + run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston - name: Build run: | @@ -28,6 +28,7 @@ jobs: - name: Test env: XDG_RUNTIME_DIR: /tmp + GSETTINGS_BACKEND: keyfile run: | glib-compile-schemas src/setup --targetdir=out/build/default/bin weston --no-config --socket=wl-headless --backend=headless & @@ -41,7 +42,7 @@ jobs: - uses: actions/checkout@v4 - name: Install build dependencies - run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston dbus-x11 + run: sudo dnf -y install clang cmake gtk4-devel ibus-devel libadwaita-devel libchewing-devel ibus gettext weston - name: Install llvm run: | @@ -64,6 +65,7 @@ jobs: - name: Test env: XDG_RUNTIME_DIR: /tmp + GSETTINGS_BACKEND: keyfile run: | source "$HOME/.cargo/env" glib-compile-schemas src/setup --targetdir=out/build/c99-coverage/bin From 712697a6e40f1bdb4d59b516f1e56f0c00d236f2 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Tue, 6 Feb 2024 21:13:02 +0900 Subject: [PATCH 24/24] refactor: remove leftover todo comments --- src/ibus-chewing-engine.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c index 4bcbd17..7c07fa0 100644 --- a/src/ibus-chewing-engine.c +++ b/src/ibus-chewing-engine.c @@ -107,8 +107,6 @@ typedef IBusChewingEngineClass SelfClass; G_DEFINE_TYPE_WITH_CODE(IBusChewingEngine, ibus_chewing_engine, IBUS_TYPE_ENGINE, G_ADD_PRIVATE(IBusChewingEngine)); /* here are local prototypes */ -// static void ibus_chewing_engine_init (IBusChewingEngine * self) G_GNUC_UNUSED; -// static void ibus_chewing_engine_class_init (IBusChewingEngineClass * klass) G_GNUC_UNUSED; static void ibus_chewing_engine_constructor (IBusChewingEngine * self) G_GNUC_UNUSED; static IBusProperty * ibus_chewing_engine_get_ibus_property_by_name (IBusChewingEngine * self, const gchar * prop_name) G_GNUC_UNUSED; static void ___b_ibus_chewing_engine_reset (IBusEngine * engine) G_GNUC_UNUSED; @@ -200,7 +198,6 @@ static void ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::init" - // ibus_chewing_engine_get_instance_private (self) = G_TYPE_INSTANCE_GET_PRIVATE(self,IBUS_TYPE_CHEWING_ENGINE,IBusChewingEnginePrivate); self->icPreEdit = NULL; self->sDialog = NULL; self->preEditText = NULL; @@ -305,7 +302,6 @@ ibus_chewing_engine_class_init (IBusChewingEngineClass * klass G_GNUC_UNUSED) GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) klass; IBusEngineClass *ibus_engine_class = (IBusEngineClass *)klass; - // g_type_class_add_private(klass,sizeof(IBusChewingEnginePrivate)); klass->InputMode_label_chi = g_object_ref_sink(ibus_text_new_from_static_string(_("Chinese Mode"))) ;