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_text[i_index] :
468 p_module_config->ppsz_list[i_index] ),
469 QVariant( p_module_config->ppsz_list[i_index] ) );
470 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
471 p_module_config->ppsz_list[i_index] ) )
472 combo->setCurrentIndex( combo->count() - 1 );
474 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
476 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
479 QString StringListConfigControl::getValue()
481 return combo->itemData( combo->currentIndex() ).toString();
484 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
485 QComboBox *combo, QWidget *parent )
487 module_config_t *p_config =
488 config_FindConfig( VLC_OBJECT(p_intf), configname );
491 if(p_config->pf_update_list)
494 val.i_int = p_config->value.i;
495 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
496 // assume in any case that dirty was set to VLC_TRUE
497 // because lazy programmes will use the same callback for
498 // this, like the one behind the refresh push button?
499 p_config->b_dirty = VLC_FALSE;
502 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
504 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
505 QVariant( p_config->pi_list[i_index] ) );
506 if( p_config->value.i == p_config->pi_list[i_index] )
508 combo->setCurrentIndex( i_index );
511 combo->setToolTip( qfu( p_config->psz_longtext ) );
515 /********* Module **********/
516 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
517 module_config_t *_p_item, QWidget *_parent, bool bycat,
518 QGridLayout *l, int &line) :
519 VStringConfigControl( _p_this, _p_item, _parent )
521 label = new QLabel( qtr(p_item->psz_text) );
522 combo = new QComboBox();
523 combo->setMinimumWidth( MINWIDTH_BOX );
527 QHBoxLayout *layout = new QHBoxLayout();
528 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
529 widget->setLayout( layout );
533 l->addWidget( label, line, 0 );
534 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
538 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
539 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
540 bool bycat ) : VStringConfigControl( _p_this, _p_item )
547 void ModuleConfigControl::finish( bool bycat )
552 combo->setEditable( false );
554 /* build a list of available modules */
555 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
556 combo->addItem( qtr("Default") );
557 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
559 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
563 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
566 module_config_t *p_config;
568 p_config = module_GetConfig (p_parser, &confsize);
569 for (size_t i = 0; i < confsize; i++)
571 /* Hack: required subcategory is stored in i_min */
572 const module_config_t *p_cfg = p_config + i;
573 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
574 p_cfg->value.i == p_item->min.i )
575 combo->addItem( qtr( module_GetLongName( p_parser )),
576 QVariant( module_GetObjName( p_parser ) ) );
577 if( p_item->value.psz && !strcmp( p_item->value.psz,
578 module_GetObjName( p_parser ) ) )
579 combo->setCurrentIndex( combo->count() - 1 );
581 module_PutConfig (p_config);
583 else if( module_IsCapable( p_parser, p_item->psz_type ) )
585 combo->addItem( qtr(module_GetLongName( p_parser ) ),
586 QVariant( module_GetObjName( p_parser ) ) );
587 if( p_item->value.psz && !strcmp( p_item->value.psz,
588 module_GetObjName( p_parser ) ) )
589 combo->setCurrentIndex( combo->count() - 1 );
592 vlc_list_release( p_list );
593 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
595 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
598 QString ModuleConfigControl::getValue()
600 return combo->itemData( combo->currentIndex() ).toString();
603 /********* Module list **********/
604 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
605 module_config_t *_p_item, QWidget *_parent, bool bycat,
606 QGridLayout *l, int &line) :
607 VStringConfigControl( _p_this, _p_item, _parent )
609 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
610 text = new QLineEdit();
611 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
616 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
617 it != modules.end(); it++ )
619 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
621 layoutGroupBox->addWidget( text, boxline, 0 );
625 QVBoxLayout *layout = new QVBoxLayout();
626 layout->addWidget( groupBox, line, 0 );
627 widget->setLayout( layout );
631 l->addWidget( groupBox, line, 0, 1, -1 );
634 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
637 ModuleListConfigControl::~ModuleListConfigControl()
639 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
640 it != modules.end(); it++ )
648 #define CHECKBOX_LISTS \
650 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
651 checkBoxListItem *cbl = new checkBoxListItem; \
653 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
654 cb->setToolTip( formatTooltip( qtr( module_GetHelp( p_parser ))));\
655 cbl->checkBox = cb; \
657 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
658 modules.push_back( cbl ); \
660 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
661 cbl->checkBox->setChecked( true ); \
665 void ModuleListConfigControl::finish( bool bycat )
670 /* build a list of available modules */
671 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
672 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
674 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
678 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
681 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
683 for (size_t i = 0; i < confsize; i++)
685 module_config_t *p_cfg = p_config + i;
686 /* Hack: required subcategory is stored in i_min */
687 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
688 p_cfg->value.i == p_item->min.i )
693 module_PutConfig (p_config);
695 else if( module_IsCapable( p_parser, p_item->psz_type ) )
700 vlc_list_release( p_list );
701 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
703 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
705 #undef CHECKBOX_LISTS
707 QString ModuleListConfigControl::getValue()
712 void ModuleListConfigControl::hide()
714 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
715 it != modules.end(); it++ )
717 (*it)->checkBox->hide();
722 void ModuleListConfigControl::show()
724 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
725 it != modules.end(); it++ )
727 (*it)->checkBox->show();
733 void ModuleListConfigControl::onUpdate( int value )
738 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
739 it != modules.end(); it++ )
741 if( (*it)->checkBox->isChecked() )
745 text->setText( text->text() + (*it)->psz_module );
750 text->setText( text->text() + ":" + (*it)->psz_module );
756 /**************************************************************************
757 * Integer-based controls
758 *************************************************************************/
760 /*********** Integer **************/
761 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
762 module_config_t *_p_item,
763 QWidget *_parent, QGridLayout *l,
765 VIntConfigControl( _p_this, _p_item, _parent )
767 label = new QLabel( qtr(p_item->psz_text) );
768 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
769 spin->setAlignment( Qt::AlignRight );
770 spin->setMaximumWidth( MINWIDTH_BOX );
775 QHBoxLayout *layout = new QHBoxLayout();
776 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
777 widget->setLayout( layout );
781 l->addWidget( label, line, 0 );
782 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
785 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
786 module_config_t *_p_item,
787 QLabel *_label, QSpinBox *_spin ) :
788 VIntConfigControl( _p_this, _p_item )
795 void IntegerConfigControl::finish()
797 spin->setMaximum( 2000000000 );
798 spin->setMinimum( -2000000000 );
799 spin->setValue( p_item->value.i );
800 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
802 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
805 int IntegerConfigControl::getValue()
807 return spin->value();
810 /********* Integer range **********/
811 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
812 module_config_t *_p_item,
813 QWidget *_parent, QGridLayout *l,
815 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
820 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
821 module_config_t *_p_item,
822 QLabel *_label, QSpinBox *_spin ) :
823 IntegerConfigControl( _p_this, _p_item, _label, _spin )
828 void IntegerRangeConfigControl::finish()
830 spin->setMaximum( p_item->max.i );
831 spin->setMinimum( p_item->min.i );
834 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
835 vlc_object_t *_p_this,
836 module_config_t *_p_item,
837 QLabel *_label, QSlider *_slider ):
838 VIntConfigControl( _p_this, _p_item )
842 slider->setMaximum( p_item->max.i );
843 slider->setMinimum( p_item->min.i );
844 slider->setValue( p_item->value.i );
845 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
847 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
850 int IntegerRangeSliderConfigControl::getValue()
852 return slider->value();
856 /********* Integer / choice list **********/
857 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
858 module_config_t *_p_item, QWidget *_parent, bool bycat,
859 QGridLayout *l, int &line) :
860 VIntConfigControl( _p_this, _p_item, _parent )
862 label = new QLabel( qtr(p_item->psz_text) );
863 combo = new QComboBox();
864 combo->setMinimumWidth( MINWIDTH_BOX );
866 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
867 if(p_module_config && p_module_config->pf_update_list)
870 val.i_int = p_module_config->value.i;
872 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
874 // assume in any case that dirty was set to VLC_TRUE
875 // because lazy programmes will use the same callback for
876 // this, like the one behind the refresh push button?
877 p_module_config->b_dirty = VLC_FALSE;
881 finish( p_module_config, bycat );
884 QHBoxLayout *layout = new QHBoxLayout();
885 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
886 widget->setLayout( layout );
890 l->addWidget( label, line, 0 );
891 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
894 if( p_item->i_action )
896 QSignalMapper *signalMapper = new QSignalMapper(this);
898 /* Some stringLists like Capture listings have action associated */
899 for( int i = 0; i < p_item->i_action; i++ )
901 QPushButton *button =
902 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
903 CONNECT( button, clicked(), signalMapper, map() );
904 signalMapper->setMapping( button, i );
905 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
908 CONNECT( signalMapper, mapped( int ),
909 this, actionRequested( int ) );
913 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
914 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
915 bool bycat ) : VIntConfigControl( _p_this, _p_item )
920 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
922 finish( p_module_config, bycat );
925 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
927 combo->setEditable( false );
929 if(!p_module_config) return;
931 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
933 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
934 QVariant( p_module_config->pi_list[i_index] ) );
935 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
936 combo->setCurrentIndex( combo->count() - 1 );
938 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
940 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
943 void IntegerListConfigControl::actionRequested( int i_action )
945 /* Supplementary check for boundaries */
946 if( i_action < 0 || i_action >= p_item->i_action ) return;
948 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
949 if(!p_module_config) return;
953 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
955 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
957 if( p_module_config->b_dirty )
960 finish( p_module_config, true );
961 p_module_config->b_dirty = VLC_FALSE;
965 int IntegerListConfigControl::getValue()
967 return combo->itemData( combo->currentIndex() ).toInt();
970 /*********** Boolean **************/
971 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
972 module_config_t *_p_item,
973 QWidget *_parent, QGridLayout *l,
975 VIntConfigControl( _p_this, _p_item, _parent )
977 checkbox = new QCheckBox( qtr(p_item->psz_text) );
982 QHBoxLayout *layout = new QHBoxLayout();
983 layout->addWidget( checkbox, 0 );
984 widget->setLayout( layout );
988 l->addWidget( checkbox, line, 0 );
991 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
992 module_config_t *_p_item,
994 QCheckBox *_checkbox,
996 VIntConfigControl( _p_this, _p_item )
998 checkbox = _checkbox;
1002 void BoolConfigControl::finish()
1004 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
1006 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1009 int BoolConfigControl::getValue()
1011 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
1014 /**************************************************************************
1015 * Float-based controls
1016 *************************************************************************/
1018 /*********** Float **************/
1019 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1020 module_config_t *_p_item,
1021 QWidget *_parent, QGridLayout *l,
1023 VFloatConfigControl( _p_this, _p_item, _parent )
1025 label = new QLabel( qtr(p_item->psz_text) );
1026 spin = new QDoubleSpinBox;
1027 spin->setMinimumWidth( MINWIDTH_BOX );
1028 spin->setMaximumWidth( MINWIDTH_BOX );
1029 spin->setAlignment( Qt::AlignRight );
1034 QHBoxLayout *layout = new QHBoxLayout();
1035 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1036 widget->setLayout( layout );
1040 l->addWidget( label, line, 0 );
1041 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1045 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1046 module_config_t *_p_item,
1048 QDoubleSpinBox *_spin ) :
1049 VFloatConfigControl( _p_this, _p_item )
1056 void FloatConfigControl::finish()
1058 spin->setMaximum( 2000000000. );
1059 spin->setMinimum( -2000000000. );
1060 spin->setSingleStep( 0.1 );
1061 spin->setValue( (double)p_item->value.f );
1062 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1064 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1067 float FloatConfigControl::getValue()
1069 return (float)spin->value();
1072 /*********** Float with range **************/
1073 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1074 module_config_t *_p_item,
1075 QWidget *_parent, QGridLayout *l,
1077 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1082 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1083 module_config_t *_p_item,
1085 QDoubleSpinBox *_spin ) :
1086 FloatConfigControl( _p_this, _p_item, _label, _spin )
1091 void FloatRangeConfigControl::finish()
1093 spin->setMaximum( (double)p_item->max.f );
1094 spin->setMinimum( (double)p_item->min.f );
1098 /**********************************************************************
1099 * Key selector widget
1100 **********************************************************************/
1101 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1102 module_config_t *_p_item,
1103 QWidget *_parent, QGridLayout *l,
1105 ConfigControl( _p_this, _p_item, _parent )
1108 QWidget *keyContainer = new QWidget;
1109 QGridLayout *gLayout = new QGridLayout( keyContainer );
1112 qtr( "Select an action to change the associated hotkey") );
1114 /* Deactivated for now
1115 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1116 QLineEdit *actionSearch = new QLineEdit;*/
1118 table = new QTreeWidget;
1119 table->setColumnCount(2);
1120 table->headerItem()->setText( 0, qtr( "Action" ) );
1121 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1123 shortcutValue = new KeyShortcutEdit;
1124 shortcutValue->setReadOnly(true);
1126 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1127 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1128 setButton->setDefault( true );
1131 gLayout->addWidget( label, 0, 0, 1, 4 );
1132 /* deactivated for now
1133 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1134 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1135 gLayout->addWidget( table, 2, 0, 1, 4 );
1136 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1137 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1138 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1140 l->addWidget( keyContainer, line, 0, 1, 2 );
1142 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1143 BUTTONACT( setButton, setTheKey() );
1146 void KeySelectorControl::finish()
1149 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1151 /* Fill the table */
1152 table->setColumnCount( 2 );
1153 table->setAlternatingRowColors( true );
1155 /* Get the main Module */
1156 module_t *p_main = module_Find( p_this, "main" );
1159 /* Access to the module_config_t */
1161 module_config_t *p_config;
1163 p_config = module_GetConfig (p_main, &confsize);
1165 for (size_t i = 0; i < confsize; i++)
1167 module_config_t *p_item = p_config + i;
1169 /* If we are a key option not empty */
1170 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1171 && strstr( p_item->psz_name , "key-" )
1172 && !EMPTY_STR( p_item->psz_text ) )
1176 - QString text in column 0
1177 - QString name in data of column 0
1178 - KeyValue in String in column 1
1179 - KeyValue in int in column 1
1181 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1182 treeItem->setText( 0, qtr( p_item->psz_text ) );
1183 treeItem->setData( 0, Qt::UserRole,
1184 QVariant( qfu( p_item->psz_name ) ) );
1185 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1186 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1187 table->addTopLevelItem( treeItem );
1190 module_PutConfig (p_config);
1191 module_Put (p_main);
1193 table->resizeColumnToContents( 0 );
1195 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1196 this, select1Key( QTreeWidgetItem * ) );
1197 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1198 this, selectKey( QTreeWidgetItem * ) );
1199 CONNECT( shortcutValue, pressed(), this, selectKey() );
1202 /* Show the key selected from the table in the keySelector */
1203 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1205 shortcutValue->setText( keyItem->text( 1 ) );
1206 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1209 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1211 /* This happens when triggered by ClickEater */
1212 if( keyItem == NULL ) keyItem = table->currentItem();
1214 /* This can happen when nothing is selected on the treeView
1215 and the shortcutValue is clicked */
1216 if( !keyItem ) return;
1218 /* Launch a small dialog to ask for a new key */
1219 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget );
1222 if( d->result() == QDialog::Accepted )
1224 int newValue = d->keyValue;
1225 shortcutValue->setText( VLCKeyToString( newValue ) );
1226 shortcutValue->setValue( newValue );
1230 QTreeWidgetItem *it;
1231 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1233 it = table->topLevelItem(i);
1234 if( ( keyItem != it )
1235 && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) )
1237 it->setData( 1, Qt::UserRole, QVariant( -1 ) );
1238 it->setText( 1, qtr( "Unset" ) );
1241 /* We already made an OK once. */
1248 void KeySelectorControl::setTheKey()
1250 table->currentItem()->setText( 1, shortcutValue->text() );
1251 table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );
1254 void KeySelectorControl::doApply()
1256 QTreeWidgetItem *it;
1257 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1259 it = table->topLevelItem(i);
1260 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1261 config_PutInt( p_this,
1262 qtu( it->data( 0, Qt::UserRole ).toString() ),
1263 it->data( 1, Qt::UserRole ).toInt() );
1267 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1268 QString keyToChange,
1269 QWidget *_parent ) :
1270 QDialog( _parent ), keyValue(0)
1276 setWindowTitle( qtr( "Hotkey for " ) + keyToChange );
1278 vLayout = new QVBoxLayout( this );
1279 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1280 vLayout->addWidget( selected , Qt::AlignCenter );
1282 buttonBox = new QDialogButtonBox;
1283 QPushButton *ok = new QPushButton( qtr("OK") );
1284 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1285 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1286 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1287 ok->setDefault( true );
1289 vLayout->addWidget( buttonBox );
1292 CONNECT( buttonBox, accepted(), this, accept() );
1293 CONNECT( buttonBox, rejected(), this, reject() );
1296 void KeyInputDialog::checkForConflicts( int i_vlckey )
1298 QList<QTreeWidgetItem *> conflictList =
1299 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 );
1301 if( conflictList.size() )
1303 QLabel *warning = new QLabel(
1304 qtr("Warning: the key is already assigned to \"") +
1305 conflictList[0]->text( 0 ) + "\"" );
1306 vLayout->insertWidget( 1, warning );
1314 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1316 if( e->key() == Qt::Key_Tab ||
1317 e->key() == Qt::Key_Shift ||
1318 e->key() == Qt::Key_Control ||
1319 e->key() == Qt::Key_Meta ||
1320 e->key() == Qt::Key_Alt ||
1321 e->key() == Qt::Key_AltGr )
1323 int i_vlck = qtEventToVLCKey( e );
1324 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1325 checkForConflicts( i_vlck );
1329 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1331 int i_vlck = qtWheelEventToVLCKey( e );
1332 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1333 checkForConflicts( i_vlck );
1337 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)