PluginLoader.cc 114 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41
\*===========================================================================*/

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56


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


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

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


Jan Möbius's avatar
Jan Möbius committed
57
#include "OpenFlipper/BasePlugin/AboutInfoInterface.hh"
58 59 60 61 62
#include "OpenFlipper/BasePlugin/KeyInterface.hh"
#include "OpenFlipper/BasePlugin/BackupInterface.hh"
#include "OpenFlipper/BasePlugin/MouseInterface.hh"
#include "OpenFlipper/BasePlugin/PickingInterface.hh"
#include "OpenFlipper/BasePlugin/ToolboxInterface.hh"
Dirk Wilden's avatar
Dirk Wilden committed
63
#include "OpenFlipper/BasePlugin/OptionsInterface.hh"
64 65
#include "OpenFlipper/BasePlugin/ToolbarInterface.hh"
#include "OpenFlipper/BasePlugin/TextureInterface.hh"
66
#include "OpenFlipper/BasePlugin/ProcessInterface.hh"
67
#include "OpenFlipper/BasePlugin/ViewModeInterface.hh"
68 69 70 71
#include "OpenFlipper/BasePlugin/LoadSaveInterface.hh"
#include "OpenFlipper/BasePlugin/INIInterface.hh"
#include "OpenFlipper/BasePlugin/RPCInterface.hh"
#include "OpenFlipper/BasePlugin/ScriptInterface.hh"
72
#include "OpenFlipper/BasePlugin/SecurityInterface.hh"
73
#include "OpenFlipper/BasePlugin/PluginConnectionInterface.hh"
74
#include "OpenFlipper/BasePlugin/MetadataInterface.hh"
75
#include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
76 77 78


#include <ACG/QtWidgets/QtFileDialog.hh>
Dirk Wilden's avatar
Dirk Wilden committed
79
#include "OpenFlipper/widgets/PluginDialog/PluginDialog.hh"
80

81
#include <OpenFlipper/common/FileTypes.hh>
82
#include <OpenFlipper/common/PluginStorage.hh>
83 84


85 86
/**
 * The number of plugins to load simultaneously.
87

88
 */
89
static const int PRELOAD_THREADS_COUNT = (QThread::idealThreadCount() != -1) ? QThread::idealThreadCount() : 8;
90

91 92
namespace cmake { extern const char *static_plugins; };

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 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 161
class PreloadAggregator {
    public:
        PreloadAggregator() : expectedLoaders_(0) {}

        /**
         * Intended to be called by a PreloadThread
         * before count subsequent calls to loaderReady().
         * May be called multiple times in which case
         * the counts accumulate.
         *
         * @param count The number of times the calling
         * PreloadThread intents to call loaderReady().
         */
        void expectLoaders(int count) {
            QMutexLocker loadersLock(&loadersMutex_);
            expectedLoaders_ += count;
        }

        /**
         * Intended to be called by a PreloadThread.
         *
         * Transfers ownership of the supplied loader
         * to the PreloadAggregator.
         */
        void loaderReady(QPluginLoader *loader) {
            QMutexLocker loadersLock(&loadersMutex_);
            loaders_.push_back(loader);
            --expectedLoaders_;
            pluginAvailable_.wakeOne();
        }

        /**
         * If there are still loaders expected, block
         * until the next loader becomes available and return
         * it.
         *
         * Ownership of the returned object is transferred
         * to the caller. (I.e. the caller has to delete it.)
         *
         * @return Null if there are no more loaders expected.
         * The next loader, otherwise.
         */
        QPluginLoader *waitForNextLoader() {
            QMutexLocker loadersLock(&loadersMutex_);
            if (loaders_.empty()) {
                if (expectedLoaders_ > 0) {
                    pluginAvailable_.wait(&loadersMutex_);
                } else {
                    return 0;
                }
            }

            /*
             * At this point, it is guaranteed that
             * loaders_.size() > 0.
             */
            QPluginLoader *result = loaders_.front();
            loaders_.pop_front();
            return result;
        }

    protected:
        std::deque<QPluginLoader *> loaders_;
        QWaitCondition pluginAvailable_;
        QMutex loadersMutex_;

        int expectedLoaders_;
};

Jan Möbius's avatar
Jan Möbius committed
162 163 164 165 166 167 168
class PreloadThread : public QThread
{
  public: 
    
    /** \brief Preload thread constructor
    *
    * This constructor initializes the preloading thread.
169 170
    *
    * @param aggregator aggregator managing the different threads
Jan Möbius's avatar
Jan Möbius committed
171
    */
172
    explicit PreloadThread(PreloadAggregator *aggregator) : aggregator_(aggregator) {
Jan Möbius's avatar
Jan Möbius committed
173 174 175 176
    }
  
  public:
    
177 178 179 180 181 182
    void addFilename(const QString &filename) {
        QMutexLocker filenamesLock(&filenamesMutex_);
        filenames_.push_back(filename);
        aggregator_->expectLoaders(1);
    }

Jan Möbius's avatar
Jan Möbius committed
183 184 185 186 187
    /** \brief preload function
    *
    * This function is used in the thread to preload a plugin. The name is given in the constructor.
    */
    void run() {
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
      for (;;) {
          QString fileName;
          {
              /*
               * Just to be on the safe side, we protect
               * filenames_. (addFilename() could be called from
               * a different thread.)
               */
              QMutexLocker filenamesLock(&filenamesMutex_);
              if (filenames_.empty()) break;
              fileName = filenames_.front();
              filenames_.pop_front();
          }

          QPluginLoader *loader = new QPluginLoader;
          loader->setFileName(fileName);
          loader->load();
          aggregator_->loaderReady(loader);
      }
Jan Möbius's avatar
Jan Möbius committed
207 208 209
    }
    
  private:
210 211 212
    std::deque<QString> filenames_;
    QMutex filenamesMutex_;
    PreloadAggregator *aggregator_;
Jan Möbius's avatar
Jan Möbius committed
213 214
};

215 216 217 218 219 220 221 222 223 224
/**
 * @brief Defines the order in which plugins have to be loaded.
 *
 * First load all type Plugins to register the dataTypes to the core
 * Than load the file plugins to load objects
 * Next is textureControl to control texture based properties
 * Then load everything else.
 */
class PluginInitializationOrder {
    public:
225
        size_t getTypeOrdinal(const QString &name) const {
226 227 228 229 230 231 232 233 234 235 236 237
            const QString basename = QFileInfo(name).baseName();
            if (basename.contains("Plugin-Type"))
                return 0;
            else if (basename.contains("Plugin-File"))
                return 1;
            else if (basename.contains("TextureControl"))
                return 2;
            else
                return 3;

        }
        bool operator() (const QString &a, const QString &b) const {
238 239
            const size_t typeA = getTypeOrdinal(a);
            const size_t typeB = getTypeOrdinal(b);
240 241 242 243 244 245 246 247
            if (typeA != typeB) { return typeA < typeB; }
            return a < b;
        }

        bool operator() (const QPluginLoader *a, const QPluginLoader *b) const {
            return operator() (a->fileName(), b->fileName());
        }
};
Jan Möbius's avatar
Jan Möbius committed
248

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
//== 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()
{
Jan Möbius's avatar
Jan Möbius committed
268
  
269 270 271
  //regsiter custom datatypes for signal/slots
  registerTypes();

Jan Möbius's avatar
Jan Möbius committed
272 273
  QString licenseTexts = "";
  
274
  //try to load plugins from new location
275
  QDir tempDir = QDir(OpenFlipper::Options::pluginDir());
276

277
  // Possible Plugin extensions
Jan Möbius's avatar
Jan Möbius committed
278 279 280
  // Windows gets DLLs
  // Mac and Linux use so
  // We don't use the dylib extension on Mac at the moment.
281 282 283
  QStringList filter;
  if ( OpenFlipper::Options::isWindows() )
    filter << "*.dll";
Jan Möbius's avatar
Jan Möbius committed
284
  else 
285 286
    filter << "*.so";
  
287
  // Get all files in the Plugin dir
288
  QStringList pluginlist = tempDir.entryList(filter,QDir::Files);
289

290 291
  // Convert local file path to absolute path
  for (int i=0; i < pluginlist.size(); i++) {
292
     pluginlist[i] = tempDir.absoluteFilePath(pluginlist[i]);
293 294
  }

295
  // get all Plugin Names which will not be loaded
296
  QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames", QStringList()).toStringList();
297 298 299 300 301 302
  
  // Output info about additional plugins
  for ( int i = 0 ; i < dontLoadPlugins.size(); ++i) 
    emit log(LOGOUT,tr("dontLoadPlugins Plugin from ini file: %1").arg( dontLoadPlugins[i] ) );
  
  // get all Plugins which should be loaded in addition to the standard plugins 
303
  QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins", QStringList()).toStringList();
304 305
  
  // Output info about additional plugins
306
  for ( int i = 0 ; i < additionalPlugins.size(); ++i) {
307
    emit log(LOGOUT,tr("Additional Plugin from file: %1").arg( additionalPlugins[i] ) );
308
  }
309 310 311
  
  // Prepend the additional Plugins to the plugin list
  pluginlist = additionalPlugins << pluginlist;
312

313
  /*
314
   * Remove static plugins from dynamically loaded list.
315
   */
316 317 318 319 320 321 322 323 324 325 326 327
  {
      QSet<QString> staticPlugins = QSet<QString>::fromList(
          QString::fromUtf8(cmake::static_plugins).split("\n"));
      for (int i = 0; i < pluginlist.size(); ) {
          const QString bn = QFileInfo(pluginlist[i]).fileName();
          if (staticPlugins.contains(bn)) {
              emit log(LOGOUT, trUtf8("Not loading dynamic %1 as it is statically "
                      "linked against OpenFlipper.").arg(bn));
              pluginlist.removeAt(i);
          } else {
              ++i;
          }
328 329 330
      }
  }

331 332 333 334
  /*
   * Note: This call is not necessary, anymore. Initialization order
   * is determined later.
   */
335
  //std::sort(pluginlist.begin(), pluginlist.end(), PluginInitializationOrder());
336

337 338
  for ( int i = 0 ; i < dontLoadPlugins.size(); ++i )
    emit log(LOGWARN,tr("Skipping Plugins :\t %1").arg( dontLoadPlugins[i] ) );
339

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

Jan Möbius's avatar
Jan Möbius committed
342 343 344 345
  QTime time;
  
  time.start();
  
346 347 348 349 350 351 352 353 354 355
  PreloadAggregator preloadAggregator;
  std::vector< PreloadThread* > loaderThreads(PRELOAD_THREADS_COUNT);

  /*
   * Initialize loaderThreads.
   */
  for (std::vector< PreloadThread* >::iterator it = loaderThreads.begin();
          it != loaderThreads.end(); ++it) {
      *it = new PreloadThread(&preloadAggregator);
  }
Jan Möbius's avatar
Jan Möbius committed
356
  
357 358 359 360
  /*
   * Distribute plugins onto loader threads in a round robin fashion.
   * (only load them in seperate thread. Instance will be created in main thread)
   */
361
  for ( int i = 0 ; i < pluginlist.size() ; ++i) {
362 363 364 365 366 367 368 369 370
    loaderThreads[i % loaderThreads.size()]->addFilename(pluginlist[i]);
  }

  /*
   * Start plugin preloading.
   */
  for (std::vector< PreloadThread* >::iterator it = loaderThreads.begin();
          it != loaderThreads.end(); ++it) {
      (*it)->start();
Jan Möbius's avatar
Jan Möbius committed
371 372
  }
  
373 374 375 376 377 378 379 380 381 382 383
  /*
   * Wait for the plugins to get preloaded
   */
  std::vector<QPluginLoader*> loadedPlugins;
  loadedPlugins.reserve(pluginlist.size());

  for (QPluginLoader *loader = preloadAggregator.waitForNextLoader(); loader != 0;
          loader = preloadAggregator.waitForNextLoader()) {

      loadedPlugins.push_back(loader);

384
      if (splash_) {
385 386 387
        splashMessage_ = tr("Loading Plugin %1/%2").arg(loadedPlugins.size()).arg(pluginlist.size()) ;
        splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
      }
388 389
  }

390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
  /*
   * Finalize PreloadThreads.
   */
  for (std::vector< PreloadThread* >::iterator it = loaderThreads.begin();
          it != loaderThreads.end(); ++it) {
      (*it)->wait();
      delete *it;
  }

  /*
   * Initialize preloaded plugins in the correct order.
   */
  std::sort(loadedPlugins.begin(), loadedPlugins.end(), PluginInitializationOrder());
  for (std::vector<QPluginLoader*>::iterator it = loadedPlugins.begin();
          it != loadedPlugins.end(); ++it) {

406
      if (splash_) {
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
        splashMessage_ = tr("Initializing Plugin %1/%2")
                .arg(std::distance(loadedPlugins.begin(), it) + 1)
                .arg(loadedPlugins.size());
        splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
      }

      if ((*it)->instance() != 0 ) {
        QString pluginLicenseText  = "";
        loadPlugin((*it)->fileName(),true,pluginLicenseText, (*it)->instance());
        licenseTexts += pluginLicenseText;
      } else {
        emit log(LOGERR,tr("Unable to load Plugin :\t %1").arg( (*it)->fileName() ) );
        emit log(LOGERR,tr("Error was : ") + (*it)->errorString() );
        emit log(LOGOUT,"================================================================================");
      }
      delete *it;
  }

425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
  /*
   * Initialize static plugins.
   */
  QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins();
  for (QVector<QStaticPlugin>::iterator it = staticPlugins.begin();
          it != staticPlugins.end(); ++it) {
      QObject *instance = it->instance();
      BaseInterface* basePlugin = qobject_cast< BaseInterface * >(instance);
      if (basePlugin) {
          QString fakeName = QString::fromUtf8("<Statically Linked>::/%1.%2")
              .arg(basePlugin->name())
              .arg(OpenFlipper::Options::isWindows() ? "dll" : "so");
          QString pluginLicenseText  = "";
          loadPlugin(fakeName, true, pluginLicenseText, instance);
          licenseTexts += pluginLicenseText;
      }
  }

443 444
  emit log(LOGINFO, tr("Total time needed to load plugins was %1 ms.").arg(time.elapsed()));

445
  splashMessage_ = "";
Jan Möbius's avatar
Jan Möbius committed
446 447
  
  if ( licenseTexts != "" ) {
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
    if ( OpenFlipper::Options::gui() ) {
      
      // split for each license block
      QStringList licenseBlocks = licenseTexts.split("==");

      // Cleanup lists to get only the ones containing valid plugins.
      for ( QStringList::iterator it = licenseBlocks.begin(); it != licenseBlocks.end() ; ++it )
        if ( ! it->contains("PluginName") ) {
          licenseBlocks.erase(it);
          it = licenseBlocks.begin();
        }
      
      // sort by the contact mails
      QMap< QString , QString > contacts;
      
      for ( QStringList::iterator it = licenseBlocks.begin(); it != licenseBlocks.end() ; ++it ) {
        QStringList lines = it->split("\n");
        
        lines = lines.filter ( "Contact mail", Qt::CaseInsensitive );
        
        // Corect one found:
        if (lines.size() == 1)  {
          QString mail = lines[0].section(":",-1).simplified();
          QString list = contacts.take(mail);
          list.append(*it);
          contacts.insert(mail,list);
        } else {
          emit log(LOGWARN,tr("Can't extract mail contact from license request"));
        }
          
      }
      
      for ( QMap<QString , QString>::iterator it = contacts.begin() ; it != contacts.end() ; ++it ) {
        
        QStringList request = it.value().split("\n");
        
        // Cleanup lists to get only the relevant part
        for ( QStringList::iterator lit = request.begin(); lit != request.end() ; ++lit ) {
          
          if ( lit->contains("Message:")  ) {
            *lit = lit->section(":",-1).simplified();
          }
          
          if ( lit->contains("Contact mail:")  ) {
            *lit = lit->section(":",-1).simplified();
          }
494
           
495
        }
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512

        QDialog licenseBox;
          
        QTextEdit *edit = new QTextEdit(&licenseBox);
        edit->setText(request.join("\n"));

        QLabel* mailLabel = new QLabel(&licenseBox);
        mailLabel->setText(tr("The text has been copied to your clipboard. Open in Mail program?"));

        QPushButton* noButton = new QPushButton(&licenseBox);
        noButton->setText(tr("No"));
        connect( noButton, SIGNAL(clicked ()), &licenseBox, SLOT(reject()) );

        QPushButton* yesButton = new QPushButton(&licenseBox);
        yesButton->setText(tr("Yes"));
        connect( yesButton, SIGNAL(clicked ()), &licenseBox, SLOT(accept()) );

Jan Möbius's avatar
Jan Möbius committed
513 514 515 516 517 518
        QGridLayout *layout = new QGridLayout;
        layout->addWidget(edit,0,0,1,2);
        layout->addWidget(mailLabel,1,0,1,2);
        layout->addWidget(noButton,2,0);
        layout->addWidget(yesButton,2,1);
        licenseBox.setLayout(layout);
519 520 521 522 523 524

        licenseBox.resize(500,500);
        licenseBox.setModal(true);
        licenseBox.setWindowTitle(tr("Plugin License check failed, issuer is: %1").arg( it.key() ));  
        int userAnswer =licenseBox.exec();

Jan Möbius's avatar
Jan Möbius committed
525
        // set a text to the Clipboard
526
        QClipboard *cb = QApplication::clipboard();
Jan Möbius's avatar
Jan Möbius committed
527
        cb->setText(request.join("\n"));
528

529
        if ( userAnswer == 1 ) {
530 531 532 533 534 535 536
           QString url = "mailto:" + it.key();
           url += "?subject=License Request&body=";
#ifdef WIN32
           url += request.join(";;");
#else
           url += request.join("\n");
#endif
537

538 539 540
           QUrl encodedURL(url, QUrl::TolerantMode);
           QDesktopServices::openUrl(encodedURL);
        }
541 542 543 544 545
        
      }

      
    } else {
546

547
      emit log(LOGWARN,tr("Plugin License check failed: "));
Jan Möbius's avatar
Jan Möbius committed
548 549 550
      std::cerr << licenseTexts.toStdString() << std::endl;
    }
  } 
551 552 553

  emit pluginsInitialized();

554 555
  emit pluginsInitialized(PluginFunctions::pluginCommandLineOptions());

556
  emit log(LOGOUT,tr("Loaded %n Plugin(s)","",int(plugins().size())) );
557 558 559 560 561 562 563 564 565
}

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

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

566
  // Setup filters for possible plugin extensions
Jan Möbius's avatar
Jan Möbius committed
567 568 569
  // Windows gets DLLs
  // Mac and Linux use so
  // We don't use the dylib extension on Mac at the moment.
Jan Möbius's avatar
Jan Möbius committed
570
  QString filter;
571 572
  if ( OpenFlipper::Options::isWindows() )
    filter = "Plugins (*.dll)";
Jan Möbius's avatar
Jan Möbius committed
573
  else 
574 575
    filter = "Plugins (*.so)";

576
  // Ask the user to select the file to load
577
  QString filename = ACG::getOpenFileName(coreWidget_,tr("Load Plugin"),filter, OpenFlipperSettings().value("Core/CurrentDir").toString() );
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598

  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;

599
  // Ask if the plugin is on the block list
600
  QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames", QStringList()).toStringList();
601
  if (dontLoadPlugins.contains(name)){
602 603
      int ret = QMessageBox::question(0, tr("Plugin Loading Prevention"),
                   tr("OpenFlipper is currently configured to prevent loading this plugin.\n"
604
                      "Do you want to enable this plugin permanently?"),
605 606
                   QMessageBox::Yes | QMessageBox::No,
                   QMessageBox::Yes);
607 608 609 610 611
      if (ret == QMessageBox::Yes) {
        dontLoadPlugins.removeAll(name);
        OpenFlipperSettings().setValue("PluginControl/DontLoadNames",dontLoadPlugins);
      } else
         return;
612
  }
613 614
  
  // check if the plugin is not on the additional plugin list
615
  QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins", QStringList()).toStringList();
616 617 618 619 620 621 622 623 624 625 626 627
  if (!additionalPlugins.contains(name)){
    int ret = QMessageBox::question(0, tr("Plugin Loading ..."),
                                       tr("Should OpenFlipper load this plugin on next startup?"),
                                    QMessageBox::Yes | QMessageBox::No,
                                    QMessageBox::Yes);
    if (ret == QMessageBox::Yes) {
      additionalPlugins << filename;
      std::cerr << "Added: " << filename.toStdString() << std::endl;
      OpenFlipperSettings().setValue("PluginControl/AdditionalPlugins",additionalPlugins);
    }
  }
  
Jan Möbius's avatar
Jan Möbius committed
628 629 630 631
  QString licenseText = "";
  loadPlugin(filename,false,licenseText);
  
  if ( licenseText != "" ) {
632
    if ( OpenFlipper::Options::gui() ) {
Jan Möbius's avatar
Jan Möbius committed
633
      QMessageBox::warning ( 0, tr("Plugin License check failed"),  licenseText );
634 635 636 637
      
      std::cerr << "OpenURL: " << std::endl;
      QDesktopServices::openUrl(QUrl(tr("mailto:contact@openflipper.com?subject=License Request&body=%1").arg(licenseText), QUrl::TolerantMode));
    } else {
Jan Möbius's avatar
Jan Möbius committed
638 639 640
      std::cerr << "Plugin License check failed" << std::endl;
      std::cerr << licenseText.toStdString() << std::endl;
    }
641
  }
642 643
}

Dirk Wilden's avatar
Dirk Wilden committed
644
/** @brief slot for showing loaded Plugins
645
 */
Dirk Wilden's avatar
Dirk Wilden committed
646
void Core::slotShowPlugins(){
647

Dirk Wilden's avatar
Dirk Wilden committed
648 649 650 651 652 653
  if ( OpenFlipper::Options::gui() ){

    int ret = 0;

    while (ret == 0){

654
      PluginDialog* dialog = new PluginDialog(plugins(), coreWidget_);
655

Dirk Wilden's avatar
Dirk Wilden committed
656 657
      //connect signals
      connect(dialog, SIGNAL( loadPlugin() ), this, SLOT( slotLoadPlugin() ));
658 659 660 661
      connect(dialog, SIGNAL(blockPlugin(const QString&)), this, SLOT(slotBlockPlugin(const QString&)));
      connect(dialog, SIGNAL(unBlockPlugin(const QString&)), this, SLOT(slotUnBlockPlugin(const QString&)));
      connect(dialog, SIGNAL(loadPlugin(const QString& ,const bool , QString& , QObject* )),
          this,SLOT(loadPlugin(const QString& ,const bool , QString& , QObject* )));
Dirk Wilden's avatar
Dirk Wilden committed
662 663 664 665 666 667 668

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

      delete dialog;
    }
  }
669 670
}

671 672 673 674 675 676 677
void Core::slotBlockPlugin(const QString &_name)
{
  QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames",QStringList()).toStringList();
  if ( !dontLoadPlugins.contains(_name) ){
    dontLoadPlugins << _name;
    OpenFlipperSettings().setValue("PluginControl/DontLoadNames",dontLoadPlugins);
  }
678

679 680 681
  for (size_t i = 0; i < plugins().size();++i)
    if (plugins()[i].name == _name)
      plugins()[i].status = PluginInfo::BLOCKED;
682
}
683

684 685 686 687 688
void Core::slotUnBlockPlugin(const QString &_name)
{
  QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames",QStringList()).toStringList();
  dontLoadPlugins.removeAll(_name);
  OpenFlipperSettings().setValue("PluginControl/DontLoadNames",dontLoadPlugins);
689

690 691 692
  for (size_t i = 0; i < plugins().size();++i)
      if (plugins()[i].name == _name)
        plugins()[i].status = PluginInfo::UNLOADED;
693 694
}

695 696 697 698 699 700 701

void Core::printPluginLoadLog(const QString& errors,const QString& warnings ) {
  emit log(LOGERR ,errors );
  emit log(LOGWARN,warnings );
  emit log(LOGOUT,"================================================================================");
}

702
/** @brief Load a Plugin with given filename
Matthias Möller's avatar
Matthias Möller committed
703 704
 *  @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
Jan Möbius's avatar
Jan Möbius committed
705
 *  @param _licenseErrors String will be epty when no license issues occured, otherwise it contains the required information for obtaining a license
Jan Möbius's avatar
Jan Möbius committed
706
 *  @param _plugin You can provide a preloaded plugin here. If this is 0 the filename will be used to load the plugin.
707
 */
708
void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _licenseErrors, QObject* _plugin){
709

Jan Möbius's avatar
Jan Möbius committed
710 711
  _licenseErrors = "";
  
712 713
  // Only load .dll under windows
  if ( OpenFlipper::Options::isWindows() ) {
714
    QString dllname = _filename;
715
    if ( ! dllname.endsWith( ".dll" ) )
716 717 718 719
      return;
  }
  // Only load .so under linux
  if ( OpenFlipper::Options::isLinux() ) {
720
    QString soname = _filename;
721
    if ( ! soname.endsWith( ".so" ) )
722 723 724
      return;
  }

Jan Möbius's avatar
Jan Möbius committed
725 726
  // This will be the reference to our plugin
  QObject *plugin = 0;
727

728 729 730 731
  // Collect error and warning info
  QString errors, warnings;


Jan Möbius's avatar
Jan Möbius committed
732 733 734
  // Try to open the file if we did not get a plugin,
  // Otherwise use the supplied plugin pointer
  if ( _plugin == 0 ) {
735
    QPluginLoader loader( _filename );
Jan Möbius's avatar
Jan Möbius committed
736 737 738
    plugin = loader.instance();  
    
    if ( !plugin) {
739 740 741 742 743 744

      errors += tr("Error: Unable to load Plugin :\t %1").arg( _filename ) + "\n";
      errors += tr("Error: Error was : ") + loader.errorString() + "\n";

      emit log(LOGERR,errors );

Jan Möbius's avatar
Jan Möbius committed
745
      emit log(LOGOUT,"================================================================================");       
746 747
    } else {
      emit log (LOGOUT,tr("Plugin loaded: \t %1").arg(_filename));
Jan Möbius's avatar
Jan Möbius committed
748 749 750 751 752 753
    }
    
  } else {
      plugin = _plugin;
  }
  
754
  // Check if a plugin has been loaded
Matthias Möller's avatar
Matthias Möller committed
755 756
  PluginInfo info;
  int alreadyLoadedAt = -1;
757
  for (unsigned int k=0; k < plugins().size(); k++)
758
  {
759
    if (plugins()[k].path == _filename)
Matthias Möller's avatar
Matthias Möller committed
760
      alreadyLoadedAt = static_cast<int>(k);
761
  }
Matthias Möller's avatar
Matthias Möller committed
762 763
  info.status = PluginInfo::FAILED;
  info.path = _filename;
Jan Möbius's avatar
Jan Möbius committed
764
  QString supported;
765

766
  emit log(LOGOUT,tr("Location : \t %1").arg( _filename) );
Jan Möbius's avatar
Jan Möbius committed
767 768 769 770
  
  // Check if it is a BasePlugin
  BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugin);
  if ( basePlugin ) {
771 772

    //set basic information about plugin
Matthias Möller's avatar
Matthias Möller committed
773 774 775
    info.name = basePlugin->name();
    info.rpcName = info.name.remove(" ").toLower();
    info.description = basePlugin->description();
776
    info.warnings = "BLA";
777 778

    QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins", QStringList()).toStringList();
Matthias Möller's avatar
Matthias Möller committed
779
    info.buildIn = !additionalPlugins.contains(info.path);
780

Jan Möbius's avatar
Jan Möbius committed
781
    emit log(LOGOUT,tr("Found Plugin : \t %1").arg(basePlugin->name()) );
782

783
    if (splash_) {
Jan Möbius's avatar
Jan Möbius committed
784 785 786
      splashMessage_ = splashMessage_ + " " + basePlugin->name() ;
      splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
    }
787

Jan Möbius's avatar
Jan Möbius committed
788
    //Check if plugin is already loaded
789
    for (unsigned int k=0; k < plugins().size(); k++){
Jan Möbius's avatar
Jan Möbius committed
790 791 792 793

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

794
        if (plugins()[k].name == name_nospace && plugins()[k].path != _filename && plugins()[k].status == PluginInfo::LOADED){
795
          if (_silent || OpenFlipper::Options::nogui() ){ //dont load the plugin
796

797
            warnings += tr("Warning: Already loaded from %1").arg( plugins()[k].path) + "\n";
798 799 800

            printPluginLoadLog(errors, warnings);

Matthias Möller's avatar
Matthias Möller committed
801
            info.description = basePlugin->description() + tr(" *Already loaded.*");
802 803 804 805 806 807

            info.errors   = errors;
            info.warnings = warnings;

            PluginStorage::pluginsFailed().push_back(info);

Jan Möbius's avatar
Jan Möbius committed
808 809 810 811 812 813
            return;
        }else{ //ask the user
          int ret = QMessageBox::question(coreWidget_,
                                          tr("Plugin already loaded"),
                                          tr("A Plugin with the same name was already loaded from %1.\n" 
                                              "You can only load the new plugin if you unload the existing one first.\n\n"
814
                                              "Do you want to unload the existing plugin first?").arg( plugins()[k].path),
Jan Möbius's avatar
Jan Möbius committed
815
                                          QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
816 817
          if (ret == QMessageBox::No)
          {
818
            warnings += tr("Warning: Already loaded from %1.").arg( plugins()[k].path) + "\n";
819 820 821

            printPluginLoadLog(errors, warnings);

Matthias Möller's avatar
Matthias Möller committed
822
            info.description = basePlugin->description() + tr(" *Already loaded.*");
823 824 825 826 827

            info.errors   = errors;
            info.warnings = warnings;

            PluginStorage::pluginsFailed().push_back(info);
Jan Möbius's avatar
Jan Möbius committed
828
            return;
829 830
          }
        }
Dirk Wilden's avatar
Dirk Wilden committed
831
      }
Jan Möbius's avatar
Jan Möbius committed
832
    }
833

834
    QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames",QStringList()).toStringList();
835

Jan Möbius's avatar
Jan Möbius committed
836
    if ( dontLoadPlugins.contains(basePlugin->name(), Qt::CaseInsensitive) ) {
837 838 839 840 841

      warnings += tr("Warning: OpenFlipper.ini prevented Plugin %1 from being loaded! ").arg( basePlugin->name() ) + "\n";

      printPluginLoadLog(errors, warnings);

Matthias Möller's avatar
Matthias Möller committed
842
      info.status = PluginInfo::BLOCKED;
843 844 845 846 847 848

      info.errors   = errors;
      info.warnings = warnings;

      PluginStorage::pluginsFailed().push_back(info);

Jan Möbius's avatar
Jan Möbius committed
849 850
      return;
    }
851

Jan Möbius's avatar
Jan Möbius committed
852 853 854 855
    //Check if it is a BasePlugin
    SecurityInterface * securePlugin = qobject_cast< SecurityInterface * >(plugin);
    if ( securePlugin ) {
      emit log(LOGINFO,tr("Plugin uses security interface. Trying to authenticate against plugin ..."));
856

Jan Möbius's avatar
Jan Möbius committed
857
      bool success = false;
858 859 860 861 862
      QMetaObject::invokeMethod(plugin,"authenticate", Q_RETURN_ARG( bool , success ) ) ;
      
      QString message = "";
      QMetaObject::invokeMethod(plugin,"licenseError", Q_RETURN_ARG( QString , message ) ) ;
      _licenseErrors = message;
863

Jan Möbius's avatar
Jan Möbius committed
864 865 866
      if ( success )
        emit log(LOGINFO,tr("... ok. Loading plugin "));
      else {
867 868 869 870 871

        errors += tr("Error: Failed to load plugin. Plugin access denied by license management.");

        printPluginLoadLog(errors, warnings);

Matthias Möller's avatar
Matthias Möller committed
872
        info.description = basePlugin->description() + tr(" *Plugin access denied.*");
Jan Möbius's avatar
Jan Möbius committed
873
        // Abort here, as the plugin will not do anything else until correct authentication.
874 875 876 877 878

        info.errors   = errors;
        info.warnings = warnings;

        PluginStorage::pluginsFailed().push_back(info);
Jan Möbius's avatar
Jan Möbius committed
879
        return;
880
      }
Jan Möbius's avatar
Jan Möbius committed
881
    }
882 883


884
    emit log(LOGOUT,tr("Plugin Description :\t %1 ").arg( basePlugin->description()) );
885

886
    supported = "BaseInterface ";
887

Matthias Möller's avatar
Matthias Möller committed
888
    info.plugin        = plugin;
Jan Möbius's avatar
Jan Möbius committed
889
    if ( checkSlot(plugin,"version()") )
Matthias Möller's avatar
Matthias Möller committed
890
      info.version = basePlugin->version();
Jan Möbius's avatar
Jan Möbius committed
891
    else
Matthias Möller's avatar
Matthias Möller committed
892
      info.version = QString::number(-1);
893

Jan Möbius's avatar
Jan Möbius committed
894
    if ( OpenFlipper::Options::nogui() ) {
895

Jan Möbius's avatar
Jan Möbius committed
896
      if ( ! checkSlot( plugin , "noguiSupported()" ) ) {
897 898 899 900
        warnings += tr("Warning: Running in nogui mode which is unsupported by this plugin, skipping");

        printPluginLoadLog(errors, warnings);

901 902 903 904 905
        info.errors   = errors;
        info.warnings = warnings;

        PluginStorage::pluginsFailed().push_back(info);

906 907 908
        return;
      }

Jan Möbius's avatar
Jan Möbius committed
909
    }
910 911


Jan Möbius's avatar
Jan Möbius committed
912 913
    // Check for baseInterface of old style!
    if ( checkSignal(plugin,"updated_objects(int)") ) {
914 915 916 917 918

      errors += tr("Error: Plugin Uses old style updated_objects! Convert to updatedObject!") + "\n";

      printPluginLoadLog(errors, warnings);

919 920 921 922 923
      info.errors   = errors;
      info.warnings = warnings;

      PluginStorage::pluginsFailed().push_back(info);

Jan Möbius's avatar
Jan Möbius committed
924 925
      return;
    }
926

Jan Möbius's avatar
Jan Möbius committed
927
    if ( checkSignal(plugin,"update_view()") ) {
928 929 930 931
      errors += tr("Error: Plugin Uses old style update_view! Convert to updateView!") + "\n";

      printPluginLoadLog(errors, warnings);

932 933 934 935 936
      info.errors   = errors;
      info.warnings = warnings;

      PluginStorage::pluginsFailed().push_back(info);

Jan Möbius's avatar
Jan Möbius committed
937 938
      return;
    }
939

Jan Möbius's avatar
Jan Möbius committed
940
    if ( checkSignal(plugin,"updateView()") )
941
      connect(plugin,SIGNAL(updateView()),this,SLOT(updateView()), Qt::AutoConnection);
942

943 944
    if ( checkSignal(plugin,"blockScenegraphUpdates(bool)") )
      connect(plugin,SIGNAL(blockScenegraphUpdates(bool)),this,SLOT(blockScenegraphUpdates(bool)), Qt::QueuedConnection);
945

946
    if ( checkSignal(plugin,"updatedObject(int)") && checkSignal(plugin,"updatedObject(int,const UpdateType&)") ){
947
      
948 949
      errors += tr("Error: Plugin uses deprecated and(!) new updatedObject. Only new updatedObject will be active.") + "\n";

Jan Möbius's avatar
Jan Möbius committed
950
      log(LOGERR,tr("Plugin uses deprecated and(!) new updatedObject. Only new updatedObject will be active."));
951
      connect(plugin,SIGNAL(updatedObject(int,const UpdateType&)),this,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::AutoConnection);
Jan Möbius's avatar
Jan Möbius committed
952 953
      
    } else {
954

Jan Möbius's avatar
Jan Möbius committed
955
      if ( checkSignal(plugin,"updatedObject(int)") ){
956 957
        warnings += tr("Warning: Plugin uses deprecated updatedObject.") + "\n";

Jan Möbius's avatar
Jan Möbius committed
958
        log(LOGWARN,tr("Plugin uses deprecated updatedObject."));
959
        connect(plugin,SIGNAL(updatedObject(int)),this,SLOT(slotObjectUpdated(int)), Qt::AutoConnection);
960
      }
961

962
      if ( checkSignal(plugin,"updatedObject(int,const UpdateType&)") )
963
        connect(plugin,SIGNAL(updatedObject(int,const UpdateType&)),this,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::AutoConnection);
Jan Möbius's avatar
Jan Möbius committed
964
    }
Jan Möbius's avatar
Jan Möbius committed
965

966
    if ( checkSlot( plugin , "slotObjectUpdated(int)" ) && checkSlot( plugin , "slotObjectUpdated(int,const UpdateType&)" ) ){
967
      errors += tr("Error: Plugin uses deprecated and(!) new slotObjectUpdated. Only new slotObjectUpdated will be active.") + "\n";
Jan Möbius's avatar
Jan Möbius committed
968 969
      
      log(LOGERR,tr("Plugin uses deprecated and(!) new slotObjectUpdated. Only new slotObjectUpdated will be active."));
970
      connect(this,SIGNAL(signalObjectUpdated(int,const UpdateType&)),plugin,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::DirectConnection);
Jan Möbius's avatar
Jan Möbius committed
971 972
    
    } else {
973

Jan Möbius's avatar
Jan Möbius committed
974
      if ( checkSlot( plugin , "slotObjectUpdated(int)" ) ){
975
        warnings += tr("Warning: Plugin uses deprecated slotObjectUpdated.") + "\n";
Jan Möbius's avatar
Jan Möbius committed
976 977
        log(LOGWARN,tr("Plugin uses deprecated slotObjectUpdated."));
        connect(this,SIGNAL(signalObjectUpdated(int)),plugin,SLOT(slotObjectUpdated(int)), Qt::DirectConnection);
978
      }
979

980 981
      if ( checkSlot( plugin , "slotObjectUpdated(int,const UpdateType&)" ) )
        connect(this,SIGNAL(signalObjectUpdated(int,const UpdateType&)),plugin,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::DirectConnection);
Jan Möbius's avatar
Jan Möbius committed
982 983 984
    }

    if ( checkSignal(plugin,"objectPropertiesChanged(int)")) {
985 986 987
      errors += tr("Error: Signal objectPropertiesChanged(int) is deprecated.") + "\n";
      errors += tr("Error: The signal will be automatically emitted by the object that has been changed and the core will deliver it to the plugins!.") + "\n";
      errors += tr("Error: Please remove this signal from your plugins!.") + "\n";
Jan Möbius's avatar
Jan Möbius committed
988 989 990 991
    }
    
    if ( checkSlot( plugin , "slotViewChanged()" ) )
      connect(this,SIGNAL(pluginViewChanged()),plugin,SLOT(slotViewChanged()), Qt::DirectConnection);
992

993 994 995
    if ( checkSlot( plugin , "slotSceneDrawn()" ) )
      connect(this,SIGNAL(pluginSceneDrawn()),plugin,SLOT(slotSceneDrawn()), Qt::DirectConnection);

996 997 998
    if ( checkSlot( plugin , "slotDrawModeChanged(int)" ) )
          connect(coreWidget_,SIGNAL(drawModeChanged(int)),plugin,SLOT(slotDrawModeChanged(int)), Qt::DirectConnection);

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

1002 1003 1004
    if ( checkSignal(plugin,"visibilityChanged()" ) ) {
      errors += tr("Error: Signal visibilityChanged() now requires objectid or -1 as argument.") + "\n";
    }
1005

Jan Möbius's avatar
Jan Möbius committed
1006
    if ( checkSignal(plugin,"visibilityChanged(int)") ) {
1007 1008 1009
      errors += tr("Error: Signal visibilityChanged(int) is deprecated!") + "\n";
      errors += tr("Error: If an object changes its visibility, it will call the required functions automatically.") + "\n";
      errors += tr("Error: If you change a scenegraph node, call nodeVisibilityChanged(int). See docu of this function for details.") + "\n";
Jan Möbius's avatar
Jan Möbius committed
1010 1011 1012 1013 1014
    }
    
    if ( checkSignal(plugin,"nodeVisibilityChanged(int)") )
      connect(plugin,SIGNAL(nodeVisibilityChanged(int)),this,SLOT(slotVisibilityChanged(int)), Qt::DirectConnection);
    
1015

Jan Möbius's avatar
Jan Möbius committed
1016 1017
    if ( checkSlot(plugin,"slotVisibilityChanged(int)") )
      connect(this,SIGNAL(visibilityChanged(int)),plugin,SLOT(slotVisibilityChanged(int)), Qt::DirectConnection);
1018

1019 1020 1021
    if ( checkSignal(plugin,"activeObjectChanged()" ) ) {
      errors += tr("Error: Signal activeObjectChanged() is now objectSelectionChanged( int _objectId )") + "\n";
    }
1022

1023 1024 1025
    if ( checkSlot(plugin,"slotActiveObjectChanged()" ) ) {
      errors += tr("Error: Slot slotActiveObjectChanged() is now slotObjectSelectionChanged( int _objectId ) ") + "\n";
    }
1026

Jan Möbius's avatar
Jan Möbius committed
1027 1028
    if ( checkSlot(plugin,"slotAllCleared()") )
      connect(this,SIGNAL(allCleared()),plugin,SLOT(slotAllCleared()));
1029

1030

Jan Möbius's avatar
Jan Möbius committed
1031
    if ( checkSignal(plugin,"objectSelectionChanged(int)") ) {
1032 1033
      errors += tr("Error: Signal objectSelectionChanged(in) is deprecated!") + "\n";
      errors += tr("Error: If the selection for an object is changed, the core will emit the required signals itself!") + "\n";
1034 1035
    }

Jan Möbius's avatar
Jan Möbius committed
1036 1037
    if ( checkSlot( plugin , "slotObjectSelectionChanged(int)" ) )
      connect(this,SIGNAL(objectSelectionChanged(int)),plugin,SLOT(slotObjectSelectionChanged(int) ), Qt::DirectConnection);
1038 1039


Jan Möbius's avatar
Jan Möbius committed
1040 1041
    if ( checkSlot( plugin , "pluginsInitialized()" ) )
      connect(this,SIGNAL(pluginsInitialized()),plugin,SLOT(pluginsInitialized()), Qt::DirectConnection);
1042

1043 1044 1045
    if ( checkSlot( plugin , "pluginsInitialized(QVector<QPair<QString,QString>>const&)" ) )
      connect(this,SIGNAL(pluginsInitialized(QVector<QPair<QString,QString>>const&)),plugin,SLOT(pluginsInitialized(QVector<QPair<QString,QString>>const&)), Qt::DirectConnection);

Jan Möbius's avatar
Jan Möbius committed
1046 1047 1048
    if ( checkSignal(plugin,"setSlotDescription(QString,QString,QStringList,QStringList)") )
      connect(plugin, SIGNAL(setSlotDescription(QString,QString,QStringList,QStringList)),
              this,   SLOT(slotSetSlotDescription(QString,QString,QStringList,QStringList)) );
1049

1050
    // =============================================
1051
    // Function allowing switching of renderers from other plugins
1052
    // =============================================
1053 1054 1055 1056
    if ( checkSignal(plugin,"setRenderer(unsigned int,QString)" ) ) {
      connect(plugin,SIGNAL(setRenderer(unsigned int,QString)),this,SLOT(slotSetRenderer(unsigned int,QString)));
    }

1057 1058 1059 1060 1061
    if ( checkSignal(plugin,"getCurrentRenderer(unsigned int,QString&)" ) ) {
      connect(plugin,SIGNAL(getCurrentRenderer(unsigned int,QString&)),this,SLOT(slotGetCurrentRenderer(unsigned int,QString&)), Qt::DirectConnection);
    }


Jan Möbius's avatar
Jan Möbius committed
1062
  }
1063

Jan Möbius's avatar
Jan Möbius committed
1064 1065 1066
  //Check if the plugin supports Logging
  LoggingInterface* logPlugin = qobject_cast< LoggingInterface * >(plugin);
  if ( logPlugin ) {
1067
    supported = supported + "Logging ";
Dirk Wilden's avatar
Dirk Wilden committed
1068

Jan Möbius's avatar
Jan Möbius committed
1069
    // Create intermediate logger class which will mangle the output
Matthias Möller's avatar
Matthias Möller committed
1070
    PluginLogger* newlog = new PluginLogger(info.name);
Jan Möbius's avatar
Jan Möbius committed
1071 1072 1073
    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);
1074

Jan Möbius's avatar
Jan Möbius committed
1075 1076 1077
    // Connect it to the core widget logger
    if ( OpenFlipper::Options::gui() )
      connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
1078

Jan Möbius's avatar
Jan Möbius committed
1079 1080
    // connection to console logger
    connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
1081

Jan Möbius's avatar
Jan Möbius committed
1082 1083
    // connection to file logger
    connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
1084

Jan Möbius's avatar
Jan Möbius committed
1085 1086 1087 1088
    // connection to external plugin logger
    if ( checkSlot(plugin,"logOutput(Logtype,QString)") )
      connect(this,SIGNAL(externalLog(Logtype,QString)), plugin, SLOT(logOutput(Logtype,QString)) ) ;
  }
1089

Jan Möbius's avatar
Jan Möbius committed
1090 1091 1092
  //Check if the plugin supports Menubar-Interface
  MenuInterface* menubarPlugin = qobject_cast< MenuInterface * >(plugin);
  if ( menubarPlugin && OpenFlipper::Options::gui() ) {
1093
    supported = supported + "Menubar ";
Jan Möbius's avatar
Jan Möbius committed
1094 1095 1096 1097

    if ( checkSignal(plugin,"addMenubarAction(QAction*,QString)") )
      connect(plugin      , SIGNAL(addMenubarAction(QAction*,QString)),
              coreWidget_ , SLOT(slotAddMenubarAction(QAction*,QString)),Qt::DirectConnection);
1098 1099 1100
    if ( checkSignal(plugin,"addMenubarActions(std::vector<QAction*>, QString)") )
      connect(plugin      , SIGNAL(addMenubarActions(std::vector<QAction*>,QString)),
              coreWidget_ , SLOT(slotAddMenubarActions(std::vector<QAction*>,QString)),Qt::DirectConnection);
Jan Möbius's avatar
Jan Möbius committed
1101 1102 1103 1104
    if ( checkSignal(plugin,"getMenubarMenu (QString,QMenu*&,bool)") )
      connect(plugin      , SIGNAL(getMenubarMenu (QString,QMenu*&,bool)),
              coreWidget_ , SLOT(slotGetMenubarMenu (QString,QMenu*&,bool)),Qt::DirectConnection);
  }
1105

Jan Möbius's avatar
Jan Möbius committed
1106 1107 1108
  //Check if the plugin supports ContextMenuInterface
  ContextMenuInterface* contextMenuPlugin = qobject_cast< ContextMenuInterface * >(plugin);
  if ( contextMenuPlugin && OpenFlipper::Options::gui() ) {
1109
    supported = supported + "ContextMenu ";
1110

Jan Möbius's avatar
Jan Möbius committed
1111 1112 1113
    if ( checkSignal(plugin,"addContextMenuItem(QAction*,ContextMenuType)") )
      connect(plugin      , SIGNAL(addContextMenuItem(QAction*,ContextMenuType)),
              coreWidget_ , SLOT(slotAddContextItem(QAction*,ContextMenuType)),Qt::DirectConnection);
1114

Jan Möbius's avatar
Jan Möbius committed
1115 1116 1117
    if ( checkSignal(plugin,"addContextMenuItem(QAction*,DataType,ContextMenuType)") )
      connect(plugin      , SIGNAL(addContextMenuItem(QAction*,DataType,ContextMenuType)),
              coreWidget_ , SLOT(slotAddContextItem(QAction*,DataType,ContextMenuType)),Qt::DirectConnection);
1118

1119 1120 1121 1122
    if ( checkSignal(plugin,"hideContextMenu()") )
          connect(plugin      , SIGNAL(hideContextMenu()),
                  coreWidget_ , SLOT(slotHideContextMenu()),Qt::DirectConnection);

Jan Möbius's avatar
Jan Möbius committed
1123 1124 1125
    if ( checkSlot(plugin,"slotUpdateContextMenu(int)") )
      connect(coreWidget_ , SIGNAL(updateContextMenu(int)),
              plugin      , SLOT(slotUpdateContextMenu(int)),Qt::DirectConnection);
1126

Jan Möbius's avatar
Jan Möbius committed
1127 1128 1129
    if ( checkSlot(plugin,"slotUpdateContextMenuNode(int)") )
      connect(coreWidget_ , SIGNAL(updateContextMenuNode(int)),
              plugin      , SLOT(slotUpdateContextMenuNode(int)),Qt::DirectConnection);
1130

Jan Möbius's avatar
Jan Möbius committed
1131 1132 1133 1134
    if ( checkSlot(plugin,"slotUpdateContextMenuBackground()") )
      connect(coreWidget_ , SIGNAL(updateContextMenuBackground()),
              plugin      , SLOT(slotUpdateContextMenuBackground()),Qt::DirectConnection);
  }
1135

Jan Möbius's avatar
Jan Möbius committed
1136 1137 1138
  //Check if the plugin supports Toolbox-Interface
  ToolboxInterface* toolboxPlugin = qobject_cast< ToolboxInterface * >(plugin);
  if ( toolboxPlugin && OpenFlipper::Options::gui() ) {
1139
    supported = supported + "Toolbox ";
1140

Dirk Wilden's avatar
Dirk Wilden committed
1141

Jan Möbius's avatar
Jan Möbius committed
1142 1143 1144
    if ( checkSignal(plugin, "addToolbox(QString,QWidget*)"))
      connect(plugin, SIGNAL( addToolbox(QString,QWidget*) ),
              this, SLOT( addToolbox(QString,QWidget*) ),Qt::DirectConnection );
1145

Dirk Wilden's avatar
Dirk Wilden committed
1146 1147 1148
    if ( checkSignal(plugin, "addToolbox(QString,QWidget*,QIcon*)"))
      connect(plugin, SIGNAL( addToolbox(QString,QWidget*,QIcon*) ),
              this, SLOT( addToolbox(QString,QWidget*,QIcon*) ),Qt::DirectConnection );
1149 1150 1151 1152 1153

    if ( checkSignal(plugin, "addToolbox(QString,QWidget*,QIcon*,QWidget*)"))
      connect(plugin, SIGNAL( addToolbox(QString,QWidget*,QIcon*,QWidget*) ),
              this, SLOT( addToolbox(QString,QWidget*,QIcon*,QWidget*) ),Qt::DirectConnection );
}
Jan Möbius's avatar
Jan Möbius committed
1154 1155 1156 1157
  
  //Check if the plugin supports ViewMode-Interface
  ViewModeInterface* viewModePlugin = qobject_cast< ViewModeInterface * >(plugin);
  if ( viewModePlugin && OpenFlipper::Options::gui() ) {
1158
    supported = supported + "ViewMode ";
Jan Möbius's avatar
Jan Möbius committed
1159 1160 1161 1162 1163 1164 1165
    
    if ( checkSignal(plugin, "defineViewModeToolboxes(QString,QStringList)"))
      connect(plugin, SIGNAL( defineViewModeToolboxes(QString, QStringList) ),
              coreWidget_, SLOT( slotAddViewModeToolboxes(QString, QStringList) ),Qt::DirectConnection );
              
    if ( checkSignal(plugin, "defineViewModeToolbars(QString,QStringList)"))
      connect(plugin, SIGNAL( defineViewModeToolbars(QString, QStringList) ),
Jan Möbius's avatar
Jan Möbius committed
1166 1167 1168 1169 1170
              coreWidget_, SLOT( slotAddViewModeToolbars(QString, QStringList) ),Qt::DirectConnection );    
              
    if ( checkSignal(plugin, "defineViewModeContextMenus(QString,QStringList)"))
      connect(plugin, SIGNAL( defineViewModeContextMenus(QString, QStringList) ),
              coreWidget_, SLOT( slotAddViewModeContextMenus(QString, QStringList) ),Qt::DirectConnection );                
Jan Möbius's avatar
Jan Möbius committed
1171 1172 1173
              
    if ( checkSignal(plugin, "defineViewModeIcon(QString,QString)"))
      connect(plugin, SIGNAL( defineViewModeIcon(QString, QString) ),
1174 1175 1176 1177 1178 1179
              coreWidget_, SLOT( slotSetViewModeIcon(QString, QString) ),Qt::DirectConnection );

    if ( checkSignal(plugin, "setViewMode(QString,bool)"))
      connect(plugin,    SIGNAL( setViewMode(QString, bool) ),
              coreWidget_, SLOT( setViewMode(QString, bool) ),Qt::DirectConnection );
  }
Jan Möbius's avatar
Jan Möbius committed
1180 1181 1182 1183

  //Check if the plugin supports Options-Interface
  OptionsInterface* optionsPlugin = qobject_cast< OptionsInterface * >(plugin);
  if ( optionsPlugin && OpenFlipper::Options::gui() ) {
1184
    supported = supported + "Options ";
Jan Möbius's avatar
Jan Möbius committed
1185 1186 1187

    QWidget* widget = 0;
    if ( optionsPlugin->initializeOptionsWidget( widget ) ) {
Matthias Möller's avatar
Matthias Möller committed
1188
          info.optionsWidget = widget;
Jan Möbius's avatar
Jan Möbius committed
1189 1190 1191 1192

          if ( checkSlot(plugin,"applyOptions()") )
            connect(coreWidget_ , SIGNAL( applyOptions() ),
                    plugin      , SLOT( applyOptions() ),Qt::DirectConnection);
1193
    }
Jan Möbius's avatar
Jan Möbius committed
1194
  }
1195

Jan Möbius's avatar
Jan Möbius committed
1196 1197 1198
  //Check if the plugin supports Toolbar-Interface
  ToolbarInterface* toolbarPlugin = qobject_cast< ToolbarInterface * >(plugin);
  if ( toolbarPlugin && OpenFlipper::Options::gui() ) {
1199
    supported = supported + "Toolbars ";
1200

Jan Möbius's avatar
Jan Möbius committed
1201 1202 1203
    if ( checkSignal(plugin,"addToolbar(QToolBar*)") )
      connect(plugin,SIGNAL(addToolbar(QToolBar*)),
              coreWidget_,SLOT(slotAddToolbar(QToolBar*)),Qt::DirectConnection);
1204

Jan Möbius's avatar
Jan Möbius committed
1205 1206 1207
    if ( checkSignal(plugin,"removeToolbar(QToolBar*)") )
      connect(plugin,SIGNAL(removeToolbar(QToolBar*)),
              coreWidget_,SLOT(slotRemoveToolbar(QToolBar*)),Qt::DirectConnection);
1208

Jan Möbius's avatar
Jan Möbius committed
1209 1210 1211 1212 1213
    if ( checkSignal(plugin,"getToolBar(QString,QToolBar*&)") )
      connect(plugin,SIGNAL(getToolBar(QString,QToolBar*&)),
              coreWidget_,SLOT(getToolBar(QString,QToolBar*&)),Qt::DirectConnection);
        
  }
1214

Jan Möbius's avatar
Jan Möbius committed
1215 1216 1217
  //Check if the plugin supports StatusBar-Interface
  StatusbarInterface* statusbarPlugin = qobject_cast< StatusbarInterface * >(plugin);
  if ( statusbarPlugin && OpenFlipper::Options::gui() ) {
1218
    supported = supported + "StatusBar ";
1219

Jan Möbius's avatar
Jan Möbius committed
1220 1221 1222
    if ( checkSignal(plugin,"showStatusMessage(QString,int)") )
      connect(plugin,SIGNAL(showStatusMessage(QString,int)),
              coreWidget_,SLOT(statusMessage(QString,int)),Qt::DirectConnection);
1223

Dirk Wilden's avatar
Dirk Wilden committed
1224

Jan Möbius's avatar
Jan Möbius committed
1225 1226 1227
    if ( checkSignal(plugin,"setStatus(ApplicationStatus::applicationStatus)") )
      connect(plugin,SIGNAL(setStatus(ApplicationStatus::applicationStatus)),
              coreWidget_,SLOT(setStatus(ApplicationStatus::applicationStatus)),Qt::DirectConnection);
1228

Jan Möbius's avatar
Jan Möbius committed
1229 1230 1231 1232 1233 1234 1235
    if ( checkSignal(plugin,"clearStatusMessage()") )
      connect(plugin,SIGNAL(clearStatusMessage()),
              coreWidget_,SLOT(clearStatusMessage()));
              
    if ( checkSignal(plugin,"addWidgetToStatusbar(QWidget*)") )
      connect(plugin,SIGNAL(addWidgetToStatusbar(QWidget*)), coreWidget_,SLOT(addWidgetToStatusbar(QWidget*)));
  }
1236

Jan Möbius's avatar
Jan Möbius committed
1237 1238 1239
  //Check if the plugin supports Key-Interface
  KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugin);
  if ( keyPlugin && OpenFlipper::Options::gui() ) {
1240
    supported = supported + "KeyboardEvents ";
1241

Jan Möbius's avatar
Jan Möbius committed
1242 1243 1244 1245
    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)) );
  }
1246

Jan Möbius's avatar
Jan Möbius committed
1247 1248 1249
  //Check if the plugin supports Mouse-Interface
  MouseInterface* mousePlugin = qobject_cast< MouseInterface * >(plugin);
  if ( mousePlugin && OpenFlipper::Options::gui()  ) {
1250
    supported = supported + "MouseEvents ";
1251

Jan Möbius's avatar
Jan Möbius committed
1252 1253 1254
    if ( checkSlot( plugin , "slotMouseWheelEvent(QWheelEvent*,const std::string&)" ) )
      connect(this   , SIGNAL(PluginWheelEvent(QWheelEvent * , const std::string & )),
              plugin , SLOT(slotMouseWheelEvent(QWheelEvent* , const std::string & )));
1255

Jan Möbius's avatar
Jan Möbius committed
1256 1257 1258
    if ( checkSlot( plugin , "slotMouseEvent(QMouseEvent*)" ) )
      connect(this   , SIGNAL(PluginMouseEvent(QMouseEvent*)),
              plugin , SLOT(slotMouseEvent(QMouseEvent*)));
1259

Jan Möbius's avatar
Jan Möbius committed
1260 1261 1262
    if ( checkSlot( plugin , "slotMouseEventLight(QMouseEvent*)" ) )
      connect(this   , SIGNAL(PluginMouseEventLight(QMouseEvent*)),
              plugin , SLOT(slotMouseEventLight(QMouseEvent*)));
1263

Jan Möbius's avatar
Jan Möbius committed
1264
  }