<commit_before>#include "kclinfowidget.h"

#include "kclcode.h"
#include "kcldetect.h"
#include "kcldevicemodel.h"
#include "kclinputwidget.h"

#include <KIcon>
#include <KMessageBox>
#include <KPushButton>
#include <KSeparator>
#include <KLocale>
#include <KTabWidget>

#include <QGroupBox>
#include <QLabel>
#include <QProcess>
#include <QVBoxLayout>
#include <QStackedWidget>
#include <QComboBox>
#include <QTreeView>

KCLInfoWidget::KCLInfoWidget(QWidget *parent)
        : QWidget(parent)
{
    QVBoxLayout *layout = new QVBoxLayout;

    m_information = new QWidget;
    m_preview = new QWidget;
    KTabWidget *tab = new KTabWidget;
    tab->addTab(m_preview, KIcon("run-build-configure.png"), i18n("Preview"));
    tab->addTab(m_information, KIcon("run-build-file.png"), i18n("Information"));
    setupPreview();
    setupInformation();
    layout->addWidget(tab);
    setLayout(layout);
}

void KCLInfoWidget::setupPreview()
{
    QStackedWidget * widget = new QStackedWidget;
    QComboBox * combo = new QComboBox;

    foreach ( KCLInput * input, KCLDetect::inputList())
    {
        KCLInputWidget * w = new KCLInputWidget(input);
        combo->addItem(KCLCode::iconDevice(input->deviceType()),input->deviceName());
        widget->addWidget(w);
    }

    connect(combo,SIGNAL(currentIndexChanged(int)),widget,SLOT(setCurrentIndex(int)));
    combo->setCurrentIndex(combo->count()-1);
    QVBoxLayout * layout = new QVBoxLayout;
    layout->addWidget(combo);
    layout->addWidget(widget);
    m_preview->setLayout(layout);
}

void KCLInfoWidget::setupInformation()
{
    QVBoxLayout *layout = new QVBoxLayout;

    QLabel *info = new QLabel(i18n("Some Linux distributions forbid direct access \n to the input method used by KCL(evdev) as it can causes security-related issues\n"
                                    "If you are sure, you can allow direct access by clicking here."));

    KPushButton *buttonAuthorizate = new KPushButton(KIcon("dialog-password.png"), i18n("Set permissions"));
    KPushButton *buttonDetect = new KPushButton(KIcon("edit-find.png"), i18n("Detect devices"));

    connect(buttonAuthorizate, SIGNAL(clicked()), this, SLOT(setAuthorization()));
    connect(buttonDetect, SIGNAL(clicked()), this, SLOT(detectDevice()));

    QHBoxLayout *hlayout = new QHBoxLayout;
    hlayout->addWidget(info);
    hlayout->addStretch();
    hlayout->addWidget(buttonAuthorizate);
    hlayout->addWidget(buttonDetect);

    m_model = new KCLDeviceModel;
    m_treeView = new QTreeView;
    m_treeView->setModel(m_model);
    m_treeView->setIconSize(QSize(22, 22));
    layout->addLayout(hlayout);
    layout->addWidget(m_treeView);
    m_information->setLayout(layout);
}

void KCLInfoWidget::setAuthorization()
{
    //TODO: Find a better way to do that(either via HAL, PolicyKit, or use X11 libs instead of evdev.
    if (QProcess::execute("kdesudo chmod -R a+rwx /dev/input/*")) {
        KMessageBox::information(this, i18n("authorization success..."), i18n("success"));
    } else {
        KMessageBox::error(this, i18n("authorization failed..."), i18n("failed"));
    }
}

void KCLInfoWidget::detectDevice()
{
    m_model->clear();
    m_model->setupList();
}
<commit_msg>Give the model a parent, fixes a memory leak<commit_after>#include "kclinfowidget.h"

#include "kclcode.h"
#include "kcldetect.h"
#include "kcldevicemodel.h"
#include "kclinputwidget.h"

#include <KIcon>
#include <KMessageBox>
#include <KPushButton>
#include <KSeparator>
#include <KLocale>
#include <KTabWidget>

#include <QGroupBox>
#include <QLabel>
#include <QProcess>
#include <QVBoxLayout>
#include <QStackedWidget>
#include <QComboBox>
#include <QTreeView>

KCLInfoWidget::KCLInfoWidget(QWidget *parent)
        : QWidget(parent)
{
    QVBoxLayout *layout = new QVBoxLayout;

    m_information = new QWidget;
    m_preview = new QWidget;
    KTabWidget *tab = new KTabWidget;
    tab->addTab(m_preview, KIcon("run-build-configure.png"), i18n("Preview"));
    tab->addTab(m_information, KIcon("run-build-file.png"), i18n("Information"));
    setupPreview();
    setupInformation();
    layout->addWidget(tab);
    setLayout(layout);
}

void KCLInfoWidget::setupPreview()
{
    QStackedWidget * widget = new QStackedWidget;
    QComboBox * combo = new QComboBox;

    foreach ( KCLInput * input, KCLDetect::inputList())
    {
        KCLInputWidget * w = new KCLInputWidget(input);
        combo->addItem(KCLCode::iconDevice(input->deviceType()),input->deviceName());
        widget->addWidget(w);
    }

    connect(combo,SIGNAL(currentIndexChanged(int)),widget,SLOT(setCurrentIndex(int)));
    combo->setCurrentIndex(combo->count()-1);
    QVBoxLayout * layout = new QVBoxLayout;
    layout->addWidget(combo);
    layout->addWidget(widget);
    m_preview->setLayout(layout);
}

void KCLInfoWidget::setupInformation()
{
    QVBoxLayout *layout = new QVBoxLayout;

    QLabel *info = new QLabel(i18n("Some Linux distributions forbid direct access \n to the input method used by KCL(evdev) as it can causes security-related issues\n"
                                    "If you are sure, you can allow direct access by clicking here."));

    KPushButton *buttonAuthorizate = new KPushButton(KIcon("dialog-password.png"), i18n("Set permissions"));
    KPushButton *buttonDetect = new KPushButton(KIcon("edit-find.png"), i18n("Detect devices"));

    connect(buttonAuthorizate, SIGNAL(clicked()), this, SLOT(setAuthorization()));
    connect(buttonDetect, SIGNAL(clicked()), this, SLOT(detectDevice()));

    QHBoxLayout *hlayout = new QHBoxLayout;
    hlayout->addWidget(info);
    hlayout->addStretch();
    hlayout->addWidget(buttonAuthorizate);
    hlayout->addWidget(buttonDetect);

    m_model = new KCLDeviceModel(this);
    m_treeView = new QTreeView;
    m_treeView->setModel(m_model);
    m_treeView->setIconSize(QSize(22, 22));
    layout->addLayout(hlayout);
    layout->addWidget(m_treeView);
    m_information->setLayout(layout);
}

void KCLInfoWidget::setAuthorization()
{
    //TODO: Find a better way to do that(either via HAL, PolicyKit, or use X11 libs instead of evdev.
    if (QProcess::execute("kdesudo chmod -R a+rwx /dev/input/*")) {
        KMessageBox::information(this, i18n("authorization success..."), i18n("success"));
    } else {
        KMessageBox::error(this, i18n("authorization failed..."), i18n("failed"));
    }
}

void KCLInfoWidget::detectDevice()
{
    m_model->clear();
    m_model->setupList();
}

{'fraction_non_alphanumeric': 0.13966826848550612, 'fraction_numerical': 0.007750736319950395, 'mean_word_length': 4.463166807790008, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6586683', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2111, 'n_words': 432}