<commit_before>/*
 * Copyright (C) 2014  <NAME> (PCMan) <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include "sessionapplication.h"
#include "sessiondbusadaptor.h"
#include "lxqtmodman.h"
#include "UdevNotifier.h"
#include "numlock.h"
#include "lockscreenmanager.h"
#include <unistd.h>
#include <csignal>
#include <LXQt/Settings>
#include <QProcess>
#include "log.h"

#include <QX11Info>
// XKB, this should be disabled in Wayland?
#include <X11/XKBlib.h>

SessionApplication::SessionApplication(int& argc, char** argv) :
    LXQt::Application(argc, argv)
{
    listenToUnixSignals({SIGINT, SIGTERM, SIGQUIT, SIGHUP});
    char* winmanager = NULL;
    int c;
    while ((c = getopt (argc, argv, "c:w:")) != -1)
    {
        if (c == 'c')
        {
            configName = optarg;
            break;
        }
        else if (c == 'w')
        {
            winmanager = optarg;
            break;
        }
    }

    if(configName.isEmpty())
      configName = "session";

    // tell the world which config file we're using.
    qputenv("LXQT_SESSION_CONFIG", configName.toUtf8());

    lockScreenManager = new LockScreenManager(this);

    modman = new LXQtModuleManager(winmanager);
    connect(this, &LXQt::Application::unixSignal, modman, &LXQtModuleManager::logout);
    new SessionDBusAdaptor(modman);
    // connect to D-Bus and register as an object:
    QDBusConnection::sessionBus().registerService("org.lxqt.session");
    QDBusConnection::sessionBus().registerObject("/LXQtSession", modman);

    // Wait until the event loop starts
    QTimer::singleShot(0, this, SLOT(startup()));
}

SessionApplication::~SessionApplication()
{
    delete modman;
}

bool SessionApplication::startup()
{
    LXQt::Settings settings(configName);
    qCDebug(SESSION) << __FILE__ << ":" << __LINE__ << "Session" << configName << "about to launch (default 'session')";

    loadEnvironmentSettings(settings);
    // loadFontSettings(settings);
    loadKeyboardSettings(settings);
    loadMouseSettings(settings);

#if defined(WITH_LIBUDEV_MONITOR)
    UdevNotifier * dev_notifier = new UdevNotifier{QStringLiteral("input"), this}; //will be released upon our destruction
    QTimer * dev_timer = new QTimer{this}; //will be released upon our destruction
    dev_timer->setSingleShot(true);
    dev_timer->setInterval(500); //give some time to xorg... we need to reset keyboard afterwards
    connect(dev_timer, &QTimer::timeout, [this]
            {
                //XXX: is this a race? (because settings can be currently changed by lxqt-config-input)
                //     but with such a little probablity we can live...
                LXQt::Settings settings(configName);
                loadKeyboardSettings(settings);
            });
    connect(dev_notifier, &UdevNotifier::deviceAdded, [this, dev_timer] (QString device)
            {
                qCInfo(SESSION) << QStringLiteral("Session '%1', new input device '%2', keyboard setting will be (optionaly) reloaded...").arg(configName).arg(device);
                dev_timer->start();
            });
#endif

    if (lockScreenManager->startup())
        qDebug() << "LockScreenManager started successfully";<commit_msg>lxqt-session: Replace qCInfo() by qCWarning()<commit_after>/*
 * Copyright (C) 2014  <NAME> (PCMan) <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include "sessionapplication.h"
#include "sessiondbusadaptor.h"
#include "lxqtmodman.h"
#include "UdevNotifier.h"
#include "numlock.h"
#include "lockscreenmanager.h"
#include <unistd.h>
#include <csignal>
#include <LXQt/Settings>
#include <QProcess>
#include "log.h"

#include <QX11Info>
// XKB, this should be disabled in Wayland?
#include <X11/XKBlib.h>

SessionApplication::SessionApplication(int& argc, char** argv) :
    LXQt::Application(argc, argv)
{
    listenToUnixSignals({SIGINT, SIGTERM, SIGQUIT, SIGHUP});
    char* winmanager = NULL;
    int c;
    while ((c = getopt (argc, argv, "c:w:")) != -1)
    {
        if (c == 'c')
        {
            configName = optarg;
            break;
        }
        else if (c == 'w')
        {
            winmanager = optarg;
            break;
        }
    }

    if(configName.isEmpty())
      configName = "session";

    // tell the world which config file we're using.
    qputenv("LXQT_SESSION_CONFIG", configName.toUtf8());

    lockScreenManager = new LockScreenManager(this);

    modman = new LXQtModuleManager(winmanager);
    connect(this, &LXQt::Application::unixSignal, modman, &LXQtModuleManager::logout);
    new SessionDBusAdaptor(modman);
    // connect to D-Bus and register as an object:
    QDBusConnection::sessionBus().registerService("org.lxqt.session");
    QDBusConnection::sessionBus().registerObject("/LXQtSession", modman);

    // Wait until the event loop starts
    QTimer::singleShot(0, this, SLOT(startup()));
}

SessionApplication::~SessionApplication()
{
    delete modman;
}

bool SessionApplication::startup()
{
    LXQt::Settings settings(configName);
    qCDebug(SESSION) << __FILE__ << ":" << __LINE__ << "Session" << configName << "about to launch (default 'session')";

    loadEnvironmentSettings(settings);
    // loadFontSettings(settings);
    loadKeyboardSettings(settings);
    loadMouseSettings(settings);

#if defined(WITH_LIBUDEV_MONITOR)
    UdevNotifier * dev_notifier = new UdevNotifier{QStringLiteral("input"), this}; //will be released upon our destruction
    QTimer * dev_timer = new QTimer{this}; //will be released upon our destruction
    dev_timer->setSingleShot(true);
    dev_timer->setInterval(500); //give some time to xorg... we need to reset keyboard afterwards
    connect(dev_timer, &QTimer::timeout, [this]
            {
                //XXX: is this a race? (because settings can be currently changed by lxqt-config-input)
                //     but with such a little probablity we can live...
                LXQt::Settings settings(configName);
                loadKeyboardSettings(settings);
            });
    connect(dev_notifier, &UdevNotifier::deviceAdded, [this, dev_timer] (QString device)
            {
                qCWarning(SESSION) << QStringLiteral("Session '%1', new input device '%2', keyboard setting will be (optionaly) reloaded...").arg(configName).arg(device);
                dev_timer->start();
            });
#endif

    if (lockScreenManager->startup())
        qDebug() << "LockScreenManager started successfully";
{'fraction_non_alphanumeric': 0.11659650465620615, 'fraction_numerical': 0.007398902921290981, 'mean_word_length': 3.3410852713178296, 'pattern_counts': {'":': 2, '<': 53, '<?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': '3385576', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2276, 'n_words': 699}