Skip to content

Commit

Permalink
Refactor plugin loading and add tooltips to plugin names
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Feb 21, 2024
1 parent f2e3336 commit f1804b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
20 changes: 11 additions & 9 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,25 +1685,23 @@ void CentralWidget::menuAndToolBarInit(void) {
qApp->addLibraryPath(QCoreApplication::applicationDirPath()+"../lib");
#endif
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName),this);
QString absoluteFilePath = pluginsDir.absoluteFilePath(fileName);
QPluginLoader loader(absoluteFilePath,this);
QJsonObject metaData = loader.metaData();
if(!metaData.contains("MetaData")) {
qInfo() << "plugin metaData not found:" << fileName;
pluginInfoWindow->addPluginInfo(fileName,"",0,false,true);
pluginInfoWindow->addPluginInfo(fileName,"",tr("Plugin metaData not found!"),0,false,true);
continue;
}
QJsonObject metaDataObject = metaData.value("MetaData").toObject();
qInfo() << metaDataObject;
if(!metaDataObject.contains("APIVersion")) {
qInfo() << "plugin api version not found:" << fileName;
pluginInfoWindow->addPluginInfo(fileName,"",0,false,true);
pluginInfoWindow->addPluginInfo(fileName,"",tr("Plugin api version not found!"),0,false,true);
continue;
}
int apiVersion = metaDataObject.value("APIVersion").toInt();
QList<uint32_t> supportVersion = PluginInfoWindow::supportAPIVersionList();
if(!supportVersion.contains((uint32_t)apiVersion)) {
qInfo() << "plugin api version [" << apiVersion << "] not match:" << fileName;
pluginInfoWindow->addPluginInfo(fileName,"",apiVersion,false,true);
pluginInfoWindow->addPluginInfo(fileName,"",tr("Plugin api version not match!"),apiVersion,false,true);
continue;
}
QObject *plugin = loader.instance();
Expand All @@ -1722,7 +1720,7 @@ void CentralWidget::menuAndToolBarInit(void) {
pluginStruct.iface = iface;
pluginStruct.state = state;
pluginList.append(pluginStruct);
pluginInfoWindow->addPluginInfo(iface,apiVersion,state,false);
pluginInfoWindow->addPluginInfo(iface,absoluteFilePath,apiVersion,state,false);
connect(iface,SIGNAL(requestTelnetConnect(QString, int, int)),this,SLOT(onPluginRequestTelnetConnect(QString, int, int)));
connect(iface,SIGNAL(requestSerialConnect(QString, uint32_t, int, int, int, bool, bool)),this,SLOT(onPluginRequestSerialConnect(QString, uint32_t, int, int, int, bool, bool)));
connect(iface,SIGNAL(requestLocalShellConnect(QString, QString)),this,SLOT(onPluginRequestLocalShellConnect(QString, QString)));
Expand Down Expand Up @@ -1750,10 +1748,14 @@ void CentralWidget::menuAndToolBarInit(void) {
}
iface->setLanguage(language,qApp);
iface->retranslateUi();
} else {
pluginInfoWindow->addPluginInfo(fileName,"",tr("Plugin init failed!"),apiVersion,false,true);
}
} else {
qInfo() << "load plugin failed:" << loader.errorString();
pluginInfoWindow->addPluginInfo(fileName,"",loader.errorString(),apiVersion,false,true);
}
} else {
pluginInfoWindow->addPluginInfo(fileName,"",loader.errorString(),apiVersion,false,true);
}
}
laboratoryMenu->addSeparator();
Expand Down
7 changes: 4 additions & 3 deletions src/plugininfowindow/plugininfowindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ PluginInfoWindow::~PluginInfoWindow()
delete ui;
}

void PluginInfoWindow::addPluginInfo(PluginInterface *plugin, uint32_t apiVersion, bool enable, bool readOnly)
void PluginInfoWindow::addPluginInfo(PluginInterface *plugin, const QString &tooltip, uint32_t apiVersion, bool enable, bool readOnly)
{
addPluginInfo(plugin->name(), plugin->version(), apiVersion, enable, readOnly);
addPluginInfo(plugin->name(), plugin->version(), tooltip, apiVersion, enable, readOnly);
}

void PluginInfoWindow::addPluginInfo(QString name, QString version, uint32_t apiVersion, bool enable, bool readOnly)
void PluginInfoWindow::addPluginInfo(QString name, QString version, const QString &tooltip, uint32_t apiVersion, bool enable, bool readOnly)
{
uint32_t i = ui->tableWidget->rowCount();
ui->tableWidget->setRowCount(i + 1);
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(name));
ui->tableWidget->item(i, 0)->setToolTip(tooltip);
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(version));
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(apiVersion?QString::number(apiVersion):""));
QTableWidgetItem *item = new QTableWidgetItem();
Expand Down
4 changes: 2 additions & 2 deletions src/plugininfowindow/plugininfowindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class PluginInfoWindow : public QDialog
public:
explicit PluginInfoWindow(QWidget *parent = nullptr);
~PluginInfoWindow();
void addPluginInfo(PluginInterface *plugin, uint32_t apiVersion, bool enable, bool readOnly);
void addPluginInfo(QString name, QString version, uint32_t apiVersion, bool enable, bool readOnly);
void addPluginInfo(PluginInterface *plugin, const QString &tooltip, uint32_t apiVersion, bool enable, bool readOnly);
void addPluginInfo(QString name, QString version, const QString &tooltip, uint32_t apiVersion, bool enable, bool readOnly);
void retranslateUi(void);

static QList<uint32_t> supportAPIVersionList(void);
Expand Down

0 comments on commit f1804b9

Please sign in to comment.