Codebase list fcitx-cloudpinyin / 3157f7d
Merge tag 'upstream/0.3.1' Upstream version 0.3.1 Conflicts: .gitignore YunQiang Su 11 years ago
12 changed file(s) with 250 addition(s) and 240 deletion(s). Raw diff Collapse all Expand all
11 cmake_minimum_required(VERSION 2.6)
22
33 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
4 find_package(Fcitx 4.2.6 REQUIRED)
4 find_package(Fcitx 4.2.7 REQUIRED)
55 find_package(PkgConfig REQUIRED)
6 find_package(Gettext REQUIRED)
76 find_package(Libintl REQUIRED)
87 find_package(Libiconv REQUIRED)
98 find_package(Pthread REQUIRED)
109
11 # uninstall target
12 configure_file(
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
14 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
15 IMMEDIATE @ONLY)
10 _fcitx_add_uninstall_target()
1611
1712 set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -fvisibility=hidden ${CMAKE_C_FLAGS}")
1813 set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -fvisibility=hidden ${CMAKE_CXX_FLAGS}")
1914 set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_SHARED_LINKER_FLAGS}")
2015 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_MODULE_LINKER_FLAGS}")
21
22 add_custom_target(uninstall
23 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
2416
2517 pkg_check_modules(CURL "libcurl" REQUIRED)
2618
3022
3123 enable_testing()
3224
25 add_subdirectory(po)
3326 add_subdirectory(src)
34 add_subdirectory(po)
35 add_subdirectory(test)
27 add_subdirectory(test)
11 Version 2, June 1991
22
33 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
4 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
55 Everyone is permitted to copy and distribute verbatim copies
66 of this license document, but changing it is not allowed.
77
304304
305305 You should have received a copy of the GNU General Public License
306306 along with this program; if not, write to the Free Software
307 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
307 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
308308
309309
310310 Also add information on how to contact you by electronic and paper mail.
0 this is a standalone module for fcitx, it can use pinyin API on the internet
1 to input.
2
3 Requires Fcitx 4.1.0 (Currently is not released).
0 Fcitx-Cloudpinyin is a standalone module for fcitx that uses web API to provide better pinyin result.
88 # present in libc. Must have more robust system for release, where Gettext
99 # functionality can also reside in standalone Gettext library, or the one
1010 # embedded within kdelibs (cf. gettext.m4 from Gettext source).
11
11
1212 # Copyright (c) 2006, Chusslove Illich, <caslav.ilic@gmx.net>
1313 # Copyright (c) 2007, Alexander Neundorf, <neundorf@kde.org>
1414 #
1515 # Redistribution and use is allowed according to the terms of the BSD license.
1616 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
17
17
1818 if(LIBINTL_INCLUDE_DIR AND LIBINTL_LIB_FOUND)
1919 set(Libintl_FIND_QUIETLY TRUE)
20 endif(LIBINTL_INCLUDE_DIR AND LIBINTL_LIB_FOUND)
21
20 endif()
21
2222 find_path(LIBINTL_INCLUDE_DIR libintl.h)
23
23
2424 set(LIBINTL_LIB_FOUND FALSE)
25
25
2626 if(LIBINTL_INCLUDE_DIR)
2727 include(CheckFunctionExists)
2828 check_function_exists(dgettext LIBINTL_LIBC_HAS_DGETTEXT)
29
30 if (LIBINTL_LIBC_HAS_DGETTEXT)
29
30 if(LIBINTL_LIBC_HAS_DGETTEXT)
3131 set(LIBINTL_LIBRARIES)
3232 set(LIBINTL_LIB_FOUND TRUE)
33 else (LIBINTL_LIBC_HAS_DGETTEXT)
34 find_library(LIBINTL_LIBRARIES NAMES intl libintl )
33 else()
34 find_library(LIBINTL_LIBRARIES NAMES intl libintl)
3535 if(LIBINTL_LIBRARIES)
3636 set(LIBINTL_LIB_FOUND TRUE)
37 endif(LIBINTL_LIBRARIES)
38 endif (LIBINTL_LIBC_HAS_DGETTEXT)
39
37 endif()
38 endif()
4039 endif(LIBINTL_INCLUDE_DIR)
41
40
4241 include(FindPackageHandleStandardArgs)
43 find_package_handle_standard_args(Libintl DEFAULT_MSG LIBINTL_INCLUDE_DIR LIBINTL_LIB_FOUND)
44
45 mark_as_advanced(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARIES LIBINTL_LIBC_HAS_DGETTEXT LIBINTL_LIB_FOUND)
42 find_package_handle_standard_args(Libintl DEFAULT_MSG LIBINTL_INCLUDE_DIR
43 LIBINTL_LIB_FOUND)
44
45 mark_as_advanced(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARIES
46 LIBINTL_LIBC_HAS_DGETTEXT LIBINTL_LIB_FOUND)
0 file(GLOB PO_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.po)
1 file(RELATIVE_PATH REL_SOURCE_ROOT ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR})
2 if ("${REL_SOURCE_ROOT}" STREQUAL "")
3 set(REL_SOURCE_ROOT ".")
4 endif("${REL_SOURCE_ROOT}" STREQUAL "")
5
6 set(POT_FILE fcitx-cloudpinyin.pot)
7
8 configure_file(POTFILES.in.in ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in)
9
10 extract_fcitx_addon_conf_postring()
11 extract_fcitx_desc_file_postring()
12
13 add_custom_target(
14 pot
15 COMMAND INTLTOOL_EXTRACT=${INTLTOOL_EXTRACT} srcdir=${CMAKE_CURRENT_BINARY_DIR} ${INTLTOOL_UPDATE} --gettext-package fcitx-cloudpinyin --pot
16 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
17 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conf.po ${CMAKE_CURRENT_BINARY_DIR}/desc.po
18 )
19
20 # Update .po files and compile them to binary .gmo files
21 gettext_create_translations(${POT_FILE} ALL ${PO_FILES})
22
0 set(PO_LANGS zh_CN zh_TW)
1 foreach(lang ${PO_LANGS})
2 fcitx_translate_add_po_file("${lang}" "${lang}.po")
3 endforeach()
4 fcitx_translate_set_pot_target(pot fcitx-cloudpinyin fcitx-cloudpinyin.pot)
+0
-5
po/POTFILES.in.in less more
0 # List of source files which contain translatable strings.
1 ./po/desc.po
2 ./po/conf.po
3 @REL_SOURCE_ROOT@/src/cloudpinyin.c
4 @REL_SOURCE_ROOT@/src/fcitx-cloudpinyin.conf.in
66 msgid ""
77 msgstr ""
88 "Project-Id-Version: PACKAGE VERSION\n"
9 "Report-Msgid-Bugs-To: \n"
10 "POT-Creation-Date: 2012-08-29 18:07-0400\n"
9 "Report-Msgid-Bugs-To: fcitx-dev@googlegroups.com\n"
10 "POT-Creation-Date: 2012-12-01 18:57-0500\n"
1111 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313 "Language-Team: LANGUAGE <LL@li.org>\n"
14 "Language: \n"
14 "Language: LANG\n"
1515 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=CHARSET\n"
16 "Content-Type: text/plain; charset=utf-8\n"
1717 "Content-Transfer-Encoding: 8bit\n"
1818
19 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:5
19 #: src/cloudpinyin.c:607
20 msgid " (via cloud)"
21 msgstr ""
22
23 #: src/fcitx-cloudpinyin.conf.in:3
24 msgid "Cloud Pinyin"
25 msgstr ""
26
27 #: src/fcitx-cloudpinyin.conf.in:4
28 msgid "Add Cloud Pinyin Support to Pinyin Input Method"
29 msgstr ""
30
31 #: src/fcitx-cloudpinyin.desc:1 src/fcitx-cloudpinyin.desc:7
32 #: src/fcitx-cloudpinyin.desc:13 src/fcitx-cloudpinyin.desc:18
33 msgid "CloudPinyin"
34 msgstr ""
35
36 #: src/fcitx-cloudpinyin.desc:5
2037 msgid "Cloud Pinyin Candidate Word Order"
2138 msgstr ""
2239
23 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:11
40 #: src/fcitx-cloudpinyin.desc:11
2441 msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
2542 msgstr ""
2643
27 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:16
44 #: src/fcitx-cloudpinyin.desc:16
2845 msgid "Don't Show the 'via cloud' hint"
2946 msgstr ""
3047
31 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:21
48 #: src/fcitx-cloudpinyin.desc:21
3249 msgid "Cloud Pinyin Source"
3350 msgstr ""
3451
35 # unknown
36 msgid "CloudPinyin"
52 #: src/fcitx-cloudpinyin.desc:23
53 msgid "Sogou"
3754 msgstr ""
3855
39 #: unknown
40 msgid "Baidu"
56 #: src/fcitx-cloudpinyin.desc:24
57 msgid "QQ"
4158 msgstr ""
4259
43 #: unknown
60 #: src/fcitx-cloudpinyin.desc:25
4461 msgid "Google"
4562 msgstr ""
4663
47 #: unknown
48 msgid "QQ"
64 #: src/fcitx-cloudpinyin.desc:26
65 msgid "Baidu"
4966 msgstr ""
50
51 #: unknown
52 msgid "Sogou"
53 msgstr ""
54
55 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:1
56 msgid "Cloud Pinyin"
57 msgstr ""
58
59 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:2
60 msgid "Add Cloud Pinyin Support to Pinyin Input Method"
61 msgstr ""
62
63 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:588
64 msgid " (via cloud)"
65 msgstr ""
00 # SOME DESCRIPTIVE TITLE.
11 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22 # This file is distributed under the same license as the PACKAGE package.
3 #
3 #
44 # Translators:
5 # Christopher Meng <cickumqt@gmail.com>, 2012.
56 # Weng Xuetian <wengxt@gmail.com>, 2011.
67 msgid ""
78 msgstr ""
89 "Project-Id-Version: fcitx\n"
9 "Report-Msgid-Bugs-To: \n"
10 "POT-Creation-Date: 2012-08-29 18:07-0400\n"
11 "PO-Revision-Date: 2012-08-29 20:00-0400\n"
12 "Last-Translator: Yichao Yu <yyc1992@gmail.com>\n"
10 "Report-Msgid-Bugs-To: fcitx-dev@googlegroups.com\n"
11 "POT-Creation-Date: 2012-12-01 18:57-0500\n"
12 "PO-Revision-Date: 2012-09-02 06:46+0000\n"
13 "Last-Translator: Xuetian Weng <wengxt@gmail.com>\n"
1314 "Language-Team: Chinese (China) <fcitx-dev@googlegroups.com>\n"
14 "Language: zh_CN\n"
1515 "MIME-Version: 1.0\n"
1616 "Content-Type: text/plain; charset=UTF-8\n"
1717 "Content-Transfer-Encoding: 8bit\n"
18 "Plural-Forms: nplurals=1; plural=0\n"
18 "Language: zh_CN\n"
19 "Plural-Forms: nplurals=1; plural=0;\n"
1920
20 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:588
21 #: src/cloudpinyin.c:607
2122 msgid " (via cloud)"
2223 msgstr " (来自云)"
2324
24 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:2
25 #: src/fcitx-cloudpinyin.conf.in:3
26 msgid "Cloud Pinyin"
27 msgstr "云拼音"
28
29 #: src/fcitx-cloudpinyin.conf.in:4
2530 msgid "Add Cloud Pinyin Support to Pinyin Input Method"
2631 msgstr "为拼音输入法加入云拼音支持"
2732
28 #: unknown
29 msgid "Baidu"
30 msgstr "百度"
31
32 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:1
33 msgid "Cloud Pinyin"
33 #: src/fcitx-cloudpinyin.desc:1 src/fcitx-cloudpinyin.desc:7
34 #: src/fcitx-cloudpinyin.desc:13 src/fcitx-cloudpinyin.desc:18
35 msgid "CloudPinyin"
3436 msgstr "云拼音"
3537
36 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:5
38 #: src/fcitx-cloudpinyin.desc:5
3739 msgid "Cloud Pinyin Candidate Word Order"
3840 msgstr "云拼音候选词顺序"
3941
40 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:21
42 #: src/fcitx-cloudpinyin.desc:11
43 msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
44 msgstr "最小触发云拼音的拼音长度"
45
46 #: src/fcitx-cloudpinyin.desc:16
47 msgid "Don't Show the 'via cloud' hint"
48 msgstr "不显示‘来自云’提示"
49
50 #: src/fcitx-cloudpinyin.desc:21
4151 msgid "Cloud Pinyin Source"
4252 msgstr "云拼音来源"
4353
44 # unknown
45 msgid "CloudPinyin"
46 msgstr "云拼音"
54 #: src/fcitx-cloudpinyin.desc:23
55 msgid "Sogou"
56 msgstr "搜狗"
4757
48 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:16
49 msgid "Don't Show the 'via cloud' hint"
50 msgstr "不显示‘来自云’提示"
58 #: src/fcitx-cloudpinyin.desc:24
59 msgid "QQ"
60 msgstr "QQ"
5161
52 #: unknown
62 #: src/fcitx-cloudpinyin.desc:25
5363 msgid "Google"
5464 msgstr "Google"
5565
56 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:11
57 msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
58 msgstr "最小触发云拼音的拼音长度"
59
60 #: unknown
61 msgid "QQ"
62 msgstr "QQ"
63
64 #: unknown
65 msgid "Sogou"
66 msgstr "搜狗"
67
68 #~ msgid "Only use origin Pinyin to query the result"
69 #~ msgstr "只使用原始拼音查询结果"
66 #: src/fcitx-cloudpinyin.desc:26
67 msgid "Baidu"
68 msgstr "百度"
00 # SOME DESCRIPTIVE TITLE.
11 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
22 # This file is distributed under the same license as the PACKAGE package.
3 #
3 #
44 # Translators:
5 # <alisha.4m@gmail.com>, 2012.
56 # Alisha <alisha.4m@gmail.com>, 2012.
67 msgid ""
78 msgstr ""
89 "Project-Id-Version: fcitx\n"
9 "Report-Msgid-Bugs-To: \n"
10 "POT-Creation-Date: 2012-08-29 18:07-0400\n"
11 "PO-Revision-Date: 2012-01-26 16:05+0000\n"
10 "Report-Msgid-Bugs-To: fcitx-dev@googlegroups.com\n"
11 "POT-Creation-Date: 2012-12-01 18:57-0500\n"
12 "PO-Revision-Date: 2012-09-11 00:12+0000\n"
1213 "Last-Translator: Alisha <alisha.4m@gmail.com>\n"
13 "Language-Team: Chinese (Taiwan) (http://www.transifex.net/projects/p/fcitx/"
14 "language/zh_TW/)\n"
15 "Language: zh_TW\n"
14 "Language-Team: Chinese (Taiwan) (http://www.transifex.com/projects/p/fcitx/language/zh_TW/)\n"
1615 "MIME-Version: 1.0\n"
1716 "Content-Type: text/plain; charset=UTF-8\n"
1817 "Content-Transfer-Encoding: 8bit\n"
19 "Plural-Forms: nplurals=1; plural=0\n"
18 "Language: zh_TW\n"
19 "Plural-Forms: nplurals=1; plural=0;\n"
2020
21 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:588
21 #: src/cloudpinyin.c:607
2222 msgid " (via cloud)"
2323 msgstr "(來自雲)"
2424
25 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:2
25 #: src/fcitx-cloudpinyin.conf.in:3
26 msgid "Cloud Pinyin"
27 msgstr "雲拼音"
28
29 #: src/fcitx-cloudpinyin.conf.in:4
2630 msgid "Add Cloud Pinyin Support to Pinyin Input Method"
2731 msgstr "為拼音輸入法加入雲拼音支援"
2832
29 #: unknown
30 msgid "Baidu"
31 msgstr ""
32
33 #: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:1
34 msgid "Cloud Pinyin"
33 #: src/fcitx-cloudpinyin.desc:1 src/fcitx-cloudpinyin.desc:7
34 #: src/fcitx-cloudpinyin.desc:13 src/fcitx-cloudpinyin.desc:18
35 msgid "CloudPinyin"
3536 msgstr "雲拼音"
3637
37 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:5
38 #: src/fcitx-cloudpinyin.desc:5
3839 msgid "Cloud Pinyin Candidate Word Order"
3940 msgstr "雲拼音候選字順序"
4041
41 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:21
42 #: src/fcitx-cloudpinyin.desc:11
43 msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
44 msgstr "最小觸發雲拼音的拼音長度"
45
46 #: src/fcitx-cloudpinyin.desc:16
47 msgid "Don't Show the 'via cloud' hint"
48 msgstr "不顯示「來自雲」提示"
49
50 #: src/fcitx-cloudpinyin.desc:21
4251 msgid "Cloud Pinyin Source"
4352 msgstr "雲拼音來源"
4453
45 # unknown
46 msgid "CloudPinyin"
47 msgstr "雲拼音"
54 #: src/fcitx-cloudpinyin.desc:23
55 msgid "Sogou"
56 msgstr "搜狗"
4857
49 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:16
50 msgid "Don't Show the 'via cloud' hint"
51 msgstr "不顯示「來自雲」提示"
58 #: src/fcitx-cloudpinyin.desc:24
59 msgid "QQ"
60 msgstr "QQ"
5261
53 #: unknown
62 #: src/fcitx-cloudpinyin.desc:25
5463 msgid "Google"
5564 msgstr "Google"
5665
57 #: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:11
58 msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
59 msgstr "最小觸發雲拼音的拼音長度"
60
61 #: unknown
62 msgid "QQ"
63 msgstr "QQ"
64
65 #: unknown
66 msgid "Sogou"
67 msgstr "搜狗"
68
69 #~ msgid "Only use origin Pinyin to query the result"
70 #~ msgstr "只使用原始拼音查詢結果"
66 #: src/fcitx-cloudpinyin.desc:26
67 msgid "Baidu"
68 msgstr "百度"
00 include_directories(
1 ${PROJECT_BINARY_DIR}
2 ${CMAKE_CURRENT_SOURCE_DIR}
3 ${CURL_INCLUDE_DIRS}
4 ${PTHREAD_INCLUDE_DIR}
5 ${FCITX4_FCITX_INCLUDE_DIRS}
6 ${FCITX4_FCITX_CONFIG_INCLUDE_DIRS}
7 ${FCITX4_FCITX_UTILS_INCLUDE_DIRS}
8 ${LIBINTL_INCLUDE_DIR}
9 )
1 ${PROJECT_BINARY_DIR}
2 ${CMAKE_CURRENT_SOURCE_DIR}
3 ${CURL_INCLUDE_DIRS}
4 ${PTHREAD_INCLUDE_DIR}
5 ${FCITX4_FCITX_INCLUDE_DIRS}
6 ${FCITX4_FCITX_CONFIG_INCLUDE_DIRS}
7 ${FCITX4_FCITX_UTILS_INCLUDE_DIRS}
8 ${LIBINTL_INCLUDE_DIR}
9 )
1010
1111 link_directories(
12 ${CURL_LIBRARY_DIRS}
13 )
12 ${CURL_LIBRARY_DIRS}
13 )
1414
1515 set(FCITX_CLOUDPINYIN_SRCS
16 cloudpinyin.c
17 cloudpinyinconifg.c
18 fetch.c
19 parse.c
20 )
16 cloudpinyin.c
17 cloudpinyinconifg.c
18 fetch.c
19 parse.c
20 )
2121
22 fcitx_add_addon(fcitx-cloudpinyin ${FCITX_CLOUDPINYIN_SRCS})
23 target_link_libraries( fcitx-cloudpinyin
24 ${CURL_LIBRARIES}
25 ${LIBINTL_LIBRARIES}
26 ${PTHREAD_LIBRARIES}
27 )
28
29 fcitx_add_addon_conf_file(fcitx-cloudpinyin.conf)
30 fcitx_add_configdesc_file(fcitx-cloudpinyin.desc)
22 fcitx_add_addon_full(cloudpinyin DESC
23 SOURCES ${FCITX_CLOUDPINYIN_SRCS}
24 LINK_LIBS ${CURL_LIBRARIES}
25 ${LIBINTL_LIBRARIES}
26 ${PTHREAD_LIBRARIES})
3232 #include <fcitx-utils/log.h>
3333 #include <fcitx/candidate.h>
3434 #include <fcitx-config/xdg.h>
35 #include <fcitx/module/pinyin/pydef.h>
35 #include <fcitx/module/pinyin/fcitx-pinyin.h>
3636
3737 #include "cloudpinyin.h"
3838 #include "fetch.h"
3939 #include "parse.h"
4040
41 #define CHECK_VALID_IM (im && \
41 DEFINE_GET_ADDON("fcitx-sunpinyin", SunPinyin)
42 DEFINE_GET_ADDON("fcitx-libpinyin", LibPinyin)
43 DEFINE_GET_ADDON("fcitx-sogoupinyin", SogouPinyin)
44 DEFINE_GET_AND_INVOKE_FUNC(SunPinyin, GetFullPinyin, 0)
45 DEFINE_GET_AND_INVOKE_FUNC(SunPinyin, AddWord, 1)
46
47 // Maybe not the right name, but doesn't matter....
48 DEFINE_GET_AND_INVOKE_FUNC(LibPinyin, AddWord, 0)
49 DEFINE_GET_AND_INVOKE_FUNC(SogouPinyin, AddWord, 0)
50
51 #define CHECK_VALID_IM (im && \
4252 strcmp(im->langCode, "zh_CN") == 0 && \
4353 (strcmp(im->uniqueName, "pinyin") == 0 || \
4454 strcmp(im->uniqueName, "pinyin-libpinyin") == 0 || \
4959 strcmp(im->uniqueName, "sogou-pinyin") == 0))
5060
5161 #define CLOUDPINYIN_CHECK_PAGE_NUMBER 3
52
53 #define LOGLEVEL DEBUG
5462
5563 typedef struct _CloudCandWord {
5664 boolean filled;
150158 } else {
151159 FcitxMessagesAddMessageAtLast(message, MSG_INPUT, "%s", str);
152160 }
153 if (string)
154 free(string);
161 fcitx_utils_free(string);
155162 FcitxInstanceUpdateClientSideUI(
156163 cloudpinyin->owner, FcitxInstanceGetCurrentIC(cloudpinyin->owner));
157164 }
278285
279286 if (inputString) {
280287 CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, inputString);
281 FcitxLog(LOGLEVEL, "%s", inputString);
288 FcitxLog(DEBUG, "%s", inputString);
282289 if (cacheEntry == NULL)
283290 CloudPinyinAddInputRequest(cloudpinyin, inputString);
284291 _CloudPinyinAddCandidateWord(cloudpinyin, inputString);
346353 void CloudPinyinProcessEvent(void* arg)
347354 {
348355 FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg;
356 FcitxInstance* instance = cloudpinyin->owner;
357 if (!FD_ISSET(cloudpinyin->pipeRecv, FcitxInstanceGetReadFDSet(instance)))
358 return;
359
349360 char c;
350361 while (read(cloudpinyin->pipeRecv, &c, sizeof(char)) > 0);
351362 pthread_mutex_lock(&cloudpinyin->finishQueueLock);
352363 CurlQueue* queue;
353364 queue = cloudpinyin->finishQueue;
365 /* this queue header is empty, so the check condition is "next" not null */
354366 while (queue->next != NULL)
355367 {
368 /* remove pivot from queue, thus pivot need to be free'd in HandleRequest */
356369 CurlQueue* pivot = queue->next;
357370 queue->next = queue->next->next;
358371 CloudPinyinHandleRequest(cloudpinyin, pivot);
362375
363376 void CloudPinyinDestroy(void* arg)
364377 {
365
378 FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg;
379 char c = 1;
380 write(cloudpinyin->pipeNotify, &c, sizeof(char));
381 pthread_join(cloudpinyin->pid, NULL);
382 pthread_mutex_destroy(&cloudpinyin->pendingQueueLock);
383 pthread_mutex_destroy(&cloudpinyin->finishQueueLock);
384 while (cloudpinyin->cache)
385 {
386 CloudPinyinCache* head = cloudpinyin->cache;
387 HASH_DEL(cloudpinyin->cache, cloudpinyin->cache);
388 free(head->pinyin);
389 free(head->str);
390 free(head);
391 }
392
393 close(cloudpinyin->pipeRecv);
394 close(cloudpinyin->pipeNotify);
395
396 close(cloudpinyin->fetch->pipeRecv);
397 close(cloudpinyin->fetch->pipeNotify);
398 int i = 0;
399 for (i = 0; i < MAX_HANDLE; i ++) {
400 if (cloudpinyin->freeList[i].curl) {
401 curl_easy_cleanup(cloudpinyin->freeList[i].curl);
402 }
403 }
404
405 curl_multi_cleanup(cloudpinyin->fetch->curlm);
406 #define _FREE_QUEUE(NAME) \
407 while(NAME) { \
408 CurlQueue* queue = NAME; \
409 NAME = NAME->next; \
410 fcitx_utils_free(queue->str); \
411 fcitx_utils_free(queue->pinyin); \
412 free(queue); \
413 }
414 _FREE_QUEUE(cloudpinyin->pendingQueue)
415 _FREE_QUEUE(cloudpinyin->finishQueue)
416 _FREE_QUEUE(cloudpinyin->fetch->queue)
417 FcitxConfigFree(&cloudpinyin->config.config);
418 free(cloudpinyin->fetch);
419 free(cloudpinyin);
366420 }
367421
368422 void CloudPinyinReloadConfig(void* arg)
444498 strToFree = GetCurrentString(cloudpinyin, &inputString);
445499
446500 if (inputString) {
447 FcitxLog(LOGLEVEL, "fill: %s %s", inputString, queue->pinyin);
501 FcitxLog(DEBUG, "fill: %s %s", inputString, queue->pinyin);
448502 if (strcmp(inputString, queue->pinyin) == 0)
449503 {
450504 if (CHECK_VALID_IM)
471525 }
472526 }
473527 CloudPinyinReleaseCurlHandle(cloudpinyin, queue->curl);
474 if (queue->str)
475 free(queue->str);
476 if (queue->pinyin)
477 free(queue->pinyin);
528 fcitx_utils_free(queue->str);
529 fcitx_utils_free(queue->pinyin);
478530 free(queue);
479531 }
480532
691743 if (py) {
692744 *py = 0;
693745
694 snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s%s", string, candWord->strWord);
746 snprintf(FcitxInputStateGetOutputString(input),
747 MAX_USER_INPUT, "%s%s", string, candWord->strWord);
695748
696749 FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner);
697 FcitxModuleFunctionArg args;
698 args.args[0] = FcitxInputStateGetOutputString(input);
699 if (im)
700 {
701 if (strcmp(im->uniqueName, "sunpinyin") == 0)
702 FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-sunpinyin", 1, args);
703 else if (strcmp(im->uniqueName, "shuangpin") == 0 || strcmp(im->uniqueName, "pinyin") == 0)
704 FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-pinyin", 7, args);
705 else if (strcmp(im->uniqueName, "pinyin-libpinyin") == 0 ||
706 strcmp(im->uniqueName, "shuangpin-libpinyin") == 0)
707 {
708 FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-libpinyin", 0, args);
750 if (im) {
751 char *output_string = FcitxInputStateGetOutputString(input);
752 FCITX_DEF_MODULE_ARGS(args, output_string);
753 if (strcmp(im->uniqueName, "sunpinyin") == 0) {
754 FcitxSunPinyinInvokeAddWord(cloudpinyin->owner, args);
755 } else if (strcmp(im->uniqueName, "shuangpin") == 0 ||
756 strcmp(im->uniqueName, "pinyin") == 0) {
757 FcitxPinyinInvokeAddUserPhrase(cloudpinyin->owner, args);
758 } else if (strcmp(im->uniqueName, "pinyin-libpinyin") == 0 ||
759 strcmp(im->uniqueName, "shuangpin-libpinyin") == 0) {
760 FcitxLibPinyinInvokeAddWord(cloudpinyin->owner, args);
709761 }
710762 else if (strcmp(im->uniqueName, "sogou-pinyin") == 0)
711763 {
712 FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-sogoupinyin", 0, args);
764 FcitxSogouPinyinInvokeAddWord(cloudpinyin->owner, args);
713765 }
714766 }
715767 }
788840
789841 if (*lastpos != '\0') {
790842 char* result = NULL;
791 FcitxModuleFunctionArg arg;
792 arg.args[0] = lastpos;
793843 boolean isshuangpin = false;
794844 if (strcmp(im->uniqueName, "sunpinyin") == 0) {
795 boolean issp = false;
796 arg.args[1] = &issp;
797 result = FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-sunpinyin", 0, arg);
798 isshuangpin = issp;
845 FCITX_DEF_MODULE_ARGS(args, lastpos, &isshuangpin);
846 result = FcitxSunPinyinInvokeGetFullPinyin(
847 cloudpinyin->owner, args);
799848 } else if (strcmp(im->uniqueName, "shuangpin") == 0) {
800849 isshuangpin = true;
801 result = InvokeFunction(cloudpinyin->owner, FCITX_PINYIN, SP2QP, arg);
850 result = FcitxPinyinSP2QP(cloudpinyin->owner, lastpos);
802851 }
803852 if (isshuangpin) {
804853 if (result) {
821870 }
822871 }
823872 }
824
825873 lastpos = pinyin + 1;
826874 }
827875 pinyin ++;
828
829876 } while(endflag);
830877 free(string);
831878 /* no pinyin append, return NULL for off it */
845892 const char* ime_patch_key = "ime_patch_key = \"";
846893 size_t len = strlen(str);
847894 if (len == SOGOU_KEY_LENGTH + strlen(ime_patch_key) + 1
848 && strncmp(str, ime_patch_key, strlen(ime_patch_key)) == 0
849 && str[len - 1] == '\"'
850 )
851 {
895 && strncmp(str, ime_patch_key, strlen(ime_patch_key)) == 0
896 && str[len - 1] == '\"') {
852897 sscanf(str,"ime_patch_key = \"%s\"", cloudpinyin->key);
853898 cloudpinyin->initialized = true;
854899 cloudpinyin->key[SOGOU_KEY_LENGTH] = '\0';
860905 void CloudPinyinHookForNewRequest(void* arg)
861906 {
862907 FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg;
863 if (!cloudpinyin->initialized && !cloudpinyin->isrequestkey)
864 {
908 if (!cloudpinyin->initialized && !cloudpinyin->isrequestkey) {
865909 CloudPinyinRequestKey(cloudpinyin);
866910 }
867911 }
4242 curl_multi_setopt(fetch->curlm, CURLMOPT_MAXCONNECTS, MAX_HANDLE);
4343
4444 while (true) {
45
45 boolean endflag = false;
4646 char c;
47 while (read(fetch->pipeRecv, &c, sizeof(char)) > 0);
47 while (read(fetch->pipeRecv, &c, sizeof(char)) > 0) {
48 if (c == 1)
49 endflag = true;
50 }
51 if (endflag)
52 break;
4853
4954 FetchProcessPendingRequest(fetch);
5055 FetchProcessEvent(fetch);