1 /*****************************************************************************
2 * plugins.hpp : Plug-ins and extensions listing
3 ****************************************************************************
4 * Copyright (C) 2008-2010 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8 * Jean-Philippe André <jpeg (at) videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include "plugins.hpp"
31 #include "util/customwidgets.hpp"
32 #include "extensions_manager.hpp"
36 //#include <vlc_modules.h>
38 #include <QTreeWidget>
39 #include <QStringList>
41 #include <QHeaderView>
42 #include <QDialogButtonBox>
45 #include <QVBoxLayout>
47 #include <QTextBrowser>
48 #include <QHBoxLayout>
49 #include <QVBoxLayout>
50 #include <QSpacerItem>
53 #include <QStyleOptionViewItem>
57 PluginDialog::PluginDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
59 setWindowTitle( qtr( "Plugins and extensions" ) );
60 setWindowRole( "vlc-plugins" );
62 QVBoxLayout *layout = new QVBoxLayout( this );
63 tabs = new QTabWidget( this );
64 tabs->addTab( extensionTab = new ExtensionTab( p_intf ),
65 qtr( "Extensions" ) );
66 tabs->addTab( pluginTab = new PluginTab( p_intf ),
68 layout->addWidget( tabs );
70 QDialogButtonBox *box = new QDialogButtonBox;
71 QPushButton *okButton = new QPushButton( qtr( "&Close" ), this );
72 box->addButton( okButton, QDialogButtonBox::AcceptRole );
73 layout->addWidget( box );
74 BUTTONACT( okButton, close() );
77 PluginDialog::~PluginDialog()
83 PluginTab::PluginTab( intf_thread_t *p_intf )
86 QGridLayout *layout = new QGridLayout( this );
88 /* Main Tree for modules */
89 treePlugins = new QTreeWidget;
90 layout->addWidget( treePlugins, 0, 0, 1, -1 );
92 /* Users cannot move the columns around but we need to sort */
93 treePlugins->header()->setMovable( false );
94 treePlugins->header()->setSortIndicatorShown( true );
95 // treePlugins->header()->setResizeMode( QHeaderView::ResizeToContents );
96 treePlugins->setAlternatingRowColors( true );
97 treePlugins->setColumnWidth( 0, 200 );
99 QStringList headerNames;
100 headerNames << qtr("Name") << qtr("Capability" ) << qtr( "Score" );
101 treePlugins->setHeaderLabels( headerNames );
105 /* Set capability column to the correct Size*/
106 treePlugins->resizeColumnToContents( 1 );
107 treePlugins->header()->restoreState(
108 getSettings()->value( "Plugins/Header-State" ).toByteArray() );
110 treePlugins->setSortingEnabled( true );
111 treePlugins->sortByColumn( 1, Qt::AscendingOrder );
113 QLabel *label = new QLabel( qtr("&Search:"), this );
114 edit = new SearchLineEdit( this );
115 label->setBuddy( edit );
117 layout->addWidget( label, 1, 0 );
118 layout->addWidget( edit, 1, 1, 1, 1 );
119 CONNECT( edit, textChanged( const QString& ),
120 this, search( const QString& ) );
122 setMinimumSize( 500, 300 );
123 readSettings( "Plugins", QSize( 540, 400 ) );
126 inline void PluginTab::FillTree()
128 module_t **p_list = module_list_get( NULL );
131 for( unsigned int i = 0; (p_module = p_list[i] ) != NULL; i++ )
134 qs_item << qfu( module_get_name( p_module, true ) )
135 << qfu( module_get_capability( p_module ) )
136 << QString::number( module_get_score( p_module ) );
138 if( qs_item.at(1).isEmpty() ) continue;
141 QTreeWidgetItem *item = new PluginTreeItem( qs_item );
142 treePlugins->addTopLevelItem( item );
146 void PluginTab::search( const QString& qs )
148 QList<QTreeWidgetItem *> items = treePlugins->findItems( qs, Qt::MatchContains );
149 items += treePlugins->findItems( qs, Qt::MatchContains, 1 );
151 QTreeWidgetItem *item = NULL;
152 for( int i = 0; i < treePlugins->topLevelItemCount(); i++ )
154 item = treePlugins->topLevelItem( i );
155 item->setHidden( !items.contains( item ) );
159 PluginTab::~PluginTab()
161 writeSettings( "Plugins" );
162 getSettings()->setValue( "Plugins/Header-State",
163 treePlugins->header()->saveState() );
166 bool PluginTreeItem::operator< ( const QTreeWidgetItem & other ) const
168 int col = treeWidget()->sortColumn();
170 return text( col ).toInt() < other.text( col ).toInt();
171 return text( col ) < other.text( col );
175 ExtensionTab::ExtensionTab( intf_thread_t *p_intf )
176 : QVLCFrame( p_intf )
179 QVBoxLayout *layout = new QVBoxLayout( this );
182 extList = new QListView( this );
183 layout->addWidget( extList );
185 // List item delegate
186 ExtensionItemDelegate *itemDelegate = new ExtensionItemDelegate( p_intf,
188 extList->setItemDelegate( itemDelegate );
190 // Extension list look & feeling
191 extList->setAlternatingRowColors( true );
192 extList->setSelectionMode( QAbstractItemView::SingleSelection );
195 ExtensionListModel *model = new ExtensionListModel( extList, p_intf );
196 extList->setModel( model );
199 QHBoxLayout *hbox = new QHBoxLayout;
200 hbox->addItem( new QSpacerItem( 1, 1, QSizePolicy::Expanding,
201 QSizePolicy::Fixed ) );
203 // More information button
204 butMoreInfo = new QPushButton( QIcon( ":/menu/info" ),
205 qtr( "More information..." ),
207 CONNECT( butMoreInfo, clicked(),
208 this, moreInformation() );
209 hbox->addWidget( butMoreInfo );
212 ExtensionsManager *EM = ExtensionsManager::getInstance( p_intf );
213 QPushButton *reload = new QPushButton( QIcon( ":/update" ),
214 qtr( "Reload extensions" ),
216 CONNECT( reload, clicked(),
217 EM, reloadExtensions() );
218 hbox->addWidget( reload );
221 layout->addItem( hbox );
224 ExtensionTab::~ExtensionTab()
228 // Do not close on ESC or ENTER
229 void ExtensionTab::keyPressEvent( QKeyEvent *keyEvent )
234 // Show more information
235 void ExtensionTab::moreInformation()
237 if( !extList->selectionModel() ||
238 extList->selectionModel()->selectedIndexes().isEmpty() )
244 QModelIndex index = extList->selectionModel()->selectedIndexes().first();
245 ExtensionCopy *ext = (ExtensionCopy*) index.internalPointer();
249 ExtensionInfoDialog dlg( *ext, p_intf, this );
253 /* Safe copy of the extension_t struct */
257 ExtensionCopy( extension_t *p_ext )
259 name = qfu( p_ext->psz_name );
260 description = qfu( p_ext->psz_description );
261 title = qfu( p_ext->psz_title );
262 author = qfu( p_ext->psz_author );
263 version = qfu( p_ext->psz_version );
264 url = qfu( p_ext->psz_url );
268 QString name, title, description, author, version, url;
271 /* Extensions list model for the QListView */
273 ExtensionListModel::ExtensionListModel( QListView *view, intf_thread_t *intf )
274 : QAbstractListModel( view ), p_intf( intf )
276 // Connect to ExtensionsManager::extensionsUpdated()
277 ExtensionsManager* EM = ExtensionsManager::getInstance( p_intf );
278 CONNECT( EM, extensionsUpdated(), this, updateList() );
280 // Load extensions now if not already loaded
281 EM->loadExtensions();
284 ExtensionListModel::~ExtensionListModel()
288 void ExtensionListModel::updateList()
292 // Clear extensions list
293 while( !extensions.isEmpty() )
295 ext = extensions.takeLast();
299 // Find new extensions
300 ExtensionsManager *EM = ExtensionsManager::getInstance( p_intf );
301 extensions_manager_t *p_mgr = EM->getManager();
305 vlc_mutex_lock( &p_mgr->lock );
307 FOREACH_ARRAY( p_ext, p_mgr->extensions )
309 ext = new ExtensionCopy( p_ext );
310 extensions.push_back( ext );
313 vlc_mutex_unlock( &p_mgr->lock );
314 vlc_object_release( p_mgr );
316 emit dataChanged( index( 0 ), index( rowCount() - 1 ) );
319 int ExtensionListModel::rowCount( const QModelIndex& parent ) const
322 ExtensionsManager *EM = ExtensionsManager::getInstance( p_intf );
323 extensions_manager_t *p_mgr = EM->getManager();
327 vlc_mutex_lock( &p_mgr->lock );
328 count = p_mgr->extensions.i_size;
329 vlc_mutex_unlock( &p_mgr->lock );
330 vlc_object_release( p_mgr );
335 QVariant ExtensionListModel::data( const QModelIndex& index, int role ) const
337 if( !index.isValid() )
347 QModelIndex ExtensionListModel::index( int row, int column,
348 const QModelIndex& parent ) const
351 return QModelIndex();
352 if( row < 0 || row >= extensions.size() )
353 return QModelIndex();
355 return createIndex( row, 0, extensions.at( row ) );
359 /* Extension List Widget Item */
360 ExtensionItemDelegate::ExtensionItemDelegate( intf_thread_t *p_intf,
362 : QStyledItemDelegate( view ), view( view ), p_intf( p_intf )
366 ExtensionItemDelegate::~ExtensionItemDelegate()
370 void ExtensionItemDelegate::paint( QPainter *painter,
371 const QStyleOptionViewItem &option,
372 const QModelIndex &index ) const
374 ExtensionCopy *ext = ( ExtensionCopy* ) index.internalPointer();
375 assert( ext != NULL );
377 int width = option.rect.width();
378 int height = option.rect.height();
380 // Pixmap: buffer where to draw
381 QPixmap pix(option.rect.size());
384 pix.fill( Qt::transparent ); // FIXME
386 // ItemView primitive style
387 QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem,
391 // Painter on the pixmap
392 QPainter *pixpaint = new QPainter(&pix);
395 QFont font = painter->font();
396 QPen pen = painter->pen();
397 if( view->selectionModel()->selectedIndexes().contains( index ) )
399 pen.setBrush( option.palette.highlightedText() );
403 pen.setBrush( option.palette.text() );
405 pixpaint->setPen( pen );
408 font.setBold( true );
409 pixpaint->setFont( font );
410 pixpaint->drawText( QRect( 10, 5, width - 70, 20 ),
411 Qt::AlignLeft, ext->title );
413 // Short description: normal
414 font.setBold( false );
415 pixpaint->setFont( font );
416 pixpaint->drawText( QRect( 10, 30, width - 40, 20 ),
417 Qt::AlignLeft, ext->description );
420 font.setItalic( true );
421 pixpaint->setFont( font );
422 pixpaint->drawText( QRect( width - 50, 5, 20, 20 ),
423 Qt::AlignLeft, ext->version );
425 // Flush paint operations
428 // Draw it on the screen!
429 painter->drawPixmap( option.rect, pix );
432 QSize ExtensionItemDelegate::sizeHint( const QStyleOptionViewItem &option,
433 const QModelIndex &index ) const
435 if (index.isValid() && index.column() == 0)
437 QFontMetrics metrics = option.fontMetrics;
438 return QSize( 200, 20 + 2 * metrics.height() );
444 /* "More information" dialog */
446 ExtensionInfoDialog::ExtensionInfoDialog( const ExtensionCopy& extension,
447 intf_thread_t *p_intf,
449 : QVLCDialog( parent, p_intf ),
450 extension( new ExtensionCopy( extension ) )
452 // Let's be a modal dialog
453 setWindowModality( Qt::WindowModal );
456 QGridLayout *layout = new QGridLayout( this );
459 QLabel *icon = new QLabel( this );
460 QPixmap pix( ":/logo/vlc48.png" );
461 icon->setPixmap( pix );
462 layout->addWidget( icon, 1, 0, 2, 1, Qt::AlignLeft );
465 QLabel *label = new QLabel( extension.title, this );
466 QFont font = label->font();
467 font.setBold( true );
468 font.setPointSizeF( font.pointSizeF() * 1.3f );
469 label->setFont( font );
470 layout->addWidget( label, 0, 0, 1, -1, Qt::AlignLeft );
473 label = new QLabel( this );
474 QString txt = qtr( "Version:" );
475 txt += extension.version;
476 label->setText( txt );
477 layout->addWidget( label, 1, 1, 1, 1, Qt::AlignLeft | Qt::AlignBottom );
480 label = new QLabel( this );
481 txt = qtr( "Author(s):" );
482 txt += extension.author;
483 label->setText( txt );
484 layout->addWidget( label, 2, 1, 1, 1, Qt::AlignLeft | Qt::AlignTop );
487 // FIXME: if( !extension.full_description.isEmpty() ) ...
488 QTextBrowser *text = new QTextBrowser( this );
489 text->setHtml( extension.description );
490 layout->addWidget( text, 4, 0, 1, -1, Qt::AlignJustify );
493 label = new QLabel( qtr( "Website:" ), this );
494 font = label->font();
495 font.setBold( true );
496 label->setFont( font );
497 layout->addWidget( label, 5, 0, 1, 1, Qt::AlignLeft );
498 label = new QLabel( extension.url, this );
499 label->setTextInteractionFlags( Qt::TextBrowserInteraction );
500 layout->addWidget( label, 5, 1, 1, 1, Qt::AlignLeft );
503 label = new QLabel( qtr( "File:" ), this );
504 label->setFont( font );
505 layout->addWidget( label, 6, 0, 1, 1, Qt::AlignLeft );
506 QLineEdit *line = new QLineEdit( extension.name, this );
507 layout->addWidget( line, 6, 1, 1, 1, Qt::AlignLeft );
510 QDialogButtonBox *group = new QDialogButtonBox( QDialogButtonBox::Close,
511 Qt::Horizontal, this );
512 layout->addWidget( group, 7, 0, 1, -1 );
513 connect( group, SIGNAL(accepted()), this, SLOT(close()) );
516 ExtensionInfoDialog::~ExtensionInfoDialog()