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"
44 #include <QGridLayout>
46 #include <QFileDialog>
48 #include <QTreeWidgetItem>
49 #include <QSignalMapper>
50 #include <QDialogButtonBox>
52 #define MINWIDTH_BOX 90
53 #define LAST_COLUMN 10
55 QString formatTooltip(const QString & tooltip)
58 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
59 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
60 "<body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; "
61 "font-style:normal; text-decoration:none;\">"
62 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
63 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
69 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
70 module_config_t *p_item,
74 return createControl( p_this, p_item, parent, NULL, i );
77 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
78 module_config_t *p_item,
80 QGridLayout *l, int &line )
82 ConfigControl *p_control = NULL;
84 switch( p_item->i_type )
86 case CONFIG_ITEM_MODULE:
87 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
90 case CONFIG_ITEM_MODULE_CAT:
91 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
94 case CONFIG_ITEM_MODULE_LIST:
95 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
98 case CONFIG_ITEM_MODULE_LIST_CAT:
99 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
102 case CONFIG_ITEM_STRING:
103 if( !p_item->i_list )
104 p_control = new StringConfigControl( p_this, p_item, parent,
107 p_control = new StringListConfigControl( p_this, p_item,
108 parent, false, l, line );
110 case CONFIG_ITEM_PASSWORD:
111 if( !p_item->i_list )
112 p_control = new StringConfigControl( p_this, p_item, parent,
115 p_control = new StringListConfigControl( p_this, p_item,
116 parent, true, l, line );
118 case CONFIG_ITEM_INTEGER:
120 p_control = new IntegerListConfigControl( p_this, p_item,
121 parent, false, l, line );
122 else if( p_item->min.i || p_item->max.i )
123 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
126 p_control = new IntegerConfigControl( p_this, p_item, parent,
129 case CONFIG_ITEM_FILE:
130 p_control = new FileConfigControl( p_this, p_item, parent, l,
133 case CONFIG_ITEM_DIRECTORY:
134 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
138 case CONFIG_ITEM_FONT:
139 p_control = new FontConfigControl( p_this, p_item, parent, l,
143 case CONFIG_ITEM_KEY:
144 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
146 case CONFIG_ITEM_BOOL:
147 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
149 case CONFIG_ITEM_FLOAT:
150 if( p_item->min.f || p_item->max.f )
151 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
154 p_control = new FloatConfigControl( p_this, p_item, parent,
163 void ConfigControl::doApply( intf_thread_t *p_intf )
167 case CONFIG_ITEM_INTEGER:
168 case CONFIG_ITEM_BOOL:
170 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
172 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
175 case CONFIG_ITEM_FLOAT:
177 VFloatConfigControl *vfcc =
178 qobject_cast<VFloatConfigControl *>(this);
180 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
183 case CONFIG_ITEM_STRING:
185 VStringConfigControl *vscc =
186 qobject_cast<VStringConfigControl *>(this);
188 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
191 case CONFIG_ITEM_KEY:
193 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
200 /**************************************************************************
201 * String-based controls
202 *************************************************************************/
204 /*********** String **************/
205 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
206 module_config_t *_p_item,
207 QWidget *_parent, QGridLayout *l,
208 int &line, bool pwd ) :
209 VStringConfigControl( _p_this, _p_item, _parent )
211 label = new QLabel( qtr(p_item->psz_text) );
212 text = new QLineEdit( qfu(p_item->value.psz) );
213 if( pwd ) text->setEchoMode( QLineEdit::Password );
218 QHBoxLayout *layout = new QHBoxLayout();
219 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
220 layout->addWidget( text, LAST_COLUMN );
221 widget->setLayout( layout );
225 l->addWidget( label, line, 0 );
226 l->setColumnMinimumWidth( 1, 10 );
227 l->addWidget( text, line, LAST_COLUMN );
231 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
232 module_config_t *_p_item,
233 QLabel *_label, QLineEdit *_text, bool pwd ):
234 VStringConfigControl( _p_this, _p_item )
241 void StringConfigControl::finish()
243 text->setText( qfu(p_item->value.psz) );
244 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
246 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
249 /*********** File **************/
250 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
251 module_config_t *_p_item,
252 QWidget *_parent, QGridLayout *l,
253 int &line, bool pwd ) :
254 VStringConfigControl( _p_this, _p_item, _parent )
256 label = new QLabel( qtr(p_item->psz_text) );
257 text = new QLineEdit( qfu(p_item->value.psz) );
258 browse = new QPushButton( qtr( "Browse..." ) );
259 QHBoxLayout *textAndButton = new QHBoxLayout();
260 textAndButton->setMargin( 0 );
261 textAndButton->addWidget( text, 2 );
262 textAndButton->addWidget( browse, 0 );
264 BUTTONACT( browse, updateField() );
270 QHBoxLayout *layout = new QHBoxLayout();
271 layout->addWidget( label, 0 );
272 layout->insertSpacing( 1, 10 );
273 layout->addLayout( textAndButton, LAST_COLUMN );
274 widget->setLayout( layout );
278 l->addWidget( label, line, 0 );
279 l->setColumnMinimumWidth( 1, 10 );
280 l->addLayout( textAndButton, line, LAST_COLUMN );
285 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
286 module_config_t *_p_item,
287 QLabel *_label, QLineEdit *_text,
288 QPushButton *_button, bool pwd ):
289 VStringConfigControl( _p_this, _p_item )
295 BUTTONACT( browse, updateField() );
300 void FileConfigControl::updateField()
302 QString file = QFileDialog::getOpenFileName( NULL,
303 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
304 if( file.isNull() ) return;
305 text->setText( file );
308 void FileConfigControl::finish()
310 text->setText( qfu(p_item->value.psz) );
311 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
313 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
316 /********* String / Directory **********/
317 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
318 module_config_t *_p_item, QWidget *_p_widget,
319 QGridLayout *_p_layout, int& _int, bool _pwd ) :
320 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
323 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
324 module_config_t *_p_item, QLabel *_p_label,
325 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
326 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
329 void DirectoryConfigControl::updateField()
331 QString dir = QFileDialog::getExistingDirectory( NULL,
332 qtr( "Select Directory" ),
333 text->text().isEmpty() ?
334 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
335 QFileDialog::ShowDirsOnly |
336 QFileDialog::DontResolveSymlinks );
337 if( dir.isNull() ) return;
338 text->setText( dir );
342 #include <QFontDialog>
344 /********* String / Font **********/
345 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
346 module_config_t *_p_item, QWidget *_p_widget,
347 QGridLayout *_p_layout, int& _int, bool _pwd ) :
348 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
351 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
352 module_config_t *_p_item, QLabel *_p_label,
353 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
354 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
357 void FontConfigControl::updateField()
360 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
362 text->setText( font.family() );
366 /********* String / choice list **********/
367 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
368 module_config_t *_p_item, QWidget *_parent, bool bycat,
369 QGridLayout *l, int &line) :
370 VStringConfigControl( _p_this, _p_item, _parent )
372 label = new QLabel( qtr(p_item->psz_text) );
373 combo = new QComboBox();
374 combo->setMinimumWidth( MINWIDTH_BOX );
375 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
379 l = new QGridLayout();
380 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
381 widget->setLayout( l );
385 l->addWidget( label, line, 0 );
386 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
389 if( p_item->i_action )
391 QSignalMapper *signalMapper = new QSignalMapper(this);
393 /* Some stringLists like Capture listings have action associated */
394 for( int i = 0; i < p_item->i_action; i++ )
396 QPushButton *button =
397 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
398 CONNECT( button, clicked(), signalMapper, map() );
399 signalMapper->setMapping( button, i );
400 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
403 CONNECT( signalMapper, mapped( int ),
404 this, actionRequested( int ) );
408 void StringListConfigControl::actionRequested( int i_action )
410 /* Supplementary check for boundaries */
411 if( i_action < 0 || i_action >= p_item->i_action ) return;
415 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
417 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
419 if( p_item->b_dirty )
423 p_item->b_dirty = VLC_FALSE;
426 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
427 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
428 bool bycat ) : VStringConfigControl( _p_this, _p_item )
435 void StringListConfigControl::finish( bool bycat )
437 combo->setEditable( false );
439 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
441 combo->addItem( qfu(p_item->ppsz_list_text ?
442 p_item->ppsz_list_text[i_index] :
443 p_item->ppsz_list[i_index] ),
444 QVariant( p_item->ppsz_list[i_index] ) );
445 if( p_item->value.psz && !strcmp( p_item->value.psz,
446 p_item->ppsz_list[i_index] ) )
447 combo->setCurrentIndex( combo->count() - 1 );
449 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
451 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
454 QString StringListConfigControl::getValue()
456 return combo->itemData( combo->currentIndex() ).toString();
459 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
460 QComboBox *combo, QWidget *parent )
462 module_config_t *p_config =
463 config_FindConfig( VLC_OBJECT(p_intf), configname );
466 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
468 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
469 QVariant( p_config->pi_list[i_index] ) );
470 if( p_config->value.i == p_config->pi_list[i_index] )
472 combo->setCurrentIndex( i_index );
475 combo->setToolTip( qfu( p_config->psz_longtext ) );
479 /********* Module **********/
480 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
481 module_config_t *_p_item, QWidget *_parent, bool bycat,
482 QGridLayout *l, int &line) :
483 VStringConfigControl( _p_this, _p_item, _parent )
485 label = new QLabel( qtr(p_item->psz_text) );
486 combo = new QComboBox();
487 combo->setMinimumWidth( MINWIDTH_BOX );
491 QHBoxLayout *layout = new QHBoxLayout();
492 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
493 widget->setLayout( layout );
497 l->addWidget( label, line, 0 );
498 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
502 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
503 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
504 bool bycat ) : VStringConfigControl( _p_this, _p_item )
511 void ModuleConfigControl::finish( bool bycat )
516 combo->setEditable( false );
518 /* build a list of available modules */
519 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
520 combo->addItem( qtr("Default") );
521 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
523 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
527 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
530 module_config_t *p_config;
532 p_config = module_GetConfig (p_parser, &confsize);
533 for (size_t i = 0; i < confsize; i++)
535 /* Hack: required subcategory is stored in i_min */
536 const module_config_t *p_cfg = p_config + i;
537 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
538 p_cfg->value.i == p_item->min.i )
539 combo->addItem( qtr( module_GetLongName( p_parser )),
540 QVariant( module_GetObjName( p_parser ) ) );
541 if( p_item->value.psz && !strcmp( p_item->value.psz,
542 module_GetObjName( p_parser ) ) )
543 combo->setCurrentIndex( combo->count() - 1 );
545 module_PutConfig (p_config);
547 else if( module_IsCapable( p_parser, p_item->psz_type ) )
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 );
556 vlc_list_release( p_list );
557 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
559 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
562 QString ModuleConfigControl::getValue()
564 return combo->itemData( combo->currentIndex() ).toString();
567 /********* Module list **********/
568 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
569 module_config_t *_p_item, QWidget *_parent, bool bycat,
570 QGridLayout *l, int &line) :
571 VStringConfigControl( _p_this, _p_item, _parent )
573 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
574 text = new QLineEdit();
575 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
580 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
581 it != modules.end(); it++ )
583 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
585 layoutGroupBox->addWidget( text, boxline, 0 );
589 QVBoxLayout *layout = new QVBoxLayout();
590 layout->addWidget( groupBox, line, 0 );
591 widget->setLayout( layout );
595 l->addWidget( groupBox, line, 0, 1, -1 );
598 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
601 ModuleListConfigControl::~ModuleListConfigControl()
603 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
604 it != modules.end(); it++ )
612 #define CHECKBOX_LISTS \
614 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
615 checkBoxListItem *cbl = new checkBoxListItem; \
617 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
618 cb->setToolTip( formatTooltip( qtr( module_GetHelp( p_parser ))));\
619 cbl->checkBox = cb; \
621 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
622 modules.push_back( cbl ); \
624 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
625 cbl->checkBox->setChecked( true ); \
629 void ModuleListConfigControl::finish( bool bycat )
634 /* build a list of available modules */
635 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
636 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
638 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
642 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
645 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
647 for (size_t i = 0; i < confsize; i++)
649 module_config_t *p_cfg = p_config + i;
650 /* Hack: required subcategory is stored in i_min */
651 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
652 p_cfg->value.i == p_item->min.i )
657 module_PutConfig (p_config);
659 else if( module_IsCapable( p_parser, p_item->psz_type ) )
664 vlc_list_release( p_list );
665 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
667 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
669 #undef CHECKBOX_LISTS
671 QString ModuleListConfigControl::getValue()
676 void ModuleListConfigControl::hide()
678 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
679 it != modules.end(); it++ )
681 (*it)->checkBox->hide();
686 void ModuleListConfigControl::show()
688 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
689 it != modules.end(); it++ )
691 (*it)->checkBox->show();
697 void ModuleListConfigControl::onUpdate( int value )
702 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
703 it != modules.end(); it++ )
705 if( (*it)->checkBox->isChecked() )
709 text->setText( text->text() + (*it)->psz_module );
714 text->setText( text->text() + ":" + (*it)->psz_module );
720 /**************************************************************************
721 * Integer-based controls
722 *************************************************************************/
724 /*********** Integer **************/
725 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
726 module_config_t *_p_item,
727 QWidget *_parent, QGridLayout *l,
729 VIntConfigControl( _p_this, _p_item, _parent )
731 label = new QLabel( qtr(p_item->psz_text) );
732 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
733 spin->setAlignment( Qt::AlignRight );
734 spin->setMaximumWidth( MINWIDTH_BOX );
739 QHBoxLayout *layout = new QHBoxLayout();
740 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
741 widget->setLayout( layout );
745 l->addWidget( label, line, 0 );
746 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
749 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
750 module_config_t *_p_item,
751 QLabel *_label, QSpinBox *_spin ) :
752 VIntConfigControl( _p_this, _p_item )
759 void IntegerConfigControl::finish()
761 spin->setMaximum( 2000000000 );
762 spin->setMinimum( -2000000000 );
763 spin->setValue( p_item->value.i );
764 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
766 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
769 int IntegerConfigControl::getValue()
771 return spin->value();
774 /********* Integer range **********/
775 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
776 module_config_t *_p_item,
777 QWidget *_parent, QGridLayout *l,
779 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
784 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
785 module_config_t *_p_item,
786 QLabel *_label, QSpinBox *_spin ) :
787 IntegerConfigControl( _p_this, _p_item, _label, _spin )
792 void IntegerRangeConfigControl::finish()
794 spin->setMaximum( p_item->max.i );
795 spin->setMinimum( p_item->min.i );
798 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
799 vlc_object_t *_p_this,
800 module_config_t *_p_item,
801 QLabel *_label, QSlider *_slider ):
802 VIntConfigControl( _p_this, _p_item )
806 slider->setMaximum( p_item->max.i );
807 slider->setMinimum( p_item->min.i );
808 slider->setValue( p_item->value.i );
809 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
811 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
814 int IntegerRangeSliderConfigControl::getValue()
816 return slider->value();
820 /********* Integer / choice list **********/
821 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
822 module_config_t *_p_item, QWidget *_parent, bool bycat,
823 QGridLayout *l, int &line) :
824 VIntConfigControl( _p_this, _p_item, _parent )
826 label = new QLabel( qtr(p_item->psz_text) );
827 combo = new QComboBox();
828 combo->setMinimumWidth( MINWIDTH_BOX );
832 QHBoxLayout *layout = new QHBoxLayout();
833 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
834 widget->setLayout( layout );
838 l->addWidget( label, line, 0 );
839 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
842 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
843 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
844 bool bycat ) : VIntConfigControl( _p_this, _p_item )
851 void IntegerListConfigControl::finish( bool bycat )
853 combo->setEditable( false );
855 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
857 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
858 QVariant( p_item->pi_list[i_index] ) );
859 if( p_item->value.i == p_item->pi_list[i_index] )
860 combo->setCurrentIndex( combo->count() - 1 );
862 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
864 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
867 int IntegerListConfigControl::getValue()
869 return combo->itemData( combo->currentIndex() ).toInt();
872 /*********** Boolean **************/
873 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
874 module_config_t *_p_item,
875 QWidget *_parent, QGridLayout *l,
877 VIntConfigControl( _p_this, _p_item, _parent )
879 checkbox = new QCheckBox( qtr(p_item->psz_text) );
884 QHBoxLayout *layout = new QHBoxLayout();
885 layout->addWidget( checkbox, 0 );
886 widget->setLayout( layout );
890 l->addWidget( checkbox, line, 0 );
893 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
894 module_config_t *_p_item,
896 QCheckBox *_checkbox,
898 VIntConfigControl( _p_this, _p_item )
900 checkbox = _checkbox;
904 void BoolConfigControl::finish()
906 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
908 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
911 int BoolConfigControl::getValue()
913 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
916 /**************************************************************************
917 * Float-based controls
918 *************************************************************************/
920 /*********** Float **************/
921 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
922 module_config_t *_p_item,
923 QWidget *_parent, QGridLayout *l,
925 VFloatConfigControl( _p_this, _p_item, _parent )
927 label = new QLabel( qtr(p_item->psz_text) );
928 spin = new QDoubleSpinBox;
929 spin->setMinimumWidth( MINWIDTH_BOX );
930 spin->setMaximumWidth( MINWIDTH_BOX );
931 spin->setAlignment( Qt::AlignRight );
936 QHBoxLayout *layout = new QHBoxLayout();
937 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
938 widget->setLayout( layout );
942 l->addWidget( label, line, 0 );
943 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
947 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
948 module_config_t *_p_item,
950 QDoubleSpinBox *_spin ) :
951 VFloatConfigControl( _p_this, _p_item )
958 void FloatConfigControl::finish()
960 spin->setMaximum( 2000000000. );
961 spin->setMinimum( -2000000000. );
962 spin->setSingleStep( 0.1 );
963 spin->setValue( (double)p_item->value.f );
964 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
966 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
969 float FloatConfigControl::getValue()
971 return (float)spin->value();
974 /*********** Float with range **************/
975 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
976 module_config_t *_p_item,
977 QWidget *_parent, QGridLayout *l,
979 FloatConfigControl( _p_this, _p_item, _parent, l, line )
984 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
985 module_config_t *_p_item,
987 QDoubleSpinBox *_spin ) :
988 FloatConfigControl( _p_this, _p_item, _label, _spin )
993 void FloatRangeConfigControl::finish()
995 spin->setMaximum( (double)p_item->max.f );
996 spin->setMinimum( (double)p_item->min.f );
1000 /**********************************************************************
1001 * Key selector widget
1002 **********************************************************************/
1003 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1004 module_config_t *_p_item,
1005 QWidget *_parent, QGridLayout *l,
1007 ConfigControl( _p_this, _p_item, _parent )
1010 QWidget *keyContainer = new QWidget;
1011 QGridLayout *gLayout = new QGridLayout( keyContainer );
1014 qtr( "Select an action to change the associated hotkey") );
1016 /* Deactivated for now
1017 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1018 QLineEdit *actionSearch = new QLineEdit;*/
1020 table = new QTreeWidget;
1021 table->setColumnCount(2);
1022 table->headerItem()->setText( 0, qtr( "Action" ) );
1023 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1025 shortcutValue = new KeyShortcutEdit;
1026 shortcutValue->setReadOnly(true);
1028 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1029 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1030 setButton->setDefault( true );
1033 gLayout->addWidget( label, 0, 0, 1, 4 );
1034 /* deactivated for now
1035 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1036 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1037 gLayout->addWidget( table, 2, 0, 1, 4 );
1038 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1039 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1040 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1042 l->addWidget( keyContainer, line, 0, 1, 2 );
1044 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1045 BUTTONACT( setButton, setTheKey() );
1048 void KeySelectorControl::finish()
1051 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1053 /* Fill the table */
1054 table->setColumnCount( 2 );
1055 table->setAlternatingRowColors( true );
1057 /* Get the main Module */
1058 module_t *p_main = module_Find( p_this, "main" );
1061 /* Access to the module_config_t */
1063 module_config_t *p_config;
1065 p_config = module_GetConfig (p_main, &confsize);
1067 for (size_t i = 0; i < confsize; i++)
1069 module_config_t *p_item = p_config + i;
1071 /* If we are a key option not empty */
1072 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1073 && strstr( p_item->psz_name , "key-" )
1074 && !EMPTY_STR( p_item->psz_text ) )
1078 - QString text in column 0
1079 - QString name in data of column 0
1080 - KeyValue in String in column 1
1081 - KeyValue in int in column 1
1083 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1084 treeItem->setText( 0, qtr( p_item->psz_text ) );
1085 treeItem->setData( 0, Qt::UserRole,
1086 QVariant( qfu( p_item->psz_name ) ) );
1087 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1088 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1089 table->addTopLevelItem( treeItem );
1092 module_PutConfig (p_config);
1093 module_Put (p_main);
1095 table->resizeColumnToContents( 0 );
1097 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1098 this, select1Key( QTreeWidgetItem * ) );
1099 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1100 this, selectKey( QTreeWidgetItem * ) );
1101 CONNECT( shortcutValue, pressed(), this, selectKey() );
1104 /* Show the key selected from the table in the keySelector */
1105 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1107 shortcutValue->setText( keyItem->text( 1 ) );
1108 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1111 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1113 /* This happens when triggered by ClickEater */
1114 if( keyItem == NULL ) keyItem = table->currentItem();
1116 /* This can happen when nothing is selected on the treeView
1117 and the shortcutValue is clicked */
1118 if( !keyItem ) return;
1120 /* Launch a small dialog to ask for a new key */
1121 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget );
1124 if( d->result() == QDialog::Accepted )
1126 int newValue = d->keyValue;
1127 shortcutValue->setText( VLCKeyToString( newValue ) );
1128 shortcutValue->setValue( newValue );
1132 QTreeWidgetItem *it;
1133 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1135 it = table->topLevelItem(i);
1136 if( ( keyItem != it )
1137 && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) )
1139 it->setData( 1, Qt::UserRole, QVariant( -1 ) );
1140 it->setText( 1, qtr( "Unset" ) );
1143 /* We already made an OK once. */
1150 void KeySelectorControl::setTheKey()
1152 table->currentItem()->setText( 1, shortcutValue->text() );
1153 table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );
1156 void KeySelectorControl::doApply()
1158 QTreeWidgetItem *it;
1159 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1161 it = table->topLevelItem(i);
1162 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1163 config_PutInt( p_this,
1164 qtu( it->data( 0, Qt::UserRole ).toString() ),
1165 it->data( 1, Qt::UserRole ).toInt() );
1169 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1170 QString keyToChange,
1171 QWidget *_parent ) :
1172 QDialog( _parent ), keyValue(0)
1178 setWindowTitle( qtr( "Hotkey for " ) + keyToChange );
1180 vLayout = new QVBoxLayout( this );
1181 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1182 vLayout->addWidget( selected , Qt::AlignCenter );
1184 buttonBox = new QDialogButtonBox;
1185 QPushButton *ok = new QPushButton( qtr("OK") );
1186 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1187 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1188 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1189 ok->setDefault( true );
1191 vLayout->addWidget( buttonBox );
1194 CONNECT( buttonBox, accepted(), this, accept() );
1195 CONNECT( buttonBox, rejected(), this, reject() );
1198 void KeyInputDialog::checkForConflicts( int i_vlckey )
1200 QList<QTreeWidgetItem *> conflictList =
1201 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 );
1203 if( conflictList.size() )
1205 QLabel *warning = new QLabel(
1206 qtr("Warning: the key is already assigned to \"") +
1207 conflictList[0]->text( 0 ) + "\"" );
1208 vLayout->insertWidget( 1, warning );
1216 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1218 if( e->key() == Qt::Key_Tab ||
1219 e->key() == Qt::Key_Shift ||
1220 e->key() == Qt::Key_Control ||
1221 e->key() == Qt::Key_Meta ||
1222 e->key() == Qt::Key_Alt ||
1223 e->key() == Qt::Key_AltGr )
1225 int i_vlck = qtEventToVLCKey( e );
1226 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1227 checkForConflicts( i_vlck );
1231 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1233 int i_vlck = qtWheelEventToVLCKey( e );
1234 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1235 checkForConflicts( i_vlck );
1239 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)