#define __PY_BUS_H_
#include <ibus.h>
-#include "Pointer.h"
+#include "Object.h"
namespace PY {
-class Bus : public Pointer <IBusBus> {
+class Bus : Object {
public:
- Bus (void) {
- set (ibus_bus_new ());
+ Bus (void) : Object (ibus_bus_new ()) {
}
bool isConnected (void) {
return ibus_bus_is_connected (*this);
}
+
+ operator IBusBus * (void) const {
+ return get<IBusBus> ();
+ }
};
};
Config::read (const gchar *section, const gchar *name, bool defval)
{
GValue value = {0};
- if (ibus_config_get_value (m_config, section, name, &value)) {
+ if (ibus_config_get_value (get<IBusConfig> (), section, name, &value)) {
if (G_VALUE_TYPE (&value) == G_TYPE_BOOLEAN)
return g_value_get_boolean (&value);
}
Config::read (const gchar *section, const gchar *name, gint defval)
{
GValue value = {0};
- if (ibus_config_get_value (m_config, section, name, &value)) {
+ if (ibus_config_get_value (get<IBusConfig> (), section, name, &value)) {
if (G_VALUE_TYPE (&value) == G_TYPE_INT)
return g_value_get_int (&value);
}
#include <glib.h>
#include <glib-object.h>
#include <ibus.h>
-#include "Pointer.h"
+#include "Object.h"
+#include "Bus.h"
namespace PY {
-class Config {
+class Config : Object {
public:
- Config (Pointer<IBusBus> & bus) {
- m_config = ibus_bus_get_config (bus);
+ Config (Bus & bus) : Object (ibus_bus_get_config (bus)) {
readDefaultValues ();
- g_signal_connect ((IBusConfig *) m_config, "value-changed", G_CALLBACK (valueChangedCallback), this);
+ g_signal_connect (get<IBusConfig> (), "value-changed", G_CALLBACK (valueChangedCallback), this);
}
static guint option (void) { return m_option & m_option_mask; }
Config *self);
private:
- Pointer<IBusConfig> m_config;
-
-private:
static guint m_option;
static guint m_option_mask;
#define __PY_LOOKUP_TABLE_H_
#include <ibus.h>
-#include "Pointer.h"
+#include "Object.h"
#include "Text.h"
namespace PY {
-class LookupTable : public Pointer <IBusLookupTable> {
+class LookupTable : Object {
public:
LookupTable (guint page_size = 10,
guint cursor_pos = 0,
gboolean cursor_visible = TRUE,
gboolean round = FALSE)
- : Pointer <IBusLookupTable> (ibus_lookup_table_new (page_size, cursor_pos, cursor_visible, round)) { }
+ : Object (ibus_lookup_table_new (page_size, cursor_pos, cursor_visible, round)) { }
guint pageSize (void) { return ibus_lookup_table_get_page_size (*this); }
guint orientation (void) { return ibus_lookup_table_get_orientation (*this); }
void appendCandidate (IBusText *text) {
ibus_lookup_table_append_candidate (*this, text);
}
+
+ operator IBusLookupTable * (void) const {
+ return get<IBusLookupTable> ();
+ }
};
};
Config config (bus);
- g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
+ g_signal_connect ((IBusBus *)bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
component = ibus_component_new ("org.freedesktop.IBus.Pinyin",
N_("Pinyin input method"),
FullPinyinEditor.h \
HalfFullConverter.h \
LookupTable.h \
+ Object.h \
Phrase.h \
PhraseArray.h \
PhraseEditor.h \
--- /dev/null
+#ifndef __PY_OBJECT_H_
+#define __PY_OBJECT_H_
+
+#include <glib-object.h>
+#include "Pointer.h"
+
+namespace PY {
+
+class Object {
+protected:
+ template <typename T>
+ Object (T *p) : m_p ((GObject *)p) {
+ }
+
+ operator GObject * (void) const {
+ return m_p;
+ }
+
+ template <typename T>
+ T * get (void) const {
+ return (T *) (GObject *) m_p;
+ }
+
+private:
+ Pointer<GObject> m_p;
+};
+
+};
+
+#endif
void
PinyinEngine::slotCommitText (Text & text)
{
- m_last_commit_text = text;
+ // m_last_commit_text = text;
ibus_engine_commit_text (m_engine, text);
if (m_input_mode != MODE_INIT)
m_input_mode = MODE_INIT;
m_editors[i]->reset ();
}
m_fallback_editor->reset ();
- m_last_commit_text = NULL;
+ // m_last_commit_text = NULL;
}
EditorPtr m_editors[MODE_LAST];
EditorPtr m_fallback_editor;
- Text m_last_commit_text;
+ // Text m_last_commit_text;
};
};
: m_mode_chinese (Config::initChinese ()),
m_mode_full (Config::initFull ()),
m_mode_full_punct (Config::initFullPunct ()),
- m_mode_simp (Config::initSimpChinese ())
+ m_mode_simp (Config::initSimpChinese ()),
+ m_prop_chinese ("mode.chinese",
+ PROP_TYPE_NORMAL,
+ StaticText ("CN"),
+ m_mode_chinese ?
+ PKGDATADIR"/icons/chinese.svg" :
+ PKGDATADIR"/icons/english.svg",
+ StaticText (_("Chinese"))),
+ m_prop_full ("mode.full",
+ PROP_TYPE_NORMAL,
+ StaticText (m_mode_full ? "Aa" : "Aa"),
+ m_mode_full ?
+ PKGDATADIR"/icons/full.svg" :
+ PKGDATADIR"/icons/half.svg",
+ StaticText (_("Full/Half width"))),
+ m_prop_full_punct ("mode.full_punct",
+ PROP_TYPE_NORMAL,
+ StaticText (m_mode_full_punct ? ",。" : ",."),
+ m_mode_full_punct ?
+ PKGDATADIR"/icons/full-punct.svg" :
+ PKGDATADIR"/icons/half-punct.svg",
+ StaticText (_("Full/Half width punctuation"))),
+ m_prop_simp ( "mode.simp",
+ PROP_TYPE_NORMAL,
+ StaticText (m_mode_simp ? "简" : "繁"),
+ m_mode_simp ?
+ PKGDATADIR"/icons/simp-chinese.svg" :
+ PKGDATADIR"/icons/trad-chinese.svg",
+ StaticText (_("Simplfied/Traditional Chinese"))),
+ m_prop_setup ("setup",
+ PROP_TYPE_NORMAL,
+ StaticText (_("Pinyin preferences")),
+ "ibus-setup",
+ StaticText (_("Pinyin preferences")))
{
- /* create properties */
- m_prop_chinese = ibus_property_new ("mode.chinese",
- PROP_TYPE_NORMAL,
- StaticText ("CN"),
- m_mode_chinese ?
- PKGDATADIR"/icons/chinese.svg" :
- PKGDATADIR"/icons/english.svg",
- StaticText (_("Chinese")),
- TRUE,
- TRUE,
- PROP_STATE_UNCHECKED,
- NULL);
m_props.append (m_prop_chinese);
-
- m_prop_full = ibus_property_new ("mode.full",
- PROP_TYPE_NORMAL,
- StaticText (m_mode_full? "Aa" : "Aa"),
- m_mode_full ?
- PKGDATADIR"/icons/full.svg" :
- PKGDATADIR"/icons/half.svg",
- StaticText (_("Full/Half width")),
- TRUE,
- TRUE,
- PROP_STATE_UNCHECKED,
- NULL);
m_props.append (m_prop_full);
-
- m_prop_full_punct = ibus_property_new ("mode.full_punct",
- PROP_TYPE_NORMAL,
- StaticText (m_mode_full_punct ? ",。" : ",."),
- m_mode_full_punct ?
- PKGDATADIR"/icons/full-punct.svg" :
- PKGDATADIR"/icons/half-punct.svg",
- StaticText (_("Full/Half width punctuation")),
- TRUE,
- TRUE,
- PROP_STATE_UNCHECKED,
- NULL);
m_props.append (m_prop_full_punct);
-
- m_prop_simp = ibus_property_new ("mode.simp",
- PROP_TYPE_NORMAL,
- StaticText (m_mode_simp ? "简" : "繁"),
- m_mode_simp ?
- PKGDATADIR"/icons/simp-chinese.svg" :
- PKGDATADIR"/icons/trad-chinese.svg",
- StaticText (_("Simplfied/Traditional Chinese")),
- TRUE,
- TRUE,
- PROP_STATE_UNCHECKED,
- NULL);
m_props.append (m_prop_simp);
-
- m_prop_setup = ibus_property_new ("setup",
- PROP_TYPE_NORMAL,
- StaticText (_("Pinyin preferences")),
- "ibus-setup",
- StaticText (_("Pinyin preferences")),
- TRUE,
- TRUE,
- PROP_STATE_UNCHECKED,
- NULL);
m_props.append (m_prop_setup);
}
#define __PY_PROPERTY_H_
#include <ibus.h>
-#include "Pointer.h"
+#include "Object.h"
#include "Text.h"
namespace PY {
-class Property : public Pointer<IBusProperty> {
+class Property : public Object {
public:
- Property & operator= (IBusProperty *p) {
- set (p);
- return *this;
+ Property (const gchar *key,
+ IBusPropType type = PROP_TYPE_NORMAL,
+ IBusText *label = NULL,
+ const gchar *icon = NULL,
+ IBusText *tooltip = NULL,
+ gboolean sensitive = TRUE,
+ gboolean visible = TRUE,
+ IBusPropState state = PROP_STATE_UNCHECKED,
+ IBusPropList *props = NULL)
+ : Object (ibus_property_new (key, type, label, icon, tooltip, sensitive, visible, state, props)) { }
+
+ void setLabel (IBusText *text) {
+ ibus_property_set_label (get<IBusProperty> (), text);
}
- void setLabel (const Text & text) {
- ibus_property_set_label (*this, text);
- }
void setLabel (const gchar *text) {
setLabel (Text (text));
}
+
void setIcon (const gchar *icon) {
- ibus_property_set_icon (*this, icon);
+ ibus_property_set_icon (get<IBusProperty> (), icon);
}
+
void setSensitive (gboolean sensitive) {
- ibus_property_set_sensitive (*this, sensitive);
+ ibus_property_set_sensitive (get<IBusProperty> (), sensitive);
+ }
+
+ operator IBusProperty * (void) const {
+ return get<IBusProperty> ();
}
};
-class PropList : public Pointer<IBusPropList> {
+class PropList : Object {
public:
- PropList (void) : Pointer<IBusPropList> (ibus_prop_list_new ()) { }
+ PropList (void) : Object (ibus_prop_list_new ()) { }
void append (Property &prop) {
- ibus_prop_list_append (*this, prop);
+ ibus_prop_list_append (get<IBusPropList> (), prop);
+ }
+
+ operator IBusPropList * (void) const {
+ return get<IBusPropList> ();
}
};
#define __PY_TEXT_H_
#include <ibus.h>
-#include "Pointer.h"
+#include "Object.h"
#include "String.h"
namespace PY {
-class Text : public Pointer<IBusText> {
+class Text : Object {
public:
- Text () : Pointer<IBusText> () {}
Text (IBusText *text)
- : Pointer<IBusText> (text) {}
+ : Object (text) {}
Text (const gchar *str)
- : Pointer<IBusText> (ibus_text_new_from_string (str)) {}
+ : Object (ibus_text_new_from_string (str)) {}
Text (const String & str)
- : Pointer<IBusText> (ibus_text_new_from_string ((const gchar *) str)) {}
+ : Object (ibus_text_new_from_string ((const gchar *) str)) {}
Text (gunichar ch)
- : Pointer<IBusText> (ibus_text_new_from_unichar (ch)) {}
+ : Object (ibus_text_new_from_unichar (ch)) {}
void appendAttribute (guint type, guint value, guint start, guint end) {
- ibus_text_append_attribute (*this, type, value, start, end);
+ ibus_text_append_attribute (get<IBusText> (), type, value, start, end);
}
- Text & operator= (IBusText *p) {
- set (p);
- return *this;
+ operator IBusText * (void) const {
+ return get<IBusText> ();
}
};
StaticText (gunichar ch)
: Text (ch) {}
+
+ operator IBusText * (void) const {
+ return Text::operator IBusText * ();
+ }
};
};