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, getName() );
378 finish( p_module_config, bycat );
381 l = new QGridLayout();
382 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
383 widget->setLayout( l );
387 l->addWidget( label, line, 0 );
388 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
391 if( p_item->i_action )
393 QSignalMapper *signalMapper = new QSignalMapper(this);
395 /* Some stringLists like Capture listings have action associated */
396 for( int i = 0; i < p_item->i_action; i++ )
398 QPushButton *button =
399 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
400 CONNECT( button, clicked(), signalMapper, map() );
401 signalMapper->setMapping( button, i );
402 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
405 CONNECT( signalMapper, mapped( int ),
406 this, actionRequested( int ) );
410 void StringListConfigControl::actionRequested( int i_action )
412 /* Supplementary check for boundaries */
413 if( i_action < 0 || i_action >= p_item->i_action ) return;
415 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
416 if(!p_module_config) return;
420 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
422 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
424 if( p_module_config->b_dirty )
427 finish( p_module_config, true );
428 p_module_config->b_dirty = VLC_FALSE;
431 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
432 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
433 bool bycat ) : VStringConfigControl( _p_this, _p_item )
438 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
440 finish( p_module_config, bycat );
443 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
445 combo->setEditable( false );
447 if(!p_module_config) return;
449 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
451 combo->addItem( qfu(p_module_config->ppsz_list_text ?
452 p_module_config->ppsz_list_text[i_index] :
453 p_module_config->ppsz_list[i_index] ),
454 QVariant( p_module_config->ppsz_list[i_index] ) );
455 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
456 p_module_config->ppsz_list[i_index] ) )
457 combo->setCurrentIndex( combo->count() - 1 );
459 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
461 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
464 QString StringListConfigControl::getValue()
466 return combo->itemData( combo->currentIndex() ).toString();
469 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
470 QComboBox *combo, QWidget *parent )
472 module_config_t *p_config =
473 config_FindConfig( VLC_OBJECT(p_intf), configname );
476 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
478 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
479 QVariant( p_config->pi_list[i_index] ) );
480 if( p_config->value.i == p_config->pi_list[i_index] )
482 combo->setCurrentIndex( i_index );
485 combo->setToolTip( qfu( p_config->psz_longtext ) );
489 /********* Module **********/
490 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
491 module_config_t *_p_item, QWidget *_parent, bool bycat,
492 QGridLayout *l, int &line) :
493 VStringConfigControl( _p_this, _p_item, _parent )
495 label = new QLabel( qtr(p_item->psz_text) );
496 combo = new QComboBox();
497 combo->setMinimumWidth( MINWIDTH_BOX );
501 QHBoxLayout *layout = new QHBoxLayout();
502 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
503 widget->setLayout( layout );
507 l->addWidget( label, line, 0 );
508 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
512 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
513 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
514 bool bycat ) : VStringConfigControl( _p_this, _p_item )
521 void ModuleConfigControl::finish( bool bycat )
526 combo->setEditable( false );
528 /* build a list of available modules */
529 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
530 combo->addItem( qtr("Default") );
531 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
533 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
537 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
540 module_config_t *p_config;
542 p_config = module_GetConfig (p_parser, &confsize);
543 for (size_t i = 0; i < confsize; i++)
545 /* Hack: required subcategory is stored in i_min */
546 const module_config_t *p_cfg = p_config + i;
547 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
548 p_cfg->value.i == p_item->min.i )
549 combo->addItem( qtr( module_GetLongName( p_parser )),
550 QVariant( module_GetObjName( p_parser ) ) );
551 if( p_item->value.psz && !strcmp( p_item->value.psz,
552 module_GetObjName( p_parser ) ) )
553 combo->setCurrentIndex( combo->count() - 1 );
555 module_PutConfig (p_config);
557 else if( module_IsCapable( p_parser, p_item->psz_type ) )
559 combo->addItem( qtr(module_GetLongName( p_parser ) ),
560 QVariant( module_GetObjName( p_parser ) ) );
561 if( p_item->value.psz && !strcmp( p_item->value.psz,
562 module_GetObjName( p_parser ) ) )
563 combo->setCurrentIndex( combo->count() - 1 );
566 vlc_list_release( p_list );
567 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
569 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
572 QString ModuleConfigControl::getValue()
574 return combo->itemData( combo->currentIndex() ).toString();
577 /********* Module list **********/
578 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
579 module_config_t *_p_item, QWidget *_parent, bool bycat,
580 QGridLayout *l, int &line) :
581 VStringConfigControl( _p_this, _p_item, _parent )
583 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
584 text = new QLineEdit();
585 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
590 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
591 it != modules.end(); it++ )
593 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
595 layoutGroupBox->addWidget( text, boxline, 0 );
599 QVBoxLayout *layout = new QVBoxLayout();
600 layout->addWidget( groupBox, line, 0 );
601 widget->setLayout( layout );
605 l->addWidget( groupBox, line, 0, 1, -1 );
608 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
611 ModuleListConfigControl::~ModuleListConfigControl()
613 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
614 it != modules.end(); it++ )
622 #define CHECKBOX_LISTS \
624 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
625 checkBoxListItem *cbl = new checkBoxListItem; \
627 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
628 cb->setToolTip( formatTooltip( qtr( module_GetHelp( p_parser ))));\
629 cbl->checkBox = cb; \
631 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
632 modules.push_back( cbl ); \
634 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
635 cbl->checkBox->setChecked( true ); \
639 void ModuleListConfigControl::finish( bool bycat )
644 /* build a list of available modules */
645 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
646 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
648 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
652 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
655 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
657 for (size_t i = 0; i < confsize; i++)
659 module_config_t *p_cfg = p_config + i;
660 /* Hack: required subcategory is stored in i_min */
661 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
662 p_cfg->value.i == p_item->min.i )
667 module_PutConfig (p_config);
669 else if( module_IsCapable( p_parser, p_item->psz_type ) )
674 vlc_list_release( p_list );
675 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
677 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
679 #undef CHECKBOX_LISTS
681 QString ModuleListConfigControl::getValue()
686 void ModuleListConfigControl::hide()
688 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
689 it != modules.end(); it++ )
691 (*it)->checkBox->hide();
696 void ModuleListConfigControl::show()
698 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
699 it != modules.end(); it++ )
701 (*it)->checkBox->show();
707 void ModuleListConfigControl::onUpdate( int value )
712 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
713 it != modules.end(); it++ )
715 if( (*it)->checkBox->isChecked() )
719 text->setText( text->text() + (*it)->psz_module );
724 text->setText( text->text() + ":" + (*it)->psz_module );
730 /**************************************************************************
731 * Integer-based controls
732 *************************************************************************/
734 /*********** Integer **************/
735 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
736 module_config_t *_p_item,
737 QWidget *_parent, QGridLayout *l,
739 VIntConfigControl( _p_this, _p_item, _parent )
741 label = new QLabel( qtr(p_item->psz_text) );
742 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
743 spin->setAlignment( Qt::AlignRight );
744 spin->setMaximumWidth( MINWIDTH_BOX );
749 QHBoxLayout *layout = new QHBoxLayout();
750 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
751 widget->setLayout( layout );
755 l->addWidget( label, line, 0 );
756 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
759 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
760 module_config_t *_p_item,
761 QLabel *_label, QSpinBox *_spin ) :
762 VIntConfigControl( _p_this, _p_item )
769 void IntegerConfigControl::finish()
771 spin->setMaximum( 2000000000 );
772 spin->setMinimum( -2000000000 );
773 spin->setValue( p_item->value.i );
774 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
776 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
779 int IntegerConfigControl::getValue()
781 return spin->value();
784 /********* Integer range **********/
785 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
786 module_config_t *_p_item,
787 QWidget *_parent, QGridLayout *l,
789 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
794 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
795 module_config_t *_p_item,
796 QLabel *_label, QSpinBox *_spin ) :
797 IntegerConfigControl( _p_this, _p_item, _label, _spin )
802 void IntegerRangeConfigControl::finish()
804 spin->setMaximum( p_item->max.i );
805 spin->setMinimum( p_item->min.i );
808 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
809 vlc_object_t *_p_this,
810 module_config_t *_p_item,
811 QLabel *_label, QSlider *_slider ):
812 VIntConfigControl( _p_this, _p_item )
816 slider->setMaximum( p_item->max.i );
817 slider->setMinimum( p_item->min.i );
818 slider->setValue( p_item->value.i );
819 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
821 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
824 int IntegerRangeSliderConfigControl::getValue()
826 return slider->value();
830 /********* Integer / choice list **********/
831 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
832 module_config_t *_p_item, QWidget *_parent, bool bycat,
833 QGridLayout *l, int &line) :
834 VIntConfigControl( _p_this, _p_item, _parent )
836 label = new QLabel( qtr(p_item->psz_text) );
837 combo = new QComboBox();
838 combo->setMinimumWidth( MINWIDTH_BOX );
840 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
842 finish( p_module_config, bycat );
845 QHBoxLayout *layout = new QHBoxLayout();
846 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
847 widget->setLayout( layout );
851 l->addWidget( label, line, 0 );
852 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
855 if( p_item->i_action )
857 QSignalMapper *signalMapper = new QSignalMapper(this);
859 /* Some stringLists like Capture listings have action associated */
860 for( int i = 0; i < p_item->i_action; i++ )
862 QPushButton *button =
863 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
864 CONNECT( button, clicked(), signalMapper, map() );
865 signalMapper->setMapping( button, i );
866 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
869 CONNECT( signalMapper, mapped( int ),
870 this, actionRequested( int ) );
874 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
875 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
876 bool bycat ) : VIntConfigControl( _p_this, _p_item )
881 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
883 finish( p_module_config, bycat );
886 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
888 combo->setEditable( false );
890 if(!p_module_config) return;
892 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
894 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
895 QVariant( p_module_config->pi_list[i_index] ) );
896 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
897 combo->setCurrentIndex( combo->count() - 1 );
899 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
901 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
904 void IntegerListConfigControl::actionRequested( int i_action )
906 /* Supplementary check for boundaries */
907 if( i_action < 0 || i_action >= p_item->i_action ) return;
909 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
910 if(!p_module_config) return;
914 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
916 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
918 if( p_module_config->b_dirty )
921 finish( p_module_config, true );
922 p_module_config->b_dirty = VLC_FALSE;
926 int IntegerListConfigControl::getValue()
928 return combo->itemData( combo->currentIndex() ).toInt();
931 /*********** Boolean **************/
932 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
933 module_config_t *_p_item,
934 QWidget *_parent, QGridLayout *l,
936 VIntConfigControl( _p_this, _p_item, _parent )
938 checkbox = new QCheckBox( qtr(p_item->psz_text) );
943 QHBoxLayout *layout = new QHBoxLayout();
944 layout->addWidget( checkbox, 0 );
945 widget->setLayout( layout );
949 l->addWidget( checkbox, line, 0 );
952 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
953 module_config_t *_p_item,
955 QCheckBox *_checkbox,
957 VIntConfigControl( _p_this, _p_item )
959 checkbox = _checkbox;
963 void BoolConfigControl::finish()
965 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
967 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
970 int BoolConfigControl::getValue()
972 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
975 /**************************************************************************
976 * Float-based controls
977 *************************************************************************/
979 /*********** Float **************/
980 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
981 module_config_t *_p_item,
982 QWidget *_parent, QGridLayout *l,
984 VFloatConfigControl( _p_this, _p_item, _parent )
986 label = new QLabel( qtr(p_item->psz_text) );
987 spin = new QDoubleSpinBox;
988 spin->setMinimumWidth( MINWIDTH_BOX );
989 spin->setMaximumWidth( MINWIDTH_BOX );
990 spin->setAlignment( Qt::AlignRight );
995 QHBoxLayout *layout = new QHBoxLayout();
996 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
997 widget->setLayout( layout );
1001 l->addWidget( label, line, 0 );
1002 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1006 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1007 module_config_t *_p_item,
1009 QDoubleSpinBox *_spin ) :
1010 VFloatConfigControl( _p_this, _p_item )
1017 void FloatConfigControl::finish()
1019 spin->setMaximum( 2000000000. );
1020 spin->setMinimum( -2000000000. );
1021 spin->setSingleStep( 0.1 );
1022 spin->setValue( (double)p_item->value.f );
1023 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1025 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1028 float FloatConfigControl::getValue()
1030 return (float)spin->value();
1033 /*********** Float with range **************/
1034 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1035 module_config_t *_p_item,
1036 QWidget *_parent, QGridLayout *l,
1038 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1043 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1044 module_config_t *_p_item,
1046 QDoubleSpinBox *_spin ) :
1047 FloatConfigControl( _p_this, _p_item, _label, _spin )
1052 void FloatRangeConfigControl::finish()
1054 spin->setMaximum( (double)p_item->max.f );
1055 spin->setMinimum( (double)p_item->min.f );
1059 /**********************************************************************
1060 * Key selector widget
1061 **********************************************************************/
1062 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1063 module_config_t *_p_item,
1064 QWidget *_parent, QGridLayout *l,
1066 ConfigControl( _p_this, _p_item, _parent )
1069 QWidget *keyContainer = new QWidget;
1070 QGridLayout *gLayout = new QGridLayout( keyContainer );
1073 qtr( "Select an action to change the associated hotkey") );
1075 /* Deactivated for now
1076 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1077 QLineEdit *actionSearch = new QLineEdit;*/
1079 table = new QTreeWidget;
1080 table->setColumnCount(2);
1081 table->headerItem()->setText( 0, qtr( "Action" ) );
1082 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1084 shortcutValue = new KeyShortcutEdit;
1085 shortcutValue->setReadOnly(true);
1087 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1088 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1089 setButton->setDefault( true );
1092 gLayout->addWidget( label, 0, 0, 1, 4 );
1093 /* deactivated for now
1094 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1095 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1096 gLayout->addWidget( table, 2, 0, 1, 4 );
1097 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1098 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1099 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1101 l->addWidget( keyContainer, line, 0, 1, 2 );
1103 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1104 BUTTONACT( setButton, setTheKey() );
1107 void KeySelectorControl::finish()
1110 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1112 /* Fill the table */
1113 table->setColumnCount( 2 );
1114 table->setAlternatingRowColors( true );
1116 /* Get the main Module */
1117 module_t *p_main = module_Find( p_this, "main" );
1120 /* Access to the module_config_t */
1122 module_config_t *p_config;
1124 p_config = module_GetConfig (p_main, &confsize);
1126 for (size_t i = 0; i < confsize; i++)
1128 module_config_t *p_item = p_config + i;
1130 /* If we are a key option not empty */
1131 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1132 && strstr( p_item->psz_name , "key-" )
1133 && !EMPTY_STR( p_item->psz_text ) )
1137 - QString text in column 0
1138 - QString name in data of column 0
1139 - KeyValue in String in column 1
1140 - KeyValue in int in column 1
1142 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1143 treeItem->setText( 0, qtr( p_item->psz_text ) );
1144 treeItem->setData( 0, Qt::UserRole,
1145 QVariant( qfu( p_item->psz_name ) ) );
1146 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1147 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1148 table->addTopLevelItem( treeItem );
1151 module_PutConfig (p_config);
1152 module_Put (p_main);
1154 table->resizeColumnToContents( 0 );
1156 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1157 this, select1Key( QTreeWidgetItem * ) );
1158 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1159 this, selectKey( QTreeWidgetItem * ) );
1160 CONNECT( shortcutValue, pressed(), this, selectKey() );
1163 /* Show the key selected from the table in the keySelector */
1164 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1166 shortcutValue->setText( keyItem->text( 1 ) );
1167 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1170 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1172 /* This happens when triggered by ClickEater */
1173 if( keyItem == NULL ) keyItem = table->currentItem();
1175 /* This can happen when nothing is selected on the treeView
1176 and the shortcutValue is clicked */
1177 if( !keyItem ) return;
1179 /* Launch a small dialog to ask for a new key */
1180 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget );
1183 if( d->result() == QDialog::Accepted )
1185 int newValue = d->keyValue;
1186 shortcutValue->setText( VLCKeyToString( newValue ) );
1187 shortcutValue->setValue( newValue );
1191 QTreeWidgetItem *it;
1192 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1194 it = table->topLevelItem(i);
1195 if( ( keyItem != it )
1196 && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) )
1198 it->setData( 1, Qt::UserRole, QVariant( -1 ) );
1199 it->setText( 1, qtr( "Unset" ) );
1202 /* We already made an OK once. */
1209 void KeySelectorControl::setTheKey()
1211 table->currentItem()->setText( 1, shortcutValue->text() );
1212 table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );
1215 void KeySelectorControl::doApply()
1217 QTreeWidgetItem *it;
1218 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1220 it = table->topLevelItem(i);
1221 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1222 config_PutInt( p_this,
1223 qtu( it->data( 0, Qt::UserRole ).toString() ),
1224 it->data( 1, Qt::UserRole ).toInt() );
1228 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1229 QString keyToChange,
1230 QWidget *_parent ) :
1231 QDialog( _parent ), keyValue(0)
1237 setWindowTitle( qtr( "Hotkey for " ) + keyToChange );
1239 vLayout = new QVBoxLayout( this );
1240 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1241 vLayout->addWidget( selected , Qt::AlignCenter );
1243 buttonBox = new QDialogButtonBox;
1244 QPushButton *ok = new QPushButton( qtr("OK") );
1245 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1246 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1247 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1248 ok->setDefault( true );
1250 vLayout->addWidget( buttonBox );
1253 CONNECT( buttonBox, accepted(), this, accept() );
1254 CONNECT( buttonBox, rejected(), this, reject() );
1257 void KeyInputDialog::checkForConflicts( int i_vlckey )
1259 QList<QTreeWidgetItem *> conflictList =
1260 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 );
1262 if( conflictList.size() )
1264 QLabel *warning = new QLabel(
1265 qtr("Warning: the key is already assigned to \"") +
1266 conflictList[0]->text( 0 ) + "\"" );
1267 vLayout->insertWidget( 1, warning );
1275 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1277 if( e->key() == Qt::Key_Tab ||
1278 e->key() == Qt::Key_Shift ||
1279 e->key() == Qt::Key_Control ||
1280 e->key() == Qt::Key_Meta ||
1281 e->key() == Qt::Key_Alt ||
1282 e->key() == Qt::Key_AltGr )
1284 int i_vlck = qtEventToVLCKey( e );
1285 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1286 checkForConflicts( i_vlck );
1290 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1292 int i_vlck = qtWheelEventToVLCKey( e );
1293 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1294 checkForConflicts( i_vlck );
1298 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)