WIP.
authorHuang Peng <shawn.p.huang@gmail.com>
Sun, 20 Jul 2008 04:55:10 +0000 (12:55 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Sun, 20 Jul 2008 04:55:10 +0000 (12:55 +0800)
qt4/ibus-client.cpp
qt4/ibus-client.h
qt4/ibus-input-context.cpp
qt4/ibus-input-context.h

index ef963e7..c765961 100644 (file)
@@ -385,6 +385,28 @@ IBusClient::connectToBus ()
                return false;
        }
 
+       if (!connection->connect ("",
+                       IBUS_PATH,
+                       IBUS_INTERFACE,
+                       "ShowPreedit",
+                       this, SLOT (slotShowPreedit(QDBusMessage)))) {
+               qWarning () << "Can not connect ShowPreedit signal";
+               delete connection;
+               QDBusConnection::disconnectFromBus ("ibus");
+               return false;
+       }
+
+       if (!connection->connect ("",
+                       IBUS_PATH,
+                       IBUS_INTERFACE,
+                       "HidePreedit",
+                       this, SLOT (slotHidePreedit(QDBusMessage)))) {
+               qWarning () << "Can not connect ShowPreedit signal";
+               delete connection;
+               QDBusConnection::disconnectFromBus ("ibus");
+               return false;
+       }
+
        ibus = connection;
 
        QList <IBusInputContext *>::iterator i;
@@ -450,7 +472,7 @@ IBusClient::slotUpdatePreedit (QDBusMessage message)
        QString text;
        QVariant attrs;
        int cursor_pos;
-       bool show;
+       bool visible;
 
        QList<QVariant> args = message.arguments ();
 
@@ -458,7 +480,7 @@ IBusClient::slotUpdatePreedit (QDBusMessage message)
        text = args[1].toString ();
        attrs = args[2];
        cursor_pos = args[3].toInt ();
-       show = args[4].toBool ();
+       visible = args[4].toBool ();
        QList <QList <quint32> > attr_list;
        const QDBusArgument arg = attrs.value <QDBusArgument> ();
        arg.beginArray ();
@@ -478,5 +500,30 @@ IBusClient::slotUpdatePreedit (QDBusMessage message)
        arg.endArray ();
 
        IBusInputContext *ctx = context_dict[ic];
-       ctx->updatePreedit (text, attr_list, cursor_pos, show);
+       ctx->updatePreedit (text, attr_list, cursor_pos, visible);
 }
+
+void
+IBusClient::slotShowPreedit (QDBusMessage message)
+{
+       QString ic;
+
+       QList<QVariant> args = message.arguments ();
+
+       ic = args[0].toString ();
+       IBusInputContext *ctx = context_dict[ic];
+       ctx->showPreedit ();
+}
+
+void
+IBusClient::slotHidePreedit (QDBusMessage message)
+{
+       QString ic;
+
+       QList<QVariant> args = message.arguments ();
+
+       ic = args[0].toString ();
+       IBusInputContext *ctx = context_dict[ic];
+       ctx->hidePreedit ();
+}
+
index 4565a78..6a37224 100644 (file)
@@ -66,6 +66,8 @@ private slots:
        void slotCommitString (QString ic, QString text);
        //void slotUpdatePreedit (QString ic, QString text, QVariant attrs, int cursor_pos, bool show);
        void slotUpdatePreedit (QDBusMessage message);
+       void slotShowPreedit (QDBusMessage message);
+       void slotHidePreedit (QDBusMessage message);
 
 private:
        bool connectToBus ();
index 6a00ec7..692fecb 100644 (file)
@@ -174,12 +174,12 @@ IBusInputContext::commitString (QString text)
 }
 
 void
-IBusInputContext::updatePreedit (QString text, QList <QList <quint32> > attr_list, int cursor_pos, bool show)
+IBusInputContext::updatePreedit (QString text, QList <QList <quint32> > attr_list, int cursor_pos, bool visible)
 {
        // qDebug () << text << cursor_pos << show;
        QList <QAttribute> qattrs;
 
-       if (show) {
+       if (visible) {
                // append cursor pos
                qattrs.append (QAttribute (QInputMethodEvent::Cursor, cursor_pos, true, 0));
 
@@ -214,10 +214,30 @@ IBusInputContext::updatePreedit (QString text, QList <QList <quint32> > attr_lis
        }
 
        preedit_string = text;
-       preedit_visible = show;
+       preedit_visible = visible;
+       preedit_attrs = attr_list;
        preedit_cursor_pos = cursor_pos;
 
        QInputMethodEvent event (text, qattrs);
        sendEvent (event);
        update ();
 }
+
+void
+IBusInputContext::showPreedit ()
+{
+       if (preedit_visible)
+               return;
+
+       updatePreedit (preedit_string, preedit_attrs, preedit_cursor_pos, TRUE);
+}
+
+void
+IBusInputContext::hidePreedit ()
+{
+       if (!preedit_visible)
+               return;
+
+       updatePreedit (preedit_string, preedit_attrs, preedit_cursor_pos, FALSE);
+}
+
index 6aac46b..317c876 100644 (file)
@@ -51,7 +51,9 @@ public:
        QString getIC ();
 
        void commitString (QString text);
-       void updatePreedit (QString text, QList <QList <quint32> > attr_list, int cursor_pos, bool show);
+       void updatePreedit (QString text, QList <QList <quint32> > attr_list, int cursor_pos, bool visible);
+       void showPreedit ();
+       void hidePreedit ();
 
 
 private:
@@ -60,6 +62,7 @@ private:
        QString preedit_string;
        bool preedit_visible;
        int preedit_cursor_pos;
+       QList <QList <quint32> > preedit_attrs;
        QRect cursor_location;
 };