aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.hgignore3
-rw-r--r--CMakeLists.txt4
-rw-r--r--config/CMakeLists.txt26
-rw-r--r--config/main.cpp29
-rw-r--r--config/settingsdialog.cpp98
-rw-r--r--plugins/ConfigurationEditor/CMakeLists.txt28
-rw-r--r--plugins/ConfigurationEditor/ConfigurationEditor.json5
-rw-r--r--plugins/ConfigurationEditor/configurationeditorplugin.cpp30
-rw-r--r--plugins/ConfigurationEditor/configurationeditorplugin.h26
-rw-r--r--plugins/ConfigurationEditor/forms/settingsdialog.cpp101
-rw-r--r--plugins/ConfigurationEditor/forms/settingsdialog.h (renamed from config/settingsdialog.h)12
-rw-r--r--plugins/interfaces.h18
-rw-r--r--src/browser.cpp27
13 files changed, 232 insertions, 175 deletions
diff --git a/.hgignore b/.hgignore
index 94233be..95c3033 100644
--- a/.hgignore
+++ b/.hgignore
@@ -8,3 +8,6 @@ build*
# qtcreator
.user
+
+test/plugins.d
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a4f64d2..c0a4bda 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -69,13 +69,11 @@ add_subdirectory(lib/configuration)
add_subdirectory(lib/web)
add_subdirectory(plugins/ProfileEditor)
+add_subdirectory(plugins/ConfigurationEditor)
# browser source code
add_subdirectory(src)
-# configuration program
-add_subdirectory(config)
-
if (Tests)
enable_testing()
find_package(Qt5 COMPONENTS Test REQUIRED)
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/plugins/ConfigurationEditor/CMakeLists.txt b/plugins/ConfigurationEditor/CMakeLists.txt
new file mode 100644
index 0000000..3687463
--- /dev/null
+++ b/plugins/ConfigurationEditor/CMakeLists.txt
@@ -0,0 +1,28 @@
+find_package(Qt5Core REQUIRED)
+find_package(Qt5Widgets REQUIRED)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTOUIC ON)
+
+add_library(ConfigurationEditorPlugin SHARED
+ configurationeditorplugin.cpp
+ configurationeditorplugin.h
+ forms/settingsdialog.cpp
+ forms/settingsdialog.h
+)
+
+target_include_directories(ConfigurationEditorPlugin
+ PRIVATE ..
+ PRIVATE ${CMAKE_SOURCE_DIR}/lib/configuration
+)
+
+target_link_libraries(ConfigurationEditorPlugin
+ PRIVATE Qt5::Widgets
+ PRIVATE configuration
+)
+
+if(WIN32)
+ install(TARGETS ConfigurationEditorPlugin RUNTIME DESTINATION lib/smolbote CONFIGURATIONS Release)
+else()
+ install(TARGETS ConfigurationEditorPlugin LIBRARY DESTINATION lib/smolbote CONFIGURATIONS Release)
+endif()
diff --git a/plugins/ConfigurationEditor/ConfigurationEditor.json b/plugins/ConfigurationEditor/ConfigurationEditor.json
new file mode 100644
index 0000000..5c9d504
--- /dev/null
+++ b/plugins/ConfigurationEditor/ConfigurationEditor.json
@@ -0,0 +1,5 @@
+{
+ "name": "Configuration Editor",
+ "author": "Aqua-sama",
+ "shortcut": "Ctrl+Shift+C"
+}
diff --git a/plugins/ConfigurationEditor/configurationeditorplugin.cpp b/plugins/ConfigurationEditor/configurationeditorplugin.cpp
new file mode 100644
index 0000000..a5ca0bd
--- /dev/null
+++ b/plugins/ConfigurationEditor/configurationeditorplugin.cpp
@@ -0,0 +1,30 @@
+#include "configurationeditorplugin.h"
+#include <QHash>
+#include <QDialog>
+#include "forms/settingsdialog.h"
+#include <configuration.h>
+
+CommandHash_t ConfigurationEditorPlugin::commands()
+{
+ QHash<QString, std::function<int()>> hash;
+
+ hash.insert("configure", [this]() -> int {
+ auto *dlg = createWidget(nullptr);
+ return dlg->exec();
+ });
+
+ return hash;
+}
+
+QDialog *ConfigurationEditorPlugin::createWidget(QWidget *parent)
+{
+ auto *dlg = new SettingsDialog(m_config, parent);
+ dlg->setAttribute(Qt::WA_DeleteOnClose, true);
+ return dlg;
+}
+
+void ConfigurationEditorPlugin::setConfiguration(Configuration *cfg)
+{
+ Q_CHECK_PTR(cfg);
+ m_config = cfg;
+}
diff --git a/plugins/ConfigurationEditor/configurationeditorplugin.h b/plugins/ConfigurationEditor/configurationeditorplugin.h
new file mode 100644
index 0000000..6054723
--- /dev/null
+++ b/plugins/ConfigurationEditor/configurationeditorplugin.h
@@ -0,0 +1,26 @@
+#ifndef CONFIGURATIONEDITOR_PLUGIN_H
+#define CONFIGURATIONEDITOR_PLUGIN_H
+
+#include <QVector>
+#include <interfaces.h>
+
+class QDialog;
+class ConfigurationEditorPlugin : public QObject, public PluginInterface, public ConfigurationInterface
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID ProfileInterfaceIid FILE "ConfigurationEditor.json")
+ Q_INTERFACES(PluginInterface ConfigurationInterface)
+
+public:
+ // PluginInterface
+ CommandHash_t commands() override;
+ QDialog *createWidget(QWidget *parent = nullptr) override;
+
+ // ConfigurationInterface
+ void setConfiguration(Configuration *cfg) override;
+
+private:
+ Configuration *m_config = nullptr;
+};
+
+#endif // CONFIGURATIONEDITOR_PLUGIN_H
diff --git a/plugins/ConfigurationEditor/forms/settingsdialog.cpp b/plugins/ConfigurationEditor/forms/settingsdialog.cpp
new file mode 100644
index 0000000..ebc054e
--- /dev/null
+++ b/plugins/ConfigurationEditor/forms/settingsdialog.cpp
@@ -0,0 +1,101 @@
+/*
+ * 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>
+#include <configuration.h>
+
+SettingsDialog::SettingsDialog(Configuration *config, QWidget *parent)
+ : QDialog(parent)
+{
+ resize(800, 600);
+ Q_CHECK_PTR(config);
+
+ // 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);
+
+ auto *layout = new QVBoxLayout(this);
+ layout->addWidget(&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/plugins/ConfigurationEditor/forms/settingsdialog.h
index d456bc3..ed9e02d 100644
--- a/config/settingsdialog.h
+++ b/plugins/ConfigurationEditor/forms/settingsdialog.h
@@ -9,12 +9,11 @@
#ifndef SMOLBOTE_SETTINGSDIALOG_H
#define SMOLBOTE_SETTINGSDIALOG_H
-#include <QMainWindow>
-#include <QMenu>
+#include <QDialog>
#include <QTreeWidget>
-#include <configuration.h>
-class SettingsDialog : public QMainWindow
+class Configuration;
+class SettingsDialog : public QDialog
{
Q_OBJECT
@@ -25,11 +24,10 @@ public:
QString configPath;
public slots:
- void editItem(QTreeWidgetItem *item, int column);
- void write(const QString &path);
+// void editItem(QTreeWidgetItem *item, int column);
+// void write(const QString &path);
private:
- QMenu settingsMenu;
QTreeWidget treeWidget;
bool unsavedChanges = false;
};
diff --git a/plugins/interfaces.h b/plugins/interfaces.h
index 1a12f02..aad43c1 100644
--- a/plugins/interfaces.h
+++ b/plugins/interfaces.h
@@ -18,6 +18,7 @@ class QString;
class QAction;
class QDialog;
class WebProfile;
+class Configuration;
struct Plugin
{
@@ -27,26 +28,37 @@ struct Plugin
QObject *instance;
};
+typedef QHash<QString, std::function<int()>> CommandHash_t;
+
class PluginInterface
{
public:
virtual ~PluginInterface() = default;
- virtual QHash<QString, std::function<int()>> commands() = 0;
+ virtual CommandHash_t commands() = 0;
+ virtual QDialog *createWidget(QWidget *parent = nullptr) = 0;
};
class ProfileInterface
{
public:
virtual ~ProfileInterface() = default;
- virtual QDialog *createWidget(QWidget *parent = nullptr) = 0;
-
virtual void registerProfile(WebProfile *profile) = 0;
};
+class ConfigurationInterface
+{
+public:
+ virtual ~ConfigurationInterface() = default;
+ virtual void setConfiguration(Configuration *cfg) = 0;
+};
+
#define PluginInterfaceIid "net.iserlohn-fortress.smolbote.PluginInterface"
Q_DECLARE_INTERFACE(PluginInterface, PluginInterfaceIid)
#define ProfileInterfaceIid "net.iserlohn-fortress.smolbote.ProfileInterface"
Q_DECLARE_INTERFACE(ProfileInterface, ProfileInterfaceIid)
+#define ConfigurationInterfaceIid "net.iserlohn-fortress.smolbote.ConfigurationInterface"
+Q_DECLARE_INTERFACE(ConfigurationInterface, ConfigurationInterfaceIid)
+
#endif // SMOLBOTE_PLUGIN_INTERFACES_H
diff --git a/src/browser.cpp b/src/browser.cpp
index 56eed96..e266024 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -70,6 +70,13 @@ void Browser::registerPlugin(const Plugin &plugin)
});
}
+ if(plugin.instance->inherits("ConfigurationInterface")) {
+ auto *configEditor = qobject_cast<ConfigurationInterface *>(plugin.instance);
+ Q_CHECK_PTR(configEditor);
+
+ configEditor->setConfiguration(m_config.get());
+ }
+
m_plugins.append(plugin);
}
@@ -193,15 +200,17 @@ MainWindow *Browser::createWindow()
window->addAction(MainWindow::ToolsMenu, downloadsAction);
for(const Plugin &p : qAsConst(m_plugins)) {
- if(p.instance->inherits("ProfileInterface")) {
- auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance);
- auto *profileAction = new QAction(tr("Profile"), window);
- profileAction->setShortcut(p.shortcut);
- connect(profileAction, &QAction::triggered, window, [profileEditor]() {
- profileEditor->createWidget(nullptr)->show();
- });
- window->addAction(MainWindow::ToolsMenu, profileAction);
- }
+ auto *plugin = qobject_cast<PluginInterface *>(p.instance);
+ Q_CHECK_PTR(plugin);
+
+ auto *pluginAction = new QAction(p.name, window);
+ pluginAction->setShortcut(p.shortcut);
+
+ connect(pluginAction, &QAction::triggered, window, [=]() {
+ plugin->createWidget(window)->exec();
+ });
+ window->addAction(MainWindow::ToolsMenu, pluginAction);
+
}
m_windows.append(window);