~cmpitg/ibus-unikey/trunk

« back to all changes in this revision

Viewing changes to src/utils.cpp

  • Committer: Yang Ha Nguyen
  • Date: 2010-10-24 11:00:29 UTC
  • Revision ID: cmpitg@gmail.com-20101024110029-8vr1ri2d56tpro18
Clone from SVN tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_CONFIG_H
 
2
#include "config.h"
 
3
#endif
 
4
 
 
5
#include <libintl.h>
 
6
 
 
7
#include <ibus.h>
 
8
#include "ukengine.h"
 
9
#include "utils.h"
 
10
#include "engine_const.h"
 
11
 
 
12
#define _(string) gettext(string)
 
13
 
 
14
#define IU_DESC _("Vietnamese Input Method Engine for IBus using Unikey Engine\n\
 
15
Usage:\n\
 
16
  - Choose input method, output charset, options in language bar.\n\
 
17
  - There are 4 input methods: Telex, Vni, STelex (simple telex) \
 
18
and STelex2 (which same as STelex, the difference is it use w as ư).\n\
 
19
  - And 7 output charsets: Unicode (UTF-8), TCVN3, VNI Win, VIQR, CString, NCR Decimal and NCR Hex.\n\
 
20
  - Use <Shift>+<Space> or <Shift>+<Shift> to restore keystrokes.\n\
 
21
  - Use <Control> to commit a word.\
 
22
")
 
23
 
 
24
IBusComponent* ibus_unikey_get_component()
 
25
{
 
26
    IBusComponent* component;
 
27
    IBusEngineDesc* engine;
 
28
 
 
29
    component = ibus_component_new("org.freedesktop.IBus.Unikey",
 
30
                                   "Unikey",
 
31
                                   PACKAGE_VERSION,
 
32
                                   "GPLv2",
 
33
                                   "Lê Quốc Tuấn <mr.lequoctuan@gmail.com>",
 
34
                                   PACKAGE_BUGREPORT,
 
35
                                   "",
 
36
                                   PACKAGE_NAME);
 
37
 
 
38
    engine = ibus_engine_desc_new
 
39
    (
 
40
        "Unikey",
 
41
        "Unikey",
 
42
        IU_DESC,
 
43
        "vi",
 
44
        "GPLv2",
 
45
        "Lê Quốc Tuấn <mr.lequoctuan@gmail.com>",
 
46
        PKGDATADIR"/icons/ibus-unikey.png",
 
47
        "us"
 
48
    );
 
49
    
 
50
    engine->rank = 99;
 
51
 
 
52
    ibus_component_add_engine(component, engine);
 
53
 
 
54
    return component;
 
55
}
 
56
 
 
57
// code from x-unikey, for convert charset that not is XUtf-8
 
58
int latinToUtf(unsigned char* dst, unsigned char* src, int inSize, int* pOutSize)
 
59
{
 
60
    int i;
 
61
    int outLeft;
 
62
    unsigned char ch;
 
63
 
 
64
    outLeft = *pOutSize;
 
65
 
 
66
    for (i=0; i<inSize; i++)
 
67
    {
 
68
        ch = *src++;
 
69
        if (ch < 0x80)
 
70
        {
 
71
            outLeft -= 1;
 
72
            if (outLeft >= 0)
 
73
                *dst++ = ch;
 
74
        }
 
75
        else
 
76
        {
 
77
            outLeft -= 2;
 
78
            if (outLeft >= 0)
 
79
            {
 
80
                *dst++ = (0xC0 | ch >> 6);
 
81
                *dst++ = (0x80 | (ch & 0x3F));
 
82
            }
 
83
        }
 
84
    }
 
85
 
 
86
    *pOutSize = outLeft;
 
87
    return (outLeft >= 0);
 
88
}
 
89