~ubuntu-branches/ubuntu/precise/fcitx-sunpinyin/precise

« back to all changes in this revision

Viewing changes to .pc/01-fix_shuangpin_fuzzy.patch/src/eim.cpp

  • Committer: Package Import Robot
  • Author(s): Aron Xu, UPSTREAM
  • Date: 2011-10-21 16:42:11 UTC
  • mfrom: (1.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20111021164211-w3aoorjcs609kxop
Tags: 0.3.2-2
debian/patches/01-fix_shuangpin_fuzzy.patch:
[UPSTREAM] Fix a problem in the fuzzy functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010~2010 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
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
 
 
21
#include <stdlib.h>
 
22
#include <stdio.h>
 
23
#include <string.h>
 
24
#include <errno.h>
 
25
#include <ime-core/imi_view.h>
 
26
#include <ime-core/imi_options.h>
 
27
#include <ime-core/utils.h>
 
28
#include <fcitx/ime.h>
 
29
#include <fcitx-config/hotkey.h>
 
30
#include <fcitx-config/xdg.h>
 
31
#include <fcitx-utils/log.h>
 
32
#include <fcitx-config/fcitx-config.h>
 
33
#include <fcitx-utils/utils.h>
 
34
#include <fcitx/instance.h>
 
35
#include <fcitx/keys.h>
 
36
#include <fcitx/module.h>
 
37
#include <string>
 
38
#include <libintl.h>
 
39
 
 
40
#include "handler.h"
 
41
#include "eim.h"
 
42
 
 
43
#define FCITX_SUNPINYIN_MAX(x, y) ((x) > (y)? (x) : (y))
 
44
 
 
45
#ifdef __cplusplus
 
46
extern "C" {
 
47
#endif
 
48
    FCITX_EXPORT_API
 
49
    FcitxIMClass ime = {
 
50
        FcitxSunpinyinCreate,
 
51
        FcitxSunpinyinDestroy
 
52
    };
 
53
 
 
54
    FCITX_EXPORT_API
 
55
    int ABI_VERSION = FCITX_ABI_VERSION;
 
56
#ifdef __cplusplus
 
57
}
 
58
#endif
 
59
 
 
60
CONFIG_DESC_DEFINE(GetSunpinyinConfigDesc, "fcitx-sunpinyin.desc")
 
61
 
 
62
boolean LoadSunpinyinConfig(FcitxSunpinyinConfig* fs);
 
63
static void SaveSunpinyinConfig(FcitxSunpinyinConfig* fs);
 
64
static void ConfigSunpinyin(FcitxSunpinyin* sunpinyin);
 
65
static void* SunpinyinGetFullPinyin(void* arg, FcitxModuleFunctionArg args);
 
66
static INPUT_RETURN_VALUE FcitxSunpinyinDeleteCandidate (FcitxSunpinyin* sunpinyin, CandidateWord* candWord);
 
67
 
 
68
 
 
69
static const char* fuzzyPairs[][2] = {
 
70
    {"sh", "s"},
 
71
    {"zh", "z"},
 
72
    {"ch", "c"},
 
73
    {"an", "ang"},
 
74
    {"on", "ong"},
 
75
    {"en", "eng"},
 
76
    {"in", "ing"},
 
77
    {"eng", "ong"},
 
78
    {"ian", "iang"},
 
79
    {"uan", "uang"},
 
80
    {"n", "l"},
 
81
    {"f", "h"},
 
82
    {"l", "r"},
 
83
    {"k", "g"}
 
84
};
 
85
 
 
86
static const char *correctionPairs[][2] = {
 
87
    {"ign", "ing"},
 
88
    {"ogn", "ong"},
 
89
    {"uen", "un"},
 
90
    {"img", "ing"},
 
91
    {"iou", "iu"},
 
92
    {"uei", "ui"}
 
93
};
 
94
 
 
95
/**
 
96
 * @brief Reset the status.
 
97
 *
 
98
 **/
 
99
__EXPORT_API
 
100
void FcitxSunpinyinReset (void* arg)
 
101
{
 
102
    FcitxSunpinyin* sunpinyin = (FcitxSunpinyin*) arg;
 
103
    FcitxUIStatus* puncStatus = GetUIStatus(sunpinyin->owner, "punc");
 
104
    FcitxUIStatus* fullwidthStatus = GetUIStatus(sunpinyin->owner, "fullwidth");
 
105
    sunpinyin->view->setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLSYMBOL, fullwidthStatus->getCurrentStatus(fullwidthStatus->arg));
 
106
    sunpinyin->view->setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLPUNC, puncStatus->getCurrentStatus(puncStatus->arg));
 
107
    sunpinyin->view->clearIC();
 
108
}
 
109
 
 
110
/**
 
111
 * @brief Process Key Input and return the status
 
112
 *
 
113
 * @param keycode keycode from XKeyEvent
 
114
 * @param state state from XKeyEvent
 
115
 * @param count count from XKeyEvent
 
116
 * @return INPUT_RETURN_VALUE
 
117
 **/
 
118
__EXPORT_API
 
119
INPUT_RETURN_VALUE FcitxSunpinyinDoInput(void* arg, FcitxKeySym sym, unsigned int state)
 
120
{
 
121
    FcitxSunpinyin* sunpinyin = (FcitxSunpinyin*) arg;
 
122
    FcitxInputState* input = FcitxInstanceGetInputState(sunpinyin->owner);
 
123
    CIMIView* view = sunpinyin->view;
 
124
    FcitxWindowHandler* windowHandler = sunpinyin->windowHandler;
 
125
    FcitxSunpinyinConfig* fs = &sunpinyin->fs;
 
126
    FcitxConfig* config = FcitxInstanceGetConfig(sunpinyin->owner);
 
127
    CandidateWordSetChoose(FcitxInputStateGetCandidateList(input), DIGIT_STR_CHOOSE);
 
128
 
 
129
    int chooseKey = CheckChooseKey(sym, KEY_NONE, DIGIT_STR_CHOOSE);
 
130
    if (state == KEY_CTRL_ALT_COMP && chooseKey >= 0)
 
131
    {
 
132
        CandidateWord* candidateWord = CandidateWordGetByIndex(FcitxInputStateGetCandidateList(input), chooseKey);
 
133
        return FcitxSunpinyinDeleteCandidate(sunpinyin, candidateWord);
 
134
    }
 
135
 
 
136
    if ( (!IsHotKeySimple(sym, state) || IsHotKey(sym, state, FCITX_SPACE)) && view->getIC()->isEmpty())
 
137
        return IRV_TO_PROCESS;
 
138
 
 
139
    /* there is some special case that ';' is used */
 
140
    if (IsHotKey(sym, state, FCITX_SEMICOLON) &&
 
141
        !(!view->getIC()->isEmpty() && fs->bUseShuangpin && (fs->SPScheme == MS2003 || fs->SPScheme == ZIGUANG)))
 
142
        return IRV_TO_PROCESS;
 
143
 
 
144
    if (IsHotKey(sym, state, FCITX_SEPARATOR) &&
 
145
        view->getIC()->isEmpty())
 
146
        return IRV_TO_PROCESS;
 
147
 
 
148
    if (sym == Key_KP_Enter)
 
149
        sym = Key_Return;
 
150
 
 
151
    if (IsHotKeyDigit(sym, state))
 
152
        return IRV_TO_PROCESS;
 
153
 
 
154
    if (IsHotKey(sym, state, FCITX_SPACE))
 
155
        return CandidateWordChooseByIndex(FcitxInputStateGetCandidateList(input), 0);
 
156
 
 
157
    if (!IsHotKeyUAZ(sym, state)
 
158
        && !IsHotKeyLAZ(sym, state)
 
159
        && !IsHotKey(sym, state, FCITX_SEMICOLON)
 
160
        && !IsHotKey(sym, state, FCITX_BACKSPACE)
 
161
        && !IsHotKey(sym, state, FCITX_DELETE)
 
162
        && !IsHotKey(sym, state, FCITX_ENTER)
 
163
        && !IsHotKey(sym, state, FCITX_LEFT)
 
164
        && !IsHotKey(sym, state, FCITX_RIGHT)
 
165
        && !IsHotKey(sym, state, FCITX_HOME)
 
166
        && !IsHotKey(sym, state, FCITX_END)
 
167
        && !IsHotKey(sym, state, FCITX_SEPARATOR)
 
168
        )
 
169
        return IRV_TO_PROCESS;
 
170
 
 
171
    if (IsHotKey(sym, state, config->hkPrevPage) || IsHotKey(sym, state, config->hkNextPage))
 
172
        return IRV_TO_PROCESS;
 
173
 
 
174
    windowHandler->commit_flag = false;
 
175
    windowHandler->candidate_flag = false;
 
176
    unsigned int changeMasks = view->onKeyEvent(CKeyEvent(sym, sym, state));
 
177
 
 
178
    if (windowHandler->commit_flag)
 
179
        return IRV_COMMIT_STRING;
 
180
    if (!(changeMasks & CIMIView::KEYEVENT_USED))
 
181
        return IRV_TO_PROCESS;
 
182
 
 
183
    if (view->getIC()->isEmpty())
 
184
        return IRV_CLEAN;
 
185
 
 
186
    if (windowHandler->candidate_flag)
 
187
    {
 
188
        return IRV_DISPLAY_CANDWORDS;
 
189
    }
 
190
 
 
191
    return IRV_DO_NOTHING;
 
192
}
 
193
 
 
194
boolean FcitxSunpinyinInit(void* arg)
 
195
{
 
196
    return true;
 
197
}
 
198
 
 
199
 
 
200
/**
 
201
 * @brief function DoInput has done everything for us.
 
202
 *
 
203
 * @param searchMode
 
204
 * @return INPUT_RETURN_VALUE
 
205
 **/
 
206
__EXPORT_API
 
207
INPUT_RETURN_VALUE FcitxSunpinyinGetCandWords(void* arg)
 
208
{
 
209
    FcitxSunpinyin* sunpinyin = (FcitxSunpinyin* )arg;
 
210
    FcitxInstance* instance = sunpinyin->owner;
 
211
    FcitxInputState* input = FcitxInstanceGetInputState(instance);
 
212
 
 
213
    CPreEditString ppd;
 
214
    sunpinyin->view->getPreeditString(ppd);
 
215
    TIConvSrcPtr src = (TIConvSrcPtr) (ppd.string());
 
216
    
 
217
    int hzlen = 0;    
 
218
    while (hzlen < ppd.charTypeSize())
 
219
    {
 
220
        if (! (ppd.charTypeAt(hzlen) & IPreeditString::USER_CHOICE))
 
221
            break;
 
222
        hzlen ++ ;
 
223
    }
 
224
    
 
225
    CleanInputWindowUp(instance);
 
226
 
 
227
    memcpy(sunpinyin->front_src, src, ppd.caret() * sizeof(TWCHAR));
 
228
    memcpy(sunpinyin->end_src, src + ppd.caret() * sizeof(TWCHAR),
 
229
           (ppd.size() - ppd.caret() + 1) * sizeof(TWCHAR));
 
230
    memcpy(sunpinyin->input_src, src, hzlen * sizeof(TWCHAR));
 
231
    
 
232
    FcitxLog(INFO, "%d", ppd.candi_start());
 
233
 
 
234
    sunpinyin->front_src[ppd.caret()] = 0;
 
235
    sunpinyin->end_src[ppd.size() - ppd.caret() + 1] = 0;
 
236
    sunpinyin->input_src[hzlen] = 0;
 
237
 
 
238
    memset(sunpinyin->clientpreedit, 0, FCITX_SUNPINYIN_MAX(hzlen * UTF8_MAX_LENGTH + 1, MAX_USER_INPUT + 1));
 
239
    WCSTOMBS(sunpinyin->clientpreedit, sunpinyin->input_src, MAX_USER_INPUT);
 
240
    AddMessageAtLast(FcitxInputStateGetClientPreedit(input), MSG_INPUT, "%s", sunpinyin->clientpreedit);
 
241
    FcitxInputStateSetClientCursorPos(input, 0);
 
242
 
 
243
    memset(sunpinyin->preedit, 0, FCITX_SUNPINYIN_MAX(ppd.size() * UTF8_MAX_LENGTH + 1, MAX_USER_INPUT + 1));
 
244
    WCSTOMBS(sunpinyin->preedit, sunpinyin->front_src, MAX_USER_INPUT);
 
245
    FcitxInputStateSetCursorPos(input, strlen(sunpinyin->preedit));
 
246
    WCSTOMBS(&sunpinyin->preedit[strlen(sunpinyin->preedit)], sunpinyin->end_src, MAX_USER_INPUT);
 
247
    
 
248
    FcitxInputStateSetShowCursor(input, true);
 
249
    
 
250
    AddMessageAtLast(FcitxInputStateGetPreedit(input), MSG_INPUT, "%s", sunpinyin->preedit);
 
251
 
 
252
    CCandidateList pcl;
 
253
    sunpinyin->view->getCandidateList(pcl, 0, sunpinyin->candNum);
 
254
    for (int i = 0; i < pcl.size(); i ++ )
 
255
    {
 
256
        const TWCHAR* pcand = pcl.candiString(i);
 
257
        if (pcand == NULL)
 
258
            continue;
 
259
 
 
260
        int *index = (int*) fcitx_malloc0(sizeof(int));
 
261
        *index = i;
 
262
        CandidateWord candWord;
 
263
        candWord.callback = FcitxSunpinyinGetCandWord;
 
264
        candWord.owner = sunpinyin;
 
265
        candWord.priv = index;
 
266
        candWord.strExtra = NULL;
 
267
 
 
268
        wstring cand_str = pcand;
 
269
        TIConvSrcPtr src = (TIConvSrcPtr)(cand_str.c_str());
 
270
        WCSTOMBS(sunpinyin->ubuf, (const TWCHAR*) src, MAX_CAND_LEN);
 
271
 
 
272
        candWord.strWord = strdup(sunpinyin->ubuf);
 
273
 
 
274
        CandidateWordAppend(FcitxInputStateGetCandidateList(input), &candWord);
 
275
 
 
276
        if (i == 0)
 
277
        {
 
278
            AddMessageAtLast(FcitxInputStateGetClientPreedit(input), MSG_INPUT, "%s", candWord.strWord);
 
279
        }
 
280
 
 
281
    }
 
282
    return IRV_DISPLAY_CANDWORDS;
 
283
}
 
284
 
 
285
/**
 
286
 * @brief get the candidate word by index
 
287
 *
 
288
 * @param iIndex index of candidate word
 
289
 * @return the string of canidate word
 
290
 **/
 
291
__EXPORT_API
 
292
INPUT_RETURN_VALUE FcitxSunpinyinGetCandWord (void* arg, CandidateWord* candWord)
 
293
{
 
294
    FcitxSunpinyin* sunpinyin = (FcitxSunpinyin* )arg;
 
295
    sunpinyin->windowHandler->commit_flag = false;
 
296
    sunpinyin->windowHandler->candidate_flag = false;
 
297
    int* index = (int*) candWord->priv;
 
298
    sunpinyin->view->onCandidateSelectRequest(*index);
 
299
 
 
300
    if (sunpinyin->windowHandler->commit_flag)
 
301
        return IRV_COMMIT_STRING;
 
302
 
 
303
    if (sunpinyin->windowHandler->candidate_flag)
 
304
        return IRV_DISPLAY_CANDWORDS;
 
305
 
 
306
    return IRV_DO_NOTHING;
 
307
}
 
308
 
 
309
/**
 
310
 * @brief initialize the extra input method
 
311
 *
 
312
 * @param arg
 
313
 * @return successful or not
 
314
 **/
 
315
__EXPORT_API
 
316
void* FcitxSunpinyinCreate (FcitxInstance* instance)
 
317
{
 
318
    FcitxSunpinyin* sunpinyin = (FcitxSunpinyin*) fcitx_malloc0(sizeof(FcitxSunpinyin));
 
319
    FcitxAddon* addon = GetAddonByName(FcitxInstanceGetAddons(instance), "fcitx-sunpinyin");
 
320
    bindtextdomain("fcitx-sunpinyin", LOCALEDIR);
 
321
    sunpinyin->owner = instance;
 
322
    FcitxSunpinyinConfig* fs = &sunpinyin->fs;
 
323
 
 
324
    if (!LoadSunpinyinConfig(&sunpinyin->fs))
 
325
    {
 
326
        free(sunpinyin);
 
327
        return NULL;
 
328
    }
 
329
    CSunpinyinSessionFactory& fac = CSunpinyinSessionFactory::getFactory();
 
330
 
 
331
    if (fs->bUseShuangpin)
 
332
        fac.setPinyinScheme(CSunpinyinSessionFactory::SHUANGPIN);
 
333
    else
 
334
        fac.setPinyinScheme(CSunpinyinSessionFactory::QUANPIN);
 
335
 
 
336
    ConfigSunpinyin(sunpinyin);
 
337
    sunpinyin->bShuangpin = fs->bUseShuangpin;
 
338
 
 
339
    sunpinyin->view = fac.createSession();
 
340
 
 
341
    if (sunpinyin->view == NULL)
 
342
    {
 
343
        free(sunpinyin);
 
344
        return NULL;
 
345
    }
 
346
 
 
347
    FcitxWindowHandler* windowHandler = new FcitxWindowHandler();
 
348
    sunpinyin->windowHandler = windowHandler;
 
349
    sunpinyin->view->getIC()->setCharsetLevel(3);
 
350
 
 
351
    sunpinyin->view->attachWinHandler(windowHandler);
 
352
    sunpinyin->windowHandler->SetOwner(sunpinyin);
 
353
    ConfigSunpinyin(sunpinyin);
 
354
 
 
355
    FcitxRegisterIMv2(instance,
 
356
                    sunpinyin,
 
357
                    "sunpinyin",
 
358
                    _("Sunpinyin"),
 
359
                    "sunpinyin",
 
360
                    FcitxSunpinyinInit,
 
361
                    FcitxSunpinyinReset,
 
362
                    FcitxSunpinyinDoInput,
 
363
                    FcitxSunpinyinGetCandWords,
 
364
                    NULL,
 
365
                    NULL,
 
366
                    ReloadConfigFcitxSunpinyin,
 
367
                    NULL,
 
368
                    fs->iSunpinyinPriority,
 
369
                    "zh_CN"
 
370
                   );
 
371
 
 
372
    AddFunction(addon, (void*) SunpinyinGetFullPinyin);
 
373
 
 
374
    return sunpinyin;
 
375
}
 
376
 
 
377
/**
 
378
 * @brief Destroy the input method while unload it.
 
379
 *
 
380
 * @return int
 
381
 **/
 
382
__EXPORT_API
 
383
void FcitxSunpinyinDestroy (void* arg)
 
384
{
 
385
    FcitxSunpinyin* sunpinyin = (FcitxSunpinyin*) arg;
 
386
    CSunpinyinSessionFactory& fac = CSunpinyinSessionFactory::getFactory();
 
387
    fac.destroySession(sunpinyin->view);
 
388
    if (sunpinyin->shuangpin_data)
 
389
        delete sunpinyin->shuangpin_data;
 
390
 
 
391
    if (sunpinyin->windowHandler)
 
392
        delete sunpinyin->windowHandler;
 
393
 
 
394
    free(arg);
 
395
}
 
396
 
 
397
INPUT_RETURN_VALUE FcitxSunpinyinDeleteCandidate (FcitxSunpinyin* sunpinyin, CandidateWord* candWord)
 
398
{
 
399
/*
 
400
        if (candWord->owner == sunpinyin)
 
401
    {
 
402
        CCandidateList pcl;
 
403
        sunpinyin->view->getCandidateList(pcl, 0, sunpinyin->candNum);
 
404
        int* index = (int*) candWord->priv;
 
405
        CIMIClassicView* classicView = (CIMIClassicView*) sunpinyin->view;
 
406
        unsigned int mask;
 
407
        classicView->deleteCandidate(*index, mask);
 
408
        return IRV_DISPLAY_CANDWORDS;
 
409
    }
 
410
*/
 
411
    return IRV_TO_PROCESS;
 
412
}
 
413
 
 
414
/**
 
415
 * @brief Load the config file for fcitx-sunpinyin
 
416
 *
 
417
 * @param Bool is reload or not
 
418
 **/
 
419
boolean LoadSunpinyinConfig(FcitxSunpinyinConfig* fs)
 
420
{
 
421
    ConfigFileDesc *configDesc = GetSunpinyinConfigDesc();
 
422
    if (!configDesc)
 
423
        return false;
 
424
 
 
425
    FILE *fp = GetXDGFileUserWithPrefix("conf", "fcitx-sunpinyin.config", "rt", NULL);
 
426
 
 
427
    if (!fp)
 
428
    {
 
429
        if (errno == ENOENT)
 
430
            SaveSunpinyinConfig(fs);
 
431
    }
 
432
    ConfigFile *cfile = ParseConfigFileFp(fp, configDesc);
 
433
 
 
434
    FcitxSunpinyinConfigConfigBind(fs, cfile, configDesc);
 
435
    ConfigBindSync(&fs->gconfig);
 
436
 
 
437
    if (fp)
 
438
        fclose(fp);
 
439
    return true;
 
440
}
 
441
 
 
442
void ConfigSunpinyin(FcitxSunpinyin* sunpinyin)
 
443
{
 
444
    FcitxInstance* instance = sunpinyin->owner;
 
445
    FcitxConfig* config = FcitxInstanceGetConfig(instance);
 
446
    FcitxSunpinyinConfig *fs = &sunpinyin->fs;
 
447
    int i = 0;
 
448
 
 
449
    if (sunpinyin->view)
 
450
    {
 
451
        sunpinyin->view->setCandiWindowSize(2048);
 
452
        // page up/down key
 
453
        CHotkeyProfile* prof = sunpinyin->view->getHotkeyProfile();
 
454
        prof->clear();
 
455
 
 
456
        for (i = 0 ; i < 2; i++)
 
457
        {
 
458
            if (config->hkPrevPage[i].sym)
 
459
                prof->addPageUpKey(CKeyEvent(config->hkPrevPage[i].sym, 0, config->hkPrevPage[i].state));
 
460
            if (config->hkNextPage[i].sym)
 
461
                prof->addPageDownKey(CKeyEvent(config->hkNextPage[i].sym, 0, config->hkNextPage[i].state));
 
462
        }
 
463
        sunpinyin->view->setCancelOnBackspace(1);
 
464
    }
 
465
 
 
466
    string_pairs fuzzy, correction;
 
467
    for (i = 0; i < FUZZY_SIZE; i++)
 
468
        if (fs->bFuzzy[i])
 
469
            fuzzy.push_back(std::make_pair<std::string, std::string>(fuzzyPairs[i][0], fuzzyPairs[i][1]));
 
470
 
 
471
    for (i = 0; i < CORRECT_SIZE; i++)
 
472
        if (fs->bAutoCorrecting[i])
 
473
            correction.push_back(std::make_pair<std::string, std::string>(correctionPairs[i][0], correctionPairs[i][1]));
 
474
 
 
475
    if (fuzzy.size() != 0)
 
476
    {
 
477
        AQuanpinSchemePolicy::instance().setFuzzyForwarding(true);
 
478
        AQuanpinSchemePolicy::instance().setFuzzyPinyinPairs(fuzzy);
 
479
    }
 
480
    else
 
481
    {
 
482
        AQuanpinSchemePolicy::instance().setFuzzyForwarding(false);
 
483
        AQuanpinSchemePolicy::instance().clearFuzzyPinyinPairs();
 
484
    }
 
485
 
 
486
    if (correction.size() != 0)
 
487
    {
 
488
        AQuanpinSchemePolicy::instance().setAutoCorrecting(true);
 
489
        AQuanpinSchemePolicy::instance().setAutoCorrectionPairs(correction);
 
490
    }
 
491
    else
 
492
        AQuanpinSchemePolicy::instance().setAutoCorrecting(false);
 
493
 
 
494
    if (sunpinyin->shuangpin_data == NULL)
 
495
        sunpinyin->shuangpin_data = new CShuangpinData(fs->SPScheme);
 
496
    AShuangpinSchemePolicy::instance().setShuangpinType(fs->SPScheme);
 
497
    AQuanpinSchemePolicy::instance().setFuzzySegmentation(fs->bFuzzySegmentation);
 
498
    AQuanpinSchemePolicy::instance().setInnerFuzzySegmentation(fs->bFuzzyInnerSegmentation);
 
499
}
 
500
 
 
501
__EXPORT_API void ReloadConfigFcitxSunpinyin(void* arg)
 
502
{
 
503
    FcitxSunpinyin* sunpinyin = (FcitxSunpinyin*) arg;
 
504
    LoadSunpinyinConfig(&sunpinyin->fs);
 
505
    ConfigSunpinyin(sunpinyin);
 
506
}
 
507
 
 
508
/**
 
509
 * @brief Save the config
 
510
 *
 
511
 * @return void
 
512
 **/
 
513
void SaveSunpinyinConfig(FcitxSunpinyinConfig* fs)
 
514
{
 
515
    ConfigFileDesc *configDesc = GetSunpinyinConfigDesc();
 
516
    FILE *fp = GetXDGFileUserWithPrefix("conf", "fcitx-sunpinyin.config", "wt", NULL);
 
517
    SaveConfigFileFp(fp, &fs->gconfig, configDesc);
 
518
    if (fp)
 
519
        fclose(fp);
 
520
}
 
521
 
 
522
void* SunpinyinGetFullPinyin(void* arg, FcitxModuleFunctionArg args)
 
523
{
 
524
    FcitxSunpinyin* sunpinyin = (FcitxSunpinyin*) arg;
 
525
    char* pinyin = (char*) args.args[0];
 
526
    boolean *issp = (boolean*) args.args[1];
 
527
    *issp = sunpinyin->bShuangpin;
 
528
    CMappedYin syls;
 
529
    if (sunpinyin->bShuangpin)
 
530
    {
 
531
        sunpinyin->shuangpin_data->getMapString(pinyin, syls);
 
532
        if (syls.size() == 0)
 
533
            return NULL;
 
534
        else
 
535
            return strdup(syls[0].c_str());
 
536
    }
 
537
    else
 
538
        return NULL;
 
539
}
 
540
 
 
541
// kate: indent-mode cstyle; space-indent on; indent-width 0;