rename codename -> id

This commit is contained in:
Mm2PL 2023-02-14 12:07:22 +01:00
parent 627aafb74b
commit 2629c56d5c
5 changed files with 25 additions and 27 deletions

View file

@ -105,7 +105,7 @@ namespace {
void logHelper(lua_State *L, Plugin *pl, QDebug stream, int argc)
{
stream.noquote();
stream << "[" + pl->codename + ":" + pl->meta.name + "]";
stream << "[" + pl->id + ":" + pl->meta.name + "]";
for (int i = 1; i <= argc; i++)
{
stream << lua::toString(L, i);
@ -226,8 +226,8 @@ int g_import(lua_State *L)
auto dir = QUrl(pl->loadDirectory().canonicalPath() + "/");
auto file = dir.resolved(fname);
qCDebug(chatterinoLua) << "plugin" << pl->codename << "is trying to load"
<< file << "(its dir is" << dir << ")";
qCDebug(chatterinoLua) << "plugin" << pl->id << "is trying to load" << file
<< "(its dir is" << dir << ")";
if (!dir.isParentOf(file))
{
lua_pushnil(L);

View file

@ -193,13 +193,13 @@ struct PluginMeta {
class Plugin
{
public:
QString codename;
QString id;
PluginMeta meta;
bool isDupeName{};
Plugin(QString codename, lua_State *state, PluginMeta meta,
Plugin(QString id, lua_State *state, PluginMeta meta,
const QDir &loadDirectory)
: codename(std::move(codename))
: id(std::move(id))
, meta(std::move(meta))
, loadDirectory_(loadDirectory)
, state_(state)

View file

@ -202,7 +202,7 @@ void PluginController::load(const QFileInfo &index, const QDir &pluginDir,
auto pluginName = pluginDir.dirName();
auto plugin = std::make_unique<Plugin>(pluginName, l, meta, pluginDir);
for (const auto &[codename, other] : this->plugins_)
for (const auto &[id, other] : this->plugins_)
{
if (other->meta.name == meta.name)
{
@ -229,9 +229,9 @@ void PluginController::load(const QFileInfo &index, const QDir &pluginDir,
qCInfo(chatterinoLua) << "Loaded" << pluginName << "plugin from" << index;
}
bool PluginController::reload(const QString &codename)
bool PluginController::reload(const QString &id)
{
auto it = this->plugins_.find(codename);
auto it = this->plugins_.find(id);
if (it == this->plugins_.end())
{
return false;
@ -247,7 +247,7 @@ bool PluginController::reload(const QString &codename)
}
it->second->ownedCommands.clear();
QDir loadDir = it->second->loadDirectory_;
this->plugins_.erase(codename);
this->plugins_.erase(id);
this->tryLoadFromDir(loadDir);
return true;
}
@ -283,14 +283,14 @@ QString PluginController::tryExecPluginCommand(const QString &commandName,
return "";
}
bool PluginController::isEnabled(const QString &codename)
bool PluginController::isEnabled(const QString &id)
{
if (!getSettings()->pluginSupportEnabled)
{
return false;
}
auto vec = getSettings()->enabledPlugins.getValue();
auto it = std::find(vec.begin(), vec.end(), codename);
auto it = std::find(vec.begin(), vec.end(), id);
return it != vec.end();
}

View file

@ -51,18 +51,18 @@ public:
}
/**
* @brief Reload plugin given by codename
* @brief Reload plugin given by id
*
* @param codename This is the 'codename' of the plugin, the name of the directory it is in
* @param id This is the unique identifier of the plugin, the name of the directory it is in
*/
bool reload(const QString &codename);
bool reload(const QString &id);
/**
* @brief Checks settings to tell if a plugin named by codename.
* @brief Checks settings to tell if a plugin named by id.
*
* It accounts for plugins being enabled/disabled globally.
*/
static bool isEnabled(const QString &codename);
static bool isEnabled(const QString &id);
private:
void loadPlugins();

View file

@ -68,7 +68,7 @@ void PluginsPage::rebuildContent()
this->dataFrame_ = frame.getElement();
this->scrollAreaWidget_.append(this->dataFrame_);
auto layout = frame.setLayoutType<QVBoxLayout>();
for (const auto &[codename, plugin] : getApp()->plugins->plugins())
for (const auto &[id, plugin] : getApp()->plugins->plugins())
{
QString headerText;
if (plugin->isDupeName)
@ -77,7 +77,7 @@ void PluginsPage::rebuildContent()
.arg(plugin->meta.name,
QString::fromStdString(
plugin->meta.version.to_string()),
codename);
id);
}
else
{
@ -146,15 +146,14 @@ void PluginsPage::rebuildContent()
if (plugin->meta.isValid())
{
QString enableOrDisableStr = "Enable";
if (PluginController::isEnabled(codename))
if (PluginController::isEnabled(id))
{
enableOrDisableStr = "Disable";
}
auto *enableDisable = new QPushButton(enableOrDisableStr);
QObject::connect(
enableDisable, &QPushButton::pressed,
[name = codename, this]() {
enableDisable, &QPushButton::pressed, [name = id, this]() {
std::vector<QString> val =
getSettings()->enabledPlugins.getValue();
if (PluginController::isEnabled(name))
@ -174,11 +173,10 @@ void PluginsPage::rebuildContent()
}
auto *reload = new QPushButton("Reload");
QObject::connect(reload, &QPushButton::pressed,
[name = codename, this]() {
getApp()->plugins->reload(name);
this->rebuildContent();
});
QObject::connect(reload, &QPushButton::pressed, [name = id, this]() {
getApp()->plugins->reload(name);
this->rebuildContent();
});
pl->addRow(reload);
}
}