void MInputContext::connectToDBus() { qDebug() << __PRETTY_FUNCTION__; g_type_init(); MDBusGlibInputContextAdaptor *inputContextAdaptor = M_DBUS_GLIB_INPUT_CONTEXT_ADAPTOR( g_object_new(M_TYPE_DBUS_GLIB_INPUT_CONTEXT_ADAPTOR, NULL)); inputContextAdaptor->inputContext = this; imServer = new GlibDBusIMServerProxy(G_OBJECT(inputContextAdaptor), DBusCallbackPath); connect(imServer, SIGNAL(dbusConnected()), this, SLOT(onDBusConnection())); connect(imServer, SIGNAL(dbusDisconnected()), this, SLOT(onDBusDisconnection())); }
void FcitxQtConnectionPrivate::createConnection() { if (m_connectedOnce && !m_autoReconnect) { return; } m_serviceWatcher->disconnect(SIGNAL(serviceOwnerChanged(QString,QString,QString))); QString addr = address(); if (!addr.isNull()) { QDBusConnection connection(QDBusConnection::connectToBus(addr, "fcitx")); if (connection.isConnected()) { // qDebug() << "create private"; m_connection = new QDBusConnection(connection); } else QDBusConnection::disconnectFromBus("fcitx"); } if (!m_connection) { QDBusConnection* connection = new QDBusConnection(QDBusConnection::sessionBus()); connect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &FcitxQtConnectionPrivate::imChanged); QDBusReply<bool> registered = connection->interface()->isServiceRegistered(m_serviceName); if (!registered.isValid() || !registered.value()) { delete connection; } else { m_connection = connection; } } Q_Q(FcitxQtConnection); if (m_connection) { m_connection->connect("org.freedesktop.DBus.Local", "/org/freedesktop/DBus/Local", "org.freedesktop.DBus.Local", "Disconnected", this, SLOT (dbusDisconnected ())); m_connectedOnce = true; emit q->connected(); } }