]> git.sesse.net Git - pkanalytics/commitdiff
Support requesting a given match on command line (in lieu of an actual command-line...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 4 May 2023 20:42:10 +0000 (22:42 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 4 May 2023 20:42:10 +0000 (22:42 +0200)
main.cpp

index a20125a61edbb7770bbb9d8ff19b4c506931ec72..2a756495397f2df983e8f633db86a62782e53daa 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -457,10 +457,11 @@ sqlite3 *open_db(const char *filename)
        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;
@@ -475,6 +476,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;
@@ -490,6 +494,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());
@@ -547,7 +555,12 @@ int main(int argc, char *argv[])
        QApplication app(argc, argv);
        sqlite3 *db = open_db("ultimate.db");
 
-       int match_id = get_match_id(db, nullptr);
+       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;
        }