<commit_before>// SPDX-License-Identifier: GPL-2.0
/*
  Copyright (C) 2008-2021 The Communi Project
*/

#include "settingsproxy.h"

#include <QStringList>
#include <QCoreApplication>
#include <QFileInfo>
#include <QDir>
#include <QStandardPaths>


SettingsProxy::SettingsProxy(BufferProxyModel *bufferModel,
                   IgnoreManager* ignore, QObject* parent)
{

    this->migrateSettings();

    m_settings = new QSettings(QCoreApplication::applicationName(),
                               QCoreApplication::applicationName(), parent);

    m_ignoreManager = ignore;
    m_bufferModel = bufferModel;
    this->restoreSettings();
}

void SettingsProxy::migrateSettings()
{
    QString oldConfigFileStr =
        QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() +
        "/" + "harbour-communi/IRC for Sailfish.conf";
    QString newConfigFileStr =
        QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() +
        "/" + QCoreApplication::applicationName() +
        "/" + QCoreApplication::applicationName() + ".conf";

    if((!QFileInfo(newConfigFileStr).exists() && !QDir(newConfigFileStr).exists()) &&
        (QFileInfo(oldConfigFileStr).exists() && !QDir(oldConfigFileStr).exists())) {
        QFile::rename(oldConfigFileStr, newConfigFileStr);
    }
}

void SettingsProxy::restoreSettings()
{
    m_bufferModel->restoreState(m_settings->value("state", QByteArray()).toByteArray());
    m_ignoreManager->setIgnores(m_settings->value("ignores").toStringList());
}

void SettingsProxy::saveSettings()
{
    m_settings->setValue("state", m_bufferModel->saveState());
    m_settings->setValue("ignores",  m_ignoreManager->ignores());
    m_settings->sync();
}

SettingsProxy::~SettingsProxy()
{
    delete m_settings;
}<commit_msg>[app] Use AppConfigLocation for settings path. Contributes to #168<commit_after>// SPDX-License-Identifier: GPL-2.0
/*
  Copyright (C) 2008-2021 The Communi Project
*/

#include "settingsproxy.h"

#include <QStringList>
#include <QCoreApplication>
#include <QFileInfo>
#include <QDir>
#include <QStandardPaths>


SettingsProxy::SettingsProxy(BufferProxyModel *bufferModel,
                   IgnoreManager* ignore, QObject* parent)
{

    this->migrateSettings();

    m_settings = new QSettings(
        QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation).first() +
        "/" + QCoreApplication::applicationName() + ".conf",
        QSettings::IniFormat,
        parent);

    m_ignoreManager = ignore;
    m_bufferModel = bufferModel;
    this->restoreSettings();
}

void SettingsProxy::migrateSettings()
{
    QString oldConfigFileStr =
        QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() +
        "/" + "harbour-communi/IRC for Sailfish.conf";
    QString newConfigFileStr =
        QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation).first() +
        "/" + QCoreApplication::applicationName() + ".conf";

    if((!QFileInfo(newConfigFileStr).exists() && !QDir(newConfigFileStr).exists()) &&
        (QFileInfo(oldConfigFileStr).exists() && !QDir(oldConfigFileStr).exists())) {
        QFile::rename(oldConfigFileStr, newConfigFileStr);
    }
}

void SettingsProxy::restoreSettings()
{
    m_bufferModel->restoreState(m_settings->value("state", QByteArray()).toByteArray());
    m_ignoreManager->setIgnores(m_settings->value("ignores").toStringList());
}

void SettingsProxy::saveSettings()
{
    m_settings->setValue("state", m_bufferModel->saveState());
    m_settings->setValue("ignores",  m_ignoreManager->ignores());
    m_settings->sync();
}

SettingsProxy::~SettingsProxy()
{
    delete m_settings;
}
{'fraction_non_alphanumeric': 0.14351851851851852, 'fraction_numerical': 0.006263616557734205, 'mean_word_length': 4.650769230769231, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, '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': '7117939', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1086, 'n_words': 156}