summaryrefslogtreecommitdiffhomepage
path: root/variant/default
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-04-28 17:25:35 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-04-28 21:27:35 +0200
commitc80dd2e156e20f028cf4631fd7874a89c3568bab (patch)
treeb15b61ad444aeaab61ea04e549ee24e98ab6415a /variant/default
parent526304a41970c1ad890cf81d92bb4b123e8608e7 (diff)
settings: store untranslated chosen module names
Now that we translate module names, they have to be stored as language-neutral in the config. - add tie_setting overload with from/to conversions - add logic to opentrack/main-window - add migration - remove actually useless tie_setting_traits
Diffstat (limited to 'variant/default')
-rw-r--r--variant/default/main-window.cpp106
-rw-r--r--variant/default/main-window.hpp21
2 files changed, 100 insertions, 27 deletions
diff --git a/variant/default/main-window.cpp b/variant/default/main-window.cpp
index 62b969e1..c52a806e 100644
--- a/variant/default/main-window.cpp
+++ b/variant/default/main-window.cpp
@@ -17,6 +17,8 @@
#include "compat/library-path.hpp"
#include "compat/math.hpp"
+#include <iterator>
+
#include <QMessageBox>
#include <QDesktopServices>
#include <QDir>
@@ -82,7 +84,7 @@ main_window::main_window() :
if (!refresh_config_list())
{
- exit(64);
+ exit(EX_OSFILE);
return;
}
@@ -97,16 +99,16 @@ main_window::main_window() :
// fill dylib comboboxen
{
- modules.filters().push_front(std::make_shared<dylib>("", dylib::Filter));
+ modules.filters().push_front(std::make_shared<dylib>(QString(), dylib::Filter));
- for (std::shared_ptr<dylib>& x : modules.trackers())
- ui.iconcomboTrackerSource->addItem(x->icon, x->name);
+ for (dylib_ptr& x : modules.trackers())
+ ui.iconcomboTrackerSource->addItem(x->icon, x->name, x->module_name);
- for (std::shared_ptr<dylib>& x : modules.protocols())
- ui.iconcomboProtocol->addItem(x->icon, x->name);
+ for (dylib_ptr& x : modules.protocols())
+ ui.iconcomboProtocol->addItem(x->icon, x->name, x->module_name);
- for (std::shared_ptr<dylib>& x : modules.filters())
- ui.iconcomboFilter->addItem(x->icon, x->name);
+ for (dylib_ptr& x : modules.filters())
+ ui.iconcomboFilter->addItem(x->icon, x->name, x->module_name);
}
// timers
@@ -155,13 +157,48 @@ main_window::main_window() :
this,
[&](const QString&) { if (pFilterDialog) pFilterDialog = nullptr; });
- connect(&m.tracker_dll, base_value::value_changed<QString>(), this, &main_window::save_modules, Qt::DirectConnection);
- connect(&m.protocol_dll, base_value::value_changed<QString>(), this, &main_window::save_modules, Qt::DirectConnection);
- connect(&m.filter_dll, base_value::value_changed<QString>(), this, &main_window::save_modules, Qt::DirectConnection);
+ connect(&m.tracker_dll, base_value::value_changed<QString>(),
+ this, &main_window::save_modules,
+ Qt::DirectConnection);
+
+ connect(&m.protocol_dll, base_value::value_changed<QString>(),
+ this, &main_window::save_modules,
+ Qt::DirectConnection);
- tie_setting(m.tracker_dll, ui.iconcomboTrackerSource);
- tie_setting(m.protocol_dll, ui.iconcomboProtocol);
- tie_setting(m.filter_dll, ui.iconcomboFilter);
+ connect(&m.filter_dll, base_value::value_changed<QString>(),
+ this, &main_window::save_modules,
+ Qt::DirectConnection);
+
+ {
+ struct list {
+ dylib_list& libs;
+ QComboBox* input;
+ value<QString>& place;
+ };
+
+ list types[] {
+ { modules.trackers(), ui.iconcomboTrackerSource, m.tracker_dll },
+ { modules.protocols(), ui.iconcomboProtocol, m.protocol_dll },
+ { modules.filters(), ui.iconcomboFilter, m.filter_dll },
+ };
+
+ for (list& type : types)
+ {
+ list& t = type;
+ tie_setting(t.place, t.input,
+ [t](const QString& name) {
+ auto [ptr, idx] = module_by_name(name, t.libs);
+ return idx;
+ },
+ [t](int, const QVariant& userdata) {
+ auto [ptr, idx] = module_by_name(userdata.toString(), t.libs);
+ if (ptr)
+ return ptr->module_name;
+ else
+ return QString();
+ });
+ }
+ }
}
connect(this, &main_window::start_tracker,
@@ -461,6 +498,39 @@ bool main_window::refresh_config_list()
return true;
}
+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)
{
bool not_running = !running;
@@ -718,13 +788,19 @@ bool main_window::set_profile(const QString& new_name_)
ui.iconcomboProfile->setCurrentText(new_name);
set_profile_in_registry(new_name);
- set_title();
+ // XXX workaround migration breakage -sh 20180428
+ QSignalBlocker b1(ui.iconcomboTrackerSource);
+ QSignalBlocker b2(ui.iconcomboProtocol);
+ QSignalBlocker b3(ui.iconcomboFilter);
+
options::detail::bundler::refresh_all_bundles();
// migrations are for config layout changes and other user-visible
// incompatibilities in future versions
run_migrations();
+ set_title();
+
return true;
}
diff --git a/variant/default/main-window.hpp b/variant/default/main-window.hpp
index c28aadc4..6e85a13c 100644
--- a/variant/default/main-window.hpp
+++ b/variant/default/main-window.hpp
@@ -32,6 +32,7 @@
#include <QEvent>
#include <QCloseEvent>
+#include <algorithm>
#include <vector>
#include <tuple>
#include <memory>
@@ -72,18 +73,14 @@ class main_window : public QMainWindow, private State
menu_action_options { &tray_menu },
menu_action_mappings { &tray_menu };
- std::shared_ptr<dylib> current_tracker()
- {
- return modules.trackers().value(ui.iconcomboTrackerSource->currentIndex(), nullptr);
- }
- std::shared_ptr<dylib> current_protocol()
- {
- return modules.protocols().value(ui.iconcomboProtocol->currentIndex(), nullptr);
- }
- std::shared_ptr<dylib> current_filter()
- {
- return modules.filters().value(ui.iconcomboFilter->currentIndex(), nullptr);
- }
+ using dylib_ptr = Modules::dylib_ptr;
+ using dylib_list = Modules::dylib_list;
+
+ static std::tuple<dylib_ptr, int> module_by_name(const QString& name, Modules::dylib_list& list);
+
+ dylib_ptr current_tracker();
+ dylib_ptr current_protocol();
+ dylib_ptr current_filter();
void update_button_state(bool running, bool inertialp);
void display_pose(const double* mapped, const double* raw);