<commit_before>/*
* Copyright (C) 2008-2013 The Communi Project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*/

#include "themeinfo.h"
#include <QStringList>
#include <QSettings>
#include <QFile>

QString ThemeInfo::name() const
{
    return d.attributes.value("name");
}

QString ThemeInfo::attribute(const QString& key) const
{
    return d.attributes.value(key);
}

static QString readFile(const QString& filePath)
{
    QFile file(filePath);
    if (file.open(QFile::ReadOnly | QIODevice::Text))
        return QString::fromUtf8(file.readAll());
    return QString();
}

bool ThemeInfo::load(const QString& filePath)
{
    QSettings settings(filePath, QSettings::IniFormat);

    QStringList groups = settings.childGroups();
    if (groups.contains("Theme")) {
        settings.beginGroup("Theme");
        foreach (const QString& key, settings.childKeys())
            d.attributes.insert(key, settings.value(key).toString());
        d.attributes.insert("document", readFile(settings.value("document").toString()));
        d.attributes.insert("application", readFile(settings.value("application").toString()));
        settings.endGroup();
    }
    return !d.attributes.value("name").isEmpty();
}
<commit_msg>ThemeInfo: read files in relation to the .theme file's dir<commit_after>/*
* Copyright (C) 2008-2013 The Communi Project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*/

#include "themeinfo.h"
#include <QStringList>
#include <QSettings>
#include <QFileInfo>
#include <QFile>
#include <QDir>

QString ThemeInfo::name() const
{
    return d.attributes.value("name");
}

QString ThemeInfo::attribute(const QString& key) const
{
    return d.attributes.value(key);
}

static QString readFile(const QDir& dir, const QString& fileName)
{
    QFile file;
    if (QFileInfo(fileName).isRelative())
        file.setFileName(dir.filePath(fileName));
    else
        file.setFileName(fileName);
    if (file.open(QFile::ReadOnly | QIODevice::Text))
        return QString::fromUtf8(file.readAll());
    return QString();
}

bool ThemeInfo::load(const QString& filePath)
{
    QSettings settings(filePath, QSettings::IniFormat);

    QStringList groups = settings.childGroups();
    if (groups.contains("Theme")) {
        settings.beginGroup("Theme");
        foreach (const QString& key, settings.childKeys())
            d.attributes.insert(key, settings.value(key).toString());
        d.attributes.insert("document", readFile(QFileInfo(filePath).dir(), settings.value("document").toString()));
        d.attributes.insert("application", readFile(QFileInfo(filePath).dir(), settings.value("application").toString()));
        settings.endGroup();
    }
    return !d.attributes.value("name").isEmpty();
}

{'fraction_non_alphanumeric': 0.12257885998893193, 'fraction_numerical': 0.005534034311012728, 'mean_word_length': 4.3240058910162, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5410063', 'n_tokens_mistral': 1015, 'n_tokens_neox': 1003, 'n_words': 317}