Splitted plugin loading and attaching to mainwindow
This commit is contained in:
@@ -7,6 +7,13 @@
|
|||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
void registerMessageHandler()
|
||||||
|
{
|
||||||
|
qDebug() << "called";
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_COREAPP_STARTUP_FUNCTION(registerMessageHandler)
|
||||||
|
|
||||||
DevToolsPlugin::DevToolsPlugin(QObject *parent) :
|
DevToolsPlugin::DevToolsPlugin(QObject *parent) :
|
||||||
ZeiterfassungPlugin(parent)
|
ZeiterfassungPlugin(parent)
|
||||||
{
|
{
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -32,7 +34,7 @@ struct {
|
|||||||
QTranslator zeiterfassungguilibTranslator;
|
QTranslator zeiterfassungguilibTranslator;
|
||||||
} translators;
|
} translators;
|
||||||
|
|
||||||
QVector<ZeiterfassungPlugin*> plugins;
|
QVector<std::shared_ptr<QPluginLoader> > pluginLoaders;
|
||||||
|
|
||||||
bool loadAndInstallTranslator(QTranslator &translator, const QString &filename)
|
bool loadAndInstallTranslator(QTranslator &translator, const QString &filename)
|
||||||
{
|
{
|
||||||
@@ -270,44 +272,25 @@ bool loadPlugins(QSplashScreen &splashScreen)
|
|||||||
).absoluteFilePath(QStringLiteral("zeiterfassung"))
|
).absoluteFilePath(QStringLiteral("zeiterfassung"))
|
||||||
);
|
);
|
||||||
|
|
||||||
for(const auto &fileInfo : dir.entryInfoList(QDir::Files))
|
for(const auto &fileInfo : dir.entryInfoList(QDir::Files | QDir::NoSymLinks))
|
||||||
{
|
{
|
||||||
if(fileInfo.isSymLink())
|
|
||||||
{
|
|
||||||
qWarning() << "skipping" << fileInfo.fileName() << "because symlink";
|
|
||||||
continue; // to skip unix so symlinks
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!QLibrary::isLibrary(fileInfo.filePath()))
|
if(!QLibrary::isLibrary(fileInfo.filePath()))
|
||||||
{
|
{
|
||||||
qWarning() << "skipping" << fileInfo.fileName() << "because no QLibrary";
|
qWarning() << "skipping" << fileInfo.fileName() << "because no QLibrary";
|
||||||
continue; // to skip windows junk files
|
continue; // to skip windows junk files
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "loading" << fileInfo.fileName();
|
auto pluginLoader = std::make_shared<QPluginLoader>(fileInfo.filePath());
|
||||||
|
if(!pluginLoader->load())
|
||||||
QPluginLoader loader(fileInfo.filePath());
|
|
||||||
if(!loader.load())
|
|
||||||
{
|
{
|
||||||
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not load plugin %0!"),
|
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not load plugin %0!"),
|
||||||
QCoreApplication::translate("main", "Could not load plugin %0!").arg(fileInfo.fileName()) %
|
QCoreApplication::translate("main", "Could not load plugin %0!").arg(fileInfo.fileName()) %
|
||||||
"\n\n" % loader.errorString());
|
"\n\n" % pluginLoader->errorString());
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto plugin = qobject_cast<ZeiterfassungPlugin*>(loader.instance());
|
pluginLoaders.append(pluginLoader);
|
||||||
|
|
||||||
if(!plugin)
|
|
||||||
{
|
|
||||||
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Plugin not valid %0!"),
|
|
||||||
QCoreApplication::translate("main", "Plugin not valid %0!").arg(fileInfo.fileName()) %
|
|
||||||
"\n\n" % loader.errorString());
|
|
||||||
ok = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.append(plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
@@ -370,8 +353,13 @@ int main(int argc, char *argv[])
|
|||||||
MainWindow mainWindow(settings, erfassung, userInfo, stripFactory);
|
MainWindow mainWindow(settings, erfassung, userInfo, stripFactory);
|
||||||
splashScreen.finish(&mainWindow);
|
splashScreen.finish(&mainWindow);
|
||||||
|
|
||||||
for(auto plugin : plugins)
|
for(auto &pluginLoader : pluginLoaders)
|
||||||
plugin->attachTo(mainWindow);
|
if(auto plugin = qobject_cast<ZeiterfassungPlugin*>(pluginLoader->instance()))
|
||||||
|
plugin->attachTo(mainWindow);
|
||||||
|
else
|
||||||
|
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Plugin not valid %0!"),
|
||||||
|
QCoreApplication::translate("main", "Plugin not valid %0!").arg(pluginLoader->fileName()) %
|
||||||
|
"\n\n" % pluginLoader->errorString());
|
||||||
|
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user