PluginLoader.cc 45.5 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




//=============================================================================
//
//  CLASS Core - IMPLEMENTATION of the Plugin Loading
//
//=============================================================================


//== INCLUDES =================================================================

// -------------------- mview
#include "Core.hh"

#include <QMenuBar>
#include <QToolBox>
#include <QMessageBox>
#include <QApplication>
Jan Möbius's avatar
Jan Möbius committed
51
#include <QScrollArea>
Jan Möbius's avatar
 
Jan Möbius committed
52 53 54 55 56 57 58 59 60

#include <QPluginLoader>
#include "OpenFlipper/BasePlugin/BaseInterface.hh"
#include "OpenFlipper/BasePlugin/KeyInterface.hh"
#include "OpenFlipper/BasePlugin/BackupInterface.hh"
#include "OpenFlipper/BasePlugin/LoggingInterface.hh"
#include "OpenFlipper/BasePlugin/MouseInterface.hh"
#include "OpenFlipper/BasePlugin/PickingInterface.hh"
#include "OpenFlipper/BasePlugin/ToolboxInterface.hh"
Dirk Wilden's avatar
Dirk Wilden committed
61
#include "OpenFlipper/BasePlugin/OptionsInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
62 63 64 65 66 67 68 69 70 71 72 73
#include "OpenFlipper/BasePlugin/ToolbarInterface.hh"
#include "OpenFlipper/BasePlugin/TextureInterface.hh"
#include "OpenFlipper/BasePlugin/MenuInterface.hh"
#include "OpenFlipper/BasePlugin/ContextMenuInterface.hh"
#include "OpenFlipper/BasePlugin/ViewInterface.hh"
#include "OpenFlipper/BasePlugin/LoadSaveInterface.hh"
#include "OpenFlipper/BasePlugin/StatusbarInterface.hh"
#include "OpenFlipper/BasePlugin/INIInterface.hh"
#include "OpenFlipper/BasePlugin/GlobalAccessInterface.hh"
#include "OpenFlipper/BasePlugin/FileInterface.hh"
#include "OpenFlipper/BasePlugin/RPCInterface.hh"
#include "OpenFlipper/BasePlugin/ScriptInterface.hh"
74
// #include "OpenFlipper/BasePlugin/SecurityInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
75 76 77 78 79 80 81 82 83

#include "OpenFlipper/INIFile/INIFile.hh"

#include "OpenFlipper/common/GlobalOptions.hh"

#include <QMessageBox>
#include <QtScript/QScriptValueIterator>

#include <ACG/QtWidgets/QtFileDialog.hh>
Dirk Wilden's avatar
Dirk Wilden committed
84
#include "OpenFlipper/widgets/PluginDialog/PluginDialog.hh"
Jan Möbius's avatar
 
Jan Möbius committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

//== IMPLEMENTATION ==========================================================


bool Core::checkSlot(QObject* _plugin , const char* _slotSignature) {
  const QMetaObject* meta = _plugin->metaObject();
  int id = meta->indexOfSlot( QMetaObject::normalizedSignature( _slotSignature ) );
  return ( id != -1 );
}

bool Core::checkSignal(QObject* _plugin , const char* _signalSignature) {
  const QMetaObject* meta = _plugin->metaObject();
  int id = meta->indexOfSignal( QMetaObject::normalizedSignature( _signalSignature ) );
  return ( id != -1 );
}

 /** Load plugins from dir Plugins. The plugin information gets stored, toolbox and menu entries are created and the required signals and slots are connected.
  */
void Core::loadPlugins()
{
Dirk Wilden's avatar
Dirk Wilden committed
105
  //try to load plugins from new location
106
  QDir tempDir = QDir(OpenFlipper::Options::pluginDir());
Dirk Wilden's avatar
Dirk Wilden committed
107

108 109
  QStringList filters;

Jan Möbius's avatar
Jan Möbius committed
110 111 112 113

  filters << "*.dll";
  filters << "*.dylib";
  filters << "*.so";
Jan Möbius's avatar
Jan Möbius committed
114

115

Jan Möbius's avatar
 
Jan Möbius committed
116
  // Get all files in the Plugin dir
117
  QStringList pluginlist = tempDir.entryList(filters,QDir::Files);
Dirk Wilden's avatar
Dirk Wilden committed
118

119
  for (int i=0; i < pluginlist.size(); i++)
120
     pluginlist[i] = tempDir.absoluteFilePath(pluginlist[i]);
Jan Möbius's avatar
 
Jan Möbius committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

  // Get all config files to be used
  QStringList configFiles = OpenFlipper::Options::optionFiles();

  QStringList iniPlugins;
  for ( int fileCount = 0 ; fileCount < (int)configFiles.size() ; ++fileCount) {
    INIFile ini;

    if (  ini.connect(configFiles[fileCount],false) ) {

      // get all Plugin Names which will not be loaded
      QString dontLoadString;
      if (ini.get_entry( dontLoadString,"Plugins","DontLoad" ) ) {
        dontLoadPlugins_ = dontLoadPlugins_ + dontLoadString.split(";",QString::SkipEmptyParts);
      }

      std::vector< QString > loadKeys;

      if ( OpenFlipper::Options::is64bit() )
        loadKeys.push_back("Load64");

      if ( OpenFlipper::Options::is32bit() )
        loadKeys.push_back("Load32");

      loadKeys.push_back("Load");

      for ( uint keyit = 0 ; keyit < loadKeys.size() ; ++ keyit) {
        //Load additional Plugins given by ini file
        std::vector< QString > additionalPlugins;
        if (ini.get_entry( additionalPlugins,"Plugins",loadKeys[keyit] ) ) {
          for ( uint i = 0 ; i < additionalPlugins.size(); ++i) {
            iniPlugins << additionalPlugins[i];
              emit log(LOGOUT,"Additional Plugin from ini file : " +  additionalPlugins[i] );
          }
        }
      }

      ini.disconnect();

   } else
161
      emit log(LOGWARN,"Failed to connect to ProgramOptions.ini file: " + configFiles[fileCount]);
Jan Möbius's avatar
 
Jan Möbius committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
  }

  pluginlist = iniPlugins << pluginlist;


  // Sort plugins to load FilePlugins first
  QStringList filePlugins;
  QStringList textureControl;
  QStringList otherPlugins;
  //plugin Liste sortieren
  for (int i=0; i < pluginlist.size(); i++)
    if (pluginlist[i].contains("FilePolyLine") || pluginlist[i].contains("FileTriangleMesh") ||
        pluginlist[i].contains("FilePolyMesh"))
      filePlugins.push_back(pluginlist[i]);
    else if (pluginlist[i].contains("TextureControl"))
      textureControl.push_back(pluginlist[i]);
    else
      otherPlugins.push_back(pluginlist[i]);

  pluginlist = filePlugins << textureControl << otherPlugins;

  // Remove Whitespace from beginning and end of Plugin Names
  for ( int i = 0 ; i < dontLoadPlugins_.size() ; ++i )
    dontLoadPlugins_[i] = dontLoadPlugins_[i].trimmed();

  for ( int i = 0 ; i < dontLoadPlugins_.size(); ++i )
    emit log(LOGWARN,"Skipping Plugins :\t " + dontLoadPlugins_[i] );

  emit log(LOGOUT,"=============================================================================================");


  // Try to load each file as a plugin
  for ( int i = 0 ; i < pluginlist.size() ; ++i) {

    if ( OpenFlipper::Options::gui() && OpenFlipper::Options::splash() ) {
      splashMessage_ = "Loading Plugin " + QString::number(i) + "/"  + QString::number(pluginlist.size());
      splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
      QApplication::processEvents();
    }

Dirk Wilden's avatar
Dirk Wilden committed
202
    loadPlugin(pluginlist[i],true);
Jan Möbius's avatar
 
Jan Möbius committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
  }

  splashMessage_ = "";

  emit pluginsInitialized();

  emit log(LOGOUT,"Loaded " + QString::number(plugins.size()) + " Plugin(s)" );
}

/** @brief slot for loading Plugins
 */
void Core::slotLoadPlugin(){

  if ( OpenFlipper::Options::nogui() )
    return;


  QString filter;
  if ( OpenFlipper::Options::isWindows() )
    filter = "Plugins (*.dll)";
223 224
  else if ( OpenFlipper::Options::isDarwin() )
    filter = "Plugins (*.dylib)";
Jan Möbius's avatar
 
Jan Möbius committed
225 226 227
  else
    filter = "Plugins (*.so)";

228

Jan Möbius's avatar
 
Jan Möbius committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
  QString filename = ACG::getOpenFileName(coreWidget_,tr("Load Plugin"),filter,OpenFlipper::Options::currentDirStr());

  if (filename.isEmpty())
    return;

  // get the plugin name
  // and check if Plugin is in the dontLoad List

  QPluginLoader loader( filename );
  QObject *plugin = loader.instance();
  QString name;

  // Check if a plugin has been loaded
  if (plugin) {
    // Check if it is a BasePlugin
    BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugin);
    if ( basePlugin ) {
      name = basePlugin->name();
    }else
      return;
  }else
    return;

  if (dontLoadPlugins_.contains(name)){
      int ret = QMessageBox::question(0, tr("Plugin Loading Prevention"),
                   tr("OpenFlipper is currently configured to prevent loading this plugin.\n"
                      "Do you want to enable this plugin?"),
                   QMessageBox::Yes | QMessageBox::No,
                   QMessageBox::Yes);
      if (ret == QMessageBox::Yes)
        dontLoadPlugins_.removeAll(name);
      else
        return;
  }
  loadPlugin(filename,false);
}

Dirk Wilden's avatar
Dirk Wilden committed
266
/** @brief slot for showing loaded Plugins
Jan Möbius's avatar
 
Jan Möbius committed
267
 */
Dirk Wilden's avatar
Dirk Wilden committed
268
void Core::slotShowPlugins(){
Jan Möbius's avatar
 
Jan Möbius committed
269

Dirk Wilden's avatar
Dirk Wilden committed
270 271 272 273 274 275 276
  if ( OpenFlipper::Options::gui() ){

    int ret = 0;

    while (ret == 0){

      PluginDialog* dialog = new PluginDialog(plugins, coreWidget_);
Jan Möbius's avatar
 
Jan Möbius committed
277

Dirk Wilden's avatar
Dirk Wilden committed
278 279 280 281 282 283 284 285 286 287 288
      //connect signals
      connect(dialog, SIGNAL(unloadPlugin(QString)), this, SLOT(unloadPlugin(QString)));
      connect(dialog, SIGNAL(dontLoadPlugins(QStringList)), this, SLOT(dontLoadPlugins(QStringList)));
      connect(dialog, SIGNAL( loadPlugin() ), this, SLOT( slotLoadPlugin() ));

      //if a plugin was deleted/loaded the dialog returns 0 and it needs to be loaded again
      ret = dialog->exec();

      delete dialog;
    }
  }
Jan Möbius's avatar
 
Jan Möbius committed
289 290 291 292 293 294 295
}

/** @brief Unload a Plugin with given name (slot)
 *  @param name plugin name
 */
void Core::unloadPlugin(QString name){
  for (uint i=0; i < plugins.size(); i++)
Dirk Wilden's avatar
Dirk Wilden committed
296
    if (plugins[i].rpcName == name){
Jan Möbius's avatar
 
Jan Möbius committed
297 298 299 300 301 302 303 304
      if ( checkSlot( plugins[i].plugin , "exit()" ) )
        QMetaObject::invokeMethod(plugins[i].plugin, "exit",  Qt::DirectConnection);

      //remove toolbox widget
      QString name_nospace = name;
      name_nospace.remove(" ");
      if ( coreWidget_->viewModes_[0]->visibleWidgets.contains(name_nospace) )
        coreWidget_->viewModes_[0]->visibleWidgets.removeAt(coreWidget_->viewModes_[0]->visibleWidgets.indexOf(name_nospace));
305 306 307 308 309
      for ( uint j = 0 ; j < plugins[i].widgets.size() ; ++j )
        if (plugins[i].widgets[j].second ){
          plugins[i].widgets[j].second->setVisible(false);
          delete plugins[i].widgets[j].second;
        }
Jan Möbius's avatar
 
Jan Möbius committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

      plugins.erase(plugins.begin() + i);

      emit log(LOGOUT,"Unloaded Plugin :\t\t " + name);

      return;
    }

    log(LOGERR, "Unable to unload plugin '" + name + "' (plugin wasn't found)");
}

/** @brief prevent OpenFlipper from loading plugins on the next start (slot)
 *  @param _plugins semicolon separated string with plugin names
 */
void Core::dontLoadPlugins(QStringList _plugins){
  for (int i=0; i < _plugins.size(); i++)
    dontLoadPlugins_ << _plugins[i];
}

/** @brief Load a Plugin with given filename
 *  @param filename complete path + filename of the plugin
 *  @param silent if 'true': user isn't asked what to do if a plugin is already loaded
 */
void Core::loadPlugin(QString filename, bool silent){

  // Only load .dll under windows
  if ( OpenFlipper::Options::isWindows() ) {
    QString dllname = filename;
    if ( ! dllname.endsWith( ".dll" ) )
      return;
  }

  // Only load .so under linux
  if ( OpenFlipper::Options::isLinux() ) {
    QString soname = filename;
    if ( ! soname.endsWith( ".so" ) )
      return;
  }

  // Try to open the file
  QPluginLoader loader( filename );
  QObject *plugin = loader.instance();

  // Check if a plugin has been loaded
  if (plugin) {
Dirk Wilden's avatar
Dirk Wilden committed
355
    PluginInfo info;
Jan Möbius's avatar
 
Jan Möbius committed
356 357 358 359 360 361 362 363 364 365 366 367 368 369
    QString supported;

    // Check if it is a BasePlugin
    BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugin);
    if ( basePlugin ) {
      emit log(LOGOUT,"Found Plugin :\t\t " + basePlugin->name() + " at " + filename);

      if ( OpenFlipper::Options::gui() && OpenFlipper::Options::splash() ) {
        splashMessage_ = splashMessage_ + " " + basePlugin->name() ;
        splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
        QApplication::processEvents();
      }

      //Check if plugin is already loaded
Dirk Wilden's avatar
Dirk Wilden committed
370 371 372 373 374
      for (uint k=0; k < plugins.size(); k++){

          QString name_nospace =  basePlugin->name();
          name_nospace.remove(" ");

375 376 377 378 379
          if (plugins[k].name == name_nospace){
            if (silent || OpenFlipper::Options::nogui() ){ //dont load the plugin
              emit log(LOGWARN, "\t\t\t Already loaded from " + plugins[k].path);
              emit log(LOGOUT,"=============================================================================================");
              return;
Jan Möbius's avatar
 
Jan Möbius committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
          }else{ //ask the user
            int ret = QMessageBox::question(coreWidget_,
                                            tr("Plugin already loaded"),
                                            "A Plugin with the same name was already loaded from " +
                                            plugins[k].path + ".\n"
                                            "You can only load the new plugin if you unload the existing one first.\n\n"
                                            "Do you want to unload the existing plugin first?",
                                            QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
            if (ret == QMessageBox::Yes)
              unloadPlugin(plugins[k].name);
            else{
              emit log(LOGWARN, "\t\t\t Already loaded from " + plugins[k].path);
              emit log(LOGOUT,"=============================================================================================");
              return;
            }
          }
        }
Dirk Wilden's avatar
Dirk Wilden committed
397
      }
Jan Möbius's avatar
 
Jan Möbius committed
398 399 400 401 402 403 404

      if ( dontLoadPlugins_.contains(basePlugin->name(), Qt::CaseInsensitive) ) {
        emit log(LOGWARN,"OpenFlipper.ini prevented Plugin " + basePlugin->name() + " from being loaded! ");
        emit log(LOGOUT,"=============================================================================================");
        return;
      }

405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
//       //Check if it is a BasePlugin
//       SecurityInterface * securePlugin = qobject_cast< SecurityInterface * >(plugin);
//       if ( securePlugin ) {
//         emit log(LOGINFO,"Plugin uses security interface. Trying to authenticate against plugin ...");
//
//         QMetaObject::invokeMethod(plugin,"authenticate" ) ;
//
//         std::cerr << "2" << std::endl;
//
//         securePlugin->authenticate();
//
//         if ( true )
//
//           emit log(LOGINFO,"... ok. Loading plugin ");
//         else {
//           emit log(LOGERR,"... failed. Plugin access denied.");
//           emit log(LOGOUT,"=============================================================================================");
//           return;
//         }
//       }


Jan Möbius's avatar
 
Jan Möbius committed
427 428 429 430 431 432 433 434 435
      emit log(LOGOUT,"Plugin Desciption :\t\t " + basePlugin->description());

      supported = "BaseInterface ";

      info.name          = basePlugin->name();
      info.description   = basePlugin->description();
      info.plugin        = plugin;
      info.path          = filename;

436 437 438 439 440
      if ( checkSlot(plugin,"version()") )
        info.version = basePlugin->version();
      else
        info.version = QString::number(-1);

Jan Möbius's avatar
 
Jan Möbius committed
441 442 443 444 445 446 447 448 449 450 451
      if ( OpenFlipper::Options::nogui() ) {

        if ( ! checkSlot( plugin , "noguiSupported()" ) ) {
          emit log(LOGWARN,"Running in nogui mode which is unsupported by this plugin, skipping" );
          emit log(LOGOUT,"=============================================================================================");
          return;
        }

      }


452 453
      // Check for baseInterface of old style!
      if ( checkSignal(plugin,"updated_objects(int)") ) {
454
        log(LOGERR,"Plugin Uses old style updated_objects! Convert to updatedObject!");
455 456 457 458 459 460 461 462 463 464 465 466 467
        emit log(LOGOUT,"=============================================================================================");
        return;
      }

      if ( checkSignal(plugin,"update_view()") ) {
        log(LOGERR,"Plugin Uses old style update_view! Convert to updateView!");
        emit log(LOGOUT,"=============================================================================================");
        return;
      }

      if ( checkSignal(plugin,"updateView()") )
        connect(plugin,SIGNAL(updateView()),this,SLOT(updateView()));

468 469


470
      if ( checkSignal(plugin,"updatedObject(int)") )
471
        connect(plugin,SIGNAL(updatedObject(int)),this,SLOT(slotObjectUpdated(int)), Qt::DirectConnection);
472

473 474 475 476
      if ( checkSlot( plugin , "slotObjectUpdated(int)" ) )
        connect(this,SIGNAL(signalObjectUpdated(int)),plugin,SLOT(slotObjectUpdated(int)), Qt::DirectConnection);


Jan Möbius's avatar
Jan Möbius committed
477 478 479 480 481
      if ( checkSignal(plugin,"objectPropertiesChanged(int)"))
        connect(plugin,SIGNAL(objectPropertiesChanged(int)),this,SLOT(slotObjectPropertiesChanged(int)), Qt::DirectConnection);

      if ( checkSlot(plugin,"slotObjectPropertiesChanged(int)"))
        connect(this,SIGNAL(objectPropertiesChanged(int)),plugin,SLOT(slotObjectPropertiesChanged(int)), Qt::DirectConnection);
Jan Möbius's avatar
Jan Möbius committed
482

Jan Möbius's avatar
Jan Möbius committed
483
      if ( checkSignal(plugin,"visibilityChanged()" ) )
484
        emit log (LOGERR,"Signal visibilityChanged() now requires objectid or -1 as argument " );
Jan Möbius's avatar
 
Jan Möbius committed
485

486 487 488 489 490 491 492 493 494
      if ( checkSignal(plugin,"visibilityChanged(int)") )
        connect(plugin,SIGNAL(visibilityChanged(int)),this,SLOT(slotVisibilityChanged(int)), Qt::DirectConnection);

      if ( checkSlot(plugin,"slotVisibilityChanged(int)") )
        connect(this,SIGNAL(visibilityChanged(int)),plugin,SLOT(slotVisibilityChanged(int)), Qt::DirectConnection);

      if ( checkSignal(plugin,"activeObjectChanged()" ) )
        emit log (LOGERR,"Signal activeObjectChanged() is now objectSelectionChanged( int _objectId ) " );

Jan Möbius's avatar
Jan Möbius committed
495
      if ( checkSlot(plugin,"slotActiveObjectChanged()" ) )
Jan Möbius's avatar
Jan Möbius committed
496
        emit log (LOGERR,"Slot slotActiveObjectChanged() is now slotObjectSelectionChanged( int _objectId ) " );
Jan Möbius's avatar
 
Jan Möbius committed
497

Jan Möbius's avatar
Jan Möbius committed
498 499
      if ( checkSlot(plugin,"slotAllCleared()") )
        connect(this,SIGNAL(allCleared()),plugin,SLOT(slotAllCleared()));
500

Jan Möbius's avatar
 
Jan Möbius committed
501

502 503 504 505 506
      if ( checkSignal(plugin,"objectSelectionChanged(int)") )
        connect(plugin,SIGNAL(objectSelectionChanged(int)),this,SLOT(slotObjectSelectionChanged(int) ));

      if ( checkSlot( plugin , "slotObjectSelectionChanged(int)" ) )
        connect(this,SIGNAL(objectSelectionChanged(int)),plugin,SLOT(slotObjectSelectionChanged(int) ));
Jan Möbius's avatar
 
Jan Möbius committed
507 508 509 510


      if ( checkSlot( plugin , "pluginsInitialized()" ) )
        connect(this,SIGNAL(pluginsInitialized()),plugin,SLOT(pluginsInitialized()), Qt::DirectConnection);
511 512 513 514

      if ( checkSignal(plugin,"setSlotDescription(QString,QString,QStringList,QStringList)") )
        connect(plugin, SIGNAL(setSlotDescription(QString,QString,QStringList,QStringList)),
                this,   SLOT(slotSetSlotDescription(QString,QString,QStringList,QStringList)) );
Jan Möbius's avatar
 
Jan Möbius committed
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
    }

    //Check if its a filePlugin
    FileInterface* filePlugin = qobject_cast< FileInterface * >(plugin);
    if ( filePlugin ){
      supported = supported + "File ";

      // Collect supported Data from file plugin
      fileTypes ft;
      ft.type = filePlugin->supportedType();
      ft.loadFilters = filePlugin->getLoadFilters();
      ft.saveFilters = filePlugin->getSaveFilters();
      ft.plugin = filePlugin;

      supportedTypes_.push_back(ft);
    }

    GlobalAccessInterface* globalAccessPlugin = qobject_cast< GlobalAccessInterface * >(plugin);
    if ( globalAccessPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "!!GLOBAL ACCESS!! ";

536
      globalAccessPlugin->set_examiner( coreWidget_->examiner_widgets_[0] );
Jan Möbius's avatar
 
Jan Möbius committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557

    }

    //Check if the plugin supports Logging
    LoggingInterface* logPlugin = qobject_cast< LoggingInterface * >(plugin);
    if ( logPlugin ) {
      supported = supported + "Logging ";

      // Create intermediate logger class which will mangle the output
      PluginLogger* newlog = new PluginLogger(info.name);
      loggers_.push_back(newlog);
      connect(plugin,SIGNAL(log(Logtype, QString )),newlog,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
      connect(plugin,SIGNAL(log(QString )),newlog,SLOT(slotLog(QString )),Qt::DirectConnection);

      // Connect it to the core widget logger
      if ( OpenFlipper::Options::gui() )
        connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);

      // connection to console logger
      connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);

Dirk Wilden's avatar
Dirk Wilden committed
558 559 560
      // connection to file logger
      connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);

Jan Möbius's avatar
 
Jan Möbius committed
561 562 563 564 565 566 567 568 569 570
      // connection to external plugin logger
      if ( checkSlot(plugin,"logOutput(Logtype,QString)") )
        connect(this,SIGNAL(externalLog(Logtype,QString)), plugin, SLOT(logOutput(Logtype,QString)) ) ;
    }

    //Check if the plugin supports Menubar-Interface
    MenuInterface* menubarPlugin = qobject_cast< MenuInterface * >(plugin);
    if ( menubarPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "Menubar ";

Jan Möbius's avatar
 
Jan Möbius committed
571 572 573
      if ( checkSignal(plugin,"addMenubarAction(QAction*,MenuActionType)") )
        connect(plugin      , SIGNAL(addMenubarAction(QAction*,MenuActionType)),
                coreWidget_ , SLOT(slotAddMenubarAction(QAction*,MenuActionType)),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
574 575 576 577 578 579 580
    }

    //Check if the plugin supports ContextMenuInterface
    ContextMenuInterface* contextMenuPlugin = qobject_cast< ContextMenuInterface * >(plugin);
    if ( contextMenuPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "ContextMenu ";

Jan Möbius's avatar
 
Jan Möbius committed
581 582 583
      if ( checkSignal(plugin,"addContextMenuItem(QAction*,ContextMenuType)") )
        connect(plugin      , SIGNAL(addContextMenuItem(QAction*,ContextMenuType)),
                coreWidget_ , SLOT(slotAddContextItem(QAction*,ContextMenuType)),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
584

Jan Möbius's avatar
 
Jan Möbius committed
585 586 587
      if ( checkSignal(plugin,"addContextMenuItem(QAction*,DataType,ContextMenuType)") )
        connect(plugin      , SIGNAL(addContextMenuItem(QAction*,DataType,ContextMenuType)),
                coreWidget_ , SLOT(slotAddContextItem(QAction*,DataType,ContextMenuType)),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
588 589 590 591 592

      if ( checkSlot(plugin,"slotUpdateContextMenu(int)") )
        connect(coreWidget_ , SIGNAL(updateContextMenu(int)),
                plugin      , SLOT(slotUpdateContextMenu(int)),Qt::DirectConnection);

593 594 595 596 597 598 599
      if ( checkSlot(plugin,"slotUpdateContextMenuNode(int)") )
        connect(coreWidget_ , SIGNAL(updateContextMenuNode(int)),
                plugin      , SLOT(slotUpdateContextMenuNode(int)),Qt::DirectConnection);

      if ( checkSlot(plugin,"slotUpdateContextMenuBackground()") )
        connect(coreWidget_ , SIGNAL(updateContextMenuBackground()),
                plugin      , SLOT(slotUpdateContextMenuBackground()),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
600 601 602 603 604 605 606 607 608 609
    }

    //Check if the plugin supports Toolbox-Interface
    ToolboxInterface* toolboxPlugin = qobject_cast< ToolboxInterface * >(plugin);
    if ( toolboxPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "Toolbox ";

      QWidget* widget = 0;
      if ( toolboxPlugin->initializeToolbox( widget ) ) {

610
            info.widgets.push_back( std::pair< QString,QWidget* >( info.name , widget) );
Jan Möbius's avatar
 
Jan Möbius committed
611 612

            // add widget name to viewMode 'all'
613 614
            if ( !viewModes_[0]->visibleWidgets.contains(info.name) ){
              viewModes_[0]->visibleWidgets << info.name;
Jan Möbius's avatar
 
Jan Möbius committed
615 616 617 618 619 620 621 622
              viewModes_[0]->visibleWidgets.sort();
            }
      }

      if ( checkSignal(plugin, "defineViewMode(QString,QStringList)"))
        connect(plugin, SIGNAL( defineViewMode(QString, QStringList) ),
                coreWidget_, SLOT( slotAddViewMode(QString, QStringList) ),Qt::DirectConnection );

623 624
      if ( checkSignal(plugin, "addToolbox(QString,QWidget*)"))
        connect(plugin, SIGNAL( addToolbox(QString,QWidget*) ),
Jan Möbius's avatar
Jan Möbius committed
625
                this, SLOT( addToolbox(QString,QWidget*) ),Qt::DirectConnection );
626 627 628



Jan Möbius's avatar
 
Jan Möbius committed
629 630
    }

Dirk Wilden's avatar
Dirk Wilden committed
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
    //Check if the plugin supports Options-Interface
    OptionsInterface* optionsPlugin = qobject_cast< OptionsInterface * >(plugin);
    if ( optionsPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "Options ";

      QWidget* widget = 0;
      if ( optionsPlugin->initializeOptionsWidget( widget ) ) {
            info.optionsWidget = widget;

            if ( checkSlot(plugin,"applyOptions()") )
              connect(coreWidget_ , SIGNAL( applyOptions() ),
                      plugin      , SLOT( applyOptions() ),Qt::DirectConnection);
      }
    }

    //Check if the plugin supports Toolbar-Interface
Jan Möbius's avatar
 
Jan Möbius committed
647 648 649 650 651 652 653 654 655 656 657
    ToolbarInterface* toolbarPlugin = qobject_cast< ToolbarInterface * >(plugin);
    if ( toolbarPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "Toolbars ";

      if ( checkSignal(plugin,"addToolbar(QToolBar*)") )
        connect(plugin,SIGNAL(addToolbar(QToolBar*)),
                coreWidget_,SLOT(slotAddToolbar(QToolBar*)),Qt::DirectConnection);

      if ( checkSignal(plugin,"removeToolbar(QToolBar*)") )
        connect(plugin,SIGNAL(removeToolbar(QToolBar*)),
                coreWidget_,SLOT(slotRemoveToolbar(QToolBar*)),Qt::DirectConnection);
Jan Möbius's avatar
Jan Möbius committed
658 659 660 661

      if ( checkSignal(plugin,"getToolBar(QString,QToolBar*&)") )
        connect(plugin,SIGNAL(getToolBar(QString,QToolBar*&)),
                coreWidget_,SLOT(getToolBar(QString,QToolBar*&)),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
    }

    //Check if the plugin supports StatusBar-Interface
    StatusbarInterface* statusbarPlugin = qobject_cast< StatusbarInterface * >(plugin);
    if ( statusbarPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "StatusBar ";

      if ( checkSignal(plugin,"showStatusMessage(QString,int)") )
        connect(plugin,SIGNAL(showStatusMessage(QString,int)),
                coreWidget_,SLOT(statusMessage(QString,int)),Qt::DirectConnection);


      if ( checkSignal(plugin,"setStatus(ApplicationStatus::applicationStatus)") )
        connect(plugin,SIGNAL(setStatus(ApplicationStatus::applicationStatus)),
                coreWidget_,SLOT(setStatus(ApplicationStatus::applicationStatus)),Qt::DirectConnection);

      if ( checkSignal(plugin,"clearStatusMessage()") )
        connect(plugin,SIGNAL(clearStatusMessage()),
                coreWidget_,SLOT(clearStatusMessage()));

    }

    //Check if the plugin supports Key-Interface
    KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugin);
    if ( keyPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "KeyboardEvents ";

Dirk Wilden's avatar
Dirk Wilden committed
689 690 691
      if ( checkSignal(plugin,"registerKey(int,Qt::KeyboardModifiers,QString,bool)") )
        connect(plugin,SIGNAL( registerKey(int, Qt::KeyboardModifiers, QString, bool) ),
                coreWidget_,SLOT(slotRegisterKey(int, Qt::KeyboardModifiers, QString, bool)) );
Dirk Wilden's avatar
Dirk Wilden committed
692 693 694

//       if ( checkSlot( plugin , "slotKeyEvent(QKeyEvent*)" ) )
//         connect(coreWidget_,SIGNAL(PluginKeyEvent(QKeyEvent* )), plugin,SLOT(slotKeyEvent(QKeyEvent*)));
695
//
Dirk Wilden's avatar
Dirk Wilden committed
696 697
//       if ( checkSlot( plugin , "slotKeyReleaseEvent(QKeyEvent*)" ) )
//         connect(coreWidget_,SIGNAL(PluginKeyReleaseEvent(QKeyEvent* )), plugin,SLOT(slotKeyReleaseEvent(QKeyEvent*)));
Jan Möbius's avatar
 
Jan Möbius committed
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
    }

    //Check if the plugin supports Mouse-Interface
    MouseInterface* mousePlugin = qobject_cast< MouseInterface * >(plugin);
    if ( mousePlugin && OpenFlipper::Options::gui()  ) {
      supported = supported + "MouseEvents ";

      if ( checkSlot( plugin , "slotMouseWheelEvent(QWheelEvent*,const std::string&)" ) )
        connect(this   , SIGNAL(PluginWheelEvent(QWheelEvent * , const std::string & )),
                plugin , SLOT(slotMouseWheelEvent(QWheelEvent* , const std::string & )));

      if ( checkSlot( plugin , "slotMouseEvent(QMouseEvent*)" ) )
        connect(this   , SIGNAL(PluginMouseEvent(QMouseEvent*)),
                plugin , SLOT(slotMouseEvent(QMouseEvent*)));

      if ( checkSlot( plugin , "slotMouseEventIdentify(QMouseEvent*)" ) )
        connect(this   , SIGNAL(PluginMouseEventIdentify(QMouseEvent*)),
                plugin , SLOT(slotMouseEventIdentify(QMouseEvent*)));

    }

    //Check if the plugin supports Picking-Interface
    PickingInterface* pickPlugin = qobject_cast< PickingInterface * >(plugin);
    if ( pickPlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "Picking ";

      if ( checkSlot( plugin , "slotPickModeChanged(const std::string&)" ) )
725
        connect(coreWidget_,SIGNAL(signalPickModeChanged (const std::string &)),
Jan Möbius's avatar
 
Jan Möbius committed
726 727 728 729 730 731 732 733 734
                plugin,SLOT(slotPickModeChanged( const std::string &)));

      if ( checkSignal(plugin,"addPickMode(const std::string)") )
        connect(plugin,SIGNAL(addPickMode( const std::string )),
                this,SLOT(slotAddPickMode( const std::string )),Qt::DirectConnection);

      if ( checkSignal(plugin,"addHiddenPickMode(const std::string)") )
        connect(plugin,SIGNAL(addHiddenPickMode( const std::string )),
                this,SLOT(slotAddHiddenPickMode( const std::string )),Qt::DirectConnection);
735

Dirk Wilden's avatar
Dirk Wilden committed
736
      if ( checkSignal(plugin,"setPickModeCursor(const std::string,QCursor)") )
737 738
        for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
          connect(plugin,SIGNAL(setPickModeCursor( const std::string ,QCursor)),
739
                  coreWidget_,SLOT(setPickModeCursor( const std::string ,QCursor)),Qt::DirectConnection);
740

Jan Möbius's avatar
 
Jan Möbius committed
741

Dirk Wilden's avatar
Dirk Wilden committed
742
      if ( checkSignal(plugin,"setPickModeMouseTracking(const std::string,bool)") )
743 744
        for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
          connect(plugin,SIGNAL(setPickModeMouseTracking( const std::string ,bool)),
745
                  coreWidget_,SLOT(setPickModeMouseTracking( const std::string ,bool)),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
    }

    //Check if the plugin supports INI-Interface
    INIInterface* iniPlugin = qobject_cast< INIInterface * >(plugin);
    if ( iniPlugin ) {
      supported = supported + "INIFile ";

      if ( checkSlot( plugin , "loadIniFile(INIFile&,int)" ) )
        connect(this    , SIGNAL(iniLoad( INIFile&,int)),
                plugin  , SLOT( loadIniFile( INIFile&,int) ),Qt::DirectConnection);

      if ( checkSlot( plugin , "saveIniFile(INIFile&,int)" ) )
        connect(this    , SIGNAL(iniSave( INIFile& , int )),
                plugin  , SLOT( saveIniFile( INIFile& , int ) ),Qt::DirectConnection);

      if ( checkSlot( plugin , "saveIniFileOptions(INIFile&)" ) )
        connect(this    , SIGNAL(iniSaveOptions( INIFile& )),
                plugin  , SLOT( saveIniFileOptions( INIFile& ) ),Qt::DirectConnection);

      if ( checkSlot( plugin , "loadIniFileOptions(INIFile&)" ) )
        connect(this    , SIGNAL(iniLoadOptions( INIFile& )),
                plugin  , SLOT( loadIniFileOptions( INIFile& ) ),Qt::DirectConnection);
768 769 770 771

      if ( checkSlot( plugin , "loadIniFileOptionsLast(INIFile&)" ) )
        connect(this    , SIGNAL(iniLoadOptionsLast( INIFile& )),
                plugin  , SLOT( loadIniFileOptionsLast( INIFile& ) ),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
772 773 774 775 776 777 778
    }

    //Check if the plugin supports Texture-Interface
    TextureInterface* texturePlugin = qobject_cast< TextureInterface * >(plugin);
    if ( texturePlugin && OpenFlipper::Options::gui() ) {
      supported = supported + "Textures ";

Dirk Wilden's avatar
Dirk Wilden committed
779 780 781 782 783 784 785 786
      if ( checkSignal(plugin,"addTexture(QString,QString,uint,int)") )
        connect(plugin , SIGNAL(addTexture( QString , QString , uint , int )),
                this   , SLOT(slotAddTexture(QString, QString, uint, int)),Qt::DirectConnection);

      if ( checkSlot( plugin , "slotTextureAdded(QString,QString,uint,int)" ) )
        connect(this   , SIGNAL(addTexture(QString,QString, uint, int)),
                plugin , SLOT(slotTextureAdded(QString,QString, uint, int)),Qt::DirectConnection);

Jan Möbius's avatar
 
Jan Möbius committed
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
      if ( checkSignal(plugin,"addTexture(QString,QString,uint)") )
        connect(plugin , SIGNAL(addTexture( QString , QString , uint )),
                this   , SLOT(slotAddTexture(QString, QString, uint)),Qt::DirectConnection);

      if ( checkSlot( plugin , "slotTextureAdded(QString,QString,uint)" ) )
        connect(this   , SIGNAL(addTexture(QString,QString, uint)),
                plugin , SLOT(slotTextureAdded(QString,QString, uint)),Qt::DirectConnection);

      if ( checkSignal(plugin,"updateTexture(QString,int)") )
        connect(plugin , SIGNAL(updateTexture( QString ,int )),
                this   , SLOT(slotUpdateTexture(QString , int)));

      if ( checkSlot( plugin , "slotUpdateTexture(QString,int)" ) )
        connect(this   , SIGNAL(updateTexture(QString ,int)),
                plugin , SLOT(slotUpdateTexture(QString,int )));

      if ( checkSignal(plugin,"updateAllTextures()") )
        connect(plugin , SIGNAL(updateAllTextures()),
                this   , SLOT(slotUpdateAllTextures()));

      if ( checkSlot( plugin , "slotUpdateAllTextures()" ) )
        connect(this   , SIGNAL(updateAllTextures()),
                plugin , SLOT(slotUpdateAllTextures()));

      if ( checkSignal(plugin,"updatedTextures(QString,int)") )
        connect(plugin , SIGNAL(updatedTextures( QString , int )),
                this   , SLOT(slotTextureUpdated( QString, int ) ));

      if ( checkSlot( plugin , "slotTextureUpdated(QString,int)" ) )
        connect(this   , SIGNAL(updatedTextures( QString , int )),
                plugin , SLOT(slotTextureUpdated( QString, int ) ));

Dirk Wilden's avatar
Dirk Wilden committed
819 820 821 822 823 824 825 826
      if ( checkSignal(plugin,"setTextureMode(QString,QString,int)") )
        connect(plugin , SIGNAL(setTextureMode(QString, QString, int )),
                this   , SLOT(slotSetTextureMode(QString, QString, int )),Qt::DirectConnection );

      if ( checkSlot( plugin , "slotSetTextureMode(QString,QString,int)" ) )
        connect(this   , SIGNAL(setTextureMode(QString, QString, int )),
                plugin , SLOT(slotSetTextureMode(QString, QString, int )),Qt::DirectConnection );

Jan Möbius's avatar
 
Jan Möbius committed
827 828 829 830 831 832 833 834
      if ( checkSignal(plugin,"setTextureMode(QString,QString)") )
        connect(plugin , SIGNAL(setTextureMode(QString  ,QString )),
                this   , SLOT(slotSetTextureMode(QString  ,QString )),Qt::DirectConnection );

      if ( checkSlot( plugin , "slotSetTextureMode(QString,QString)" ) )
        connect(this   , SIGNAL(setTextureMode(QString  ,QString )),
                plugin , SLOT(slotSetTextureMode(QString  ,QString )),Qt::DirectConnection );

Dirk Wilden's avatar
Dirk Wilden committed
835 836 837 838 839 840 841 842
      if ( checkSignal(plugin,"switchTexture(QString,int)") )
        connect(plugin , SIGNAL(switchTexture(QString, int )),
                this   , SLOT(slotSwitchTexture(QString, int )),Qt::DirectConnection);

      if ( checkSlot( plugin , "slotSwitchTexture(QString,int)" ) )
        connect(this   , SIGNAL(switchTexture(QString, int )),
                plugin , SLOT(slotSwitchTexture(QString, int )),Qt::DirectConnection);

Jan Möbius's avatar
 
Jan Möbius committed
843 844 845 846 847 848 849
      if ( checkSignal(plugin,"switchTexture(QString)") )
        connect(plugin , SIGNAL(switchTexture(QString )),
                this   , SLOT(slotSwitchTexture(QString )),Qt::DirectConnection);

      if ( checkSlot( plugin , "slotSwitchTexture(QString)" ) )
        connect(this   , SIGNAL(switchTexture(QString )),
                plugin , SLOT(slotSwitchTexture(QString )),Qt::DirectConnection);
850 851 852 853 854 855 856 857 858

      if ( checkSignal( plugin , "addMultiTexture(QString,QString,QString,int,int&)" ) )
        connect(plugin   , SIGNAL(addMultiTexture(QString,QString,QString,int,int&) ),
                this , SLOT(slotMultiTextureAdded(QString,QString,QString,int,int&) ),Qt::DirectConnection);

      if ( checkSlot( plugin , "slotMultiTextureAdded( QString,QString,QString,int,int&)" ) )
        connect(this   , SIGNAL(addMultiTexture(QString,QString,QString,int,int&) ),
                plugin , SLOT(slotMultiTextureAdded( QString,QString,QString,int,int&) ),Qt::DirectConnection);

Jan Möbius's avatar
 
Jan Möbius committed
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
    }

    //Check if the plugin supports Backup-Interface
    BackupInterface* backupPlugin = qobject_cast< BackupInterface * >(plugin);
    if ( backupPlugin ) {
      supported = supported + "Backups ";

      if ( checkSignal( plugin , "createBackup(int,QString)" ) )
        connect(plugin , SIGNAL(createBackup( int , QString )) ,
                this   , SLOT(backupRequest( int , QString )),Qt::DirectConnection );

      if ( checkSlot( plugin , "slotBackupRequested(int,QString,int)" ) )
        connect(this   , SIGNAL(createBackup(int,QString,int)) ,
                plugin , SLOT( slotBackupRequested(int,QString,int) ),Qt::DirectConnection);
    }

    //Check if the plugin supports LoadSave-Interface
    LoadSaveInterface* LoadSavePlugin = qobject_cast< LoadSaveInterface * >(plugin);
    if ( LoadSavePlugin ) {
      supported = supported + "Load/Save ";
      if ( checkSignal(plugin,"load( QString,DataType,int& )" ) )
        connect(plugin , SIGNAL(load( QString,DataType,int& )) ,
                this   , SLOT(slotLoad( QString,DataType,int& )),Qt::DirectConnection );
      if ( checkSignal(plugin,"save(int,QString)" ) )
        connect(plugin , SIGNAL( save(int,QString) ) ,
884
                this   , SLOT( saveObject(int,QString) ), Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
885 886 887 888 889 890 891 892 893 894 895 896 897

      if ( checkSlot( plugin , "fileOpened(int)" ) )
        connect(this   , SIGNAL( openedFile( int) ) ,
                plugin , SLOT( fileOpened( int ) ),Qt::DirectConnection);

      if ( checkSignal(plugin,"openedFile(int)" ) )
        connect(plugin , SIGNAL( openedFile( int ) ) ,
                this   , SLOT( slotObjectOpened ( int ) ),Qt::DirectConnection);

      if ( checkSignal(plugin,"addEmptyObject(DataType,int&)" ) )
        connect(plugin , SIGNAL( addEmptyObject( DataType, int& )) ,
                this   , SLOT( slotAddEmptyObject( DataType, int&) ),Qt::DirectConnection);

898 899 900 901
      if ( checkSignal(plugin,"copyObject(int,int&)" ) )
        connect(plugin , SIGNAL( copyObject( int, int& )) ,
                this   , SLOT( slotCopyObject( int, int&) ),Qt::DirectConnection);

Jan Möbius's avatar
 
Jan Möbius committed
902 903 904 905
      if ( checkSignal(plugin,"emptyObjectAdded(int)" ) )
        connect(plugin , SIGNAL( emptyObjectAdded( int ) ) ,
                this   , SLOT( slotEmptyObjectAdded ( int ) ),Qt::DirectConnection);

Dirk Wilden's avatar
Dirk Wilden committed
906 907 908 909
      if ( checkSlot(plugin,"addedEmptyObject(int)" ) )
        connect(this ,   SIGNAL( emptyObjectAdded( int ) ) ,
                plugin   , SLOT( addedEmptyObject( int ) ),Qt::DirectConnection);

Jan Möbius's avatar
 
Jan Möbius committed
910 911 912 913
      if ( checkSignal(plugin,"getAllFilters(QStringList&)" ) )
        connect(plugin , SIGNAL( getAllFilters( QStringList& ) ) ,
                this   , SLOT( slotGetAllFilters ( QStringList& ) ),Qt::DirectConnection);

914 915 916 917
      if ( checkSignal(plugin,"deleteObject(int)" ) )
        connect(plugin , SIGNAL( deleteObject( int ) ) ,
                this   , SLOT( slotDeleteObject( int ) ),Qt::DirectConnection);

918 919 920 921
      if ( checkSignal(plugin,"deleteAllObjects()" ) )
        connect(plugin , SIGNAL( deleteAllObjects() ) ,
                this   , SLOT( slotDeleteAllObjects() ),Qt::DirectConnection);

922 923 924 925
      if ( checkSlot(plugin,"objectDeleted(int)" ) )
        connect(this ,   SIGNAL( objectDeleted( int ) ) ,
                plugin   , SLOT( objectDeleted( int ) ),Qt::DirectConnection);

Jan Möbius's avatar
 
Jan Möbius committed
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
    }

    //Check if the plugin supports View-Interface
    ViewInterface* viewPlugin = qobject_cast< ViewInterface * >(plugin);
    if ( viewPlugin  && OpenFlipper::Options::gui() ) {
      supported = supported + "View ";

      if ( checkSignal(plugin,"getStackWidget(QString,QWidget*&)" ) )
        connect(plugin      , SIGNAL(getStackWidget( QString , QWidget*&)),
                coreWidget_ , SLOT( slotGetStackWidget( QString , QWidget*& ) ) ,Qt::DirectConnection );
      if ( checkSignal(plugin,"addStackWidget(QString,QWidget*)" ) )
        connect(plugin      , SIGNAL(addStackWidget( QString , QWidget*)),
                coreWidget_ , SLOT( slotAddStackWidget( QString , QWidget* ) ) ,Qt::DirectConnection );
      if ( checkSignal(plugin,"updateStackWidget(QString,QWidget*)" ) )
        connect(plugin      , SIGNAL(updateStackWidget( QString , QWidget*)),
                coreWidget_ , SLOT( slotUpdateStackWidget( QString , QWidget* ) ) ,Qt::DirectConnection );
    }

    //Check if the plugin supports RPC-Interface
    RPCInterface* rpcPlugin = qobject_cast< RPCInterface * >(plugin);
    if ( rpcPlugin ) {
      supported = supported + "RPC ";

      if ( checkSignal(plugin,"pluginExists(QString,bool&)" ) )
        connect(plugin  , SIGNAL( pluginExists(QString,bool&) ),
                this    , SLOT( slotPluginExists(QString,bool&) ) ,Qt::DirectConnection );
      if ( checkSignal(plugin,"functionExists(QString,QString,bool&)" ) )
        connect(plugin  , SIGNAL(functionExists(QString,QString,bool&)),
                this    , SLOT( slotFunctionExists(QString,QString,bool&) ) ,Qt::DirectConnection );
      if ( checkSignal(plugin,"call(QString,QString,bool&)" ) )
        connect(plugin  , SIGNAL(call(QString,QString,bool&)),
                this    , SLOT(slotCall(QString,QString,bool&)) ,Qt::DirectConnection );
      if ( checkSignal(plugin,"call(QString,bool&)" ) )
        connect(plugin  , SIGNAL(call(QString,bool&)),
                this    , SLOT(slotCall(QString,bool&)) ,Qt::DirectConnection );
      if ( checkSignal(plugin,"getValue(QString,QVariant&)" ) )
        connect(plugin  , SIGNAL(getValue(QString,QVariant&)),
                this    , SLOT(slotGetValue(QString,QVariant&)) ,Qt::DirectConnection );
    }

    //========================================================================================
    // ===          Collect Scripting Information for Plugin      ============================

    QScriptValue scriptInstance = scriptEngine_.newQObject(plugin,
                                                           QScriptEngine::QtOwnership,
                                                           QScriptEngine::ExcludeChildObjects |
                                                           QScriptEngine::ExcludeSuperClassMethods |
                                                           QScriptEngine::ExcludeSuperClassProperties
                                                           );

    // Make plugin available for scripting
    QString scriptingName = info.name.remove(" ").toLower();

    scriptEngine_.globalObject().setProperty(scriptingName, scriptInstance);
    emit log(LOGOUT,"Registered scriping with name :\t " + scriptingName);

    info.rpcName = scriptingName;

    emit log(LOGOUT,"Available scripting functions :");

    QScriptValueIterator it(scriptInstance);
    while (it.hasNext()) {
      it.next();

      /// Skip all signals for function calls
      if ( checkSignal( plugin, it.name().toAscii() ) )
        continue;

      info.rpcFunctions.push_back( it.name() );

      scriptingFunctions_.push_back( scriptingName + "." + it.name() );

//       QScriptValue function = it.value();
//       scriptEngine_.globalObject().setProperty(it.name(), function );

      emit log(LOGOUT,"\t" + it.name());
    }

        //Check if the plugin supports RPC-Interface
    ScriptInterface* scriptPlugin = qobject_cast< ScriptInterface * >(plugin);
    if ( scriptPlugin ) {
      supported = supported + "Scripting ";

      // Create intermediate wrapper class which will mangle the call information
      ScriptingWrapper* newScript = new ScriptingWrapper(info.rpcName);
      scriptingWrappers_.push_back(newScript);

      //========= Part one, Scriptinfos via wrapper to core and than to scipting Plugin ==========

      if ( checkSignal(plugin,"scriptInfo(QString)" ) ) {

        // Plugin to wrapper
        connect(plugin    , SIGNAL( scriptInfo(QString) ),
                newScript , SLOT( slotScriptInfo(QString) ) ,Qt::DirectConnection );

        // wrapper to core
        connect(newScript , SIGNAL( scriptInfo(QString,QString) ),
                this      , SLOT( slotScriptInfo(QString,QString) ));
      }

      // Core to plugins ( normally only one scripting plugin)
      if ( checkSlot(plugin,"slotScriptInfo(QString,QString)") ) {
        connect(this      , SIGNAL(scriptInfo(QString,QString)),
                plugin    , SLOT(slotScriptInfo(QString,QString)));
      }

1032 1033 1034 1035 1036
      // Function descriptions
      if ( checkSignal(plugin,"getDescription(QString,QString&,QStringList&,QStringList&)") )
        connect(plugin    , SIGNAL( getDescription(QString,QString&,QStringList&,QStringList&) ),
                this      , SLOT( slotGetDescription(QString,QString&,QStringList&,QStringList&) ));

Jan Möbius's avatar
 
Jan Möbius committed
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
      //========= Script Execution ==========

      // Plugins to Core
      if ( checkSignal(plugin,"executeScript(QString)") )
        connect(plugin      , SIGNAL(executeScript(QString)),
                this       , SLOT(slotExecuteScript(QString)));

      // Core to plugins ( normally only one scripting plugin)
      if ( checkSlot(plugin,"slotExecuteScript(QString)") )
        connect(this      , SIGNAL(executeScript(QString)),
                plugin       , SLOT(slotExecuteScript(QString)));

      // Core to plugins ( normally only one scripting plugin)
      if ( checkSlot(plugin,"slotExecuteFileScript(QString)") )
        connect(this      , SIGNAL(executeFileScript(QString)),
                plugin       , SLOT(slotExecuteFileScript(QString)));

      //========= Engine  ==========

      // Plugins to Core
      if ( checkSignal(plugin,"getScriptingEngine(QScriptEngine*&)") )
        connect(plugin      , SIGNAL(getScriptingEngine(QScriptEngine*&)),
                this       , SLOT(slotGetScriptingEngine(QScriptEngine*&)));

      // Plugins to Core
      if ( checkSignal(plugin,"getAvailableFunctions(QStringList&)") )
        connect(plugin      , SIGNAL(getAvailableFunctions(QStringList&)),
                this       , SLOT(slotGetAllAvailableFunctions(QStringList&)));

    }

    emit log(LOGOUT,"Supported Interfaces :\t " + supported);


    //========================================================================================
    //========================================================================================

    plugins.push_back(info);

    // Initialize Plugin
    if ( basePlugin ) {
      if ( checkSlot(plugin,"initializePlugin()") )
         QMetaObject::invokeMethod(plugin, "initializePlugin",  Qt::DirectConnection);
    }

    emit log(LOGOUT,"=============================================================================================");
  } else {
    emit log(LOGERR,"Unable to load Plugin :\t " + filename );
    emit log(LOGERR,"Error was : " + loader.errorString() );
    emit log(LOGOUT,"=============================================================================================");
  }



}