int main(int argc, char *argv[]) { ExtensionSystem::PluginManager manager; QApplication app(argc, argv); PluginDialog dialog(&manager); manager.setPluginPaths(QStringList() << "plugins"); manager.loadPlugins(); dialog.show(); app.exec(); }
/*! * \brief 该函数最初是在子线程中完成的,但是由于在子线程中完成创建对象的任务后,还需要将该对象moveToThread到 * 主线,给很多操作带来不小的麻烦,所以这里还是在主线程中完成的。 * \param[] receiver 用来传输数据 * \return 返回0表示成功 */ int loadPluginThread(MainApp *receiver) { QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, QCoreApplication::applicationDirPath() + QLatin1String(SHARE_PATH)); QSettings::setDefaultFormat(QSettings::IniFormat); QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QLatin1String(Core::Constants::TOTEM_SETTINGSVARIANT_STR), QLatin1String("Totem")); QSettings *globalSettings = new QSettings(QSettings::IniFormat, QSettings::SystemScope, QLatin1String(Core::Constants::TOTEM_SETTINGSVARIANT_STR), QLatin1String("Totem")); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); pm->setFileExtension(QLatin1String(PLUGINSPEC_FILE_EXTENTION)); pm->setGlobalSettings(globalSettings); pm->setSettings(settings); QTranslator translator; QTranslator qtTranslator; QStringList uiLanguages; #if (QT_VERSION >= 0x040801) || (QT_VERSION >= 0x040800 && !defined(Q_OS_WIN)) uiLanguages = QLocale::system().uiLanguages(); #else uiLanguages << QLocale::system().name(); #endif // QString overrideLanguage = settings->value("General/OverrideLanguage").toString(); // if (!overrideLanguage.isEmpty()) // uiLanguages.prepend(overrideLanguage); const QString &totemTrPath = QCoreApplication::applicationDirPath() + QLatin1String(SHARE_PATH "/translations"); foreach (const QString &locale, uiLanguages) { if (translator.load(QLatin1String("totem_") + locale, totemTrPath)) { const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath); const QString &qtTrFile = QLatin1String("qt_") + locale; if (qtTranslator.load(qtTrFile, qtTrPath) || qtTranslator.load(qtTrFile, totemTrPath)) { receiver->app.installTranslator(&translator); receiver->app.installTranslator(&qtTranslator); receiver->app.setProperty("qtc_locale", locale); break; } translator.load(QString()); // unload() } else if (locale == QLatin1String("C") /* overrideLanguage == "English" */) { break; } else if (locale.startsWith(QLatin1String("en")) /* "English" is built-in */) { break; } } //这里没有考虑MacOS,Unix QNetworkProxyFactory::setUseSystemConfiguration(true); //设置插件搜索路径 const QStringList pluginPaths = getPluginPaths(); pm->setPluginPaths(pluginPaths); //检查核心插件 const PluginSpecSet plugins = pm->plugins(); ExtensionSystem::PluginSpec *coreplugin = 0; foreach(ExtensionSystem::PluginSpec *spec, plugins) { if(spec->name() == QLatin1String(corePluginNameC)) { coreplugin = spec; break; } } int status; if( status = checkPlugin(coreplugin, QLatin1String(corePluginNameC)))//如果核心插件检查有问题 { return status; } //载入皮肤 receiver->loadSkin(defaultQssFileC); QList<ExtensionSystem::PluginSpec *> queue = pm->loadQueue(); receiver->m_futureInterface->setProgressRange(0, queue.size()); QMetaObject::invokeMethod(receiver, "onStart", Qt::QueuedConnection); receiver->m_futureInterface->reportStarted(); foreach(ExtensionSystem::PluginSpec *spec, queue) { pm->loadPlugin(spec,ExtensionSystem::PluginSpec::Loaded); receiver->m_futureInterface->setProgressValue( receiver->m_futureInterface->progressValue() + 1); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); #if QT_VERSION < 0x050000 // Removed in Qt5 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); #endif app.setApplicationName(BINARY_NAME); app.setOrganizationName(BINARY_NAME); app.setApplicationVersion(PACKAGE_VERSION); QStringList args = qApp->arguments(); if (args.contains("--version") || args.contains("-version") || args.contains("-v")) { std::cout << qPrintable(VERSION_MESSAGE); return 0; } if (args.contains("--help") || args.contains("-help") || args.contains("-h")) { std::cout << qPrintable(HELP_MESSAGE); return 0; } // Create plugins manager ExtensionSystem::PluginManager pluginManager; pluginManager.setFileExtension(QString("pluginspec")); // Getting & feeding libraries/plugins path QStringList libpath; #ifdef LIBRARY_BASENAME libpath << Utils::applicationPluginsPath(QString(BINARY_NAME), QString(LIBRARY_BASENAME)); #else libpath << Utils::applicationPluginsPath(QString(BINARY_NAME), ""); #endif if (libpath.isEmpty()) return 123; pluginManager.setPluginPaths(libpath); // Add some debugging information Utils::Log::logCompilationConfiguration(); const PluginSpecSet plugins = pluginManager.plugins(); ExtensionSystem::PluginSpec *coreplugin = 0; if (WarnAllPluginSpecs) { foreach (ExtensionSystem::PluginSpec *spec, plugins) { qWarning() << "PluginSpecs :::"<< spec->filePath() << spec->name() << spec->version(); } } foreach (ExtensionSystem::PluginSpec *spec, plugins) { if (spec->name() == QString(COREPLUGINSNAME)) { coreplugin = spec; break; } } if (!coreplugin) { const QString reason = QCoreApplication::translate("Application", "Couldn't find 'Core.pluginspec' in %1").arg(qApp->libraryPaths().join("; ")); qWarning() << reason; return 1; } if (coreplugin->hasError()) { qWarning() << coreplugin->errorString(); return 1; } pluginManager.loadPlugins(); if (WarnAllPluginSpecs) { foreach (ExtensionSystem::PluginSpec *spec, plugins) { qWarning() << "PluginSpecs :::"<< spec->name() << "hasError:" << spec->hasError() << spec->errorString(); } } if (coreplugin->hasError()) { qWarning() << coreplugin->errorString(); return 1; } // shutdown plugin manager on the exit QObject::connect(&app, SIGNAL(aboutToQuit()), &pluginManager, SLOT(shutdown())); int r = app.exec(); // Utils::Log::saveLog(); return r; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); #if QT_VERSION < 0x050000 // Removed in Qt5 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); #endif app.setApplicationName(BINARY_NAME); app.setOrganizationName(BINARY_NAME); app.setApplicationVersion(PACKAGE_VERSION); QStringList args = qApp->arguments(); if (args.contains("--version") || args.contains("-version") || args.contains("-v")) { std::cout << qPrintable(VERSION_MESSAGE); return 0; } if (args.contains("--help") || args.contains("-help") || args.contains("-h")) { std::cout << qPrintable(HELP_MESSAGE); return 0; } // Create plugins manager ExtensionSystem::PluginManager pluginManager; pluginManager.setFileExtension(QString("pluginspec")); // Getting & feeding libraries/plugins path QStringList libpath; #ifdef LIBRARY_BASENAME libpath << Utils::applicationPluginsPath(QString(BINARY_NAME), QString(LIBRARY_BASENAME)); #else libpath << Utils::applicationPluginsPath(QString(BINARY_NAME), ""); #endif if (libpath.isEmpty()) return 123; pluginManager.setPluginPaths(libpath); // Add some debugging information Utils::Log::logCompilationConfiguration(); // Manage plugin manager options QStringList arguments = app.arguments(); // adapted arguments list is passed to plugin manager later QMap<QString, QString> foundAppOptions; if (arguments.size() > 1) { QMap<QString, bool> appOptions; QString errorMessage; if (!pluginManager.parseOptions(arguments, appOptions, &foundAppOptions, &errorMessage)) { // qWarning() << errorMessage; // qWarning() << HELP_MESSAGE; // return -1; } } const PluginSpecSet plugins = pluginManager.plugins(); ExtensionSystem::PluginSpec *coreplugin = 0; if (WarnAllPluginSpecs) { foreach (ExtensionSystem::PluginSpec *spec, plugins) { qWarning() << "PluginSpecs :::"<< spec->filePath() << spec->name() << spec->version(); } } foreach (ExtensionSystem::PluginSpec *spec, plugins) { if (spec->name() == QString(COREPLUGINSNAME)) { coreplugin = spec; break; } } ExtensionSystem::PluginSpec *userplugin = 0; foreach (ExtensionSystem::PluginSpec *spec, plugins) { if (spec->name() == QString(USERPLUGINSNAME)) { userplugin = spec; break; } } if (!coreplugin) { const QString reason = QCoreApplication::translate("Application", "Couldn't find 'Core.pluginspec' in %1").arg(qApp->libraryPaths().join("; ")); qWarning() << reason; // displayError(msgCoreLoadFailure(reason)); return 1; } if (!userplugin) { const QString reason = QCoreApplication::translate("Application", "Couldn't find 'UserManager.pluginspec' in %1").arg(qApp->libraryPaths().join("; ")); qWarning() << reason; // displayError(msgCoreLoadFailure(reason)); return 1; } if (coreplugin->hasError()) { qWarning() << coreplugin->errorString(); // displayError(msgCoreLoadFailure(coreplugin->errorString())); return 1; } if (userplugin->hasError()) { qWarning() << userplugin->errorString(); // displayError(msgCoreLoadFailure(coreplugin->errorString())); return 1; } // if (foundAppOptions.contains(QLatin1String(VERSION_OPTION))) { // printVersion(coreplugin, pluginManager); // return 0; // } // if (foundAppOptions.contains(QLatin1String(HELP_OPTION1)) // || foundAppOptions.contains(QLatin1String(HELP_OPTION2)) // || foundAppOptions.contains(QLatin1String(HELP_OPTION3)) // || foundAppOptions.contains(QLatin1String(HELP_OPTION4))) { // printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager); // return 0; // } // const bool isFirstInstance = !app.isRunning(); // if (!isFirstInstance && foundAppOptions.contains(QLatin1String(CLIENT_OPTION))) // return sendArguments(app, pluginManager.arguments()) ? 0 : -1; // foreach (ExtensionSystem::PluginSpec *spec, plugins) { // qWarning() << "PlugInSpec" << spec->name() << spec->errorString() << spec->state(); // } pluginManager.loadPlugins(); if (WarnAllPluginSpecs) { foreach (ExtensionSystem::PluginSpec *spec, plugins) { qWarning() << "PluginSpecs :::"<< spec->name() << "hasError:" << spec->hasError() << spec->errorString(); } } if (coreplugin->hasError()) { qWarning() << coreplugin->errorString(); return 1; } if (userplugin->hasError()) { qWarning() << userplugin->errorString(); // displayError(msgCoreLoadFailure(coreplugin->errorString())); return 1; } // if (isFirstInstance) { // // Set up lock and remote arguments for the first instance only. // // Silently fallback to unconnected instances for any subsequent // // instances. // app.initialize(); // QObject::connect(&app, SIGNAL(messageReceived(QString)), coreplugin->plugin(), SLOT(remoteArgument(QString))); // } // QObject::connect(&app, SIGNAL(fileOpenRequest(QString)), coreplugin->plugin(), SLOT(remoteArgument(QString))); // shutdown plugin manager on the exit QObject::connect(&app, SIGNAL(aboutToQuit()), &pluginManager, SLOT(shutdown())); #ifdef WITH_TESTS // Do this after the event loop has started if (pluginManager.runningTests()) QTimer::singleShot(100, &pluginManager, SLOT(startTests())); #endif int r = app.exec(); // Utils::Log::saveLog(); return r; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); #if QT_VERSION < 0x050000 // Removed in Qt5 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); #endif app.setApplicationName(BINARY_NAME); app.setOrganizationName(BINARY_NAME); app.setApplicationVersion(PACKAGE_VERSION); QStringList args = qApp->arguments(); if (args.contains("--version") || args.contains("-version") || args.contains("-v")) { std::cout << qPrintable(VERSION_MESSAGE); return 0; } if (args.contains("--help") || args.contains("-help") || args.contains("-h")) { std::cout << qPrintable(HELP_MESSAGE); return 0; } // Create plugins manager ExtensionSystem::PluginManager pluginManager; pluginManager.setFileExtension(QString("pluginspec")); // Getting & feeding libraries/plugins path QStringList libpath; #ifdef LIBRARY_BASENAME libpath << Utils::applicationPluginsPath(QString(BINARY_NAME), QString(LIBRARY_BASENAME)); #else libpath << Utils::applicationPluginsPath(QString(BINARY_NAME), ""); #endif if (libpath.isEmpty()) return 123; pluginManager.setPluginPaths(libpath); // Add some debugging information Utils::Log::logCompilationConfiguration(); // Manage plugin manager options QStringList arguments = app.arguments(); // adapted arguments list is passed to plugin manager later QMap<QString, QString> foundAppOptions; if (arguments.size() > 1) { QMap<QString, bool> appOptions; QString errorMessage; if (!pluginManager.parseOptions(arguments, appOptions, &foundAppOptions, &errorMessage)) { qWarning() << errorMessage; qWarning() << HELP_MESSAGE; return -1; } } const PluginSpecSet plugins = pluginManager.plugins(); ExtensionSystem::PluginSpec *coreplugin = 0; if (WarnAllPluginSpecs) { foreach (ExtensionSystem::PluginSpec *spec, plugins) { qWarning() << "PluginSpecs :::"<< spec->filePath() << spec->name() << spec->version(); } } foreach (ExtensionSystem::PluginSpec *spec, plugins) { if (spec->name() == QString(COREPLUGINSNAME)) { coreplugin = spec; break; } } // ExtensionSystem::PluginSpec *userplugin = 0; // foreach (ExtensionSystem::PluginSpec *spec, plugins) { // if (spec->name() == QString(USERPLUGINSNAME)) { // userplugin = spec; // break; // } // } if (!coreplugin) { const QString reason = QCoreApplication::translate("Application", "Couldn't find 'Core.pluginspec' in %1").arg(qApp->libraryPaths().join("; ")); qWarning() << reason; return 1; } // if (!userplugin) { // const QString reason = QCoreApplication::translate("Application", "Couldn't find 'UserManager.pluginspec' in %1").arg(qApp->libraryPaths().join("; ")); // qWarning() << reason; // return 1; // } if (coreplugin->hasError()) { qWarning() << coreplugin->errorString(); return 1; } // if (userplugin->hasError()) { // qWarning() << userplugin->errorString(); // return 1; // } pluginManager.loadPlugins(); if (WarnAllPluginSpecs) { foreach (ExtensionSystem::PluginSpec *spec, plugins) { qWarning() << "PluginSpecs :::"<< spec->name() << "hasError:" << spec->hasError() << spec->errorString(); } } if (coreplugin->hasError()) { qWarning() << coreplugin->errorString(); return 1; } // if (userplugin->hasError()) { // qWarning() << userplugin->errorString(); // return 1; // } // shutdown plugin manager on the exit QObject::connect(&app, SIGNAL(aboutToQuit()), &pluginManager, SLOT(shutdown())); #ifdef WITH_TESTS // Do this after the event loop has started if (pluginManager.runningTests()) QTimer::singleShot(100, &pluginManager, SLOT(startTests())); #endif int r = app.exec(); // Utils::Log::saveLog(); return r; }