1 /*****************************************************************************
2 * plugins.hpp : Plug-ins and extensions listing
3 ****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include "plugins.hpp"
30 #include "util/customwidgets.hpp"
32 //#include <vlc_modules.h>
34 #include <QTreeWidget>
35 #include <QStringList>
36 #include <QHeaderView>
37 #include <QDialogButtonBox>
41 PluginDialog *PluginDialog::instance = NULL;
43 PluginDialog::PluginDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
45 setAttribute( Qt::WA_DeleteOnClose );
47 setWindowTitle( qtr( "Plugins and extensions" ) );
48 QGridLayout *layout = new QGridLayout( this );
50 /* Main Tree for modules */
51 treePlugins = new QTreeWidget;
52 layout->addWidget( treePlugins, 0, 0, 1, -1 );
54 /* Users cannot move the columns around but we need to sort */
55 treePlugins->header()->setMovable( false );
56 treePlugins->header()->setSortIndicatorShown( true );
57 // treePlugins->header()->setResizeMode( QHeaderView::ResizeToContents );
58 treePlugins->setAlternatingRowColors( true );
59 treePlugins->setColumnWidth( 0, 200 );
61 QStringList headerNames;
62 headerNames << qtr("Name") << qtr("Capability" ) << qtr( "Score" );
63 treePlugins->setHeaderLabels( headerNames );
67 /* Set capability column to the correct Size*/
68 treePlugins->resizeColumnToContents( 1 );
69 treePlugins->header()->restoreState(
70 getSettings()->value( "Plugins/Header-State" ).toByteArray() );
72 treePlugins->setSortingEnabled( true );
73 treePlugins->sortByColumn( 1, Qt::AscendingOrder );
75 QLabel *label = new QLabel( qtr("&Search:"), this );
76 edit = new SearchLineEdit( this );
77 label->setBuddy( edit );
79 layout->addWidget( label, 1, 0 );
80 layout->addWidget( edit, 1, 1, 1, -1 );
81 CONNECT( edit, textChanged( const QString& ),
82 this, search( const QString& ) );
84 QDialogButtonBox *box = new QDialogButtonBox;
85 QPushButton *okButton = new QPushButton( qtr( "&Close" ), this );
86 box->addButton( okButton, QDialogButtonBox::AcceptRole );
87 layout->addWidget( box, 2, 2 );
89 BUTTONACT( okButton, close() );
91 setMinimumSize( 500, 300 );
92 readSettings( "Plugins", QSize( 540, 400 ) );
95 inline void PluginDialog::FillTree()
97 module_t **p_list = module_list_get( NULL );
100 for( unsigned int i = 0; (p_module = p_list[i] ) != NULL; i++ )
103 qs_item << qfu( module_get_name( p_module, true ) )
104 << qfu( module_get_capability( p_module ) )
105 << QString::number( module_get_score( p_module ) );
107 if( qs_item.at(1).isEmpty() ) continue;
110 QTreeWidgetItem *item = new QTreeWidgetItem( qs_item );
111 treePlugins->addTopLevelItem( item );
115 void PluginDialog::search( const QString& qs )
117 QList<QTreeWidgetItem *> items = treePlugins->findItems( qs, Qt::MatchContains );
118 items += treePlugins->findItems( qs, Qt::MatchContains, 1 );
120 QTreeWidgetItem *item = NULL;
121 for( int i = 0; i < treePlugins->topLevelItemCount(); i++ )
123 item = treePlugins->topLevelItem( i );
124 item->setHidden( !items.contains( item ) );
128 PluginDialog::~PluginDialog()
130 writeSettings( "Plugins" );
131 getSettings()->setValue( "Plugins/Header-State",
132 treePlugins->header()->saveState() );