aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--config/CMakeLists.txt15
-rw-r--r--config/main.cpp21
-rw-r--r--config/settingsdialog.cpp37
-rw-r--r--config/settingsdialog.h31
-rw-r--r--lib/settings/settingsdialog.cpp83
-rw-r--r--lib/settings/settingsdialog.h35
-rw-r--r--lib/settings/settingsdialog.ui67
-rw-r--r--src/configuration.h19
9 files changed, 124 insertions, 186 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 74bddd2..841c64d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,8 @@ add_subdirectory(lib/downloads)
add_subdirectory(plugins/ProfileEditor)
+add_subdirectory(config)
+
# configure a header file to pass version information
# if you don't have git, or are building this off the source tarball, define versions in version.h.in
execute_process(COMMAND hg log -r '.' --template={latesttag} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE VcsVersion OUTPUT_STRIP_TRAILING_WHITESPACE)
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
new file mode 100644
index 0000000..129b2f2
--- /dev/null
+++ b/config/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.1.0)
+
+# Find includes in corresponding build directories
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(poi-config
+ main.cpp
+ settingsdialog.cpp
+ settingsdialog.h
+ ../src/configuration.h
+ ../src/configuration.cpp
+ )
+
+target_link_libraries(poi-config Qt5::Core Qt5::Widgets)
+target_link_libraries(poi-config ${Boost_LIBRARIES})
diff --git a/config/main.cpp b/config/main.cpp
new file mode 100644
index 0000000..25751e6
--- /dev/null
+++ b/config/main.cpp
@@ -0,0 +1,21 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "settingsdialog.h"
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ app.setQuitOnLastWindowClosed(true);
+
+ SettingsDialog dlg;
+ dlg.show();
+
+ return app.exec();
+} \ No newline at end of file
diff --git a/config/settingsdialog.cpp b/config/settingsdialog.cpp
new file mode 100644
index 0000000..56acc01
--- /dev/null
+++ b/config/settingsdialog.cpp
@@ -0,0 +1,37 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "settingsdialog.h"
+#include <QApplication>
+#include <QMenuBar>
+#include <QToolButton>
+#include <QVBoxLayout>
+
+SettingsDialog::SettingsDialog(QWidget *parent)
+ : QMainWindow(parent)
+{
+ resize(800, 600);
+
+ // main menu
+ settingsMenu.setTitle(tr("Settings"));
+ settingsMenu.addAction(tr("Quit"), qApp, &QApplication::quit, QKeySequence("Ctrl+Q"));
+ menuBar()->addMenu(&settingsMenu);
+
+ setCentralWidget(&treeWidget);
+ treeWidget.setColumnCount(2);
+
+ //config.read()
+
+ for(const auto &option : config.options()) {
+ auto *item = new QTreeWidgetItem(&treeWidget);
+ item->setText(0, QString::fromStdString(option->long_name()));
+ item->setText(1, QString::fromStdString(config.value<std::string>(option->long_name().c_str()).value_or(std::string())));
+ }
+}
+
+SettingsDialog::~SettingsDialog() = default;
diff --git a/config/settingsdialog.h b/config/settingsdialog.h
new file mode 100644
index 0000000..82cd1be
--- /dev/null
+++ b/config/settingsdialog.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SETTINGSDIALOG_H
+#define SETTINGSDIALOG_H
+
+#include "../src/configuration.h"
+#include <QMainWindow>
+#include <QMenu>
+#include <QTreeWidget>
+
+class SettingsDialog : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit SettingsDialog(QWidget *parent = nullptr);
+ ~SettingsDialog() override;
+
+private:
+ QMenu settingsMenu;
+ QTreeWidget treeWidget;
+ Configuration config;
+};
+
+#endif // SETTINGSDIALOG_H
diff --git a/lib/settings/settingsdialog.cpp b/lib/settings/settingsdialog.cpp
deleted file mode 100644
index bd0aa49..0000000
--- a/lib/settings/settingsdialog.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "settingsdialog.h"
-#include "../../src/configuration.h"
-#include "ui_settingsdialog.h"
-#include <QFormLayout>
-#include <QGroupBox>
-#include <QLineEdit>
-#include <QScrollArea>
-#include <QToolButton>
-
-inline QHBoxLayout *createEntry(Configuration *config, const std::string &path, QWidget *widget);
-
-SettingsDialog::SettingsDialog(std::shared_ptr<Configuration> &settings, QWidget *parent)
- : QDialog(parent)
- , ui(new Ui::SettingsDialog)
-{
- ui->setupUi(this);
-
- for(const std::string &group : settings->childrenGroups("")) {
- QScrollArea *area = new QScrollArea(this);
- area->setWidgetResizable(true);
- area->setWidget(widgetForGroup(settings, group, this));
- ui->tabWidget->addTab(area, QString::fromStdString(group));
- }
-}
-
-SettingsDialog::~SettingsDialog()
-{
- delete ui;
-}
-
-QWidget *widgetForGroup(std::shared_ptr<Configuration> &settings, const std::string &group, QWidget *parent)
-{
- QWidget *widget = new QWidget(parent);
- QVBoxLayout *layout = new QVBoxLayout();
- widget->setLayout(layout);
-
- // add entry for every key
- QFormLayout *form = new QFormLayout();
- for(const std::string &key : settings->childrenSettings(group.c_str())) {
- QHBoxLayout *hBox = createEntry(settings.get(), group + '.' + key, widget);
- form->addRow(parent->tr(key.c_str()), hBox);
- }
- layout->addLayout(form);
-
- // TODO: iterate through groups
- for(const std::string &childGroup : settings->childrenGroups(group.c_str())) {
- QGroupBox *groupBox = new QGroupBox(QString::fromStdString(childGroup), widget);
- layout->addWidget(groupBox);
- QFormLayout *boxForm = new QFormLayout(groupBox);
- groupBox->setLayout(boxForm);
-
- const std::string groupPath = group + '.' + childGroup;
- for(const std::string &key : settings->childrenSettings(groupPath.c_str())) {
- QHBoxLayout *hBox = createEntry(settings.get(), groupPath + '.' + key, groupBox);
- boxForm->addRow(parent->tr(key.c_str()), hBox);
- }
- }
-
- return widget;
-}
-
-inline QHBoxLayout *createEntry(Configuration *config, const std::string &path, QWidget *widget)
-{
- QLineEdit *lineEdit = new QLineEdit(widget);
- lineEdit->setText(QString::fromStdString(config->value<std::string>(path.c_str()).value()));
-
- QObject::connect(lineEdit, &QLineEdit::editingFinished, widget, [config, path, lineEdit]() {
- config->setValue<std::string>(path, lineEdit->text().toStdString());
- });
-
- QHBoxLayout *hBox = new QHBoxLayout();
- hBox->addWidget(lineEdit);
-
- return hBox;
-}
diff --git a/lib/settings/settingsdialog.h b/lib/settings/settingsdialog.h
deleted file mode 100644
index 3d822d4..0000000
--- a/lib/settings/settingsdialog.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#ifndef SETTINGSDIALOG_H
-#define SETTINGSDIALOG_H
-
-#include <QDialog>
-#include <memory>
-
-namespace Ui
-{
-class SettingsDialog;
-}
-
-class Configuration;
-class SettingsDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit SettingsDialog(std::shared_ptr<Configuration> &settings, QWidget *parent = nullptr);
- ~SettingsDialog();
-
-private:
- Ui::SettingsDialog *ui;
-};
-
-[[nodiscard]] QWidget *widgetForGroup(std::shared_ptr<Configuration> &settings, const std::string &group, QWidget *parent);
-
-#endif // SETTINGSDIALOG_H
diff --git a/lib/settings/settingsdialog.ui b/lib/settings/settingsdialog.ui
deleted file mode 100644
index 522754d..0000000
--- a/lib/settings/settingsdialog.ui
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>SettingsDialog</class>
- <widget class="QDialog" name="SettingsDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>640</width>
- <height>480</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Settings</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QTabWidget" name="tabWidget"/>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>SettingsDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>SettingsDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>316</x>
- <y>260</y>
- </hint>
- <hint type="destinationlabel">
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/src/configuration.h b/src/configuration.h
index c9223eb..5038a4d 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -37,7 +37,20 @@ public:
#endif
if constexpr(std::is_same_v<T, std::string>) {
- std::string r = vm[path].as<std::string>();
+ std::string r;
+ try {
+ r = vm[path].as<std::string>();
+ } catch (boost::bad_any_cast &) {
+ // try int
+ try {
+ r = std::to_string(vm[path].as<int>());
+ } catch (boost::bad_any_cast &) {
+
+ // try bool, and crash if not that either
+ r = vm[path].as<bool>() ? "true" : "false";
+ }
+
+ }
// check if it's a path
if(r.front() == '~') {
@@ -49,6 +62,10 @@ public:
return std::optional<T>(vm[path].as<T>());
}
+ const std::vector<boost::shared_ptr<boost::program_options::option_description>> & options() {
+ return desc.options();
+ }
+
private:
boost::program_options::options_description desc;
boost::program_options::variables_map vm;