Remove configuration from libappleii and delegate it to the frontends.

In qapple we use QSettings.


Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2017-10-10 14:26:40 +01:00
parent 03de883889
commit 3733da1af7
16 changed files with 169 additions and 30 deletions

2
.gitignore vendored
View file

@ -195,8 +195,6 @@ compile_commands.json
CTestTestfile.cmake
*.so
*.a
applen
qapple
# Qt
# C++ objects and libs

View file

@ -17,7 +17,6 @@ add_library(appleii SHARED
ParallelPrinter.cpp
MouseInterface.cpp
linux/configuration.cpp
linux/data.cpp
linux/dummies.cpp
linux/wwrapper.cpp

View file

@ -8,6 +8,7 @@ add_executable(applen
nframe.cpp
asciiart.cpp
resources.cpp
configuration.cpp
)
target_link_libraries(applen

View file

@ -1,4 +1,4 @@
#include "linux/configuration.h"
#include "frontends/ncurses/configuration.h"
#include "linux/wincompat.h"
#include "Log.h"

View file

@ -1,11 +1,14 @@
#pragma once
#include "linux/interface.h"
#include "linux/wincompat.h"
#include <boost/property_tree/ptree.hpp>
void InitializeRegistry(const std::string & filename);
const boost::property_tree::ptree & getProperties();
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars);
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD *value);
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, BOOL *value);
void RegSaveString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPCTSTR buffer);
void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value);

View file

@ -19,9 +19,9 @@
#include "Video.h"
#include "SaveState.h"
#include "linux/configuration.h"
#include "linux/data.h"
#include "linux/benchmark.h"
#include "frontends/ncurses/configuration.h"
#include "frontends/ncurses/world.h"
namespace

View file

@ -18,6 +18,7 @@ add_executable(qapple
graphicscache.cpp
gamepadpaddle.cpp
video.cpp
settings.cpp
commands.cpp
chunks.cpp

View file

@ -4,6 +4,10 @@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setOrganizationName("AndSoft");
QApplication::setApplicationName("QAppleEmulator");
QApple w;
w.show();

View file

@ -73,22 +73,38 @@ namespace
}
}
void processPropertyTree(const boost::property_tree::ptree & registry, QTreeWidgetItem * item)
void processSettingsGroup(QSettings & settings, QTreeWidgetItem * item)
{
QList<QTreeWidgetItem *> items;
for (const auto & it : registry)
{
const boost::property_tree::ptree::data_type & key = it.first;
const boost::property_tree::ptree & subTree = it.second;
// first the leaves
const QStringList children = settings.childKeys();
for (const auto & child : children)
{
QStringList columns;
columns.append(QString::fromStdString(key));
columns.append(QString::fromStdString(subTree.data()));
columns.append(child); // the name
columns.append(settings.value(child).toString()); // the value
QTreeWidgetItem * newItem = new QTreeWidgetItem(item, columns);
processPropertyTree(subTree, newItem);
items.append(newItem);
}
// then the subtrees
const QStringList groups = settings.childGroups();
for (const auto & group : groups)
{
settings.beginGroup(group);
QStringList columns;
columns.append(group); // the name
QTreeWidgetItem * newItem = new QTreeWidgetItem(item, columns);
processSettingsGroup(settings, newItem); // process subtree
items.append(newItem);
settings.endGroup();
}
item->addChildren(items);
}
@ -106,11 +122,11 @@ Preferences::Preferences(QWidget *parent) :
myHDs.push_back(hd2);
}
void Preferences::setup(const Data & data, const boost::property_tree::ptree & registry)
void Preferences::setup(const Data & data, QSettings & settings)
{
populateJoysticks();
setData(data);
setRegistry(registry);
setSettings(settings);
}
void Preferences::populateJoysticks()
@ -132,11 +148,17 @@ void Preferences::populateJoysticks()
}
}
void Preferences::setRegistry(const boost::property_tree::ptree & registry)
void Preferences::setSettings(QSettings & settings)
{
registryTree->clear();
QTreeWidgetItem * newItem = new QTreeWidgetItem(registryTree, QStringList(QString("Registry")));
processPropertyTree(registry, newItem);
QStringList columns;
columns.append(QString::fromUtf8("Registry")); // the name
columns.append(settings.fileName()); // the value
QTreeWidgetItem * newItem = new QTreeWidgetItem(registryTree, columns);
processSettingsGroup(settings, newItem);
registryTree->addTopLevelItem(newItem);
registryTree->expandAll();
}

View file

@ -4,7 +4,7 @@
#include "ui_preferences.h"
#include <vector>
#include <boost/property_tree/ptree.hpp>
#include <QSettings>
class Preferences : public QDialog, private Ui::Preferences
{
@ -28,7 +28,7 @@ public:
explicit Preferences(QWidget *parent);
void setup(const Data & data, const boost::property_tree::ptree & registry);
void setup(const Data & data, QSettings & settings);
Data getData() const;
private slots:
@ -48,7 +48,7 @@ private:
std::vector<QComboBox *> myDisks;
std::vector<QComboBox *> myHDs;
void setRegistry(const boost::property_tree::ptree & registry);
void setSettings(QSettings & settings);
void setData(const Data & data);
void populateJoysticks();
void browseDisk(const std::vector<QComboBox *> & disks, const size_t id);

View file

@ -15,13 +15,13 @@
#include "Registry.h"
#include "linux/data.h"
#include "linux/configuration.h"
#include "linux/benchmark.h"
#include "linux/paddle.h"
#include "emulator.h"
#include "memorycontainer.h"
#include "gamepadpaddle.h"
#include "settings.h"
#include <QMdiSubWindow>
#include <QMessageBox>
@ -34,8 +34,6 @@ namespace
g_fh = fopen("/tmp/applewin.txt", "w");
setbuf(g_fh, NULL);
InitializeRegistry("../qapple/applen.conf");
LogFileOutput("Initialisation\n");
ImageInitialize();
@ -320,7 +318,8 @@ void QApple::on_actionOptions_triggered()
currentOptions.joystickId = myGamepad->deviceId();
}
myPreferences.setup(currentOptions, getProperties());
QSettings settings; // the function will "modify" it
myPreferences.setup(currentOptions, settings);
if (myPreferences.exec())
{

View file

@ -5,6 +5,7 @@
#include <QElapsedTimer>
#include <QGamepad>
#include <memory>
#include "preferences.h"
class Emulator;

View file

@ -23,7 +23,8 @@ SOURCES += main.cpp\
qhexedit.cpp \
memorycontainer.cpp \
preferences.cpp \
gamepadpaddle.cpp
gamepadpaddle.cpp \
settings.cpp
HEADERS += qapple.h \
emulator.h \
@ -34,7 +35,8 @@ HEADERS += qapple.h \
qhexedit.h \
memorycontainer.h \
preferences.h \
gamepadpaddle.h
gamepadpaddle.h \
settings.h
FORMS += qapple.ui \
emulator.ui \
@ -44,12 +46,12 @@ FORMS += qapple.ui \
RESOURCES += \
qapple.qrc
unix: LIBS += -L$$PWD/../../../ -lappleii
unix: LIBS += -L$$PWD/../../ -lappleii
INCLUDEPATH += $$PWD/../../../source
DEPENDPATH += $$PWD/../../../source
unix: LIBS += -levdev
unix:QMAKE_RPATHDIR += $ORIGIN/../../..
unix:QMAKE_RPATHDIR += $ORIGIN/../..

View file

@ -0,0 +1,89 @@
#include "settings.h"
#include <QSettings>
namespace
{
QString getKey(LPCTSTR section, LPCTSTR key)
{
const QString qkey = QString::fromUtf8(section) + "/" + QString::fromUtf8(key);
return qkey;
}
QSettings & getOurSettings()
{
static QSettings settings;
return settings;
}
}
void RegSaveString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPCTSTR buffer)
{
Q_UNUSED(peruser)
const QString s = QString::fromUtf8(buffer);
getOurSettings().setValue(getKey(section, key), QVariant::fromValue(s));
}
void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value)
{
Q_UNUSED(peruser)
getOurSettings().setValue(getKey(section, key), QVariant::fromValue(value));
}
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars)
{
Q_UNUSED(peruser)
QSettings & settings = getOurSettings();
const QString qkey = getKey(section, key);
if (settings.contains(qkey))
{
const QVariant value = settings.value(qkey);
const std::string s = value.toString().toStdString();
strncpy(buffer, s.c_str(), chars);
buffer[chars - 1] = 0;
return TRUE;
}
else
{
return FALSE;
}
}
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD *value)
{
Q_UNUSED(peruser)
QSettings & settings = getOurSettings();
const QString qkey = getKey(section, key);
if (settings.contains(qkey))
{
const QVariant v = settings.value(qkey);
*value = v.toUInt();
return TRUE;
}
else
{
return FALSE;
}
}
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, BOOL *value)
{
Q_UNUSED(peruser)
QSettings & settings = getOurSettings();
const QString qkey = getKey(section, key);
if (settings.contains(qkey))
{
const QVariant v = settings.value(qkey);
*value = v.toBool();
return TRUE;
}
else
{
return FALSE;
}
}

View file

@ -0,0 +1,12 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#include "linux/wincompat.h"
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars);
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD *value);
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, BOOL *value);
void RegSaveString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPCTSTR buffer);
void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value);
#endif // SETTINGS_H

View file

@ -28,3 +28,11 @@ BYTE __stdcall JoyResetPosition(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG n
// Speaker
BYTE __stdcall SpkrToggle (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);
// Registry
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars);
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD *value);
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, BOOL *value);
void RegSaveString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPCTSTR buffer);
void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value);