1 /* vim:set et ts=4 sts=4:
3 * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
5 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
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)
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #if defined(HAVE_UUID_CREATE)
30 #elif defined(HAVE_LIBUUID)
31 # include <uuid/uuid.h>
34 #include <sys/utsname.h>
38 #ifdef __GXX_EXPERIMENTAL_CXX0X__
41 # include <boost/shared_ptr.hpp>
42 # include <boost/scoped_ptr.hpp>
45 // import boost::shared_ptr to std namespace
46 using boost::shared_ptr;
47 // import boost::scoped_ptr to std namespace, and rename to unique_ptr
48 // XXX: the unique_ptr can transfer the pointer ownership,
49 // but scoped_ptr cannot.
50 template<typename T> class unique_ptr : public boost::scoped_ptr<T> {};
59 // mask for Ctrl, Alt, Super, Hyper, Meta
60 const guint CMSHM_MASK = IBUS_CONTROL_MASK |
65 // mask for Shift, Ctrl, Alt, Super, Hyper, Meta
66 const guint SCMSHM_MASK = CMSHM_MASK | IBUS_SHIFT_MASK;
69 cmshm_filter (guint modifiers)
71 return modifiers & CMSHM_MASK;
75 scmshm_filter (guint modifiers)
77 return modifiers & SCMSHM_MASK;
81 cmshm_test (guint modifiers, guint mask)
83 return cmshm_filter (modifiers) == mask;
87 scmshm_test (guint modifiers, guint mask)
89 return scmshm_filter (modifiers) == mask;
97 #if defined(HAVE_UUID_CREATE)
100 uuid_to_string (&u, &uuid, 0);
101 g_strlcpy (m_uuid, uuid, sizeof(m_uuid));
103 #elif defined(HAVE_LIBUUID)
105 uuid_unparse_lower (u, m_uuid);
109 operator const gchar * (void) const
125 const gchar *hostname (void) const { return m_buf.nodename; }
127 struct utsname m_buf;
130 class Hostname : public Uname {
132 operator const gchar * (void) const
138 class Env : public std::string {
140 Env (const gchar *name)
143 str = std::getenv (name);
144 assign (str != NULL ? str : "");
147 operator const gchar *(void) const