PluginLoader.cc 112 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44
*                                                                            *
*   $Revision$                                                       *
45
*   $LastChangedBy$                                         *
Jan Möbius's avatar
Jan Möbius committed
46 47
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65




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


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

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


Jan Möbius's avatar
Jan Möbius committed
66
#include "OpenFlipper/BasePlugin/AboutInfoInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
67 68 69 70 71
#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
72
#include "OpenFlipper/BasePlugin/OptionsInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
73 74
#include "OpenFlipper/BasePlugin/ToolbarInterface.hh"
#include "OpenFlipper/BasePlugin/TextureInterface.hh"
75
#include "OpenFlipper/BasePlugin/ProcessInterface.hh"
Jan Möbius's avatar
Jan Möbius committed
76
#include "OpenFlipper/BasePlugin/ViewModeInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
77 78 79 80
#include "OpenFlipper/BasePlugin/LoadSaveInterface.hh"
#include "OpenFlipper/BasePlugin/INIInterface.hh"
#include "OpenFlipper/BasePlugin/RPCInterface.hh"
#include "OpenFlipper/BasePlugin/ScriptInterface.hh"
81
#include "OpenFlipper/BasePlugin/SecurityInterface.hh"
82
#include "OpenFlipper/BasePlugin/PluginConnectionInterface.hh"
83
#include "OpenFlipper/BasePlugin/MetadataInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
84 85 86


#include <ACG/QtWidgets/QtFileDialog.hh>
Dirk Wilden's avatar
Dirk Wilden committed
87
#include "OpenFlipper/widgets/PluginDialog/PluginDialog.hh"
Jan Möbius's avatar
 
Jan Möbius committed
88

89
#include <OpenFlipper/common/FileTypes.hh>
90
#include <OpenFlipper/common/PluginStorage.hh>
91 92


93 94
/**
 * The number of plugins to load simultaneously.
95

96
 */
97
static const int PRELOAD_THREADS_COUNT = (QThread::idealThreadCount() != -1) ? QThread::idealThreadCount() : 8;
98

99 100
namespace cmake { extern const char *static_plugins; };

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

Jan Möbius's avatar
Jan Möbius committed
191 192 193 194 195
    /** \brief preload function
    *
    * This function is used in the thread to preload a plugin. The name is given in the constructor.
    */
    void run() {
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
      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
215 216 217
    }
    
  private:
218 219 220
    std::deque<QString> filenames_;
    QMutex filenamesMutex_;
    PreloadAggregator *aggregator_;
Jan Möbius's avatar
Jan Möbius committed
221 222
};

223 224 225 226 227 228 229 230 231 232
/**
 * @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:
233
        size_t getTypeOrdinal(const QString &name) const {
234 235 236 237 238 239 240 241 242 243 244 245
            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 {
246 247
            const size_t typeA = getTypeOrdinal(a);
            const size_t typeB = getTypeOrdinal(b);
248 249 250 251 252 253 254 255
            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
256

Jan Möbius's avatar
 
Jan Möbius committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
//== 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
276
  
277 278 279
  //regsiter custom datatypes for signal/slots
  registerTypes();

Jan Möbius's avatar
Jan Möbius committed
280 281
  QString licenseTexts = "";
  
Dirk Wilden's avatar
Dirk Wilden committed
282
  //try to load plugins from new location
283
  QDir tempDir = QDir(OpenFlipper::Options::pluginDir());
Dirk Wilden's avatar
Dirk Wilden committed
284

285
  // Possible Plugin extensions
Jan Möbius's avatar
Jan Möbius committed
286 287 288
  // Windows gets DLLs
  // Mac and Linux use so
  // We don't use the dylib extension on Mac at the moment.
289 290 291
  QStringList filter;
  if ( OpenFlipper::Options::isWindows() )
    filter << "*.dll";
Jan Möbius's avatar
Jan Möbius committed
292
  else 
293 294
    filter << "*.so";
  
Jan Möbius's avatar
 
Jan Möbius committed
295
  // Get all files in the Plugin dir
296
  QStringList pluginlist = tempDir.entryList(filter,QDir::Files);
Dirk Wilden's avatar
Dirk Wilden committed
297

298 299
  // Convert local file path to absolute path
  for (int i=0; i < pluginlist.size(); i++) {
300
     pluginlist[i] = tempDir.absoluteFilePath(pluginlist[i]);
Jan Möbius's avatar
 
Jan Möbius committed
301 302
  }

303
  // get all Plugin Names which will not be loaded
304
  QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames", QStringList()).toStringList();
305 306 307 308 309 310
  
  // 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 
311
  QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins", QStringList()).toStringList();
312 313
  
  // Output info about additional plugins
Jan Möbius's avatar
Jan Möbius committed
314
  for ( int i = 0 ; i < additionalPlugins.size(); ++i) {
315
    emit log(LOGOUT,tr("Additional Plugin from file: %1").arg( additionalPlugins[i] ) );
Jan Möbius's avatar
Jan Möbius committed
316
  }
317 318 319
  
  // Prepend the additional Plugins to the plugin list
  pluginlist = additionalPlugins << pluginlist;
320

321
  /*
322
   * Remove static plugins from dynamically loaded list.
323
   */
324 325 326 327 328 329 330 331 332 333 334 335
  {
      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;
          }
336 337 338
      }
  }

339 340 341 342
  /*
   * Note: This call is not necessary, anymore. Initialization order
   * is determined later.
   */
343
  //std::sort(pluginlist.begin(), pluginlist.end(), PluginInitializationOrder());
Jan Möbius's avatar
 
Jan Möbius committed
344

345 346
  for ( int i = 0 ; i < dontLoadPlugins.size(); ++i )
    emit log(LOGWARN,tr("Skipping Plugins :\t %1").arg( dontLoadPlugins[i] ) );
Jan Möbius's avatar
 
Jan Möbius committed
347

348
  emit log(LOGOUT,"================================================================================");
Jan Möbius's avatar
 
Jan Möbius committed
349

Jan Möbius's avatar
Jan Möbius committed
350 351 352 353
  QTime time;
  
  time.start();
  
354 355 356 357 358 359 360 361 362 363
  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
364
  
365 366 367 368
  /*
   * Distribute plugins onto loader threads in a round robin fashion.
   * (only load them in seperate thread. Instance will be created in main thread)
   */
Jan Möbius's avatar
 
Jan Möbius committed
369
  for ( int i = 0 ; i < pluginlist.size() ; ++i) {
370 371 372 373 374 375 376 377 378
    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
379 380
  }
  
381 382 383 384 385 386 387 388 389 390 391
  /*
   * 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);

392
      if (splash_) {
393 394 395
        splashMessage_ = tr("Loading Plugin %1/%2").arg(loadedPlugins.size()).arg(pluginlist.size()) ;
        splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
      }
Jan Möbius's avatar
 
Jan Möbius committed
396 397
  }

398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
  /*
   * 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) {

414
      if (splash_) {
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
        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;
  }

433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
  /*
   * 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;
      }
  }

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

Jan Möbius's avatar
 
Jan Möbius committed
453
  splashMessage_ = "";
Jan Möbius's avatar
Jan Möbius committed
454 455
  
  if ( licenseTexts != "" ) {
Jan Möbius's avatar
Jan Möbius committed
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 494 495 496 497 498 499 500 501
    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();
          }
502
           
Jan Möbius's avatar
Jan Möbius committed
503
        }
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520

        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
521 522 523 524 525 526
        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);
527 528 529 530 531 532

        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
533
        // set a text to the Clipboard
534
        QClipboard *cb = QApplication::clipboard();
Jan Möbius's avatar
Jan Möbius committed
535
        cb->setText(request.join("\n"));
Jan Möbius's avatar
Jan Möbius committed
536

537
        if ( userAnswer == 1 ) {
538 539 540 541 542 543 544
           QString url = "mailto:" + it.key();
           url += "?subject=License Request&body=";
#ifdef WIN32
           url += request.join(";;");
#else
           url += request.join("\n");
#endif
Jan Möbius's avatar
Jan Möbius committed
545

546 547 548
           QUrl encodedURL(url, QUrl::TolerantMode);
           QDesktopServices::openUrl(encodedURL);
        }
Jan Möbius's avatar
Jan Möbius committed
549 550 551 552 553
        
      }

      
    } else {
554

Jan Möbius's avatar
Jan Möbius committed
555
      emit log(LOGWARN,tr("Plugin License check failed: "));
Jan Möbius's avatar
Jan Möbius committed
556 557 558
      std::cerr << licenseTexts.toStdString() << std::endl;
    }
  } 
Jan Möbius's avatar
 
Jan Möbius committed
559 560 561

  emit pluginsInitialized();

562
  emit log(LOGOUT,tr("Loaded %n Plugin(s)","",int(plugins().size())) );
Jan Möbius's avatar
 
Jan Möbius committed
563 564 565 566 567 568 569 570 571
}

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

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

572
  // Setup filters for possible plugin extensions
Jan Möbius's avatar
Jan Möbius committed
573 574 575
  // 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
576
  QString filter;
Jan Möbius's avatar
 
Jan Möbius committed
577 578
  if ( OpenFlipper::Options::isWindows() )
    filter = "Plugins (*.dll)";
Jan Möbius's avatar
Jan Möbius committed
579
  else 
Jan Möbius's avatar
 
Jan Möbius committed
580 581
    filter = "Plugins (*.so)";

582
  // Ask the user to select the file to load
583
  QString filename = ACG::getOpenFileName(coreWidget_,tr("Load Plugin"),filter, OpenFlipperSettings().value("Core/CurrentDir").toString() );
Jan Möbius's avatar
 
Jan Möbius committed
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604

  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;

605
  // Ask if the plugin is on the block list
606
  QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames", QStringList()).toStringList();
607
  if (dontLoadPlugins.contains(name)){
Jan Möbius's avatar
 
Jan Möbius committed
608 609
      int ret = QMessageBox::question(0, tr("Plugin Loading Prevention"),
                   tr("OpenFlipper is currently configured to prevent loading this plugin.\n"
610
                      "Do you want to enable this plugin permanently?"),
Jan Möbius's avatar
 
Jan Möbius committed
611 612
                   QMessageBox::Yes | QMessageBox::No,
                   QMessageBox::Yes);
613 614 615 616 617
      if (ret == QMessageBox::Yes) {
        dontLoadPlugins.removeAll(name);
        OpenFlipperSettings().setValue("PluginControl/DontLoadNames",dontLoadPlugins);
      } else
         return;
Jan Möbius's avatar
 
Jan Möbius committed
618
  }
619 620
  
  // check if the plugin is not on the additional plugin list
621
  QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins", QStringList()).toStringList();
622 623 624 625 626 627 628 629 630 631 632 633
  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
634 635 636 637
  QString licenseText = "";
  loadPlugin(filename,false,licenseText);
  
  if ( licenseText != "" ) {
Jan Möbius's avatar
Jan Möbius committed
638
    if ( OpenFlipper::Options::gui() ) {
Jan Möbius's avatar
Jan Möbius committed
639
      QMessageBox::warning ( 0, tr("Plugin License check failed"),  licenseText );
Jan Möbius's avatar
Jan Möbius committed
640 641 642 643
      
      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
644 645 646
      std::cerr << "Plugin License check failed" << std::endl;
      std::cerr << licenseText.toStdString() << std::endl;
    }
647
  }
Jan Möbius's avatar
 
Jan Möbius committed
648 649
}

Dirk Wilden's avatar
Dirk Wilden committed
650
/** @brief slot for showing loaded Plugins
Jan Möbius's avatar
 
Jan Möbius committed
651
 */
Dirk Wilden's avatar
Dirk Wilden committed
652
void Core::slotShowPlugins(){
Jan Möbius's avatar
 
Jan Möbius committed
653

Dirk Wilden's avatar
Dirk Wilden committed
654 655 656 657 658 659
  if ( OpenFlipper::Options::gui() ){

    int ret = 0;

    while (ret == 0){

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

Dirk Wilden's avatar
Dirk Wilden committed
662 663
      //connect signals
      connect(dialog, SIGNAL( loadPlugin() ), this, SLOT( slotLoadPlugin() ));
664 665 666 667
      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
668 669 670 671 672 673 674

      //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
675 676
}

677 678 679 680 681 682 683
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);
  }
Jan Möbius's avatar
 
Jan Möbius committed
684

685 686 687
  for (size_t i = 0; i < plugins().size();++i)
    if (plugins()[i].name == _name)
      plugins()[i].status = PluginInfo::BLOCKED;
688
}
Jan Möbius's avatar
 
Jan Möbius committed
689

690 691 692 693 694
void Core::slotUnBlockPlugin(const QString &_name)
{
  QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames",QStringList()).toStringList();
  dontLoadPlugins.removeAll(_name);
  OpenFlipperSettings().setValue("PluginControl/DontLoadNames",dontLoadPlugins);
Jan Möbius's avatar
 
Jan Möbius committed
695

696 697 698
  for (size_t i = 0; i < plugins().size();++i)
      if (plugins()[i].name == _name)
        plugins()[i].status = PluginInfo::UNLOADED;
Jan Möbius's avatar
 
Jan Möbius committed
699 700
}

701 702 703 704 705 706 707

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

Jan Möbius's avatar
 
Jan Möbius committed
708
/** @brief Load a Plugin with given filename
Matthias Möller's avatar
doc fix  
Matthias Möller committed
709 710
 *  @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
711
 *  @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
712
 *  @param _plugin You can provide a preloaded plugin here. If this is 0 the filename will be used to load the plugin.
Jan Möbius's avatar
 
Jan Möbius committed
713
 */
714
void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _licenseErrors, QObject* _plugin){
Jan Möbius's avatar
 
Jan Möbius committed
715

Jan Möbius's avatar
Jan Möbius committed
716 717
  _licenseErrors = "";
  
Jan Möbius's avatar
 
Jan Möbius committed
718 719
  // Only load .dll under windows
  if ( OpenFlipper::Options::isWindows() ) {
720
    QString dllname = _filename;
721
    if ( ! dllname.endsWith( ".dll" ) )
Jan Möbius's avatar
 
Jan Möbius committed
722 723 724 725
      return;
  }
  // Only load .so under linux
  if ( OpenFlipper::Options::isLinux() ) {
726
    QString soname = _filename;
727
    if ( ! soname.endsWith( ".so" ) )
Jan Möbius's avatar
 
Jan Möbius committed
728 729 730
      return;
  }

Jan Möbius's avatar
Jan Möbius committed
731 732
  // This will be the reference to our plugin
  QObject *plugin = 0;
Jan Möbius's avatar
 
Jan Möbius committed
733

734 735 736 737
  // Collect error and warning info
  QString errors, warnings;


Jan Möbius's avatar
Jan Möbius committed
738 739 740
  // Try to open the file if we did not get a plugin,
  // Otherwise use the supplied plugin pointer
  if ( _plugin == 0 ) {
741
    QPluginLoader loader( _filename );
Jan Möbius's avatar
Jan Möbius committed
742 743 744
    plugin = loader.instance();  
    
    if ( !plugin) {
745 746 747 748 749 750

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

772
  emit log(LOGOUT,tr("Location : \t %1").arg( _filename) );
Jan Möbius's avatar
Jan Möbius committed
773 774 775 776
  
  // Check if it is a BasePlugin
  BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugin);
  if ( basePlugin ) {
777 778

    //set basic information about plugin
Matthias Möller's avatar
Matthias Möller committed
779 780 781
    info.name = basePlugin->name();
    info.rpcName = info.name.remove(" ").toLower();
    info.description = basePlugin->description();
782
    info.warnings = "BLA";
783 784

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

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

789
    if (splash_) {
Jan Möbius's avatar
Jan Möbius committed
790 791 792
      splashMessage_ = splashMessage_ + " " + basePlugin->name() ;
      splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
    }
Jan Möbius's avatar
 
Jan Möbius committed
793

Jan Möbius's avatar
Jan Möbius committed
794
    //Check if plugin is already loaded
795
    for (unsigned int k=0; k < plugins().size(); k++){
Jan Möbius's avatar
Jan Möbius committed
796 797 798 799

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

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

803
            warnings += tr("Warning: Already loaded from %1").arg( plugins()[k].path) + "\n";
804 805 806

            printPluginLoadLog(errors, warnings);

Matthias Möller's avatar
Matthias Möller committed
807
            info.description = basePlugin->description() + tr(" *Already loaded.*");
808 809 810 811 812 813

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

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

Jan Möbius's avatar
Jan Möbius committed
814 815 816 817 818 819
            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"
820
                                              "Do you want to unload the existing plugin first?").arg( plugins()[k].path),
Jan Möbius's avatar
Jan Möbius committed
821
                                          QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
822 823
          if (ret == QMessageBox::No)
          {
824
            warnings += tr("Warning: Already loaded from %1.").arg( plugins()[k].path) + "\n";
825 826 827

            printPluginLoadLog(errors, warnings);

Matthias Möller's avatar
Matthias Möller committed
828
            info.description = basePlugin->description() + tr(" *Already loaded.*");
829 830 831 832 833

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

            PluginStorage::pluginsFailed().push_back(info);
Jan Möbius's avatar
Jan Möbius committed
834
            return;
Jan Möbius's avatar
 
Jan Möbius committed
835 836
          }
        }
Dirk Wilden's avatar
Dirk Wilden committed
837
      }
Jan Möbius's avatar
Jan Möbius committed
838
    }
Jan Möbius's avatar
 
Jan Möbius committed
839

840
    QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames",QStringList()).toStringList();
841

Jan Möbius's avatar
Jan Möbius committed
842
    if ( dontLoadPlugins.contains(basePlugin->name(), Qt::CaseInsensitive) ) {
843 844 845 846 847

      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
848
      info.status = PluginInfo::BLOCKED;
849 850 851 852 853 854

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

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

Jan Möbius's avatar
Jan Möbius committed
855 856
      return;
    }
Jan Möbius's avatar
 
Jan Möbius committed
857

Jan Möbius's avatar
Jan Möbius committed
858 859 860 861
    //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 ..."));
862

Jan Möbius's avatar
Jan Möbius committed
863
      bool success = false;
864 865 866 867 868
      QMetaObject::invokeMethod(plugin,"authenticate", Q_RETURN_ARG( bool , success ) ) ;
      
      QString message = "";
      QMetaObject::invokeMethod(plugin,"licenseError", Q_RETURN_ARG( QString , message ) ) ;
      _licenseErrors = message;
869

Jan Möbius's avatar
Jan Möbius committed
870 871 872
      if ( success )
        emit log(LOGINFO,tr("... ok. Loading plugin "));
      else {
873 874 875 876 877

        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
878
        info.description = basePlugin->description() + tr(" *Plugin access denied.*");
Jan Möbius's avatar
Jan Möbius committed
879
        // Abort here, as the plugin will not do anything else until correct authentication.
880 881 882 883 884

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

        PluginStorage::pluginsFailed().push_back(info);
Jan Möbius's avatar
Jan Möbius committed
885
        return;
886
      }
Jan Möbius's avatar
Jan Möbius committed
887
    }
888 889


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

892
    supported = "BaseInterface ";
Jan Möbius's avatar
 
Jan Möbius committed
893

Matthias Möller's avatar
Matthias Möller committed
894
    info.plugin        = plugin;
Jan Möbius's avatar
Jan Möbius committed
895
    if ( checkSlot(plugin,"version()") )
Matthias Möller's avatar
Matthias Möller committed
896
      info.version = basePlugin->version();
Jan Möbius's avatar
Jan Möbius committed
897
    else
Matthias Möller's avatar
Matthias Möller committed
898
      info.version = QString::number(-1);
Jan Möbius's avatar
 
Jan Möbius committed
899

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

Jan Möbius's avatar
Jan Möbius committed
902
      if ( ! checkSlot( plugin , "noguiSupported()" ) ) {
903 904 905 906
        warnings += tr("Warning: Running in nogui mode which is unsupported by this plugin, skipping");

        printPluginLoadLog(errors, warnings);

907 908 909 910 911
        info.errors   = errors;
        info.warnings = warnings;

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

912 913 914
        return;
      }

Jan Möbius's avatar
Jan Möbius committed
915
    }
916 917


Jan Möbius's avatar
Jan Möbius committed
918 919
    // Check for baseInterface of old style!
    if ( checkSignal(plugin,"updated_objects(int)") ) {
920 921 922 923 924

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

      printPluginLoadLog(errors, warnings);

925 926 927 928 929
      info.errors   = errors;
      info.warnings = warnings;

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

Jan Möbius's avatar
Jan Möbius committed
930 931
      return;
    }
932

Jan Möbius's avatar
Jan Möbius committed
933
    if ( checkSignal(plugin,"update_view()") ) {
934 935 936 937
      errors += tr("Error: Plugin Uses old style update_view! Convert to updateView!") + "\n";

      printPluginLoadLog(errors, warnings);

938 939 940 941 942
      info.errors   = errors;
      info.warnings = warnings;

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

Jan Möbius's avatar
Jan Möbius committed
943 944
      return;
    }
945

Jan Möbius's avatar
Jan Möbius committed
946
    if ( checkSignal(plugin,"updateView()") )
947
      connect(plugin,SIGNAL(updateView()),this,SLOT(updateView()), Qt::AutoConnection);
Dirk Wilden's avatar
Dirk Wilden committed
948

949 950
    if ( checkSignal(plugin,"blockScenegraphUpdates(bool)") )
      connect(plugin,SIGNAL(blockScenegraphUpdates(bool)),this,SLOT(blockScenegraphUpdates(bool)), Qt::QueuedConnection);
951

952
    if ( checkSignal(plugin,"updatedObject(int)") && checkSignal(plugin,"updatedObject(int,const UpdateType&)") ){
Dirk Wilden's avatar
Dirk Wilden committed
953
      
954 955
      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
956
      log(LOGERR,tr("Plugin uses deprecated and(!) new updatedObject. Only new updatedObject will be active."));
957
      connect(plugin,SIGNAL(updatedObject(int,const UpdateType&)),this,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::AutoConnection);
Jan Möbius's avatar
Jan Möbius committed
958 959
      
    } else {
960

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

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

968
      if ( checkSignal(plugin,"updatedObject(int,const UpdateType&)") )
969
        connect(plugin,SIGNAL(updatedObject(int,const UpdateType&)),this,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::AutoConnection);
Jan Möbius's avatar
Jan Möbius committed
970
    }
Jan Möbius's avatar
Jan Möbius committed
971

972
    if ( checkSlot( plugin , "slotObjectUpdated(int)" ) && checkSlot( plugin , "slotObjectUpdated(int,const UpdateType&)" ) ){
973
      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
974 975
      
      log(LOGERR,tr("Plugin uses deprecated and(!) new slotObjectUpdated. Only new slotObjectUpdated will be active."));
976
      connect(this,SIGNAL(signalObjectUpdated(int,const UpdateType&)),plugin,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::DirectConnection);
Jan Möbius's avatar
Jan Möbius committed
977 978
    
    } else {
Jan Möbius's avatar
 
Jan Möbius committed
979

Jan Möbius's avatar
Jan Möbius committed
980
      if ( checkSlot( plugin , "slotObjectUpdated(int)" ) ){
981
        warnings += tr("Warning: Plugin uses deprecated slotObjectUpdated.") + "\n";
Jan Möbius's avatar
Jan Möbius committed
982 983
        log(LOGWARN,tr("Plugin uses deprecated slotObjectUpdated."));
        connect(this,SIGNAL(signalObjectUpdated(int)),plugin,SLOT(slotObjectUpdated(int)), Qt::DirectConnection);
984
      }
985

986 987
      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
988 989 990
    }

    if ( checkSignal(plugin,"objectPropertiesChanged(int)")) {
991 992 993
      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
994 995 996 997
    }
    
    if ( checkSlot( plugin , "slotViewChanged()" ) )
      connect(this,SIGNAL(pluginViewChanged()),plugin,SLOT(slotViewChanged()), Qt::DirectConnection);
998

999 1000 1001
    if ( checkSlot( plugin , "slotSceneDrawn()" ) )
      connect(this,SIGNAL(pluginSceneDrawn()),plugin,SLOT(slotSceneDrawn()), Qt::DirectConnection);

1002 1003 1004
    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
1005 1006
    if ( checkSlot(plugin,"slotObjectPropertiesChanged(int)"))
      connect(this,SIGNAL(objectPropertiesChanged(int)),plugin,SLOT(slotObjectPropertiesChanged(int)), Qt::DirectConnection);
1007

1008 1009 1010
    if ( checkSignal(plugin,"visibilityChanged()" ) ) {
      errors += tr("Error: Signal visibilityChanged() now requires objectid or -1 as argument.") + "\n";
    }
Jan Möbius's avatar
 
Jan Möbius committed
1011

Jan Möbius's avatar
Jan Möbius committed
1012
    if ( checkSignal(plugin,"visibilityChanged(int)") ) {
1013 1014 1015
      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
1016 1017 1018 1019 1020
    }
    
    if ( checkSignal(plugin,"nodeVisibilityChanged(int)") )
      connect(plugin,SIGNAL(nodeVisibilityChanged(int)),this,SLOT(slotVisibilityChanged(int)), Qt::DirectConnection);
    
1021

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

1025 1026 1027
    if ( checkSignal(plugin,"activeObjectChanged()" ) ) {
      errors += tr("Error: Signal activeObjectChanged() is now objectSelectionChanged( int _objectId )") + "\n";
    }
1028

1029 1030 1031
    if ( checkSlot(plugin,"slotActiveObjectChanged()" ) ) {
      errors += tr("Error: Slot slotActiveObjectChanged() is now slotObjectSelectionChanged( int _objectId ) ") + "\n";
    }
Jan Möbius's avatar
 
Jan Möbius committed
1032

Jan Möbius's avatar
Jan Möbius committed
1033 1034
    if ( checkSlot(plugin,"slotAllCleared()") )
      connect(this,SIGNAL(allCleared()),plugin,SLOT(slotAllCleared()));
Jan Möbius's avatar
 
Jan Möbius committed
1035

1036

Jan Möbius's avatar
Jan Möbius committed
1037
    if ( checkSignal(plugin,"objectSelectionChanged(int)") ) {
1038 1039
      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";
Jan Möbius's avatar
 
Jan Möbius committed
1040 1041
    }

Jan Möbius's avatar
Jan Möbius committed
1042 1043
    if ( checkSlot( plugin , "slotObjectSelectionChanged(int)" ) )
      connect(this,SIGNAL(objectSelectionChanged(int)),plugin,SLOT(slotObjectSelectionChanged(int) ), Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
1044 1045


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

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

Jan Möbius's avatar
Jan Möbius committed
1053
    // =============================================
1054
    // Function allowing switching of renderers from other plugins
Jan Möbius's avatar
Jan Möbius committed
1055
    // =============================================
1056 1057 1058 1059
    if ( checkSignal(plugin,"setRenderer(unsigned int,QString)" ) ) {
      connect(plugin,SIGNAL(setRenderer(unsigned int,QString)),this,SLOT(slotSetRenderer(unsigned int,QString)));
    }

Jan Möbius's avatar
Jan Möbius committed
1060 1061 1062 1063 1064
    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
1065
  }
Jan Möbius's avatar
 
Jan Möbius committed
1066

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

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

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

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

Jan Möbius's avatar
Jan Möbius committed
1085 1086
    // 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
1087

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

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

    if ( checkSignal(plugin,"addMenubarAction(QAction*,QString)") )
      connect(plugin      , SIGNAL(addMenubarAction(QAction*,QString)),
              coreWidget_ , SLOT(slotAddMenubarAction(QAction*,QString)),Qt::DirectConnection);
1101 1102 1103
    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
1104 1105 1106 1107
    if ( checkSignal(plugin,"getMenubarMenu (QString,QMenu*&,bool)") )
      connect(plugin      , SIGNAL(getMenubarMenu (QString,QMenu*&,bool)),
              coreWidget_ , SLOT(slotGetMenubarMenu (QString,QMenu*&,bool)),Qt::DirectConnection);
  }
Jan Möbius's avatar
 
Jan Möbius committed
1108

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

Jan Möbius's avatar
Jan Möbius committed
1114 1115 1116
    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
1117

Jan Möbius's avatar
Jan Möbius committed
1118 1119 1120
    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
1121

Marcel Campen's avatar
Marcel Campen committed
1122 1123 1124 1125
    if ( checkSignal(plugin,"hideContextMenu()") )
          connect(plugin      , SIGNAL(hideContextMenu()),
                  coreWidget_ , SLOT(slotHideContextMenu()),Qt::DirectConnection);

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

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

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

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

Dirk Wilden's avatar
Dirk Wilden committed
1144

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

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

    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
1157 1158 1159 1160
  
  //Check if the plugin supports ViewMode-Interface
  ViewModeInterface* viewModePlugin = qobject_cast< ViewModeInterface * >(plugin);
  if ( viewModePlugin && OpenFlipper::Options::gui() ) {
1161
    supported = supported + "ViewMode ";
Jan Möbius's avatar
Jan Möbius committed
1162 1163 1164 1165 1166 1167 1168
    
    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
Marlin:  
Jan Möbius committed
1169 1170 1171 1172 1173
              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
1174 1175 1176
              
    if ( checkSignal(plugin, "defineViewModeIcon(QString,QString)"))
      connect(plugin, SIGNAL( defineViewModeIcon(QString, QString) ),
1177 1178 1179 1180 1181 1182
              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
1183 1184 1185 1186

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

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

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

Jan Möbius's avatar
Jan Möbius committed
1199 1200 1201
  //Check if the plugin supports Toolbar-Interface
  ToolbarInterface* toolbarPlugin = qobject_cast< ToolbarInterface * >