1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * - Finish implementation (see WX, there might be missing a
29 * i_action handler for IntegerLists, but I don't see any module using it...
30 * - Improvements over WX
31 * - Validator for modulelist
37 #include "components/preferences_widgets.hpp"
38 #include "util/customwidgets.hpp"
43 #include <QGridLayout>
45 #include <QFileDialog>
47 #include <QTreeWidgetItem>
48 #include <QSignalMapper>
49 #include <QDialogButtonBox>
51 #define MINWIDTH_BOX 90
52 #define LAST_COLUMN 10
54 QString formatTooltip(const QString & tooltip)
57 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
58 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
59 "<body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; "
60 "font-style:normal; text-decoration:none;\">"
61 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
62 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
68 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
69 module_config_t *p_item,
73 return createControl( p_this, p_item, parent, NULL, i );
76 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
77 module_config_t *p_item,
79 QGridLayout *l, int &line )
81 ConfigControl *p_control = NULL;
83 switch( p_item->i_type )
85 case CONFIG_ITEM_MODULE:
86 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
89 case CONFIG_ITEM_MODULE_CAT:
90 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
93 case CONFIG_ITEM_MODULE_LIST:
94 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
97 case CONFIG_ITEM_MODULE_LIST_CAT:
98 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
100 /* Special Hack for a bug in video-filter */
101 if( qobject_cast<ModuleListConfigControl *>( p_control )->groupBox == NULL )
104 case CONFIG_ITEM_STRING:
105 if( !p_item->i_list )
106 p_control = new StringConfigControl( p_this, p_item, parent,
109 p_control = new StringListConfigControl( p_this, p_item,
110 parent, false, l, line );
112 case CONFIG_ITEM_PASSWORD:
113 if( !p_item->i_list )
114 p_control = new StringConfigControl( p_this, p_item, parent,
117 p_control = new StringListConfigControl( p_this, p_item,
118 parent, true, l, line );
120 case CONFIG_ITEM_INTEGER:
122 p_control = new IntegerListConfigControl( p_this, p_item,
123 parent, false, l, line );
124 else if( p_item->min.i || p_item->max.i )
125 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
128 p_control = new IntegerConfigControl( p_this, p_item, parent,
131 case CONFIG_ITEM_FILE:
132 p_control = new FileConfigControl( p_this, p_item, parent, l,
135 case CONFIG_ITEM_DIRECTORY:
136 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
140 case CONFIG_ITEM_FONT:
141 p_control = new FontConfigControl( p_this, p_item, parent, l,
145 case CONFIG_ITEM_KEY:
146 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
148 case CONFIG_ITEM_BOOL:
149 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
151 case CONFIG_ITEM_FLOAT:
152 if( p_item->min.f || p_item->max.f )
153 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
156 p_control = new FloatConfigControl( p_this, p_item, parent,
165 void ConfigControl::doApply( intf_thread_t *p_intf )
169 case CONFIG_ITEM_INTEGER:
170 case CONFIG_ITEM_BOOL:
172 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
174 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
177 case CONFIG_ITEM_FLOAT:
179 VFloatConfigControl *vfcc =
180 qobject_cast<VFloatConfigControl *>(this);
182 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
185 case CONFIG_ITEM_STRING:
187 VStringConfigControl *vscc =
188 qobject_cast<VStringConfigControl *>(this);
190 config_PutPsz( p_intf, vscc->getName(), qtu( vscc->getValue() ) );
193 case CONFIG_ITEM_KEY:
195 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
202 /**************************************************************************
203 * String-based controls
204 *************************************************************************/
206 /*********** String **************/
207 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
208 module_config_t *_p_item,
209 QWidget *_parent, QGridLayout *l,
210 int &line, bool pwd ) :
211 VStringConfigControl( _p_this, _p_item, _parent )
213 label = new QLabel( qtr(p_item->psz_text) );
214 text = new QLineEdit( qfu(p_item->value.psz) );
215 if( pwd ) text->setEchoMode( QLineEdit::Password );
220 QHBoxLayout *layout = new QHBoxLayout();
221 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
222 layout->addWidget( text, LAST_COLUMN );
223 widget->setLayout( layout );
227 l->addWidget( label, line, 0 );
228 l->setColumnMinimumWidth( 1, 10 );
229 l->addWidget( text, line, LAST_COLUMN );
233 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
234 module_config_t *_p_item,
235 QLabel *_label, QLineEdit *_text, bool pwd ):
236 VStringConfigControl( _p_this, _p_item )
243 void StringConfigControl::finish()
245 text->setText( qfu(p_item->value.psz) );
246 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
248 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
251 /*********** File **************/
252 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
253 module_config_t *_p_item,
254 QWidget *_parent, QGridLayout *l,
255 int &line, bool pwd ) :
256 VStringConfigControl( _p_this, _p_item, _parent )
258 label = new QLabel( qtr(p_item->psz_text) );
259 text = new QLineEdit( qfu(p_item->value.psz) );
260 browse = new QPushButton( qtr( "Browse..." ) );
261 QHBoxLayout *textAndButton = new QHBoxLayout();
262 textAndButton->setMargin( 0 );
263 textAndButton->addWidget( text, 2 );
264 textAndButton->addWidget( browse, 0 );
266 BUTTONACT( browse, updateField() );
272 QHBoxLayout *layout = new QHBoxLayout();
273 layout->addWidget( label, 0 );
274 layout->insertSpacing( 1, 10 );
275 layout->addLayout( textAndButton, LAST_COLUMN );
276 widget->setLayout( layout );
280 l->addWidget( label, line, 0 );
281 l->setColumnMinimumWidth( 1, 10 );
282 l->addLayout( textAndButton, line, LAST_COLUMN );
287 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
288 module_config_t *_p_item,
289 QLabel *_label, QLineEdit *_text,
290 QPushButton *_button, bool pwd ):
291 VStringConfigControl( _p_this, _p_item )
297 BUTTONACT( browse, updateField() );
302 void FileConfigControl::updateField()
304 QString file = QFileDialog::getOpenFileName( NULL,
305 qtr( "Select File" ), qfu( config_GetHomeDir() ) );
306 if( file.isNull() ) return;
307 text->setText( file );
310 void FileConfigControl::finish()
312 text->setText( qfu(p_item->value.psz) );
313 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
315 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
318 /********* String / Directory **********/
319 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
320 module_config_t *_p_item, QWidget *_p_widget,
321 QGridLayout *_p_layout, int& _int, bool _pwd ) :
322 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
325 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
326 module_config_t *_p_item, QLabel *_p_label,
327 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
328 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
331 void DirectoryConfigControl::updateField()
333 QString dir = QFileDialog::getExistingDirectory( NULL,
334 qtr( "Select Directory" ),
335 text->text().isEmpty() ?
336 qfu( config_GetHomeDir() ) : text->text(),
337 QFileDialog::ShowDirsOnly |
338 QFileDialog::DontResolveSymlinks );
339 if( dir.isNull() ) return;
340 text->setText( dir );
344 #include <QFontDialog>
346 /********* String / Font **********/
347 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
348 module_config_t *_p_item, QWidget *_p_widget,
349 QGridLayout *_p_layout, int& _int, bool _pwd ) :
350 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
353 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
354 module_config_t *_p_item, QLabel *_p_label,
355 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
356 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
359 void FontConfigControl::updateField()
362 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
364 text->setText( font.family() );
368 /********* String / choice list **********/
369 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
370 module_config_t *_p_item, QWidget *_parent, bool bycat,
371 QGridLayout *l, int &line) :
372 VStringConfigControl( _p_this, _p_item, _parent )
374 label = new QLabel( qtr(p_item->psz_text) );
375 combo = new QComboBox();
376 combo->setMinimumWidth( MINWIDTH_BOX );
377 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
379 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
380 if(p_module_config && p_module_config->pf_update_list)
383 val.psz_string = strdup(p_module_config->value.psz);
385 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
387 // assume in any case that dirty was set to true
388 // because lazy programmes will use the same callback for
389 // this, like the one behind the refresh push button?
390 p_module_config->b_dirty = false;
392 free( val.psz_string );
395 finish( p_module_config, bycat );
398 l = new QGridLayout();
399 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
400 widget->setLayout( l );
404 l->addWidget( label, line, 0 );
405 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
408 if( p_item->i_action )
410 QSignalMapper *signalMapper = new QSignalMapper(this);
412 /* Some stringLists like Capture listings have action associated */
413 for( int i = 0; i < p_item->i_action; i++ )
415 QPushButton *button =
416 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
417 CONNECT( button, clicked(), signalMapper, map() );
418 signalMapper->setMapping( button, i );
419 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
422 CONNECT( signalMapper, mapped( int ),
423 this, actionRequested( int ) );
427 void StringListConfigControl::actionRequested( int i_action )
429 /* Supplementary check for boundaries */
430 if( i_action < 0 || i_action >= p_item->i_action ) return;
432 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
433 if(!p_module_config) return;
437 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
439 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
441 if( p_module_config->b_dirty )
444 finish( p_module_config, true );
445 p_module_config->b_dirty = false;
448 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
449 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
450 bool bycat ) : VStringConfigControl( _p_this, _p_item )
455 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
457 finish( p_module_config, bycat );
460 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
462 combo->setEditable( false );
464 if(!p_module_config) return;
466 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
468 combo->addItem( qfu((p_module_config->ppsz_list_text &&
469 p_module_config->ppsz_list_text[i_index])?
470 p_module_config->ppsz_list_text[i_index] :
471 p_module_config->ppsz_list[i_index] ),
472 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
473 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
474 p_module_config->ppsz_list[i_index] ) )
475 combo->setCurrentIndex( combo->count() - 1 );
477 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
479 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
482 QString StringListConfigControl::getValue()
484 return combo->itemData( combo->currentIndex() ).toString();
487 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
488 QComboBox *combo, QWidget *parent )
490 module_config_t *p_config =
491 config_FindConfig( VLC_OBJECT(p_intf), configname );
494 if(p_config->pf_update_list)
497 val.i_int = p_config->value.i;
498 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
499 // assume in any case that dirty was set to true
500 // because lazy programmes will use the same callback for
501 // this, like the one behind the refresh push button?
502 p_config->b_dirty = false;
505 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
507 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
508 QVariant( p_config->pi_list[i_index] ) );
509 if( p_config->value.i == p_config->pi_list[i_index] )
511 combo->setCurrentIndex( i_index );
514 combo->setToolTip( qfu( p_config->psz_longtext ) );
518 /********* Module **********/
519 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
520 module_config_t *_p_item, QWidget *_parent, bool bycat,
521 QGridLayout *l, int &line) :
522 VStringConfigControl( _p_this, _p_item, _parent )
524 label = new QLabel( qtr(p_item->psz_text) );
525 combo = new QComboBox();
526 combo->setMinimumWidth( MINWIDTH_BOX );
530 QHBoxLayout *layout = new QHBoxLayout();
531 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
532 widget->setLayout( layout );
536 l->addWidget( label, line, 0 );
537 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
541 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
542 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
543 bool bycat ) : VStringConfigControl( _p_this, _p_item )
550 void ModuleConfigControl::finish( bool bycat )
555 combo->setEditable( false );
557 /* build a list of available modules */
558 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
559 combo->addItem( qtr("Default") );
560 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
562 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
566 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
569 module_config_t *p_config;
571 p_config = module_GetConfig (p_parser, &confsize);
572 for (size_t i = 0; i < confsize; i++)
574 /* Hack: required subcategory is stored in i_min */
575 const module_config_t *p_cfg = p_config + i;
576 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
577 p_cfg->value.i == p_item->min.i )
578 combo->addItem( qtr( module_GetLongName( p_parser )),
579 QVariant( module_GetObjName( p_parser ) ) );
580 if( p_item->value.psz && !strcmp( p_item->value.psz,
581 module_GetObjName( p_parser ) ) )
582 combo->setCurrentIndex( combo->count() - 1 );
584 module_PutConfig (p_config);
586 else if( module_IsCapable( p_parser, p_item->psz_type ) )
588 combo->addItem( qtr(module_GetLongName( p_parser ) ),
589 QVariant( module_GetObjName( p_parser ) ) );
590 if( p_item->value.psz && !strcmp( p_item->value.psz,
591 module_GetObjName( p_parser ) ) )
592 combo->setCurrentIndex( combo->count() - 1 );
595 vlc_list_release( p_list );
596 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
598 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
601 QString ModuleConfigControl::getValue()
603 return combo->itemData( combo->currentIndex() ).toString();
606 /********* Module list **********/
607 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
608 module_config_t *_p_item, QWidget *_parent, bool bycat,
609 QGridLayout *l, int &line) :
610 VStringConfigControl( _p_this, _p_item, _parent )
614 if( !p_item->psz_text ) return;
616 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
617 text = new QLineEdit;
618 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
623 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
624 it != modules.end(); it++ )
626 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
628 layoutGroupBox->addWidget( text, boxline, 0 );
632 QVBoxLayout *layout = new QVBoxLayout();
633 layout->addWidget( groupBox, line, 0 );
634 widget->setLayout( layout );
638 l->addWidget( groupBox, line, 0, 1, -1 );
641 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
644 ModuleListConfigControl::~ModuleListConfigControl()
646 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
647 it != modules.end(); it++ )
654 #define CHECKBOX_LISTS \
656 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
657 checkBoxListItem *cbl = new checkBoxListItem; \
659 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
660 cb->setToolTip( formatTooltip( qtr( module_GetHelp( p_parser ))));\
661 cbl->checkBox = cb; \
663 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
664 modules.push_back( cbl ); \
666 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
667 cbl->checkBox->setChecked( true ); \
671 void ModuleListConfigControl::finish( bool bycat )
676 /* build a list of available modules */
677 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
678 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
680 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
684 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
687 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
689 for (size_t i = 0; i < confsize; i++)
691 module_config_t *p_cfg = p_config + i;
692 /* Hack: required subcategory is stored in i_min */
693 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
694 p_cfg->value.i == p_item->min.i )
699 module_PutConfig (p_config);
701 else if( module_IsCapable( p_parser, p_item->psz_type ) )
706 vlc_list_release( p_list );
707 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
709 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
711 #undef CHECKBOX_LISTS
713 QString ModuleListConfigControl::getValue()
719 void ModuleListConfigControl::hide()
721 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
722 it != modules.end(); it++ )
724 (*it)->checkBox->hide();
729 void ModuleListConfigControl::show()
731 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
732 it != modules.end(); it++ )
734 (*it)->checkBox->show();
740 void ModuleListConfigControl::onUpdate( int value )
745 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
746 it != modules.end(); it++ )
748 if( (*it)->checkBox->isChecked() )
752 text->setText( text->text() + (*it)->psz_module );
757 text->setText( text->text() + ":" + (*it)->psz_module );
763 /**************************************************************************
764 * Integer-based controls
765 *************************************************************************/
767 /*********** Integer **************/
768 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
769 module_config_t *_p_item,
770 QWidget *_parent, QGridLayout *l,
772 VIntConfigControl( _p_this, _p_item, _parent )
774 label = new QLabel( qtr(p_item->psz_text) );
775 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
776 spin->setAlignment( Qt::AlignRight );
777 spin->setMaximumWidth( MINWIDTH_BOX );
782 QHBoxLayout *layout = new QHBoxLayout();
783 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
784 widget->setLayout( layout );
788 l->addWidget( label, line, 0 );
789 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
792 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
793 module_config_t *_p_item,
794 QLabel *_label, QSpinBox *_spin ) :
795 VIntConfigControl( _p_this, _p_item )
802 void IntegerConfigControl::finish()
804 spin->setMaximum( 2000000000 );
805 spin->setMinimum( -2000000000 );
806 spin->setValue( p_item->value.i );
807 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
809 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
812 int IntegerConfigControl::getValue()
814 return spin->value();
817 /********* Integer range **********/
818 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
819 module_config_t *_p_item,
820 QWidget *_parent, QGridLayout *l,
822 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
827 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
828 module_config_t *_p_item,
829 QLabel *_label, QSpinBox *_spin ) :
830 IntegerConfigControl( _p_this, _p_item, _label, _spin )
835 void IntegerRangeConfigControl::finish()
837 spin->setMaximum( p_item->max.i );
838 spin->setMinimum( p_item->min.i );
841 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
842 vlc_object_t *_p_this,
843 module_config_t *_p_item,
844 QLabel *_label, QSlider *_slider ):
845 VIntConfigControl( _p_this, _p_item )
849 slider->setMaximum( p_item->max.i );
850 slider->setMinimum( p_item->min.i );
851 slider->setValue( p_item->value.i );
852 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
854 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
857 int IntegerRangeSliderConfigControl::getValue()
859 return slider->value();
863 /********* Integer / choice list **********/
864 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
865 module_config_t *_p_item, QWidget *_parent, bool bycat,
866 QGridLayout *l, int &line) :
867 VIntConfigControl( _p_this, _p_item, _parent )
869 label = new QLabel( qtr(p_item->psz_text) );
870 combo = new QComboBox();
871 combo->setMinimumWidth( MINWIDTH_BOX );
873 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
874 if(p_module_config && p_module_config->pf_update_list)
877 val.i_int = p_module_config->value.i;
879 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
881 // assume in any case that dirty was set to true
882 // because lazy programmes will use the same callback for
883 // this, like the one behind the refresh push button?
884 p_module_config->b_dirty = false;
888 finish( p_module_config, bycat );
891 QHBoxLayout *layout = new QHBoxLayout();
892 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
893 widget->setLayout( layout );
897 l->addWidget( label, line, 0 );
898 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
901 if( p_item->i_action )
903 QSignalMapper *signalMapper = new QSignalMapper(this);
905 /* Some stringLists like Capture listings have action associated */
906 for( int i = 0; i < p_item->i_action; i++ )
908 QPushButton *button =
909 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
910 CONNECT( button, clicked(), signalMapper, map() );
911 signalMapper->setMapping( button, i );
912 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
915 CONNECT( signalMapper, mapped( int ),
916 this, actionRequested( int ) );
920 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
921 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
922 bool bycat ) : VIntConfigControl( _p_this, _p_item )
927 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
929 finish( p_module_config, bycat );
932 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
934 combo->setEditable( false );
936 if(!p_module_config) return;
938 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
940 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
941 QVariant( p_module_config->pi_list[i_index] ) );
942 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
943 combo->setCurrentIndex( combo->count() - 1 );
945 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
947 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
950 void IntegerListConfigControl::actionRequested( int i_action )
952 /* Supplementary check for boundaries */
953 if( i_action < 0 || i_action >= p_item->i_action ) return;
955 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
956 if(!p_module_config) return;
960 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
962 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
964 if( p_module_config->b_dirty )
967 finish( p_module_config, true );
968 p_module_config->b_dirty = false;
972 int IntegerListConfigControl::getValue()
974 return combo->itemData( combo->currentIndex() ).toInt();
977 /*********** Boolean **************/
978 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
979 module_config_t *_p_item,
980 QWidget *_parent, QGridLayout *l,
982 VIntConfigControl( _p_this, _p_item, _parent )
984 checkbox = new QCheckBox( qtr(p_item->psz_text) );
989 QHBoxLayout *layout = new QHBoxLayout();
990 layout->addWidget( checkbox, 0 );
991 widget->setLayout( layout );
995 l->addWidget( checkbox, line, 0 );
998 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
999 module_config_t *_p_item,
1001 QCheckBox *_checkbox,
1003 VIntConfigControl( _p_this, _p_item )
1005 checkbox = _checkbox;
1009 void BoolConfigControl::finish()
1011 checkbox->setCheckState( p_item->value.i == true ? Qt::Checked
1013 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1016 int BoolConfigControl::getValue()
1018 return checkbox->checkState() == Qt::Checked ? true : false;
1021 /**************************************************************************
1022 * Float-based controls
1023 *************************************************************************/
1025 /*********** Float **************/
1026 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1027 module_config_t *_p_item,
1028 QWidget *_parent, QGridLayout *l,
1030 VFloatConfigControl( _p_this, _p_item, _parent )
1032 label = new QLabel( qtr(p_item->psz_text) );
1033 spin = new QDoubleSpinBox;
1034 spin->setMinimumWidth( MINWIDTH_BOX );
1035 spin->setMaximumWidth( MINWIDTH_BOX );
1036 spin->setAlignment( Qt::AlignRight );
1041 QHBoxLayout *layout = new QHBoxLayout();
1042 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1043 widget->setLayout( layout );
1047 l->addWidget( label, line, 0 );
1048 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1052 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1053 module_config_t *_p_item,
1055 QDoubleSpinBox *_spin ) :
1056 VFloatConfigControl( _p_this, _p_item )
1063 void FloatConfigControl::finish()
1065 spin->setMaximum( 2000000000. );
1066 spin->setMinimum( -2000000000. );
1067 spin->setSingleStep( 0.1 );
1068 spin->setValue( (double)p_item->value.f );
1069 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1071 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1074 float FloatConfigControl::getValue()
1076 return (float)spin->value();
1079 /*********** Float with range **************/
1080 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1081 module_config_t *_p_item,
1082 QWidget *_parent, QGridLayout *l,
1084 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1089 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1090 module_config_t *_p_item,
1092 QDoubleSpinBox *_spin ) :
1093 FloatConfigControl( _p_this, _p_item, _label, _spin )
1098 void FloatRangeConfigControl::finish()
1100 spin->setMaximum( (double)p_item->max.f );
1101 spin->setMinimum( (double)p_item->min.f );
1105 /**********************************************************************
1106 * Key selector widget
1107 **********************************************************************/
1108 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1109 module_config_t *_p_item,
1110 QWidget *_parent, QGridLayout *l,
1112 ConfigControl( _p_this, _p_item, _parent )
1115 QWidget *keyContainer = new QWidget;
1116 QGridLayout *gLayout = new QGridLayout( keyContainer );
1119 qtr( "Select an action to change the associated hotkey") );
1121 /* Deactivated for now
1122 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1123 QLineEdit *actionSearch = new QLineEdit;*/
1125 table = new QTreeWidget;
1126 table->setColumnCount(2);
1127 table->headerItem()->setText( 0, qtr( "Action" ) );
1128 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1130 shortcutValue = new KeyShortcutEdit;
1131 shortcutValue->setReadOnly(true);
1133 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1134 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1135 setButton->setDefault( true );
1138 gLayout->addWidget( label, 0, 0, 1, 4 );
1139 /* deactivated for now
1140 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1141 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1142 gLayout->addWidget( table, 2, 0, 1, 4 );
1143 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1144 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1145 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1147 l->addWidget( keyContainer, line, 0, 1, 2 );
1149 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1150 CONNECT( clearButton, clicked(), this, setTheKey() );
1151 BUTTONACT( setButton, setTheKey() );
1154 void KeySelectorControl::finish()
1157 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1159 /* Fill the table */
1160 table->setColumnCount( 2 );
1161 table->setAlternatingRowColors( true );
1163 /* Get the main Module */
1164 module_t *p_main = module_Find( p_this, "main" );
1167 /* Access to the module_config_t */
1169 module_config_t *p_config;
1171 p_config = module_GetConfig (p_main, &confsize);
1173 for (size_t i = 0; i < confsize; i++)
1175 module_config_t *p_item = p_config + i;
1177 /* If we are a key option not empty */
1178 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1179 && strstr( p_item->psz_name , "key-" )
1180 && !EMPTY_STR( p_item->psz_text ) )
1184 - QString text in column 0
1185 - QString name in data of column 0
1186 - KeyValue in String in column 1
1187 - KeyValue in int in column 1
1189 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1190 treeItem->setText( 0, qtr( p_item->psz_text ) );
1191 treeItem->setData( 0, Qt::UserRole,
1192 QVariant( qfu( p_item->psz_name ) ) );
1193 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1194 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1195 table->addTopLevelItem( treeItem );
1198 module_PutConfig (p_config);
1199 module_Put (p_main);
1201 table->resizeColumnToContents( 0 );
1203 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1204 this, selectKey( QTreeWidgetItem * ) );
1205 CONNECT( table, itemSelectionChanged (),
1206 this, select1Key() );
1208 CONNECT( shortcutValue, pressed(), this, selectKey() );
1211 /* Show the key selected from the table in the keySelector */
1212 void KeySelectorControl::select1Key()
1214 QTreeWidgetItem *keyItem = table->currentItem();
1215 shortcutValue->setText( keyItem->text( 1 ) );
1216 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1219 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1221 /* This happens when triggered by ClickEater */
1222 if( keyItem == NULL ) keyItem = table->currentItem();
1224 /* This can happen when nothing is selected on the treeView
1225 and the shortcutValue is clicked */
1226 if( !keyItem ) return;
1228 /* Launch a small dialog to ask for a new key */
1229 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget );
1232 if( d->result() == QDialog::Accepted )
1234 int newValue = d->keyValue;
1235 shortcutValue->setText( VLCKeyToString( newValue ) );
1236 shortcutValue->setValue( newValue );
1240 QTreeWidgetItem *it;
1241 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1243 it = table->topLevelItem(i);
1244 if( ( keyItem != it )
1245 && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) )
1247 it->setData( 1, Qt::UserRole, QVariant( -1 ) );
1248 it->setText( 1, qtr( "Unset" ) );
1251 /* We already made an OK once. */
1258 void KeySelectorControl::setTheKey()
1260 table->currentItem()->setText( 1, shortcutValue->text() );
1261 table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );
1264 void KeySelectorControl::doApply()
1266 QTreeWidgetItem *it;
1267 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1269 it = table->topLevelItem(i);
1270 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1271 config_PutInt( p_this,
1272 qtu( it->data( 0, Qt::UserRole ).toString() ),
1273 it->data( 1, Qt::UserRole ).toInt() );
1277 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1278 QString keyToChange,
1279 QWidget *_parent ) :
1280 QDialog( _parent ), keyValue(0)
1286 setWindowTitle( qtr( "Hotkey for " ) + keyToChange );
1288 vLayout = new QVBoxLayout( this );
1289 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1290 vLayout->addWidget( selected , Qt::AlignCenter );
1292 buttonBox = new QDialogButtonBox;
1293 QPushButton *ok = new QPushButton( qtr("OK") );
1294 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1295 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1296 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1297 ok->setDefault( true );
1299 vLayout->addWidget( buttonBox );
1302 CONNECT( buttonBox, accepted(), this, accept() );
1303 CONNECT( buttonBox, rejected(), this, reject() );
1306 void KeyInputDialog::checkForConflicts( int i_vlckey )
1308 QList<QTreeWidgetItem *> conflictList =
1309 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 );
1311 if( conflictList.size() )
1313 QLabel *warning = new QLabel(
1314 qtr("Warning: the key is already assigned to \"") +
1315 conflictList[0]->text( 0 ) + "\"" );
1316 vLayout->insertWidget( 1, warning );
1324 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1326 if( e->key() == Qt::Key_Tab ||
1327 e->key() == Qt::Key_Shift ||
1328 e->key() == Qt::Key_Control ||
1329 e->key() == Qt::Key_Meta ||
1330 e->key() == Qt::Key_Alt ||
1331 e->key() == Qt::Key_AltGr )
1333 int i_vlck = qtEventToVLCKey( e );
1334 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1335 checkForConflicts( i_vlck );
1339 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1341 int i_vlck = qtWheelEventToVLCKey( e );
1342 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1343 checkForConflicts( i_vlck );
1347 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)