Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    KLocalizedString::setApplicationDomain("ktp-text-ui");

    Kdelibs4ConfigMigrator migrator(QLatin1String("ktp-text-ui"));
    migrator.setConfigFiles(QStringList() << QLatin1String("ktp-text-uirc"));
    migrator.setUiFiles(QStringList() << QLatin1String("chatwindow.rc"));
    migrator.migrate();

    // KAboutData is in telepathy-chat-ui.cpp, read there why

    Tp::registerTypes();
    KTp::registerOtrTypes();

    Tp::SharedPtr<TelepathyChatUi> app(new TelepathyChatUi(argc, argv));

    Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
    channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);

    Tp::Features textFeatures = Tp::Features() << Tp::TextChannel::FeatureMessageQueue
                                               << Tp::TextChannel::FeatureMessageSentSignal
                                               << Tp::TextChannel::FeatureChatState
                                               << Tp::TextChannel::FeatureMessageCapabilities;
    channelFactory->addFeaturesForTextChats(textFeatures);
    channelFactory->addFeaturesForTextChatrooms(textFeatures);
    channelFactory->addFeaturesForOutgoingFileTransfers(Tp::OutgoingFileTransferChannel::FeatureCore);

    Tp::ClientRegistrarPtr registrar = Tp::ClientRegistrar::create(KTp::accountFactory(), KTp::connectionFactory(), channelFactory, KTp::contactFactory());

    Tp::AbstractClientPtr handler = Tp::AbstractClientPtr(app);
    registrar->registerClient(handler, QLatin1String(KTP_TEXTUI_CLIENT_NAME));

    return app->exec();
}
int main(int argc, char *argv[])
{
    KAboutData aboutData("ktp-auth-handler",
                         i18n("Telepathy Authentication Handler"),

                         KTP_AUTH_HANDLER_VERSION);
    aboutData.addAuthor(i18n("David Edmundson"), i18n("Developer"), "*****@*****.**");
    aboutData.addAuthor(i18n("Daniele E. Domenichelli"), i18n("Developer"), "*****@*****.**");
    aboutData.setProductName("telepathy/auth-handler");
    aboutData.setProgramIconName(QLatin1String("telepathy-kde"));

    KAboutData::setApplicationData(aboutData);

    // This is a very very very ugly hack that attempts to solve the following problem:
    // D-Bus service activated applications inherit the environment of dbus-daemon.
    // Normally, in KDE, startkde sets these environment variables. However, the session's
    // dbus-daemon is started before this happens, which means that dbus-daemon does NOT
    // have these variables in its environment and therefore all service-activated UIs
    // think that they are not running in KDE. This causes Qt not to load the KDE platform
    // plugin, which leaves the UI in a sorry state, using a completely wrong theme,
    // wrong colors, etc...
    // See also:
    // - https://bugs.kde.org/show_bug.cgi?id=269861
    // - https://bugs.kde.org/show_bug.cgi?id=267770
    // - https://git.reviewboard.kde.org/r/102194/
    // Here we are just going to assume that kde-telepathy is always used in KDE and
    // not anywhere else. This is probably the best that we can do.
    setenv("KDE_FULL_SESSION", "true", 0);
    setenv("KDE_SESSION_VERSION", "5", 0);

    KTp::TelepathyHandlerApplication app(argc, argv);

    // FIXME: Move this to tp-qt4 itself
    registerTypes();

    Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(
            QDBusConnection::sessionBus(), Tp::Account::FeatureCore);
    Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(
            QDBusConnection::sessionBus(), Tp::Connection::FeatureCore);
    Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(
            QDBusConnection::sessionBus());
    channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
    Tp::ClientRegistrarPtr clientRegistrar = Tp::ClientRegistrar::create(
            accountFactory, connectionFactory, channelFactory);

    QMap<QString,Tp::AbstractClientPtr> handlers;
    handlers.insert(QLatin1String("KTp.SASLHandler"), Tp::SharedPtr<SaslHandler>(new SaslHandler));
    handlers.insert(QLatin1String("KTp.TLSHandler"), Tp::SharedPtr<TlsHandler>(new TlsHandler));
    Tp::ChannelClassSpecList confAuthFilter =  Tp::ChannelClassSpecList() << Tp::ChannelClassSpec::textChatroom();
    handlers.insert(QLatin1String("KTp.ConfAuthObserver"), Tp::SharedPtr<ConferenceAuthObserver>(new ConferenceAuthObserver(confAuthFilter)));

    int loadedHandlers = handlers.count();
    QMap<QString,Tp::AbstractClientPtr>::ConstIterator iter = handlers.constBegin();
    for (; iter != handlers.constEnd(); ++iter) {
        if (!clientRegistrar->registerClient(iter.value(), iter.key())) {
            loadedHandlers--;
        }
    }

    if (loadedHandlers == 0) {
        qDebug() << "No handlers registered. Exiting";
        return 1;
    }

    return app.exec();
}