File: ccPluginInfoDlg.cpp

package info (click to toggle)
cloudcompare 2.11.3-7.1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 58,224 kB
  • sloc: cpp: 229,982; ansic: 30,723; makefile: 84; sh: 20
file content (348 lines) | stat: -rw-r--r-- 9,235 bytes parent folder | download
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
//##########################################################################
//#                                                                        #
//#                              CLOUDCOMPARE                              #
//#                                                                        #
//#  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; version 2 or later of the License.      #
//#                                                                        #
//#  This program is distributed in the hope that it will be useful,       #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          #
//#  GNU General Public License for more details.                          #
//#                                                                        #
//#          COPYRIGHT: CloudCompare project                               #
//#                                                                        #
//##########################################################################

#include <QDebug>
#include <QDir>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>

#include "ccPluginInfoDlg.h"
#include "ccPluginManager.h"
#include "ccStdPluginInterface.h"

#include "ui_ccPluginInfoDlg.h"


static QString sFormatReferenceList( const ccPluginInterface::ReferenceList &list )
{
	const QString linkFormat( " <a href=\"%1\" style=\"text-decoration:none\">&#x1F517;</a>" );
	QString	formattedText;
	int referenceNum = 1;
	
	for ( const ccPluginInterface::Reference &reference : list )
	{
		formattedText += QStringLiteral( "%1. " ).arg( QString::number( referenceNum++ ) );
		
		formattedText += reference.article;
		
		if ( !reference.url.isEmpty() )
		{
			formattedText += linkFormat.arg( reference.url );
		}
		
		formattedText += QStringLiteral( "<br/>" );
	}
	
	return formattedText;
}

static QString sFormatContactList( const ccPluginInterface::ContactList &list, const QString &pluginName )
{
	const QString emailFormat( "&lt;<a href=\"mailto:%1?Subject=CloudCompare %2\">%1</a>&gt;" );
	QString	formattedText;
	
	for ( const ccPluginInterface::Contact &contact : list )
	{
		formattedText += contact.name;
		
		if ( !contact.email.isEmpty() )
		{
			formattedText += emailFormat.arg( contact.email, pluginName );
		}
		
		formattedText += QStringLiteral( "<br/>" );
	}
	
	return formattedText;
}

namespace
{
	class _Icons
	{
	public:
		static QIcon   sGetIcon( CC_PLUGIN_TYPE inPluginType )
		{
			if ( sIconMap.empty() )
			{
				_init();
			}
			
			return sIconMap[inPluginType];
		}
		
	private:
		static void	_init()
		{
			if ( !sIconMap.empty() )
			{
				return;
			}
			
			sIconMap[CC_STD_PLUGIN] = QIcon( ":/CC/pluginManager/images/std_plugin.png" );
			sIconMap[CC_GL_FILTER_PLUGIN] = QIcon( ":/CC/pluginManager/images/gl_plugin.png" );
			sIconMap[CC_IO_FILTER_PLUGIN] = QIcon( ":/CC/pluginManager/images/io_plugin.png" );
		}
		
		static QMap<CC_PLUGIN_TYPE, QIcon>	sIconMap;
	};
	
	QMap<CC_PLUGIN_TYPE, QIcon>	_Icons::sIconMap;
}

ccPluginInfoDlg::ccPluginInfoDlg( QWidget *parent ) :
	QDialog( parent )
  , m_UI( new Ui::ccPluginInfoDlg )
  , m_ProxyModel( new QSortFilterProxyModel( this ) )
  , m_ItemModel( new QStandardItemModel( this ) )
{
	m_UI->setupUi( this );
	
	setWindowTitle( tr("About Plugins" ) );
	
	m_UI->mWarningLabel->setText( tr( "Enabling/disabling plugins will take effect next time you run %1" ).arg( QApplication::applicationName() ) );
	m_UI->mWarningLabel->setStyleSheet( QStringLiteral( "QLabel { background-color : #FFFF99; color : black; }" ) );
	m_UI->mWarningLabel->hide();
	
	m_UI->mSearchLineEdit->setStyleSheet( "QLineEdit, QLineEdit:focus { border: none; }" );
	m_UI->mSearchLineEdit->setAttribute( Qt::WA_MacShowFocusRect, false );
				
	m_ProxyModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
	m_ProxyModel->setSourceModel( m_ItemModel );
	
	m_UI->mPluginListView->setModel( m_ProxyModel );
	m_UI->mPluginListView->setFocus();
	
	connect( m_UI->mSearchLineEdit, &QLineEdit::textEdited, m_ProxyModel, &QSortFilterProxyModel::setFilterFixedString );
	
	connect( m_UI->mPluginListView->selectionModel(), &QItemSelectionModel::currentChanged, 
			 this, &ccPluginInfoDlg::selectionChanged );
}

ccPluginInfoDlg::~ccPluginInfoDlg()
{
	delete m_UI;
}

void ccPluginInfoDlg::setPluginPaths( const QStringList &pluginPaths )
{
	QString	paths;
	
	for ( const QString &path : pluginPaths )
	{
		paths += QDir::toNativeSeparators( path );
		paths += QStringLiteral( "\n" );
	}
	
	m_UI->mPluginPathTextEdit->setText( paths );
}

void ccPluginInfoDlg::setPluginList( const QList<ccPluginInterface *> &pluginList )
{
	m_ItemModel->clear();
	m_ItemModel->setRowCount( pluginList.count() );
	m_ItemModel->setColumnCount( 1 );
	
	int	row = 0;
	
	for ( const ccPluginInterface *plugin : pluginList )
	{
		auto name = plugin->getName();
		auto tooltip = tr( "%1 Plugin" ).arg( plugin->getName() );
		
		if ( plugin->isCore() )
		{
			tooltip += tr( " (core)" );
		}
		else
		{
			name += " 👽";
			tooltip += tr( " (3rd Party)" );
		}
		
		QStandardItem *item = new QStandardItem( name );
				
		item->setCheckable( true );
		
		if ( ccPluginManager::get().isEnabled( plugin ) )
		{
			item->setCheckState( Qt::Checked );
		}
		
		item->setData( QVariant::fromValue( plugin ), PLUGIN_PTR );		
		item->setIcon( _Icons::sGetIcon( plugin->getType() ) );
		item->setToolTip( tooltip );
		
		m_ItemModel->setItem( row, 0, item );
		
		++row;
	}
	
	if ( !pluginList.empty() )
	{
		m_ItemModel->sort( 0 );
		
		QModelIndex	index = m_ItemModel->index( 0, 0 );
		
		m_UI->mPluginListView->setCurrentIndex( index );
	}
	
	connect( m_ItemModel, &QStandardItemModel::itemChanged, this, &ccPluginInfoDlg::itemChanged );
}

const ccPluginInterface *ccPluginInfoDlg::pluginFromItemData( const QStandardItem *item ) const
{
	return item->data( PLUGIN_PTR ).value<const ccPluginInterface*>();;
}

void ccPluginInfoDlg::selectionChanged( const QModelIndex &current, const QModelIndex &previous )
{
	Q_UNUSED( previous );
	
	auto sourceItem = m_ProxyModel->mapToSource( current );
	auto item = m_ItemModel->itemFromIndex( sourceItem );
	
	if ( item == nullptr )
	{
		// This happens if we are filtering and there are no results
		updatePluginInfo( nullptr );
		return;
	}
	
	auto plugin = pluginFromItemData( item );
	
	updatePluginInfo( plugin );	
}

void ccPluginInfoDlg::itemChanged( QStandardItem *item )
{
	bool checked = item->checkState() == Qt::Checked;
	auto plugin = pluginFromItemData( item );
	
	if ( plugin != nullptr )
	{
		ccPluginManager::get().setPluginEnabled( plugin, checked );
		
		if ( m_UI->mWarningLabel->isHidden() )
		{
			ccLog::Warning( m_UI->mWarningLabel->text() );
			
			m_UI->mWarningLabel->show();
		}
	}
}

void ccPluginInfoDlg::updatePluginInfo( const ccPluginInterface *plugin )
{
	if ( plugin == nullptr )
	{
		m_UI->mIcon->setPixmap( QPixmap() );
		m_UI->mNameLabel->setText( tr( "(No plugin selected)" ) );
		m_UI->mDescriptionTextEdit->clear();
		m_UI->mReferencesTextBrowser->clear();
		m_UI->mAuthorsTextBrowser->clear();
		m_UI->mMaintainerTextBrowser->clear();
		return;
	}
	
	const QSize iconSize( 64, 64 );
	
	QPixmap	iconPixmap;
	
	if ( !plugin->getIcon().isNull() )
	{
		iconPixmap = plugin->getIcon().pixmap( iconSize );
	}
	
	switch ( plugin->getType() )
	{
		case CC_STD_PLUGIN:
		{
			if ( iconPixmap.isNull() )
			{
				iconPixmap = QPixmap( ":/CC/pluginManager/images/std_plugin.png" ).scaled( iconSize );
			}
			
			m_UI->mPluginTypeLabel->clear();
			break;				
		}
			
		case CC_GL_FILTER_PLUGIN:
		{
			if ( iconPixmap.isNull() )
			{
				iconPixmap = QPixmap( ":/CC/pluginManager/images/gl_plugin.png" ).scaled( iconSize );
			}
			
			m_UI->mPluginTypeLabel->setText( tr( "GL Shader" ) );
			break;
		}
			
		case CC_IO_FILTER_PLUGIN:
		{
			if ( iconPixmap.isNull() )
			{
				iconPixmap = QPixmap( ":/CC/pluginManager/images/io_plugin.png" ).scaled( iconSize );
			}
			
			m_UI->mPluginTypeLabel->setText( tr( "I/O" ) );
			break;
		}
	}
	
	m_UI->mIcon->setPixmap( iconPixmap );
	
	m_UI->mNameLabel->setText( plugin->getName() );
	m_UI->mDescriptionTextEdit->setHtml( plugin->getDescription() );
	
	const QString referenceText = sFormatReferenceList( plugin->getReferences() );
	
	if ( !referenceText.isEmpty() )
	{
		m_UI->mReferencesTextBrowser->setHtml( referenceText );
		m_UI->mReferencesLabel->show();
		m_UI->mReferencesTextBrowser->show();
	}
	else
	{
		m_UI->mReferencesLabel->hide();
		m_UI->mReferencesTextBrowser->hide();
		m_UI->mReferencesTextBrowser->clear();
	}
	
	const QString authorsText = sFormatContactList( plugin->getAuthors(), plugin->getName() );
	
	if ( !authorsText.isEmpty() )
	{
		m_UI->mAuthorsTextBrowser->setHtml( authorsText );
	}
	else
	{
		m_UI->mAuthorsTextBrowser->clear();
	}
	
	const QString maintainersText = sFormatContactList( plugin->getMaintainers(), plugin->getName() );
	
	if ( !maintainersText.isEmpty() )
	{
		m_UI->mMaintainerTextBrowser->setHtml( maintainersText );
	}
	else
	{
		m_UI->mMaintainerTextBrowser->clear();
	}
}