Move settings lib into the main code, fixing error logging in it.

This commit is contained in:
Petr Mrázek 2014-07-01 01:48:09 +02:00
parent 8b86306d48
commit 18a342ef14
33 changed files with 80 additions and 175 deletions

View File

@ -252,11 +252,6 @@ add_definitions(-DLIBUTIL_STATIC)
add_subdirectory(depends/util)
include_directories(${LIBUTIL_INCLUDE_DIR})
# Add the settings library.
add_definitions(-DLIBSETTINGS_STATIC)
add_subdirectory(depends/settings)
include_directories(${LIBSETTINGS_INCLUDE_DIR})
# Add the updater
add_subdirectory(mmc_updater)
@ -553,6 +548,18 @@ SET(MULTIMC_SOURCES
logic/tasks/SequentialTask.h
logic/tasks/SequentialTask.cpp
# Settings
logic/settings/INIFile.cpp
logic/settings/INIFile.h
logic/settings/INISettingsObject.cpp
logic/settings/INISettingsObject.h
logic/settings/OverrideSetting.cpp
logic/settings/OverrideSetting.h
logic/settings/Setting.cpp
logic/settings/Setting.h
logic/settings/SettingsObject.cpp
logic/settings/SettingsObject.h
# Java related code
logic/java/JavaChecker.h
logic/java/JavaChecker.cpp
@ -698,7 +705,7 @@ add_executable(MultiMC MACOSX_BUNDLE WIN32 main.cpp ${MULTIMC_RCS})
# Link
target_link_libraries(MultiMC MultiMC_common)
target_link_libraries(MultiMC_common xz-embedded unpack200 quazip libUtil libSettings ${MultiMC_LINK_ADDITIONAL_LIBS})
target_link_libraries(MultiMC_common xz-embedded unpack200 quazip libUtil ${MultiMC_LINK_ADDITIONAL_LIBS})
qt5_use_modules(MultiMC Core Widgets Network Xml Concurrent ${MultiMC_QT_ADDITIONAL_MODULES})
qt5_use_modules(MultiMC_common Core Widgets Network Xml Concurrent ${MultiMC_QT_ADDITIONAL_MODULES})

View File

@ -42,10 +42,10 @@
#include "pathutils.h"
#include "cmdutils.h"
#include <inisettingsobject.h>
#include <setting.h>
#include "logic/settings/INISettingsObject.h"
#include "logic/settings/Setting.h"
#include "logger/QsLog.h"
#include <logger/QsLogDest.h>
#include "logger/QsLogDest.h"
#ifdef Q_OS_WIN32
#include <windows.h>
@ -219,7 +219,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override)
m_instances.reset(new InstanceList(InstDirSetting->get().toString(), this));
QLOG_INFO() << "Loading Instances...";
m_instances->loadList();
connect(InstDirSetting.get(), SIGNAL(settingChanged(const Setting &, QVariant)),
connect(InstDirSetting.get(), SIGNAL(SettingChanged(const Setting &, QVariant)),
m_instances.get(), SLOT(on_InstFolderChanged(const Setting &, QVariant)));
// and accounts

View File

@ -1,41 +0,0 @@
project(libSettings)
# Find Qt
find_package(Qt5Core REQUIRED)
# Include Qt headers.
include_directories(${Qt5Base_INCLUDE_DIRS})
include(UseCXX11)
include(Coverage)
set(LIBSETTINGS_SOURCES
libsettings_config.h
inifile.h
inifile.cpp
settingsobject.h
settingsobject.cpp
inisettingsobject.h
inisettingsobject.cpp
setting.h
setting.cpp
overridesetting.h
overridesetting.cpp
)
# Set the include dir path.
set(LIBSETTINGS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE)
# Static link!
add_definitions(-DLIBSETTINGS_STATIC)
add_definitions(-DLIBSETTINGS_LIBRARY)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_library(libSettings STATIC ${LIBSETTINGS_SOURCES})
qt5_use_modules(libSettings Core)
target_link_libraries(libSettings)

View File

@ -1,29 +0,0 @@
/* Copyright 2013 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QtCore/QtGlobal>
#ifdef LIBSETTINGS_STATIC
#define LIBSETTINGS_EXPORT
#else
#ifdef LIBSETTINGS_LIBRARY
#define LIBSETTINGS_EXPORT Q_DECL_EXPORT
#else
#define LIBSETTINGS_EXPORT Q_DECL_IMPORT
#endif
#endif

View File

@ -32,7 +32,7 @@
#include "logic/tools/BaseProfiler.h"
#include <settingsobject.h>
#include "logic/settings/SettingsObject.h"
#include <pathutils.h>
#include <QFileDialog>
#include <QMessageBox>

View File

@ -16,7 +16,7 @@
#include "PageDialog.h"
#include "gui/Platform.h"
#include "MultiMC.h"
#include <settingsobject.h>
#include "logic/settings/SettingsObject.h"
#include <gui/widgets/IconLabel.h>
#include <gui/widgets/PageContainer.h>

View File

@ -27,7 +27,7 @@
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QDesktopServices>
#include <settingsobject.h>
#include "logic/settings/SettingsObject.h"
#include "PageContainer_p.h"
#include <gui/widgets/IconLabel.h>

View File

@ -21,9 +21,9 @@
#include <QDir>
#include "MultiMC.h"
#include "inisettingsobject.h"
#include "setting.h"
#include "overridesetting.h"
#include "logic/settings/INISettingsObject.h"
#include "logic/settings/Setting.h"
#include "logic/settings/OverrideSetting.h"
#include "pathutils.h"
#include <cmdutils.h>

View File

@ -19,9 +19,9 @@
#include <QDateTime>
#include <QSet>
#include <settingsobject.h>
#include "logic/settings/SettingsObject.h"
#include "inifile.h"
#include "logic/settings/INIFile.h"
#include "logic/BaseVersionList.h"
#include "logic/auth/MojangAccount.h"

View File

@ -18,7 +18,7 @@
#include <QString>
#include <QSet>
#include <settingsobject.h>
#include "logic/settings/SettingsObject.h"
#include "BaseInstance.h"

View File

@ -15,9 +15,10 @@
#include <QDir>
#include <QFileInfo>
#include <inifile.h>
#include <inisettingsobject.h>
#include <setting.h>
#include "logic/settings/INIFile.h"
#include "logic/settings/INISettingsObject.h"
#include "logic/settings/Setting.h"
#include <pathutils.h>
#include "logger/QsLog.h"

View File

@ -16,7 +16,7 @@
#include <QFileInfo>
#include <QDir>
#include <QImage>
#include <setting.h>
#include <logic/settings/Setting.h>
#include <pathutils.h>
#include <cmdutils.h>

View File

@ -15,7 +15,7 @@
#pragma once
#include <QString>
#include <settingsobject.h>
#include "logic/settings/SettingsObject.h"
#include <memory>
#include "BaseInstance_p.h"

View File

@ -24,7 +24,7 @@
#include "Mod.h"
#include <pathutils.h>
#include <inifile.h>
#include "logic/settings/INIFile.h"
#include "logger/QsLog.h"
Mod::Mod(const QFileInfo &file)

View File

@ -15,14 +15,14 @@
#include "IconList.h"
#include <pathutils.h>
#include <settingsobject.h>
#include "logic/settings/SettingsObject.h"
#include <QMap>
#include <QEventLoop>
#include <QMimeData>
#include <QUrl>
#include <QFileSystemWatcher>
#include <MultiMC.h>
#include <setting.h>
#include <logic/settings/Setting.h>
#define MAX_SIZE 1024
@ -45,8 +45,8 @@ IconList::IconList(QObject *parent) : QAbstractListModel(parent)
auto setting = MMC->settings()->getSetting("IconsDir");
QString path = setting->get().toString();
connect(setting.get(), SIGNAL(settingChanged(const Setting &, QVariant)),
SLOT(settingChanged(const Setting &, QVariant)));
connect(setting.get(), SIGNAL(SettingChanged(const Setting &, QVariant)),
SLOT(SettingChanged(const Setting &, QVariant)));
directoryChanged(path);
}
@ -143,7 +143,7 @@ void IconList::fileChanged(const QString &path)
emit iconUpdated(key);
}
void IconList::settingChanged(const Setting &setting, QVariant value)
void IconList::SettingChanged(const Setting &setting, QVariant value)
{
if(setting.id() != "IconsDir")
return;

View File

@ -22,7 +22,7 @@
#include <QtGui/QIcon>
#include <memory>
#include "MMCIcon.h"
#include "setting.h"
#include "logic/settings/Setting.h"
class QFileSystemWatcher;
@ -68,7 +68,7 @@ protected
slots:
void directoryChanged(const QString &path);
void fileChanged(const QString &path);
void settingChanged(const Setting & setting, QVariant value);
void SettingChanged(const Setting & setting, QVariant value);
private:
std::shared_ptr<QFileSystemWatcher> m_watcher;
bool is_watching;

View File

@ -18,7 +18,7 @@
#include <QDir>
#include <QStringList>
#include <setting.h>
#include <logic/settings/Setting.h>
#include <pathutils.h>
#include "MultiMC.h"

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "inifile.h"
#include "logic/settings/INIFile.h"
#include <QFile>
#include <QTextStream>

View File

@ -19,10 +19,8 @@
#include <QVariant>
#include <QIODevice>
#include "libsettings_config.h"
// Sectionless INI parser (for instance config files)
class LIBSETTINGS_EXPORT INIFile : public QMap<QString, QVariant>
class INIFile : public QMap<QString, QVariant>
{
public:
explicit INIFile();

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#include "inisettingsobject.h"
#include "setting.h"
#include "INISettingsObject.h"
#include "Setting.h"
INISettingsObject::INISettingsObject(const QString &path, QObject *parent)
: SettingsObject(parent)

View File

@ -17,16 +17,14 @@
#include <QObject>
#include "inifile.h"
#include "logic/settings/INIFile.h"
#include "settingsobject.h"
#include "libsettings_config.h"
#include "logic/settings/SettingsObject.h"
/*!
* \brief A settings object that stores its settings in an INIFile.
*/
class LIBSETTINGS_EXPORT INISettingsObject : public SettingsObject
class INISettingsObject : public SettingsObject
{
Q_OBJECT
public:

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "overridesetting.h"
#include "OverrideSetting.h"
OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other)
: Setting(other->configKeys(), QVariant())

View File

@ -18,9 +18,7 @@
#include <QObject>
#include <memory>
#include "setting.h"
#include "libsettings_config.h"
#include "Setting.h"
/*!
* \brief A setting that 'overrides another.'
@ -28,7 +26,7 @@
* The other setting can be (and usually is) a part of a different SettingsObject
* than this one.
*/
class LIBSETTINGS_EXPORT OverrideSetting : public Setting
class OverrideSetting : public Setting
{
Q_OBJECT
public:

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#include "setting.h"
#include "settingsobject.h"
#include "Setting.h"
#include "logic/settings/SettingsObject.h"
Setting::Setting(QStringList synonyms, QVariant defVal)
: QObject(), m_synonyms(synonyms), m_defVal(defVal)
@ -44,7 +44,7 @@ QVariant Setting::defValue() const
void Setting::set(QVariant value)
{
emit settingChanged(*this, value);
emit SettingChanged(*this, value);
}
void Setting::reset()

View File

@ -20,14 +20,12 @@
#include <QStringList>
#include <memory>
#include "libsettings_config.h"
class SettingsObject;
/*!
*
*/
class LIBSETTINGS_EXPORT Setting : public QObject
class Setting : public QObject
{
Q_OBJECT
public:
@ -86,7 +84,7 @@ signals:
* \param setting A reference to the Setting that changed.
* \param value This Setting object's new value.
*/
void settingChanged(const Setting &setting, QVariant value);
void SettingChanged(const Setting &setting, QVariant value);
/*!
* \brief Signal emitted when this Setting object's value resets to default.
@ -98,7 +96,7 @@ public
slots:
/*!
* \brief Changes the setting's value.
* This is done by emitting the settingChanged() signal which will then be
* This is done by emitting the SettingChanged() signal which will then be
* handled by the SettingsObject object and cause the setting to change.
* \param value The new value.
*/

View File

@ -13,9 +13,10 @@
* limitations under the License.
*/
#include "settingsobject.h"
#include "setting.h"
#include "overridesetting.h"
#include "logic/settings/SettingsObject.h"
#include "logic/settings/Setting.h"
#include "logic/settings/OverrideSetting.h"
#include "logger/QsLog.h"
#include <QVariant>
@ -32,9 +33,8 @@ std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Settin
{
if (contains(original->id()))
{
qDebug(QString("Failed to register setting %1. ID already exists.")
.arg(original->id())
.toUtf8());
QLOG_ERROR() << QString("Failed to register setting %1. ID already exists.")
.arg(original->id());
return nullptr; // Fail
}
auto override = std::make_shared<OverrideSetting>(original);
@ -50,9 +50,8 @@ std::shared_ptr<Setting> SettingsObject::registerSetting(QStringList synonyms, Q
return nullptr;
if (contains(synonyms.first()))
{
qDebug(QString("Failed to register setting %1. ID already exists.")
.arg(synonyms.first())
.toUtf8());
QLOG_ERROR() << QString("Failed to register setting %1. ID already exists.")
.arg(synonyms.first());
return nullptr; // Fail
}
auto setting = std::make_shared<Setting>(synonyms, defVal);
@ -62,28 +61,6 @@ std::shared_ptr<Setting> SettingsObject::registerSetting(QStringList synonyms, Q
return setting;
}
/*
bool SettingsObject::registerSetting(Setting *setting)
{
if (contains(setting->id()))
{
qDebug(QString("Failed to register setting %1. ID already exists.")
.arg(setting->id())
.toUtf8());
return false; // Fail
}
m_settings.insert(setting->id(), setting);
setting->setParent(this); // Take ownership.
// Connect signals.
connectSignals(*setting);
// qDebug(QString("Registered setting %1.").arg(setting->id()).toUtf8());
return true;
}
*/
std::shared_ptr<Setting> SettingsObject::getSetting(const QString &id) const
{
// Make sure there is a setting with the given ID.
@ -104,7 +81,7 @@ bool SettingsObject::set(const QString &id, QVariant value)
auto setting = getSetting(id);
if (!setting)
{
qDebug(QString("Error changing setting %1. Setting doesn't exist.").arg(id).toUtf8());
QLOG_ERROR() << QString("Error changing setting %1. Setting doesn't exist.").arg(id);
return false;
}
else
@ -137,10 +114,10 @@ bool SettingsObject::reload()
void SettingsObject::connectSignals(const Setting &setting)
{
connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)),
connect(&setting, SIGNAL(SettingChanged(const Setting &, QVariant)),
SLOT(changeSetting(const Setting &, QVariant)));
connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)),
SIGNAL(settingChanged(const Setting &, QVariant)));
connect(&setting, SIGNAL(SettingChanged(const Setting &, QVariant)),
SIGNAL(SettingChanged(const Setting &, QVariant)));
connect(&setting, SIGNAL(settingReset(Setting)), SLOT(resetSetting(const Setting &)));
connect(&setting, SIGNAL(settingReset(Setting)), SIGNAL(settingReset(const Setting &)));

View File

@ -21,8 +21,6 @@
#include <QVariant>
#include <memory>
#include "libsettings_config.h"
class Setting;
/*!
@ -37,7 +35,7 @@ class Setting;
*
* \sa Setting
*/
class LIBSETTINGS_EXPORT SettingsObject : public QObject
class SettingsObject : public QObject
{
Q_OBJECT
public:
@ -123,11 +121,11 @@ signals:
/*!
* \brief Signal emitted when one of this SettingsObject object's settings changes.
* This is usually just connected directly to each Setting object's
* settingChanged() signals.
* SettingChanged() signals.
* \param setting A reference to the Setting object that changed.
* \param value The Setting object's new value.
*/
void settingChanged(const Setting &setting, QVariant value);
void SettingChanged(const Setting &setting, QVariant value);
/*!
* \brief Signal emitted when one of this SettingsObject object's settings resets.
@ -142,7 +140,7 @@ slots:
/*!
* \brief Changes a setting.
* This slot is usually connected to each Setting object's
* settingChanged() signal. The signal is emitted, causing this slot
* SettingChanged() signal. The signal is emitted, causing this slot
* to update the setting's value in the config file.
* \param setting A reference to the Setting object that changed.
* \param value The setting's new value.

View File

@ -3,7 +3,7 @@
#include <QDir>
#include <QMessageBox>
#include "settingsobject.h"
#include "logic/settings/SettingsObject.h"
#include "logic/MinecraftProcess.h"
#include "logic/BaseInstance.h"
#include "MultiMC.h"

View File

@ -3,7 +3,7 @@
#include <QDir>
#include <QStandardPaths>
#include "settingsobject.h"
#include "logic/settings/SettingsObject.h"
#include "logic/MinecraftProcess.h"
#include "logic/BaseInstance.h"
#include "MultiMC.h"

View File

@ -5,7 +5,7 @@
#include <QDesktopServices>
#include <QUrl>
#include "settingsobject.h"
#include "logic/settings/SettingsObject.h"
#include "logic/BaseInstance.h"
#include "MultiMC.h"

View File

@ -24,7 +24,7 @@
#include <QJsonArray>
#include <QJsonValue>
#include <settingsobject.h>
#include "logic/settings/SettingsObject.h"
#define API_VERSION 0
#define CHANLIST_FORMAT 0

View File

@ -1,8 +1,8 @@
#include <QTest>
#include <QSignalSpy>
#include "depends/settings/settingsobject.h"
#include "depends/settings/setting.h"
#include "logic/settings/SettingsObject.h"
#include "logic/settings/Setting.h"
#include "BuildConfig.h"
#include "TestUtil.h"

View File

@ -1,7 +1,7 @@
#include <QTest>
#include "TestUtil.h"
#include "depends/settings/inifile.h"
#include "logic/settings/INIFile.h"
class IniFileTest : public QObject
{