<commit_before>#include "DactApplication.hh"
#include <QDesktopServices>
#include <QFileOpenEvent>


DactApplication::DactApplication(int &argc, char** argv)
:
QApplication(argc, argv),
d_mainWindow(0)
{
    //d_mainWindow = new DactMainWindow();
}

void DactApplication::init()
{
    QDesktopServices::setUrlHandler("dact", this, "openUrl");

    d_mainWindow.reset(new MainWindow());
    d_mainWindow->show();
}

bool DactApplication::event(QEvent *event)
{
    qDebug() << "event" << event->type();
    switch (event->type())
    {
        case QEvent::FileOpen:
        {
            QFileOpenEvent *fileEvent(static_cast<QFileOpenEvent *>(event));
            
            if (!fileEvent->file().isEmpty())
            {
                QStringList files;
                files << fileEvent->file();
                openCorpora(files);
            }

            else if (!fileEvent->url().isEmpty())
                openUrl(fileEvent->url());
            
            else
                return false;

            return true;
        }
        default:
            return QApplication::event(event);
    }
}

void DactApplication::openCorpora(QStringList const &fileNames)
{
    d_mainWindow->readCorpora(fileNames);
}

void DactApplication::openMacros(QStringList const &fileNames)
{
    d_mainWindow->readMacros(fileNames);
}

void DactApplication::openUrl(QUrl const &url)
{
    if (url.scheme() != "dact")
        return;

    if (url.hasQueryItem("filter"))
    {
        QByteArray encodedFilter(url.queryItemValue("filter").toUtf8());
        d_mainWindow->setFilter(QUrl::fromPercentEncoding(encodedFilter));
    }

    if (url.hasQueryItem("corpus"))
    {
        QStringList fileNames;

        foreach (QString fileName, url.allQueryItemValues("corpus"))
        {
            QByteArray encodedFileName(fileName.toUtf8());
            fileNames << QUrl::fromPercentEncoding(encodedFileName);
        }

        d_mainWindow->readCorpora(fileNames);
    }
}<commit_msg>Disable corpus path parameter in dact urls for now.<commit_after>#include "DactApplication.hh"
#include <QDesktopServices>
#include <QFileOpenEvent>


DactApplication::DactApplication(int &argc, char** argv)
:
QApplication(argc, argv),
d_mainWindow(0)
{
    //d_mainWindow = new DactMainWindow();
}

void DactApplication::init()
{
    QDesktopServices::setUrlHandler("dact", this, "openUrl");

    d_mainWindow.reset(new MainWindow());
    d_mainWindow->show();
}

bool DactApplication::event(QEvent *event)
{
    qDebug() << "event" << event->type();
    switch (event->type())
    {
        case QEvent::FileOpen:
        {
            QFileOpenEvent *fileEvent(static_cast<QFileOpenEvent *>(event));
            
            if (!fileEvent->file().isEmpty())
            {
                QStringList files;
                files << fileEvent->file();
                openCorpora(files);
            }

            else if (!fileEvent->url().isEmpty())
                openUrl(fileEvent->url());
            
            else
                return false;

            return true;
        }
        default:
            return QApplication::event(event);
    }
}

void DactApplication::openCorpora(QStringList const &fileNames)
{
    d_mainWindow->readCorpora(fileNames);
}

void DactApplication::openMacros(QStringList const &fileNames)
{
    d_mainWindow->readMacros(fileNames);
}

void DactApplication::openUrl(QUrl const &url)
{
    if (url.scheme() != "dact")
        return;

    if (url.hasQueryItem("filter"))
    {
        QByteArray encodedFilter(url.queryItemValue("filter").toUtf8());
        d_mainWindow->setFilter(QUrl::fromPercentEncoding(encodedFilter));
    }

    // Disabled because I don't trust this functionality. I think it can
    // be easily abused to let Dact open arbritray files. We then have to
    // trust dbxml for doing nothing stupid.
    #if 0
    if (url.hasQueryItem("corpus"))
    {
        QStringList fileNames;

        foreach (QString fileName, url.allQueryItemValues("corpus"))
        {
            QByteArray encodedFileName(fileName.toUtf8());
            fileNames << QUrl::fromPercentEncoding(encodedFileName);
        }

        d_mainWindow->readCorpora(fileNames);
    }
    #endif
}
{'fraction_non_alphanumeric': 0.12692034979910186, 'fraction_numerical': 0.0016544552115339162, 'mean_word_length': 2.6017021276595744, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '6683483', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1242, 'n_words': 225}