summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-01-11 14:36:07 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-01-11 14:36:07 +0100
commite1d6232217120be879bb639681f61e46e2d48580 (patch)
treed186ffc3dd72de6e4703d584a41971107ca8389b /gui
parent98ef185a5c9075720acb54ec1c2e5fec6e4ab440 (diff)
cmake, gui, main: make user interface reusable
The work isn't complete. We need moving out all non-reusable parts away and only keeping user interface logic in a class.
Diffstat (limited to 'gui')
-rw-r--r--gui/CMakeLists.txt7
-rw-r--r--gui/export.hpp11
-rw-r--r--gui/keyboard.cpp2
-rw-r--r--gui/keyboard.h6
-rw-r--r--gui/main-window.cpp112
-rw-r--r--gui/main-window.hpp14
-rw-r--r--gui/main.cpp255
-rw-r--r--gui/mapping-dialog.cpp16
-rw-r--r--gui/mapping-dialog.hpp10
-rw-r--r--gui/mapping-dialog.ui4
-rw-r--r--gui/process_detector.cpp18
-rw-r--r--gui/process_detector.h12
-rw-r--r--gui/settings.cpp22
-rw-r--r--gui/settings.hpp8
14 files changed, 129 insertions, 368 deletions
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index d0cba4ac..954fa67a 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -1,9 +1,4 @@
-otr_module(user-interface EXECUTABLE BIN)
-
-set_target_properties(opentrack-user-interface PROPERTIES
- SUFFIX "${opentrack-binary-suffix}"
- OUTPUT_NAME "opentrack"
- )
+otr_module(user-interface BIN)
target_link_libraries(opentrack-user-interface
opentrack-migration
diff --git a/gui/export.hpp b/gui/export.hpp
new file mode 100644
index 00000000..3ef3e5b8
--- /dev/null
+++ b/gui/export.hpp
@@ -0,0 +1,11 @@
+// generates export.hpp for each module from compat/linkage.hpp
+
+#pragma once
+
+#include "compat/linkage-macros.hpp"
+
+#ifdef BUILD_USER_INTERFACE
+# define OTR_GUI_EXPORT OTR_GENERIC_EXPORT
+#else
+# define OTR_GUI_EXPORT OTR_GENERIC_IMPORT
+#endif
diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp
index 79c8fb29..3d956970 100644
--- a/gui/keyboard.cpp
+++ b/gui/keyboard.cpp
@@ -2,7 +2,7 @@
#include <QDebug>
-KeyboardListener::KeyboardListener(QWidget* parent) :
+keyboard_listener::keyboard_listener(QWidget* parent) :
QDialog(parent)
#if defined _WIN32
, token([&](const Key& k) {
diff --git a/gui/keyboard.h b/gui/keyboard.h
index f4e5f7c0..9ca50df1 100644
--- a/gui/keyboard.h
+++ b/gui/keyboard.h
@@ -1,5 +1,7 @@
#pragma once
+#include "export.hpp"
+
#ifdef _WIN32
# include "logic/win32-shortcuts.h"
# include "dinput/keybinding-worker.hpp"
@@ -10,7 +12,7 @@
#include <QDialog>
#include <QKeyEvent>
-class KeyboardListener : public QDialog
+class OTR_GUI_EXPORT keyboard_listener : public QDialog
{
Q_OBJECT
Ui_keyboard_listener ui;
@@ -18,7 +20,7 @@ class KeyboardListener : public QDialog
KeybindingWorker::Token token;
#endif
public:
- KeyboardListener(QWidget* parent = nullptr);
+ keyboard_listener(QWidget* parent = nullptr);
#ifndef _WIN32
void keyPressEvent(QKeyEvent* event) override;
#endif
diff --git a/gui/main-window.cpp b/gui/main-window.cpp
index 34846131..1f84ea71 100644
--- a/gui/main-window.cpp
+++ b/gui/main-window.cpp
@@ -59,7 +59,7 @@ void MainWindow::annoy_if_root()
}
#endif
-MainWindow::MainWindow() :
+main_window::main_window() :
State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH),
pose_update_timer(this),
kbd_quit(QKeySequence("Ctrl+Q"), this),
@@ -162,28 +162,28 @@ MainWindow::MainWindow() :
this,
[&](const QString&) { if (pFilterDialog) pFilterDialog = nullptr; });
- connect(&m.tracker_dll, base_value::value_changed<QString>(), this, &MainWindow::save_modules, Qt::QueuedConnection);
- connect(&m.protocol_dll, base_value::value_changed<QString>(), this, &MainWindow::save_modules, Qt::QueuedConnection);
- connect(&m.filter_dll, base_value::value_changed<QString>(), this, &MainWindow::save_modules, Qt::QueuedConnection);
+ connect(&m.tracker_dll, base_value::value_changed<QString>(), this, &main_window::save_modules, Qt::QueuedConnection);
+ connect(&m.protocol_dll, base_value::value_changed<QString>(), this, &main_window::save_modules, Qt::QueuedConnection);
+ connect(&m.filter_dll, base_value::value_changed<QString>(), this, &main_window::save_modules, Qt::QueuedConnection);
tie_setting(m.tracker_dll, ui.iconcomboTrackerSource);
tie_setting(m.protocol_dll, ui.iconcomboProtocol);
tie_setting(m.filter_dll, ui.iconcomboFilter);
}
- connect(this, &MainWindow::start_tracker,
+ connect(this, &main_window::start_tracker,
this, [&]() { qDebug() << "start tracker"; start_tracker_(); },
Qt::QueuedConnection);
- connect(this, &MainWindow::stop_tracker,
+ connect(this, &main_window::stop_tracker,
this, [&]() { qDebug() << "stop tracker"; stop_tracker_(); },
Qt::QueuedConnection);
- connect(this, &MainWindow::toggle_tracker,
+ connect(this, &main_window::toggle_tracker,
this, [&]() { qDebug() << "toggle tracker"; if (work) stop_tracker_(); else start_tracker_(); },
Qt::QueuedConnection);
- connect(this, &MainWindow::restart_tracker,
+ connect(this, &main_window::restart_tracker,
this, [&]() { qDebug() << "restart tracker"; stop_tracker_(); start_tracker_(); },
Qt::QueuedConnection);
@@ -204,7 +204,7 @@ MainWindow::MainWindow() :
kbd_quit.setEnabled(true);
}
-void MainWindow::init_tray_menu()
+void main_window::init_tray_menu()
{
tray_menu.clear();
@@ -231,39 +231,39 @@ void MainWindow::init_tray_menu()
menu_action_tracker.setText(tr("Tracker settings"));
menu_action_tracker.setIcon(QIcon(":/images/tools.png"));
- QObject::connect(&menu_action_tracker, &QAction::triggered, this, &MainWindow::show_tracker_settings);
+ QObject::connect(&menu_action_tracker, &QAction::triggered, this, &main_window::show_tracker_settings);
tray_menu.addAction(&menu_action_tracker);
menu_action_filter.setText(tr("Filter settings"));
menu_action_filter.setIcon(QIcon(":/images/filter-16.png"));
- QObject::connect(&menu_action_filter, &QAction::triggered, this, &MainWindow::show_filter_settings);
+ QObject::connect(&menu_action_filter, &QAction::triggered, this, &main_window::show_filter_settings);
tray_menu.addAction(&menu_action_filter);
menu_action_proto.setText(tr("Protocol settings"));
menu_action_proto.setIcon(QIcon(":/images/settings16.png"));
- QObject::connect(&menu_action_proto, &QAction::triggered, this, &MainWindow::show_proto_settings);
+ QObject::connect(&menu_action_proto, &QAction::triggered, this, &main_window::show_proto_settings);
tray_menu.addAction(&menu_action_proto);
tray_menu.addSeparator();
menu_action_mappings.setIcon(QIcon(":/images/curves.png"));
menu_action_mappings.setText(tr("Mappings"));
- QObject::connect(&menu_action_mappings, &QAction::triggered, this, &MainWindow::show_mapping_window);
+ QObject::connect(&menu_action_mappings, &QAction::triggered, this, &main_window::show_mapping_window);
tray_menu.addAction(&menu_action_mappings);
menu_action_options.setIcon(QIcon(":/images/tools.png"));
menu_action_options.setText(tr("Options"));
- QObject::connect(&menu_action_options, &QAction::triggered, this, &MainWindow::show_options_dialog);
+ QObject::connect(&menu_action_options, &QAction::triggered, this, &main_window::show_options_dialog);
tray_menu.addAction(&menu_action_options);
tray_menu.addSeparator();
menu_action_exit.setText(tr("Exit"));
- QObject::connect(&menu_action_exit, &QAction::triggered, this, &MainWindow::exit);
+ QObject::connect(&menu_action_exit, &QAction::triggered, this, &main_window::exit);
tray_menu.addAction(&menu_action_exit);
}
-void MainWindow::register_shortcuts()
+void main_window::register_shortcuts()
{
using t_key = Shortcuts::t_key;
using t_keys = Shortcuts::t_keys;
@@ -289,7 +289,7 @@ void MainWindow::register_shortcuts()
work->reload_shortcuts();
}
-void MainWindow::die_on_config_not_writable()
+void main_window::die_on_config_not_writable()
{
stop_tracker_();
@@ -312,7 +312,7 @@ void MainWindow::die_on_config_not_writable()
close();
}
-bool MainWindow::maybe_die_on_config_not_writable(const QString& current, QStringList* ini_list_)
+bool main_window::maybe_die_on_config_not_writable(const QString& current, QStringList* ini_list_)
{
const bool writable =
group::with_settings_object([&](QSettings& s) {
@@ -337,14 +337,14 @@ bool MainWindow::maybe_die_on_config_not_writable(const QString& current, QStrin
return false;
}
-bool MainWindow::get_new_config_name_from_dialog(QString& ret)
+bool main_window::get_new_config_name_from_dialog(QString& ret)
{
new_file_dialog dlg;
dlg.exec();
return dlg.is_ok(ret);
}
-MainWindow::~MainWindow()
+main_window::~main_window()
{
if (tray)
tray->hide();
@@ -361,18 +361,18 @@ MainWindow::~MainWindow()
}
}
-void MainWindow::set_working_directory()
+void main_window::set_working_directory()
{
QDir::setCurrent(OPENTRACK_BASE_PATH);
}
-void MainWindow::save_modules()
+void main_window::save_modules()
{
qDebug() << "save modules";
m.b->save();
}
-void MainWindow::make_empty_config()
+void main_window::make_empty_config()
{
QString name;
if (get_new_config_name_from_dialog(name))
@@ -393,7 +393,7 @@ void MainWindow::make_empty_config()
}
}
-void MainWindow::make_copied_config()
+void main_window::make_copied_config()
{
const QString cur = group::ini_pathname();
QString name;
@@ -418,12 +418,12 @@ void MainWindow::make_copied_config()
}
-void MainWindow::open_config_directory()
+void main_window::open_config_directory()
{
QDesktopServices::openUrl("file:///" + QDir::toNativeSeparators(group::ini_directory()));
}
-bool MainWindow::refresh_config_list()
+bool main_window::refresh_config_list()
{
if (work)
return true;
@@ -472,7 +472,7 @@ bool MainWindow::refresh_config_list()
return true;
}
-void MainWindow::update_button_state(bool running, bool inertialp)
+void main_window::update_button_state(bool running, bool inertialp)
{
bool not_running = !running;
ui.iconcomboProfile->setEnabled(not_running);
@@ -492,7 +492,7 @@ void MainWindow::update_button_state(bool running, bool inertialp)
}
}
-void MainWindow::start_tracker_()
+void main_window::start_tracker_()
{
if (work)
return;
@@ -529,7 +529,7 @@ void MainWindow::start_tracker_()
ui.btnStopTracker->setFocus();
}
-void MainWindow::stop_tracker_()
+void main_window::stop_tracker_()
{
if (!work)
return;
@@ -560,7 +560,7 @@ void MainWindow::stop_tracker_()
ui.btnStartTracker->setFocus();
}
-void MainWindow::display_pose(const double *mapped, const double *raw)
+void main_window::display_pose(const double *mapped, const double *raw)
{
ui.pose_display->rotate_async(mapped[Yaw], mapped[Pitch], -mapped[Roll],
mapped[TX], mapped[TY], mapped[TZ]);
@@ -587,7 +587,7 @@ void MainWindow::display_pose(const double *mapped, const double *raw)
set_title(game_title);
}
-void MainWindow::set_title(const QString& game_title_)
+void main_window::set_title(const QString& game_title_)
{
QString game_title;
if (game_title_ != "")
@@ -598,7 +598,7 @@ void MainWindow::set_title(const QString& game_title_)
setWindowTitle(version + tr(" :: ") + current + game_title);
}
-void MainWindow::show_pose()
+void main_window::show_pose()
{
set_is_visible(*this);
@@ -616,7 +616,7 @@ void MainWindow::show_pose()
}
template<typename t, typename F>
-bool MainWindow::mk_window_common(std::unique_ptr<t>& d, F&& ctor)
+bool main_window::mk_window_common(std::unique_ptr<t>& d, F&& ctor)
{
if (d)
{
@@ -644,13 +644,13 @@ bool MainWindow::mk_window_common(std::unique_ptr<t>& d, F&& ctor)
}
template<typename t, typename... Args>
-inline bool MainWindow::mk_window(std::unique_ptr<t>& place, Args&&... params)
+inline bool main_window::mk_window(std::unique_ptr<t>& place, Args&&... params)
{
return mk_window_common(place, [&]() { return new t(std::forward<Args>(params)...); });
}
template<typename t>
-bool MainWindow::mk_dialog(std::shared_ptr<dylib> lib, std::unique_ptr<t>& d)
+bool main_window::mk_dialog(std::shared_ptr<dylib> lib, std::unique_ptr<t>& d)
{
const bool just_created = mk_window_common(d, [&]() -> t* {
if (lib && lib->Dialog)
@@ -661,7 +661,7 @@ bool MainWindow::mk_dialog(std::shared_ptr<dylib> lib, std::unique_ptr<t>& d)
return just_created;
}
-void MainWindow::show_tracker_settings()
+void main_window::show_tracker_settings()
{
if (mk_dialog(current_tracker(), pTrackerDialog) && work && work->libs.pTracker)
pTrackerDialog->register_tracker(work->libs.pTracker.get());
@@ -670,7 +670,7 @@ void MainWindow::show_tracker_settings()
QObject::connect(pTrackerDialog.get(), &ITrackerDialog::closing, this, [this]() { pTrackerDialog = nullptr; });
}
-void MainWindow::show_proto_settings()
+void main_window::show_proto_settings()
{
if (mk_dialog(current_protocol(), pProtocolDialog) && work && work->libs.pProtocol)
pProtocolDialog->register_protocol(work->libs.pProtocol.get());
@@ -679,7 +679,7 @@ void MainWindow::show_proto_settings()
QObject::connect(pProtocolDialog.get(), &IProtocolDialog::closing, this, [this]() { pProtocolDialog = nullptr; });
}
-void MainWindow::show_filter_settings()
+void main_window::show_filter_settings()
{
if (mk_dialog(current_filter(), pFilterDialog) && work && work->libs.pFilter)
pFilterDialog->register_filter(work->libs.pFilter.get());
@@ -688,25 +688,25 @@ void MainWindow::show_filter_settings()
QObject::connect(pFilterDialog.get(), &IFilterDialog::closing, this, [this]() { pFilterDialog = nullptr; });
}
-void MainWindow::show_options_dialog()
+void main_window::show_options_dialog()
{
if (mk_window(options_widget, [&](bool flag) { set_keys_enabled(!flag); }))
{
- connect(options_widget.get(), &OptionsDialog::closing, this, &MainWindow::register_shortcuts);
+ connect(options_widget.get(), &options_dialog::closing, this, &main_window::register_shortcuts);
}
}
-void MainWindow::show_mapping_window()
+void main_window::show_mapping_window()
{
mk_window(mapping_widget, pose);
}
-void MainWindow::exit()
+void main_window::exit()
{
QCoreApplication::exit(0);
}
-bool MainWindow::set_profile(const QString& new_name_)
+bool main_window::set_profile(const QString& new_name_)
{
if (!refresh_config_list())
return false;
@@ -732,7 +732,7 @@ bool MainWindow::set_profile(const QString& new_name_)
return true;
}
-void MainWindow::ensure_tray()
+void main_window::ensure_tray()
{
if (!QSystemTrayIcon::isSystemTrayAvailable())
return;
@@ -749,7 +749,7 @@ void MainWindow::ensure_tray()
connect(tray.get(),
&QSystemTrayIcon::activated,
this,
- &MainWindow::toggle_restore_from_tray);
+ &main_window::toggle_restore_from_tray);
}
}
else
@@ -771,7 +771,7 @@ void MainWindow::ensure_tray()
}
}
-void MainWindow::toggle_restore_from_tray(QSystemTrayIcon::ActivationReason e)
+void main_window::toggle_restore_from_tray(QSystemTrayIcon::ActivationReason e)
{
if (progn(
switch (e)
@@ -818,7 +818,7 @@ void MainWindow::toggle_restore_from_tray(QSystemTrayIcon::ActivationReason e)
}
}
-bool MainWindow::maybe_hide_to_tray(QEvent* e)
+bool main_window::maybe_hide_to_tray(QEvent* e)
{
if (e->type() == QEvent::WindowStateChange &&
(windowState() & Qt::WindowMinimized) &&
@@ -834,7 +834,7 @@ bool MainWindow::maybe_hide_to_tray(QEvent* e)
return false;
}
-void MainWindow::maybe_start_profile_from_executable()
+void main_window::maybe_start_profile_from_executable()
{
if (!work)
{
@@ -852,7 +852,7 @@ void MainWindow::maybe_start_profile_from_executable()
}
}
-void MainWindow::set_keys_enabled(bool flag)
+void main_window::set_keys_enabled(bool flag)
{
if (!flag)
{
@@ -866,7 +866,7 @@ void MainWindow::set_keys_enabled(bool flag)
}
}
-bool MainWindow::is_config_listed(const QString& name)
+bool main_window::is_config_listed(const QString& name)
{
const int sz = ui.iconcomboProfile->count();
for (int i = 0; i < sz; i++)
@@ -875,7 +875,7 @@ bool MainWindow::is_config_listed(const QString& name)
return false;
}
-void MainWindow::changeEvent(QEvent* e)
+void main_window::changeEvent(QEvent* e)
{
if (maybe_hide_to_tray(e))
e->accept();
@@ -885,12 +885,12 @@ void MainWindow::changeEvent(QEvent* e)
}
}
-void MainWindow::closeEvent(QCloseEvent*)
+void main_window::closeEvent(QCloseEvent*)
{
exit();
}
-bool MainWindow::event(QEvent* event)
+bool main_window::event(QEvent* event)
{
using t = QEvent::Type;
@@ -912,17 +912,17 @@ bool MainWindow::event(QEvent* event)
return QMainWindow::event(event);
}
-bool MainWindow::is_tray_enabled()
+bool main_window::is_tray_enabled()
{
return s.tray_enabled && QSystemTrayIcon::isSystemTrayAvailable();
}
-bool MainWindow::start_in_tray()
+bool main_window::start_in_tray()
{
return s.tray_enabled && s.tray_start && QSystemTrayIcon::isSystemTrayAvailable();
}
-void MainWindow::set_profile_in_registry(const QString &profile)
+void main_window::set_profile_in_registry(const QString &profile)
{
group::with_global_settings_object([&](QSettings& s) {
s.setValue(OPENTRACK_CONFIG_FILENAME_KEY, profile);
diff --git a/gui/main-window.hpp b/gui/main-window.hpp
index 8b0144b8..253c1194 100644
--- a/gui/main-window.hpp
+++ b/gui/main-window.hpp
@@ -8,6 +8,8 @@
#pragma once
+#include "export.hpp"
+
#include "api/plugin-support.hpp"
#include "mapping-dialog.hpp"
#include "settings.hpp"
@@ -37,11 +39,11 @@
#include <tuple>
#include <memory>
-#include "ui_main-window.h"
+#include "gui/ui_main-window.h"
using namespace options;
-class MainWindow : public QMainWindow, private State
+class OTR_GUI_EXPORT main_window : public QMainWindow, private State
{
Q_OBJECT
@@ -54,8 +56,8 @@ class MainWindow : public QMainWindow, private State
QTimer pose_update_timer;
QTimer det_timer;
QTimer config_list_timer;
- std::unique_ptr<OptionsDialog> options_widget;
- std::unique_ptr<MapWidget> mapping_widget;
+ std::unique_ptr<options_dialog> options_widget;
+ std::unique_ptr<mapping_dialog> mapping_widget;
QShortcut kbd_quit;
std::unique_ptr<IFilterDialog> pFilterDialog;
std::unique_ptr<IProtocolDialog> pProtocolDialog;
@@ -143,8 +145,8 @@ signals:
void toggle_tracker();
void restart_tracker();
public:
- MainWindow();
- ~MainWindow();
+ main_window();
+ ~main_window();
static void set_working_directory();
bool maybe_die_on_config_not_writable(const QString& current, QStringList* ini_list);
void die_on_config_not_writable();
diff --git a/gui/main.cpp b/gui/main.cpp
deleted file mode 100644
index d07e0d27..00000000
--- a/gui/main.cpp
+++ /dev/null
@@ -1,255 +0,0 @@
-#ifdef _WIN32
-# include <cstdio>
-# include <stdlib.h>
-# include <vector>
-# include <QCoreApplication>
-# include <QFile>
-# include <QString>
-# include <QSysInfo>
-# include <QtGlobal>
-#endif
-
-#include "migration/migration.hpp"
-#include "main-window.hpp"
-#include "options/options.hpp"
-using namespace options;
-#include "opentrack-library-path.h"
-#include <QApplication>
-#include <QCommandLineParser>
-#include <QStyleFactory>
-#include <QStringList>
-#include <QLocale>
-#include <QTranslator>
-#include <QDebug>
-#include <memory>
-#include <cstring>
-
-#if /* denormal control */ \
- /* GNU */ defined __x86_64__ || defined __SSE2__ || \
- /* MSVC */ defined _M_AMD64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
-# include <xmmintrin.h>
-# include <pmmintrin.h>
-# include <float.h>
-
-#define OTR_HAS_DENORM_CONTROL
-void set_fp_mask()
-{
- unsigned old_mask = _mm_getcsr();
- (void) old_mask;
-
- _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
- _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
- _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST);
- _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK);
-
-#if 0
- unsigned new_mask = _mm_getcsr();
-
- qDebug() << "old" << (void*) old_mask << "new" << (void*) new_mask;
-#endif
-}
-#endif
-
-void set_qt_style()
-{
-#if defined _WIN32
- if (QSysInfo::WindowsVersion == QSysInfo::WV_XP)
- return;
-#endif
-
-#if defined(_WIN32) || defined(__APPLE__)
- // our layouts on OSX make some control wrongly sized -sh 20160908
- {
- const QStringList preferred { "fusion", "windowsvista", "macintosh" };
- for (const auto& style_name : preferred)
- {
- QStyle* s = QStyleFactory::create(style_name);
- if (s)
- {
- QApplication::setStyle(s);
- break;
- }
- }
- }
-#endif
-}
-
-#ifdef _WIN32
-
-void qdebug_to_console(QtMsgType, const QMessageLogContext& ctx, const QString &msg)
-{
- const unsigned short* const str_ = msg.utf16();
- auto str = reinterpret_cast<const wchar_t* const>(str_);
- static_assert(sizeof(*str_) == sizeof(*str), "");
-
- std::fflush(stderr);
- if (ctx.function)
- std::fprintf(stderr, "[%s]: %ls\n", ctx.function, str);
- else if (ctx.file)
- std::fprintf(stderr, "[%s:%d]: %ls\n", ctx.file, ctx.line, str);
- else
- std::fprintf(stderr, "%ls\n", str);
- std::fflush(stderr);
-}
-
-void attach_parent_console()
-{
- if (AttachConsole(ATTACH_PARENT_PROCESS))
- {
- // XXX c++ iostreams aren't reopened
-
- _wfreopen(L"CON", L"w", stdout);
- _wfreopen(L"CON", L"w", stderr);
- _wfreopen(L"CON", L"r", stdin);
- qInstallMessageHandler(qdebug_to_console);
- }
-}
-
-void add_win32_path()
-{
- // see https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable
- static char env_path[4096] { '\0', };
- {
- QString lib_path = OPENTRACK_BASE_PATH;
- lib_path.replace("/", "\\");
- const QByteArray lib_path_ = QFile::encodeName(lib_path);
-
- QString mod_path = OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH;
- mod_path.replace("/", "\\");
- const QByteArray mod_path_ = QFile::encodeName(mod_path);
-
- std::vector<const char*> contents
- {
- "PATH=",
- lib_path_.constData(),
- ";",
- mod_path_.constData(),
- ";",
- getenv("PATH"),
- };
-
- bool ok = true;
-
- for (const char* ptr : contents)
- {
- if (ptr)
- strcat_s(env_path, sizeof(env_path), ptr);
-
- if (!ptr || ptr[0] == '\0' || env_path[0] == '\0')
- {
- qDebug() << "bad path element"
- << (ptr == nullptr ? "<null>" : ptr);
- ok = false;
- break;
- }
- }
-
- if (ok)
- {
- const int error = _putenv(env_path);
-
- if (error)
- qDebug() << "can't _putenv win32 path";
- }
- else
- qDebug() << "can't set win32 path";
- }
-}
-
-#endif
-
-int
-#ifdef _MSC_VER
-WINAPI
-#endif
-main(int argc, char** argv)
-{
-#ifdef _WIN32
- attach_parent_console();
-#endif
-
-#if defined OTR_HAS_DENORM_CONTROL
- set_fp_mask();
-#endif
-
-#if QT_VERSION >= 0x050600 // flag introduced in QT 5.6. It is non-essential so might as well allow compilation on older systems.
- QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
-#endif
- QApplication::setAttribute(Qt::AA_X11InitThreads, true);
-
- QApplication app(argc, argv);
-
-#ifdef _WIN32
- add_win32_path();
-#endif
-
- MainWindow::set_working_directory();
-
-#if !defined(__linux) && !defined _WIN32
- // workaround QTBUG-38598
- QCoreApplication::addLibraryPath(".");
-#endif
-
- set_qt_style();
- QTranslator t;
-
- // QLocale::setDefault(QLocale("ru_RU")); // force i18n for testing
-
- if (group::with_global_settings_object([&](QSettings& s) {
- return !s.value("disable-translation", false).toBool();
- }))
- {
- (void) t.load(QLocale(), "", "", OPENTRACK_BASE_PATH + "/" OPENTRACK_I18N_PATH, ".qm");
- (void) QCoreApplication::installTranslator(&t);
- }
-
- do
- {
- std::shared_ptr<MainWindow> w = std::make_shared<MainWindow>();
-
- if (!w->isEnabled())
- break;
-
- if (!w->start_in_tray())
- {
- w->setVisible(true);
- w->show();
- w->adjustSize();
- w->setFixedSize(w->size());
- }
- else
- w->setVisible(false);
-
- app.setQuitOnLastWindowClosed(false);
- app.exec();
-
- app.exit(0);
-
- qDebug() << "exit: window";
- }
- while (false);
-
- // msvc crashes in Qt plugin system's dtor
- // Note: QLibrary::PreventUnloadHint seems to workaround it
-#if defined(_MSC_VER) && 0
- qDebug() << "exit: terminating";
- TerminateProcess(GetCurrentProcess(), 0);
-#endif
-
- qDebug() << "exit: main()";
-
- return 0;
-}
-
-#if defined(Q_CREATOR_RUN)
-# pragma clang diagnostic ignored "-Wmain"
-#endif
-
-#ifdef _MSC_VER
-int WINAPI
-WinMain (struct HINSTANCE__*, struct HINSTANCE__*, char*, int)
-{
- return main (__argc, __argv);
-}
-
-#endif
diff --git a/gui/mapping-dialog.cpp b/gui/mapping-dialog.cpp
index fbe274e0..5f884607 100644
--- a/gui/mapping-dialog.cpp
+++ b/gui/mapping-dialog.cpp
@@ -10,7 +10,7 @@
#include "logic/main-settings.hpp"
#include "spline/spline-widget.hpp"
-MapWidget::MapWidget(Mappings& m) : m(m), widgets{}
+mapping_dialog::mapping_dialog(Mappings& m) : m(m), widgets{}
{
ui.setupUi(this);
@@ -66,7 +66,7 @@ MapWidget::MapWidget(Mappings& m) : m(m), widgets{}
tie_setting(s.a_pitch.clamp_y_, ui.max_pitch_output);
}
-void MapWidget::load()
+void mapping_dialog::load()
{
struct {
spline_widget* qfc;
@@ -145,12 +145,12 @@ void MapWidget::load()
}
}
-void MapWidget::closeEvent(QCloseEvent*)
+void mapping_dialog::closeEvent(QCloseEvent*)
{
invalidate_dialog();
}
-void MapWidget::refresh_tab()
+void mapping_dialog::refresh_tab()
{
if (!isVisible())
return;
@@ -166,7 +166,7 @@ void MapWidget::refresh_tab()
qDebug() << "map-widget: bad index" << idx;
}
-void MapWidget::save_dialog()
+void mapping_dialog::save_dialog()
{
s.b_map->save();
@@ -181,7 +181,7 @@ void MapWidget::save_dialog()
}
}
-void MapWidget::invalidate_dialog()
+void mapping_dialog::invalidate_dialog()
{
s.b_map->reload();
@@ -193,13 +193,13 @@ void MapWidget::invalidate_dialog()
});
}
-void MapWidget::doOK()
+void mapping_dialog::doOK()
{
save_dialog();
close();
}
-void MapWidget::doCancel()
+void mapping_dialog::doCancel()
{
invalidate_dialog();
close();
diff --git a/gui/mapping-dialog.hpp b/gui/mapping-dialog.hpp
index ba5d1867..5ab8a066 100644
--- a/gui/mapping-dialog.hpp
+++ b/gui/mapping-dialog.hpp
@@ -1,7 +1,9 @@
#pragma once
+#include "export.hpp"
+
#include "logic/mappings.hpp"
-#include "ui_mapping-dialog.h"
+#include "gui/ui_mapping-dialog.h"
#include <QWidget>
#include <QDialog>
@@ -9,14 +11,14 @@
#include <QCloseEvent>
#include <QCheckBox>
-class MapWidget final : public QDialog
+class OTR_GUI_EXPORT mapping_dialog final : public QDialog
{
Q_OBJECT
public:
- MapWidget(Mappings& m);
+ mapping_dialog(Mappings& m);
void refresh_tab();
private:
- Ui::mapping_window ui;
+ Ui::mapping_dialog ui;
Mappings& m;
main_settings s;
diff --git a/gui/mapping-dialog.ui b/gui/mapping-dialog.ui
index 7db6f425..58b8ad1f 100644
--- a/gui/mapping-dialog.ui
+++ b/gui/mapping-dialog.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>mapping_window</class>
- <widget class="QWidget" name="mapping_window">
+ <class>mapping_dialog</class>
+ <widget class="QWidget" name="mapping_dialog">
<property name="geometry">
<rect>
<x>0</x>
diff --git a/gui/process_detector.cpp b/gui/process_detector.cpp
index 806f0b47..e9f58aad 100644
--- a/gui/process_detector.cpp
+++ b/gui/process_detector.cpp
@@ -20,35 +20,35 @@
static constexpr inline auto RECORD_SEPARATOR = QChar(char(0x1e)); // RS ^]
static constexpr inline auto UNIT_SEPARATOR = QChar(char(0x1f)); // US ^_
-void settings::set_game_list(const QString &game_list)
+void proc_detector_settings::set_game_list(const QString &game_list)
{
group::with_global_settings_object([&](QSettings& settings) {
settings.setValue("executable-list", game_list);
});
}
-QString settings::get_game_list()
+QString proc_detector_settings::get_game_list()
{
return group::with_global_settings_object([&](QSettings& settings) {
return settings.value("executable-list").toString();
});
}
-bool settings::is_enabled()
+bool proc_detector_settings::is_enabled()
{
return group::with_global_settings_object([&](QSettings& settings) {
return settings.value("executable-detector-enabled", false).toBool();
});
}
-void settings::set_is_enabled(bool enabled)
+void proc_detector_settings::set_is_enabled(bool enabled)
{
group::with_global_settings_object([&](QSettings& settings) {
settings.setValue("executable-detector-enabled", enabled);
});
}
-QHash<QString, QString> settings::split_process_names()
+QHash<QString, QString> proc_detector_settings::split_process_names()
{
QHash<QString, QString> ret;
QString str = get_game_list();
@@ -79,7 +79,7 @@ void BrowseButton::browse()
tr("Set executable name"),
dir_path,
tr("Executable (*.exe);;All Files (*)"));
- MainWindow::set_working_directory();
+ main_window::set_working_directory();
filename = QFileInfo(filename).fileName();
if (!filename.isNull())
twi->setText(filename);
@@ -132,7 +132,7 @@ process_detector::process_detector(QWidget* parent) : QWidget(parent)
QResizeEvent e(ui.tableWidget->size(), ui.tableWidget->size());
ui.tableWidget->resizeEvent(&e);
- settings s;
+ proc_detector_settings s;
ui.enabled->setChecked(s.is_enabled());
}
@@ -173,7 +173,7 @@ bool process_detector_worker::should_stop()
if (last_exe_name == "")
return false;
- settings s;
+ proc_detector_settings s;
if (!s.is_enabled())
{
@@ -193,7 +193,7 @@ bool process_detector_worker::should_stop()
bool process_detector_worker::config_to_start(QString& str)
{
- settings s;
+ proc_detector_settings s;
if (!s.is_enabled())
{
last_exe_name = "";
diff --git a/gui/process_detector.h b/gui/process_detector.h
index 475ebde0..16d50e42 100644
--- a/gui/process_detector.h
+++ b/gui/process_detector.h
@@ -8,6 +8,8 @@
#pragma once
+#include "export.hpp"
+
#include <QObject>
#include <QWidget>
#include <QTableWidget>
@@ -17,7 +19,7 @@
#include "process-detector-fancy-table.hpp"
#include "options/options.hpp"
-struct settings
+struct OTR_GUI_EXPORT proc_detector_settings
{
QHash<QString, QString> split_process_names();
QString get_game_list();
@@ -26,12 +28,12 @@ struct settings
void set_is_enabled(bool enabled);
};
-class process_detector final : public QWidget
+class OTR_GUI_EXPORT process_detector final : public QWidget
{
Q_OBJECT
Ui_process_detector ui;
- settings s;
+ proc_detector_settings s;
int add_row(QString exe_name = "...", QString profile = "");
void add_items();
@@ -56,10 +58,10 @@ public slots:
void browse();
};
-class process_detector_worker : QObject
+class OTR_GUI_EXPORT process_detector_worker : QObject
{
Q_OBJECT
- settings s;
+ proc_detector_settings s;
QString last_exe_name;
public:
bool config_to_start(QString& s);
diff --git a/gui/settings.cpp b/gui/settings.cpp
index 3b14dec7..b6d4255e 100644
--- a/gui/settings.cpp
+++ b/gui/settings.cpp
@@ -14,7 +14,7 @@
#include <QDialog>
#include <QFileDialog>
-QString OptionsDialog::kopts_to_string(const key_opts& kopts)
+QString options_dialog::kopts_to_string(const key_opts& kopts)
{
if (static_cast<QString>(kopts.guid) != "")
{
@@ -31,7 +31,7 @@ QString OptionsDialog::kopts_to_string(const key_opts& kopts)
return kopts.keycode;
}
-void OptionsDialog::set_disable_translation_state(bool value)
+void options_dialog::set_disable_translation_state(bool value)
{
group::with_global_settings_object([&](QSettings& s)
{
@@ -39,7 +39,7 @@ void OptionsDialog::set_disable_translation_state(bool value)
});
}
-OptionsDialog::OptionsDialog(std::function<void(bool)> pause_keybindings) :
+options_dialog::options_dialog(std::function<void(bool)> pause_keybindings) :
pause_keybindings(pause_keybindings)
{
ui.setupUi(this);
@@ -145,22 +145,22 @@ OptionsDialog::OptionsDialog(std::function<void(bool)> pause_keybindings) :
}
}
-void OptionsDialog::closeEvent(QCloseEvent *)
+void options_dialog::closeEvent(QCloseEvent *)
{
done(result());
}
-void OptionsDialog::bind_key(key_opts& kopts, QLabel* label)
+void options_dialog::bind_key(key_opts& kopts, QLabel* label)
{
kopts.button = -1;
kopts.guid = "";
kopts.keycode = "";
- auto k = new KeyboardListener;
+ auto k = new keyboard_listener;
k->setWindowModality(Qt::ApplicationModal);
k->deleteLater();
connect(k,
- &KeyboardListener::key_pressed,
+ &keyboard_listener::key_pressed,
this,
[&](const QKeySequence& s)
{
@@ -169,7 +169,7 @@ void OptionsDialog::bind_key(key_opts& kopts, QLabel* label)
kopts.button = -1;
k->close();
});
- connect(k, &KeyboardListener::joystick_button_pressed,
+ connect(k, &keyboard_listener::joystick_button_pressed,
this,
[&](const QString& guid, int idx, bool held)
{
@@ -202,7 +202,7 @@ void OptionsDialog::bind_key(key_opts& kopts, QLabel* label)
label->setText(kopts_to_string(kopts));
}
-void OptionsDialog::doOK()
+void options_dialog::doOK()
{
if (isHidden()) // close() can return true twice in a row it seems
return;
@@ -216,7 +216,7 @@ void OptionsDialog::doOK()
emit closing();
}
-void OptionsDialog::doCancel()
+void options_dialog::doCancel()
{
if (isHidden()) // close() can return true twice in a row it seems
return;
@@ -229,7 +229,7 @@ void OptionsDialog::doCancel()
emit closing();
}
-void OptionsDialog::done(int res)
+void options_dialog::done(int res)
{
if (isVisible())
{
diff --git a/gui/settings.hpp b/gui/settings.hpp
index 67c0ee54..63e109a4 100644
--- a/gui/settings.hpp
+++ b/gui/settings.hpp
@@ -1,19 +1,21 @@
#pragma once
-#include "ui_settings-dialog.h"
+#include "export.hpp"
+
+#include "gui/ui_settings-dialog.h"
#include "logic/shortcuts.h"
#include <QObject>
#include <QDialog>
#include <QWidget>
#include <functional>
-class OptionsDialog : public QDialog
+class OTR_GUI_EXPORT options_dialog : public QDialog
{
Q_OBJECT
signals:
void closing();
public:
- OptionsDialog(std::function<void(bool)> pause_keybindings);
+ options_dialog(std::function<void(bool)> pause_keybindings);
private:
main_settings main;
std::function<void(bool)> pause_keybindings;