<commit_before>#include "application.h"

#include <QtQml>
#include <QScreen>
#include <QKeyEvent>
#include <QQuickView>
#include <QStandardPaths>
#include <QDebug>
#include <QDir>
#include <QFontDatabase>
#include <QFile>
#include <QWeakPointer>

#include "imageprovider.h"

#include "quick/enums.h"
#include "quick/models.h"
#include "quick/quicktrackinfo.h"
#include "quick/quickmosaicgenerator.h"
#include "quick/quickfactory.h"
#include "quick/quickartistsynopsis.h"
#include "quick/quickglobalstatemachine.h"

#include "../../appkey.c"

namespace sp = Spotinetta;

namespace {
// This global is unfortunately necessary for the Qt Quick models
// to retrieve the current session
QWeakPointer<Spotinetta::Session> g_session;
}

namespace Sonetta {

Application::Application(QObject * parent)
    :   QObject(parent),
      m_view(new QQuickView),
      m_ui(new UIStateCoordinator),
      m_output(new AudioOutput),
      m_settings(new Settings),
      m_exiting(false)
{
    createSession();

    m_player.reset(new Player(m_session, m_output));
    m_search.reset(new SearchEngine(m_session.constCast<const sp::Session>(), m_settings));

    connect(m_session.data(), &sp::Session::loggedOut, this, &Application::onLogout);
    connect(m_session.data(), &sp::Session::log, [] (const QString &msg) { qDebug() << msg; });

    connect(m_settings.data(), &Settings::mouseEnabledChanged, this, &Application::updateCursor);

    m_view->installEventFilter(this);
}

Application::~Application()
{
    // Manually reset view here to make sure it's deleted
    // before any of the others (Player, SearchEngine etc.)
    m_view.reset();
}

bool Application::initialize()
{
    registerQmlTypes();

    if (m_session->error() == sp::Error::Ok)
    {
        m_navigation.initialize(m_settings->lircDelay());

        setupQuickEnvironment();
        showUi();
        return true;
    }
    else
    {
        const QByteArray error = sp::errorMessage(m_session->error()).toUtf8();
        qFatal("Session creation failed. Error: %s", error.constData());
        return false;
    }
}

void Application::onExit()
{
    if (!m_exiting)
    {
        m_exiting = true;
        if (m_session->connectionState() == sp::Session::ConnectionState::LoggedIn
                || m_session->connectionState() == sp::Session::ConnectionState::Offline)
        {
            m_session->logout();
        }
        else
        {
            // Skip session logout<commit_msg>Enabled mouse<commit_after>#include "application.h"

#include <QtQml>
#include <QScreen>
#include <QKeyEvent>
#include <QQuickView>
#include <QStandardPaths>
#include <QDebug>
#include <QDir>
#include <QFontDatabase>
#include <QFile>
#include <QWeakPointer>

#include "imageprovider.h"

#include "quick/enums.h"
#include "quick/models.h"
#include "quick/quicktrackinfo.h"
#include "quick/quickmosaicgenerator.h"
#include "quick/quickfactory.h"
#include "quick/quickartistsynopsis.h"
#include "quick/quickglobalstatemachine.h"

#include "../../appkey.c"

namespace sp = Spotinetta;

namespace {
// This global is unfortunately necessary for the Qt Quick models
// to retrieve the current session
QWeakPointer<Spotinetta::Session> g_session;
}

namespace Sonetta {

Application::Application(QObject * parent)
    :   QObject(parent),
      m_view(new QQuickView),
      m_ui(new UIStateCoordinator),
      m_output(new AudioOutput),
      m_settings(new Settings),
      m_exiting(false)
{
    createSession();

    m_player.reset(new Player(m_session, m_output));
    m_search.reset(new SearchEngine(m_session.constCast<const sp::Session>(), m_settings));

    connect(m_session.data(), &sp::Session::loggedOut, this, &Application::onLogout);
    connect(m_session.data(), &sp::Session::log, [] (const QString &msg) { qDebug() << msg; });

    connect(m_settings.data(), &Settings::mouseEnabledChanged, this, &Application::updateCursor);

    m_view->installEventFilter(this);
}

Application::~Application()
{
    // Manually reset view here to make sure it's deleted
    // before any of the others (Player, SearchEngine etc.)
    m_view.reset();
}

bool Application::initialize()
{
    registerQmlTypes();

    // Enable mouse
    m_settings->setMouseEnabled(true);

    if (m_session->error() == sp::Error::Ok)
    {
        m_navigation.initialize(m_settings->lircDelay());

        setupQuickEnvironment();
        showUi();
        return true;
    }
    else
    {
        const QByteArray error = sp::errorMessage(m_session->error()).toUtf8();
        qFatal("Session creation failed. Error: %s", error.constData());
        return false;
    }
}

void Application::onExit()
{
    if (!m_exiting)
    {
        m_exiting = true;
        if (m_session->connectionState() == sp::Session::ConnectionState::LoggedIn
                || m_session->connectionState() == sp::Session::ConnectionState::Offline)
        {
            m_session->logout();
        }
        else
        {
            // Skip session logout
{'fraction_non_alphanumeric': 0.14041783848935316, 'fraction_numerical': 0.0004017677782241864, 'mean_word_length': 3.7239089184060723, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 42, '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': '2452802', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1536, 'n_words': 319}