summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gui/ui.cpp50
-rw-r--r--gui/ui.h2
-rw-r--r--opentrack-logic/state.hpp2
-rw-r--r--opentrack-logic/tracklogger.hpp7
-rw-r--r--opentrack-logic/work.cpp45
-rw-r--r--opentrack-logic/work.hpp10
6 files changed, 52 insertions, 64 deletions
diff --git a/gui/ui.cpp b/gui/ui.cpp
index 3bda6ee2..94fd0cbf 100644
--- a/gui/ui.cpp
+++ b/gui/ui.cpp
@@ -15,7 +15,6 @@
#include <QFileDialog>
#include <QDesktopServices>
#include <QCoreApplication>
-#include <cassert>
#ifdef _WIN32
# include <windows.h>
@@ -286,44 +285,6 @@ void MainWindow::reload_options()
ensure_tray();
}
-/*
- Allocates a new logger instance depending on main settings. Result is assigned to logger variable of State object.
- May open warning dialogs.
- May also assign nullptr in case of an error.
-*/
-void MainWindow::initialize_logger()
-{
- logger = nullptr;
- if (s.tracklogging_enabled)
- {
- if (static_cast<QString>(s.tracklogging_filename).isEmpty())
- {
- QMessageBox::warning(this, tr("Logging Error"),
- tr("No filename given for track logging. Aborting."),
- QMessageBox::Ok,
- QMessageBox::NoButton);
- return;
- }
- try
- {
- logger = TrackLoggerCSV::make(s);
- }
- catch (std::ios_base::failure &)
- {
- QMessageBox::warning(this, tr("Logging Error"),
- tr("Unable to open file: ") + s.tracklogging_filename + tr(". Aborting."),
- QMessageBox::Ok,
- QMessageBox::NoButton);
- return;
- }
- }
- else
- {
- logger = TrackLogger::make();
- }
- assert(logger != nullptr);
-}
-
void MainWindow::startTracker()
{
@@ -350,17 +311,9 @@ void MainWindow::startTracker()
return;
}
- initialize_logger();
- if (logger == nullptr)
- {
- // error -> rollback
- libs = SelectedLibraries();
- return;
- }
-
save_modules();
- work = std::make_shared<Work>(pose, libs, *logger, winId());
+ work = std::make_shared<Work>(pose, libs, winId());
reload_options();
@@ -412,7 +365,6 @@ void MainWindow::stopTracker()
work = nullptr;
libs = SelectedLibraries();
- logger = nullptr;
{
double p[6] = {0,0,0, 0,0,0};
diff --git a/gui/ui.h b/gui/ui.h
index acec615e..d6f5e400 100644
--- a/gui/ui.h
+++ b/gui/ui.h
@@ -103,8 +103,6 @@ private slots:
void stopTracker();
void reload_options();
- void initialize_logger();
-
signals:
void emit_start_tracker();
void emit_stop_tracker();
diff --git a/opentrack-logic/state.hpp b/opentrack-logic/state.hpp
index bdab9afe..1c608f7a 100644
--- a/opentrack-logic/state.hpp
+++ b/opentrack-logic/state.hpp
@@ -14,7 +14,6 @@ using namespace options;
#include "main-settings.hpp"
#include "mappings.hpp"
#include "selected-libraries.hpp"
-#include "tracklogger.hpp"
#include "work.hpp"
#include <vector>
#include <QString>
@@ -30,5 +29,4 @@ struct State
main_settings s;
Mappings pose;
mem<Work> work;
- mem<TrackLogger> logger;
};
diff --git a/opentrack-logic/tracklogger.hpp b/opentrack-logic/tracklogger.hpp
index 99bc71b0..65128d48 100644
--- a/opentrack-logic/tracklogger.hpp
+++ b/opentrack-logic/tracklogger.hpp
@@ -14,8 +14,6 @@ public:
{
}
- static mem<TrackLogger> make() { return std::make_shared<TrackLogger>(); }
-
virtual void write(const char *)
{
}
@@ -45,12 +43,9 @@ public:
first_col(true)
{
out.open(filename.toStdString());
- if (!out.is_open())
- throw std::ios_base::failure("unable to open file");
}
- static mem<TrackLogger> make(const main_settings &s) { return std::static_pointer_cast<TrackLogger>(std::make_shared<TrackLoggerCSV>(s.tracklogging_filename)); }
-
+ bool is_open() const { return out.is_open(); }
virtual void write(const char *s);
virtual void write(const double *p, int n);
virtual void next_line();
diff --git a/opentrack-logic/work.cpp b/opentrack-logic/work.cpp
index e5b08c18..8d00270b 100644
--- a/opentrack-logic/work.cpp
+++ b/opentrack-logic/work.cpp
@@ -1,9 +1,50 @@
#include "work.hpp"
+#include <QMessageBox>
-Work::Work(Mappings& m, SelectedLibraries& libs, TrackLogger &logger, WId handle) :
+
+std::shared_ptr<TrackLogger> Work::make_logger(const main_settings &s)
+{
+ if (s.tracklogging_enabled)
+ {
+ if (static_cast<QString>(s.tracklogging_filename).isEmpty())
+ {
+ QMessageBox::warning(nullptr, "Logging Error",
+ "No filename given for track logging. Proceeding without logging.",
+ QMessageBox::Ok,
+ QMessageBox::NoButton);
+ }
+ else
+ {
+ auto logger = std::make_shared<TrackLoggerCSV>(s.tracklogging_filename);
+ if (!logger->is_open())
+ {
+ logger = nullptr;
+ QMessageBox::warning(nullptr, "Logging Error",
+ "Unable to open file: " + s.tracklogging_filename + ". Proceeding without logging.",
+ QMessageBox::Ok,
+ QMessageBox::NoButton);
+ }
+ else
+ {
+ /* As this function has the potential to fill up the hard drive
+ of the unwary with junk data, a warning is in order. */
+ QMessageBox::warning(nullptr, "Logging Active",
+ "Just a heads up. You are recoding pose data to " + s.tracklogging_filename + "!",
+ QMessageBox::Ok,
+ QMessageBox::NoButton);
+ return logger;
+ }
+ }
+ }
+ return std::make_shared<TrackLogger>();
+}
+
+
+Work::Work(Mappings& m, SelectedLibraries& libs, WId handle) :
libs(libs),
- tracker(std::make_shared<Tracker>(m, libs, logger)),
+ logger(make_logger(s)),
+ tracker(std::make_shared<Tracker>(m, libs, *logger)),
sc(std::make_shared<Shortcuts>()),
handle(handle),
keys {
diff --git a/opentrack-logic/work.hpp b/opentrack-logic/work.hpp
index 6425b11c..4afb1da4 100644
--- a/opentrack-logic/work.hpp
+++ b/opentrack-logic/work.hpp
@@ -13,6 +13,7 @@
#include "tracker.h"
#include "shortcuts.h"
#include "export.hpp"
+#include "tracklogger.hpp"
#include <QObject>
#include <QFrame>
@@ -25,15 +26,18 @@ struct OPENTRACK_LOGIC_EXPORT Work
{
using fn_t = std::function<void(bool)>;
using key_tuple = std::tuple<key_opts&, fn_t, bool>;
-
+ main_settings s; // tracker needs settings, so settings must come before it
SelectedLibraries& libs;
+ std::shared_ptr<TrackLogger> logger; // must come before tracker, since tracker depends on it
std::shared_ptr<Tracker> tracker;
std::shared_ptr<Shortcuts> sc;
WId handle;
std::vector<key_tuple> keys;
- main_settings s;
- Work(Mappings& m, SelectedLibraries& libs, TrackLogger &logger, WId handle);
+ Work(Mappings& m, SelectedLibraries& libs, WId handle);
~Work();
void reload_shortcuts();
+
+private:
+ std::shared_ptr<TrackLogger> make_logger(const main_settings &s);
};