diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-03 12:06:50 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-09 12:13:24 +0100 |
commit | 195767619e7a7aeeeb33b13420538f687bef0104 (patch) | |
tree | 5701f484f4b8bff13452a192deab76e70ae91196 | |
parent | e5fdc0dad2609d89dc2a1294ea1c232c33e64785 (diff) |
opentrack: move module list to base class
-rw-r--r-- | logic/state.cpp | 45 | ||||
-rw-r--r-- | logic/state.hpp | 22 | ||||
-rw-r--r-- | variant/default/main-window.cpp | 35 | ||||
-rw-r--r-- | variant/default/main-window.hpp | 10 |
4 files changed, 63 insertions, 49 deletions
diff --git a/logic/state.cpp b/logic/state.cpp new file mode 100644 index 00000000..afdf5b12 --- /dev/null +++ b/logic/state.cpp @@ -0,0 +1,45 @@ +#include "state.hpp" + +#include <iterator> + +using dylib_ptr = Modules::dylib_ptr; +using dylib_list = Modules::dylib_list; + +std::tuple<dylib_ptr, int> State::module_by_name(const QString& name, dylib_list& list) +{ + auto it = std::find_if(list.cbegin(), list.cend(), [&name](const dylib_ptr& lib) { + if (!lib) + return name.isEmpty(); + else + return name == lib->module_name; + }); + + if (it == list.cend()) + return { nullptr, -1 }; + else + return { *it, int(std::distance(list.cbegin(), it)) }; +} + +State::State(const QString& library_path) : + modules(library_path), + ev(modules.extensions()), + pose(s.all_axis_opts) +{} + +dylib_ptr State::current_tracker() +{ + auto [ptr, idx] = module_by_name(m.tracker_dll, modules.trackers()); + return ptr; +} + +dylib_ptr State::current_protocol() +{ + auto [ptr, idx] = module_by_name(m.protocol_dll, modules.protocols()); + return ptr; +} + +dylib_ptr State::current_filter() +{ + auto [ptr, idx] = module_by_name(m.filter_dll, modules.filters()); + return ptr; +} diff --git a/logic/state.hpp b/logic/state.hpp index c400df18..abce1daf 100644 --- a/logic/state.hpp +++ b/logic/state.hpp @@ -14,19 +14,27 @@ #include "mappings.hpp" #include "extensions.hpp" #include "work.hpp" -#include <vector> +#include "export.hpp" + +#include <memory> #include <QString> -struct State +struct OTR_LOGIC_EXPORT State { - explicit State(const QString& library_path) : - modules(library_path), - ev(modules.extensions()), - pose(s.all_axis_opts) - {} + using dylib_ptr = Modules::dylib_ptr; + using dylib_list = Modules::dylib_list; + + explicit State(const QString& library_path); + static std::tuple<dylib_ptr, int> module_by_name(const QString& name, dylib_list& list); + + dylib_ptr current_tracker(); + dylib_ptr current_protocol(); + dylib_ptr current_filter(); + Modules modules; event_handler ev; main_settings s; + module_settings m; Mappings pose; std::shared_ptr<Work> work; }; diff --git a/variant/default/main-window.cpp b/variant/default/main-window.cpp index 192ad289..7f8b3bb8 100644 --- a/variant/default/main-window.cpp +++ b/variant/default/main-window.cpp @@ -19,7 +19,6 @@ #include "compat/sysexits.hpp" #include <algorithm> -#include <iterator> #include <utility> #include <QMessageBox> @@ -75,6 +74,9 @@ void main_window::init_shortcuts() void main_window::init_dylibs() { + using dylib_ptr = Modules::dylib_ptr; + using dylib_list = Modules::dylib_list; + modules.filters().push_front(std::make_shared<dylib>("", dylib::Filter)); for (dylib_ptr& x : modules.trackers()) @@ -389,38 +391,7 @@ void main_window::refresh_config_list() ui.iconcomboProfile->setCurrentText(current); } -std::tuple<main_window::dylib_ptr, int> main_window::module_by_name(const QString& name, Modules::dylib_list& list) -{ - auto it = std::find_if(list.cbegin(), list.cend(), [&name](const dylib_ptr& lib) { - if (!lib) - return name.isEmpty(); - else - return name == lib->module_name; - }); - - if (it == list.cend()) - return { nullptr, -1 }; - else - return { *it, int(std::distance(list.cbegin(), it)) }; -} -main_window::dylib_ptr main_window::current_tracker() -{ - auto [ptr, idx] = module_by_name(m.tracker_dll, modules.trackers()); - return ptr; -} - -main_window::dylib_ptr main_window::current_protocol() -{ - auto [ptr, idx] = module_by_name(m.protocol_dll, modules.protocols()); - return ptr; -} - -main_window::dylib_ptr main_window::current_filter() -{ - auto [ptr, idx] = module_by_name(m.filter_dll, modules.filters()); - return ptr; -} void main_window::update_button_state(bool running, bool inertialp) { diff --git a/variant/default/main-window.hpp b/variant/default/main-window.hpp index 6333c131..e6b2ed2e 100644 --- a/variant/default/main-window.hpp +++ b/variant/default/main-window.hpp @@ -44,8 +44,6 @@ class main_window final : public QMainWindow, private State Ui::main_window ui; - module_settings m; - std::unique_ptr<QSystemTrayIcon> tray; QMenu tray_menu { this }; @@ -77,13 +75,6 @@ class main_window final : public QMainWindow, private State bool exiting_already { false }; - using dylib_ptr = Modules::dylib_ptr; - using dylib_list = Modules::dylib_list; - - dylib_ptr current_tracker(); - dylib_ptr current_protocol(); - dylib_ptr current_filter(); - qt_sig::nullary start_tracker { this, &main_window::start_tracker_, Qt::QueuedConnection }; qt_sig::nullary stop_tracker { this, &main_window::stop_tracker_, Qt::QueuedConnection }; qt_sig::nullary toggle_tracker { this, &main_window::toggle_tracker_, Qt::QueuedConnection }; @@ -143,7 +134,6 @@ class main_window final : public QMainWindow, private State bool start_in_tray(); void save_modules(); - static std::tuple<dylib_ptr, int> module_by_name(const QString& name, Modules::dylib_list& list); void exit(int status = EXIT_SUCCESS); |