]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/plugins.cpp
Qt: search implementation in the plugins list dialog for fast-seeing if a module...
[vlc] / modules / gui / qt4 / dialogs / plugins.cpp
1 /*****************************************************************************
2  * plugins.hpp : Plug-ins and extensions listing
3  ****************************************************************************
4  * Copyright (C) 2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "plugins.hpp"
29
30 //#include <vlc_modules.h>
31
32 #include <QTreeWidget>
33 #include <QStringList>
34 #include <QHeaderView>
35 #include <QDialogButtonBox>
36 #include <QLineEdit>
37 #include <QLabel>
38
39 PluginDialog::PluginDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
40 {
41     setAttribute( Qt::WA_DeleteOnClose );
42
43     setWindowTitle( qtr( "Plugins and extensions" ) );
44     QGridLayout *layout = new QGridLayout( this );
45
46     /* Main Tree for modules */
47     treePlugins = new QTreeWidget;
48     layout->addWidget( treePlugins, 0, 0, 1, -1 );
49
50     /* Users cannot move the columns around but we need to sort */
51     treePlugins->header()->setMovable( false );
52     treePlugins->header()->setSortIndicatorShown( true );
53     //    treePlugins->header()->setResizeMode( QHeaderView::ResizeToContents );
54     treePlugins->setAlternatingRowColors( true );
55     treePlugins->setColumnWidth( 0, 200 );
56
57     QStringList headerNames;
58     headerNames << _("Name") << _("Capability" ) << _( "Score" );
59     treePlugins->setHeaderLabels( headerNames );
60
61     FillTree();
62
63     /* Set capability column to the correct Size*/
64     treePlugins->resizeColumnToContents( 1 );
65     treePlugins->header()->restoreState(
66             getSettings()->value( "Plugins/Header-State" ).toByteArray() );
67
68     treePlugins->setSortingEnabled( true );
69     treePlugins->sortByColumn( 1, Qt::AscendingOrder );
70
71     QLabel *label = new QLabel( _("&Search:"), this );
72     edit = new QLineEdit;
73     label->setBuddy( edit );
74
75     layout->addWidget( label, 1, 0 );
76     layout->addWidget( edit, 1, 1, 1, -1 );
77     CONNECT( edit, textChanged( QString ),
78             this, search( QString ) );
79
80     QDialogButtonBox *box = new QDialogButtonBox;
81     QPushButton *okButton = new QPushButton( "ok", this );
82     box->addButton( okButton, QDialogButtonBox::AcceptRole );
83     layout->addWidget( box, 2, 2 );
84
85     BUTTONACT( okButton, close() );
86
87     setMinimumSize( 500, 300 );
88     readSettings( "Plugins", QSize( 500, 300 ) );
89 }
90
91 inline void PluginDialog::FillTree()
92 {
93     module_t **p_list = module_list_get( NULL );
94     module_t *p_module;
95
96     for( unsigned int i = 0; (p_module = p_list[i] ) != NULL; i++ )
97     {
98         QStringList qs_item;
99         qs_item << qfu( module_get_name( p_module, true ) )
100                 << qfu( module_get_capability( p_module ) )
101                 << QString::number( module_get_score( p_module ) );
102
103         QTreeWidgetItem *item = new QTreeWidgetItem( qs_item );
104         treePlugins->addTopLevelItem( item );
105     }
106 }
107
108 void PluginDialog::search( const QString qs )
109 {
110     QList<QTreeWidgetItem *> items = treePlugins->findItems( qs, Qt::MatchContains );
111     items += treePlugins->findItems( qs, Qt::MatchContains, 1 );
112
113     QTreeWidgetItem *item = NULL;
114     for( int i = 0; i < treePlugins->topLevelItemCount(); i++ )
115     {
116         item = treePlugins->topLevelItem( i );
117         item->setHidden( !items.contains( item ) );
118     }
119 }
120
121 PluginDialog::~PluginDialog()
122 {
123     writeSettings( "Plugins" );
124     getSettings()->setValue( "Plugins/Header-State",
125                              treePlugins->header()->saveState() );
126 }
127