diff --git a/.neovim.lua b/.neovim.lua index f893c3b..80f34ef 100644 --- a/.neovim.lua +++ b/.neovim.lua @@ -22,6 +22,7 @@ vim.api.nvim_set_keymap('n', 'ΓΈ', ":lua require'dapui'.toggle()", { noremap -- https://sourceware.org/gdb/current/onlinedocs/gdb.html/Interpreters.html -- https://sourceware.org/gdb/current/onlinedocs/gdb.html/Debugger-Adapter-Protocol.html -- Require DAP and DAP-Python +-- Use qtcreator to debug c++ part local dap = require("dap") require("dap-python").setup("python") @@ -48,33 +49,6 @@ dap.configurations.python = { }, } --- C++ configuration with GDB -dap.adapters.gdb = { - type = "executable", - command = "gdb", -- Ensure GDB is installed and available in your PATH - args = { "-i", "dap" } -} - -dap.configurations.cpp = { - { - name = 'Launch executable (GDB)', - type = 'gdb', - request = 'launch', - program = '~/TombRaiderLinuxLauncher/TombRaiderLinuxLauncher', - stopOnEntry = false, -- or true if you want to stop at the beginning - cwd = '${workspaceFolder}', - setupCommands = { - { - text = '-enable-pretty-printing', -- Enable pretty-printing for gdb - description = 'enable pretty printing', - ignoreFailures = false - }, - }, - args = {}, -- Pass arguments to the executable - environment = {}, -- Set environment variables here - } -} - require("dapui").setup() local nvim_lsp = require('lspconfig') @@ -92,7 +66,6 @@ vim.api.nvim_create_autocmd("FileType", { end, }) - function ToggleShiftwidth() if vim.g.current_shiftwidth == 2 then vim.g.current_shiftwidth = 4 @@ -105,16 +78,14 @@ end -- The style is meant to keep the code narrow, never let it over 80-100 -- With cpplint --filter=-whitespace/braces,-whitespace/newline - require('lint').linters_by_ft = { sh = {'shellcheck'}, -- Ensure you have shellcheck installed python = {'pylint', 'bandit', 'ruff', 'pydocstyle', 'mypy', 'flake8'}, -- Ensure these are installed cmake = { 'cmakelint' }, cpp = {'cppcheck', 'cpplint', 'flawfinder'}, } --- add: --- --check-level=exhaustive +-- .local/share/nvim/plugged/nvim-lint/lua/lint/linters/cppcheck.lua -- cppcheck <= 1.84 doesn't support {column} so the start_col group is ambiguous local pattern = [[([^:]*):(%d*):([^:]*): %[([^%]\]*)%] ([^:]*): (.*)]] local groups = { "file", "lnum", "col", "code", "severity", "message" } @@ -150,8 +121,29 @@ return { "--template={file}:{line}:{column}: [{id}] {severity}: {message}", "--check-level=exhaustive", "--library=qt", + "--suppress=unmatchedSuppression", + "--suppress=unusedStructMember", }, stream = "stderr", parser = require("lint.parser").from_pattern(pattern, groups, severity_map, { ["source"] = "cppcheck" }), } +-- .local/share/nvim/plugged/nvim-lint/lua/lint/linters/cpplint.lua +-- path/to/file:line: message [code] [code_id] +local pattern = '([^:]+):(%d+): (.+) (.+)' +local groups = { 'file', 'lnum', 'message', 'code'} + +return { + cmd = 'cpplint', + stdin = false, + args = { + "--filter=-build/include_subdir", + }, + ignore_exitcode = true, + stream = 'stderr', + parser = require('lint.parser').from_pattern(pattern, groups, nil, { + ['source'] = 'cpplint', + ['severity'] = vim.diagnostic.severity.WARN, + }), +} + diff --git a/setup_nvim_lsp.sh b/setup_nvim_lsp.sh index 64b243d..24b7ba0 100755 --- a/setup_nvim_lsp.sh +++ b/setup_nvim_lsp.sh @@ -1,28 +1,6 @@ #!/bin/bash cd "$(dirname "$0")" || exit 1 # don't forget that you need to build it one time -# and look at .neovim how to use debuger -mkdir -p .gdb/qt5prettyprinters/ - -gdbinit=$(cat <<'EOINS' -python -import sys, os - -sys.path.insert(0, "./.gdb/qt5prettyprinters") - -from qt import register_qt_printers -register_qt_printers (None) - -end -EOINS -) -echo "$gdbinit" > .gdbinit -chmod 0644 .gdbinit - -wget -O .gdb/qt5prettyprinters/helper.py \ - https://invent.kde.org/kdevelop/kdevelop/-/raw/master/plugins/gdb/printers/helper.py -wget -O .gdb/qt5prettyprinters/qt.py \ - https://invent.kde.org/kdevelop/kdevelop/-/raw/master/plugins/gdb/printers/qt.py rm -fr build mkdir build diff --git a/src/Controller.cpp b/src/Controller.cpp index 60a9c79..44848b1 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -31,10 +31,12 @@ void Controller::initializeThread() { controllerThread->start(); // Using the controller thread to start model work + /* connect(this, &Controller::checkCommonFilesThreadSignal, this, [this]() { model.checkCommonFiles(); }); + */ connect(this, &Controller::setupThreadSignal, this, [this](const QString& level, const QString& game) { @@ -43,7 +45,7 @@ void Controller::initializeThread() { connect(this, &Controller::setupLevelThreadSignal, this, [this](int id) { - model.getGame(id); + model.getLevel(id); }); connect(this, &Controller::setupGameThreadSignal, @@ -67,14 +69,9 @@ void Controller::initializeThread() { emit controllerDownloadError(status); }, Qt::QueuedConnection); - connect(&model, &Model::askGameSignal, - this, [this](int id) { - emit controllerAskGame(id); - }, Qt::QueuedConnection); - connect(&model, &Model::generateListSignal, - this, [this]() { - emit controllerGenerateList(); + this, [this](const QList& availableGames) { + emit controllerGenerateList(availableGames); }, Qt::QueuedConnection); } @@ -94,7 +91,7 @@ void Controller::setupLevel(int id) { emit setupLevelThreadSignal(id); } -// GUI Threads +// Using the GUI Threads int Controller::checkGameDirectory(int id) { return model.checkGameDirectory(id); } diff --git a/src/Controller.hpp b/src/Controller.hpp index 6994405..52309b9 100644 --- a/src/Controller.hpp +++ b/src/Controller.hpp @@ -44,8 +44,7 @@ class Controller : public QObject { int getItemState(int id); signals: - void controllerAskGame(int id); - void controllerGenerateList(); + void controllerGenerateList(const QList& availableGames); void controllerTickSignal(); void controllerDownloadError(int status); diff --git a/src/FileManager.cpp b/src/FileManager.cpp index ee02853..05e6629 100644 --- a/src/FileManager.cpp +++ b/src/FileManager.cpp @@ -222,14 +222,14 @@ bool FileManager::linkGameDir(const QString& levelDir, const QString& gameDir) { test(levelPath); // here we just output the directory tree for now.. - if (QFile::link(levelPath, gamePath)) { + if (QFile::link(levelPath, gamePath) == true) { qDebug() << "Symbolic link created successfully."; - return 0; + status = true; } else { QFileInfo fileInfo(gamePath); if (fileInfo.isSymLink() == true) { QFile::remove(gamePath); - if (QFile::link(levelPath, gamePath)) { + if (QFile::link(levelPath, gamePath) == true) { qDebug() << "Symbolic link created successfully."; status = true; } else { @@ -256,14 +256,14 @@ bool FileManager::makeRelativeLink( const QString toPath = QString("%1%2") .arg(levelPath, to); - if (QFile::link(fromPath, toPath)) { + if (QFile::link(fromPath, toPath) == true) { qDebug() << "Symbolic link created successfully."; status = true; } else { QFileInfo i(toPath); - if (i.isSymLink()) { + if (i.isSymLink() == true) { QFile::remove(toPath); - if (QFile::link(fromPath, toPath)) { + if (QFile::link(fromPath, toPath) == true) { qDebug() << "Symbolic link created successfully."; status = true; } else { diff --git a/src/Model.cpp b/src/Model.cpp index 800ff5a..5ef0fc0 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -16,7 +16,7 @@ // Those lambda should be in another header file // I hate this and it should be able to recognize both the directory // when linking and the game exe to make a symbolic link to automatically -Model::Model(QObject *parent) : QObject(parent), checkCommonFilesIndex_m(1) { +Model::Model(QObject *parent) : QObject(parent) { instructionManager.addInstruction(4, [this](int id) { qDebug() << "Perform Operation A"; const QString s = "/"+QString::number(id) + ".TRLE"; @@ -32,54 +32,41 @@ Model::Model(QObject *parent) : QObject(parent), checkCommonFilesIndex_m(1) { const QString s = QString::number(id) + ".TRLE/TRBiohazard"; fileManager.moveFilesToParentDirectory(s, 1); }); - /* - instructionManager.addInstruction(12, [this](int id) { - qDebug() << "Perform Operation C"; - const QString s = QString::number(id) + ".TRLE/Delca-KittenAdventureDemo/Engine"; - fileManager.moveFilesToParentDirectory(s, 2); - }); - */ } Model::~Model() {} bool Model::setup(const QString& level, const QString& game) { bool status = false; - if (setDirectory(level, game)) { + if (setDirectory(level, game) == true) { status = true; - checkCommonFiles(); + emit generateListSignal(checkCommonFiles()); + QCoreApplication::processEvents(); } return status; } bool Model::setDirectory(const QString& level, const QString& game) { + bool status = false; if (fileManager.setUpCamp(level, game) && - downloader.setUpCamp(level) && - data.initializeDatabase(level) - ) - return true; - else - return false; + downloader.setUpCamp(level) && + data.initializeDatabase(level)) { + status = true; + } + return status; } -// true if there was new original game -// false if there was no new original games -bool Model::checkCommonFiles() { - int index = checkCommonFilesIndex_m; - assert(index >= 1 && index <= 5); - for (int i = index; i <= 5; i++) { - if (checkGameDirectory(i) == 2) { - // checkCommonFilesIndex_m this is becouse it should start here - // becouse we use a return, we should only use 1 return... - checkCommonFilesIndex_m = i+1; - emit askGameSignal(i); - QCoreApplication::processEvents(); - return true; +const QList& Model::checkCommonFiles() { + m_availableGames.clear(); + for (int i = 1; i <= 5; i++) { + int dirStatus = checkGameDirectory(i); + if (dirStatus == 1) { // symbolic link + m_availableGames.append(i); + } else if (dirStatus == 2) { // directory + m_availableGames.append(-i); } } - emit generateListSignal(); - QCoreApplication::processEvents(); - return false; + return m_availableGames; } QString Model::getGameDirectory(int id) { @@ -95,6 +82,8 @@ QString Model::getGameDirectory(int id) { return folder.TR4; case 5: return folder.TR5; + case 10: + return folder.TEN; default: qDebug() << "Id number:" << id << " is not a game."; return ""; @@ -102,10 +91,13 @@ QString Model::getGameDirectory(int id) { } int Model::checkGameDirectory(int id) { + int status = -1; const QString s = getGameDirectory(id); - if (s != "") - return fileManager.checkFileInfo(s, true); - return -1; + qDebug() << s; + if (s != "") { + status = fileManager.checkFileInfo(s, true); + } + return status; } void Model::getList(QVector* list) { @@ -113,21 +105,25 @@ void Model::getList(QVector* list) { } int Model::getItemState(int id) { + int status = 0; if (id < 0) { - return 1; + status = 1; } else if (id > 0) { - QString map(QString::number(id) + ".TRLE"); - if (fileManager.checkDir(map, false)) - return 2; - else - return 0; + QString dir(QString::number(id) + ".TRLE"); + if (fileManager.checkDir(dir, false)) { + status = 2; + } else { + status = 0; + } + } else { + status = -1; } - return -1; + return status; } bool Model::setLink(int id) { bool status = false; - if (id < 0) { + if (id < 0) { // we use original game id as negative number id = -id; const QString s = "/Original.TR" + QString::number(id); if (fileManager.checkDir(s, false )) @@ -171,14 +167,16 @@ void Model::setupGame(int id) { const QString src = levelPath.chopped(1); const QString des = gamePath.chopped(1); if (!fileManager.linkGameDir(src, des)) { - checkCommonFiles(); // TODO(noisecode3): Remove this - return; + qDebug() << "Faild to create the link to the new game directory"; } } - checkCommonFiles(); // TODO(noisecode3): Remove this + for (int i=0; i < 100; i++) { + emit this->modelTickSignal(); + QCoreApplication::processEvents(); + } } -bool Model::getGame(int id) { +bool Model::getLevel(int id) { assert(id > 0); if (id) { int status = 0; diff --git a/src/Model.hpp b/src/Model.hpp index 4f86861..c7a3e81 100644 --- a/src/Model.hpp +++ b/src/Model.hpp @@ -55,7 +55,7 @@ class Model : public QObject { static Model instance; return instance; } - bool checkCommonFiles(); + const QList& checkCommonFiles(); int checkGameDirectory(int id); int checkLevelDirectory(int id); void getList(QVector* list); @@ -63,19 +63,18 @@ class Model : public QObject { bool setLink(int id); QString getGameDirectory(int id); void setupGame(int id); - bool getGame(int id); + bool getLevel(int id); const InfoData getInfo(int id); const QString getWalkthrough(int id); bool setDirectory(const QString& level, const QString& game); bool setup(const QString& level, const QString& game); signals: - void askGameSignal(int); - void generateListSignal(); + void generateListSignal(QList availableGames); void modelTickSignal(); private: - int checkCommonFilesIndex_m = 1; + QList m_availableGames; Data& data = Data::getInstance(); FileManager& fileManager = FileManager::getInstance(); Downloader& downloader = Downloader::getInstance(); diff --git a/src/TombRaiderLinuxLauncher.cpp b/src/TombRaiderLinuxLauncher.cpp index 9a27f3f..c0ce8ae 100644 --- a/src/TombRaiderLinuxLauncher.cpp +++ b/src/TombRaiderLinuxLauncher.cpp @@ -15,6 +15,7 @@ #include "TombRaiderLinuxLauncher.hpp" #include "ui_TombRaiderLinuxLauncher.h" #include "staticData.hpp" +#include "debug.hpp" TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent) :QMainWindow(parent), @@ -40,17 +41,14 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent) this, SLOT(workTick())); // Thread work done signal connections - connect(&Controller::getInstance(), SIGNAL(controllerGenerateList()), - this, SLOT(generateList())); + connect(&Controller::getInstance(), + SIGNAL(controllerGenerateList(const QList&)), + this, SLOT(generateList(const QList&))); // Error signal connections connect(&Controller::getInstance(), SIGNAL(controllerDownloadError(int)), this, SLOT(downloadError(int))); - // Ask if a game should be moved and get a symbolic link - connect(&Controller::getInstance(), SIGNAL(controllerAskGame(int)), - this, SLOT(askGame(int))); - // Set init state ui->pushButtonLink->setEnabled(false); ui->pushButtonInfo->setEnabled(false); @@ -106,67 +104,43 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent) this, &TombRaiderLinuxLauncher::sortByReleaseDate); // Read settings - QString value = settings.value("setup").toString(); + QString value = m_settings.value("setup").toString(); if (value != "yes") setup(); else readSavedSettings(); } -void TombRaiderLinuxLauncher::askGame(int id) { - QMessageBox msgBox; - msgBox.setWindowTitle("Confirmation"); - msgBox.setText( - "TombRaider " + - QString::number(id) + - " found, you want to proceed?"); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::No); - int result = msgBox.exec(); - if (result == QMessageBox::Yes) { - qDebug() << "User clicked Yes."; - controller.setupGame(id); - } else { - qDebug() << "User clicked No or closed the dialog."; - controller.checkCommonFiles(); - } -} - -void TombRaiderLinuxLauncher::generateList() { - const QString& directoryPath = settings.value("levelPath").toString(); - const QString& pictures = ":/pictures/"; - - QDir info(directoryPath); - QFileInfoList entryInfoList = info.entryInfoList(); - - QMap> fileMap = { - {".TR1", {"Tomb_Raider_I.jpg", -1}}, - {".TR2", {"Tomb_Raider_II.jpg", -2}}, - {".TR3", {"Tomb_Raider_III.jpg", -3}}, - {".TR4", {"Tomb_Raider_IIII.jpg", -4}}, - {".TR5", {"Tomb_Raider_IIIII.jpg", -5}} - }; - - foreach(const QFileInfo &file, entryInfoList) { - QString extension = file.suffix().prepend("."); - if (fileMap.contains(extension)) { - if (file.fileName() == "Original" + extension) { - QString iconPath = pictures + fileMap[extension].first; - QString itemName = - QString("Tomb Raider %1 Original").arg(extension.mid(3)); - int userRole = fileMap[extension].second; - - QListWidgetItem *wi = - new QListWidgetItem(QIcon(iconPath), itemName); - wi->setData(Qt::UserRole, QVariant(userRole)); - ui->listWidgetModds->addItem(wi); - originalGamesSet_m.insert(wi); - originalGamesList_m.append(wi); - } else { - qDebug() << "No link or id implementation"; - // Implement logic to handle other files - } +void TombRaiderLinuxLauncher::generateList(const QList& availableGames) { + const QString pictures = ":/pictures/"; + + QMap> fileMap = { + {1, {"Tomb_Raider_I.jpg", "I"}}, + {2, {"Tomb_Raider_II.jpg", "II"}}, + {3, {"Tomb_Raider_III.jpg", "III"}}, + {4, {"Tomb_Raider_IIII.jpg", "VI"}}, + {5, {"Tomb_Raider_IIIII.jpg", "V"}} }; + + foreach(const int &id, availableGames) { + // debugStop(QString("%1").arg(id)); + int IdPositive; + bool linkedGameDir; + if (id < 0) { + linkedGameDir = false; + IdPositive = id*(-1); + } else { + linkedGameDir = true; + IdPositive = id; } + QString iconPath = pictures + fileMap[IdPositive].first; + QString itemName = + QString("Tomb Raider %1 Original").arg(fileMap[IdPositive].second); + QListWidgetItem *wi = new QListWidgetItem(QIcon(iconPath), itemName); + wi->setData(Qt::UserRole, QVariant(IdPositive*(-1))); + wi->setData(Qt::UserRole + 1, QVariant(linkedGameDir)); + ui->listWidgetModds->addItem(wi); + originalGamesSet_m.insert(wi); + originalGamesList_m.append(wi); } StaticData staticData; @@ -194,7 +168,6 @@ void TombRaiderLinuxLauncher::generateList() { QListWidgetItem *wi = new QListWidgetItem(list[i].m_picture, tag); - wi->setData(Qt::UserRole, QVariant(i + 1)); QVariantMap itemData; itemData["title"] = list[i].m_title; @@ -214,6 +187,7 @@ void TombRaiderLinuxLauncher::generateList() { void TombRaiderLinuxLauncher::sortItems( std::function compare) { QList items; + // Step 1: Extract items from the QListWidget if (ui->checkBoxOriginalFirst->isChecked()) { for (int i = 0; i < ui->listWidgetModds->count(); ++i) { @@ -229,7 +203,6 @@ void TombRaiderLinuxLauncher::sortItems( } } - // Step 2: Sort the items using the provided comparison lambda std::sort(items.begin(), items.end(), compare); @@ -323,9 +296,9 @@ void TombRaiderLinuxLauncher::sortByReleaseDate() { } void TombRaiderLinuxLauncher::readSavedSettings() { - const QString& gamePathValue = settings.value("gamePath").toString(); + const QString gamePathValue = m_settings.value("gamePath").toString(); qDebug() << "Read game path value:" << gamePathValue; - const QString& levelPathValue = settings.value("levelPath").toString(); + const QString levelPathValue = m_settings.value("levelPath").toString(); qDebug() << "Read level path value:" << levelPathValue; controller.setup(levelPathValue, gamePathValue); } @@ -341,17 +314,32 @@ void TombRaiderLinuxLauncher::setup() { ui->Tabs->indexOf(ui->Tabs->findChild("Modding")), false); qDebug() << "Entering setup" << Qt::endl; - const QString& homeDir = + const QString homeDir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); qDebug() << "Home Directory:" << homeDir; - const QString& s = "/.steam/root/steamapps/common/"; - const QString& l = "/.local/share/TombRaiderLinuxLauncher"; + const QString s = "/.steam/root/steamapps/common/"; + const QString l = "/.local/share/TombRaiderLinuxLauncher"; ui->gamePathEdit->setText(homeDir + s); ui->levelPathEdit->setText(homeDir + l); } -void TombRaiderLinuxLauncher::onListItemSelected() { - QListWidgetItem *selectedItem = ui->listWidgetModds->currentItem(); +void TombRaiderLinuxLauncher::originalSelected(QListWidgetItem *selectedItem) { + if (selectedItem) { + int id = selectedItem->data(Qt::UserRole).toInt(); + bool linkedGameDir = selectedItem->data(Qt::UserRole + 1).toBool(); + // the game dirr was a symbolic link and it has a level dir + if (linkedGameDir == true && controller.getItemState(id) == 1) { + ui->pushButtonLink->setEnabled(true); + ui->pushButtonDownload->setEnabled(false); + } else { + ui->pushButtonLink->setEnabled(false); + ui->pushButtonDownload->setEnabled(true); + } + ui->pushButtonInfo->setEnabled(false); + } +} + +void TombRaiderLinuxLauncher::levelDirSelected(QListWidgetItem *selectedItem) { if (selectedItem) { int id = selectedItem->data(Qt::UserRole).toInt(); int state = controller.getItemState(id); @@ -382,12 +370,24 @@ void TombRaiderLinuxLauncher::onListItemSelected() { } } +void TombRaiderLinuxLauncher::onListItemSelected() { + QListWidgetItem *selectedItem = ui->listWidgetModds->currentItem(); + if (selectedItem) { + int id = selectedItem->data(Qt::UserRole).toInt(); + if (id < 0) { // its the original game + originalSelected(selectedItem); + } else if (id > 0) { // do not know what to do with 0 + levelDirSelected(selectedItem); + } + } +} + void TombRaiderLinuxLauncher::setOptionsClicked() { QString gamePath = ui->gamePathEdit->text(); QString levelPath = ui->levelPathEdit->text(); - settings.setValue("gamePath" , gamePath); - settings.setValue("levelPath" , levelPath); - settings.setValue("setup" , "yes"); + m_settings.setValue("gamePath" , gamePath); + m_settings.setValue("levelPath" , levelPath); + m_settings.setValue("setup" , "yes"); ui->tableWidgetSetup->item(0, 0)->setText(gamePath); ui->tableWidgetSetup->item(1, 0)->setText(levelPath); @@ -423,7 +423,15 @@ void TombRaiderLinuxLauncher::linkClicked() { void TombRaiderLinuxLauncher::downloadClicked() { QListWidgetItem *selectedItem = ui->listWidgetModds->currentItem(); int id = selectedItem->data(Qt::UserRole).toInt(); - if (id) { + if (id < 0) { + ui->listWidgetModds->setEnabled(false); + ui->progressBar->setValue(0); + ui->stackedWidgetBar->setCurrentWidget( + ui->stackedWidgetBar->findChild("progress")); + // debugStop(QString("%1").arg(id*(-1))); + controller.setupGame(id*(-1)); + } else if (id > 0) { + ui->listWidgetModds->setEnabled(false); ui->progressBar->setValue(0); ui->stackedWidgetBar->setCurrentWidget( ui->stackedWidgetBar->findChild("progress")); @@ -491,11 +499,21 @@ void TombRaiderLinuxLauncher::workTick() { ui->progressBar->setValue(value + 1); qDebug() << ui->progressBar->value() << "%"; if (ui->progressBar->value() >= 100) { - ui->pushButtonLink->setEnabled(true); - ui->pushButtonInfo->setEnabled(true); - ui->pushButtonDownload->setEnabled(false); + QListWidgetItem *selectedItem = ui->listWidgetModds->currentItem(); + int id = selectedItem->data(Qt::UserRole).toInt(); + if (id < 0) { // its the original game + ui->pushButtonLink->setEnabled(true); + ui->pushButtonInfo->setEnabled(false); + ui->pushButtonDownload->setEnabled(false); + selectedItem->setData(Qt::UserRole + 1, QVariant(true)); + } else if (id > 0) { // do not know what to do with 0 + ui->pushButtonLink->setEnabled(true); + ui->pushButtonInfo->setEnabled(true); + ui->pushButtonDownload->setEnabled(false); + } ui->stackedWidgetBar->setCurrentWidget( ui->stackedWidgetBar->findChild("navigate")); + ui->listWidgetModds->setEnabled(true); } } diff --git a/src/TombRaiderLinuxLauncher.hpp b/src/TombRaiderLinuxLauncher.hpp index 0aed106..7baf513 100644 --- a/src/TombRaiderLinuxLauncher.hpp +++ b/src/TombRaiderLinuxLauncher.hpp @@ -33,82 +33,107 @@ namespace Ui { class TombRaiderLinuxLauncher; } QT_END_NAMESPACE /** - * + * View component in the MVC pattern; Main UI class for the launcher. */ class TombRaiderLinuxLauncher : public QMainWindow { Q_OBJECT public: /** - * Create Main Window + * Constructs the main window. */ explicit TombRaiderLinuxLauncher(QWidget *parent = nullptr); ~TombRaiderLinuxLauncher(); public slots: /** - * Called by Link function button + * Triggered by the "Link" button. */ void linkClicked(); /** - * Called by Download function button + * Triggered by the "Download" button. */ void downloadClicked(); /** - * Called by Info navigation button + * Opens the Info thru the navigation bar. */ void infoClicked(); /** - * Called by Walkthrough navigation button + * Opens the Walkthrough thru the navigation bar. */ void walkthroughClicked(); /** - * Called by Back navigation button + * Returns to the first navigation state, the list. */ void backClicked(); /** - * Called by first time setup button + * Opens the first-time setup options. */ void setOptionsClicked(); /** - * Called when selecting menu level, for disable and enable buttons + * Updates button states based on selected menu level. */ void onListItemSelected(); /** - * Called when 1% work done calculated from total work steps + * Updates progress by 1% of total work steps. */ void workTick(); /** - * + * Displays an error dialog for a curl download error. */ void downloadError(int status); /** - * + * Generates the initial level list after file analysis. */ - void askGame(int id); + void generateList(const QList& availableGames); /** - * + * Sorts the list by author. */ - void generateList(); void sortByAuthor(); + /** + * Sorts the list by title. + */ void sortByTitle(); + /** + * Sorts the list by difficulty. + */ void sortByDifficulty(); + /** + * Sorts the list by duration. + */ void sortByDuration(); + /** + * Sorts the list by level class. + */ void sortByClass(); + /** + * Sorts the list by type. + */ void sortByType(); + /** + * Sorts the list by release date. + */ void sortByReleaseDate(); private: /** * */ - void setup(); + void originalSelected(QListWidgetItem *selectedItem); /** * */ + void levelDirSelected(QListWidgetItem *selectedItem); + /** + * Configures game and level directories. + */ + void setup(); + /** + * Loads saved settings. + */ void readSavedSettings(); /** - * + * Executes the sorting algorithm. */ void sortItems(std::function originalGamesSet_m; QList originalGamesList_m; Controller& controller = Controller::getInstance(); - QSettings settings; + QSettings m_settings; Ui::TombRaiderLinuxLauncher *ui; }; #endif // SRC_TOMBRAIDERLINUXLAUNCHER_HPP_ diff --git a/src/debug.hpp b/src/debug.hpp new file mode 100644 index 0000000..b6f92e1 --- /dev/null +++ b/src/debug.hpp @@ -0,0 +1,43 @@ +#ifndef SRC_DEBUG_HPP_ +#define SRC_DEBUG_HPP_ + +#include +#include +#include + +// Debug variable +inline bool DEBUG_ENABLED = true; // Toggle this to enable/disable debugging + +// Debug log function +inline void debugLog(const QString &message) { + if (DEBUG_ENABLED) { + qDebug() << message; + } +} + +// Stop function for debugging +inline void debugStop( + const QString& var1 = "", + const QString& var2 = "", + const QString& var3 = "", + const QString& var4 = "") { + if (DEBUG_ENABLED) { + QTextStream in(stdin); + if (var1 != "") { + qDebug() << var1; + } + if (var2 != "") { + qDebug() << var2; + } + if (var3 != "") { + qDebug() << var3; + } + if (var4 != "") { + qDebug() << var4; + } + in.readLine(); + } +} + +#endif // SRC_DEBUG_HPP_ +