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