<commit_before>/* * This file is part of Maliit framework *
 *
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * and appearing in the file LICENSE.LGPL included in the packaging
 * of this file.
 */

#include "mdirectinputcontextplugin.h"

#include "mimserver.h"
#include "mimapphostedserverlogic.h"

#include "connectionfactory.h"
#include "mimdirectserverconnection.h"
#include "miminputcontextdirectconnection.h"

#include <maliit/inputmethod.h>

using namespace std::tr1;

#include <minputcontext.h>
#include <QString>
#include <QStringList>

namespace {
    const QString MaliitDirectInputContextName(MALIIT_INPUTCONTEXT_NAME"Direct");
}

MDirectInputContextPlugin::MDirectInputContextPlugin(QObject *parent)
    : QInputContextPlugin(parent)
{
    // nothing
}


MDirectInputContextPlugin::~MDirectInputContextPlugin()
{
    // nothing
}


QInputContext *MDirectInputContextPlugin::create(const QString &key)
{
    QInputContext *ctx = NULL;

    if (key == MaliitDirectInputContextName) {
        QSharedPointer<MImDirectServerConnection> serverConnection =
                qSharedPointerObjectCast<MImDirectServerConnection>(Maliit::createServerConnection(MaliitDirectInputContextName));
        MImInputContextDirectConnection *icConnection = new MImInputContextDirectConnection;
        serverConnection->connectTo(icConnection);

        shared_ptr<MInputContextConnection> icConn(icConnection);
        QSharedPointer<MImAppHostedServerLogic> serverLogic(new MImAppHostedServerLogic);
        MImServer::configureSettings(MImServer::TemporarySettings);
        MImServer *imServer = new MImServer(serverLogic, icConn);

        Maliit::InputMethod::instance()->setWidget(serverLogic->pluginsProxyWidget());

        ctx = new MInputContext(serverConnection, MaliitDirectInputContextName, this);
        imServer->setParent(ctx);
    } else {
        qCritical() << "Unknown plugin name";
    }

    return ctx;
}


QString MDirectInputContextPlugin::description(const QString &s)
{
    Q_UNUSED(s);

    return "Maliit input context plugin";
}


QString MDirectInputContextPlugin::displayName(const QString &s)
{
    Q_UNUSED(s);

    // TODO: want this translated?
    return "Input context for Maliit input methods";
}


QStringList MDirectInputContextPlugin::keys() const
{
    return QStringList(MaliitDirectInputContextName);<commit_msg>Differentiate direct input context plugin description strings<commit_after>/* * This file is part of Maliit framework *
 *
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * and appearing in the file LICENSE.LGPL included in the packaging
 * of this file.
 */

#include "mdirectinputcontextplugin.h"

#include "mimserver.h"
#include "mimapphostedserverlogic.h"

#include "connectionfactory.h"
#include "mimdirectserverconnection.h"
#include "miminputcontextdirectconnection.h"

#include <maliit/inputmethod.h>

using namespace std::tr1;

#include <minputcontext.h>
#include <QString>
#include <QStringList>

namespace {
    const QString MaliitDirectInputContextName(MALIIT_INPUTCONTEXT_NAME"Direct");
}

MDirectInputContextPlugin::MDirectInputContextPlugin(QObject *parent)
    : QInputContextPlugin(parent)
{
    // nothing
}


MDirectInputContextPlugin::~MDirectInputContextPlugin()
{
    // nothing
}


QInputContext *MDirectInputContextPlugin::create(const QString &key)
{
    QInputContext *ctx = NULL;

    if (key == MaliitDirectInputContextName) {
        QSharedPointer<MImDirectServerConnection> serverConnection =
                qSharedPointerObjectCast<MImDirectServerConnection>(Maliit::createServerConnection(MaliitDirectInputContextName));
        MImInputContextDirectConnection *icConnection = new MImInputContextDirectConnection;
        serverConnection->connectTo(icConnection);

        shared_ptr<MInputContextConnection> icConn(icConnection);
        QSharedPointer<MImAppHostedServerLogic> serverLogic(new MImAppHostedServerLogic);
        MImServer::configureSettings(MImServer::TemporarySettings);
        MImServer *imServer = new MImServer(serverLogic, icConn);

        Maliit::InputMethod::instance()->setWidget(serverLogic->pluginsProxyWidget());

        ctx = new MInputContext(serverConnection, MaliitDirectInputContextName, this);
        imServer->setParent(ctx);
    } else {
        qCritical() << "Unknown plugin name";
    }

    return ctx;
}


QString MDirectInputContextPlugin::description(const QString &s)
{
    Q_UNUSED(s);

    return "Maliit input context plugin (direct)";
}


QString MDirectInputContextPlugin::displayName(const QString &s)
{
    Q_UNUSED(s);

    // TODO: want this translated?
    return "Input context for Maliit input methods (direct)";
}


QStringList MDirectInputContextPlugin::keys() const
{
    return QStringList(MaliitDirectInputContextName);
{'fraction_non_alphanumeric': 0.09118311981914091, 'fraction_numerical': 0.0026375282592313487, 'mean_word_length': 4.931843575418994, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5833120', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1502, 'n_words': 351}