PluginLoader.cc 108 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
66
67
68




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


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

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

#include <QMenuBar>
#include <QToolBox>
#include <QMessageBox>
#include <QApplication>
Jan Möbius's avatar
Jan Möbius committed
69
#include <QScrollArea>
70
71
72
73
#include <QMessageBox>
#include <QtScript/QScriptValueIterator>
#include <QThread>
#include <QMutexLocker>
Jan Möbius's avatar
 
Jan Möbius committed
74
75
76

#include <QPluginLoader>
#include "OpenFlipper/BasePlugin/BaseInterface.hh"
Jan Möbius's avatar
Jan Möbius committed
77
#include "OpenFlipper/BasePlugin/AboutInfoInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
78
79
80
81
82
83
#include "OpenFlipper/BasePlugin/KeyInterface.hh"
#include "OpenFlipper/BasePlugin/BackupInterface.hh"
#include "OpenFlipper/BasePlugin/LoggingInterface.hh"
#include "OpenFlipper/BasePlugin/MouseInterface.hh"
#include "OpenFlipper/BasePlugin/PickingInterface.hh"
#include "OpenFlipper/BasePlugin/ToolboxInterface.hh"
Dirk Wilden's avatar
Dirk Wilden committed
84
#include "OpenFlipper/BasePlugin/OptionsInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
85
86
#include "OpenFlipper/BasePlugin/ToolbarInterface.hh"
#include "OpenFlipper/BasePlugin/TextureInterface.hh"
Jan Möbius's avatar
Jan Möbius committed
87
#include "OpenFlipper/BasePlugin/RenderInterface.hh"
88
#include "OpenFlipper/BasePlugin/PostProcessorInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
89
90
#include "OpenFlipper/BasePlugin/MenuInterface.hh"
#include "OpenFlipper/BasePlugin/ContextMenuInterface.hh"
91
#include "OpenFlipper/BasePlugin/ProcessInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
92
#include "OpenFlipper/BasePlugin/ViewInterface.hh"
Jan Möbius's avatar
Jan Möbius committed
93
#include "OpenFlipper/BasePlugin/ViewModeInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
94
95
96
97
98
99
#include "OpenFlipper/BasePlugin/LoadSaveInterface.hh"
#include "OpenFlipper/BasePlugin/StatusbarInterface.hh"
#include "OpenFlipper/BasePlugin/INIInterface.hh"
#include "OpenFlipper/BasePlugin/FileInterface.hh"
#include "OpenFlipper/BasePlugin/RPCInterface.hh"
#include "OpenFlipper/BasePlugin/ScriptInterface.hh"
100
#include "OpenFlipper/BasePlugin/SecurityInterface.hh"
101
#include "OpenFlipper/BasePlugin/SelectionInterface.hh"
102
#include "OpenFlipper/BasePlugin/TypeInterface.hh"
103
#include "OpenFlipper/BasePlugin/PluginConnectionInterface.hh"
104
#include "OpenFlipper/BasePlugin/MetadataInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
105

106
#include "OpenFlipper/common/RendererInfo.hh"
107

Jan Möbius's avatar
 
Jan Möbius committed
108
109
110
111
112
113
#include "OpenFlipper/INIFile/INIFile.hh"

#include "OpenFlipper/common/GlobalOptions.hh"


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

116
117
118
119
120
#include <deque>
#include <limits>

/**
 * The number of plugins to load simultaneously.
121

122
 */
123
static const int PRELOAD_THREADS_COUNT = (QThread::idealThreadCount() != -1) ? QThread::idealThreadCount() : 8;
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

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
194
195
196
197
198
199
200
class PreloadThread : public QThread
{
  public: 
    
    /** \brief Preload thread constructor
    *
    * This constructor initializes the preloading thread.
Jan Möbius's avatar
Jan Möbius committed
201
202
    *
    * @param aggregator aggregator managing the different threads
Jan Möbius's avatar
Jan Möbius committed
203
    */
204
    PreloadThread(PreloadAggregator *aggregator) : aggregator_(aggregator) {
Jan Möbius's avatar
Jan Möbius committed
205
206
207
208
    }
  
  public:
    
209
210
211
212
213
214
    void addFilename(const QString &filename) {
        QMutexLocker filenamesLock(&filenamesMutex_);
        filenames_.push_back(filename);
        aggregator_->expectLoaders(1);
    }

Jan Möbius's avatar
Jan Möbius committed
215
216
217
218
219
    /** \brief preload function
    *
    * This function is used in the thread to preload a plugin. The name is given in the constructor.
    */
    void run() {
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
      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
239
240
241
    }
    
  private:
242
243
244
    std::deque<QString> filenames_;
    QMutex filenamesMutex_;
    PreloadAggregator *aggregator_;
Jan Möbius's avatar
Jan Möbius committed
245
246
};

247
248
249
250
251
252
253
254
255
256
/**
 * @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:
257
        size_t getTypeOrdinal(const QString &name) const {
258
259
260
261
262
263
264
265
266
267
268
269
            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 {
270
271
            const size_t typeA = getTypeOrdinal(a);
            const size_t typeB = getTypeOrdinal(b);
272
273
274
275
276
277
278
279
            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
280

Jan Möbius's avatar
 
Jan Möbius committed
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//== 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
300
  
301
302
303
  //regsiter custom datatypes for signal/slots
  registerTypes();

Jan Möbius's avatar
Jan Möbius committed
304
305
  QString licenseTexts = "";
  
Dirk Wilden's avatar
Dirk Wilden committed
306
  //try to load plugins from new location
307
  QDir tempDir = QDir(OpenFlipper::Options::pluginDir());
Dirk Wilden's avatar
Dirk Wilden committed
308

309
  // Possible Plugin extensions
Jan Möbius's avatar
Jan Möbius committed
310
311
312
  // Windows gets DLLs
  // Mac and Linux use so
  // We don't use the dylib extension on Mac at the moment.
313
314
315
  QStringList filter;
  if ( OpenFlipper::Options::isWindows() )
    filter << "*.dll";
Jan Möbius's avatar
Jan Möbius committed
316
  else 
317
318
    filter << "*.so";
  
Jan Möbius's avatar
 
Jan Möbius committed
319
  // Get all files in the Plugin dir
320
  QStringList pluginlist = tempDir.entryList(filter,QDir::Files);
Dirk Wilden's avatar
Dirk Wilden committed
321

322
323
  // Convert local file path to absolute path
  for (int i=0; i < pluginlist.size(); i++) {
324
     pluginlist[i] = tempDir.absoluteFilePath(pluginlist[i]);
Jan Möbius's avatar
 
Jan Möbius committed
325
326
  }

327
  // get all Plugin Names which will not be loaded
328
  QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames", QStringList()).toStringList();
329
330
331
332
333
334
  
  // 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 
335
  QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins", QStringList()).toStringList();
336
337
  
  // Output info about additional plugins
Jan Möbius's avatar
Jan Möbius committed
338
  for ( int i = 0 ; i < additionalPlugins.size(); ++i) {
339
    emit log(LOGOUT,tr("Additional Plugin from file: %1").arg( additionalPlugins[i] ) );
Jan Möbius's avatar
Jan Möbius committed
340
  }
341
342
343
  
  // Prepend the additional Plugins to the plugin list
  pluginlist = additionalPlugins << pluginlist;
344
345
346
347
348

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

351
352
  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
353

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

Jan Möbius's avatar
Jan Möbius committed
356
357
358
359
  QTime time;
  
  time.start();
  
360
361
362
363
364
365
366
367
368
369
  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
370
  
371
372
373
374
  /*
   * 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
375
  for ( int i = 0 ; i < pluginlist.size() ; ++i) {
376
377
378
379
380
381
382
383
384
    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
385
386
  }
  
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
  /*
   * 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);

      if ( OpenFlipper::Options::gui() && OpenFlipperSettings().value("Core/Gui/splash",true).toBool() ) {
        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
402
403
  }

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
  /*
   * 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) {

      if ( OpenFlipper::Options::gui() && OpenFlipperSettings().value("Core/Gui/splash",true).toBool() ) {
        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;
  }

  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
441
  splashMessage_ = "";
Jan Möbius's avatar
Jan Möbius committed
442
443
  
  if ( licenseTexts != "" ) {
Jan Möbius's avatar
Jan Möbius committed
444
445
446
447
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
    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();
          }
490
           
Jan Möbius's avatar
Jan Möbius committed
491
        }
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508

        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
509
510
511
512
513
514
        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);
515
516
517
518
519
520

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

525
        if ( userAnswer == 1 ) {
526
527
528
529
530
531
532
           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
533

534
535
536
           QUrl encodedURL(url, QUrl::TolerantMode);
           QDesktopServices::openUrl(encodedURL);
        }
Jan Möbius's avatar
Jan Möbius committed
537
538
539
540
541
542
        
      }

      
    } else {
      emit log(LOGWARN,tr("Plugin License check failed: "));
Jan Möbius's avatar
Jan Möbius committed
543
544
545
      std::cerr << licenseTexts.toStdString() << std::endl;
    }
  } 
Jan Möbius's avatar
 
Jan Möbius committed
546
547
548

  emit pluginsInitialized();

549
  emit log(LOGOUT,tr("Loaded %n Plugin(s)","",int(plugins_.size())) );
Jan Möbius's avatar
 
Jan Möbius committed
550
551
552
553
554
555
556
557
558
}

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

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

559
  // Setup filters for possible plugin extensions
Jan Möbius's avatar
Jan Möbius committed
560
561
562
  // 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
563
  QString filter;
Jan Möbius's avatar
 
Jan Möbius committed
564
565
  if ( OpenFlipper::Options::isWindows() )
    filter = "Plugins (*.dll)";
Jan Möbius's avatar
Jan Möbius committed
566
  else 
Jan Möbius's avatar
 
Jan Möbius committed
567
568
    filter = "Plugins (*.so)";

569
  // Ask the user to select the file to load
570
  QString filename = ACG::getOpenFileName(coreWidget_,tr("Load Plugin"),filter, OpenFlipperSettings().value("Core/CurrentDir").toString() );
Jan Möbius's avatar
 
Jan Möbius committed
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591

  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;

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

Dirk Wilden's avatar
Dirk Wilden committed
637
/** @brief slot for showing loaded Plugins
Jan Möbius's avatar
 
Jan Möbius committed
638
 */
Dirk Wilden's avatar
Dirk Wilden committed
639
void Core::slotShowPlugins(){
Jan Möbius's avatar
 
Jan Möbius committed
640

Dirk Wilden's avatar
Dirk Wilden committed
641
642
643
644
645
646
  if ( OpenFlipper::Options::gui() ){

    int ret = 0;

    while (ret == 0){

Jan Möbius's avatar
Jan Möbius committed
647
      PluginDialog* dialog = new PluginDialog(plugins_, coreWidget_);
Jan Möbius's avatar
 
Jan Möbius committed
648

Dirk Wilden's avatar
Dirk Wilden committed
649
650
      //connect signals
      connect(dialog, SIGNAL( loadPlugin() ), this, SLOT( slotLoadPlugin() ));
651
652
653
654
      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
655
656
657
658
659
660
661

      //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
662
663
}

664
665
666
667
668
669
670
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
671

672
673
674
675
  for (size_t i = 0; i < plugins_.size();++i)
    if (plugins_[i].name == _name)
      plugins_[i].status = PluginInfo::BLOCKED;
}
Jan Möbius's avatar
 
Jan Möbius committed
676

677
678
679
680
681
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
682

683
684
685
  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
686
687
688
}

/** @brief Load a Plugin with given filename
Matthias Möller's avatar
doc fix    
Matthias Möller committed
689
690
 *  @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
691
 *  @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
692
 *  @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
693
 */
694
void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _licenseErrors, QObject* _plugin){
Jan Möbius's avatar
 
Jan Möbius committed
695

Jan Möbius's avatar
Jan Möbius committed
696
697
  _licenseErrors = "";
  
Jan Möbius's avatar
 
Jan Möbius committed
698
699
  // Only load .dll under windows
  if ( OpenFlipper::Options::isWindows() ) {
700
    QString dllname = _filename;
701
    if ( ! dllname.endsWith( ".dll" ) )
Jan Möbius's avatar
 
Jan Möbius committed
702
703
704
705
      return;
  }
  // Only load .so under linux
  if ( OpenFlipper::Options::isLinux() ) {
706
    QString soname = _filename;
707
    if ( ! soname.endsWith( ".so" ) )
Jan Möbius's avatar
 
Jan Möbius committed
708
709
710
      return;
  }

Jan Möbius's avatar
Jan Möbius committed
711
712
  // This will be the reference to our plugin
  QObject *plugin = 0;
Jan Möbius's avatar
 
Jan Möbius committed
713

Jan Möbius's avatar
Jan Möbius committed
714
715
716
  // Try to open the file if we did not get a plugin,
  // Otherwise use the supplied plugin pointer
  if ( _plugin == 0 ) {
717
    QPluginLoader loader( _filename );
Jan Möbius's avatar
Jan Möbius committed
718
719
720
    plugin = loader.instance();  
    
    if ( !plugin) {
721
      emit log(LOGERR,tr("Unable to load Plugin :\t %1").arg( _filename ) );
Jan Möbius's avatar
Jan Möbius committed
722
723
724
      emit log(LOGERR,tr("Error was : ") + loader.errorString() );
      emit log(LOGOUT,"================================================================================");       
    }
725
    emit log (LOGOUT,tr("Plugin loaded: \t %1").arg(_filename));
Jan Möbius's avatar
Jan Möbius committed
726
727
728
729
730
    
  } else {
      plugin = _plugin;
  }
  
Jan Möbius's avatar
 
Jan Möbius committed
731
  // Check if a plugin has been loaded
Matthias Möller's avatar
Matthias Möller committed
732
733
  PluginInfo info;
  int alreadyLoadedAt = -1;
734
  for (unsigned int k=0; k < plugins_.size(); k++)
735
736
  {
    if (plugins_[k].path == _filename)
Matthias Möller's avatar
Matthias Möller committed
737
      alreadyLoadedAt = static_cast<int>(k);
738
  }
Matthias Möller's avatar
Matthias Möller committed
739
740
  info.status = PluginInfo::FAILED;
  info.path = _filename;
Jan Möbius's avatar
Jan Möbius committed
741
  QString supported;
Jan Möbius's avatar
 
Jan Möbius committed
742

743
  emit log(LOGOUT,tr("Location : \t %1").arg( _filename) );
Jan Möbius's avatar
Jan Möbius committed
744
745
746
747
  
  // Check if it is a BasePlugin
  BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugin);
  if ( basePlugin ) {
748
749

    //set basic information about plugin
Matthias Möller's avatar
Matthias Möller committed
750
751
752
    info.name = basePlugin->name();
    info.rpcName = info.name.remove(" ").toLower();
    info.description = basePlugin->description();
753
754

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

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

Jan Möbius's avatar
Jan Möbius committed
759
760
761
762
    if ( OpenFlipper::Options::gui() && OpenFlipperSettings().value("Core/Gui/splash",true).toBool() ) {
      splashMessage_ = splashMessage_ + " " + basePlugin->name() ;
      splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
    }
Jan Möbius's avatar
 
Jan Möbius committed
763

Jan Möbius's avatar
Jan Möbius committed
764
    //Check if plugin is already loaded
765
    for (unsigned int k=0; k < plugins_.size(); k++){
Jan Möbius's avatar
Jan Möbius committed
766
767
768
769

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

770
771
        if (plugins_[k].name == name_nospace && plugins_[k].path != _filename && plugins_[k].status == PluginInfo::LOADED){
          if (_silent || OpenFlipper::Options::nogui() ){ //dont load the plugin
Jan Möbius's avatar
Jan Möbius committed
772
            emit log(LOGWARN, tr("\t\t\t Already loaded from %1").arg( plugins_[k].path) );
Jan Möbius's avatar
Jan Möbius committed
773
            emit log(LOGOUT,"================================================================================");
Matthias Möller's avatar
Matthias Möller committed
774
            info.description = basePlugin->description() + tr(" *Already loaded.*");
Jan Möbius's avatar
Jan Möbius committed
775
776
777
778
779
780
            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"
Jan Möbius's avatar
Jan Möbius committed
781
                                              "Do you want to unload the existing plugin first?").arg( plugins_[k].path),
Jan Möbius's avatar
Jan Möbius committed
782
                                          QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
783
784
          if (ret == QMessageBox::No)
          {
Jan Möbius's avatar
Jan Möbius committed
785
            emit log(LOGWARN, tr("\t\t\t Already loaded from %1.").arg( plugins_[k].path));
Jan Möbius's avatar
Jan Möbius committed
786
            emit log(LOGOUT,"================================================================================");
Matthias Möller's avatar
Matthias Möller committed
787
            info.description = basePlugin->description() + tr(" *Already loaded.*");
Jan Möbius's avatar
Jan Möbius committed
788
            return;
Jan Möbius's avatar
 
Jan Möbius committed
789
790
          }
        }
Dirk Wilden's avatar
Dirk Wilden committed
791
      }
Jan Möbius's avatar
Jan Möbius committed
792
    }
Jan Möbius's avatar
 
Jan Möbius committed
793

794
    QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames",QStringList()).toStringList();
795

Jan Möbius's avatar
Jan Möbius committed
796
797
798
    if ( dontLoadPlugins.contains(basePlugin->name(), Qt::CaseInsensitive) ) {
      emit log(LOGWARN,tr("OpenFlipper.ini prevented Plugin %1 from being loaded! ").arg( basePlugin->name() ));
      emit log(LOGOUT,"================================================================================");
Matthias Möller's avatar
Matthias Möller committed
799
      info.status = PluginInfo::BLOCKED;
Jan Möbius's avatar
Jan Möbius committed
800
801
      return;
    }
Jan Möbius's avatar
 
Jan Möbius committed
802

Jan Möbius's avatar
Jan Möbius committed
803
804
805
806
    //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 ..."));
807

Jan Möbius's avatar
Jan Möbius committed
808
      bool success = false;
809
810
811
812
813
      QMetaObject::invokeMethod(plugin,"authenticate", Q_RETURN_ARG( bool , success ) ) ;
      
      QString message = "";
      QMetaObject::invokeMethod(plugin,"licenseError", Q_RETURN_ARG( QString , message ) ) ;
      _licenseErrors = message;
814

Jan Möbius's avatar
Jan Möbius committed
815
816
817
818
819
      if ( success )
        emit log(LOGINFO,tr("... ok. Loading plugin "));
      else {
        emit log(LOGERR,tr("... failed. Plugin access denied."));
        emit log(LOGOUT,"================================================================================");
Matthias Möller's avatar
Matthias Möller committed
820
        info.description = basePlugin->description() + tr(" *Plugin access denied.*");
Jan Möbius's avatar
Jan Möbius committed
821
        // Abort here, as the plugin will not do anything else until correct authentication.
Jan Möbius's avatar
Jan Möbius committed
822
        return;
823
      }
Jan Möbius's avatar
Jan Möbius committed
824
    }
825
826


Jan Möbius's avatar
Jan Möbius committed
827
    emit log(LOGOUT,tr("Plugin Desciption :\t %1 ").arg( basePlugin->description()) );
828

829
    supported = "BaseInterface ";
Jan Möbius's avatar
 
Jan Möbius committed
830

Matthias Möller's avatar
Matthias Möller committed
831
    info.plugin        = plugin;
Jan Möbius's avatar
Jan Möbius committed
832
    if ( checkSlot(plugin,"version()") )
Matthias Möller's avatar
Matthias Möller committed
833
      info.version = basePlugin->version();
Jan Möbius's avatar
Jan Möbius committed
834
    else
Matthias Möller's avatar
Matthias Möller committed
835
      info.version = QString::number(-1);
Jan Möbius's avatar
 
Jan Möbius committed
836

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

Jan Möbius's avatar
Jan Möbius committed
839
840
      if ( ! checkSlot( plugin , "noguiSupported()" ) ) {
        emit log(LOGWARN,tr("Running in nogui mode which is unsupported by this plugin, skipping") );
841
        emit log(LOGOUT,"================================================================================");
842
843
844
        return;
      }

Jan Möbius's avatar
Jan Möbius committed
845
    }
846
847


Jan Möbius's avatar
Jan Möbius committed
848
849
850
851
852
853
    // Check for baseInterface of old style!
    if ( checkSignal(plugin,"updated_objects(int)") ) {
      log(LOGERR,tr("Plugin Uses old style updated_objects! Convert to updatedObject!"));
      emit log(LOGOUT,"================================================================================");
      return;
    }
854

Jan Möbius's avatar
Jan Möbius committed
855
856
857
858
859
    if ( checkSignal(plugin,"update_view()") ) {
      log(LOGERR,tr("Plugin Uses old style update_view! Convert to updateView!"));
      emit log(LOGOUT,"================================================================================");
      return;
    }
860

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

864

865
    if ( checkSignal(plugin,"updatedObject(int)") && checkSignal(plugin,"updatedObject(int,const UpdateType&)") ){
Dirk Wilden's avatar
Dirk Wilden committed
866
      
Jan Möbius's avatar
Jan Möbius committed
867
      log(LOGERR,tr("Plugin uses deprecated and(!) new updatedObject. Only new updatedObject will be active."));
868
      connect(plugin,SIGNAL(updatedObject(int,const UpdateType&)),this,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::AutoConnection);
Jan Möbius's avatar
Jan Möbius committed
869
870
      
    } else {
871

Jan Möbius's avatar
Jan Möbius committed
872
873
      if ( checkSignal(plugin,"updatedObject(int)") ){
        log(LOGWARN,tr("Plugin uses deprecated updatedObject."));
874
        connect(plugin,SIGNAL(updatedObject(int)),this,SLOT(slotObjectUpdated(int)), Qt::AutoConnection);
875
      }
Jan Möbius's avatar
Jan Möbius committed
876

877
      if ( checkSignal(plugin,"updatedObject(int,const UpdateType&)") )
878
        connect(plugin,SIGNAL(updatedObject(int,const UpdateType&)),this,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::AutoConnection);
Jan Möbius's avatar
Jan Möbius committed
879
    }
Jan Möbius's avatar
Jan Möbius committed
880

881
    if ( checkSlot( plugin , "slotObjectUpdated(int)" ) && checkSlot( plugin , "slotObjectUpdated(int,const UpdateType&)" ) ){
Jan Möbius's avatar
Jan Möbius committed
882
883
      
      log(LOGERR,tr("Plugin uses deprecated and(!) new slotObjectUpdated. Only new slotObjectUpdated will be active."));
884
      connect(this,SIGNAL(signalObjectUpdated(int,const UpdateType&)),plugin,SLOT(slotObjectUpdated(int,const UpdateType&)), Qt::DirectConnection);
Jan Möbius's avatar
Jan Möbius committed
885
886
    
    } else {
Jan Möbius's avatar
 
Jan Möbius committed
887

Jan Möbius's avatar
Jan Möbius committed
888
889
890
      if ( checkSlot( plugin , "slotObjectUpdated(int)" ) ){
        log(LOGWARN,tr("Plugin uses deprecated slotObjectUpdated."));
        connect(this,SIGNAL(signalObjectUpdated(int)),plugin,SLOT(slotObjectUpdated(int)), Qt::DirectConnection);
891
      }
892

893
894
      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
895
896
897
898
899
900
901
902
903
904
    }

    if ( checkSignal(plugin,"objectPropertiesChanged(int)")) {
      emit log (LOGERR,tr("Signal objectPropertiesChanged(int) is deprecated. " ));
      emit log (LOGERR,tr("The signal will be automatically emitted by the object that has been changed and the core will deliver it to the plugins!. "));
      emit log (LOGERR,tr("Please remove this signal from your plugins!. "));
    }
    
    if ( checkSlot( plugin , "slotViewChanged()" ) )
      connect(this,SIGNAL(pluginViewChanged()),plugin,SLOT(slotViewChanged()), Qt::DirectConnection);
905

906
907
908
    if ( checkSlot( plugin , "slotSceneDrawn()" ) )
      connect(this,SIGNAL(pluginSceneDrawn()),plugin,SLOT(slotSceneDrawn()), Qt::DirectConnection);

909
910
911
    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
912
913
    if ( checkSlot(plugin,"slotObjectPropertiesChanged(int)"))
      connect(this,SIGNAL(objectPropertiesChanged(int)),plugin,SLOT(slotObjectPropertiesChanged(int)), Qt::DirectConnection);
914

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

Jan Möbius's avatar
Jan Möbius committed
918
919
920
921
922
923
924
925
926
    if ( checkSignal(plugin,"visibilityChanged(int)") ) {
      emit log (LOGERR,tr("Signal visibilityChanged(int) is deprecated! " ));
      emit log (LOGERR,tr("If an object changes its visibility, it will call the required functions automatically." ));
      emit log (LOGERR,tr("If you change a scenegraph node, call nodeVisibilityChanged(int). See docu of this function for details." ));
    }
    
    if ( checkSignal(plugin,"nodeVisibilityChanged(int)") )
      connect(plugin,SIGNAL(nodeVisibilityChanged(int)),this,SLOT(slotVisibilityChanged(int)), Qt::DirectConnection);
    
927

Jan Möbius's avatar
Jan Möbius committed
928
929
    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
930

Jan Möbius's avatar
Jan Möbius committed
931
932
    if ( checkSignal(plugin,"activeObjectChanged()" ) )
      emit log (LOGERR,tr("Signal activeObjectChanged() is now objectSelectionChanged( int _objectId ) ") );
933

Jan Möbius's avatar
Jan Möbius committed
934
935
    if ( checkSlot(plugin,"slotActiveObjectChanged()" ) )
      emit log (LOGERR,tr("Slot slotActiveObjectChanged() is now slotObjectSelectionChanged( int _objectId ) ") );
Jan Möbius's avatar
 
Jan Möbius committed
936

Jan Möbius's avatar
Jan Möbius committed
937
938
    if ( checkSlot(plugin,"slotAllCleared()") )
      connect(this,SIGNAL(allCleared()),plugin,SLOT(slotAllCleared()));
Jan Möbius's avatar
 
Jan Möbius committed
939

940

Jan Möbius's avatar
Jan Möbius committed
941
942
943
    if ( checkSignal(plugin,"objectSelectionChanged(int)") ) {
      emit log (LOGERR,tr("Signal objectSelectionChanged(in) is deprecated!") );
      emit log (LOGERR,tr("If the selection for an object is changed, the core will emit the required signals itself!") );
Jan Möbius's avatar
 
Jan Möbius committed
944
945
    }

Jan Möbius's avatar
Jan Möbius committed
946
947
    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
948
949


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

Jan Möbius's avatar
Jan Möbius committed
953
954
955
    if ( checkSignal(plugin,"setSlotDescription(QString,QString,QStringList,QStringList)") )
      connect(plugin, SIGNAL(setSlotDescription(QString,QString,QStringList,QStringList)),
              this,   SLOT(slotSetSlotDescription(QString,QString,QStringList,QStringList)) );
956

Jan Möbius's avatar
Jan Möbius committed
957
    // =============================================
958
    // Function allowing switching of renderers from other plugins
Jan Möbius's avatar
Jan Möbius committed
959
    // =============================================
960
961
962
963
    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
964
965
966
967
968
    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
969
  }
Jan Möbius's avatar
 
Jan Möbius committed
970

Jan Möbius's avatar
Jan Möbius committed
971
972
973
  //Check if the plugin supports Logging
  LoggingInterface* logPlugin = qobject_cast< LoggingInterface * >(plugin);
  if ( logPlugin ) {
974
    supported = supported + "Logging ";
Dirk Wilden's avatar
Dirk Wilden committed
975

Jan Möbius's avatar
Jan Möbius committed
976
    // Create intermediate logger class which will mangle the output
Matthias Möller's avatar
Matthias Möller committed
977
    PluginLogger* newlog = new PluginLogger(info.name);
Jan Möbius's avatar
Jan Möbius committed
978
979
980
    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
981

Jan Möbius's avatar
Jan Möbius committed
982
983
984
    // 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
985

Jan Möbius's avatar
Jan Möbius committed
986
987
    // 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
988

Jan Möbius's avatar
Jan Möbius committed
989
990
    // 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
991

Jan Möbius's avatar
Jan Möbius committed
992
993
994
995
    // 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
996

Jan Möbius's avatar
Jan Möbius committed
997
998
999
  //Check if the plugin supports Menubar-Interface
  MenuInterface* menubarPlugin = qobject_cast< MenuInterface * >(plugin);
  if ( menubarPlugin && OpenFlipper::Options::gui() ) {
1000
    supported = supported + "Menubar ";
Jan Möbius's avatar
Jan Möbius committed
1001
1002
1003
1004

    if ( checkSignal(plugin,"addMenubarAction(QAction*,QString)") )
      connect(plugin      , SIGNAL(addMenubarAction(QAction*,QString)),
              coreWidget_ , SLOT(slotAddMenubarAction(QAction*,QString)),Qt::DirectConnection);
1005
1006
1007
    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
1008
1009
1010
1011
    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
1012

Jan Möbius's avatar
Jan Möbius committed
1013
1014
1015
  //Check if the plugin supports ContextMenuInterface
  ContextMenuInterface* contextMenuPlugin = qobject_cast< ContextMenuInterface * >(plugin);
  if ( contextMenuPlugin && OpenFlipper::Options::gui() ) {
1016
    supported = supported + "ContextMenu ";
1017

Jan Möbius's avatar
Jan Möbius committed
1018
1019
1020
    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
1021

Jan Möbius's avatar
Jan Möbius committed
1022
1023
1024
    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
1025

Marcel Campen's avatar
Marcel Campen committed
1026
1027
1028
1029
    if ( checkSignal(plugin,"hideContextMenu()") )
          connect(plugin      , SIGNAL(hideContextMenu()),
                  coreWidget_ , SLOT(slotHideContextMenu()),Qt::DirectConnection);

Jan Möbius's avatar
Jan Möbius committed
1030
1031
1032
    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
1033

Jan Möbius's avatar
Jan Möbius committed
1034
1035
1036
    if ( checkSlot(plugin,"slotUpdateContextMenuNode(int)") )
      connect(coreWidget_ , SIGNAL(updateContextMenuNode(int)),
              plugin      , SLOT(slotUpdateContextMenuNode(int)),Qt::DirectConnection);
1037

Jan Möbius's avatar
Jan Möbius committed
1038
1039
1040
1041
    if ( checkSlot(plugin,"slotUpdateContextMenuBackground()") )
      connect(coreWidget_ , SIGNAL(updateContextMenuBackground()),
              plugin      , SLOT(slotUpdateContextMenuBackground()),Qt::DirectConnection);
  }
1042

Jan Möbius's avatar
Jan Möbius committed
1043
1044
1045
  //Check if the plugin supports Toolbox-Interface
  ToolboxInterface* toolboxPlugin = qobject_cast< ToolboxInterface * >(plugin);
  if ( toolboxPlugin && OpenFlipper::Options::gui() ) {
1046
    supported = supported + "Toolbox ";
1047

Dirk Wilden's avatar
Dirk Wilden committed
1048

Jan Möbius's avatar
Jan Möbius committed
1049
1050
1051
    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
1052

Dirk Wilden's avatar
Dirk Wilden committed
1053
1054
1055
    if ( checkSignal(plugin, "addToolbox(QString,QWidget*,QIcon*)"))
      connect(plugin, SIGNAL( addToolbox(QString,QWidget*,QIcon*) ),
              this, SLOT( addToolbox(QString,QWidget*,QIcon*) ),Qt::DirectConnection );
Jan Möbius's avatar
Jan Möbius committed
1056
1057
1058
1059
1060
  }
  
  //Check if the plugin supports ViewMode-Interface
  ViewModeInterface* viewModePlugin = qobject_cast< ViewModeInterface * >(plugin);
  if ( viewModePlugin && OpenFlipper::Options::gui() ) {
1061
    supported = supported + "ViewMode ";
Jan Möbius's avatar
Jan Möbius committed
1062
1063
1064
1065
1066
1067
1068
    
    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
1069
1070
1071
1072
1073
              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
1074
1075
1076
              
    if ( checkSignal(plugin, "defineViewModeIcon(QString,QString)"))
      connect(plugin, SIGNAL( defineViewModeIcon(QString, QString) ),
1077
1078
1079
1080
1081
1082
              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
1083
1084
1085
1086

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

    QWidget* widget = 0;
    if ( optionsPlugin->initializeOptionsWidget( widget ) ) {
Matthias Möller's avatar
Matthias Möller committed
1091
          info.optionsWidget = widget;
Jan Möbius's avatar
Jan Möbius committed
1092
1093
1094
1095

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

Jan Möbius's avatar
Jan Möbius committed
1099
1100
1101
  //Check if the plugin supports Toolbar-Interface
  ToolbarInterface* toolbarPlugin = qobject_cast< ToolbarInterface * >(plugin);
  if ( toolbarPlugin && OpenFlipper::Options::gui() ) {
1102
    supported = supported + "Toolbars ";
Jan Möbius's avatar
 
Jan Möbius committed
1103

Jan Möbius's avatar
Jan Möbius committed
1104
1105
1106
    if ( checkSignal(plugin,"addToolbar(QToolBar*)") )
      connect(plugin,SIGNAL(addToolbar(QToolBar*)),
              coreWidget_,SLOT(slotAddToolbar(QToolBar*)),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
1107

Jan Möbius's avatar
Jan Möbius committed
1108
1109
1110
    if ( checkSignal(plugin,"removeToolbar(QToolBar*)") )
      connect(plugin,SIGNAL(removeToolbar(QToolBar*)),
              coreWidget_,SLOT(slotRemoveToolbar(QToolBar*)),Qt::DirectConnection);
Jan Möbius's avatar
 
Jan Möbius committed
1111

Jan Möbius's avatar
Jan Möbius committed
1112
1113
1114
1115
1116
    if ( checkSignal(plugin,"getToolBar(QString,QToolBar*&)") )
      connect(plugin,SIGNAL(getToolBar(QString,QToolBar*&)),
              coreWidget_,SLOT(getToolBar(QString,QToolBar*&)),Qt::DirectConnection);
        
  }
Jan Möbius's avatar
 
Jan Möbius committed
1117

Jan Möbius's avatar
Jan Möbius committed
1118
1119
1120
  //Check if the plugin supports StatusBar-Interface
  StatusbarInterface* statusbarPlugin = qobject_cast< StatusbarInterface * >(plugin);
  if ( statusbarPlugin && OpenFlipper::Options::gui() ) {
1121
    supported = supported + "StatusBar ";
Jan Möbius's avatar
 
Jan Möbius committed
1122