From 77cf67d61c8f6ae7ec00fd069b0e6586927069a3 Mon Sep 17 00:00:00 2001 From: DaMichel Date: Thu, 8 Sep 2016 16:43:12 +0200 Subject: tracklogging: begone file selector gui. Now a file select dialog will pop up when the tracker starts. --- logic/work.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'logic/work.cpp') diff --git a/logic/work.cpp b/logic/work.cpp index c369921c..c5fcad9a 100644 --- a/logic/work.cpp +++ b/logic/work.cpp @@ -1,18 +1,38 @@ #include "work.hpp" +#include "opentrack-library-path.h" #include +#include -std::shared_ptr Work::make_logger(const main_settings &s) +static QString browse_datalogging_file(main_settings &s) +{ + QString filename = s.tracklogging_filename; + if (filename.isEmpty()) + filename = OPENTRACK_BASE_PATH; + /* Sometimes this function freezes the app before opening the dialog. + Might be related to https://forum.qt.io/topic/49209/qfiledialog-getopenfilename-hangs-in-windows-when-using-the-native-dialog/8 + and be a known problem. Possible solution is to use the QFileDialog::DontUseNativeDialog flag. + Since the freeze is apparently random, I'm not sure it helped. + */ + QString newfilename = QFileDialog::getSaveFileName(nullptr, QFileDialog::tr("Select Filename"), filename, QFileDialog::tr("CSV File (*.csv)"), nullptr); //, QFileDialog::DontUseNativeDialog); + if (!newfilename.isEmpty()) + { + s.tracklogging_filename = newfilename; + } + // dialog likes to mess with current directory + QDir::setCurrent(OPENTRACK_BASE_PATH); + return newfilename; +} + +std::shared_ptr Work::make_logger(main_settings &s) { if (s.tracklogging_enabled) { + QString filename = browse_datalogging_file(s); if (static_cast(s.tracklogging_filename).isEmpty()) { - QMessageBox::warning(nullptr, "Logging Error", - "No filename given for track logging. Proceeding without logging.", - QMessageBox::Ok, - QMessageBox::NoButton); + // The user probably canceled the file dialog. In this case we don't want to do anything. } else { @@ -27,12 +47,6 @@ std::shared_ptr Work::make_logger(const main_settings &s) } 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; } } -- cgit v1.2.3