From 6c20b37b0cb7a533065b684207655cf2085336ea Mon Sep 17 00:00:00 2001 From: Sclafus Date: Wed, 19 Jun 2024 20:32:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20chore:=20clang-tidy=20improvemen?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-tidy | 147 ++++++++++++++++++ .gitignore | 10 +- src/backup/backup.cpp | 16 +- src/backup/backup.h | 7 +- src/commands/commandswindow.cpp | 55 +++---- src/commands/commandswindow.h | 31 ++-- src/main.cpp | 17 +- src/mainwindow.cpp | 29 ++-- src/mainwindow.h | 38 +++-- src/osu/api/auth/clientCredentialsFlow.cpp | 12 +- src/osu/api/auth/clientCredentialsFlow.h | 11 +- src/osu/api/osuapi.cpp | 18 +-- src/osu/api/osuapi.h | 5 +- src/osu/data/gosu/gosumemoryclient.cpp | 53 +++---- src/osu/data/gosu/gosumemoryclient.h | 8 +- src/osu/data/gosu/gosumemorydatawrapper.cpp | 30 ++-- src/osu/data/gosu/gosumemorydatawrapper.h | 12 +- src/osu/irc/osuircclient.cpp | 92 +++++------ src/osu/irc/osuircclient.h | 30 ++-- src/preferences/preferences.cpp | 76 ++++----- src/preferences/preferences.h | 57 +++---- .../streaming/streamingServiceDataWrapper.h | 11 +- .../streaming/twitch/twitchClient.cpp | 77 ++++----- src/services/streaming/twitch/twitchClient.h | 29 ++-- .../streaming/twitch/twitchdatawrapper.cpp | 12 +- .../streaming/twitch/twitchdatawrapper.h | 23 +-- src/setupwizard/setupwizard.cpp | 60 +++---- src/setupwizard/setupwizard.h | 39 ++--- src/skinsurl/skinsurl.cpp | 68 ++++---- src/skinsurl/skinsurl.h | 39 ++--- src/theme/theme.cpp | 41 ++--- src/theme/theme.h | 20 +-- src/twitchcommandhandler.cpp | 56 +++---- src/twitchcommandhandler.h | 36 ++--- src/updater/updater.cpp | 36 ++--- src/updater/updater.h | 24 +-- src/updater/updaterurls.h | 4 +- src/updater/version.h | 2 + src/utils/utils.h | 2 + 39 files changed, 685 insertions(+), 648 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..fd8c681 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,147 @@ +# Generated from CLion Inspection settings +--- +Checks: '-*, +bugprone-argument-comment, +bugprone-assert-side-effect, +bugprone-bad-signal-to-kill-thread, +bugprone-branch-clone, +bugprone-copy-constructor-init, +bugprone-dangling-handle, +bugprone-dynamic-static-initializers, +bugprone-fold-init-type, +bugprone-forward-declaration-namespace, +bugprone-forwarding-reference-overload, +bugprone-inaccurate-erase, +bugprone-incorrect-roundings, +bugprone-integer-division, +bugprone-lambda-function-name, +bugprone-macro-parentheses, +bugprone-macro-repeated-side-effects, +bugprone-misplaced-operator-in-strlen-in-alloc, +bugprone-misplaced-pointer-arithmetic-in-alloc, +bugprone-misplaced-widening-cast, +bugprone-move-forwarding-reference, +bugprone-multiple-statement-macro, +bugprone-no-escape, +bugprone-parent-virtual-call, +bugprone-posix-return, +bugprone-reserved-identifier, +bugprone-sizeof-container, +bugprone-sizeof-expression, +bugprone-spuriously-wake-up-functions, +bugprone-string-constructor, +bugprone-string-integer-assignment, +bugprone-string-literal-with-embedded-nul, +bugprone-suspicious-enum-usage, +bugprone-suspicious-include, +bugprone-suspicious-memset-usage, +bugprone-suspicious-missing-comma, +bugprone-suspicious-semicolon, +bugprone-suspicious-string-compare, +bugprone-suspicious-memory-comparison, +bugprone-suspicious-realloc-usage, +bugprone-swapped-arguments, +bugprone-terminating-continue, +bugprone-throw-keyword-missing, +bugprone-too-small-loop-variable, +bugprone-undefined-memory-manipulation, +bugprone-undelegated-constructor, +bugprone-unhandled-self-assignment, +bugprone-unused-raii, +bugprone-unused-return-value, +bugprone-use-after-move, +bugprone-virtual-near-miss, +cert-dcl21-cpp, +cert-dcl58-cpp, +cert-err34-c, +cert-err52-cpp, +cert-err60-cpp, +cert-flp30-c, +cert-msc50-cpp, +cert-msc51-cpp, +cert-str34-c, +cppcoreguidelines-interfaces-global-init, +cppcoreguidelines-narrowing-conversions, +cppcoreguidelines-pro-type-member-init, +cppcoreguidelines-pro-type-static-cast-downcast, +cppcoreguidelines-slicing, +google-default-arguments, +google-explicit-constructor, +google-runtime-operator, +hicpp-exception-baseclass, +hicpp-multiway-paths-covered, +misc-misplaced-const, +misc-new-delete-overloads, +misc-no-recursion, +misc-non-copyable-objects, +misc-throw-by-value-catch-by-reference, +misc-unconventional-assign-operator, +misc-uniqueptr-reset-release, +modernize-avoid-bind, +modernize-concat-nested-namespaces, +modernize-deprecated-headers, +modernize-deprecated-ios-base-aliases, +modernize-loop-convert, +modernize-make-shared, +modernize-make-unique, +modernize-pass-by-value, +modernize-raw-string-literal, +modernize-redundant-void-arg, +modernize-replace-auto-ptr, +modernize-replace-disallow-copy-and-assign-macro, +modernize-replace-random-shuffle, +modernize-return-braced-init-list, +modernize-shrink-to-fit, +modernize-unary-static-assert, +modernize-use-auto, +modernize-use-bool-literals, +modernize-use-emplace, +modernize-use-equals-default, +modernize-use-equals-delete, +modernize-use-nodiscard, +modernize-use-noexcept, +modernize-use-nullptr, +modernize-use-override, +modernize-use-transparent-functors, +modernize-use-uncaught-exceptions, +mpi-buffer-deref, +mpi-type-mismatch, +openmp-use-default-none, +performance-faster-string-find, +performance-for-range-copy, +performance-implicit-conversion-in-loop, +performance-inefficient-algorithm, +performance-inefficient-string-concatenation, +performance-inefficient-vector-operation, +performance-move-const-arg, +performance-move-constructor-init, +performance-no-automatic-move, +performance-noexcept-move-constructor, +performance-trivially-destructible, +performance-type-promotion-in-math-fn, +performance-unnecessary-copy-initialization, +performance-unnecessary-value-param, +portability-simd-intrinsics, +readability-avoid-const-params-in-decls, +readability-const-return-type, +readability-container-size-empty, +readability-convert-member-functions-to-static, +readability-delete-null-pointer, +readability-deleted-default, +readability-inconsistent-declaration-parameter-name, +readability-make-member-function-const, +readability-misleading-indentation, +readability-misplaced-array-index, +readability-non-const-parameter, +readability-redundant-control-flow, +readability-redundant-declaration, +readability-redundant-function-ptr-dereference, +readability-redundant-smartptr-get, +readability-redundant-string-cstr, +readability-redundant-string-init, +readability-simplify-subscript-expr, +readability-static-accessed-through-instance, +readability-static-definition-in-anonymous-namespace, +readability-string-compare, +readability-uniqueptr-delete-release, +readability-use-anyofallof' \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6777e7a..3fa54fe 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,12 @@ compile_commands.json # Cmake builds build* +bin* + +# VSCode +.vscode + +# Testing stuff +*.conf +*.json -#Visual Studio -.vscode \ No newline at end of file diff --git a/src/backup/backup.cpp b/src/backup/backup.cpp index 994ccb3..8eb84ea 100644 --- a/src/backup/backup.cpp +++ b/src/backup/backup.cpp @@ -1,14 +1,13 @@ #include "backup.h" -void Backup::backup(QString filePath, bool includeSensitiveInfo) -{ +void Backup::backup(QString filePath, bool includeSensitiveInfo) { if (filePath.isEmpty()) { return; } // adding .json if needed - if(!filePath.endsWith(".json")) { + if (!filePath.endsWith(".json")) { filePath.append(".json"); } @@ -26,13 +25,13 @@ void Backup::backup(QString filePath, bool includeSensitiveInfo) QStringList keys = settings.allKeys(); // sensitive info must be excluded - if(!includeSensitiveInfo) { - keys.removeIf([](const QString& key){ + if (!includeSensitiveInfo) { + keys.removeIf([](const QString &key) { return key.startsWith("osuirc") || key.startsWith("twitch"); }); } - for(const QString& key: keys){ + for (const QString &key: keys) { QString value = settings.value(key).toString(); jsonObject.insert(key, QJsonValue(value)); } @@ -45,8 +44,7 @@ void Backup::backup(QString filePath, bool includeSensitiveInfo) qDebug() << "[Backup] Backup completed"; } -void Backup::restore(QString filePath) -{ +void Backup::restore(const QString &filePath) { if (filePath.isEmpty()) { return; } @@ -65,7 +63,7 @@ void Backup::restore(QString filePath) QSettings settings; QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8()); - if (!jsonDoc.isNull()){ + if (!jsonDoc.isNull()) { QJsonObject jsonObject = jsonDoc.object(); for (auto it = jsonObject.begin(); it != jsonObject.end(); ++it) { QString key = it.key(); diff --git a/src/backup/backup.h b/src/backup/backup.h index 84f3e50..9a47fa9 100644 --- a/src/backup/backup.h +++ b/src/backup/backup.h @@ -10,11 +10,12 @@ #include #include -class Backup -{ +// @formatter:off +class Backup { public: static void backup(QString filePath, bool includeSensitiveInfo); - static void restore(QString filePath); + static void restore(const QString &filePath); }; +// @formatter:on #endif // BACKUP_H diff --git a/src/commands/commandswindow.cpp b/src/commands/commandswindow.cpp index 62e2a12..90ed99c 100644 --- a/src/commands/commandswindow.cpp +++ b/src/commands/commandswindow.cpp @@ -2,9 +2,8 @@ #include "ui_commandswindow.h" CommandsWindow::CommandsWindow(QWidget *parent) : - QDialog(parent), - ui(new Ui::CommandsWindow) -{ + QDialog(parent), + ui(new Ui::CommandsWindow) { ui->setupUi(this); loadData(); connect(ui->addCommandBtn, &QPushButton::clicked, this, &CommandsWindow::on_addCommandBtn_clicked); @@ -12,47 +11,43 @@ CommandsWindow::CommandsWindow(QWidget *parent) : connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &CommandsWindow::on_saveBtn_clicked); } -CommandsWindow::~CommandsWindow() -{ - delete ui; +CommandsWindow::~CommandsWindow() { + delete ui; } -void CommandsWindow::loadData() -{ +void CommandsWindow::loadData() { qDebug() << "[Commands] Loading data"; QSettings settings; settings.beginGroup("command"); QStringList commands = settings.childKeys(); - for (QString command: commands) { + for (const QString &command: commands) { addRow(command, settings.value(command).toString()); } } -void CommandsWindow::addRow(QString command, QString response) -{ +void CommandsWindow::addRow(const QString &command, const QString &response) { // adding new line ui->commandsTable->insertRow(ui->commandsTable->rowCount()); - QTableWidgetItem *commandNameItem = new QTableWidgetItem(command); - QTableWidgetItem *commandResponseItem = new QTableWidgetItem(response); + auto *commandNameItem = new QTableWidgetItem(command); + auto *commandResponseItem = new QTableWidgetItem(response); // Command name column ui->commandsTable->setItem( - ui->commandsTable->rowCount() - 1, - 0, - commandNameItem + ui->commandsTable->rowCount() - 1, + 0, + commandNameItem ); // Command response column ui->commandsTable->setItem( - ui->commandsTable->rowCount() - 1, - 1, - commandResponseItem + ui->commandsTable->rowCount() - 1, + 1, + commandResponseItem ); } -void CommandsWindow::on_addCommandBtn_clicked() -{ +void CommandsWindow::on_addCommandBtn_clicked() { int lastRow = ui->commandsTable->rowCount() - 1; auto lastCommand = ui->commandsTable->item(lastRow, 0); auto lastResponse = ui->commandsTable->item(lastRow, 1); @@ -60,21 +55,20 @@ void CommandsWindow::on_addCommandBtn_clicked() bool isLastCommandEmpty = lastCommand != nullptr && lastCommand->text().isEmpty(); bool isLastResponseEmpty = lastResponse != nullptr && lastResponse->text().isEmpty(); - if (!isLastCommandEmpty && !isLastResponseEmpty){ - addRow("",""); + if (!isLastCommandEmpty && !isLastResponseEmpty) { + addRow("", ""); } } -void CommandsWindow::on_removeCommandBtn_clicked() -{ +void CommandsWindow::on_removeCommandBtn_clicked() { QSettings settings; auto selectionModel = ui->commandsTable->selectionModel(); - if (!selectionModel->hasSelection()){ + if (!selectionModel->hasSelection()) { return; } auto selected = selectionModel->selectedIndexes(); - for (auto selection : selected) { + for (auto selection: selected) { int row = selection.row(); QString command = ui->commandsTable->item(row, 0)->text(); @@ -83,21 +77,20 @@ void CommandsWindow::on_removeCommandBtn_clicked() } } -void CommandsWindow::on_saveBtn_clicked() -{ +void CommandsWindow::on_saveBtn_clicked() { qDebug() << "[Commands] Saving data..."; QSettings settings; for (int row = 2; row < ui->commandsTable->rowCount(); row++) { QTableWidgetItem *commandNameItem = ui->commandsTable->item(row, 0); - QTableWidgetItem *commandResponseItem = ui->commandsTable->item(row, 1); + QTableWidgetItem *commandResponseItem = ui->commandsTable->item(row, 1); if (commandResponseItem == nullptr || commandNameItem == nullptr) { return; } QString commandName = commandNameItem->text(); - QString commandResponse = commandResponseItem->text(); + QString commandResponse = commandResponseItem->text(); if (!commandName.startsWith("!")) { commandName.prepend("!"); diff --git a/src/commands/commandswindow.h b/src/commands/commandswindow.h index 31ad6f1..34e5688 100644 --- a/src/commands/commandswindow.h +++ b/src/commands/commandswindow.h @@ -6,26 +6,25 @@ #include namespace Ui { - class CommandsWindow; + class CommandsWindow; } -class CommandsWindow : public QDialog -{ +// @formatter:off +class CommandsWindow : public QDialog { Q_OBJECT -public: - explicit CommandsWindow(QWidget *parent = nullptr); - ~CommandsWindow(); - -private: - void on_addCommandBtn_clicked(); - void on_removeCommandBtn_clicked(); - void on_saveBtn_clicked(); - - void loadData(); - void addRow(QString command, QString response); - - Ui::CommandsWindow *ui; + public: + explicit CommandsWindow(QWidget *parent = nullptr); + ~CommandsWindow() override; + + private: + void on_addCommandBtn_clicked(); + void on_removeCommandBtn_clicked(); + void on_saveBtn_clicked(); + void loadData(); + void addRow(const QString& command, const QString& response); + Ui::CommandsWindow *ui; }; +// @formatter:on #endif // COMMANDSWINDOW_H diff --git a/src/main.cpp b/src/main.cpp index 48cac49..2786d9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,17 @@ #include #include -#include #include "mainwindow.h" int main(int argc, char **argv) { QApplication app(argc, argv); - app.setOrganizationName("miraya"); - app.setOrganizationDomain("github.com/MirayaProject"); - app.setApplicationName("bot"); - app.setApplicationVersion("1.3.0-alpha.1"); - #ifdef Q_OS_LINUX - app.setWindowIcon(QIcon(":/resources/logo/logo.png")); - #endif + QApplication::setOrganizationName("miraya"); + QApplication::setOrganizationDomain("github.com/MirayaProject"); + QApplication::setApplicationName("bot"); + QApplication::setApplicationVersion("1.3.0-alpha.1"); +#ifdef Q_OS_LINUX + QApplication::setWindowIcon(QIcon(":/resources/logo/logo.png")); +#endif MainWindow mw; mw.show(); - return app.exec(); + return QApplication::exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4677e5e..8733d3f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -78,25 +78,25 @@ void MainWindow::on_actionStart_Setup_triggered() } -void MainWindow::on_actionGithub_triggered() +[[maybe_unused]] void MainWindow::on_actionGithub_triggered() { QDesktopServices::openUrl(QUrl("https://www.github.com/MirayaProject/miraya")); } -void MainWindow::on_actionDiscord_triggered() +[[maybe_unused]] void MainWindow::on_actionDiscord_triggered() { QDesktopServices::openUrl(QUrl("https://www.discord.gg/anHrS7p5Sf")); } -void MainWindow::on_actionAbout_triggered() +[[maybe_unused]] void MainWindow::on_actionAbout_triggered() { return About::show(); } -void MainWindow::on_actionPreferences_triggered() +[[maybe_unused]] void MainWindow::on_actionPreferences_triggered() { auto preferences = Preferences(this); connect(&preferences, &Preferences::themeChanged, this, &MainWindow::onThemeChanged); @@ -104,19 +104,19 @@ void MainWindow::on_actionPreferences_triggered() } -void MainWindow::on_actionSkins_triggered() +[[maybe_unused]] void MainWindow::on_actionSkins_triggered() { SkinsUrl(gosumemoryClient, this).exec(); } -void MainWindow::on_actionCommands_triggered() +[[maybe_unused]] void MainWindow::on_actionCommands_triggered() { CommandsWindow(this).exec(); } -void MainWindow::on_btnStart_clicked() +[[maybe_unused]] void MainWindow::on_btnStart_clicked() { qDebug() << "[MainWindow] init"; twitchClient->restart(); @@ -145,7 +145,7 @@ void MainWindow::onGosumemoryClientMessageReceived(GosuMemoryDataWrapper message void MainWindow::onTwitchClientMessageReceived(TwitchDataWrapper message) { // TODO: this should not be here - for (QString url : Utils::getOsuBeatmapUrls(message.getMessage())) { + for (const QString& url : Utils::getOsuBeatmapUrls(message.getMessage())) { qDebug() << "[MainWindow] Osu beatmap url: " << url; int beatmapId = Utils::getBeatmapIdFromOsuBeatmapLink(url); @@ -161,7 +161,7 @@ void MainWindow::onTwitchClientMessageReceived(TwitchDataWrapper message) QLabel* label = getTwitchChatMessage(message.getUsername(), message.getMessage()); label->adjustSize(); - QListWidgetItem* item = new QListWidgetItem(ui->twitchChat); + auto* item = new QListWidgetItem(ui->twitchChat); item->setSizeHint(label->size()); // Set the size hint based on the label's size ui->twitchChat->addItem(item); ui->twitchChat->setItemWidget(item, label); @@ -172,7 +172,7 @@ void MainWindow::onTwitchClientMessageReceived(TwitchDataWrapper message) void MainWindow::onNewVersionReceived() { qDebug() << "[MainWindow] New version available"; - QMessageBox().information( + QMessageBox::information( this, "New Version Available", "There is a new version available! Click here to check it out!", @@ -181,10 +181,10 @@ void MainWindow::onNewVersionReceived() } -QLabel* MainWindow::getTwitchChatMessage(QString username, QString message) +QLabel* MainWindow::getTwitchChatMessage(const QString& username, const QString& message) { QString richTextMsg = getRichTextMessage(message); - QLabel* label = new QLabel(); + auto *label = new QLabel(); QFont font = label->font(); font.setPointSize(12); @@ -196,7 +196,8 @@ QLabel* MainWindow::getTwitchChatMessage(QString username, QString message) label->setOpenExternalLinks(true); label->setWordWrap(true); - label->setText(QString("%1: %2").arg(username).arg(richTextMsg)); + auto chatMessage = QString("%1: %2").arg(username, richTextMsg); + label->setText(chatMessage); label->setMaximumHeight(qMax(label->sizeHint().height(), 44)); //noqa return label; } @@ -206,7 +207,7 @@ QString MainWindow::getRichTextMessage(const QString& message) { auto urls = Utils::getUrls(message); QString substitutedMessage = message; - for (auto url : urls){ + for (const auto& url : urls){ substitutedMessage.replace(url, QString("%1").arg(url)); } return substitutedMessage; diff --git a/src/mainwindow.h b/src/mainwindow.h index e958042..f07a37f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -31,28 +31,27 @@ namespace Ui { - class MainWindow; + class MainWindow; } -class MainWindow : public QMainWindow -{ +// @formatter:off +class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + ~MainWindow() override; private slots: - void on_btnStart_clicked(); + [[maybe_unused]] void on_btnStart_clicked(); void on_actionStart_Setup_triggered(); - void on_actionGithub_triggered(); - void on_actionDiscord_triggered(); - void on_actionAbout_triggered(); - void on_actionPreferences_triggered(); - void on_actionSkins_triggered(); - void on_actionCommands_triggered(); - - void onThemeChanged(); + [[maybe_unused]] static void on_actionGithub_triggered(); + [[maybe_unused]] static void on_actionDiscord_triggered(); + [[maybe_unused]] static void on_actionAbout_triggered(); + [[maybe_unused]] void on_actionPreferences_triggered(); + [[maybe_unused]] void on_actionSkins_triggered(); + [[maybe_unused]] void on_actionCommands_triggered(); + static void onThemeChanged(); void onTwitchClientConnected(); void onGosumemoryClientConnected(); void onOsuIrcClientConnected(); @@ -69,9 +68,8 @@ class MainWindow : public QMainWindow void setupSignals(); void setupStatusbar(); void setupUi(); - - QLabel *getTwitchChatMessage(QString username, QString message); - QString getRichTextMessage(const QString& message); + static QLabel *getTwitchChatMessage(const QString& username, const QString& message); + static QString getRichTextMessage(const QString& message); Ui::MainWindow *ui; TwitchClient *twitchClient; TwitchCommandHandler *twitchCommandHandler; @@ -79,10 +77,10 @@ class MainWindow : public QMainWindow OsuIrcClient *osuIrcClient; Updater *updater; OsuApi *osuApi; - - QLabel *ircConnectionLabel; - QLabel *twitchConnectionLabel; - QLabel *gosumemoryConnectionLabel; + QLabel *ircConnectionLabel{}; + QLabel *twitchConnectionLabel{}; + QLabel *gosumemoryConnectionLabel{}; }; +// @formatter:on #endif // MAINWINDOW_H diff --git a/src/osu/api/auth/clientCredentialsFlow.cpp b/src/osu/api/auth/clientCredentialsFlow.cpp index 1edcaa1..1388025 100644 --- a/src/osu/api/auth/clientCredentialsFlow.cpp +++ b/src/osu/api/auth/clientCredentialsFlow.cpp @@ -1,18 +1,18 @@ #include "clientCredentialsFlow.h" -QJsonObject ClientCredentialsFlow::getToken(QString clientId, QString clientSecret, QString oAuthUrl) -{ +QJsonObject +ClientCredentialsFlow::getToken(const QString &clientId, const QString &clientSecret, const QString &oAuthUrl) { qDebug() << "[ClientCredentialsFlow] getToken"; QNetworkAccessManager manager; QNetworkRequest request((QUrl(oAuthUrl))); request.setHeader( - QNetworkRequest::ContentTypeHeader, - "application/x-www-form-urlencoded" + QNetworkRequest::ContentTypeHeader, + "application/x-www-form-urlencoded" ); request.setHeader( - QNetworkRequest::UserAgentHeader, - "Miraya" + QNetworkRequest::UserAgentHeader, + "Miraya" ); QUrlQuery params; diff --git a/src/osu/api/auth/clientCredentialsFlow.h b/src/osu/api/auth/clientCredentialsFlow.h index ecbe07f..fb0c64a 100644 --- a/src/osu/api/auth/clientCredentialsFlow.h +++ b/src/osu/api/auth/clientCredentialsFlow.h @@ -11,14 +11,15 @@ #include #include -class ClientCredentialsFlow -{ +// @formatter:off +class ClientCredentialsFlow { public: static QJsonObject getToken( - QString clientId, - QString clientSecret, - QString oAuthUrl = QString("https://osu.ppy.sh/oauth/token") + const QString &clientId, + const QString &clientSecret, + const QString &oAuthUrl = QString("https://osu.ppy.sh/oauth/token") ); }; +// @formatter:on #endif // CLIENTCREDENTIALSFLOW_H diff --git a/src/osu/api/osuapi.cpp b/src/osu/api/osuapi.cpp index 7df38e5..c71325c 100644 --- a/src/osu/api/osuapi.cpp +++ b/src/osu/api/osuapi.cpp @@ -1,7 +1,6 @@ #include "osuapi.h" -OsuApi::OsuApi() -{ +OsuApi::OsuApi() { qDebug() << "[OsuApi] Init"; QSettings settings; clientId = settings.value("osuapi/clientId").toString(); @@ -10,14 +9,12 @@ OsuApi::OsuApi() if (!(clientId.isEmpty() || clientSecret.isEmpty())) { token = ClientCredentialsFlow::getToken(clientId, clientSecret, oAuthUrl); - } - else { + } else { qDebug() << "[OsuApi] Client ID or Client Secret are empty"; } } -QJsonObject OsuApi::getBeatmapInfo(int beatmapId) -{ +QJsonObject OsuApi::getBeatmapInfo(int beatmapId) { // TODO: A lot can be split into smaller functions // TODO: also, the QEventLoop is making everything synchronous, which is suboptimal to say the least. qDebug() << "[OsuApi] getBeatmapInfo"; @@ -29,8 +26,8 @@ QJsonObject OsuApi::getBeatmapInfo(int beatmapId) QString accessToken = token["access_token"].toString(); request.setRawHeader( - QByteArray("Authorization"), - (QString("Bearer %1").arg(accessToken)).toUtf8() + QByteArray("Authorization"), + (QString("Bearer %1").arg(accessToken)).toUtf8() ); QNetworkReply *reply = manager.get(request); @@ -49,10 +46,9 @@ QJsonObject OsuApi::getBeatmapInfo(int beatmapId) return obj; } qDebug() << "[OsuApi] Error: " << reply->errorString(); - return QJsonObject(); + return {}; } -bool OsuApi::isValid() -{ +bool OsuApi::isValid() { return !(clientId.isEmpty() || clientSecret.isEmpty()); } diff --git a/src/osu/api/osuapi.h b/src/osu/api/osuapi.h index a37578d..8bcecc9 100644 --- a/src/osu/api/osuapi.h +++ b/src/osu/api/osuapi.h @@ -14,8 +14,8 @@ #include "api/auth/clientCredentialsFlow.h" -class OsuApi : public QObject -{ +// @formatter:off +class OsuApi : public QObject { public: OsuApi(); QJsonObject getBeatmapInfo(int beatmapId); @@ -27,5 +27,6 @@ class OsuApi : public QObject QString oAuthUrl; QJsonObject token; }; +// @formatter:on #endif // OSUAPI_H diff --git a/src/osu/data/gosu/gosumemoryclient.cpp b/src/osu/data/gosu/gosumemoryclient.cpp index fd7e1ff..fc2c409 100644 --- a/src/osu/data/gosu/gosumemoryclient.cpp +++ b/src/osu/data/gosu/gosumemoryclient.cpp @@ -1,68 +1,58 @@ #include "osu/data/gosu/gosumemoryclient.h" -GosumemoryClient::GosumemoryClient( - const QUrl &url, - QObject *parent -) : QObject(parent), url(url) -{ +#include + +[[maybe_unused]] GosumemoryClient::GosumemoryClient( + QUrl url, + QObject *parent +) : QObject(parent), url(std::move(url)) { initSignals(); enableRead(true); } -GosumemoryClient::GosumemoryClient(QObject *parent) : QObject(parent) -{ +GosumemoryClient::GosumemoryClient(QObject *parent) : QObject(parent) { initSignals(); enableRead(true); } -void GosumemoryClient::initSignals() -{ +void GosumemoryClient::initSignals() { connect(&socket, &QWebSocket::connected, this, &GosumemoryClient::onConnected); connect(&socket, &QWebSocket::textMessageReceived, this, &GosumemoryClient::onTextMessageReceived); connect(&socket, &QWebSocket::disconnected, this, &GosumemoryClient::onDisconnected); } -void GosumemoryClient::init() -{ +void GosumemoryClient::init() { refreshData(); qDebug() << "Connecting to: " << url.toString(); socket.open(QUrl(url)); } -void GosumemoryClient::refreshData() -{ +void GosumemoryClient::refreshData() { qDebug() << "[Gosumemory] Refreshing data..."; QSettings settings; - setUrl( - "ws://" - + settings.value("gosumemory/ip").toString() - + ":" - + settings.value("gosumemory/port").toString() - + "/ws" - ); + auto wsUrl = QString("ws://%1:%2/ws").arg(settings.value("gosumemory/ip").toString(), + settings.value("gosumemory/port").toString()); + setUrl(wsUrl); } -void GosumemoryClient::restart() -{ +void GosumemoryClient::restart() { socket.close(); init(); } -void GosumemoryClient::onConnected() -{ +void GosumemoryClient::onConnected() { qDebug() << "[Gosumemory] Connected to: " << url.toString(); emit connected(); } -void GosumemoryClient::onTextMessageReceived(QString message) -{ +void GosumemoryClient::onTextMessageReceived(QString message) { if (readEnabled) { // qDebug() << "GosumemoryClient: message received from: " << url.toString() << message; emit messageReceived(GosuMemoryDataWrapper(message)); @@ -70,19 +60,16 @@ void GosumemoryClient::onTextMessageReceived(QString message) } -void GosumemoryClient::onDisconnected() -{ +void GosumemoryClient::onDisconnected() { qDebug() << "[Gosumemory] Disconnected from: " << url.toString(); emit disconnected(); } -void GosumemoryClient::setUrl(const QUrl &url) -{ - this->url = url; +void GosumemoryClient::setUrl(const QUrl &newUrl) { + this->url = newUrl; } -void GosumemoryClient::enableRead(bool enable) -{ +void GosumemoryClient::enableRead(bool enable) { readEnabled = enable; } diff --git a/src/osu/data/gosu/gosumemoryclient.h b/src/osu/data/gosu/gosumemoryclient.h index 57fa4bb..f691b3c 100644 --- a/src/osu/data/gosu/gosumemoryclient.h +++ b/src/osu/data/gosu/gosumemoryclient.h @@ -9,21 +9,22 @@ #include "osu/data/gosu/gosumemorydatawrapper.h" +// @formatter:off class GosumemoryClient : public QObject { Q_OBJECT public: explicit GosumemoryClient(QObject *parent = nullptr); - explicit GosumemoryClient(const QUrl &url, QObject *parent = nullptr); + [[maybe_unused]] explicit GosumemoryClient(QUrl url, QObject *parent = nullptr); void enableRead(bool enable); void init(); void restart(); - void setUrl(const QUrl &url); + void setUrl(const QUrl &newUrl); private: void initSignals(); void refreshData(); - bool readEnabled; + bool readEnabled{}; QWebSocket socket; QUrl url; @@ -37,5 +38,6 @@ class GosumemoryClient : public QObject { void onTextMessageReceived(QString message); void onDisconnected(); }; +// @formatter:on #endif diff --git a/src/osu/data/gosu/gosumemorydatawrapper.cpp b/src/osu/data/gosu/gosumemorydatawrapper.cpp index 6c81dd5..039df01 100644 --- a/src/osu/data/gosu/gosumemorydatawrapper.cpp +++ b/src/osu/data/gosu/gosumemorydatawrapper.cpp @@ -1,61 +1,51 @@ #include "osu/data/gosu/gosumemorydatawrapper.h" GosuMemoryDataWrapper::GosuMemoryDataWrapper() -{ -} += default; GosuMemoryDataWrapper::GosuMemoryDataWrapper(QString &data) - : data(data) -{ + : data(data) { parseData(); } -void GosuMemoryDataWrapper::parseData() -{ +void GosuMemoryDataWrapper::parseData() { json = QJsonDocument::fromJson(data.toUtf8()).object(); } -QJsonObject GosuMemoryDataWrapper::getBeatmapMetadata() -{ +QJsonObject GosuMemoryDataWrapper::getBeatmapMetadata() { return json["menu"].toObject()["bm"].toObject()["metadata"].toObject(); } -QString GosuMemoryDataWrapper::getMapName() -{ +QString GosuMemoryDataWrapper::getMapName() { return getBeatmapMetadata()["title"].toString(); } -QString GosuMemoryDataWrapper::getMapArtist() -{ +QString GosuMemoryDataWrapper::getMapArtist() { return getBeatmapMetadata()["artist"].toString(); } -QString GosuMemoryDataWrapper::getMapMapper() -{ +QString GosuMemoryDataWrapper::getMapMapper() { return getBeatmapMetadata()["mapper"].toString(); } -QString GosuMemoryDataWrapper::getMapDifficulty() -{ +QString GosuMemoryDataWrapper::getMapDifficulty() { return getBeatmapMetadata()["difficulty"].toString(); } -QString GosuMemoryDataWrapper::getMapUrl() -{ +QString GosuMemoryDataWrapper::getMapUrl() { auto val = json["menu"].toObject()["bm"].toObject()["id"].toInt(); qDebug() << val; return QString("https://osu.ppy.sh/b/%1").arg(val); } -QString GosuMemoryDataWrapper::getSkinName() -{ +QString GosuMemoryDataWrapper::getSkinName() { return json["settings"].toObject()["folders"].toObject()["skin"].toString(); } diff --git a/src/osu/data/gosu/gosumemorydatawrapper.h b/src/osu/data/gosu/gosumemorydatawrapper.h index fb0d271..3eba1de 100644 --- a/src/osu/data/gosu/gosumemorydatawrapper.h +++ b/src/osu/data/gosu/gosumemorydatawrapper.h @@ -5,11 +5,11 @@ #include #include -class GosuMemoryDataWrapper -{ +// @formatter:off +class GosuMemoryDataWrapper { public: GosuMemoryDataWrapper(); - GosuMemoryDataWrapper(QString &data); + explicit GosuMemoryDataWrapper(QString &data); QString getMapName(); QString getMapArtist(); QString getMapMapper(); @@ -21,8 +21,10 @@ class GosuMemoryDataWrapper QString data; QJsonObject json; - void parseData(); - QJsonObject getBeatmapMetadata(); + void parseData(); + + QJsonObject getBeatmapMetadata(); }; +// @formatter:on #endif // GOSUMEMORYDATAWRAPPER_H diff --git a/src/osu/irc/osuircclient.cpp b/src/osu/irc/osuircclient.cpp index 5bb0550..776c24c 100644 --- a/src/osu/irc/osuircclient.cpp +++ b/src/osu/irc/osuircclient.cpp @@ -1,47 +1,46 @@ #include "osuircclient.h" -OsuIrcClient::OsuIrcClient( - const QString &nickname, - const QString &password, - const QString &server, - const int &port, - QObject *parent -) : QObject(parent), nickname(nickname), password(password), server(server), port(port) -{ +#include + +[[maybe_unused]] OsuIrcClient::OsuIrcClient( + QString nickname, + QString password, + QString server, + const int &port, + QObject *parent +) : QObject(parent), nickname(std::move(nickname)), password(std::move(password)), server(std::move(server)), + port(port) { initSignals(); } -OsuIrcClient::OsuIrcClient(QObject *parent) : QObject(parent) -{ +OsuIrcClient::OsuIrcClient(QObject *parent) : QObject(parent) { initSignals(); } -void OsuIrcClient::initSignals() -{ +void OsuIrcClient::initSignals() { connect(&socket, &QTcpSocket::connected, this, &OsuIrcClient::onConnected); connect(&socket, &QTcpSocket::readyRead, this, &OsuIrcClient::onReadyRead); connect(&socket, &QTcpSocket::disconnected, this, &OsuIrcClient::onDisconnected); } -void OsuIrcClient::init() -{ +void OsuIrcClient::init() { refreshData(); qDebug() << "[osu!IRC] Connecting to: " << server << ":" << port; socket.connectToHost(server, port); socket.write("PASS " + password.toLocal8Bit() + "\r\n"); - socket.write("USER " + nickname.toLocal8Bit() + " " + nickname.toLocal8Bit() + " " + nickname.toLocal8Bit() + " :" + nickname.toLocal8Bit() + "\r\n"); + socket.write("USER " + nickname.toLocal8Bit() + " " + nickname.toLocal8Bit() + " " + nickname.toLocal8Bit() + " :" + + nickname.toLocal8Bit() + "\r\n"); socket.write("NICK " + nickname.toLocal8Bit() + "\r\n"); sendPrivmsg("Ready to process requests!"); } -void OsuIrcClient::refreshData() -{ +void OsuIrcClient::refreshData() { qDebug() << "[osu!IRC] Refreshing data..."; QSettings settings; @@ -52,67 +51,57 @@ void OsuIrcClient::refreshData() } -void OsuIrcClient::restart() -{ +void OsuIrcClient::restart() { socket.close(); init(); } -void OsuIrcClient::onConnected() -{ +void OsuIrcClient::onConnected() { qDebug() << "[osu!IRC] Connected to: " << socket.peerAddress().toString(); emit connected(); } -void OsuIrcClient::onDisconnected() -{ +void OsuIrcClient::onDisconnected() { qDebug() << "[osu!IRC] Disconnected from: " << socket.peerAddress().toString(); emit disconnected(); } -void OsuIrcClient::setNickname(const QString &nickname) -{ - this->nickname = nickname; +void OsuIrcClient::setNickname(const QString &newNickname) { + nickname = newNickname; } -void OsuIrcClient::setPassword(const QString &password) -{ - this->password = password; +void OsuIrcClient::setPassword(const QString &newPassword) { + password = newPassword; } -void OsuIrcClient::setServer(const QString &server) -{ - this->server = server; +void OsuIrcClient::setServer(const QString &newServer) { + server = newServer; } -void OsuIrcClient::setPort(const int &port) -{ - this->port = port; +void OsuIrcClient::setPort(const int &newPort) { + port = newPort; } -void OsuIrcClient::sendPrivmsg(QString message) -{ +void OsuIrcClient::sendPrivmsg(const QString &message) { socket.write("PRIVMSG " + nickname.toLocal8Bit() + " :" + message.toLocal8Bit() + "\r\n"); } -void OsuIrcClient::sendMap(QUrl url, TwitchDataWrapper message) -{ +void OsuIrcClient::sendMap(const QUrl &url, TwitchDataWrapper message) { qDebug() << "[osu!IRC] Sending map-request: " << url.toString() << " by " << message.getUsername(); - QString msg = QString("[%1 Map request] sent by %2").arg(url.toString()).arg(message.getUsername()); + QString msg = QString("[%1 Map request] sent by %2").arg(url.toString(), message.getUsername()); sendPrivmsg(msg); } -void OsuIrcClient::sendMap(QJsonObject map, TwitchDataWrapper message) -{ +void OsuIrcClient::sendMap(QJsonObject map, TwitchDataWrapper message) { QString requestor = message.getUsername(); QString artist = map["beatmapset"].toObject()["artist"].toString(); QString title = map["beatmapset"].toObject()["title"].toString(); @@ -120,30 +109,25 @@ void OsuIrcClient::sendMap(QJsonObject map, TwitchDataWrapper message) int mapId = map["id"].toInt(); QString url = QString("https://osu.ppy.sh/b/%1").arg(mapId); - qDebug() << "[osu!IRC] Sending map-request: " << url << " by " << requestor << " (" << artist << " - " << title << " - " << status << ")"; + qDebug() << "[osu!IRC] Sending map-request: " << url << " by " << requestor << " (" << artist << " - " << title + << " - " << status << ")"; QString msg = QString("(%1) [%2 %3 - %4] sent by %5") - .arg(status) - .arg(url) - .arg(artist) - .arg(title) - .arg(message.getUsername()); + .arg(status, url, artist, title, message.getUsername()); sendPrivmsg(msg); } -void OsuIrcClient::handlePing(QString response) -{ +void OsuIrcClient::handlePing() { socket.write("PONG :\r\n"); qDebug() << "[osu!IRC] PING request handled"; } -void OsuIrcClient::onReadyRead() -{ +void OsuIrcClient::onReadyRead() { auto data = QString(socket.readAll()); - if(data.contains("PING")) { - handlePing(data.split(" ").last().toLocal8Bit()); + if (data.contains("PING")) { + handlePing(); } emit readyRead(); } diff --git a/src/osu/irc/osuircclient.h b/src/osu/irc/osuircclient.h index d20aaa6..3859885 100644 --- a/src/osu/irc/osuircclient.h +++ b/src/osu/irc/osuircclient.h @@ -9,36 +9,37 @@ #include "twitchdatawrapper.h" +// @formatter:off class OsuIrcClient : public QObject { Q_OBJECT public: explicit OsuIrcClient(QObject *parent = nullptr); - explicit OsuIrcClient( - const QString &nickname, - const QString &password, - const QString &server, - const int &port, - QObject *parent = nullptr + [[maybe_unused]] explicit OsuIrcClient( + QString nickname, + QString password, + QString server, + const int &port, + QObject *parent = nullptr ); void init(); void initSignals(); void restart(); - void setNickname(const QString &nickname); - void setPassword(const QString &password); - void setServer(const QString &server); - void setPort(const int &port); - void sendPrivmsg(QString message); - void sendMap(QUrl url, TwitchDataWrapper message); + void setNickname(const QString &newNickname); + void setPassword(const QString &newPassword); + void setServer(const QString &newServer); + void setPort(const int &newPort); + void sendPrivmsg(const QString &message); + void sendMap(const QUrl &url, TwitchDataWrapper message); void sendMap(QJsonObject map, TwitchDataWrapper message); private: - void handlePing(QString response); + void handlePing(); void refreshData(); QString nickname; QString password; QString server; - int port; + int port{}; QTcpSocket socket; signals: @@ -51,5 +52,6 @@ class OsuIrcClient : public QObject { void onReadyRead(); void onDisconnected(); }; +// @formatter:on #endif // OSUIRCCLIENT_H diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 027eeb5..ec8a6cf 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -2,9 +2,8 @@ #include "ui_preferences.h" Preferences::Preferences(QWidget *parent) : - QDialog(parent), - ui(new Ui::Preferences) -{ + QDialog(parent), + ui(new Ui::Preferences) { ui->setupUi(this); connect(ui->listWidget, &QListWidget::currentItemChanged, this, &Preferences::on_listWidget_currentItemChanged); connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &Preferences::on_saveBtnClicked); @@ -16,14 +15,12 @@ Preferences::Preferences(QWidget *parent) : } -Preferences::~Preferences() -{ +Preferences::~Preferences() { delete ui; } -void Preferences::setupUi() -{ +void Preferences::setupUi() { // TODO: this should be a standalone widget. auto *portValidator = new QIntValidator(0, 65535, this); ui->gosumemoryPortLineEdit->setValidator(portValidator); @@ -33,18 +30,17 @@ void Preferences::setupUi() // TODO: this should be a standalone widget. QString IpRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"; QRegularExpression IpRegex("^" + IpRange + "\\." + IpRange + "\\." + IpRange + "\\." + IpRange + "$"); - QRegularExpressionValidator *IpValidator = new QRegularExpressionValidator(IpRegex, this); + auto *IpValidator = new QRegularExpressionValidator(IpRegex, this); ui->gosumemoryIpLineEdit->setValidator(IpValidator); // TODO: this should be a standalone widget. QRegularExpression oauthRegex("^oauth:.{30}$"); - QRegularExpressionValidator *oauthValidator = new QRegularExpressionValidator(oauthRegex, this); + auto *oauthValidator = new QRegularExpressionValidator(oauthRegex, this); ui->twitchBotOAuthLineEdit->setValidator(oauthValidator); } -void Preferences::loadSettings() -{ +void Preferences::loadSettings() { loadGosuMemorySettings(); loadTwitchSettings(); loadOsuIrcSettings(); @@ -53,30 +49,26 @@ void Preferences::loadSettings() } -void Preferences::loadTwitchSettings() -{ +void Preferences::loadTwitchSettings() { ui->twitchBotNickLineEdit->setText(settings.value("twitch/botNick").toString()); ui->twitchBotOAuthLineEdit->setText(settings.value("twitch/oauth").toString()); ui->twitchChannelLineEdit->setText(settings.value("twitch/channel").toString()); } -void Preferences::loadOsuApiSettings() -{ +void Preferences::loadOsuApiSettings() { ui->osuapiClientIdLineEdit->setText(settings.value("osuapi/clientId").toString()); ui->osuapiClientSecretLineEdit->setText(settings.value("osuapi/clientSecret").toString()); } -void Preferences::loadGosuMemorySettings() -{ +void Preferences::loadGosuMemorySettings() { ui->gosumemoryIpLineEdit->setText(settings.value("gosumemory/ip").toString()); ui->gosumemoryPortLineEdit->setText(settings.value("gosumemory/port").toString()); } -void Preferences::loadOsuIrcSettings() -{ +void Preferences::loadOsuIrcSettings() { ui->osuIrcNicknameLineEdit->setText(settings.value("osuirc/nick").toString()); ui->osuIrcPasswordLineEdit->setText(settings.value("osuirc/password").toString()); ui->osuIrcServerLineEdit->setText(settings.value("osuirc/server").toString()); @@ -84,14 +76,12 @@ void Preferences::loadOsuIrcSettings() } -void Preferences::loadThemeSettings() -{ +void Preferences::loadThemeSettings() { auto darkModeSetting = settings.value("theme/darkMode"); - if(darkModeSetting.isNull()){ + if (darkModeSetting.isNull()) { ui->themesDefaultRadio->setChecked(true); - } - else { + } else { bool isDarkMode = darkModeSetting.toBool(); QRadioButton *button = isDarkMode ? ui->themesDarkRadio : ui->themesLightRadio; button->setChecked(true); @@ -99,17 +89,15 @@ void Preferences::loadThemeSettings() } -void Preferences::on_saveBtnClicked() -{ +void Preferences::on_saveBtnClicked() { saveSettings(); - QMessageBox().information(this, "Saved", "Settings saved"); + QMessageBox::information(this, "Saved", "Settings saved"); emit themeChanged(); accept(); } -void Preferences::saveSettings() -{ +void Preferences::saveSettings() { settings.setValue("twitch/botNick", ui->twitchBotNickLineEdit->text().toLower()); settings.setValue("twitch/oauth", ui->twitchBotOAuthLineEdit->text()); settings.setValue("twitch/channel", ui->twitchChannelLineEdit->text().toLower()); @@ -129,26 +117,24 @@ void Preferences::saveSettings() if (ui->themesDefaultRadio->isChecked()) { settings.remove("theme/darkMode"); - } - else { + } else { settings.setValue("theme/darkMode", ui->themesDarkRadio->isChecked()); } } -void Preferences::on_backupBtn_clicked() -{ +void Preferences::on_backupBtn_clicked() { QString message = QString("%1
%2").arg( - "Would you like to include sensitive informations in your backup file?", - "Anyone that has this information will be able to access your accounts!" + "Would you like to include sensitive informations in your backup file?", + "Anyone that has this information will be able to access your accounts!" ); - auto buttonAnswer = QMessageBox().question( - this, - "Sensitive information", - message, - QMessageBox::No | QMessageBox::Yes, - QMessageBox::No + auto buttonAnswer = QMessageBox::question( + this, + "Sensitive information", + message, + QMessageBox::No | QMessageBox::Yes, + QMessageBox::No ); bool includeSensitiveInfo = buttonAnswer == QMessageBox::Yes; @@ -157,18 +143,16 @@ void Preferences::on_backupBtn_clicked() } -void Preferences::on_restoreBtn_clicked() -{ +void Preferences::on_restoreBtn_clicked() { QString filePath = QFileDialog::getOpenFileName(nullptr, "Import Settings", QString(), "JSON Files (*.json)"); Backup::restore(filePath); // reloading loadSettings(); - QMessageBox().information(this, "Backup Restored", "Backup restored successfully"); + QMessageBox::information(this, "Backup Restored", "Backup restored successfully"); } -void Preferences::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) -{ +void Preferences::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) { if (current == nullptr) return; auto index = ui->listWidget->currentRow(); diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index 0868591..7c30da3 100644 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -15,36 +15,37 @@ #include "backup.h" namespace Ui { - class Preferences; + class Preferences; } -class Preferences : public QDialog -{ - Q_OBJECT - -public: - explicit Preferences(QWidget *parent = nullptr); - ~Preferences(); - -private: - Ui::Preferences *ui; - QSettings settings; - void loadSettings(); - void loadTwitchSettings(); - void loadGosuMemorySettings(); - void loadOsuApiSettings(); - void loadOsuIrcSettings(); - void loadThemeSettings(); - void setupUi(); - void saveSettings(); - - void on_saveBtnClicked(); - void on_backupBtn_clicked(); - void on_restoreBtn_clicked(); - void on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous); - -signals: - void themeChanged(); +// @formatter:off +class Preferences : public QDialog { + Q_OBJECT + + public: + explicit Preferences(QWidget *parent = nullptr); + ~Preferences() override; + + private: + Ui::Preferences *ui; + QSettings settings; + void loadSettings(); + void loadTwitchSettings(); + void loadGosuMemorySettings(); + void loadOsuApiSettings(); + void loadOsuIrcSettings(); + void loadThemeSettings(); + void setupUi(); + void saveSettings(); + + void on_saveBtnClicked(); + void on_backupBtn_clicked(); + void on_restoreBtn_clicked(); + void on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous); + + signals: + void themeChanged(); }; +// @formatter:on #endif // PREFERENCES_H diff --git a/src/services/streaming/streamingServiceDataWrapper.h b/src/services/streaming/streamingServiceDataWrapper.h index 7f957f4..d8d6012 100644 --- a/src/services/streaming/streamingServiceDataWrapper.h +++ b/src/services/streaming/streamingServiceDataWrapper.h @@ -3,11 +3,12 @@ #include -class StreamingServiceDataWrapper -{ -public: - virtual QString getMessage() = 0; - virtual QString getUsername() = 0; +// @formatter:off +class StreamingServiceDataWrapper { + public: + virtual QString getMessage() = 0; + virtual QString getUsername() = 0; }; +// @formatter:on #endif // STREAMINGSERVICEDATAWRAPPER_H diff --git a/src/services/streaming/twitch/twitchClient.cpp b/src/services/streaming/twitch/twitchClient.cpp index 60081ca..74940a9 100644 --- a/src/services/streaming/twitch/twitchClient.cpp +++ b/src/services/streaming/twitch/twitchClient.cpp @@ -1,41 +1,39 @@ #include "twitchClient.h" -TwitchClient::TwitchClient( - const QUrl &url, - const QString &botNick, - const QString &oauth, - const QString &channel, - QObject *parent -) : QObject(parent), url(url), oauth(oauth), botNick(botNick), channel(channel) -{ +#include + +[[maybe_unused]] TwitchClient::TwitchClient( + QUrl url, + QString botNick, + QString oauth, + QString channel, + QObject *parent +) : QObject(parent), url(std::move(url)), oauth(std::move(oauth)), botNick(std::move(botNick)), + channel(std::move(channel)) { initSignals(); } -TwitchClient::TwitchClient(QObject *parent) : QObject(parent) -{ +TwitchClient::TwitchClient(QObject *parent) : QObject(parent) { initSignals(); } -void TwitchClient::initSignals() -{ +void TwitchClient::initSignals() { connect(&socket, &QWebSocket::connected, this, &TwitchClient::onConnected); connect(&socket, &QWebSocket::textMessageReceived, this, &TwitchClient::onTextMessageReceived); connect(&socket, &QWebSocket::disconnected, this, &TwitchClient::onDisconnected); } -void TwitchClient::init() -{ +void TwitchClient::init() { refreshData(); qDebug() << "[TwitchClient] Connecting to: " << url.toString(); socket.open(QUrl(url)); } -void TwitchClient::refreshData() -{ +void TwitchClient::refreshData() { qDebug() << "[TwitchClient] Refreshing data..."; QSettings settings; @@ -46,29 +44,25 @@ void TwitchClient::refreshData() } -void TwitchClient::restart() -{ +void TwitchClient::restart() { socket.close(); init(); } -void TwitchClient::sendChatMessage(QString message) -{ +void TwitchClient::sendChatMessage(const QString &message) { qDebug() << "[TwitchClient] Sending channel message: " << message; socket.sendTextMessage("PRIVMSG #" + channel + " :" + message); } -void TwitchClient::sendMessage(QString message) -{ +void TwitchClient::sendMessage(const QString &message) { qDebug() << "[TwitchClient] Sending message: " << message; socket.sendTextMessage(message); } -void TwitchClient::onConnected() -{ +void TwitchClient::onConnected() { qDebug() << "[TwitchClient] Connected to: " << url.toString(); emit connected(); sendMessage("PASS " + oauth); @@ -77,8 +71,7 @@ void TwitchClient::onConnected() } -void TwitchClient::onTextMessageReceived(QString message) -{ +void TwitchClient::onTextMessageReceived(QString message) { auto wrappedMessage = TwitchDataWrapper(message); qDebug() << "[TwitchClient] Message received from: " << url.toString(); @@ -96,15 +89,13 @@ void TwitchClient::onTextMessageReceived(QString message) } -void TwitchClient::handlePing() -{ +void TwitchClient::handlePing() { qDebug() << "[TwitchClient] Handling ping"; sendMessage("PONG :tmi.twitch.tv"); } -bool TwitchClient::shouldBeFiltered(QString message) -{ +bool TwitchClient::shouldBeFiltered(const QString &message) { // TODO: this can be done better, i think. if (message.startsWith("PING")) { handlePing(); @@ -122,8 +113,7 @@ bool TwitchClient::shouldBeFiltered(QString message) } -bool TwitchClient::isCommand(QString message) -{ +bool TwitchClient::isCommand(const QString &message) { if (message.startsWith("!")) { return true; } @@ -131,32 +121,27 @@ bool TwitchClient::isCommand(QString message) } -void TwitchClient::onDisconnected() -{ +void TwitchClient::onDisconnected() { qDebug() << "[TwitchClient] Disconnected from:" << url.toString(); emit disconnected(); } -void TwitchClient::setChannel(QString channel) -{ - this->channel = channel; +void TwitchClient::setChannel(QString newChannel) { + channel = std::move(newChannel); } -void TwitchClient::setBotNick(QString botNick) -{ - this->botNick = botNick; +void TwitchClient::setBotNick(QString newBotNick) { + botNick = std::move(newBotNick); } -void TwitchClient::setOauth(QString oauth) -{ - this->oauth = oauth; +void TwitchClient::setOauth(QString newOauth) { + oauth = std::move(newOauth); } -void TwitchClient::setUrl(QUrl url) -{ - this->url = QUrl(url); +void TwitchClient::setUrl(QUrl newUrl) { + url = QUrl(std::move(newUrl)); } diff --git a/src/services/streaming/twitch/twitchClient.h b/src/services/streaming/twitch/twitchClient.h index 70a11d0..934c46e 100644 --- a/src/services/streaming/twitch/twitchClient.h +++ b/src/services/streaming/twitch/twitchClient.h @@ -10,34 +10,34 @@ #include "twitchdatawrapper.h" +// @formatter:off class TwitchClient : public QObject { Q_OBJECT public: explicit TwitchClient(QObject *parent = nullptr); - explicit TwitchClient( - const QUrl &url, - const QString &botNick, - const QString &oauth, - const QString &channel, + [[maybe_unused]] explicit TwitchClient( + QUrl url, + QString botNick, + QString oauth, + QString channel, QObject *parent = nullptr ); void init(); void restart(); - void setChannel(QString channel); - void setBotNick(QString botNick); - void setOauth(QString oauth); - void setUrl(QUrl url); - void sendChatMessage(QString message); + void setChannel(QString newChannel); + void setBotNick(QString newBotNick); + void setOauth(QString newOauth); + void setUrl(QUrl newUrl); + void sendChatMessage(const QString& message); private: void handlePing(); - bool isCommand(QString message); + static bool isCommand(const QString& message); void initSignals(); void refreshData(); - void sendMessage(QString message); - bool shouldBeFiltered(QString message); - + void sendMessage(const QString& message); + bool shouldBeFiltered(const QString& message); QWebSocket socket; QUrl url; QString oauth; @@ -55,5 +55,6 @@ class TwitchClient : public QObject { void onTextMessageReceived(QString message); void onDisconnected(); }; +// @formatter:on #endif diff --git a/src/services/streaming/twitch/twitchdatawrapper.cpp b/src/services/streaming/twitch/twitchdatawrapper.cpp index bd306a3..6adfcf5 100644 --- a/src/services/streaming/twitch/twitchdatawrapper.cpp +++ b/src/services/streaming/twitch/twitchdatawrapper.cpp @@ -1,26 +1,22 @@ #include "twitchdatawrapper.h" TwitchDataWrapper::TwitchDataWrapper(QString &data) - : data(data) -{ + : data(data) { parseData(); } -void TwitchDataWrapper::parseData() -{ +void TwitchDataWrapper::parseData() { message = data.mid(data.indexOf(":", 1) + 1).trimmed(); username = data.mid(data.indexOf("!", 1) + 1, data.indexOf("!", 1) - 1); } -QString TwitchDataWrapper::getMessage() -{ +QString TwitchDataWrapper::getMessage() { return message; } -QString TwitchDataWrapper::getUsername() -{ +QString TwitchDataWrapper::getUsername() { return username; } diff --git a/src/services/streaming/twitch/twitchdatawrapper.h b/src/services/streaming/twitch/twitchdatawrapper.h index 98ceafb..b5b897a 100644 --- a/src/services/streaming/twitch/twitchdatawrapper.h +++ b/src/services/streaming/twitch/twitchdatawrapper.h @@ -4,18 +4,19 @@ #include #include "streamingServiceDataWrapper.h" -class TwitchDataWrapper : public StreamingServiceDataWrapper -{ -public: - TwitchDataWrapper(QString &data); - QString getMessage(); - QString getUsername(); +// @formatter:off +class TwitchDataWrapper : public StreamingServiceDataWrapper { + public: + explicit TwitchDataWrapper(QString &data); + QString getMessage() override; + QString getUsername() override; -private: - void parseData(); - QString data; - QString message; - QString username; + private: + void parseData(); + QString data; + QString message; + QString username; }; +// @formatter:on #endif // TWITCHDATAWRAPPER_H diff --git a/src/setupwizard/setupwizard.cpp b/src/setupwizard/setupwizard.cpp index 0b3adf7..47b0ebe 100644 --- a/src/setupwizard/setupwizard.cpp +++ b/src/setupwizard/setupwizard.cpp @@ -2,21 +2,18 @@ #include "ui_setupwizard.h" SetupWizard::SetupWizard(QWidget *parent) : - QWizard(parent), - ui(new Ui::SetupWizard) -{ + QWizard(parent), + ui(new Ui::SetupWizard) { ui->setupUi(this); setupUi(); } -SetupWizard::~SetupWizard() -{ +SetupWizard::~SetupWizard() { delete ui; } -void SetupWizard::setupUi() -{ +void SetupWizard::setupUi() { // TODO: this should be a standalone widget. auto *portValidator = new QIntValidator(0, 65535, this); ui->gosumemoryPortLineEdit->setValidator(portValidator); @@ -25,12 +22,12 @@ void SetupWizard::setupUi() // TODO: this should be a standalone widget. QString IpRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"; QRegularExpression IpRegex("^" + IpRange + "\\." + IpRange + "\\." + IpRange + "\\." + IpRange + "$"); - QRegularExpressionValidator *IpValidator = new QRegularExpressionValidator(IpRegex, this); + auto *IpValidator = new QRegularExpressionValidator(IpRegex, this); ui->gosumemoryIpLineEdit->setValidator(IpValidator); // TODO: this should be a standalone widget. QRegularExpression oauthRegex("^oauth:.{30}$"); - QRegularExpressionValidator *oauthValidator = new QRegularExpressionValidator(oauthRegex, this); + auto *oauthValidator = new QRegularExpressionValidator(oauthRegex, this); ui->twitchOauthLineEdit->setValidator(oauthValidator); ui->gosumemoryExplanationLabel->setOpenExternalLinks(true); @@ -39,8 +36,7 @@ void SetupWizard::setupUi() } -void SetupWizard::on_SetupWizard_finished(int result) -{ +[[maybe_unused]] void SetupWizard::on_SetupWizard_finished(int result) { if (result == 1) { QJsonObject data = gatherData(); saveData(data); @@ -50,8 +46,7 @@ void SetupWizard::on_SetupWizard_finished(int result) } -QJsonObject SetupWizard::gatherData() -{ +QJsonObject SetupWizard::gatherData() { QJsonObject data; data["gosumemory"] = getGosumemoryData(); data["osuapi"] = getOsuApiData(); @@ -62,50 +57,46 @@ QJsonObject SetupWizard::gatherData() } -QJsonObject SetupWizard::getGosumemoryData() -{ +QJsonObject SetupWizard::getGosumemoryData() { QString gosuIp = ui->gosumemoryIpLineEdit->text(); int gosuPort = ui->gosumemoryPortLineEdit->text().toInt(); QJsonObject gosumemoryData = QJsonObject{ - {"ip", gosuIp}, - {"port", gosuPort} + {"ip", gosuIp}, + {"port", gosuPort} }; return gosumemoryData; } -QJsonObject SetupWizard::getOsuApiData() -{ +QJsonObject SetupWizard::getOsuApiData() { int osuapiClientId = ui->osuapiClientIdLineEdit->text().toInt(); QString osuapiClientSecret = ui->osuapiClientSecretLineEdit->text(); QJsonObject osuapiClientData = QJsonObject{ - {"clientId", osuapiClientId}, - {"clientSecret", osuapiClientSecret} + {"clientId", osuapiClientId}, + {"clientSecret", osuapiClientSecret} }; return osuapiClientData; } -QJsonObject SetupWizard::getTwitchData() -{ +QJsonObject SetupWizard::getTwitchData() { QString twitchBotNick = ui->twitchBotNickLineEdit->text(); QString twitchOauth = ui->twitchOauthLineEdit->text(); QString twitchChannel = ui->twitchChannelLineEdit->text(); QJsonObject twitchData = QJsonObject{ - {"botNick", twitchBotNick.toLower()}, - {"oauth", twitchOauth}, - {"channel", twitchChannel.toLower()} + {"botNick", twitchBotNick.toLower()}, + {"oauth", twitchOauth}, + {"channel", twitchChannel.toLower()} }; return twitchData; } -QJsonObject SetupWizard::getOsuircData() -{ +QJsonObject SetupWizard::getOsuircData() { QString osuircNick = ui->osuircNickLineEdit->text(); QString osuircPassword = ui->osuircPasswordLineEdit->text(); QString osuircServer = ui->osuircServerLineEdit->text(); @@ -116,19 +107,18 @@ QJsonObject SetupWizard::getOsuircData() osuircNick.replace(' ', '_'); QJsonObject osuircData = QJsonObject{ - {"nick", osuircNick}, - {"password", osuircPassword}, - {"server", osuircServer}, - {"port", osuircPort} + {"nick", osuircNick}, + {"password", osuircPassword}, + {"server", osuircServer}, + {"port", osuircPort} }; return osuircData; } -void SetupWizard::saveData(QJsonObject data) -{ - QSettings settings; +void SetupWizard::saveData(QJsonObject data) { + QSettings settings; QJsonObject osuapiData = data["osuapi"].toObject(); QJsonObject gosumemoryData = data["gosumemory"].toObject(); QJsonObject twitchData = data["twitch"].toObject(); diff --git a/src/setupwizard/setupwizard.h b/src/setupwizard/setupwizard.h index ac6016e..45c1fec 100644 --- a/src/setupwizard/setupwizard.h +++ b/src/setupwizard/setupwizard.h @@ -7,33 +7,34 @@ #include namespace Ui { - class SetupWizard; + class SetupWizard; } -class SetupWizard : public QWizard -{ +// @formatter:off +class SetupWizard : public QWizard { Q_OBJECT -public: - explicit SetupWizard(QWidget *parent = nullptr); - ~SetupWizard(); + public: + explicit SetupWizard(QWidget *parent = nullptr); + ~SetupWizard() override; -signals: - void wizardFinished(QJsonObject json); + signals: + void wizardFinished(QJsonObject json); -private slots: - void on_SetupWizard_finished(int result); + private slots: + [[maybe_unused]] void on_SetupWizard_finished(int result); -private: - void setupUi(); + private: + void setupUi(); - QJsonObject gatherData(); - QJsonObject getGosumemoryData(); - QJsonObject getOsuApiData(); - QJsonObject getTwitchData(); - QJsonObject getOsuircData(); - void saveData(QJsonObject data); - Ui::SetupWizard *ui; + QJsonObject gatherData(); + QJsonObject getGosumemoryData(); + QJsonObject getOsuApiData(); + QJsonObject getTwitchData(); + QJsonObject getOsuircData(); + static void saveData(QJsonObject data); + Ui::SetupWizard *ui; }; +// @formatter:on #endif // SETUPWIZARD_H diff --git a/src/skinsurl/skinsurl.cpp b/src/skinsurl/skinsurl.cpp index 454608a..7d90404 100644 --- a/src/skinsurl/skinsurl.cpp +++ b/src/skinsurl/skinsurl.cpp @@ -2,10 +2,7 @@ #include "ui_skinsurl.h" SkinsUrl::SkinsUrl(GosumemoryClient *client, QWidget *parent) : - QDialog(parent) - , gosumemoryClient(client) - , ui(new Ui::SkinsUrl) -{ + QDialog(parent), gosumemoryClient(client), ui(new Ui::SkinsUrl) { ui->setupUi(this); loadData(); @@ -19,28 +16,24 @@ SkinsUrl::SkinsUrl(GosumemoryClient *client, QWidget *parent) : } -SkinsUrl::~SkinsUrl() -{ +SkinsUrl::~SkinsUrl() { delete ui; } -void SkinsUrl::loadData() -{ +void SkinsUrl::loadData() { qDebug() << "[Osu!Skins] Loading data"; QSettings settings; settings.beginGroup("skin"); auto skins = settings.childKeys(); - for (auto skin : skins) - { + for (const auto &skin: skins) { addRow(skin, settings.value(skin).toString()); } } -void SkinsUrl::on_addSkinBtn_clicked() -{ +void SkinsUrl::on_addSkinBtn_clicked() { auto skins = getListedSkins(); auto skinName = getSkinName(); @@ -53,17 +46,16 @@ void SkinsUrl::on_addSkinBtn_clicked() } -void SkinsUrl::on_removeSkinBtn_clicked() -{ +void SkinsUrl::on_removeSkinBtn_clicked() { QSettings settings; auto selectionModel = ui->skinURLsTable->selectionModel(); - if (!selectionModel->hasSelection()){ + if (!selectionModel->hasSelection()) { return; } auto selected = selectionModel->selectedIndexes(); - for (auto selection : selected) { + for (auto selection: selected) { auto row = selection.row(); auto skinName = ui->skinURLsTable->item(row, 0)->text(); @@ -73,23 +65,22 @@ void SkinsUrl::on_removeSkinBtn_clicked() } -void SkinsUrl::on_saveBtnClicked() -{ +void SkinsUrl::on_saveBtnClicked() { qDebug() << "[Osu!Skins] Saving data"; for (int row = 0; row < ui->skinURLsTable->rowCount(); row++) { auto skinNameItem = ui->skinURLsTable->item(row, 0); - auto skinUrlItem = ui->skinURLsTable->item(row, 1); + auto skinUrlItem = ui->skinURLsTable->item(row, 1); if (skinUrlItem == nullptr || skinNameItem == nullptr) { return; } auto skinName = skinNameItem->text(); - auto skinUrl = skinUrlItem->text(); + auto skinUrl = skinUrlItem->text(); if (!isUrl(skinUrl)) { - QMessageBox().critical(this, "Error", "Invalid url"); + QMessageBox::critical(this, "Error", "Invalid url"); break; } @@ -97,47 +88,44 @@ void SkinsUrl::on_saveBtnClicked() QString key = QString("skin/%1").arg(skinName); settings.setValue(key, skinUrl); } - accept(); + accept(); } -void SkinsUrl::on_gosumemoryMessage_received(GosuMemoryDataWrapper message) -{ +void SkinsUrl::on_gosumemoryMessage_received(GosuMemoryDataWrapper message) { ui->addSkinBtn->setEnabled(true); ui->currentSkinLabel->setText(message.getSkinName()); } -void SkinsUrl::addRow(QString skinName, QString skinUrl) -{ +void SkinsUrl::addRow(const QString &skinName, const QString &skinUrl) { // adding new line ui->skinURLsTable->insertRow(ui->skinURLsTable->rowCount()); auto skinNameItem = new QTableWidgetItem(skinName); - skinNameItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); + skinNameItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); // Skin Name column ui->skinURLsTable->setItem( - ui->skinURLsTable->rowCount() - 1, - 0, - skinNameItem + ui->skinURLsTable->rowCount() - 1, + 0, + skinNameItem ); // Skin URL column ui->skinURLsTable->setItem( - ui->skinURLsTable->rowCount() - 1, - 1, - new QTableWidgetItem(skinUrl) + ui->skinURLsTable->rowCount() - 1, + 1, + new QTableWidgetItem(skinUrl) ); } -QStringList SkinsUrl::getListedSkins() -{ +QStringList SkinsUrl::getListedSkins() { QStringList skins; for (int row = 0; row < ui->skinURLsTable->rowCount(); row++) { auto value = ui->skinURLsTable->item(row, 0); - if (value == nullptr){ + if (value == nullptr) { continue; } skins << value->text(); @@ -146,14 +134,12 @@ QStringList SkinsUrl::getListedSkins() } -QString SkinsUrl::getSkinName() -{ +QString SkinsUrl::getSkinName() { return ui->currentSkinLabel->text(); } -bool SkinsUrl::isUrl(QString url) -{ - QRegularExpression rx("(https?:\\/\\/)?(www)?.*\\.(.){2,}"); +bool SkinsUrl::isUrl(const QString &url) { + QRegularExpression rx(R"((https?:\/\/)?(www)?.*\.(.){2,})"); return rx.globalMatch(url).hasNext(); } diff --git a/src/skinsurl/skinsurl.h b/src/skinsurl/skinsurl.h index 9d5fb1f..5015fe1 100644 --- a/src/skinsurl/skinsurl.h +++ b/src/skinsurl/skinsurl.h @@ -7,31 +7,32 @@ #include "osu/data/gosu/gosumemorydatawrapper.h" namespace Ui { - class SkinsUrl; + class SkinsUrl; } -class SkinsUrl : public QDialog -{ - Q_OBJECT +// @formatter:off +class SkinsUrl : public QDialog { + Q_OBJECT -public: - explicit SkinsUrl(GosumemoryClient *client, QWidget *parent = nullptr); - ~SkinsUrl(); + public: + explicit SkinsUrl(GosumemoryClient *client, QWidget *parent = nullptr); + ~SkinsUrl() override; -private: - void on_addSkinBtn_clicked(); - void on_removeSkinBtn_clicked(); - void on_gosumemoryMessage_received(GosuMemoryDataWrapper message); - void on_saveBtnClicked(); + private: + void on_addSkinBtn_clicked(); + void on_removeSkinBtn_clicked(); + void on_gosumemoryMessage_received(GosuMemoryDataWrapper message); + void on_saveBtnClicked(); - void loadData(); - void addRow(QString skinName, QString skinUrl = ""); - QStringList getListedSkins(); - QString getSkinName(); - bool isUrl(QString str); + void loadData(); + void addRow(const QString& skinName, const QString& skinUrl = ""); + QStringList getListedSkins(); + QString getSkinName(); + static bool isUrl(const QString& str); - Ui::SkinsUrl *ui; - GosumemoryClient *gosumemoryClient; + Ui::SkinsUrl *ui; + GosumemoryClient *gosumemoryClient; }; +// @formatter:on #endif // SKINSURL_H diff --git a/src/theme/theme.cpp b/src/theme/theme.cpp index 9b130bb..572c68e 100644 --- a/src/theme/theme.cpp +++ b/src/theme/theme.cpp @@ -1,8 +1,7 @@ #include "theme.h" -void Theme::loadTheme() -{ +void Theme::loadTheme() { qDebug() << "[Theme] Loading theme..."; QSettings settings; bool isDarkMode; @@ -12,42 +11,38 @@ void Theme::loadTheme() if (darkModeSettingExists) { // If present, prefer local settings. loadThemeFromSetting(darkModeSetting); - } - else { - #ifdef Q_OS_WIN - loadDefaultThemeWindows(); - #else - loadLightMode(); - #endif + } else { +#ifdef Q_OS_WIN + loadDefaultThemeWindows(); +#else + loadLightMode(); +#endif } qDebug() << "[Theme] Theme loaded"; } -void Theme::loadThemeFromSetting(QVariant darkModeSetting) -{ +void Theme::loadThemeFromSetting(const QVariant &darkModeSetting) { qDebug() << "[Theme] Loading theme from settings..."; bool isDarkMode = darkModeSetting.toBool(); if (isDarkMode) { loadDarkMode(); - } - else { + } else { loadLightMode(); } qDebug() << "[Theme] Theme loaded from settings"; } -void Theme::loadDefaultThemeWindows() -{ +void Theme::loadDefaultThemeWindows() { qDebug() << "[Theme](Windows) Loading system theme..."; // In windows>=10, you can set a default behaviour for app themes in the settings menu. // TODO: Check for major and minor version of windows. // Perhaps this can be used in linux and macos too? QSettings windowsSettings( - "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", - QSettings::NativeFormat + R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", + QSettings::NativeFormat ); auto isDarkMode = windowsSettings.value("AppsUseLightTheme") == 0; @@ -58,17 +53,16 @@ void Theme::loadDefaultThemeWindows() } -void Theme::loadDarkMode() -{ +void Theme::loadDarkMode() { qDebug() << "[Theme] Loading dark theme..."; qApp->setStyle(QStyleFactory::create("Fusion")); QPalette darkPalette; - QColor darkColor = QColor(45,45,45); - QColor disabledColor = QColor(127,127,127); + QColor darkColor = QColor(45, 45, 45); + QColor disabledColor = QColor(127, 127, 127); darkPalette.setColor(QPalette::Window, darkColor); darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, QColor(18,18,18)); + darkPalette.setColor(QPalette::Base, QColor(18, 18, 18)); darkPalette.setColor(QPalette::AlternateBase, darkColor); darkPalette.setColor(QPalette::ToolTipBase, Qt::white); darkPalette.setColor(QPalette::ToolTipText, Qt::white); @@ -89,8 +83,7 @@ void Theme::loadDarkMode() } -void Theme::loadLightMode() -{ +void Theme::loadLightMode() { qDebug() << "[Theme] Loading light theme..."; QPalette lightPalette; qApp->setPalette(lightPalette); diff --git a/src/theme/theme.h b/src/theme/theme.h index 99178dd..8ff6945 100644 --- a/src/theme/theme.h +++ b/src/theme/theme.h @@ -9,16 +9,18 @@ #include #include -class Theme : public QObject -{ +// @formatter:off +class Theme : public QObject { Q_OBJECT -public: - static void loadTheme(); -private: - static void loadDarkMode(); - static void loadLightMode(); - static void loadThemeFromSetting(QVariant darkModeSettings); - static void loadDefaultThemeWindows(); + + public: + static void loadTheme(); + private: + static void loadDarkMode(); + static void loadLightMode(); + static void loadThemeFromSetting(const QVariant& darkModeSettings); + static void loadDefaultThemeWindows(); }; +// @formatter:on #endif // THEME_H diff --git a/src/twitchcommandhandler.cpp b/src/twitchcommandhandler.cpp index 46297fb..a0dd2e8 100644 --- a/src/twitchcommandhandler.cpp +++ b/src/twitchcommandhandler.cpp @@ -1,39 +1,34 @@ #include "twitchcommandhandler.h" -TwitchCommandHandler::TwitchCommandHandler() -{ +TwitchCommandHandler::TwitchCommandHandler() { twitchData = nullptr; gosumemoryData = nullptr; } -TwitchCommandHandler::TwitchCommandHandler(TwitchDataWrapper *twitchData, GosuMemoryDataWrapper *gosumemoryData) -{ - this->twitchData = twitchData; - this->gosumemoryData = gosumemoryData; +[[maybe_unused]] TwitchCommandHandler::TwitchCommandHandler(TwitchDataWrapper *newTwitchData, + GosuMemoryDataWrapper *newGosumemoryData) { + twitchData = newTwitchData; + gosumemoryData = newGosumemoryData; } -void TwitchCommandHandler::setGosumemoryData(GosuMemoryDataWrapper *gosumemoryData) -{ - this->gosumemoryData = gosumemoryData; +void TwitchCommandHandler::setGosumemoryData(GosuMemoryDataWrapper *newGosumemoryData) { + gosumemoryData = newGosumemoryData; } -GosuMemoryDataWrapper* TwitchCommandHandler::getGosumemoryData() -{ +GosuMemoryDataWrapper *TwitchCommandHandler::getGosumemoryData() { return gosumemoryData; } -TwitchDataWrapper* TwitchCommandHandler::getTwitchData() -{ +[[maybe_unused]] TwitchDataWrapper *TwitchCommandHandler::getTwitchData() { return twitchData; } -void TwitchCommandHandler::setTwitchData(TwitchDataWrapper *twitchData) -{ - this->twitchData = twitchData; +void TwitchCommandHandler::setTwitchData(TwitchDataWrapper *newTwitchData) { + twitchData = newTwitchData; } @@ -44,10 +39,8 @@ void TwitchCommandHandler::setTwitchData(TwitchDataWrapper *twitchData) * * @throws None */ -QString TwitchCommandHandler::getResponse() -{ +QString TwitchCommandHandler::getResponse() { QString command = twitchData->getMessage(); - QSettings settings; // handling !commands if (command.startsWith("!commands")) { @@ -57,17 +50,16 @@ QString TwitchCommandHandler::getResponse() // gosumemory dependent commands if (command.startsWith("!np") && gosumemoryData != nullptr) { return getResponseNowPlaying(); - } - else if (command.startsWith("!skin") && gosumemoryData != nullptr) { + } else if (command.startsWith("!skin") && gosumemoryData != nullptr) { return getResponseSkin(); } // static user commands QString response = getResponseStaticCommands(); - if (!response.isEmpty()){ + if (!response.isEmpty()) { return response; } - return QString(); + return {}; } /** @@ -78,14 +70,13 @@ QString TwitchCommandHandler::getResponse() * * @throws None */ -QString TwitchCommandHandler::getResponseStaticCommands() -{ +QString TwitchCommandHandler::getResponseStaticCommands() { QSettings settings; QString command = twitchData->getMessage(); settings.beginGroup("command"); QStringList commands = settings.childKeys(); - auto it = std::find_if(commands.begin(), commands.end(), [&](const QString& savedCommand){ + auto it = std::find_if(commands.begin(), commands.end(), [&](const QString &savedCommand) { return command.startsWith(savedCommand); }); if (it != commands.end()) { @@ -93,7 +84,7 @@ QString TwitchCommandHandler::getResponseStaticCommands() return response; } settings.endGroup(); - return QString(); + return {}; } /** @@ -103,12 +94,11 @@ QString TwitchCommandHandler::getResponseStaticCommands() * * @throws None */ -QString TwitchCommandHandler::getResponseAllCommands() -{ +QString TwitchCommandHandler::getResponseAllCommands() { QSettings settings; QString command = twitchData->getMessage(); if (!command.startsWith("!commands")) { - return QString(); + return {}; } settings.beginGroup("command"); @@ -124,8 +114,7 @@ QString TwitchCommandHandler::getResponseAllCommands() * * @return QString of the currently playing song's information */ -QString TwitchCommandHandler::getResponseNowPlaying() -{ +QString TwitchCommandHandler::getResponseNowPlaying() { QString mapName = gosumemoryData->getMapName(); QString mapArtist = gosumemoryData->getMapArtist(); QString mapDiff = gosumemoryData->getMapDifficulty(); @@ -141,8 +130,7 @@ QString TwitchCommandHandler::getResponseNowPlaying() * * @throws None */ -QString TwitchCommandHandler::getResponseSkin() -{ +QString TwitchCommandHandler::getResponseSkin() { QSettings settings; QString skinName = gosumemoryData->getSkinName(); QString skinResponse = QString("skin/%1").arg(skinName); diff --git a/src/twitchcommandhandler.h b/src/twitchcommandhandler.h index c219ef4..b0c03ba 100644 --- a/src/twitchcommandhandler.h +++ b/src/twitchcommandhandler.h @@ -7,25 +7,25 @@ #include "twitchdatawrapper.h" #include "osu/data/gosu/gosumemorydatawrapper.h" -class TwitchCommandHandler -{ -public: - TwitchCommandHandler(); - TwitchCommandHandler(TwitchDataWrapper *twitchData, GosuMemoryDataWrapper *gosumemoryData); - void setGosumemoryData(GosuMemoryDataWrapper *gosumemoryData); - void setTwitchData(TwitchDataWrapper *twitchData); - GosuMemoryDataWrapper* getGosumemoryData(); - TwitchDataWrapper* getTwitchData(); - QString getResponse(); +// @formatter:off +class TwitchCommandHandler { + public: + TwitchCommandHandler(); + [[maybe_unused]] TwitchCommandHandler(TwitchDataWrapper *newTwitchData, GosuMemoryDataWrapper *gosumemoryData); + void setGosumemoryData(GosuMemoryDataWrapper *newGosumemoryData); + void setTwitchData(TwitchDataWrapper *newTwitchData); + GosuMemoryDataWrapper* getGosumemoryData(); + [[maybe_unused]] TwitchDataWrapper* getTwitchData(); + QString getResponse(); -private: - QString getResponseStaticCommands(); - QString getResponseAllCommands(); - QString getResponseNowPlaying(); - QString getResponseSkin(); - - TwitchDataWrapper *twitchData; - GosuMemoryDataWrapper *gosumemoryData; + private: + QString getResponseStaticCommands(); + QString getResponseAllCommands(); + QString getResponseNowPlaying(); + QString getResponseSkin(); + TwitchDataWrapper *twitchData; + GosuMemoryDataWrapper *gosumemoryData; }; +// @formatter:on #endif // TWITCHCOMMANDHANDLER_H diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index eee0add..7377665 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -1,12 +1,10 @@ #include "updater.h" Updater::Updater(QObject *parent) - : QObject{parent} -{ + : QObject{parent} { } -void Updater::checkVersion() -{ +void Updater::checkVersion() { qDebug() << "[Updater] starting version check"; auto *manager = new QNetworkAccessManager(this); auto url = getUrl(); @@ -18,10 +16,9 @@ void Updater::checkVersion() qDebug() << "[Updater] version check request sent"; } -void Updater::onReplyFinished(QNetworkReply *reply) -{ +void Updater::onReplyFinished(QNetworkReply *reply) { qDebug() << "[Updater] version reply received"; - if (reply->error() != QNetworkReply::NoError){ + if (reply->error() != QNetworkReply::NoError) { return; } @@ -34,7 +31,7 @@ void Updater::onReplyFinished(QNetworkReply *reply) qDebug() << "[Updater] latest version: " << latestVersion.toString(); - if (currentVersion >= latestVersion){ + if (currentVersion >= latestVersion) { qDebug() << "[Updater] already running on latest or pre-release version"; return; } @@ -42,28 +39,25 @@ void Updater::onReplyFinished(QNetworkReply *reply) } -QUrl Updater::getUrl() -{ - auto url = QUrl(UpdaterUrls::latestStable); +QUrl Updater::getUrl() { + auto url = QUrl(UpdaterUrls::latestStable); - auto const version = Version::fromString(QCoreApplication::applicationVersion()); + auto const version = Version::fromString(QCoreApplication::applicationVersion()); - if (version.isPrerelease()) { - url = QUrl(UpdaterUrls::allReleases); - } - qDebug() << "[Updater] url: " << url.toString(); - return url; + if (version.isPrerelease()) { + url = QUrl(UpdaterUrls::allReleases); + } + qDebug() << "[Updater] url: " << url.toString(); + return url; } -Version Updater::getLatestVersion(const QJsonDocument& json) -{ +Version Updater::getLatestVersion(const QJsonDocument &json) { QString version; if (json.isArray()) { auto array = json.array(); auto first = array.at(0).toObject(); version = first.value("tag_name").toString(); - } - else { + } else { version = json.object().value("tag_name").toString(); } qDebug() << "[Updater] latest version: " << version; diff --git a/src/updater/updater.h b/src/updater/updater.h index 0af5c86..b95f6bd 100644 --- a/src/updater/updater.h +++ b/src/updater/updater.h @@ -14,21 +14,21 @@ #include "updaterurls.h" #include "version.h" -class Updater : public QObject -{ +// @formatter:off +class Updater : public QObject { Q_OBJECT -public: - explicit Updater(QObject *parent = nullptr); - void checkVersion(); + public: + explicit Updater(QObject *parent = nullptr); + void checkVersion(); -signals: - void newVersionAvailable(); + signals: + void newVersionAvailable(); -private: - void onReplyFinished(QNetworkReply *reply); -// static bool isPreRelease(const QString& version); - static QUrl getUrl(); - static Version getLatestVersion(const QJsonDocument& json); + private: + void onReplyFinished(QNetworkReply *reply); + static QUrl getUrl(); + static Version getLatestVersion(const QJsonDocument& json); }; +// @formatter:on #endif // UPDATER_H diff --git a/src/updater/updaterurls.h b/src/updater/updaterurls.h index 9571424..06f0088 100644 --- a/src/updater/updaterurls.h +++ b/src/updater/updaterurls.h @@ -3,11 +3,13 @@ #include +// @formatter:off class UpdaterUrls{ public: constexpr static const char* latestStable = "https://api.github.com/repos/MirayaProject/miraya/releases/latest"; - constexpr static const char* allReleases = "https://api.github.com/repos/MirayaProject/miraya/releases"; + [[maybe_unused]] constexpr static const char* allReleases = "https://api.github.com/repos/MirayaProject/miraya/releases"; }; +// @formatter:on #endif //MIRAYA_UPDATERURLS_H diff --git a/src/updater/version.h b/src/updater/version.h index da54994..1da4adb 100644 --- a/src/updater/version.h +++ b/src/updater/version.h @@ -4,6 +4,7 @@ #include #include +// @formatter:off class Version { public: Version(const QVersionNumber& version, const QString& suffix); @@ -19,5 +20,6 @@ class Version { QVersionNumber version; QString suffix; }; +// @formatter:on #endif //MIRAYA_VERSION_H diff --git a/src/utils/utils.h b/src/utils/utils.h index d8998b5..2d7512e 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -5,11 +5,13 @@ #include #include +// @formatter:off class Utils { public: static QStringList getOsuBeatmapUrls(const QString &message); static QStringList getUrls(const QString &message); static int getBeatmapIdFromOsuBeatmapLink(const QString &link); }; +// @formatter:on #endif // UTILS_H