Massive re-organization.

This commit is contained in:
Andrew
2013-02-26 16:47:39 -06:00
parent bd64cda672
commit 36396f7c6a
53 changed files with 223 additions and 185 deletions

View File

@ -1,4 +1,4 @@
project(libmmcsettings)
project(libSettings)
# Find Qt
find_package(Qt5Core REQUIRED)
@ -7,12 +7,11 @@ find_package(Qt5Core REQUIRED)
include_directories(${Qt5Base_INCLUDE_DIRS})
include_directories(${Qt5Network_INCLUDE_DIRS})
# Include utils library headers.
include_directories(${CMAKE_SOURCE_DIR}/libutil/include)
SET(LIBSETTINGS_HEADERS
include/libsettings_config.h
include/inifile.h
include/settingsobject.h
include/setting.h
include/overridesetting.h
@ -22,6 +21,8 @@ include/inisettingsobject.h
)
SET(LIBSETTINGS_SOURCES
src/inifile.cpp
src/settingsobject.cpp
src/setting.cpp
src/overridesetting.cpp
@ -31,10 +32,11 @@ src/inisettingsobject.cpp
)
# Set the include dir path.
SET(LIBMMCSETTINGS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
SET(LIBSETTINGS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
include_directories(${LIBSETTINGS_INCLUDE_DIR})
add_definitions(-DLIBMMCSETTINGS_LIBRARY)
add_definitions(-DLIBSETTINGS_LIBRARY)
add_library(libmmcsettings SHARED ${LIBSETTINGS_SOURCES} ${LIBSETTINGS_HEADERS})
qt5_use_modules(libmmcsettings Core)
target_link_libraries(libmmcsettings libmmcutil)
add_library(libSettings SHARED ${LIBSETTINGS_SOURCES} ${LIBSETTINGS_HEADERS})
qt5_use_modules(libSettings Core)
target_link_libraries(libSettings)

View File

@ -26,7 +26,7 @@
/*!
* \brief A settings object that stores its settings in a QSettings object.
*/
class LIBMMCSETTINGS_EXPORT BasicSettingsObject : public SettingsObject
class LIBSETTINGS_EXPORT BasicSettingsObject : public SettingsObject
{
Q_OBJECT
public:

View File

@ -0,0 +1,38 @@
/* 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.
*/
#ifndef INIFILE_H
#define INIFILE_H
#include <QMap>
#include <QString>
#include <QVariant>
#include "libsettings_config.h"
// Sectionless INI parser (for instance config files)
class LIBSETTINGS_EXPORT INIFile : public QMap<QString, QVariant>
{
public:
explicit INIFile();
bool loadFile(QString fileName);
bool saveFile(QString fileName);
QVariant get(QString key, QVariant def) const;
void set(QString key, QVariant val);
};
#endif // INIFILE_H

View File

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

View File

@ -18,10 +18,10 @@
#include <QtCore/QtGlobal>
#ifdef LIBMMCSETTINGS_LIBRARY
# define LIBMMCSETTINGS_EXPORT Q_DECL_EXPORT
#ifdef LIBSETTINGS_LIBRARY
# define LIBSETTINGS_EXPORT Q_DECL_EXPORT
#else
# define LIBMMCSETTINGS_EXPORT Q_DECL_IMPORT
# define LIBSETTINGS_EXPORT Q_DECL_IMPORT
#endif
#endif // LIBINSTANCE_CONFIG_H

View File

@ -28,7 +28,7 @@
* The other setting can be (and usually is) a part of a different SettingsObject
* than this one.
*/
class LIBMMCSETTINGS_EXPORT OverrideSetting : public Setting
class LIBSETTINGS_EXPORT OverrideSetting : public Setting
{
Q_OBJECT
public:

View File

@ -26,7 +26,7 @@ class SettingsObject;
/*!
*
*/
class LIBMMCSETTINGS_EXPORT Setting : public QObject
class LIBSETTINGS_EXPORT Setting : public QObject
{
Q_OBJECT
public:

View File

@ -34,7 +34,7 @@ class Setting;
*
* \sa Setting
*/
class LIBMMCSETTINGS_EXPORT SettingsObject : public QObject
class LIBSETTINGS_EXPORT SettingsObject : public QObject
{
Q_OBJECT
public:
@ -165,6 +165,6 @@ private:
/*!
* \brief A global settings object.
*/
LIBMMCSETTINGS_EXPORT extern SettingsObject *globalSettings;
LIBSETTINGS_EXPORT extern SettingsObject *globalSettings;
#endif // SETTINGSOBJECT_H

View File

@ -0,0 +1,86 @@
/* 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.
*/
#include "include/inifile.h"
#include <QFile>
#include <QTextStream>
#include <QStringList>
INIFile::INIFile()
{
}
bool INIFile::saveFile(QString fileName)
{
// TODO Handle errors.
QFile file(fileName);
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
for (Iterator iter = begin(); iter != end(); iter++)
{
out << iter.key() << "=" << iter.value().toString() << "\n";
}
return true;
}
bool INIFile::loadFile(QString fileName)
{
// TODO Handle errors.
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QTextStream in(&file);
QStringList lines = in.readAll().split('\n');
for (int i = 0; i < lines.count(); i++)
{
QString & lineRaw = lines[i];
// Ignore comments.
QString line = lineRaw.left(lineRaw.indexOf('#')).trimmed();
int eqPos = line.indexOf('=');
if(eqPos == -1)
continue;
QString key = line.left(eqPos).trimmed();
QString valueStr = line.right(line.length() - eqPos - 1).trimmed();
QVariant value(valueStr);
/*
QString dbg = key;
dbg += " = ";
dbg += valueStr;
qDebug(dbg.toLocal8Bit());
*/
this->operator [](key) = value;
}
return true;
}
QVariant INIFile::get(QString key, QVariant def) const
{
if (!this->contains(key))
return def;
else
return this->operator [](key);
}
void INIFile::set(QString key, QVariant val)
{
this->operator [](key) = val;
}