<commit_before>/**
 *  For conditions of distribution and use, see copyright notice in license.txt
 *
 *  @file   
 *  @brief  
 */

#include "StableHeaders.h"
#include "DebugOperatorNew.h"

#include "LoginScreenModule.h"
#include "LoginWidget.h"

#include "UiServiceInterface.h"
#include "Input.h"
#include "LoginServiceInterface.h"
#include "UiServiceInterface.h"
#include "UiProxyWidget.h"
#include "EventManager.h"

#ifdef ENABLE_TAIGA_LOGIN
#include "../ProtocolUtilities/NetworkEvents.h"
#endif

#include "../TundraLogicModule/TundraEvents.h"

#include "MemoryLeakCheck.h"

/*
void StoreLoginInfo(const QMap<QString, QString> &login_info)
{
    QSettings settings(QSettings::IniFormat, QSettings::UserScope, APPLICATION_NAME, classic_settings_name_);
    settings.setValue("avatar/type", classic_login_info["avatartype"]);
    settings.setValue("avatar/account", classic_login_info["account"]);
    settings.setValue("avatar/password", QByteArray(classic_login_info["password"].toStdString().c_str()).toBase64());
    settings.setValue("world/loginurl", QUrl(classic_login_info["loginurl"]));
    settings.setValue("world/startlocation", classic_login_info["startlocation"]);
}

QMap<QString, QString> GetLoginInfo() const
{
    QSettings classic_settings(QSettings::IniFormat, QSettings::UserScope, APPLICATION_NAME, classic_settings_name_);
    QMap<QString, QString> info;
    info["avatartype"] = classic_settings.value("avatar/type").toString();
    info["account"] = classic_settings.value("avatar/account").toString();
    info["password"] = QByteArray::fromBase64(classic_settings.value("avatar/password").toByteArray());
    info["loginurl"] = classic_settings.value("world/loginurl").toUrl().toString();
    info["startlocation"] = classic_settings.value("world/startlocation").toString();
    return data_map;
}
*/

std::string LoginScreenModule::type_name_static_ = "LoginScreen";

LoginScreenModule::LoginScreenModule() :
    IModule(type_name_static_),
    window_(0),
    framework_category_(0),
    network_category_(0),
    connected_(false)
{
}

LoginScreenModule::~LoginScreenModule()
{
}

void LoginScreenModule::PreInitialize()
{
}

void LoginScreenModule::Initialize()
{
}

void LoginScreenModule::PostInitialize()
{
    input_ = framework_->GetInput()->RegisterInputContext("LoginScreenInput", 101);
    input_->SetTakeKeyboardEventsOverQt(true);
    connect(input_.get(), SIGNAL(KeyPressed(KeyEvent *)), SLOT(HandleKeyEvent(KeyEvent *)));

    UiServiceInterface *ui = framework_->GetService<UiServiceInterface>();
    if (ui)
    {
        window_ = new LoginWidget(framework_);
        connect(window_, SIGNAL(ExitClicked()), SLOT(Exit()));

        ui->AddWidgetToScene(window_, Qt::Widget);
//        ui->ShowWidget(window_);

        Foundation::LoginServiceInterface *login = framework_->GetService<Foundation::LoginServiceInterface>();
        if (login)
        {
            connect(window_, SIGNAL(Connect(const QMap<QString, QString> &)),
                login, SLOT(ProcessLoginData(const QMap<QString, QString> &)));

            // Connect also to Tundra login
            connect(window_, SIGNAL(Connect(const QMap<QString, QString> &)),
                this, SLOT(ProcessTundraLogin(const QMap<QString, QString> &)));
            
            connect(login, SIGNAL(LoginStarted()), window_, SLOT(StartProgressBar()));

            connect(login, SIGNAL(LoginFailed(const QString &)), window_, SLOT(StopProgressBar()));<commit_msg>Revert "Commented a line which shows LoginWidget on screen. This is for demo purposes and running "./viewer --run autoConnect.js" is preferable."<commit_after>/**
 *  For conditions of distribution and use, see copyright notice in license.txt
 *
 *  @file   
 *  @brief  
 */

#include "StableHeaders.h"
#include "DebugOperatorNew.h"

#include "LoginScreenModule.h"
#include "LoginWidget.h"

#include "UiServiceInterface.h"
#include "Input.h"
#include "LoginServiceInterface.h"
#include "UiServiceInterface.h"
#include "UiProxyWidget.h"
#include "EventManager.h"

#ifdef ENABLE_TAIGA_LOGIN
#include "../ProtocolUtilities/NetworkEvents.h"
#endif

#include "../TundraLogicModule/TundraEvents.h"

#include "MemoryLeakCheck.h"

/*
void StoreLoginInfo(const QMap<QString, QString> &login_info)
{
    QSettings settings(QSettings::IniFormat, QSettings::UserScope, APPLICATION_NAME, classic_settings_name_);
    settings.setValue("avatar/type", classic_login_info["avatartype"]);
    settings.setValue("avatar/account", classic_login_info["account"]);
    settings.setValue("avatar/password", QByteArray(classic_login_info["password"].toStdString().c_str()).toBase64());
    settings.setValue("world/loginurl", QUrl(classic_login_info["loginurl"]));
    settings.setValue("world/startlocation", classic_login_info["startlocation"]);
}

QMap<QString, QString> GetLoginInfo() const
{
    QSettings classic_settings(QSettings::IniFormat, QSettings::UserScope, APPLICATION_NAME, classic_settings_name_);
    QMap<QString, QString> info;
    info["avatartype"] = classic_settings.value("avatar/type").toString();
    info["account"] = classic_settings.value("avatar/account").toString();
    info["password"] = QByteArray::fromBase64(classic_settings.value("avatar/password").toByteArray());
    info["loginurl"] = classic_settings.value("world/loginurl").toUrl().toString();
    info["startlocation"] = classic_settings.value("world/startlocation").toString();
    return data_map;
}
*/

std::string LoginScreenModule::type_name_static_ = "LoginScreen";

LoginScreenModule::LoginScreenModule() :
    IModule(type_name_static_),
    window_(0),
    framework_category_(0),
    network_category_(0),
    connected_(false)
{
}

LoginScreenModule::~LoginScreenModule()
{
}

void LoginScreenModule::PreInitialize()
{
}

void LoginScreenModule::Initialize()
{
}

void LoginScreenModule::PostInitialize()
{
    input_ = framework_->GetInput()->RegisterInputContext("LoginScreenInput", 101);
    input_->SetTakeKeyboardEventsOverQt(true);
    connect(input_.get(), SIGNAL(KeyPressed(KeyEvent *)), SLOT(HandleKeyEvent(KeyEvent *)));

    UiServiceInterface *ui = framework_->GetService<UiServiceInterface>();
    if (ui)
    {
        window_ = new LoginWidget(framework_);
        connect(window_, SIGNAL(ExitClicked()), SLOT(Exit()));

        ui->AddWidgetToScene(window_, Qt::Widget);
        ui->ShowWidget(window_);

        Foundation::LoginServiceInterface *login = framework_->GetService<Foundation::LoginServiceInterface>();
        if (login)
        {
            connect(window_, SIGNAL(Connect(const QMap<QString, QString> &)),
                login, SLOT(ProcessLoginData(const QMap<QString, QString> &)));

            // Connect also to Tundra login
            connect(window_, SIGNAL(Connect(const QMap<QString, QString> &)),
                this, SLOT(ProcessTundraLogin(const QMap<QString, QString> &)));
            
            connect(login, SIGNAL(LoginStarted()), window_, SLOT(StartProgressBar()));

            connect(login, SIGNAL(LoginFailed(const QString &)), window_, SLOT(StopProgressBar()));
{'fraction_non_alphanumeric': 0.14275628353572437, 'fraction_numerical': 0.002824060999717594, 'mean_word_length': 5.191433566433567, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, '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': '396864', 'n_tokens_mistral': 2123, 'n_tokens_neox': 2101, 'n_words': 337}