summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/plugin-api.cpp9
-rw-r--r--api/plugin-api.hpp9
-rw-r--r--gui/settings.cpp110
-rw-r--r--gui/settings.hpp20
-rw-r--r--opentrack/main-window.cpp40
5 files changed, 147 insertions, 41 deletions
diff --git a/api/plugin-api.cpp b/api/plugin-api.cpp
index b6de3b16..3bfe9855 100644
--- a/api/plugin-api.cpp
+++ b/api/plugin-api.cpp
@@ -24,6 +24,9 @@ void BaseDialog::done(int)
}
bool BaseDialog::embeddable() noexcept { return false; }
+void BaseDialog::save() {}
+void BaseDialog::reload() {}
+void BaseDialog::set_buttons_visible(bool x) {}
} // ns plugin_api::detail
@@ -38,10 +41,14 @@ IFilter::IFilter() = default;
IFilter::~IFilter() = default;
IFilterDialog::IFilterDialog() = default;
IFilterDialog::~IFilterDialog() = default;
+void IFilterDialog::register_filter(IFilter* filter) {}
+void IFilterDialog::unregister_filter() {}
IProtocol::IProtocol() = default;
IProtocol::~IProtocol() = default;
IProtocolDialog::IProtocolDialog() = default;
IProtocolDialog::~IProtocolDialog() = default;
+void IProtocolDialog::register_protocol(IProtocol* protocol){}
+void IProtocolDialog::unregister_protocol() {}
ITracker::ITracker() = default;
ITracker::~ITracker() = default;
bool ITracker::center() { return false; }
@@ -49,7 +56,6 @@ ITrackerDialog::ITrackerDialog() = default;
ITrackerDialog::~ITrackerDialog() = default;
void ITrackerDialog::register_tracker(ITracker*) {}
void ITrackerDialog::unregister_tracker() {}
-void ITrackerDialog::set_buttons_visible(bool) {}
IExtension::~IExtension() = default;
IExtensionDialog::~IExtensionDialog() = default;
@@ -57,7 +63,6 @@ bool module_status::is_ok() const
{
return error.isNull();
}
-
module_status_mixin::~module_status_mixin() = default;
module_status::module_status(const QString& error) : error(error) {}
module_status::module_status() = default;
diff --git a/api/plugin-api.hpp b/api/plugin-api.hpp
index ab43884a..9cc87f82 100644
--- a/api/plugin-api.hpp
+++ b/api/plugin-api.hpp
@@ -43,6 +43,9 @@ protected:
public:
void closeEvent(QCloseEvent *) override;
virtual bool embeddable() noexcept;
+ virtual void set_buttons_visible(bool x); // XXX TODO remove it once all modules are converted
+ virtual void save(); // XXX HACK should be pure virtual
+ virtual void reload(); // XXX HACK should be pure virtual -sh 20211214
signals:
void closing();
private slots:
@@ -216,17 +219,11 @@ struct OTR_API_EXPORT ITrackerDialog : public plugin_api::detail::BaseDialog
virtual void register_tracker(ITracker *tracker);
// received tracker pointer is about to get deleted
virtual void unregister_tracker();
- virtual void set_buttons_visible(bool x); // XXX TODO remove it once all modules are converted
- virtual void save(); // XXX HACK should be pure virtual
- virtual void reload(); // XXX HACK should be pure virtual -sh 20211214
ITrackerDialog();
~ITrackerDialog() override;
};
-inline void ITrackerDialog::save() {}
-inline void ITrackerDialog::reload() {}
-
// call once with your chosen class names in the plugin
#define OPENTRACK_DECLARE_TRACKER(tracker_class, dialog_class, metadata_class) \
OPENTRACK_DECLARE_PLUGIN_INTERNAL(tracker_class, ITracker, metadata_class, dialog_class, ITrackerDialog)
diff --git a/gui/settings.cpp b/gui/settings.cpp
index 907fe8f3..7d74c762 100644
--- a/gui/settings.cpp
+++ b/gui/settings.cpp
@@ -47,6 +47,8 @@ void options_dialog::set_disable_translation_state(bool value)
}
options_dialog::options_dialog(std::unique_ptr<ITrackerDialog>& tracker_dialog_,
+ std::unique_ptr<IProtocolDialog>& proto_dialog_,
+ std::unique_ptr<IFilterDialog>& filter_dialog_,
std::function<void(bool)> pause_keybindings) :
pause_keybindings(std::move(pause_keybindings))
{
@@ -177,6 +179,18 @@ options_dialog::options_dialog(std::unique_ptr<ITrackerDialog>& tracker_dialog_,
tracker_dialog->set_buttons_visible(false);
ui.tabWidget->addTab(tracker_dialog, tr("Tracker"));
}
+ if (proto_dialog_ && proto_dialog_->embeddable())
+ {
+ proto_dialog = proto_dialog_.release();
+ proto_dialog->set_buttons_visible(false);
+ ui.tabWidget->addTab(proto_dialog, tr("Output"));
+ }
+ if (filter_dialog_ && filter_dialog_->embeddable())
+ {
+ filter_dialog = filter_dialog_.release();
+ filter_dialog->set_buttons_visible(false);
+ ui.tabWidget->addTab(filter_dialog, tr("Filter"));
+ }
}
void options_dialog::bind_key(key_opts& kopts, QLabel* label)
@@ -236,23 +250,23 @@ void options_dialog::switch_to_tracker_tab()
if (tracker_dialog)
ui.tabWidget->setCurrentWidget(tracker_dialog);
else
- eval_once(qDebug() << "options: asked for tab widget with old-style widget dialog!");
+ eval_once(qDebug() << "options: asked for tracker tab widget with old-style widget dialog!");
}
-void options_dialog::unregister_tracker()
+void options_dialog::switch_to_proto_tab()
{
- if (tracker_dialog)
- {
- tracker_dialog->unregister_tracker();
- }
+ if (proto_dialog)
+ ui.tabWidget->setCurrentWidget(proto_dialog);
+ else
+ eval_once(qDebug() << "options: asked for proto tab widget with old-style widget dialog!");
}
-void options_dialog::register_tracker(ITracker* t)
+void options_dialog::switch_to_filter_tab()
{
- if (tracker_dialog)
- {
- tracker_dialog->register_tracker(t);
- }
+ if (filter_dialog)
+ ui.tabWidget->setCurrentWidget(filter_dialog);
+ else
+ eval_once(qDebug() << "options: asked for filter tab widget with old-style widget dialog!");
}
void options_dialog::tracker_module_changed()
@@ -266,14 +280,75 @@ void options_dialog::tracker_module_changed()
}
}
+void options_dialog::proto_module_changed()
+{
+ if (proto_dialog)
+ {
+ unregister_protocol();
+ reload();
+ delete proto_dialog;
+ proto_dialog = nullptr;
+ }
+}
+
+void options_dialog::filter_module_changed()
+{
+ if (filter_dialog)
+ {
+ unregister_filter();
+ reload();
+ delete filter_dialog;
+ filter_dialog = nullptr;
+ }
+}
+
+void options_dialog::register_tracker(ITracker* t)
+{
+ if (tracker_dialog)
+ tracker_dialog->register_tracker(t);
+}
+
+void options_dialog::unregister_tracker()
+{
+ if (tracker_dialog)
+ tracker_dialog->unregister_tracker();
+}
+
+void options_dialog::register_protocol(IProtocol* p)
+{
+ if (proto_dialog)
+ proto_dialog->register_protocol(p);
+}
+
+void options_dialog::unregister_protocol()
+{
+ if (proto_dialog)
+ proto_dialog->unregister_protocol();
+}
+
+void options_dialog::register_filter(IFilter* f)
+{
+ if (filter_dialog)
+ filter_dialog->register_filter(f);
+}
+
+void options_dialog::unregister_filter()
+{
+ if (filter_dialog)
+ filter_dialog->unregister_filter();
+}
+
+using module_list = std::initializer_list<plugin_api::detail::BaseDialog*>;
+
void options_dialog::save()
{
main.b->save();
ui.game_detector->save();
set_disable_translation_state(ui.disable_translation->isChecked());
- if (tracker_dialog)
- tracker_dialog->save();
+ for (auto* dlg : module_list{ tracker_dialog, proto_dialog, filter_dialog })
+ if (dlg)
+ dlg->save();
}
void options_dialog::reload()
@@ -281,8 +356,9 @@ void options_dialog::reload()
ui.game_detector->revert();
main.b->reload();
- if (tracker_dialog)
- tracker_dialog->reload();
+ for (auto* dlg : module_list{ tracker_dialog, proto_dialog, filter_dialog })
+ if (dlg)
+ dlg->reload();
}
void options_dialog::doOK()
@@ -313,4 +389,8 @@ options_dialog::~options_dialog()
{
if (tracker_dialog)
tracker_dialog->unregister_tracker();
+ if (proto_dialog)
+ proto_dialog->unregister_protocol();
+ if (filter_dialog)
+ filter_dialog->unregister_filter();
}
diff --git a/gui/settings.hpp b/gui/settings.hpp
index 268ccb73..2cb3492c 100644
--- a/gui/settings.hpp
+++ b/gui/settings.hpp
@@ -17,13 +17,24 @@ class OTR_GUI_EXPORT options_dialog final : public QDialog
signals:
void closing();
public:
- options_dialog(std::unique_ptr<ITrackerDialog>& tracker_dialog, std::function<void(bool)> pause_keybindings);
+ options_dialog(std::unique_ptr<ITrackerDialog>& tracker_dialog_,
+ std::unique_ptr<IProtocolDialog>& proto_dialog_,
+ std::unique_ptr<IFilterDialog>& filter_dialog_,
+ std::function<void(bool)> pause_keybindings);
~options_dialog() override;
inline bool embeddable() noexcept { return false; }
void switch_to_tracker_tab();
+ void switch_to_proto_tab();
+ void switch_to_filter_tab();
+ void tracker_module_changed();
+ void proto_module_changed();
+ void filter_module_changed();
void register_tracker(ITracker* t);
void unregister_tracker();
- void tracker_module_changed();
+ void register_protocol(IProtocol* p);
+ void unregister_protocol();
+ void register_filter(IFilter* f);
+ void unregister_filter();
void save();
void reload();
private:
@@ -33,7 +44,10 @@ private:
main_settings main;
std::function<void(bool)> pause_keybindings;
Ui::options_dialog ui;
- ITrackerDialog* tracker_dialog = nullptr;
+
+ ITrackerDialog* tracker_dialog = nullptr;
+ IProtocolDialog* proto_dialog = nullptr;
+ IFilterDialog* filter_dialog = nullptr;
private slots:
void doOK();
diff --git a/opentrack/main-window.cpp b/opentrack/main-window.cpp
index d16e7854..f68e1c25 100644
--- a/opentrack/main-window.cpp
+++ b/opentrack/main-window.cpp
@@ -89,10 +89,10 @@ void main_window::init_dylibs()
this, [this](const QString&) { pTrackerDialog = nullptr; if (options_widget) options_widget->tracker_module_changed(); });
connect(ui.iconcomboProtocol, &QComboBox::currentTextChanged,
- this, [this](const QString&) { pProtocolDialog = nullptr; });
+ this, [this](const QString&) { pProtocolDialog = nullptr; if (options_widget) options_widget->proto_module_changed(); });
connect(ui.iconcomboFilter, &QComboBox::currentTextChanged,
- this, [this](const QString&) { pFilterDialog = nullptr; });
+ this, [this](const QString&) { pFilterDialog = nullptr; if (options_widget) options_widget->filter_module_changed(); });
connect(&m.tracker_dll, value_::value_changed<QString>(),
this, &main_window::save_modules,
@@ -409,24 +409,22 @@ void main_window::start_tracker_()
}
if (pTrackerDialog)
- {
- auto* tracker = &*work->libs.pTracker;
- pTrackerDialog->register_tracker(tracker);
- }
-
- if (options_widget)
- {
- // XXX TODO other module types
- auto* tracker = &*work->libs.pTracker;
- options_widget->register_tracker(tracker);
- }
+ pTrackerDialog->register_tracker(&*work->libs.pTracker);
- if (pFilterDialog)
+ if (pFilterDialog && work->libs.pFilter)
pFilterDialog->register_filter(&*work->libs.pFilter);
if (pProtocolDialog)
pProtocolDialog->register_protocol(&*work->libs.pProtocol);
+ if (options_widget)
+ {
+ options_widget->register_tracker(&*work->libs.pTracker);
+ options_widget->register_protocol(&*work->libs.pProtocol);
+ if (work->libs.pFilter)
+ options_widget->register_filter(&*work->libs.pFilter);
+ }
+
pose_update_timer.start(15);
// NB check valid since SelectedLibraries ctor called
@@ -619,6 +617,11 @@ void main_window::show_proto_settings_(bool show)
QObject::connect(&*pProtocolDialog, &IProtocolDialog::closing,
this, [this] { pProtocolDialog = nullptr; });
}
+ else if (show && pFilterDialog && pProtocolDialog->embeddable())
+ {
+ show_options_dialog();
+ options_widget->switch_to_proto_tab();
+ }
}
void main_window::show_filter_settings_(bool show)
@@ -629,6 +632,11 @@ void main_window::show_filter_settings_(bool show)
QObject::connect(&*pFilterDialog, &IFilterDialog::closing,
this, [this] { pFilterDialog = nullptr; });
}
+ else if (show && pFilterDialog && pFilterDialog->embeddable())
+ {
+ show_options_dialog();
+ options_widget->switch_to_filter_tab();
+ }
}
void main_window::show_options_dialog()
@@ -637,8 +645,10 @@ void main_window::show_options_dialog()
return;
show_tracker_settings_(false);
+ show_proto_settings_(false);
+ show_filter_settings_(false);
- if (mk_window(options_widget, true, pTrackerDialog,
+ if (mk_window(options_widget, true, pTrackerDialog, pProtocolDialog, pFilterDialog,
[this](bool flag) { set_keys_enabled(!flag); }))
{
// move shortcuts to a separate bundle and add a migration -sh 20180218