From ee1bb1956b669c9d73cd868274a113b0007fd261 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Thu, 2 Feb 2023 21:32:15 +0100 Subject: [PATCH] Make clang-tidy complain a little less --- src/controllers/plugins/PluginController.cpp | 18 +++++++++++------- src/controllers/plugins/PluginController.hpp | 13 +++++++------ src/widgets/settingspages/PluginsPage.cpp | 4 ++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index b5066a984..785a33a41 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -101,7 +101,9 @@ bool PluginController::tryLoadFromDir(const QDir &pluginDir) this->load(index, pluginDir, PluginMeta(doc.object())); return true; } -void PluginController::openLibrariesFor(lua_State *L, PluginMeta meta) + +void PluginController::openLibrariesFor(lua_State *L, + const PluginMeta & /*meta*/) { // Stuff to change, remove or hide behind a permission system: static const std::vector loadedlibs = { @@ -135,12 +137,13 @@ void PluginController::openLibrariesFor(lua_State *L, PluginMeta meta) } } -void PluginController::load(QFileInfo index, QDir pluginDir, PluginMeta meta) +void PluginController::load(const QFileInfo &index, const QDir &pluginDir, + const PluginMeta &meta) { qCDebug(chatterinoLua) << "Running lua file" << index; lua_State *l = luaL_newstate(); - this->openLibrariesFor(l, meta); - this->loadChatterinoLib(l); + PluginController::openLibrariesFor(l, meta); + PluginController::loadChatterinoLib(l); auto pluginName = pluginDir.dirName(); auto plugin = std::make_unique(pluginName, l, meta, pluginDir); @@ -154,7 +157,7 @@ void PluginController::load(QFileInfo index, QDir pluginDir, PluginMeta meta) } } this->plugins_.insert({pluginName, std::move(plugin)}); - if (!this->isEnabled(pluginName)) + if (!PluginController::isEnabled(pluginName)) { qCInfo(chatterinoLua) << "Skipping loading" << pluginName << "(" << meta.name << ") because it is disabled"; @@ -189,7 +192,7 @@ bool PluginController::reload(const QString &codename) getApp()->commands->unregisterPluginCommand(cmd); } it->second->ownedCommands.clear(); - if (this->isEnabled(codename)) + if (PluginController::isEnabled(codename)) { QDir loadDir = it->second->loadDirectory_; this->plugins_.erase(codename); @@ -209,7 +212,8 @@ void PluginController::callEvery(const QString &functionName) void PluginController::callEveryWithArgs( const QString &functionName, int count, - std::function &pl, lua_State *L)> argCb) + const std::function &pl, lua_State *L)> + &argCb) { for (const auto &[name, plugin] : this->plugins_) { diff --git a/src/controllers/plugins/PluginController.hpp b/src/controllers/plugins/PluginController.hpp index e4eedd128..e87e1e6d9 100644 --- a/src/controllers/plugins/PluginController.hpp +++ b/src/controllers/plugins/PluginController.hpp @@ -30,8 +30,8 @@ public: void callEvery(const QString &functionName); void callEveryWithArgs( const QString &functionName, int count, - std::function &pl, lua_State *L)> - argCb); + const std::function &pl, + lua_State *L)> &argCb); QString tryExecPluginCommand(const QString &commandName, const CommandContext &ctx); @@ -56,15 +56,16 @@ public: } bool reload(const QString &codename); - bool isEnabled(const QString &codename); + static bool isEnabled(const QString &codename); private: void actuallyInitialize(); - void load(QFileInfo index, QDir pluginDir, PluginMeta meta); - void loadChatterinoLib(lua_State *l); + void load(const QFileInfo &index, const QDir &pluginDir, + const PluginMeta &meta); // This function adds lua standard libraries into the state - void openLibrariesFor(lua_State *L, PluginMeta meta); + static void openLibrariesFor(lua_State *L, const PluginMeta & /*meta*/); + static void loadChatterinoLib(lua_State *l); bool tryLoadFromDir(const QDir &pluginDir); std::map> plugins_; }; diff --git a/src/widgets/settingspages/PluginsPage.cpp b/src/widgets/settingspages/PluginsPage.cpp index df4f8aa15..91ab4fba2 100644 --- a/src/widgets/settingspages/PluginsPage.cpp +++ b/src/widgets/settingspages/PluginsPage.cpp @@ -106,7 +106,7 @@ void PluginsPage::rebuildContent() pl->addRow("Commands", new QLabel(cmds)); QString enableOrDisableStr = "Enable"; - if (getApp()->plugins->isEnabled(codename)) + if (PluginController::isEnabled(codename)) { enableOrDisableStr = "Disable"; } @@ -116,7 +116,7 @@ void PluginsPage::rebuildContent() enableDisable, &QPushButton::pressed, [name = codename, this]() { std::vector val = getSettings()->enabledPlugins.getValue(); - if (getApp()->plugins->isEnabled(name)) + if (PluginController::isEnabled(name)) { val.erase(std::remove(val.begin(), val.end(), name), val.end());