]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.cpp
Skeleton for preferences widgets
[vlc] / modules / gui / qt4 / components / preferences_widgets.cpp
1 /*****************************************************************************
2  * preferences_widgets.cpp : Widgets for preferences displays
3  ****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@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 #include "components/preferences_widgets.hpp"
25
26 #include <QLineEdit>
27 #include <QString>
28 #include <QSpinBox>
29 #include <QDoubleSpinBox>
30 #include <QVariant>
31 #include <QComboBox>
32
33 ConfigControl::ConfigControl( vlc_object_t *_p_this, module_config_t *p_item,
34                               QWidget *_parent ) : QWidget( _parent ),
35                               p_this( _p_this ), _name( p_item->psz_name )
36 {
37 }
38
39 ConfigControl::~ConfigControl() {}
40
41 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
42                                     module_config_t *p_item, QWidget *parent )
43 {
44     ConfigControl *p_control = NULL;
45     if( p_item->psz_current ) return NULL;
46
47     switch( p_item->i_type )
48     {
49     case CONFIG_ITEM_MODULE:
50         p_control = new ModuleConfigControl( p_this, p_item, parent, false );
51         break;
52     case CONFIG_ITEM_MODULE_CAT:
53         p_control = new ModuleConfigControl( p_this, p_item, parent, true );
54         break;
55     case CONFIG_ITEM_STRING:
56         if( !p_item->i_list )
57             p_control = new StringConfigControl( p_this, p_item, parent,false );
58         else
59             abort();
60         break;
61     default:
62         break;
63     }
64     return p_control;
65 }
66
67 /**************************************************************************
68  * String-based controls
69  *************************************************************************/
70
71 /*********** String **************/
72 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
73                      module_config_t *p_item, QWidget *_parent, bool pwd )
74                            : VStringConfigControl( _p_this, p_item, _parent )
75 {
76     QLabel *label = new QLabel( p_item->psz_text );
77     text = new QLineEdit( p_item->psz_value );
78     text->setToolTip( p_item->psz_longtext );
79     label->setToolTip( p_item->psz_longtext );
80
81     QHBoxLayout *layout = new QHBoxLayout();
82     layout->addWidget( label ); layout->addWidget( text );
83     setLayout( layout );
84 }
85
86 StringConfigControl::~StringConfigControl() {}
87
88 QString StringConfigControl::getValue() { return text->text(); };
89
90
91 /********* Module **********/
92 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
93                 module_config_t *p_item, QWidget *_parent,
94                 bool bycat ) : VStringConfigControl( _p_this, p_item, _parent )
95 {
96     vlc_list_t *p_list;
97     module_t *p_parser;
98
99     QLabel *label = new QLabel( p_item->psz_text );
100     combo = new QComboBox();
101     combo->setEditable( false );
102
103     /* build a list of available modules */
104     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
105     combo->addItem( "Default" );
106     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
107     {
108         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
109
110         if( bycat )
111         {
112             if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
113
114             module_config_t *p_config = p_parser->p_config;
115             if( p_config ) do
116             {
117                 /* Hack: required subcategory is stored in i_min */
118                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
119                     p_config->i_value == p_item->i_min )
120                     combo->addItem( p_parser->psz_longname,
121                                     QVariant( p_parser->psz_object_name ) );
122                 if( p_item->psz_value && !strcmp( p_item->psz_value,
123                                                   p_parser->psz_object_name) )
124                     combo->setCurrentIndex( combo->count() - 1 );
125             } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
126         }
127         else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
128         {
129             combo->addItem( p_parser->psz_longname,
130                             QVariant( p_parser->psz_object_name ) );
131             if( p_item->psz_value && !strcmp( p_item->psz_value,
132                                               p_parser->psz_object_name) )
133                 combo->setCurrentIndex( combo->count() - 1 );
134         }
135     }
136     vlc_list_release( p_list );
137     combo->setToolTip( p_item->psz_longtext );
138     label->setToolTip( p_item->psz_longtext );
139
140     QHBoxLayout *layout = new QHBoxLayout();
141     layout->addWidget( label ); layout->addWidget( combo );
142     setLayout( layout );
143 }
144
145 ModuleConfigControl::~ModuleConfigControl() {};
146
147 QString ModuleConfigControl::getValue()
148 {
149     return combo->itemData( combo->currentIndex() ).toString();
150 }