summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-05-07 14:21:19 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-05-11 20:45:10 +0200
commit9c8d21972c56f834637253ddc17e1231dca040d9 (patch)
tree961ab4a901772ccea7b2afbfd49e72da9a5ca8cc
parent2b19c6c532c37c2eeb2547cf92f719197957ab72 (diff)
opentrack: implement profile vendor presets
Sponsored by: TrackHat Sponsored by: IRTrack
-rw-r--r--logic/state.cpp3
-rw-r--r--logic/state.hpp1
-rw-r--r--opentrack/main-window.cpp33
-rw-r--r--opentrack/main-window.hpp1
4 files changed, 34 insertions, 4 deletions
diff --git a/logic/state.cpp b/logic/state.cpp
index 8218e5c3..dc5e5a36 100644
--- a/logic/state.cpp
+++ b/logic/state.cpp
@@ -22,7 +22,8 @@ std::tuple<dylib_ptr, int> State::module_by_name(const QString& name, dylib_list
State::State(const QString& library_path) :
modules(library_path),
- pose(s.all_axis_opts)
+ pose(s.all_axis_opts),
+ library_path{library_path}
{}
dylib_ptr State::current_tracker()
diff --git a/logic/state.hpp b/logic/state.hpp
index 809ca458..7fc06a5c 100644
--- a/logic/state.hpp
+++ b/logic/state.hpp
@@ -35,4 +35,5 @@ struct OTR_LOGIC_EXPORT State
module_settings m;
Mappings pose;
std::shared_ptr<Work> work;
+ QString library_path;
};
diff --git a/opentrack/main-window.cpp b/opentrack/main-window.cpp
index 1fded8e0..a8146120 100644
--- a/opentrack/main-window.cpp
+++ b/opentrack/main-window.cpp
@@ -320,7 +320,7 @@ void main_window::create_empty_profile()
QString name;
if (profile_name_from_dialog(name))
{
- QFile(ini_combine(name)).open(QFile::ReadWrite);
+ (void)maybe_create_profile(name);
refresh_profile_list();
if (profile_list.contains(name))
@@ -784,13 +784,16 @@ void main_window::set_profile(const QString& new_name_, bool migrate)
QString new_name = new_name_;
- if (!profile_list.contains(new_name))
+ if (!profile_list.contains(new_name_))
{
- new_name = OPENTRACK_DEFAULT_PROFILE;
+ new_name = QStringLiteral(OPENTRACK_DEFAULT_PROFILE);
if (!profile_list.contains(new_name))
migrate = false;
}
+ if (maybe_create_profile(new_name))
+ migrate = true;
+
const bool status = new_name != ini_filename();
if (status)
@@ -1002,6 +1005,30 @@ void main_window::toggle_tracker_()
start_tracker_();
}
+bool main_window::maybe_create_profile(const QString& name)
+{
+ const QString dest = ini_combine(name);
+
+ if (QFile::exists(dest))
+ return false;
+
+ const QString& default_name = QStringLiteral(OPENTRACK_DEFAULT_PROFILE);
+ const QString default_preset = (library_path + "/presets/%1").arg(default_name);
+
+ if (QFile::exists(default_preset))
+ {
+ bool ret = QFile::copy(default_preset, dest);
+ if (ret)
+ qDebug() << "create profile" << name << "from default preset" << (ret ? "" : "FAILED!");
+ return ret;
+ }
+ else
+ {
+ (void)QFile(ini_combine(name)).open(QFile::ReadWrite);
+ return false;
+ }
+}
+
#if !defined _WIN32
# include <unistd.h>
void main_window::annoy_if_root()
diff --git a/opentrack/main-window.hpp b/opentrack/main-window.hpp
index 495300c1..43440ff8 100644
--- a/opentrack/main-window.hpp
+++ b/opentrack/main-window.hpp
@@ -118,6 +118,7 @@ public:
void restart_tracker_();
void toggle_tracker_();
+ [[nodiscard]] bool maybe_create_profile(const QString& name);
void set_profile(const QString& new_name, bool migrate = true);
void set_profile_in_registry(const QString& profile);
void refresh_profile_list();