~ubuntu-branches/ubuntu/saucy/ibus-pinyin/saucy-proposed

« back to all changes in this revision

Viewing changes to src/Util.h

  • Committer: Bazaar Package Importer
  • Author(s): LI Daobing, Asias He
  • Date: 2010-09-08 21:38:54 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100908213854-q4wlx8zlcyqxvelz
Tags: 1.3.11-1
[ Asias He ]
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* vim:set et ts=4 sts=4:
2
 
 *
3
 
 * ibus-pinyin - The Chinese PinYin engine for IBus
4
 
 *
5
 
 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; either version 2, or (at your option)
10
 
 * any later version.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
 
 */
21
 
#ifndef __PY_UTIL_H_
22
 
#define __PY_UTIL_H_
23
 
 
24
 
#ifdef HAVE_CONFIG_H
25
 
#  include "config.h"
26
 
#endif
27
 
 
28
 
#if defined(HAVE_UUID_CREATE)
29
 
#  include <uuid.h>
30
 
#elif defined(HAVE_LIBUUID)
31
 
#  include <uuid/uuid.h>
32
 
#endif
33
 
 
34
 
#include <sys/utsname.h>
35
 
#include <cstdlib>
36
 
#include <string>
37
 
 
38
 
#include <ibus.h>
39
 
 
40
 
namespace PY {
41
 
 
42
 
// mask for Ctrl, Alt, Super, Hyper, Meta
43
 
const guint CMSHM_MASK = IBUS_CONTROL_MASK |
44
 
                         IBUS_MOD1_MASK |
45
 
                         IBUS_SUPER_MASK |
46
 
                         IBUS_HYPER_MASK |
47
 
                         IBUS_META_MASK;
48
 
// mask for Shift, Ctrl, Alt, Super, Hyper, Meta
49
 
const guint SCMSHM_MASK = CMSHM_MASK | IBUS_SHIFT_MASK;
50
 
 
51
 
inline guint
52
 
cmshm_filter (guint modifiers)
53
 
{
54
 
    return modifiers & CMSHM_MASK;
55
 
}
56
 
 
57
 
inline guint
58
 
scmshm_filter (guint modifiers)
59
 
{
60
 
    return modifiers & SCMSHM_MASK;
61
 
}
62
 
 
63
 
inline gboolean
64
 
cmshm_test (guint modifiers, guint mask)
65
 
{
66
 
    return cmshm_filter (modifiers) == mask;
67
 
}
68
 
 
69
 
inline gboolean
70
 
scmshm_test (guint modifiers, guint mask)
71
 
{
72
 
    return scmshm_filter (modifiers) == mask;
73
 
}
74
 
 
75
 
class UUID {
76
 
public:
77
 
    UUID (void)
78
 
    {
79
 
        uuid_t u;
80
 
#if defined(HAVE_UUID_CREATE)
81
 
        gchar* uuid;
82
 
        uuid_create (&u, 0);
83
 
        uuid_to_string (&u, &uuid, 0);
84
 
        g_strlcpy (m_uuid, uuid, sizeof(m_uuid));
85
 
        free(uuid);
86
 
#elif defined(HAVE_LIBUUID)
87
 
        uuid_generate (u);
88
 
        uuid_unparse_lower (u, m_uuid);
89
 
#endif
90
 
    }
91
 
 
92
 
    operator const gchar * (void) const
93
 
    {
94
 
        return m_uuid;        
95
 
    }
96
 
 
97
 
private:
98
 
    gchar m_uuid[256];
99
 
};
100
 
 
101
 
class Uname {
102
 
public:
103
 
    Uname (void)
104
 
    {
105
 
        uname (&m_buf);
106
 
    }
107
 
 
108
 
    const gchar *hostname (void) const { return m_buf.nodename; }
109
 
private:
110
 
    struct utsname m_buf;
111
 
};
112
 
 
113
 
class Hostname : public Uname {
114
 
public:
115
 
    operator const gchar * (void) const
116
 
    {
117
 
        return hostname ();
118
 
    }
119
 
};
120
 
 
121
 
class Env : public std::string {
122
 
public:
123
 
    Env (const gchar *name)
124
 
    {
125
 
        gchar *str;
126
 
        str = std::getenv (name);
127
 
        assign (str != NULL ? str : "");
128
 
    }
129
 
 
130
 
    operator const gchar *(void) const
131
 
    {
132
 
        return c_str();
133
 
    }
134
 
};
135
 
 
136
 
};
137
 
#endif