aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/CMakeLists.txt26
-rw-r--r--config/main.cpp29
-rw-r--r--config/settingsdialog.cpp98
-rw-r--r--config/settingsdialog.h37
4 files changed, 0 insertions, 190 deletions
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
deleted file mode 100644
index 7ee13b0..0000000
--- a/config/CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-# Find includes in corresponding build directories
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-# Instruct CMake to run moc automatically when needed.
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTOUIC ON)
-set(CMAKE_AUTORCC ON)
-
-add_executable(poi-config
- main.cpp
- settingsdialog.cpp
- settingsdialog.h
-)
-
-target_include_directories(poi-config
- PRIVATE ../lib/configuration
- PRIVATE ${Boost_INCLUDE_DIRS}
-)
-
-target_link_libraries(poi-config
- Qt5::Core Qt5::Widgets
- ${Boost_LIBRARIES}
- configuration
-)
-
-install(TARGETS poi-config RUNTIME DESTINATION bin CONFIGURATIONS Release)
diff --git a/config/main.cpp b/config/main.cpp
deleted file mode 100644
index 2597e35..0000000
--- a/config/main.cpp
+++ /dev/null
@@ -1,29 +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 <QApplication>
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
- app.setApplicationDisplayName("poi-config");
- app.setApplicationVersion("0.1.0");
- app.setQuitOnLastWindowClosed(true);
-
- Configuration config;
- config.parse(argc, argv);
- config.parse(config.value<std::string>("config").value());
-
- SettingsDialog dlg(&config);
- dlg.configPath = QString::fromStdString(config.value<std::string>("config").value());
- dlg.setWindowTitle(dlg.configPath);
- dlg.show();
-
- return app.exec();
-}
diff --git a/config/settingsdialog.cpp b/config/settingsdialog.cpp
deleted file mode 100644
index 5ff4328..0000000
--- a/config/settingsdialog.cpp
+++ /dev/null
@@ -1,98 +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 <QApplication>
-#include <QFile>
-#include <QMenuBar>
-#include <QStatusBar>
-#include <QToolButton>
-#include <QVBoxLayout>
-#include <QFileDialog>
-
-SettingsDialog::SettingsDialog(Configuration *config, QWidget *parent)
- : QMainWindow(parent)
-{
- resize(800, 600);
-
- // main menu
- settingsMenu.setTitle(tr("Settings"));
-
- auto *saveAction = settingsMenu.addAction(tr("Save"));
- saveAction->setShortcut(QKeySequence::Save);
-
- auto *saveAsAction = settingsMenu.addAction(tr("Save As"));
- saveAsAction->setShortcut(QKeySequence::SaveAs);
-
- settingsMenu.addAction(tr("Quit"), qApp, &QApplication::quit, QKeySequence::Quit);
-
- menuBar()->addMenu(&settingsMenu);
-
- setCentralWidget(&treeWidget);
- treeWidget.setColumnCount(2);
- treeWidget.setHeaderLabels({ tr("setting"), tr("value") });
- treeWidget.setEditTriggers(QTreeWidget::NoEditTriggers);
- connect(&treeWidget, &QTreeWidget::itemDoubleClicked, this, &SettingsDialog::editItem);
-
- 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())));
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- }
-
- treeWidget.resizeColumnToContents(0);
-
- // connect signals
- connect(saveAction, &QAction::triggered, this, [this]() {
- write(configPath);
- statusBar()->showMessage(tr("Configuration saved to: ") + configPath, 3000);
- });
-
- connect(saveAsAction, &QAction::triggered, this, [this]() {
- QString path = QFileDialog::getSaveFileName(this, tr("Save Configuration"), configPath, tr("smolbote config (smolbote.cfg)"));
- if(!path.isEmpty()) {
- write(path);
- statusBar()->showMessage(tr("Configuration saved to: ") + path, 3000);
- }
- });
-}
-
-SettingsDialog::~SettingsDialog()
-{
- if(unsavedChanges)
- write(configPath);
-}
-
-void SettingsDialog::editItem(QTreeWidgetItem *item, int column)
-{
- if(column == 1) {
- treeWidget.editItem(item, column);
- unsavedChanges = true;
-
- if(!windowTitle().endsWith('*')) {
- setWindowTitle(windowTitle() + '*');
- }
- }
-}
-
-void SettingsDialog::write(const QString &path)
-{
- QFile output(path);
- output.open(QIODevice::WriteOnly);
-
- for(int i = 0; i < treeWidget.topLevelItemCount(); ++i) {
- auto *item = treeWidget.topLevelItem(i);
- output.write(QString(item->text(0) + " = " + item->text(1) + "\n").toUtf8());
- }
-
- output.close();
-
- unsavedChanges = false;
- setWindowTitle(configPath);
-}
diff --git a/config/settingsdialog.h b/config/settingsdialog.h
deleted file mode 100644
index d456bc3..0000000
--- a/config/settingsdialog.h
+++ /dev/null
@@ -1,37 +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 SMOLBOTE_SETTINGSDIALOG_H
-#define SMOLBOTE_SETTINGSDIALOG_H
-
-#include <QMainWindow>
-#include <QMenu>
-#include <QTreeWidget>
-#include <configuration.h>
-
-class SettingsDialog : public QMainWindow
-{
- Q_OBJECT
-
-public:
- explicit SettingsDialog(Configuration *config, QWidget *parent = nullptr);
- ~SettingsDialog() override;
-
- QString configPath;
-
-public slots:
- void editItem(QTreeWidgetItem *item, int column);
- void write(const QString &path);
-
-private:
- QMenu settingsMenu;
- QTreeWidget treeWidget;
- bool unsavedChanges = false;
-};
-
-#endif // SMOLBOTE_SETTINGSDIALOG_H