1 /*************************************************************************** 2 * Copyright (C) 2011~2012 by CSSlayer * 3 * wengxt@gmail.com * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * 19 ***************************************************************************/ 20 21 #ifndef FCITX_CLOUDPINYIN_H 22 #define FCITX_CLOUDPINYIN_H 23 #include <curl/curl.h> 24 #include <fcitx-config/fcitx-config.h> 25 #include <fcitx/instance.h> 26 #include <libintl.h> 27 28 #define SOGOU_KEY_LENGTH 32 29 #define QQ_KEY_LENGTH 32 30 #define MAX_CACHE_ENTRY 2048 31 #define MAX_ERROR 10 32 #define MAX_HANDLE 100l 33 34 #define _(x) dgettext("fcitx-cloudpinyin", (x)) 35 36 typedef enum { 37 CloudPinyin_Google = 0, 38 CloudPinyin_Baidu = 1 39 } CloudPinyinSource; 40 41 typedef enum { 42 RequestKey, 43 RequestPinyin 44 } CloudPinyinRequestType ; 45 46 typedef struct { 47 boolean used; 48 CURL* curl; 49 } CurlFreeListItem; 50 51 typedef struct _CurlQueue { 52 CURL* curl; 53 struct _CurlQueue* next; 54 CloudPinyinRequestType type; 55 int curl_result; 56 long http_code; 57 char* str; 58 char* pinyin; 59 size_t size; 60 CloudPinyinSource source; 61 } CurlQueue; 62 63 typedef struct { 64 char* pinyin; 65 char* str; 66 UT_hash_handle hh; 67 } CloudPinyinCache; 68 69 typedef struct { 70 FcitxGenericConfig config; 71 int iCandidateOrder; 72 int iMinimumPinyinLength; 73 boolean bDontShowSource; 74 CloudPinyinSource source; 75 FcitxHotkeys hkToggle; 76 boolean bEnabled; 77 } FcitxCloudPinyinConfig; 78 79 typedef struct { 80 FcitxInstance* owner; 81 FcitxCloudPinyinConfig config; 82 CurlQueue* pendingQueue; 83 CurlQueue* finishQueue; 84 85 pthread_mutex_t pendingQueueLock; 86 pthread_mutex_t finishQueueLock; 87 88 int pipeNotify; 89 int pipeRecv; 90 int errorcount; 91 char key[SOGOU_KEY_LENGTH + 1]; 92 boolean initialized; 93 CloudPinyinCache* cache; 94 boolean isrequestkey; 95 struct _FcitxFetchThread* fetch; 96 97 CurlFreeListItem freeList[MAX_HANDLE]; 98 99 pthread_t pid; 100 } FcitxCloudPinyin; 101 102 CONFIG_BINDING_DECLARE(FcitxCloudPinyinConfig); 103 104 #endif 105 // kate: indent-mode cstyle; space-indent on; indent-width 0; 106