Example #1
0
CAddIns::CAddIns()
{

    if (instances++ > 0) return;
    qDebug() << "PluginLoader created";
#if defined(Q_OS_WIN)
    QDir pluginsDir("../");
#elif defined(Q_OS_MAC)
    QDir pluginsDir("../../../");
#endif
    LoadAddIns(pluginsDir);
}
Example #2
0
void PluginManager::initialize(QString const & _dirPath)
{

    //! TODO: reutrn error
    if (!QDir(_dirPath).exists())
        return;

    QDir pluginsDir(_dirPath);

    QDirIterator dirIt(_dirPath, QDirIterator::Subdirectories);

    while (dirIt.hasNext())
    {
        QString fileName = dirIt.next();
        QFileInfo fionfo(fileName);

        // skip non file objetcs
        if (!fionfo.isFile()) continue;

        try
        {
            loadPlugin(fileName);
        }catch (...)
        {
            qDebug() << "Can't load plugin from " << pluginsDir.absoluteFilePath(fileName);
        }
    }
}
Example #3
0
VatesParaViewApplication::VatesParaViewApplication()
    : m_logger("VatesParaViewApplication"), m_behaviorsSetup(false) {
  // Get the plugin path that we set in the ConfigService.
  auto &configSvc = Kernel::ConfigService::Instance();
  // This currently points at the top pvplugins directory and not the
  // subdirectory.
  // Needs tidying up!!
  std::string pvPluginPathTop = configSvc.getPVPluginsPath();
  if (pvPluginPathTop.empty()) {
    throw std::runtime_error(
        "pvplugins.directory key not setup.\nVates plugins will not be "
        "available.\n"
        "Further use will cause the program to crash.\nPlease exit and "
        "set this variable.");
  }

  Q_ASSERT(pqApplicationCore::instance() == NULL);

  // Provide ParaView's application core with a path to the running executable
  int argc = 1;
  std::string exePath = configSvc.getPathToExecutable();
  std::vector<char> argvConversion(exePath.begin(), exePath.end());
  argvConversion.push_back('\0');
  char *argv[] = {&argvConversion[0]};

  m_logger.debug("Intialize pqApplicationCore with " + exePath + "\n");
  // We need to manually set the PV_PLUGIN_PATH because it's
  // not going to be picked up from the paraview/vtk side otherwise.
  Poco::Path pluginsDir(pvPluginPathTop, "pvplugins");
  m_logger.debug("Setting PV_PLUGIN_PATH=" + pluginsDir.toString() + "\n");
  vtksys::SystemTools::PutEnv("PV_PLUGIN_PATH=" + pluginsDir.toString());
  new pqPVApplicationCore(argc, argv);
}
Example #4
0
void ScriptPlugins :: load(QScriptEngine *engine)
{
  auto const softpath = QProcessEnvironment::systemEnvironment().value("SOFTBASE", SOFTBASE);
  QStringList pluginList;
  QCoreApplication::addLibraryPath (softpath + "/modules");
  auto const pluginPath = softpath + "/plugins";
  QDir pluginsDir(pluginPath);
  auto files = pluginsDir.entryList(QDir::Files);
  foreach( auto const &file, files ) {
    if( QLibrary::isLibrary(file) ) {
      auto loader = new QPluginLoader(pluginsDir.absoluteFilePath(file), this);
      auto const ok = loader->load();
      if( ok ) {
        d->pluginsMap.insert(file, loader);
        auto const jsonObj = loader->metaData();
        if (jsonObj.value("IID") == "org.sintef.soft/ISoftPlugin/0.1") {
          auto pluginPtr = qobject_cast<ISoftPlugin*>(loader->instance());
          if( pluginPtr ) {
            pluginPtr->registerPlugin(engine);
            pluginList << file;
          }
          else {
            QTextStream(stdout) << "failed to register: " << loader->errorString() << endl;
          }
        }
      }
    }
  }
  auto const l = qScriptValueFromSequence(engine, pluginList);
  engine->globalObject().setProperty("__script_plugins__", l);
}
Example #5
0
void suiPluginManager::loadPluginsFromDir(const QString &dirPath, bool subdirs)
{
    if (!QDir(dirPath).exists()) SuiExcept(SuiExceptionFileNotFound,
                                           QString("Directory '%1' doesn't exist").arg(dirPath),
                                           "void suiPluginManager::loadPluginsFromDir(const QString &dirPath)");
    QDir pluginsDir(dirPath);

    QDirIterator dirIt(pluginsDir, subdirs ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags);

    while (dirIt.hasNext())
    {
        QString fileName = dirIt.next();
        QFileInfo fionfo(fileName);

        // skip non file objetcs
        if (!fionfo.isFile()) continue;

        try
        {
            loadPlugin(fileName);
        }catch (...)
        {
            qDebug() << "Can't load plugin from " << pluginsDir.absoluteFilePath(fileName);
        }
    }
}
Example #6
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    SettingsObserver(Settings::Category::Layout),
    ui(new Ui::MainWindow),
    m_treeView(0),
    m_graphicsItemView(0),
    m_graphicsScene(0),
    m_proxyModel(0),
    m_model(0),
    m_addSymbolsDialog(0),
    m_aboutDialog(0),
    m_settingsDialog(0),
    m_smuflLoader(0),
    m_commonApplication(0)
{
    ui->setupUi(this);

    m_commonApplication = new CommonApplication();
    m_sharedApplication = Application(m_commonApplication);

    LayoutSettings::registerObserver(this);

    QDir pluginsDir(QCoreApplication::applicationDirPath());
    if (!pluginsDir.exists(pluginsDirName)) {
        pluginsDir.mkdir(pluginsDirName);
    }
    pluginsDir.cd(pluginsDirName);

    initMusicFont();

    m_addSymbolsDialog = new AddSymbolsDialog(this);
    m_aboutDialog = new AboutDialog(this);
    m_settingsDialog = new SettingsDialog(this);

    CommonPluginManager *pluginManager = new CommonPluginManager(pluginsDir);
    m_pluginManager = PluginManager(pluginManager);
    pluginManager->setSharedPluginManager(m_pluginManager);
    pluginManager->setMusicFont(m_musicFont);

    createModelAndView();
    createMenusAndToolBars();
    createAndPopulateSymbolPalettes();
    createConnections();
    // Show at least first instrument palette
    if (m_pluginManager->instrumentNames().count()) {
        QString instrumentName = m_pluginManager->instrumentNames().at(0);
        QDockWidget *instrumentDock = m_symbolDockWidgets.value(instrumentName);
        if (instrumentDock) {
            instrumentDock->setVisible(true);
        }
    }
    createObjectNames();

    setWindowTitle(tr("%1 [*]")
                   .arg(QApplication::applicationName()));
    updateUi();
}
void PropertyEditorCore::loadPlugins()
{
    QFileInfoList files;
    QStringList dirs;
    dirs << PROPERTYEDITOR_PLUGINS_PATH;
    dirs << "propertyeditor_plugins";

    foreach (const QString & dirName, dirs) {
        QDir pluginsDir(dirName);
        files += pluginsDir.entryInfoList(QDir::Files);
    }
Example #8
0
bool MainWindow::loadPlugins()
{
    bool res = false;
    QDir pluginsDir( qApp->applicationDirPath() );
    pluginsDir.cd( "plugins" );

    Q_FOREACH( const QString& fileName, pluginsDir.entryList( QDir::Files ) )
        if ( const QObject *plugin = QPluginLoader( pluginsDir.absoluteFilePath( fileName ) ).instance() )
            res |= populateMenu( plugin );

    return res;
}
void CompositorLauncher::detectLibInput()
{
    // Do we have the libinput plugin?
    for (const QString &path: QCoreApplication::libraryPaths()) {
        QDir pluginsDir(path + QStringLiteral("/generic"));
        for (const QString &fileName: pluginsDir.entryList(QDir::Files)) {
            if (fileName == QStringLiteral("libqlibinputplugin.so")) {
                m_hasLibInputPlugin = true;
                break;
            }
        }
    }
}
//---------------------------------------------------------------------
// PosSettingsPluginsLoader::loadPlugins
// 
//---------------------------------------------------------------------
QList<PosSettingsAdvInterface*> PosSettingsPluginsLoader::loadPlugins()
    {
    qDebug() << "+ PosSettingsPluginsLoader::loadPlugins()";
    // parse the default cen rep key value which is used to determine
    // the order of loading the default positioning settings plugins
    ParseCenRepKey();
    // List containing the plugins implementing the PositioningSettingsAdvancedInterface
    QList<PosSettingsAdvInterface*> pluginsList;
    // Check for the files under the positioningsettings directory
    QDir pluginsDir(PLUGIN_PATH + QDir::separator());
    QFileInfoList fileInfoList = pluginsDir.entryInfoList();
    // check each file in this directory,only if its a dll give it to the
    // plugin loader
    foreach ( const QFileInfo &fileInfo, fileInfoList )
            {
            QString fileName = fileInfo.absoluteFilePath();
						qDebug() << "Filename: " <<  fileName;
						
            if (!QLibrary::isLibrary(fileName))
                {
                continue;
                }
            // load the dlls using QPluginLoader
            QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
            qDebug() << "Plugin Filename: " <<  pluginsDir.absoluteFilePath(fileName);
            QObject *plugin = pluginLoader.instance();
            // Check if the plugin found is an implementation of the
            // PosSettingsAdvInterface,if yes add it to the plugins list

            if (plugin)
                {
                PosSettingsAdvInterface* advancedInterface = qobject_cast<
                        PosSettingsAdvInterface *> (plugin);

                if (advancedInterface)
                    {
                    
                    QString dllName = fileInfo.baseName();
                    // check the position into which the plugin needs to be
                    // inserted if it is one of the default plugins
                    for (int i = 0; i < mDllNameList.count(); i++)
                        {
                        if (dllName.compare(mDllNameList[i],Qt::CaseInsensitive) == KErrNone)
                            {
                            pluginsList.insert(i, advancedInterface);
                            break;
                            }
                        }
                    }
                }
            }
Example #11
0
void g19daemon::loadPlugins()
{
	PluginInterface *pluginint;
	QDir pluginsDir(qApp->applicationDirPath());
	QString name;
	
	name = settings->value("ActivePlugin").toString();
	pluginsDir.cd(PLUGINS_DIR);
	QDirIterator iterator(pluginsDir.absolutePath(), QStringList() << "*.so", QDir::Files, QDirIterator::NoIteratorFlags);

	while (iterator.hasNext())
	{
		iterator.next();
		QString filename = iterator.fileName();
		
		QPluginLoader pluginLoader(iterator.filePath());
		pluginLoader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
		QObject *plugin = pluginLoader.instance();
		
		if (plugin)
		{
			pluginint = qobject_cast<PluginInterface *>(plugin);
			
			if (pluginint)
			{
				QObject *signalsource = pluginint->getQObject();
				connect(signalsource, SIGNAL(doAction(gAction, void *)), this, SLOT(doAction(gAction, void *)));

				if (pluginint->isPopup())
				{
					PopupPlugins.append(pluginint);
				}
				else
				{
					plugins.append(pluginint);

					if (pluginint->getName().compare(name) == 0)
					{
						activePlugin = plugins.indexOf(pluginint);
					}
				}
			}
		}
		else
		{
			QErrorMessage err(this);
			err.showMessage(pluginLoader.errorString());
			qDebug() << "\tError: " << pluginLoader.errorString();
		}
	}
Example #12
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QDir pluginsDir(app.applicationDirPath() + "/plugins");
    for (const QString &fileName: pluginsDir.entryList(QDir::Files)) {
        QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
        QQmlExtensionPlugin *plugin = qobject_cast<QQmlExtensionPlugin *>(loader.instance());
        if (plugin)
            plugin->registerTypes("ShapesOriginal");
    }

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/files/ellipse9.qml")));
    return app.exec();
}
QStringList QAudioPluginLoader::pluginList() const
{
#if !defined QT_NO_DEBUG
    const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
#endif

    QStringList paths = QApplication::libraryPaths();
#ifdef QTM_PLUGIN_PATH
    paths << QLatin1String(QTM_PLUGIN_PATH);
#endif
#if !defined QT_NO_DEBUG
    if (showDebug)
        qDebug() << "Plugin paths:" << paths;
#endif

    //temp variable to avoid multiple identic path
    QSet<QString> processed;

    /* Discover a bunch o plugins */
    QStringList plugins;

    /* Enumerate our plugin paths */
    for (int i=0; i < paths.count(); i++) {
        if (processed.contains(paths.at(i)))
            continue;
        processed.insert(paths.at(i));
        QDir pluginsDir(paths.at(i)+m_location);
        if (!pluginsDir.exists())
            continue;

        QStringList files = pluginsDir.entryList(QDir::Files);
#if !defined QT_NO_DEBUG
        if (showDebug)
            qDebug()<<"Looking for plugins in "<<pluginsDir.path()<<files;
#endif
        for (int j=0; j < files.count(); j++) {
            const QString &file = files.at(j);
#if defined(Q_WS_MAEMO_5)
            if (!file.contains(QLatin1String("n900audio")))
#endif
            plugins <<  pluginsDir.absoluteFilePath(file);
        }
    }
    return  plugins;
}
Example #14
0
//--------------------------------------
QStringList getSearchPaths() {
  QStringList paths;
  paths.append(QFileInfo(qApp->applicationDirPath(), "plugins").absoluteFilePath());
  paths.append(QFileInfo(QDir::currentPath(), "plugins").absoluteFilePath());
  paths.append(getUserPluginsDirectory());

#ifdef Q_OS_MAC
  QDir pluginsDir(qApp->applicationDirPath());
  pluginsDir.cdUp();
  pluginsDir.cd("PlugIns");
  pluginsDir.cd("services");
  paths.append(pluginsDir.path());
  qWarning() << "OSX Application Plugins Path:" << pluginsDir.path();
#endif

#ifdef Q_OS_LINUX
  paths.append("/usr/share/mellowplayer/plugins");
  paths.append("/usr/local/share/mellowplayer/plugins");
#endif

  return QSet<QString>::fromList(paths).toList();
}
Example #15
0
int main(int argc, char *argv[])
{
    // Configure qt environment.
#if !defined(IREMOTE_NO_QT_PLUGINS)
    // Specify subdirectory where plugins are located.
 #if defined(WIN32)
    QDir pluginsDir(argv[0]);
    pluginsDir.cdUp();
    pluginsDir.cd("plugins");
    QApplication::setLibraryPaths(QStringList(pluginsDir.absolutePath()));
 #elif defined(__MACH__)
    QDir pluginsDir(argv[0]);
    pluginsDir.cdUp();
    pluginsDir.cdUp();
    pluginsDir.cd("plugins");
    QApplication::setLibraryPaths(QStringList(pluginsDir.absolutePath()));
 #endif // Platform
#endif //Plugins

    QApplication app(argc, argv);

	// Check whether another instance of the application is already running.
	RemotePC::InstanceLockPtr instanceLock = RemotePC::InstanceLock::SharedLock();
	if ( !instanceLock )
	{
		// TODO: Notify another instance on this attempt ...
		// .. and quit.
		return 0;
	}

#if defined(__MACH__)
    // Disable App Nap
    RemotePC::AppNapSuspender appNapSuspender;
#endif // __MACH__

	// Configure default style sheet.
    app.setStyleSheet(RemotePC::UIConfig::globalStylesheet_);

	// Prevents from terminating application when:
	//  main window is hidden to tray and user closes any other window.
	app.setQuitOnLastWindowClosed(false);

	// Load application settings.
	QDir configDir(QApplication::applicationDirPath());
	RemotePC::Config::Instance().Load(configDir.absolutePath().toUtf8().constData());

	// Launch shell service.
	RemotePC::ShellHost::Instance().Launch();

	// Display application UI.
    Dialog w;
    w.show();
    int retCode = app.exec();

	// Stop shell service.
	RemotePC::ShellHost::Instance().Exit();

	// Save config when application is subject to close.
	RemotePC::Config::Instance().Save();

	return retCode;
}
Example #16
0
void PluginManager::Load()
{
    wxString ext;
#if defined (__WXGTK__)
    ext = wxT("so");

#elif defined(__WXMAC__)
    ext = wxT("dylib");

#else
    ext = wxT("dll");
#endif

    wxString fileSpec( wxT( "*." ) + ext );
    clConfig conf("plugins.conf");

    conf.ReadItem( &m_pluginsData );

    //set the managers
    //this code assures us that the shared objects will see the same instances as the application
    //does
    LanguageST::Get()->SetTagsManager( GetTagsManager() );
    TagsManagerST::Get()->SetLanguage( LanguageST::Get() );

    // Plugin loading policy
    CodeLiteApp* app = static_cast<CodeLiteApp*>( GetTheApp() );
    CodeLiteApp::PluginPolicy pp = app->GetPluginLoadPolicy();
    wxArrayString allowedPlugins;
    if( pp == CodeLiteApp::PP_None )
        return;

    else if( pp == CodeLiteApp::PP_FromList )
        allowedPlugins = app->GetAllowedPlugins();

#ifdef __WXGTK__
    wxString pluginsDir(PLUGINS_DIR, wxConvUTF8);
#else
    wxString pluginsDir(ManagerST::Get()->GetInstallDir() + wxT( "/plugins" ));
#endif

    if ( wxDir::Exists(pluginsDir) ) {

        //get list of dlls
        wxArrayString files;
        wxDir::GetAllFiles( pluginsDir, &files, fileSpec, wxDIR_FILES );

        // Sort the plugins by A-Z
        std::sort(files.begin(), files.end());
        for ( size_t i=0; i<files.GetCount(); i++ ) {

            wxString fileName( files.Item( i ) );
#if defined(__WXMSW__) && !defined(NDEBUG)

            // Under MSW loading a release plugin while in debug mode will cause a crash
            if ( !fileName.EndsWith("-dbg.dll") ) {
                continue;
            }
#elif defined(__WXMSW__)

            // filter debug plugins
            if ( fileName.EndsWith("-dbg.dll") ) {
                continue;
            }
#endif

            clDynamicLibrary *dl = new clDynamicLibrary();
            if ( !dl->Load( fileName ) ) {
                CL_ERROR( wxT( "Failed to load plugin's dll: " ) + fileName );
                if (!dl->GetError().IsEmpty()) {
                    CL_ERROR(dl->GetError());
                }
                continue;
            }

            bool success( false );
            GET_PLUGIN_INFO_FUNC pfnGetPluginInfo = ( GET_PLUGIN_INFO_FUNC )dl->GetSymbol( wxT( "GetPluginInfo" ), &success );
            if ( !success ) {
                continue;
            }

            // load the plugin version method
            // if the methods does not exist, handle it as if it has value of 100 (lowest version API)
            int interface_version(100);
            GET_PLUGIN_INTERFACE_VERSION_FUNC pfnInterfaceVersion = (GET_PLUGIN_INTERFACE_VERSION_FUNC) dl->GetSymbol(wxT("GetPluginInterfaceVersion"), &success);
            if ( success ) {
                interface_version = pfnInterfaceVersion();
            } else {
                CL_WARNING(wxT("Failed to find GetPluginInterfaceVersion() in dll: ") + fileName);
                if (!dl->GetError().IsEmpty()) {
                    CL_WARNING(dl->GetError());
                }
            }

            if ( interface_version != PLUGIN_INTERFACE_VERSION ) {
                CL_WARNING(wxString::Format(wxT("Version interface mismatch error for plugin '%s'. Plugin's interface version is '%d', CodeLite interface version is '%d'"),
                                            fileName.c_str(),
                                            interface_version,
                                            PLUGIN_INTERFACE_VERSION));
                continue;
            }

            // Check if this dll can be loaded
            PluginInfo pluginInfo = pfnGetPluginInfo();

            wxString pname = pluginInfo.GetName();
            pname.MakeLower().Trim().Trim(false);

            // Check the policy
            if(pp == CodeLiteApp::PP_FromList && allowedPlugins.Index(pname) == wxNOT_FOUND) {
                // Policy is set to 'from list' and this plugin does not match any plugins from
                // the list, don't allow it to be loaded
                continue;
            }

            // Add the plugin information
            m_pluginsData.AddPlugin( pluginInfo );

            // Can we load it?
            if ( !m_pluginsData.CanLoad( pluginInfo.GetName()) ) {
                CL_WARNING( wxT( "Plugin " ) + pluginInfo.GetName() + wxT(" is not enabled") );
                continue;
            }

            // try and load the plugin
            GET_PLUGIN_CREATE_FUNC pfn = ( GET_PLUGIN_CREATE_FUNC )dl->GetSymbol( wxT( "CreatePlugin" ), &success );
            if ( !success ) {
                CL_WARNING(wxT("Failed to find CreatePlugin() in dll: ") + fileName);
                if (!dl->GetError().IsEmpty()) {
                    CL_WARNING(dl->GetError());
                }

                m_pluginsData.DisablePlugin( pluginInfo.GetName() );
                continue;
            }

            // Construct the plugin
            IPlugin *plugin = pfn( ( IManager* )this );
            CL_DEBUG( wxT( "Loaded plugin: " ) + plugin->GetLongName() );
            m_plugins[plugin->GetShortName()] = plugin;

            // Load the toolbar
            clToolBar *tb = plugin->CreateToolBar( (wxWindow*)clMainFrame::Get() );
            if ( tb ) {
#if USE_AUI_TOOLBAR
                // When using AUI toolbars, use our own custom art-provider
                tb->SetArtProvider(new CLMainAuiTBArt());
#endif
                clMainFrame::Get()->GetDockingManager().AddPane( tb, wxAuiPaneInfo().Name( plugin->GetShortName() ).LeftDockable( true ).RightDockable( true ).Caption( plugin->GetShortName() ).ToolbarPane().Top().Row(1) );

                //Add menu entry at the 'View->Toolbars' menu for this toolbar
                wxMenuItem* item = clMainFrame::Get()->GetMenuBar()->FindItem(XRCID("toolbars_menu"));
                if (item) {
                    wxMenu* submenu = NULL;
                    submenu = item->GetSubMenu();
                    //add the new toolbar entry at the end of this menu

                    int id = wxNewId();
                    wxString text(plugin->GetShortName());
                    text << _(" ToolBar");
                    wxMenuItem *newItem = new wxMenuItem(submenu, id, text, wxEmptyString, wxITEM_CHECK);
                    submenu->Append(newItem);
                    clMainFrame::Get()->RegisterToolbar(id, plugin->GetShortName());
                }
            }

            // Let the plugin plug its menu in the 'Plugins' menu at the menu bar
            // the create menu will be placed as a sub menu of the 'Plugin' menu
            wxMenu* pluginsMenu = NULL;
            wxMenuItem* menuitem = clMainFrame::Get()->GetMenuBar()->FindItem( XRCID("manage_plugins"), &pluginsMenu );
            if ( menuitem && pluginsMenu ) {
                plugin->CreatePluginMenu( pluginsMenu );
            }

            // Keep the dynamic load library
            m_dl.push_back( dl );
        }
        clMainFrame::Get()->GetDockingManager().Update();

        //save the plugins data
        conf.WriteItem( &m_pluginsData );
    }
}
Example #17
0
suiRoot::suiRoot(QMainWindow *mainWindow, QObject *parent) :
    QObject(parent),
    mMainWindow(mainWindow),
    mComponentsManager(0),
    mPluginManager(0),
    mMemoryInterface(0),
    mScHelper(0),
    mKnowBase(0),
    mKpm(0),
    mMainScWindow(0)
{
    Q_ASSERT(mInstance == 0);
    mInstance = this;

    mComponentsManager = new suiComponentsManager(this);
    mPluginManager = new suiPluginManager(this);

    // load plugins
    QDir pluginsDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
    pluginsDir.cdUp();
    pluginsDir.cd("plugins");
#elif defined(Q_OS_LINUX)
    pluginsDir.cd("plugins");
#endif    
    // load sc plugins
    mPluginManager->loadPluginsFromDir(pluginsDir.absoluteFilePath("sc"), false);
    scMemory()->initialize("../kb");

    // create knowledge base control class
    mKnowBase = new suiKnowBase(this);
    mKnowBase->initialize();
    // load ui plugins
    mPluginManager->loadPluginsFromDir(pluginsDir.absoluteFilePath("ui"), true);
    // load sources
    //mKnowBase->loadSources(QStringList());// << "../repo/sources");

    // create main window
    UiComponentFactoryInterfaceList res;
    Q_ASSERT(mComponentsManager->factoriesList(UiComponentMainWindow, res));
    mMainScWindow = qobject_cast<UiMainWindowInterface*>(res.front()->createInstance());
    mMainScWindow->setUri(mScHelper->keynode("/ui/main_window"));

    mMainWindow->setCentralWidget(mMainScWindow->widget());

    // initialize knowledge processing machine
    mKpm = new suiKpm(this);
    mKpm->initialize();


    // >>>>> test
    // show main menu on main window
    ScUri main_menu = scHelper()->keynode("/ui/main_menu");
    ScUri decomp = scHelper()->keynode("/etc/decomposition*");

    // get set of child items for main menu
    ScUriVector v;
    if (scHelper()->searchOneShot(ScTemplate() << ScElementType(ScNode | ScConst)
                              << ScElementType(ScArcCommon | ScConst)
                              << main_menu
                              << ScElementType(ScArcMain)
                              << decomp, v))
    {
        ScUriList objects;
        ScTemplate templ;
        templ << v[0] << ScElementType(ScArcMain) << ScElementType(ScNode | ScConst);
        ScSafeIterator it(scMemory(), templ);
        while (!it.is_over())
        {
            objects << it.value(2);
            it.next();
        }

        mMainScWindow->showObjects(objects);
    }

    // <<<<<<< test
}
Example #18
0
void PluginLoader::loadPlugins(
        iscore::ApplicationRegistrar& registrar,
        const iscore::ApplicationContext& context)
{
    auto folders = pluginsDir();

    // Here, the plug-ins that are effectively loaded.
    std::vector<iscore::Plugin_QtInterface*> availablePlugins;

    // Load static plug-ins
    for(QObject* plugin : QPluginLoader::staticInstances())
    {
        if(auto iscore_plug = dynamic_cast<iscore::Plugin_QtInterface*>(plugin))
            availablePlugins.push_back(iscore_plug);
    }

    QSet<QString> pluginFiles;
#if !defined(ISCORE_STATIC_QT)
    // Load dynamic plug-ins
    for(const QString& pluginsFolder : folders)
    {
        QDir pluginsDir(pluginsFolder);
        for(const QString& fileName : pluginsDir.entryList(QDir::Files))
        {
            auto plug = loadPlugin(pluginsDir.absoluteFilePath(fileName), availablePlugins);

            if(!plug.first.isEmpty())
            {
                pluginFiles.insert(plug.first);
            }

            if(plug.second)
            {
                availablePlugins.push_back(plug.second);
            }
        }
    }
#endif

    // First bring in the plugin objects
    registrar.registerPlugins(
                pluginFiles.toList(),
                availablePlugins);


    // Here, it is important not to collapse all the for-loops
    // because for instance a ApplicationPlugin from plugin B might require the factory
    // from plugin A to be loaded prior.
    // Load all the factories.
    for(iscore::Plugin_QtInterface* plugin : availablePlugins)
    {
        auto facfam_interface = dynamic_cast<FactoryList_QtInterface*> (plugin);

        if(facfam_interface)
        {
            for(auto&& elt : facfam_interface->factoryFamilies())
            {
                registrar.registerFactory(std::move(elt));
            }
        }
    }

    // Load all the application context plugins.
    // We have to order them according to their dependencies
    PluginDependencyGraph graph;
    for(auto plugin : availablePlugins)
    {
        graph.addNode(dynamic_cast<QObject*>(plugin));
    }

    graph.visit([&] (QObject* plugin) {
        auto ctrl_plugin = dynamic_cast<GUIApplicationContextPlugin_QtInterface*> (plugin);
        if(ctrl_plugin)
        {
            auto plug = ctrl_plugin->make_applicationPlugin(context);
            registrar.registerApplicationContextPlugin(plug);
        }
    });

    // Load what the plug-ins have to offer.
    for(auto plugin : availablePlugins)
    {
        auto panel_plugin = dynamic_cast<PanelFactory_QtInterface*> (plugin);
        if(panel_plugin)
        {
            auto panels = panel_plugin->panels();
            for(auto panel : panels)
            {
                registrar.registerPanel(panel);
            }
        }

        auto commands_plugin = dynamic_cast<CommandFactory_QtInterface*> (plugin);
        if(commands_plugin)
        {
            registrar.registerCommands(commands_plugin->make_commands());
        }

        auto factories_plugin = dynamic_cast<FactoryInterface_QtInterface*> (plugin);
        if(factories_plugin)
        {
            for(auto& factory_family : registrar.components().factories)
            {
                for(auto&& new_factory : factories_plugin->factories(context, factory_family.first))
                {
                    factory_family.second->insert(std::move(new_factory));
                }
            }
        }
    }
}
//FIXME: keep loaded plugins in own plugin manager and
//unload plugins to let load new version without
//the need to restart the application
void RackWindow::loadPlugin(QWidget *pluginHost)
{
    QDir pluginsDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
    if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
        pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
    if (pluginsDir.dirName() == "MacOS") {
        pluginsDir.cdUp();
        pluginsDir.cdUp();
        pluginsDir.cdUp();
    }
#endif

    if (!pluginsDir.cd("plugins"))
    {
        QMessageBox::information(this, "Error", "No plugin folder found");
        return;
    }


    QStringList pluginList = pluginsDir.entryList(QDir::Files);


    RSelectPluginDialog pluginDialog(this);
    pluginDialog.pluginListWidget->addItems(pluginList);
    pluginDialog.pluginListWidget->setCurrentRow(0);
    if (pluginDialog.exec())
    {



//    bool ok;
//    int newPluginIndex = RSelectPluginDialog::getIndex(this, pluginList, &ok);
//    if (ok) {

        //QString fileName = pluginsDir.entryList(QDir::Files).at(newPluginIndex);

        QString fileName = pluginsDir.entryList(QDir::Files).at(pluginDialog.pluginListWidget->currentRow());

        QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
        QObject *plugin = pluginLoader.instance();


        ///test

//        QList<QPluginLoader *> loadedPlugins = findChildren<QPluginLoader *>();

//        QObject *plugin = 0;

//        for (int i = 0; i < loadedPlugins.size(); ++i) {
//            if (loadedPlugins.at(i)->fileName() == pluginsDir.absoluteFilePath(fileName)) {
//                plugin = loadedPlugins.at(i)->instance();
//                break;
//            }
//        }

//        if (!plugin) {
//            QPluginLoader *pluginLoader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName), this);
//            plugin = pluginLoader->instance();
//        }


        //debug code
        qDebug() << "we have the following plugins loaded:";
        QList<QPluginLoader *> debugPlugins = findChildren<QPluginLoader *>();
        for (int i = 0; i < debugPlugins.size(); ++i) {
            qDebug() << debugPlugins.at(i)->fileName();
        }


        //////////


//        m_pluginLoader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName), this);
//        QObject *plugin = m_pluginLoader->instance();

        /////////////////


        if (plugin)
        {
            IWidgetPlugin *widgetPlugin = qobject_cast<IWidgetPlugin *>(plugin);
            if (widgetPlugin)
            {
                QWidget *newWidget = widgetPlugin->createRWidget(m_coreImpl, this);

                //get pointers from pluginhost:
                QStackedWidget *pluginStack = pluginHost->findChild<QStackedWidget *>("rackPluginStack");
                QToolBar *pluginHostToolBar = pluginHost->findChild<QToolBar *>("rackPluginHostToolBar");
                QToolBar *pluginToolBar = pluginHost->property("pluginToolBar").value<QToolBar *>();
                QSignalMapper *sm = pluginHost->findChild<QSignalMapper *>("rackPluginSwitchMapper");
                QActionGroup *ag = pluginHostToolBar->findChild<QActionGroup *>();

                //add plugin widget to the widget stack:
                pluginStack->setCurrentIndex(pluginStack->addWidget(newWidget));

                //create action for the toolbars:
                QAction *act = new QAction(widgetPlugin->name(), ag);
                act->setCheckable(true);
                act->setChecked(true);
                //qt bugfix: set transparent dummy icon to move button text down or right
                act->setIcon(QIcon(":/images/transparent-icon.png"));

                //create button for pluginhost toolbar:
                QToolButton *tb = new QToolButton;
                tb->setObjectName(QLatin1String(newWidget->metaObject()->className()) + "ToolButton");
                tb->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
                tb->setFocusPolicy(Qt::NoFocus);
                tb->setDefaultAction(act);
                RPushButton *settingsButton = new RPushButton;
                settingsButton->setObjectName("rackPluginHostToolBarSettingsButton");
                RPushButton *deleteButton = new RPushButton;
                deleteButton->setObjectName("rackPluginHostToolBarDeleteButton");
                QHBoxLayout *hl = new QHBoxLayout(tb);
                hl->setSpacing(0);
                hl->setContentsMargins(0,0,1,0);
                hl->addStretch();
                hl->addWidget(settingsButton);
                hl->addWidget(deleteButton);
                pluginHostToolBar->addWidget(tb);

                //create button for plugin toolbar:
                QToolButton *tb1 = new QToolButton;
                tb1->setObjectName(QLatin1String(newWidget->metaObject()->className()) + "ToolButton");
                tb1->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                tb1->setFocusPolicy(Qt::NoFocus);
                tb1->setDefaultAction(act);
                pluginToolBar->addWidget(tb1);

                //connect action trigger to PluginSwitchMapper;
                QObject::connect(act, SIGNAL(triggered()), sm, SLOT(map()));
                sm->setMapping(act, newWidget);

                //connect delete signal
                //remove act from actiongroup and delete it:
                QObject::connect(deleteButton, SIGNAL(clicked()), m_mapperClosePlugin, SLOT(map()));
                m_mapperClosePlugin->setMapping(deleteButton, act);
                QObject::connect(deleteButton, SIGNAL(clicked()), newWidget, SLOT(deleteLater()));
                QObject::connect(deleteButton, SIGNAL(clicked()), tb1, SLOT(deleteLater()));
                QObject::connect(deleteButton, SIGNAL(clicked()), tb, SLOT(deleteLater()));

                //connect settings signal
                //if (plugin has settings) ...
                //QObject::connect(settingsButton, SIGNAL(clicked()),

            }
        }
        else
        {
            QMessageBox::information(this, "Error", "Could not load the plugin");
            qDebug() << pluginLoader.errorString();

        }
    }
}