]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/plugins.cpp
Qt: New dialog for plugins listing.
[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
37 PluginDialog::PluginDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
38 {
39     setAttribute( Qt::WA_DeleteOnClose );
40
41     setWindowTitle( qtr( "Plugins and extensions" ) );
42     QGridLayout *layout = new QGridLayout( this );
43
44     /* Main Tree for modules */
45     treePlugins = new QTreeWidget;
46     layout->addWidget( treePlugins, 0, 0, 1, -1 );
47
48     /* Users cannot move the columns around but we need to sort */
49     treePlugins->header()->setMovable( false );
50     treePlugins->header()->setSortIndicatorShown( true );
51     //    treePlugins->header()->setResizeMode( QHeaderView::ResizeToContents );
52     treePlugins->setAlternatingRowColors( true );
53     treePlugins->setColumnWidth( 0, 200 );
54
55     QStringList headerNames;
56     headerNames << _("Name") << _("Capability" ) << _( "Score" );
57     treePlugins->setHeaderLabels( headerNames );
58
59     FillTree();
60
61     /* Set capability column to the correct Size*/
62     treePlugins->resizeColumnToContents( 1 );
63     treePlugins->header()->restoreState(
64             getSettings()->value( "Plugins/Header-State" ).toByteArray() );
65
66     treePlugins->setSortingEnabled( true );
67     treePlugins->sortByColumn( 1, Qt::AscendingOrder );
68
69     QDialogButtonBox *box = new QDialogButtonBox;
70     QPushButton *okButton = new QPushButton( "ok", this );
71     box->addButton( okButton, QDialogButtonBox::AcceptRole );
72     layout->addWidget( box, 1, 2 );
73
74     BUTTONACT( okButton, close() );
75
76     setMinimumSize( 500, 300 );
77     readSettings( "Plugins", QSize( 500, 300 ) );
78 }
79
80 inline void PluginDialog::FillTree()
81 {
82     module_t **p_list = module_list_get( NULL );
83     module_t *p_module;
84
85     for( unsigned int i = 0; (p_module = p_list[i] ) != NULL; i++ )
86     {
87         QStringList qs_item;
88         qs_item << module_get_name( p_module, true )
89                 << module_get_capability( p_module )
90                 << QString::number( module_get_score( p_module ) );
91
92         QTreeWidgetItem *item = new QTreeWidgetItem( qs_item );
93         treePlugins->addTopLevelItem( item );
94     }
95 }
96
97 PluginDialog::~PluginDialog()
98 {
99     writeSettings( "Plugins" );
100     getSettings()->setValue( "Plugins/Header-State",
101                              treePlugins->header()->saveState() );
102 }
103