/
qgspluginmanager.cpp
1690 lines (1427 loc) · 60.2 KB
/
qgspluginmanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
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
441
442
443
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
qgspluginmanager.cpp - description
-------------------
begin : Someday 2003
copyright : (C) 2003 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <cmath>
#include <QApplication>
#include <QFileDialog>
#include <QLineEdit>
#include <QMessageBox>
#include <QLibrary>
#include <QStandardItem>
#include <QPushButton>
#include <QRegExp>
#include <QSortFilterProxyModel>
#include <QActionGroup>
#include <QTextStream>
#include <QTimer>
#include <QDesktopServices>
#include "qgis.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsconfig.h"
#include "qgsproviderregistry.h"
#include "qgspluginregistry.h"
#include "qgspluginsortfilterproxymodel.h"
#include "qgspythonrunner.h"
#include "qgspluginmanager.h"
#include "qgisplugin.h"
#include "qgslogger.h"
#include "qgspluginitemdelegate.h"
#include "qgssettings.h"
#ifdef WITH_BINDINGS
#include "qgspythonutils.h"
#endif
// Do we need this?
// #define TESTLIB
#ifdef TESTLIB
// This doesn't work on windows and causes problems with plugins
// on OS X (the code doesn't cause a problem but including dlfcn.h
// renders plugins unloadable)
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACX)
#include <dlfcn.h>
#endif
#endif
QgsPluginManager::QgsPluginManager( QWidget *parent, bool pluginsAreEnabled, Qt::WindowFlags fl )
: QgsOptionsDialogBase( QStringLiteral( "PluginManager" ), parent, fl )
{
// initialize pointer
mPythonUtils = nullptr;
setupUi( this );
connect( vwPlugins, &QListView::clicked, this, &QgsPluginManager::vwPlugins_clicked );
connect( vwPlugins, &QListView::doubleClicked, this, &QgsPluginManager::vwPlugins_doubleClicked );
connect( wvDetails, &QgsWebView::linkClicked, this, &QgsPluginManager::wvDetails_linkClicked );
connect( leFilter, &QgsFilterLineEdit::textChanged, this, &QgsPluginManager::leFilter_textChanged );
connect( buttonUpgradeAll, &QPushButton::clicked, this, &QgsPluginManager::buttonUpgradeAll_clicked );
connect( buttonInstall, &QPushButton::clicked, this, &QgsPluginManager::buttonInstall_clicked );
connect( buttonUninstall, &QPushButton::clicked, this, &QgsPluginManager::buttonUninstall_clicked );
connect( treeRepositories, &QTreeWidget::itemSelectionChanged, this, &QgsPluginManager::treeRepositories_itemSelectionChanged );
connect( treeRepositories, &QTreeWidget::doubleClicked, this, &QgsPluginManager::treeRepositories_doubleClicked );
connect( buttonAddRep, &QPushButton::clicked, this, &QgsPluginManager::buttonAddRep_clicked );
connect( buttonEditRep, &QPushButton::clicked, this, &QgsPluginManager::buttonEditRep_clicked );
connect( buttonDeleteRep, &QPushButton::clicked, this, &QgsPluginManager::buttonDeleteRep_clicked );
connect( buttonRefreshRepos, &QPushButton::clicked, this, &QgsPluginManager::buttonRefreshRepos_clicked );
connect( ckbExperimental, &QgsCollapsibleGroupBox::toggled, this, &QgsPluginManager::ckbExperimental_toggled );
connect( ckbDeprecated, &QgsCollapsibleGroupBox::toggled, this, &QgsPluginManager::ckbDeprecated_toggled );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsPluginManager::showHelp );
// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( true );
// Don't let QgsOptionsDialogBase to narrow the vertical tab list widget
mOptListWidget->setMaximumWidth( 16777215 );
// load translated description strings from qgspluginmanager_texts
initTabDescriptions();
// set internal variable
mPluginsAreEnabled = pluginsAreEnabled;
// Init models
mModelPlugins = new QStandardItemModel( 0, 1 );
mModelProxy = new QgsPluginSortFilterProxyModel( this );
mModelProxy->setSourceModel( mModelPlugins );
mModelProxy->setSortCaseSensitivity( Qt::CaseInsensitive );
mModelProxy->setSortRole( Qt::DisplayRole );
mModelProxy->setDynamicSortFilter( true );
mModelProxy->sort( 0, Qt::AscendingOrder );
vwPlugins->setModel( mModelProxy );
vwPlugins->setItemDelegate( new QgsPluginItemDelegate( vwPlugins ) );
vwPlugins->setFocus();
// Preset widgets
leFilter->setFocus( Qt::MouseFocusReason );
leFilter->setShowSearchIcon( true );
leFilter->setPlaceholderText( tr( "Search…" ) );
wvDetails->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
// Connect other signals
connect( mOptionsListWidget, &QListWidget::currentRowChanged, this, &QgsPluginManager::setCurrentTab );
connect( vwPlugins->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsPluginManager::currentPluginChanged );
connect( mModelPlugins, &QStandardItemModel::itemChanged, this, &QgsPluginManager::pluginItemChanged );
// Restiore UI state for widgets not handled by QgsOptionsDialogBase
QgsSettings settings;
// 1) The second splitter state:
mPluginsDetailsSplitter->restoreState( settings.value( QStringLiteral( "Windows/PluginManager/secondSplitterState" ) ).toByteArray() );
// 2) The current mOptionsListWidget index (it will overwrite the "tab" setting of QgsOptionsDialogBase that handles the stackedWidget page
// instead of the mOptionsListWidget index). Then the signal connected above will update the relevant page as well.
mOptionsListWidget->setCurrentRow( settings.value( QStringLiteral( "Windows/PluginManager/option" ), 0 ).toInt() );
// Hide widgets only suitable with Python support enabled (they will be uncovered back in setPythonUtils)
buttonUpgradeAll->hide();
buttonInstall->hide();
buttonUninstall->hide();
frameSettings->setHidden( true );
mOptionsListWidget->item( PLUGMAN_TAB_INSTALL_FROM_ZIP )->setHidden( true );
voteRating->hide();
voteLabel->hide();
voteSlider->hide();
voteSubmit->hide();
#ifndef WITH_QTWEBKIT
connect( voteSubmit, SIGNAL( clicked() ), this, SLOT( submitVote() ) );
#endif
// Init the message bar instance
msgBar = new QgsMessageBar( this );
msgBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
vlayoutRightColumn->insertWidget( 0, msgBar );
}
QgsPluginManager::~QgsPluginManager()
{
delete mModelProxy;
delete mModelPlugins;
QgsSettings settings;
settings.setValue( QStringLiteral( "Windows/PluginManager/secondSplitterState" ), mPluginsDetailsSplitter->saveState() );
settings.setValue( QStringLiteral( "Windows/PluginManager/option" ), mOptionsListWidget->currentRow() );
}
void QgsPluginManager::setPythonUtils( QgsPythonUtils *pythonUtils )
{
mPythonUtils = pythonUtils;
// Now enable Python support:
// Show and preset widgets only suitable when Python support active
mOptionsListWidget->item( PLUGMAN_TAB_INSTALL_FROM_ZIP )->setHidden( false );
buttonUpgradeAll->show();
buttonInstall->show();
buttonUninstall->show();
frameSettings->setHidden( false );
labelNoPython->setHidden( true );
buttonRefreshRepos->setEnabled( false );
buttonEditRep->setEnabled( false );
buttonDeleteRep->setEnabled( false );
// Add context menu to the plugins list view
QAction *actionSortByName = new QAction( tr( "sort by name" ), vwPlugins );
QAction *actionSortByDownloads = new QAction( tr( "sort by downloads" ), vwPlugins );
QAction *actionSortByVote = new QAction( tr( "sort by vote" ), vwPlugins );
QAction *actionSortByStatus = new QAction( tr( "sort by status" ), vwPlugins );
actionSortByName->setCheckable( true );
actionSortByDownloads->setCheckable( true );
actionSortByVote->setCheckable( true );
actionSortByStatus->setCheckable( true );
QActionGroup *group = new QActionGroup( vwPlugins );
actionSortByName->setActionGroup( group );
actionSortByDownloads->setActionGroup( group );
actionSortByVote->setActionGroup( group );
actionSortByStatus->setActionGroup( group );
actionSortByName->setChecked( true );
vwPlugins->addAction( actionSortByName );
vwPlugins->addAction( actionSortByDownloads );
vwPlugins->addAction( actionSortByVote );
vwPlugins->addAction( actionSortByStatus );
vwPlugins->setContextMenuPolicy( Qt::ActionsContextMenu );
connect( actionSortByName, &QAction::triggered, mModelProxy, &QgsPluginSortFilterProxyModel::sortPluginsByName );
connect( actionSortByDownloads, &QAction::triggered, mModelProxy, &QgsPluginSortFilterProxyModel::sortPluginsByDownloads );
connect( actionSortByVote, &QAction::triggered, mModelProxy, &QgsPluginSortFilterProxyModel::sortPluginsByVote );
connect( actionSortByStatus, &QAction::triggered, mModelProxy, &QgsPluginSortFilterProxyModel::sortPluginsByStatus );
// get the QgsSettings group from the installer
QString settingsGroup;
QgsPythonRunner::eval( QStringLiteral( "pyplugin_installer.instance().exportSettingsGroup()" ), settingsGroup );
QgsSettings settings;
// Initialize the "Install from ZIP" tab widgets
mZipFileWidget->setDefaultRoot( settings.value( settingsGroup + "/lastZipDirectory", "." ).toString() );
mZipFileWidget->setFilter( tr( "Plugin packages (*.zip *.ZIP)" ) );
connect( mZipFileWidget, &QgsFileWidget::fileChanged, this, &QgsPluginManager::mZipFileWidget_fileChanged );
connect( buttonInstallFromZip, &QPushButton::clicked, this, &QgsPluginManager::buttonInstallFromZip_clicked );
// Initialize list of allowed checking intervals
mCheckingOnStartIntervals << 0 << 1 << 3 << 7 << 14 << 30;
// Initialize the "Settings" tab widgets
if ( settings.value( settingsGroup + "/checkOnStart", false ).toBool() )
{
ckbCheckUpdates->setChecked( true );
}
if ( settings.value( settingsGroup + "/allowExperimental", false ).toBool() )
{
ckbExperimental->setChecked( true );
}
if ( settings.value( settingsGroup + "/allowDeprecated", false ).toBool() )
{
ckbDeprecated->setChecked( true );
}
int interval = settings.value( settingsGroup + "/checkOnStartInterval", "" ).toInt();
int indx = mCheckingOnStartIntervals.indexOf( interval ); // if none found, just use -1 index.
comboInterval->setCurrentIndex( indx );
}
void QgsPluginManager::loadPlugin( const QString &id )
{
const QMap<QString, QString> *plugin = pluginMetadata( id );
if ( ! plugin )
{
return;
}
QApplication::setOverrideCursor( Qt::WaitCursor );
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
QString library = plugin->value( QStringLiteral( "library" ) );
if ( plugin->value( QStringLiteral( "pythonic" ) ) == QLatin1String( "true" ) )
{
library = plugin->value( QStringLiteral( "id" ) );
QgsDebugMsg( "Loading Python plugin: " + library );
pRegistry->loadPythonPlugin( library );
}
else // C++ plugin
{
QgsDebugMsg( "Loading C++ plugin: " + library );
pRegistry->loadCppPlugin( library );
}
QgsDebugMsg( "Plugin loaded: " + library );
QApplication::restoreOverrideCursor();
}
void QgsPluginManager::unloadPlugin( const QString &id )
{
const QMap<QString, QString> *plugin = pluginMetadata( id );
if ( ! plugin )
{
return;
}
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
QString library = plugin->value( QStringLiteral( "library" ) );
if ( plugin->value( QStringLiteral( "pythonic" ) ) == QLatin1String( "true" ) )
{
library = plugin->value( QStringLiteral( "id" ) );
QgsDebugMsg( "Unloading Python plugin: " + library );
pRegistry->unloadPythonPlugin( library );
}
else // C++ plugin
{
QgsDebugMsg( "Unloading C++ plugin: " + library );
pRegistry->unloadCppPlugin( library );
}
}
void QgsPluginManager::savePluginState( QString id, bool state )
{
const QMap<QString, QString> *plugin = pluginMetadata( id );
if ( ! plugin )
{
return;
}
QgsSettings settings;
if ( plugin->value( QStringLiteral( "pythonic" ) ) == QLatin1String( "true" ) )
{
// Python plugin
settings.setValue( "/PythonPlugins/" + id, state );
}
else
{
// C++ plugin
// Trim "cpp:" prefix from cpp plugin id
id = id.mid( 4 );
settings.setValue( "/Plugins/" + id, state );
}
}
void QgsPluginManager::getCppPluginsMetadata()
{
QString sharedLibExtension;
#if defined(Q_OS_WIN) || defined(__CYGWIN__)
sharedLibExtension = "*.dll";
#else
sharedLibExtension = QStringLiteral( "*.so*" );
#endif
// check all libs in the current ans user plugins directories, and get name and descriptions
// First, the qgis install directory/lib (this info is available from the provider registry so we use it here)
QgsProviderRegistry *pr = QgsProviderRegistry::instance();
QStringList myPathList( pr->libraryDirectory().path() );
QgsSettings settings;
QString myPaths = settings.value( QStringLiteral( "plugins/searchPathsForPlugins" ), "" ).toString();
if ( !myPaths.isEmpty() )
{
myPathList.append( myPaths.split( '|' ) );
}
for ( int j = 0; j < myPathList.size(); ++j )
{
QString myPluginDir = myPathList.at( j );
QDir pluginDir( myPluginDir, sharedLibExtension, QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks );
if ( pluginDir.count() == 0 )
{
QMessageBox::information( this, tr( "No Plugins" ), tr( "No QGIS plugins found in %1" ).arg( myPluginDir ) );
return;
}
for ( uint i = 0; i < pluginDir.count(); i++ )
{
QString lib = QStringLiteral( "%1/%2" ).arg( myPluginDir, pluginDir[i] );
#ifdef TESTLIB
// This doesn't work on windows and causes problems with plugins
// on OS X (the code doesn't cause a problem but including dlfcn.h
// renders plugins unloadable)
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACX)
// test code to help debug loading problems
// This doesn't work on windows and causes problems with plugins
// on OS X (the code doesn't cause a problem but including dlfcn.h
// renders plugins unloadable)
//void *handle = dlopen( (const char *) lib, RTLD_LAZY);
void *handle = dlopen( lib.toLocal8Bit().data(), RTLD_LAZY | RTLD_GLOBAL );
if ( !handle )
{
QgsDebugMsg( "Error in dlopen: " );
QgsDebugMsg( dlerror() );
}
else
{
QgsDebugMsg( "dlopen succeeded for " + lib );
dlclose( handle );
}
#endif //#ifndef Q_OS_WIN && Q_OS_MACX
#endif //#ifdef TESTLIB
QgsDebugMsg( "Examining: " + lib );
QLibrary *myLib = new QLibrary( lib );
bool loaded = myLib->load();
if ( !loaded )
{
QgsDebugMsg( QString( "Failed to load: %1 (%2)" ).arg( myLib->fileName(), myLib->errorString() ) );
delete myLib;
continue;
}
QgsDebugMsg( "Loaded library: " + myLib->fileName() );
// Don't bother with libraries that are providers
//if(!myLib->resolve( "isProvider" ) )
//MH: Replaced to allow for plugins that are linked to providers
//type is only used in non-provider plugins
if ( !myLib->resolve( "type" ) )
{
delete myLib;
continue;
}
// resolve the metadata from plugin
name_t *pName = ( name_t * ) cast_to_fptr( myLib->resolve( "name" ) );
description_t *pDesc = ( description_t * ) cast_to_fptr( myLib->resolve( "description" ) );
category_t *pCat = ( category_t * ) cast_to_fptr( myLib->resolve( "category" ) );
version_t *pVersion = ( version_t * ) cast_to_fptr( myLib->resolve( "version" ) );
icon_t *pIcon = ( icon_t * ) cast_to_fptr( myLib->resolve( "icon" ) );
experimental_t *pExperimental = ( experimental_t * ) cast_to_fptr( myLib->resolve( "experimental" ) );
// show the values (or lack of) for each function
if ( pName )
{
QgsDebugMsg( "Plugin name: " + pName() );
}
else
{
QgsDebugMsg( "Plugin name not returned when queried" );
}
if ( pDesc )
{
QgsDebugMsg( "Plugin description: " + pDesc() );
}
else
{
QgsDebugMsg( "Plugin description not returned when queried" );
}
if ( pCat )
{
QgsDebugMsg( "Plugin category: " + pCat() );
}
else
{
QgsDebugMsg( "Plugin category not returned when queried" );
}
if ( pVersion )
{
QgsDebugMsg( "Plugin version: " + pVersion() );
}
else
{
QgsDebugMsg( "Plugin version not returned when queried" );
}
if ( pIcon )
{
QgsDebugMsg( "Plugin icon: " + pIcon() );
}
if ( !pName || !pDesc || !pVersion )
{
QgsDebugMsg( "Failed to get name, description, or type for " + myLib->fileName() );
delete myLib;
continue;
}
// Add "cpp:" prefix in case of two: Python and C++ plugins with the same name
QString baseName = "cpp:" + QFileInfo( lib ).baseName();
QMap<QString, QString> metadata;
metadata[QStringLiteral( "id" )] = baseName;
metadata[QStringLiteral( "name" )] = pName();
metadata[QStringLiteral( "description" )] = pDesc();
metadata[QStringLiteral( "category" )] = ( pCat ? pCat() : tr( "Plugins" ) );
metadata[QStringLiteral( "version_installed" )] = pVersion();
metadata[QStringLiteral( "icon" )] = ( pIcon ? pIcon() : QString() );
metadata[QStringLiteral( "library" )] = myLib->fileName();
metadata[QStringLiteral( "pythonic" )] = QStringLiteral( "false" );
metadata[QStringLiteral( "installed" )] = QStringLiteral( "true" );
metadata[QStringLiteral( "readonly" )] = QStringLiteral( "true" );
metadata[QStringLiteral( "status" )] = QStringLiteral( "orphan" );
metadata[QStringLiteral( "experimental" )] = ( pExperimental ? pExperimental() : QString() );
mPlugins.insert( baseName, metadata );
delete myLib;
}
}
}
QStandardItem *QgsPluginManager::createSpacerItem( const QString &text, const QString &value )
{
QStandardItem *mySpacerltem = new QStandardItem( text );
mySpacerltem->setData( value, PLUGIN_STATUS_ROLE );
mySpacerltem->setData( "status", SPACER_ROLE );
mySpacerltem->setEnabled( false );
mySpacerltem->setEditable( false );
QFont font = mySpacerltem->font();
font.setBold( true );
mySpacerltem->setFont( font );
mySpacerltem->setTextAlignment( Qt::AlignHCenter );
return mySpacerltem;
}
void QgsPluginManager::reloadModelData()
{
mModelPlugins->clear();
if ( !mCurrentlyDisplayedPlugin.isEmpty() )
{
wvDetails->setHtml( QString() );
buttonInstall->setEnabled( false );
buttonUninstall->setEnabled( false );
}
for ( QMap<QString, QMap<QString, QString> >::const_iterator it = mPlugins.constBegin();
it != mPlugins.constEnd();
++it )
{
if ( ! it->value( QStringLiteral( "id" ) ).isEmpty() )
{
QString baseName = it->value( QStringLiteral( "id" ) );
QString pluginName = it->value( QStringLiteral( "name" ) );
QString description = it->value( QStringLiteral( "description" ) );
QString author = it->value( QStringLiteral( "author_name" ) );
QString iconPath = it->value( QStringLiteral( "icon" ) );
QString status = it->value( QStringLiteral( "status" ) );
QString error = it->value( QStringLiteral( "error" ) );
QStandardItem *mypDetailItem = new QStandardItem( pluginName );
mypDetailItem->setData( baseName, PLUGIN_BASE_NAME_ROLE );
mypDetailItem->setData( status, PLUGIN_STATUS_ROLE );
mypDetailItem->setData( error, PLUGIN_ERROR_ROLE );
mypDetailItem->setData( description, PLUGIN_DESCRIPTION_ROLE );
mypDetailItem->setData( author, PLUGIN_AUTHOR_ROLE );
mypDetailItem->setData( it->value( QStringLiteral( "tags" ) ), PLUGIN_TAGS_ROLE );
mypDetailItem->setData( it->value( QStringLiteral( "downloads" ) ).rightJustified( 10, '0' ), PLUGIN_DOWNLOADS_ROLE );
mypDetailItem->setData( it->value( QStringLiteral( "average_vote" ) ), PLUGIN_VOTE_ROLE );
mypDetailItem->setData( it->value( QStringLiteral( "deprecated" ) ), PLUGIN_ISDEPRECATED_ROLE );
if ( QFileInfo( iconPath ).isFile() )
{
mypDetailItem->setData( QPixmap( iconPath ), Qt::DecorationRole );
}
else
{
mypDetailItem->setData( QPixmap( QgsApplication::defaultThemePath() + "/propertyicons/plugin.svg" ), Qt::DecorationRole );
}
mypDetailItem->setEditable( false );
// Set checkable if the plugin is installed and not disabled due to incompatibility.
// Broken plugins are checkable to to allow disabling them
mypDetailItem->setCheckable( it->value( QStringLiteral( "installed" ) ) == QLatin1String( "true" ) && it->value( QStringLiteral( "error" ) ) != QLatin1String( "incompatible" ) );
// Set ckeckState depending on the plugin is loaded or not.
// Initially mark all unchecked, then overwrite state of loaded ones with checked.
// Only do it with installed plugins, not not initialize checkboxes of not installed plugins at all.
if ( it->value( QStringLiteral( "installed" ) ) == QLatin1String( "true" ) )
{
mypDetailItem->setCheckState( Qt::Unchecked );
}
if ( isPluginEnabled( it->value( QStringLiteral( "id" ) ) ) )
{
mypDetailItem->setCheckState( Qt::Checked );
}
// Add items to model
mModelPlugins->appendRow( mypDetailItem );
// Repaint the details view if the currently displayed data are changed.
if ( baseName == mCurrentlyDisplayedPlugin )
{
showPluginDetails( mypDetailItem );
}
}
}
#ifdef WITH_BINDINGS
// Add spacers for sort by status
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
// TODO: implement better sort method instead of these dummy -Z statuses
mModelPlugins->appendRow( createSpacerItem( tr( "Only locally available", "category: plugins that are only locally available" ), QStringLiteral( "orphanZ" ) ) );
if ( hasReinstallablePlugins() )
mModelPlugins->appendRow( createSpacerItem( tr( "Reinstallable", "category: plugins that are installed and available" ), QStringLiteral( "installedZ" ) ) );
if ( hasUpgradeablePlugins() )
mModelPlugins->appendRow( createSpacerItem( tr( "Upgradeable", "category: plugins that are installed and there is a newer version available" ), QStringLiteral( "upgradeableZ" ) ) );
if ( hasNewerPlugins() )
mModelPlugins->appendRow( createSpacerItem( tr( "Downgradeable", "category: plugins that are installed and there is an OLDER version available" ), QStringLiteral( "newerZ" ) ) );
if ( hasAvailablePlugins() )
mModelPlugins->appendRow( createSpacerItem( tr( "Installable", "category: plugins that are available for installation" ), QStringLiteral( "not installedZ" ) ) );
}
#endif
updateWindowTitle();
buttonUpgradeAll->setEnabled( hasUpgradeablePlugins() );
// Disable tabs that are empty because of no suitable plugins in the model.
mOptionsListWidget->item( PLUGMAN_TAB_NOT_INSTALLED )->setHidden( ! hasAvailablePlugins() );
mOptionsListWidget->item( PLUGMAN_TAB_UPGRADEABLE )->setHidden( ! hasUpgradeablePlugins() );
mOptionsListWidget->item( PLUGMAN_TAB_NEW )->setHidden( ! hasNewPlugins() );
mOptionsListWidget->item( PLUGMAN_TAB_INVALID )->setHidden( ! hasInvalidPlugins() );
}
void QgsPluginManager::pluginItemChanged( QStandardItem *item )
{
QString id = item->data( PLUGIN_BASE_NAME_ROLE ).toString();
if ( item->checkState() )
{
if ( mPluginsAreEnabled && ! isPluginEnabled( id ) )
{
QgsDebugMsg( " Loading plugin: " + id );
loadPlugin( id );
}
else
{
// only enable the plugin, as we're in --noplugins mode
QgsDebugMsg( " Enabling plugin: " + id );
savePluginState( id, true );
}
}
else if ( ! item->checkState() )
{
QgsDebugMsg( " Unloading plugin: " + id );
unloadPlugin( id );
}
}
void QgsPluginManager::showPluginDetails( QStandardItem *item )
{
const QMap<QString, QString> *metadata = pluginMetadata( item->data( PLUGIN_BASE_NAME_ROLE ).toString() );
if ( !metadata )
{
return;
}
QString html = "<style>"
" body {"
" background-color:white;"
" }"
" body, table {"
" padding:0px;"
" margin:0px;"
" font-family:Verdana, Sans-serif;"
" font-size:10pt;"
" }"
" a {"
" color:#08c;"
" text-decoration:none;"
" }"
" a:hover,a:focus {"
" color:#005580;"
" text-decoration:underline;"
" }"
" div#votes {"
" width:360px;"
" margin-left:98px;"
" padding-top:3px;"
" }"
" td {"
" vertical-align:top;"
" }"
" td.key {"
" font-weight: bold;"
" white-space:nowrap;"
" padding-right:10px;"
" text-align:right;"
" }"
"</style>";
if ( !metadata->value( QStringLiteral( "plugin_id" ) ).isEmpty() )
{
#ifdef WITH_QTWEBKIT
html += QString(
"<style>"
" div#stars_bg {"
" background-image: url('qrc:/images/themes/default/stars_empty.svg');"
" background-size: 92px 16px;"
" width:92px;"
" height:16px;"
" margin-bottom:16px;"
" }"
" div#stars {"
" background-image: url('qrc:/images/themes/default/stars_full.svg');"
" background-size: 92px 16px;" /*scale to the full width*/
" width:%1px;"
" height:16px;"
" }"
"</style>" ).arg( metadata->value( QStringLiteral( "average_vote" ) ).toFloat() / 5 * 92 );
html += QString(
"<script>"
" var plugin_id=%1;"
" var vote=0;"
" function ready()"
" {"
" document.getElementById('stars_bg').onmouseover=save_vote;"
" document.getElementById('stars_bg').onmouseout=restore_vote;"
" document.getElementById('stars_bg').onmousemove=change_vote;"
" document.getElementById('stars_bg').onclick=send_vote;"
" };"
" "
" function save_vote(e)"
" {"
" vote = document.getElementById('stars').style.width"
" }"
" "
" function restore_vote(e)"
" {"
" document.getElementById('stars').style.width = vote;"
" }"
" "
" function change_vote(e)"
" {"
" var length = e.x - document.getElementById('stars').getBoundingClientRect().left;"
" max = document.getElementById('stars_bg').getBoundingClientRect().right;"
" if ( length <= max ) document.getElementById('stars').style.width = length + 'px';"
" }"
" "
" function send_vote(e)"
" {"
" save_vote();"
" result = Number(vote.replace('px',''));"
" if (!result) return;"
" result = Math.floor(result/92*5)+1;"
" document.getElementById('send_vote_trigger').href='rpc2://plugin.vote/'+plugin_id+'/'+result;"
" ev=document.createEvent('MouseEvents');"
" ev.initEvent('click', false, true);"
" document.getElementById('send_vote_trigger').dispatchEvent(ev);"
" }"
"</script>" ).arg( metadata->value( QStringLiteral( "plugin_id" ) ) );
#else
voteRating->show();
voteLabel->show();
voteSlider->show();
voteSubmit->show();
QgsDebugMsg( QString( "vote slider:%1" ).arg( std::round( metadata->value( "average_vote" ).toFloat() ) ) );
voteSlider->setValue( std::round( metadata->value( "average_vote" ).toFloat() ) );
mCurrentPluginId = metadata->value( "plugin_id" ).toInt();
}
else
{
voteRating->hide();
voteLabel->hide();
voteSlider->hide();
voteSubmit->hide();
mCurrentPluginId = -1;
#endif
}
#ifdef WITH_QTWEBKIT
html += QLatin1String( "<body onload='ready()'>" );
#else
html += "<body>";
#endif
// First prepare message box(es)
if ( ! metadata->value( QStringLiteral( "error" ) ).isEmpty() )
{
QString errorMsg;
if ( metadata->value( QStringLiteral( "error" ) ) == QLatin1String( "incompatible" ) )
{
errorMsg = QStringLiteral( "<b>%1</b><br/>%2" ).arg( tr( "This plugin is incompatible with this version of QGIS" ), tr( "Plugin designed for QGIS %1", "compatible QGIS version(s)" ).arg( metadata->value( QStringLiteral( "error_details" ) ) ) );
}
else if ( metadata->value( QStringLiteral( "error" ) ) == QLatin1String( "dependent" ) )
{
errorMsg = QStringLiteral( "<b>%1:</b><br/>%2" ).arg( tr( "This plugin requires a missing module" ), metadata->value( QStringLiteral( "error_details" ) ) );
}
else
{
errorMsg = QStringLiteral( "<b>%1</b><br/>%2" ).arg( tr( "This plugin is broken" ), metadata->value( QStringLiteral( "error_details" ) ) );
}
html += QString( "<table bgcolor=\"#FFFF88\" cellspacing=\"2\" cellpadding=\"6\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#CC0000\">%1</td></tr>"
"</table>" ).arg( errorMsg );
}
if ( metadata->value( QStringLiteral( "status" ) ) == QLatin1String( "upgradeable" ) )
{
html += QString( "<table bgcolor=\"#FFFFAA\" cellspacing=\"2\" cellpadding=\"6\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#880000\"><b>%1</b></td></tr>"
"</table>" ).arg( tr( "There is a new version available" ) );
}
if ( metadata->value( QStringLiteral( "status" ) ) == QLatin1String( "new" ) )
{
html += QString( "<table bgcolor=\"#CCFFCC\" cellspacing=\"2\" cellpadding=\"6\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#008800\"><b>%1</b></td></tr>"
"</table>" ).arg( tr( "This is a new plugin" ) );
}
if ( metadata->value( QStringLiteral( "status" ) ) == QLatin1String( "newer" ) )
{
html += QString( "<table bgcolor=\"#FFFFCC\" cellspacing=\"2\" cellpadding=\"6\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#550000\"><b>%1</b></td></tr>"
"</table>" ).arg( tr( "Installed version of this plugin is higher than any version found in repository" ) );
}
if ( metadata->value( QStringLiteral( "experimental" ) ) == QLatin1String( "true" ) )
{
html += QString( "<table bgcolor=\"#EEEEBB\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#660000\">"
" <img src=\"qrc:/images/themes/default/pluginExperimental.png\" width=\"32\"><b>%1</b>"
" </td></tr>"
"</table>" ).arg( tr( "This plugin is experimental" ) );
}
if ( metadata->value( QStringLiteral( "deprecated" ) ) == QLatin1String( "true" ) )
{
html += QString( "<table bgcolor=\"#EEBBCC\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#660000\">"
" <img src=\"qrc:/images/themes/default/pluginDeprecated.svg\" width=\"32\"><b>%1</b>"
" </td></tr>"
"</table>" ).arg( tr( "This plugin is deprecated" ) );
}
if ( metadata->value( QStringLiteral( "readonly" ) ) == QLatin1String( "true" ) )
{
html += QString( "<table bgcolor=\"#90EEE9\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\">"
" <tr><td width=\"100%\" style=\"color:#660000\"><b>%1</b></td></tr>"
"</table>" ).arg( tr( "This is a core plugin, so you can't uninstall it" ) );
}
// Now the metadata
html += QLatin1String( "<table cellspacing='4' width='100%'>" );
html += QLatin1String( "<tr><td colspan='2'>" );
QString iconPath = metadata->value( QStringLiteral( "icon" ) );
if ( QFileInfo( iconPath ).isFile() || iconPath.startsWith( QLatin1String( "http" ) ) )
{
if ( iconPath.startsWith( QLatin1String( ":/" ) ) )
{
iconPath = "qrc" + iconPath;
}
else if ( ! iconPath.startsWith( QLatin1String( "http" ) ) )
{
#if defined(Q_OS_WIN)
iconPath = "file:///" + iconPath;
#else
iconPath = "file://" + iconPath;
#endif
}
html += QStringLiteral( "<img src=\"%1\" style=\"float:right;max-width:64px;max-height:64px;\">" ).arg( iconPath );
}
html += QStringLiteral( "<h1>%1</h1>" ).arg( metadata->value( QStringLiteral( "name" ) ) );
html += QStringLiteral( "<h3>%1</h3>" ).arg( metadata->value( QStringLiteral( "description" ) ) );
if ( ! metadata->value( QStringLiteral( "about" ) ).isEmpty() )
{
QString about = metadata->value( QStringLiteral( "about" ) );
html += about.replace( '\n', QLatin1String( "<br/>" ) );
html += QLatin1String( "<br/><br/>" );
}
QString votes;
#ifndef WITH_QTWEBKIT
votes += tr( "Average rating %1" ).arg( metadata->value( "average_vote" ).toFloat(), 0, 'f', 1 );
#endif
if ( ! metadata->value( QStringLiteral( "rating_votes" ) ).isEmpty() )
{
if ( !votes.isEmpty() )
votes += QLatin1String( ", " );
votes += tr( "%1 rating vote(s)" ).arg( metadata->value( QStringLiteral( "rating_votes" ) ) );
}
if ( ! metadata->value( QStringLiteral( "downloads" ) ).isEmpty() )
{
if ( !votes.isEmpty() )
votes += QLatin1String( ", " );
votes += tr( "%1 downloads" ).arg( metadata->value( QStringLiteral( "downloads" ) ) );
}
#ifdef WITH_QTWEBKIT
html += QLatin1String( "<div id='stars_bg'/><div id='stars'/>" );
html += QLatin1String( "<div id='votes'>" );
html += votes;
html += QLatin1String( "</div>" );
html += QLatin1String( "<div><a id='send_vote_trigger'/></div>" );
#else
voteRating->setText( votes );
#endif
html += QLatin1String( "</td></tr>" );
html += QLatin1String( "<tr><td width='1%'> </td><td width='99%'> </td></tr>" );
if ( ! metadata->value( QStringLiteral( "category" ) ).isEmpty() )
{
html += QStringLiteral( "<tr><td class='key'>%1 </td><td>%2</td></tr>" ).arg( tr( "Category" ), metadata->value( QStringLiteral( "category" ) ) );
}
if ( ! metadata->value( QStringLiteral( "tags" ) ).isEmpty() )
{
html += QStringLiteral( "<tr><td class='key'>%1 </td><td>%2</td></tr>" ).arg( tr( "Tags" ), metadata->value( QStringLiteral( "tags" ) ) );
}
if ( ! metadata->value( QStringLiteral( "homepage" ) ).isEmpty() || ! metadata->value( QStringLiteral( "tracker" ) ).isEmpty() || ! metadata->value( QStringLiteral( "code_repository" ) ).isEmpty() )
{
html += QStringLiteral( "<tr><td class='key'>%1 </td><td>" ).arg( tr( "More info" ) );
if ( ! metadata->value( QStringLiteral( "homepage" ) ).isEmpty() )
{
html += QStringLiteral( "<a href='%1'>%2</a> " ).arg( metadata->value( QStringLiteral( "homepage" ) ), tr( "homepage" ) );
}
if ( ! metadata->value( QStringLiteral( "tracker" ) ).isEmpty() )
{
html += QStringLiteral( "<a href='%1'>%2</a> " ).arg( metadata->value( QStringLiteral( "tracker" ) ), tr( "bug tracker" ) );
}
if ( ! metadata->value( QStringLiteral( "code_repository" ) ).isEmpty() )
{
html += QStringLiteral( "<a href='%1'>%2</a>" ).arg( metadata->value( QStringLiteral( "code_repository" ) ), tr( "code repository" ) );
}
html += QLatin1String( "</td></tr>" );
}
if ( ! metadata->value( QStringLiteral( "author_email" ) ).isEmpty() )
{
html += QStringLiteral( "<tr><td class='key'>%1 </td><td><a href='mailto:%2'>%3</a></td></tr>" ).arg( tr( "Author" ), metadata->value( QStringLiteral( "author_email" ) ), metadata->value( QStringLiteral( "author_name" ) ) );
}
else if ( ! metadata->value( QStringLiteral( "author_name" ) ).isEmpty() )
{
html += QStringLiteral( "<tr><td class='key'>%1 </td><td>%2</td></tr>" ).arg( tr( "Author" ), metadata->value( QStringLiteral( "author_name" ) ) );
}
if ( ! metadata->value( QStringLiteral( "version_installed" ) ).isEmpty() )
{
QString ver = metadata->value( QStringLiteral( "version_installed" ) );
if ( ver == QLatin1String( "-1" ) )
{
ver = '?';
}
QString localDir = metadata->value( QStringLiteral( "library" ) );
if ( QFileInfo( localDir ).isFile() )
{
localDir = QFileInfo( localDir ).absolutePath();
}
html += QStringLiteral( "<tr><td class='key'>%1 </td><td title='%2'><a href='%3'>%4</a></td></tr>"
).arg( tr( "Installed version" ),
metadata->value( QStringLiteral( "library" ) ),
QUrl::fromLocalFile( localDir ).toString(),
ver );
}
if ( ! metadata->value( QStringLiteral( "version_available" ) ).isEmpty() )
{
QString downloadUrl = metadata->value( QStringLiteral( "download_url" ) );
if ( downloadUrl.contains( QStringLiteral( "plugins.qgis.org" ) ) )
{
// For the main repo, open the plugin version page instead of the download link. For other repositories the download link is the only known endpoint.
downloadUrl = downloadUrl.replace( QStringLiteral( "download/" ), QString() );
}
html += QStringLiteral( "<tr><td class='key'>%1 </td><td title='%2'><a href='%2'>%3</a></td></tr>"
).arg( tr( "Available version" ),
downloadUrl,
metadata->value( QStringLiteral( "version_available" ) ) );
}
if ( ! metadata->value( QStringLiteral( "changelog" ) ).isEmpty() )
{
QString changelog = metadata->value( QStringLiteral( "changelog" ) );
changelog = changelog.trimmed().replace( '\n', QLatin1String( "<br/>" ) );
html += QStringLiteral( "<tr><td class='key'>%1 </td><td>%2</td></tr>" ).arg( tr( "Changelog" ), changelog );
}
html += QLatin1String( "</td></tr></table>" );
html += QLatin1String( "</body>" );
wvDetails->setHtml( html );
// Set buttonInstall text (and sometimes focus)
buttonInstall->setDefault( false );
if ( metadata->value( QStringLiteral( "status" ) ) == QLatin1String( "upgradeable" ) )
{
buttonInstall->setText( tr( "Upgrade plugin" ) );
buttonInstall->setDefault( true );
}
else if ( metadata->value( QStringLiteral( "status" ) ) == QLatin1String( "newer" ) )
{
buttonInstall->setText( tr( "Downgrade plugin" ) );
}
else if ( metadata->value( QStringLiteral( "status" ) ) == QLatin1String( "not installed" ) || metadata->value( QStringLiteral( "status" ) ) == QLatin1String( "new" ) )
{
buttonInstall->setText( tr( "Install plugin" ) );
}
else
{
// Default (will be grayed out if not available for reinstallation)
buttonInstall->setText( tr( "Reinstall plugin" ) );