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,
101 case CONFIG_ITEM_STRING:
102 if( !p_item->i_list )
103 p_control = new StringConfigControl( p_this, p_item, parent,
106 p_control = new StringListConfigControl( p_this, p_item,
107 parent, false, l, line );
109 case CONFIG_ITEM_PASSWORD:
110 if( !p_item->i_list )
111 p_control = new StringConfigControl( p_this, p_item, parent,
114 p_control = new StringListConfigControl( p_this, p_item,
115 parent, true, l, line );
117 case CONFIG_ITEM_INTEGER:
119 p_control = new IntegerListConfigControl( p_this, p_item,
120 parent, false, l, line );
121 else if( p_item->min.i || p_item->max.i )
122 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
125 p_control = new IntegerConfigControl( p_this, p_item, parent,
128 case CONFIG_ITEM_FILE:
129 p_control = new FileConfigControl( p_this, p_item, parent, l,
132 case CONFIG_ITEM_DIRECTORY:
133 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
137 case CONFIG_ITEM_FONT:
138 p_control = new FontConfigControl( p_this, p_item, parent, l,
142 case CONFIG_ITEM_KEY:
143 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
145 case CONFIG_ITEM_BOOL:
146 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
148 case CONFIG_ITEM_FLOAT:
149 if( p_item->min.f || p_item->max.f )
150 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
153 p_control = new FloatConfigControl( p_this, p_item, parent,
162 void ConfigControl::doApply( intf_thread_t *p_intf )
166 case CONFIG_ITEM_INTEGER:
167 case CONFIG_ITEM_BOOL:
169 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
171 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
174 case CONFIG_ITEM_FLOAT:
176 VFloatConfigControl *vfcc =
177 qobject_cast<VFloatConfigControl *>(this);
179 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
182 case CONFIG_ITEM_STRING:
184 VStringConfigControl *vscc =
185 qobject_cast<VStringConfigControl *>(this);
187 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
190 case CONFIG_ITEM_KEY:
192 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
199 /**************************************************************************
200 * String-based controls
201 *************************************************************************/
203 /*********** String **************/
204 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
205 module_config_t *_p_item,
206 QWidget *_parent, QGridLayout *l,
207 int &line, bool pwd ) :
208 VStringConfigControl( _p_this, _p_item, _parent )
210 label = new QLabel( qtr(p_item->psz_text) );
211 text = new QLineEdit( qfu(p_item->value.psz) );
212 if( pwd ) text->setEchoMode( QLineEdit::Password );
217 QHBoxLayout *layout = new QHBoxLayout();
218 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
219 layout->addWidget( text, LAST_COLUMN );
220 widget->setLayout( layout );
224 l->addWidget( label, line, 0 );
225 l->setColumnMinimumWidth( 1, 10 );
226 l->addWidget( text, line, LAST_COLUMN );
230 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
231 module_config_t *_p_item,
232 QLabel *_label, QLineEdit *_text, bool pwd ):
233 VStringConfigControl( _p_this, _p_item )
240 void StringConfigControl::finish()
242 text->setText( qfu(p_item->value.psz) );
243 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
245 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
248 /*********** File **************/
249 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
250 module_config_t *_p_item,
251 QWidget *_parent, QGridLayout *l,
252 int &line, bool pwd ) :
253 VStringConfigControl( _p_this, _p_item, _parent )
255 label = new QLabel( qtr(p_item->psz_text) );
256 text = new QLineEdit( qfu(p_item->value.psz) );
257 browse = new QPushButton( qtr( "Browse..." ) );
258 QHBoxLayout *textAndButton = new QHBoxLayout();
259 textAndButton->setMargin( 0 );
260 textAndButton->addWidget( text, 2 );
261 textAndButton->addWidget( browse, 0 );
263 BUTTONACT( browse, updateField() );
269 QHBoxLayout *layout = new QHBoxLayout();
270 layout->addWidget( label, 0 );
271 layout->insertSpacing( 1, 10 );
272 layout->addLayout( textAndButton, LAST_COLUMN );
273 widget->setLayout( layout );
277 l->addWidget( label, line, 0 );
278 l->setColumnMinimumWidth( 1, 10 );
279 l->addLayout( textAndButton, line, LAST_COLUMN );
284 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
285 module_config_t *_p_item,
286 QLabel *_label, QLineEdit *_text,
287 QPushButton *_button, bool pwd ):
288 VStringConfigControl( _p_this, _p_item )
294 BUTTONACT( browse, updateField() );
299 void FileConfigControl::updateField()
301 QString file = QFileDialog::getOpenFileName( NULL,
302 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
303 if( file.isNull() ) return;
304 text->setText( file );
307 void FileConfigControl::finish()
309 text->setText( qfu(p_item->value.psz) );
310 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
312 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
315 /********* String / Directory **********/
316 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
317 module_config_t *_p_item, QWidget *_p_widget,
318 QGridLayout *_p_layout, int& _int, bool _pwd ) :
319 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
322 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
323 module_config_t *_p_item, QLabel *_p_label,
324 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
325 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
328 void DirectoryConfigControl::updateField()
330 QString dir = QFileDialog::getExistingDirectory( NULL,
331 qtr( "Select Directory" ),
332 text->text().isEmpty() ?
333 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
334 QFileDialog::ShowDirsOnly |
335 QFileDialog::DontResolveSymlinks );
336 if( dir.isNull() ) return;
337 text->setText( dir );
341 #include <QFontDialog>
343 /********* String / Font **********/
344 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
345 module_config_t *_p_item, QWidget *_p_widget,
346 QGridLayout *_p_layout, int& _int, bool _pwd ) :
347 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
350 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
351 module_config_t *_p_item, QLabel *_p_label,
352 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
353 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
356 void FontConfigControl::updateField()
359 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
361 text->setText( font.family() );
365 /********* String / choice list **********/
366 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
367 module_config_t *_p_item, QWidget *_parent, bool bycat,
368 QGridLayout *l, int &line) :
369 VStringConfigControl( _p_this, _p_item, _parent )
371 label = new QLabel( qtr(p_item->psz_text) );
372 combo = new QComboBox();
373 combo->setMinimumWidth( MINWIDTH_BOX );
374 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
376 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
377 if(p_module_config && p_module_config->pf_update_list)
380 val.psz_string = strdup(p_module_config->value.psz);
382 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
384 // assume in aĂ—y case that dirty was set to VLC_TRUE
385 // because lazy programmes will use the same callback for
386 // this, like the one behind the refresh push button?
387 p_module_config->b_dirty = VLC_FALSE;
389 free( val.psz_string );
392 finish( p_module_config, bycat );
395 l = new QGridLayout();
396 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
397 widget->setLayout( l );
401 l->addWidget( label, line, 0 );
402 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
405 if( p_item->i_action )
407 QSignalMapper *signalMapper = new QSignalMapper(this);
409 /* Some stringLists like Capture listings have action associated */
410 for( int i = 0; i < p_item->i_action; i++ )
412 QPushButton *button =
413 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
414 CONNECT( button, clicked(), signalMapper, map() );
415 signalMapper->setMapping( button, i );
416 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
419 CONNECT( signalMapper, mapped( int ),
420 this, actionRequested( int ) );
424 void StringListConfigControl::actionRequested( int i_action )
426 /* Supplementary check for boundaries */
427 if( i_action < 0 || i_action >= p_item->i_action ) return;
429 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
430 if(!p_module_config) return;
434 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
436 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
438 if( p_module_config->b_dirty )
441 finish( p_module_config, true );
442 p_module_config->b_dirty = VLC_FALSE;
445 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
446 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
447 bool bycat ) : VStringConfigControl( _p_this, _p_item )
452 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
454 finish( p_module_config, bycat );
457 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
459 combo->setEditable( false );
461 if(!p_module_config) return;
463 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
465 combo->addItem( qfu(p_module_config->ppsz_list_text ?
466 p_module_config->ppsz_list_text[i_index] :
467 p_module_config->ppsz_list[i_index] ),
468 QVariant( p_module_config->ppsz_list[i_index] ) );
469 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
470 p_module_config->ppsz_list[i_index] ) )
471 combo->setCurrentIndex( combo->count() - 1 );
473 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
475 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
478 QString StringListConfigControl::getValue()
480 return combo->itemData( combo->currentIndex() ).toString();
483 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
484 QComboBox *combo, QWidget *parent )
486 module_config_t *p_config =
487 config_FindConfig( VLC_OBJECT(p_intf), configname );
490 if(p_config->pf_update_list)
493 val.i_int = p_config->value.i;
494 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
495 // assume in any case that dirty was set to VLC_TRUE
496 // because lazy programmes will use the same callback for
497 // this, like the one behind the refresh push button?
498 p_config->b_dirty = VLC_FALSE;
501 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
503 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
504 QVariant( p_config->pi_list[i_index] ) );
505 if( p_config->value.i == p_config->pi_list[i_index] )
507 combo->setCurrentIndex( i_index );
510 combo->setToolTip( qfu( p_config->psz_longtext ) );
514 /********* Module **********/
515 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
516 module_config_t *_p_item, QWidget *_parent, bool bycat,
517 QGridLayout *l, int &line) :
518 VStringConfigControl( _p_this, _p_item, _parent )
520 label = new QLabel( qtr(p_item->psz_text) );
521 combo = new QComboBox();
522 combo->setMinimumWidth( MINWIDTH_BOX );
526 QHBoxLayout *layout = new QHBoxLayout();
527 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
528 widget->setLayout( layout );
532 l->addWidget( label, line, 0 );
533 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
537 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
538 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
539 bool bycat ) : VStringConfigControl( _p_this, _p_item )
546 void ModuleConfigControl::finish( bool bycat )
551 combo->setEditable( false );
553 /* build a list of available modules */
554 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
555 combo->addItem( qtr("Default") );
556 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
558 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
562 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
565 module_config_t *p_config;
567 p_config = module_GetConfig (p_parser, &confsize);
568 for (size_t i = 0; i < confsize; i++)
570 /* Hack: required subcategory is stored in i_min */
571 const module_config_t *p_cfg = p_config + i;
572 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
573 p_cfg->value.i == p_item->min.i )
574 combo->addItem( qtr( module_GetLongName( p_parser )),
575 QVariant( module_GetObjName( p_parser ) ) );
576 if( p_item->value.psz && !strcmp( p_item->value.psz,
577 module_GetObjName( p_parser ) ) )
578 combo->setCurrentIndex( combo->count() - 1 );
580 module_PutConfig (p_config);
582 else if( module_IsCapable( p_parser, p_item->psz_type ) )
584 combo->addItem( qtr(module_GetLongName( p_parser ) ),
585 QVariant( module_GetObjName( p_parser ) ) );
586 if( p_item->value.psz && !strcmp( p_item->value.psz,
587 module_GetObjName( p_parser ) ) )
588 combo->setCurrentIndex( combo->count() - 1 );
591 vlc_list_release( p_list );
592 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
594 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
597 QString ModuleConfigControl::getValue()
599 return combo->itemData( combo->currentIndex() ).toString();
602 /********* Module list **********/
603 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
604 module_config_t *_p_item, QWidget *_parent, bool bycat,
605 QGridLayout *l, int &line) :
606 VStringConfigControl( _p_this, _p_item, _parent )
608 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
609 text = new QLineEdit();
610 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
615 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
616 it != modules.end(); it++ )
618 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
620 layoutGroupBox->addWidget( text, boxline, 0 );
624 QVBoxLayout *layout = new QVBoxLayout();
625 layout->addWidget( groupBox, line, 0 );
626 widget->setLayout( layout );
630 l->addWidget( groupBox, line, 0, 1, -1 );
633 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
636 ModuleListConfigControl::~ModuleListConfigControl()
638 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
639 it != modules.end(); it++ )
647 #define CHECKBOX_LISTS \
649 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
650 checkBoxListItem *cbl = new checkBoxListItem; \
652 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
653 cb->setToolTip( formatTooltip( qtr( module_GetHelp( p_parser ))));\
654 cbl->checkBox = cb; \
656 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
657 modules.push_back( cbl ); \
659 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
660 cbl->checkBox->setChecked( true ); \
664 void ModuleListConfigControl::finish( bool bycat )
669 /* build a list of available modules */
670 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
671 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
673 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
677 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
680 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
682 for (size_t i = 0; i < confsize; i++)
684 module_config_t *p_cfg = p_config + i;
685 /* Hack: required subcategory is stored in i_min */
686 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
687 p_cfg->value.i == p_item->min.i )
692 module_PutConfig (p_config);
694 else if( module_IsCapable( p_parser, p_item->psz_type ) )
699 vlc_list_release( p_list );
700 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
702 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
704 #undef CHECKBOX_LISTS
706 QString ModuleListConfigControl::getValue()
711 void ModuleListConfigControl::hide()
713 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
714 it != modules.end(); it++ )
716 (*it)->checkBox->hide();
721 void ModuleListConfigControl::show()
723 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
724 it != modules.end(); it++ )
726 (*it)->checkBox->show();
732 void ModuleListConfigControl::onUpdate( int value )
737 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
738 it != modules.end(); it++ )
740 if( (*it)->checkBox->isChecked() )
744 text->setText( text->text() + (*it)->psz_module );
749 text->setText( text->text() + ":" + (*it)->psz_module );
755 /**************************************************************************
756 * Integer-based controls
757 *************************************************************************/
759 /*********** Integer **************/
760 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
761 module_config_t *_p_item,
762 QWidget *_parent, QGridLayout *l,
764 VIntConfigControl( _p_this, _p_item, _parent )
766 label = new QLabel( qtr(p_item->psz_text) );
767 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
768 spin->setAlignment( Qt::AlignRight );
769 spin->setMaximumWidth( MINWIDTH_BOX );
774 QHBoxLayout *layout = new QHBoxLayout();
775 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
776 widget->setLayout( layout );
780 l->addWidget( label, line, 0 );
781 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
784 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
785 module_config_t *_p_item,
786 QLabel *_label, QSpinBox *_spin ) :
787 VIntConfigControl( _p_this, _p_item )
794 void IntegerConfigControl::finish()
796 spin->setMaximum( 2000000000 );
797 spin->setMinimum( -2000000000 );
798 spin->setValue( p_item->value.i );
799 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
801 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
804 int IntegerConfigControl::getValue()
806 return spin->value();
809 /********* Integer range **********/
810 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
811 module_config_t *_p_item,
812 QWidget *_parent, QGridLayout *l,
814 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
819 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
820 module_config_t *_p_item,
821 QLabel *_label, QSpinBox *_spin ) :
822 IntegerConfigControl( _p_this, _p_item, _label, _spin )
827 void IntegerRangeConfigControl::finish()
829 spin->setMaximum( p_item->max.i );
830 spin->setMinimum( p_item->min.i );
833 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
834 vlc_object_t *_p_this,
835 module_config_t *_p_item,
836 QLabel *_label, QSlider *_slider ):
837 VIntConfigControl( _p_this, _p_item )
841 slider->setMaximum( p_item->max.i );
842 slider->setMinimum( p_item->min.i );
843 slider->setValue( p_item->value.i );
844 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
846 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
849 int IntegerRangeSliderConfigControl::getValue()
851 return slider->value();
855 /********* Integer / choice list **********/
856 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
857 module_config_t *_p_item, QWidget *_parent, bool bycat,
858 QGridLayout *l, int &line) :
859 VIntConfigControl( _p_this, _p_item, _parent )
861 label = new QLabel( qtr(p_item->psz_text) );
862 combo = new QComboBox();
863 combo->setMinimumWidth( MINWIDTH_BOX );
865 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
866 if(p_module_config && p_module_config->pf_update_list)
869 val.i_int = p_module_config->value.i;
871 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
873 // assume in any case that dirty was set to VLC_TRUE
874 // because lazy programmes will use the same callback for
875 // this, like the one behind the refresh push button?
876 p_module_config->b_dirty = VLC_FALSE;
880 finish( p_module_config, bycat );
883 QHBoxLayout *layout = new QHBoxLayout();
884 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
885 widget->setLayout( layout );
889 l->addWidget( label, line, 0 );
890 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
893 if( p_item->i_action )
895 QSignalMapper *signalMapper = new QSignalMapper(this);
897 /* Some stringLists like Capture listings have action associated */
898 for( int i = 0; i < p_item->i_action; i++ )
900 QPushButton *button =
901 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
902 CONNECT( button, clicked(), signalMapper, map() );
903 signalMapper->setMapping( button, i );
904 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
907 CONNECT( signalMapper, mapped( int ),
908 this, actionRequested( int ) );
912 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
913 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
914 bool bycat ) : VIntConfigControl( _p_this, _p_item )
919 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
921 finish( p_module_config, bycat );
924 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
926 combo->setEditable( false );
928 if(!p_module_config) return;
930 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
932 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
933 QVariant( p_module_config->pi_list[i_index] ) );
934 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
935 combo->setCurrentIndex( combo->count() - 1 );
937 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
939 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
942 void IntegerListConfigControl::actionRequested( int i_action )
944 /* Supplementary check for boundaries */
945 if( i_action < 0 || i_action >= p_item->i_action ) return;
947 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
948 if(!p_module_config) return;
952 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
954 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
956 if( p_module_config->b_dirty )
959 finish( p_module_config, true );
960 p_module_config->b_dirty = VLC_FALSE;
964 int IntegerListConfigControl::getValue()
966 return combo->itemData( combo->currentIndex() ).toInt();
969 /*********** Boolean **************/
970 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
971 module_config_t *_p_item,
972 QWidget *_parent, QGridLayout *l,
974 VIntConfigControl( _p_this, _p_item, _parent )
976 checkbox = new QCheckBox( qtr(p_item->psz_text) );
981 QHBoxLayout *layout = new QHBoxLayout();
982 layout->addWidget( checkbox, 0 );
983 widget->setLayout( layout );
987 l->addWidget( checkbox, line, 0 );
990 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
991 module_config_t *_p_item,
993 QCheckBox *_checkbox,
995 VIntConfigControl( _p_this, _p_item )
997 checkbox = _checkbox;
1001 void BoolConfigControl::finish()
1003 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
1005 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1008 int BoolConfigControl::getValue()
1010 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
1013 /**************************************************************************
1014 * Float-based controls
1015 *************************************************************************/
1017 /*********** Float **************/
1018 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1019 module_config_t *_p_item,
1020 QWidget *_parent, QGridLayout *l,
1022 VFloatConfigControl( _p_this, _p_item, _parent )
1024 label = new QLabel( qtr(p_item->psz_text) );
1025 spin = new QDoubleSpinBox;
1026 spin->setMinimumWidth( MINWIDTH_BOX );
1027 spin->setMaximumWidth( MINWIDTH_BOX );
1028 spin->setAlignment( Qt::AlignRight );
1033 QHBoxLayout *layout = new QHBoxLayout();
1034 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1035 widget->setLayout( layout );
1039 l->addWidget( label, line, 0 );
1040 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1044 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1045 module_config_t *_p_item,
1047 QDoubleSpinBox *_spin ) :
1048 VFloatConfigControl( _p_this, _p_item )
1055 void FloatConfigControl::finish()
1057 spin->setMaximum( 2000000000. );
1058 spin->setMinimum( -2000000000. );
1059 spin->setSingleStep( 0.1 );
1060 spin->setValue( (double)p_item->value.f );
1061 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1063 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1066 float FloatConfigControl::getValue()
1068 return (float)spin->value();
1071 /*********** Float with range **************/
1072 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1073 module_config_t *_p_item,
1074 QWidget *_parent, QGridLayout *l,
1076 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1081 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1082 module_config_t *_p_item,
1084 QDoubleSpinBox *_spin ) :
1085 FloatConfigControl( _p_this, _p_item, _label, _spin )
1090 void FloatRangeConfigControl::finish()
1092 spin->setMaximum( (double)p_item->max.f );
1093 spin->setMinimum( (double)p_item->min.f );
1097 /**********************************************************************
1098 * Key selector widget
1099 **********************************************************************/
1100 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1101 module_config_t *_p_item,
1102 QWidget *_parent, QGridLayout *l,
1104 ConfigControl( _p_this, _p_item, _parent )
1107 QWidget *keyContainer = new QWidget;
1108 QGridLayout *gLayout = new QGridLayout( keyContainer );
1111 qtr( "Select an action to change the associated hotkey") );
1113 /* Deactivated for now
1114 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1115 QLineEdit *actionSearch = new QLineEdit;*/
1117 table = new QTreeWidget;
1118 table->setColumnCount(2);
1119 table->headerItem()->setText( 0, qtr( "Action" ) );
1120 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1122 shortcutValue = new KeyShortcutEdit;
1123 shortcutValue->setReadOnly(true);
1125 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1126 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1127 setButton->setDefault( true );
1130 gLayout->addWidget( label, 0, 0, 1, 4 );
1131 /* deactivated for now
1132 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1133 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1134 gLayout->addWidget( table, 2, 0, 1, 4 );
1135 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1136 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1137 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1139 l->addWidget( keyContainer, line, 0, 1, 2 );
1141 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1142 BUTTONACT( setButton, setTheKey() );
1145 void KeySelectorControl::finish()
1148 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1150 /* Fill the table */
1151 table->setColumnCount( 2 );
1152 table->setAlternatingRowColors( true );
1154 /* Get the main Module */
1155 module_t *p_main = module_Find( p_this, "main" );
1158 /* Access to the module_config_t */
1160 module_config_t *p_config;
1162 p_config = module_GetConfig (p_main, &confsize);
1164 for (size_t i = 0; i < confsize; i++)
1166 module_config_t *p_item = p_config + i;
1168 /* If we are a key option not empty */
1169 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1170 && strstr( p_item->psz_name , "key-" )
1171 && !EMPTY_STR( p_item->psz_text ) )
1175 - QString text in column 0
1176 - QString name in data of column 0
1177 - KeyValue in String in column 1
1178 - KeyValue in int in column 1
1180 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1181 treeItem->setText( 0, qtr( p_item->psz_text ) );
1182 treeItem->setData( 0, Qt::UserRole,
1183 QVariant( qfu( p_item->psz_name ) ) );
1184 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1185 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1186 table->addTopLevelItem( treeItem );
1189 module_PutConfig (p_config);
1190 module_Put (p_main);
1192 table->resizeColumnToContents( 0 );
1194 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1195 this, select1Key( QTreeWidgetItem * ) );
1196 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1197 this, selectKey( QTreeWidgetItem * ) );
1198 CONNECT( shortcutValue, pressed(), this, selectKey() );
1201 /* Show the key selected from the table in the keySelector */
1202 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1204 shortcutValue->setText( keyItem->text( 1 ) );
1205 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1208 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1210 /* This happens when triggered by ClickEater */
1211 if( keyItem == NULL ) keyItem = table->currentItem();
1213 /* This can happen when nothing is selected on the treeView
1214 and the shortcutValue is clicked */
1215 if( !keyItem ) return;
1217 /* Launch a small dialog to ask for a new key */
1218 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget );
1221 if( d->result() == QDialog::Accepted )
1223 int newValue = d->keyValue;
1224 shortcutValue->setText( VLCKeyToString( newValue ) );
1225 shortcutValue->setValue( newValue );
1229 QTreeWidgetItem *it;
1230 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1232 it = table->topLevelItem(i);
1233 if( ( keyItem != it )
1234 && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) )
1236 it->setData( 1, Qt::UserRole, QVariant( -1 ) );
1237 it->setText( 1, qtr( "Unset" ) );
1240 /* We already made an OK once. */
1247 void KeySelectorControl::setTheKey()
1249 table->currentItem()->setText( 1, shortcutValue->text() );
1250 table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );
1253 void KeySelectorControl::doApply()
1255 QTreeWidgetItem *it;
1256 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1258 it = table->topLevelItem(i);
1259 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1260 config_PutInt( p_this,
1261 qtu( it->data( 0, Qt::UserRole ).toString() ),
1262 it->data( 1, Qt::UserRole ).toInt() );
1266 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1267 QString keyToChange,
1268 QWidget *_parent ) :
1269 QDialog( _parent ), keyValue(0)
1275 setWindowTitle( qtr( "Hotkey for " ) + keyToChange );
1277 vLayout = new QVBoxLayout( this );
1278 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1279 vLayout->addWidget( selected , Qt::AlignCenter );
1281 buttonBox = new QDialogButtonBox;
1282 QPushButton *ok = new QPushButton( qtr("OK") );
1283 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1284 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1285 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1286 ok->setDefault( true );
1288 vLayout->addWidget( buttonBox );
1291 CONNECT( buttonBox, accepted(), this, accept() );
1292 CONNECT( buttonBox, rejected(), this, reject() );
1295 void KeyInputDialog::checkForConflicts( int i_vlckey )
1297 QList<QTreeWidgetItem *> conflictList =
1298 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 );
1300 if( conflictList.size() )
1302 QLabel *warning = new QLabel(
1303 qtr("Warning: the key is already assigned to \"") +
1304 conflictList[0]->text( 0 ) + "\"" );
1305 vLayout->insertWidget( 1, warning );
1313 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1315 if( e->key() == Qt::Key_Tab ||
1316 e->key() == Qt::Key_Shift ||
1317 e->key() == Qt::Key_Control ||
1318 e->key() == Qt::Key_Meta ||
1319 e->key() == Qt::Key_Alt ||
1320 e->key() == Qt::Key_AltGr )
1322 int i_vlck = qtEventToVLCKey( e );
1323 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1324 checkForConflicts( i_vlck );
1328 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1330 int i_vlck = qtWheelEventToVLCKey( e );
1331 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1332 checkForConflicts( i_vlck );
1336 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)