<commit_before>/* dtkAbstractApplication.cpp ---
 *
 * Author: <NAME>
 * Copyright (C) 2015 - <NAME>, Inria.
 * Created: 2015/02/04 12:03:44
 */

/* Commentary:
 *
 */

/* Change log:
 *
 */

#include "dtkAbstractApplication.h"

class dtkAbstractApplicationPrivate
{
public:
    QSettings *settings;
    QCommandLineParser parser;

};

dtkAbstractApplication::dtkAbstractApplication(void)
{
    d = new dtkAbstractApplicationPrivate;
    d->settings = NULL;
    d->parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);

}

dtkAbstractApplication::~dtkAbstractApplication(void)
{
    if (d->settings)
        delete d->settings;

    delete d;
    d = NULL;
}

QSettings *dtkAbstractApplication::settings(void)
{
    return d->settings;
}

bool dtkAbstractApplication::noGui(void) {
    return true;
}

QCommandLineParser *dtkAbstractApplication::parser(void)
{
    return &(d->parser);
}

void dtkAbstractApplication::setApplicationName(const QString& name)
{
    qApp->setApplicationName(name);
}

QString dtkAbstractApplication::applicationName(void)
{
    return qApp->applicationName();
}

void dtkAbstractApplication::setOrganizationName(const QString& name)
{
    qApp->setOrganizationName(name);
}

void dtkAbstractApplication::setOrganizationDomain(const QString& name)
{
    qApp->setOrganizationDomain(name);
}

void dtkAbstractApplication::setApplicationVersion(const QString& version)
{
    qApp->setApplicationVersion(version);
}

void dtkAbstractApplication::initialize(void)
{
    // unset QT_PLUGIN_PATH, otherwise, kde plugins can change the qmetatype ids
    qputenv("QT_PLUGIN_PATH", "1");
    qputenv("LC_ALL", "C");
    QLocale::setDefault(QLocale::c());

#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
    // to avoid troubles with floats separators ('.' and not ',')
    setlocale(LC_NUMERIC, "C");
#endif

    d->parser.addHelpOption();
    d->parser.addVersionOption();

    QCommandLineOption settingsOption("settings", "settings file", "filename");
    d->parser.addOption(settingsOption);

    QCommandLineOption verboseOption("verbose", QCoreApplication::translate("main", "verbose plugin initialization"));
    d->parser.addOption(verboseOption);

    QCommandLineOption nonguiOption(QStringList() << "nw" << "no-window", QCoreApplication::translate("main", "non GUI application (no window)"));
    d->parser.addOption(nonguiOption);

    QString verbosity = "info";
    QCommandLineOption loglevelOption("loglevel", "log level used by dtkLog (default is info)", "trace|debug|info|warn|error|fatal", verbosity);
    d->parser.addOption(loglevelOption);

    QCoreApplication *q = dynamic_cast<QCoreApplication *>(this);
    QCommandLineOption logfileOption("logfile", qPrintable(QString("log file used by dtkLog; default is: ").append(dtkLogPath(q))),"filename | console",dtkLogPath(q));
    d->parser.addOption(logfileOption);

    d->parser.process(*q);

    if(d->parser.isSet(settingsOption)) {
        d->settings = new QSettings(d->parser.value(settingsOption), QSettings::IniFormat);
    } else {
        d->settings = new QSettings(q->organizationName(), q->applicationName());
    }
    if (d->settings->contains("log_level")) {
        dtkLogger::instance().setLevel(d->settings->value("log_level").toString());
    } else {
        if (d->parser.isSet(loglevelOption)) {
            verbosity= d->parser.value(loglevelOption);
        }
        dtkLogger::instance().setLevel(verbosity);
    }
    if (d->parser.isSet(logfileOption)) {
        if (d->parser.value(logfileOption) == "console") {
            dtkLogger::instance().attachConsole();
        } else {
            dtkLogger::instance().attachFile(d->parser.value(logfileOption));
        }
    }
}
<commit_msg>create log file with default path if not set on the command line<commit_after>/* dtkAbstractApplication.cpp ---
 *
 * Author: <NAME>
 * Copyright (C) 2015 - <NAME>, Inria.
 * Created: 2015/02/04 12:03:44
 */

/* Commentary:
 *
 */

/* Change log:
 *
 */

#include "dtkAbstractApplication.h"

class dtkAbstractApplicationPrivate
{
public:
    QSettings *settings;
    QCommandLineParser parser;

};

dtkAbstractApplication::dtkAbstractApplication(void)
{
    d = new dtkAbstractApplicationPrivate;
    d->settings = NULL;
    d->parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);

}

dtkAbstractApplication::~dtkAbstractApplication(void)
{
    if (d->settings)
        delete d->settings;

    delete d;
    d = NULL;
}

QSettings *dtkAbstractApplication::settings(void)
{
    return d->settings;
}

bool dtkAbstractApplication::noGui(void) {
    return true;
}

QCommandLineParser *dtkAbstractApplication::parser(void)
{
    return &(d->parser);
}

void dtkAbstractApplication::setApplicationName(const QString& name)
{
    qApp->setApplicationName(name);
}

QString dtkAbstractApplication::applicationName(void)
{
    return qApp->applicationName();
}

void dtkAbstractApplication::setOrganizationName(const QString& name)
{
    qApp->setOrganizationName(name);
}

void dtkAbstractApplication::setOrganizationDomain(const QString& name)
{
    qApp->setOrganizationDomain(name);
}

void dtkAbstractApplication::setApplicationVersion(const QString& version)
{
    qApp->setApplicationVersion(version);
}

void dtkAbstractApplication::initialize(void)
{
    // unset QT_PLUGIN_PATH, otherwise, kde plugins can change the qmetatype ids
    qputenv("QT_PLUGIN_PATH", "1");
    qputenv("LC_ALL", "C");
    QLocale::setDefault(QLocale::c());

#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
    // to avoid troubles with floats separators ('.' and not ',')
    setlocale(LC_NUMERIC, "C");
#endif

    d->parser.addHelpOption();
    d->parser.addVersionOption();

    QCommandLineOption settingsOption("settings", "settings file", "filename");
    d->parser.addOption(settingsOption);

    QCommandLineOption verboseOption("verbose", QCoreApplication::translate("main", "verbose plugin initialization"));
    d->parser.addOption(verboseOption);

    QCommandLineOption nonguiOption(QStringList() << "nw" << "no-window", QCoreApplication::translate("main", "non GUI application (no window)"));
    d->parser.addOption(nonguiOption);

    QString verbosity = "info";
    QCommandLineOption loglevelOption("loglevel", "log level used by dtkLog (default is info)", "trace|debug|info|warn|error|fatal", verbosity);
    d->parser.addOption(loglevelOption);

    QCoreApplication *q = dynamic_cast<QCoreApplication *>(this);
    QCommandLineOption logfileOption("logfile", qPrintable(QString("log file used by dtkLog; default is: ").append(dtkLogPath(q))),"filename | console",dtkLogPath(q));
    d->parser.addOption(logfileOption);

    d->parser.process(*q);

    if(d->parser.isSet(settingsOption)) {
        d->settings = new QSettings(d->parser.value(settingsOption), QSettings::IniFormat);
    } else {
        d->settings = new QSettings(q->organizationName(), q->applicationName());
    }
    if (d->settings->contains("log_level")) {
        dtkLogger::instance().setLevel(d->settings->value("log_level").toString());
    } else {
        if (d->parser.isSet(loglevelOption)) {
            verbosity= d->parser.value(loglevelOption);
        }
        dtkLogger::instance().setLevel(verbosity);
    }
    if (d->parser.isSet(logfileOption)) {
        if (d->parser.value(logfileOption) == "console") {
            dtkLogger::instance().attachConsole();
        } else {
            dtkLogger::instance().attachFile(d->parser.value(logfileOption));
        }
    } else {
        dtkLogger::instance().attachFile(dtkLogPath(q));
    }
}

{'fraction_non_alphanumeric': 0.14366679847106895, 'fraction_numerical': 0.005008567286147357, 'mean_word_length': 4.522561863173217, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 77, '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': '960799', 'n_tokens_mistral': 2380, 'n_tokens_neox': 2327, 'n_words': 402}