]> git.sesse.net Git - pkanalytics/blobdiff - main.cpp
Implement filter-by-player-on-field.
[pkanalytics] / main.cpp
index 907bc2fc2c81c1c462452686bcf914cff9ebe88f..4383f2e84958bc1dbfc06c6c72f58e9a959cba36 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -15,6 +15,7 @@
 #include "ui_mainwindow.h"
 #include "events.h"
 #include "players.h"
+#include "json.h"
 
 using namespace std;
 
@@ -74,6 +75,17 @@ MainWindow::MainWindow(EventsModel *events, PlayersModel *players) : events(even
        QShortcut *pgup = new QShortcut(QKeySequence(Qt::Key_PageUp), this);
        connect(pgup, &QShortcut::activated, [this]() { seek(120000); });
 
+       // Ugh. Used when Qt messes up and hangs the video.
+       QShortcut *f5 = new QShortcut(QKeySequence(Qt::Key_F5), this);
+       connect(f5, &QShortcut::activated, [this]() {
+               QVideoWidget *nvw = new QVideoWidget(ui->video->parentWidget());
+               nvw->setObjectName("video");
+               nvw->setMinimumSize(QSize(320, 240));
+               video->setVideoOutput(nvw);
+               ui->main_grid->replaceWidget(ui->video, nvw);
+               ui->video = nvw;
+       });
+
        connect(ui->minus10s, &QPushButton::clicked, [this]() { seek(-10000); });
        connect(ui->plus10s, &QPushButton::clicked, [this]() { seek(10000); });
 
@@ -453,13 +465,15 @@ sqlite3 *open_db(const char *filename)
 
        sqlite3_exec(db, "PRAGMA journal_mode=WAL", nullptr, nullptr, nullptr);  // Ignore errors.
        sqlite3_exec(db, "PRAGMA synchronous=NORMAL", nullptr, nullptr, nullptr);  // Ignore errors.
+       sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);  // Ignore errors.
        return db;
 }
 
-int get_match_id(sqlite3 *db, QWidget *parent)
+int get_match_id(sqlite3 *db, QWidget *parent, int requested_match)
 {
        QStringList items;
        vector<int> ids;
+       bool requested_match_ok = false;
 
        // Read the list of matches already in the database.
        sqlite3_stmt *stmt;
@@ -474,6 +488,9 @@ int get_match_id(sqlite3 *db, QWidget *parent)
                        char buf[256];
                        snprintf(buf, sizeof(buf), "%s (%d)", sqlite3_column_text(stmt, 1), sqlite3_column_int(stmt, 0));
                        ids.push_back(sqlite3_column_int(stmt, 0));
+                       if (ids.back() == requested_match) {
+                               requested_match_ok = true;
+                       }
                        items.push_back(buf);
                } else if (ret == SQLITE_DONE) {
                        break;
@@ -489,6 +506,10 @@ int get_match_id(sqlite3 *db, QWidget *parent)
        }
        items.push_back("Add new…");
 
+       if (requested_match_ok) {
+               return requested_match;
+       }
+
        QString chosen_str;
        {
                QInputDialog dialog(parent, Qt::WindowFlags());
@@ -546,7 +567,15 @@ int main(int argc, char *argv[])
        QApplication app(argc, argv);
        sqlite3 *db = open_db("ultimate.db");
 
-       int match_id = get_match_id(db, nullptr);
+       // TODO: do this on-demand instead, from a menu
+       export_to_json(db, "ultimate.json");
+
+       int requested_match = -1;
+       if (argc >= 2) {
+               requested_match = atoi(argv[1]);
+       }
+
+       int match_id = get_match_id(db, nullptr, requested_match);
        if (match_id <= 0) {  // Cancel.
                return 0;
        }