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"
39 #include "util/qt_dirs.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'; "
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,
101 /* Special Hack for a bug in video-filter */
102 if( qobject_cast<ModuleListConfigControl *>( p_control )->groupBox == NULL )
105 case CONFIG_ITEM_STRING:
106 if( !p_item->i_list )
107 p_control = new StringConfigControl( p_this, p_item, parent,
110 p_control = new StringListConfigControl( p_this, p_item,
111 parent, false, l, line );
113 case CONFIG_ITEM_PASSWORD:
114 if( !p_item->i_list )
115 p_control = new StringConfigControl( p_this, p_item, parent,
118 p_control = new StringListConfigControl( p_this, p_item,
119 parent, true, l, line );
121 case CONFIG_ITEM_INTEGER:
123 p_control = new IntegerListConfigControl( p_this, p_item,
124 parent, false, l, line );
125 else if( p_item->min.i || p_item->max.i )
126 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
129 p_control = new IntegerConfigControl( p_this, p_item, parent,
132 case CONFIG_ITEM_FILE:
133 p_control = new FileConfigControl( p_this, p_item, parent, l, line);
135 case CONFIG_ITEM_DIRECTORY:
136 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
139 case CONFIG_ITEM_FONT:
140 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(), qtu( vscc->getValue() ) );
191 case CONFIG_ITEM_KEY:
193 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
200 /*******************************************************
202 *******************************************************/
203 InterfacePreviewWidget::InterfacePreviewWidget
204 ( QWidget *parent ) : QLabel( parent, 0 )
206 setGeometry( 0, 0, 128, 100 );
207 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
210 void InterfacePreviewWidget::setPreview( int comboid )
212 /* Need to move resources references as soon as qt4.cpp
213 local defines has been moved somewhere else
215 const char * pixmaps[] = { ":/prefsmenu/sample_classic",
216 ":/prefsmenu/sample_complete",
217 ":/prefsmenu/sample_minimal" };
218 setPixmap( QPixmap( pixmaps[ comboid ] ) );
223 /**************************************************************************
224 * String-based controls
225 *************************************************************************/
227 /*********** String **************/
228 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
229 module_config_t *_p_item,
230 QWidget *_parent, QGridLayout *l,
231 int &line, bool pwd ) :
232 VStringConfigControl( _p_this, _p_item, _parent )
234 label = new QLabel( qtr(p_item->psz_text) );
235 text = new QLineEdit( qfu(p_item->value.psz) );
236 if( pwd ) text->setEchoMode( QLineEdit::Password );
241 QHBoxLayout *layout = new QHBoxLayout();
242 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
243 layout->addWidget( text, LAST_COLUMN );
244 widget->setLayout( layout );
248 l->addWidget( label, line, 0 );
249 l->setColumnMinimumWidth( 1, 10 );
250 l->addWidget( text, line, LAST_COLUMN );
254 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
255 module_config_t *_p_item,
256 QLabel *_label, QLineEdit *_text, bool pwd ):
257 VStringConfigControl( _p_this, _p_item )
260 if( pwd ) text->setEchoMode( QLineEdit::Password );
265 void StringConfigControl::finish()
267 text->setText( qfu(p_item->value.psz) );
268 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
271 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
272 label->setBuddy( text );
276 /*********** File **************/
277 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
278 module_config_t *_p_item,
279 QWidget *_parent, QGridLayout *l,
281 VStringConfigControl( _p_this, _p_item, _parent )
283 label = new QLabel( qtr(p_item->psz_text) );
284 text = new QLineEdit( qfu(p_item->value.psz) );
285 browse = new QPushButton( qtr( "Browse..." ) );
286 QHBoxLayout *textAndButton = new QHBoxLayout();
287 textAndButton->setMargin( 0 );
288 textAndButton->addWidget( text, 2 );
289 textAndButton->addWidget( browse, 0 );
291 BUTTONACT( browse, updateField() );
297 QHBoxLayout *layout = new QHBoxLayout();
298 layout->addWidget( label, 0 );
299 layout->insertSpacing( 1, 10 );
300 layout->addLayout( textAndButton, LAST_COLUMN );
301 widget->setLayout( layout );
305 l->addWidget( label, line, 0 );
306 l->setColumnMinimumWidth( 1, 10 );
307 l->addLayout( textAndButton, line, LAST_COLUMN );
312 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
313 module_config_t *_p_item,
314 QLabel *_label, QLineEdit *_text,
315 QPushButton *_button ):
316 VStringConfigControl( _p_this, _p_item )
322 BUTTONACT( browse, updateField() );
327 void FileConfigControl::updateField()
329 QString file = QFileDialog::getOpenFileName( NULL,
330 qtr( "Select File" ), qfu( config_GetHomeDir() ) );
331 if( file.isNull() ) return;
332 text->setText( toNativeSeparators( file ) );
335 void FileConfigControl::finish()
337 text->setText( qfu(p_item->value.psz) );
338 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
341 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
342 label->setBuddy( text );
346 /********* String / Directory **********/
347 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
348 module_config_t *_p_item, QWidget *_p_widget,
349 QGridLayout *_p_layout, int& _int ) :
350 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
353 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
354 module_config_t *_p_item, QLabel *_p_label,
355 QLineEdit *_p_line, QPushButton *_p_button ):
356 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
359 void DirectoryConfigControl::updateField()
361 QString dir = QFileDialog::getExistingDirectory( NULL,
362 qtr( "Select Directory" ),
363 text->text().isEmpty() ?
364 qfu( config_GetHomeDir() ) : text->text(),
365 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
367 if( dir.isNull() ) return;
368 text->setText( toNativeSepNoSlash( dir ) );
371 #include <QFontDialog>
373 /********* String / Font **********/
374 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
375 module_config_t *_p_item, QWidget *_p_widget,
376 QGridLayout *_p_layout, int& _int) :
377 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int)
380 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
381 module_config_t *_p_item, QLabel *_p_label,
382 QLineEdit *_p_line, QPushButton *_p_button):
383 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
386 void FontConfigControl::updateField()
389 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
391 text->setText( font.family() );
394 /********* String / choice list **********/
395 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
396 module_config_t *_p_item, QWidget *_parent, bool bycat,
397 QGridLayout *l, int &line) :
398 VStringConfigControl( _p_this, _p_item, _parent )
400 label = new QLabel( qtr(p_item->psz_text) );
401 combo = new QComboBox();
402 combo->setMinimumWidth( MINWIDTH_BOX );
403 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
405 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
406 if(p_module_config && p_module_config->pf_update_list)
409 val.psz_string = strdup(p_module_config->value.psz);
411 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
413 // assume in any case that dirty was set to true
414 // because lazy programmes will use the same callback for
415 // this, like the one behind the refresh push button?
416 p_module_config->b_dirty = false;
418 free( val.psz_string );
421 finish( p_module_config, bycat );
424 l = new QGridLayout();
425 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
426 widget->setLayout( l );
430 l->addWidget( label, line, 0 );
431 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
434 if( p_item->i_action )
436 QSignalMapper *signalMapper = new QSignalMapper(this);
438 /* Some stringLists like Capture listings have action associated */
439 for( int i = 0; i < p_item->i_action; i++ )
441 QPushButton *button =
442 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
443 CONNECT( button, clicked(), signalMapper, map() );
444 signalMapper->setMapping( button, i );
445 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
448 CONNECT( signalMapper, mapped( int ),
449 this, actionRequested( int ) );
453 void StringListConfigControl::actionRequested( int i_action )
455 /* Supplementary check for boundaries */
456 if( i_action < 0 || i_action >= p_item->i_action ) return;
458 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
459 if(!p_module_config) return;
462 val.psz_string = const_cast<char *>
463 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
465 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
467 if( p_module_config->b_dirty )
470 finish( p_module_config, true );
471 p_module_config->b_dirty = false;
474 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
475 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
476 bool bycat ) : VStringConfigControl( _p_this, _p_item )
481 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
483 finish( p_module_config, bycat );
486 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
488 combo->setEditable( false );
490 if(!p_module_config) return;
492 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
494 combo->addItem( qfu((p_module_config->ppsz_list_text &&
495 p_module_config->ppsz_list_text[i_index])?
496 p_module_config->ppsz_list_text[i_index] :
497 p_module_config->ppsz_list[i_index] ),
498 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
499 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
500 p_module_config->ppsz_list[i_index] ) )
501 combo->setCurrentIndex( combo->count() - 1 );
503 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
506 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
507 label->setBuddy( combo );
511 QString StringListConfigControl::getValue()
513 return combo->itemData( combo->currentIndex() ).toString();
516 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
519 module_config_t *p_config =
520 config_FindConfig( VLC_OBJECT(p_intf), configname );
523 if(p_config->pf_update_list)
526 val.i_int = p_config->value.i;
527 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
528 // assume in any case that dirty was set to true
529 // because lazy programmes will use the same callback for
530 // this, like the one behind the refresh push button?
531 p_config->b_dirty = false;
534 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
536 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
537 QVariant( p_config->pi_list[i_index] ) );
538 if( p_config->value.i == p_config->pi_list[i_index] )
540 combo->setCurrentIndex( i_index );
543 combo->setToolTip( qfu( p_config->psz_longtext ) );
547 /********* Module **********/
548 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
549 module_config_t *_p_item, QWidget *_parent, bool bycat,
550 QGridLayout *l, int &line) :
551 VStringConfigControl( _p_this, _p_item, _parent )
553 label = new QLabel( qtr(p_item->psz_text) );
554 combo = new QComboBox();
555 combo->setMinimumWidth( MINWIDTH_BOX );
559 QHBoxLayout *layout = new QHBoxLayout();
560 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
561 widget->setLayout( layout );
565 l->addWidget( label, line, 0 );
566 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
570 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
571 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
572 bool bycat ) : VStringConfigControl( _p_this, _p_item )
579 void ModuleConfigControl::finish( bool bycat )
583 combo->setEditable( false );
585 /* build a list of available modules */
586 module_t **p_list = module_list_get( NULL );
587 combo->addItem( qtr("Default") );
588 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
592 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
595 module_config_t *p_config;
597 p_config = module_config_get (p_parser, &confsize);
598 for (size_t i = 0; i < confsize; i++)
600 /* Hack: required subcategory is stored in i_min */
601 const module_config_t *p_cfg = p_config + i;
602 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
603 p_cfg->value.i == p_item->min.i )
604 combo->addItem( qtr( module_GetLongName( p_parser )),
605 QVariant( module_get_object( p_parser ) ) );
606 if( p_item->value.psz && !strcmp( p_item->value.psz,
607 module_get_object( p_parser ) ) )
608 combo->setCurrentIndex( combo->count() - 1 );
610 module_config_free (p_config);
612 else if( module_provides( p_parser, p_item->psz_type ) )
614 combo->addItem( qtr(module_GetLongName( p_parser ) ),
615 QVariant( module_get_object( p_parser ) ) );
616 if( p_item->value.psz && !strcmp( p_item->value.psz,
617 module_get_object( p_parser ) ) )
618 combo->setCurrentIndex( combo->count() - 1 );
621 module_list_free( p_list );
622 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
625 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
626 label->setBuddy( combo );
630 QString ModuleConfigControl::getValue()
632 return combo->itemData( combo->currentIndex() ).toString();
635 /********* Module list **********/
636 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
637 module_config_t *_p_item, QWidget *_parent, bool bycat,
638 QGridLayout *l, int &line) :
639 VStringConfigControl( _p_this, _p_item, _parent )
643 if( !p_item->psz_text ) return;
645 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
646 text = new QLineEdit;
647 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
652 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
653 it != modules.end(); it++ )
655 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
657 layoutGroupBox->addWidget( text, boxline, 0 );
661 QVBoxLayout *layout = new QVBoxLayout();
662 layout->addWidget( groupBox, line, 0 );
663 widget->setLayout( layout );
667 l->addWidget( groupBox, line, 0, 1, -1 );
670 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
673 ModuleListConfigControl::~ModuleListConfigControl()
675 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
676 it != modules.end(); it++ )
683 #define CHECKBOX_LISTS \
685 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
686 checkBoxListItem *cbl = new checkBoxListItem; \
688 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
689 cb->setToolTip( formatTooltip( qtr( module_get_help( p_parser ))));\
690 cbl->checkBox = cb; \
692 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
693 modules.push_back( cbl ); \
695 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
696 cbl->checkBox->setChecked( true ); \
700 void ModuleListConfigControl::finish( bool bycat )
704 /* build a list of available modules */
705 module_t **p_list = module_list_get( NULL );
706 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
710 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
713 module_config_t *p_config = module_config_get (p_parser, &confsize);
715 for (size_t i = 0; i < confsize; i++)
717 module_config_t *p_cfg = p_config + i;
718 /* Hack: required subcategory is stored in i_min */
719 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
720 p_cfg->value.i == p_item->min.i )
725 module_config_free (p_config);
727 else if( module_provides( p_parser, p_item->psz_type ) )
732 module_list_free( p_list );
733 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
735 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
737 #undef CHECKBOX_LISTS
739 QString ModuleListConfigControl::getValue()
745 void ModuleListConfigControl::hide()
747 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
748 it != modules.end(); it++ )
750 (*it)->checkBox->hide();
755 void ModuleListConfigControl::show()
757 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
758 it != modules.end(); it++ )
760 (*it)->checkBox->show();
766 void ModuleListConfigControl::onUpdate()
771 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
772 it != modules.end(); it++ )
774 if( (*it)->checkBox->isChecked() )
778 text->setText( text->text() + (*it)->psz_module );
783 text->setText( text->text() + ":" + (*it)->psz_module );
789 /**************************************************************************
790 * Integer-based controls
791 *************************************************************************/
793 /*********** Integer **************/
794 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
795 module_config_t *_p_item,
796 QWidget *_parent, QGridLayout *l,
798 VIntConfigControl( _p_this, _p_item, _parent )
800 label = new QLabel( qtr(p_item->psz_text) );
801 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
802 spin->setAlignment( Qt::AlignRight );
803 spin->setMaximumWidth( MINWIDTH_BOX );
808 QHBoxLayout *layout = new QHBoxLayout();
809 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
810 widget->setLayout( layout );
814 l->addWidget( label, line, 0 );
815 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
818 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
819 module_config_t *_p_item,
820 QLabel *_label, QSpinBox *_spin ) :
821 VIntConfigControl( _p_this, _p_item )
828 void IntegerConfigControl::finish()
830 spin->setMaximum( 2000000000 );
831 spin->setMinimum( -2000000000 );
832 spin->setValue( p_item->value.i );
833 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
836 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
837 label->setBuddy( spin );
841 int IntegerConfigControl::getValue()
843 return spin->value();
846 /********* Integer range **********/
847 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
848 module_config_t *_p_item,
849 QWidget *_parent, QGridLayout *l,
851 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
856 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
857 module_config_t *_p_item,
858 QLabel *_label, QSpinBox *_spin ) :
859 IntegerConfigControl( _p_this, _p_item, _label, _spin )
864 void IntegerRangeConfigControl::finish()
866 spin->setMaximum( p_item->max.i );
867 spin->setMinimum( p_item->min.i );
870 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
871 vlc_object_t *_p_this,
872 module_config_t *_p_item,
873 QLabel *_label, QSlider *_slider ):
874 VIntConfigControl( _p_this, _p_item )
878 slider->setMaximum( p_item->max.i );
879 slider->setMinimum( p_item->min.i );
880 slider->setValue( p_item->value.i );
881 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
884 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
885 label->setBuddy( slider );
889 int IntegerRangeSliderConfigControl::getValue()
891 return slider->value();
895 /********* Integer / choice list **********/
896 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
897 module_config_t *_p_item, QWidget *_parent, bool bycat,
898 QGridLayout *l, int &line) :
899 VIntConfigControl( _p_this, _p_item, _parent )
901 label = new QLabel( qtr(p_item->psz_text) );
902 combo = new QComboBox();
903 combo->setMinimumWidth( MINWIDTH_BOX );
905 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
906 if(p_module_config && p_module_config->pf_update_list)
909 val.i_int = p_module_config->value.i;
911 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
913 // assume in any case that dirty was set to true
914 // because lazy programmes will use the same callback for
915 // this, like the one behind the refresh push button?
916 p_module_config->b_dirty = false;
920 finish( p_module_config, bycat );
923 QHBoxLayout *layout = new QHBoxLayout();
924 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
925 widget->setLayout( layout );
929 l->addWidget( label, line, 0 );
930 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
933 if( p_item->i_action )
935 QSignalMapper *signalMapper = new QSignalMapper(this);
937 /* Some stringLists like Capture listings have action associated */
938 for( int i = 0; i < p_item->i_action; i++ )
940 QPushButton *button =
941 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
942 CONNECT( button, clicked(), signalMapper, map() );
943 signalMapper->setMapping( button, i );
944 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
947 CONNECT( signalMapper, mapped( int ),
948 this, actionRequested( int ) );
952 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
953 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
954 bool bycat ) : VIntConfigControl( _p_this, _p_item )
959 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
961 finish( p_module_config, bycat );
964 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
966 combo->setEditable( false );
968 if(!p_module_config) return;
970 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
972 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
973 QVariant( p_module_config->pi_list[i_index] ) );
974 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
975 combo->setCurrentIndex( combo->count() - 1 );
977 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
980 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
981 label->setBuddy( combo );
985 void IntegerListConfigControl::actionRequested( int i_action )
987 /* Supplementary check for boundaries */
988 if( i_action < 0 || i_action >= p_item->i_action ) return;
990 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
991 if(!p_module_config) return;
995 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
997 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
999 if( p_module_config->b_dirty )
1002 finish( p_module_config, true );
1003 p_module_config->b_dirty = false;
1007 int IntegerListConfigControl::getValue()
1009 return combo->itemData( combo->currentIndex() ).toInt();
1012 /*********** Boolean **************/
1013 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1014 module_config_t *_p_item,
1015 QWidget *_parent, QGridLayout *l,
1017 VIntConfigControl( _p_this, _p_item, _parent )
1019 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1024 QHBoxLayout *layout = new QHBoxLayout();
1025 layout->addWidget( checkbox, 0 );
1026 widget->setLayout( layout );
1030 l->addWidget( checkbox, line, 0 );
1033 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1034 module_config_t *_p_item,
1036 QAbstractButton *_checkbox,
1038 VIntConfigControl( _p_this, _p_item )
1040 checkbox = _checkbox;
1041 VLC_UNUSED( _label );
1045 void BoolConfigControl::finish()
1047 checkbox->setChecked( p_item->value.i == true );
1048 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1051 int BoolConfigControl::getValue()
1053 return checkbox->isChecked();
1056 /**************************************************************************
1057 * Float-based controls
1058 *************************************************************************/
1060 /*********** Float **************/
1061 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1062 module_config_t *_p_item,
1063 QWidget *_parent, QGridLayout *l,
1065 VFloatConfigControl( _p_this, _p_item, _parent )
1067 label = new QLabel( qtr(p_item->psz_text) );
1068 spin = new QDoubleSpinBox;
1069 spin->setMinimumWidth( MINWIDTH_BOX );
1070 spin->setMaximumWidth( MINWIDTH_BOX );
1071 spin->setAlignment( Qt::AlignRight );
1076 QHBoxLayout *layout = new QHBoxLayout();
1077 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1078 widget->setLayout( layout );
1082 l->addWidget( label, line, 0 );
1083 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1087 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1088 module_config_t *_p_item,
1090 QDoubleSpinBox *_spin ) :
1091 VFloatConfigControl( _p_this, _p_item )
1098 void FloatConfigControl::finish()
1100 spin->setMaximum( 2000000000. );
1101 spin->setMinimum( -2000000000. );
1102 spin->setSingleStep( 0.1 );
1103 spin->setValue( (double)p_item->value.f );
1104 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1107 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1108 label->setBuddy( spin );
1112 float FloatConfigControl::getValue()
1114 return (float)spin->value();
1117 /*********** Float with range **************/
1118 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1119 module_config_t *_p_item,
1120 QWidget *_parent, QGridLayout *l,
1122 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1127 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1128 module_config_t *_p_item,
1130 QDoubleSpinBox *_spin ) :
1131 FloatConfigControl( _p_this, _p_item, _label, _spin )
1136 void FloatRangeConfigControl::finish()
1138 spin->setMaximum( (double)p_item->max.f );
1139 spin->setMinimum( (double)p_item->min.f );
1143 /**********************************************************************
1144 * Key selector widget
1145 **********************************************************************/
1146 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1147 module_config_t *_p_item,
1148 QWidget *_parent, QGridLayout *l,
1150 ConfigControl( _p_this, _p_item, _parent )
1153 QWidget *keyContainer = new QWidget;
1154 QGridLayout *gLayout = new QGridLayout( keyContainer );
1157 qtr( "Select an action to change the associated hotkey") );
1159 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1160 actionSearch = new SearchLineEdit( keyContainer );
1162 table = new QTreeWidget;
1163 table->setColumnCount(3);
1164 table->headerItem()->setText( 0, qtr( "Action" ) );
1165 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1166 table->headerItem()->setText( 2, qtr( "Global" ) );
1167 table->setAlternatingRowColors( true );
1169 shortcutValue = new KeyShortcutEdit;
1170 shortcutValue->setReadOnly(true);
1172 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1173 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1174 setButton->setDefault( true );
1177 gLayout->addWidget( label, 0, 0, 1, 4 );
1178 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1179 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1180 gLayout->addWidget( table, 2, 0, 1, 4 );
1181 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1182 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1183 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1185 l->addWidget( keyContainer, line, 0, 1, -1 );
1187 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1188 CONNECT( clearButton, clicked(), this, setTheKey() );
1189 BUTTONACT( setButton, setTheKey() );
1190 CONNECT( actionSearch, textChanged( const QString& ),
1191 this, filter( const QString& ) );
1194 void KeySelectorControl::finish()
1197 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1199 /* Fill the table */
1201 /* Get the main Module */
1202 module_t *p_main = module_get_main();
1205 /* Access to the module_config_t */
1207 module_config_t *p_config;
1209 p_config = module_config_get (p_main, &confsize);
1211 for (size_t i = 0; i < confsize; i++)
1213 module_config_t *p_item = p_config + i;
1215 /* If we are a key option not empty */
1216 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1217 && strstr( p_item->psz_name , "key-" )
1218 && !strstr( p_item->psz_name , "global-key" )
1219 && !EMPTY_STR( p_item->psz_text ) )
1223 - QString text in column 0
1224 - QString name in data of column 0
1225 - KeyValue in String in column 1
1226 - KeyValue in int in column 1
1228 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1229 treeItem->setText( 0, qtr( p_item->psz_text ) );
1230 treeItem->setData( 0, Qt::UserRole,
1231 QVariant( qfu( p_item->psz_name ) ) );
1232 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1233 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1234 table->addTopLevelItem( treeItem );
1238 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1239 && strstr( p_item->psz_name , "global-key" )
1240 && !EMPTY_STR( p_item->psz_text ) )
1242 QList<QTreeWidgetItem *> list =
1243 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1244 if( list.count() >= 1 )
1246 list[0]->setText( 2, VLCKeyToString( p_item->value.i ) );
1247 list[0]->setData( 2, Qt::UserRole,
1248 QVariant( p_item->value.i ) );
1250 if( list.count() >= 2 )
1251 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1254 module_config_free (p_config);
1255 module_release (p_main);
1257 table->resizeColumnToContents( 0 );
1259 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1260 this, selectKey( QTreeWidgetItem *, int ) );
1261 CONNECT( table, itemSelectionChanged(),
1262 this, select1Key() );
1264 CONNECT( shortcutValue, pressed(), this, selectKey() );
1267 void KeySelectorControl::filter( const QString &qs_search )
1269 QList<QTreeWidgetItem *> resultList =
1270 table->findItems( qs_search, Qt::MatchContains, 0 );
1271 for( int i = 0; i < table->topLevelItemCount(); i++ )
1273 table->topLevelItem( i )->setHidden(
1274 !resultList.contains( table->topLevelItem( i ) ) );
1278 /* Show the key selected from the table in the keySelector */
1279 void KeySelectorControl::select1Key()
1281 QTreeWidgetItem *keyItem = table->currentItem();
1282 shortcutValue->setText( keyItem->text( 1 ) );
1283 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1284 shortcutValue->setGlobal( false );
1287 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1289 /* This happens when triggered by ClickEater */
1290 if( keyItem == NULL ) keyItem = table->currentItem();
1292 /* This can happen when nothing is selected on the treeView
1293 and the shortcutValue is clicked */
1294 if( !keyItem ) return;
1296 /* If clicked on the first column, assuming user wants the normal hotkey */
1297 if( column == 0 ) column = 1;
1299 bool b_global = ( column == 2 );
1301 /* Launch a small dialog to ask for a new key */
1302 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1305 if( d->result() == QDialog::Accepted )
1307 int newValue = d->keyValue;
1308 shortcutValue->setText( VLCKeyToString( newValue ) );
1309 shortcutValue->setValue( newValue );
1310 shortcutValue->setGlobal( b_global );
1314 QTreeWidgetItem *it;
1315 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1317 it = table->topLevelItem(i);
1318 if( ( keyItem != it ) &&
1319 ( it->data( b_global ? 2: 1, Qt::UserRole ).toInt() == newValue ) )
1321 it->setData( b_global ? 2 : 1, Qt::UserRole, QVariant( -1 ) );
1322 it->setText( b_global ? 2 : 1, qtr( "Unset" ) );
1325 /* We already made an OK once. */
1332 void KeySelectorControl::setTheKey()
1334 if( !table->currentItem() ) return;
1335 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1336 shortcutValue->text() );
1337 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1338 Qt::UserRole, shortcutValue->getValue() );
1341 void KeySelectorControl::doApply()
1343 QTreeWidgetItem *it;
1344 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1346 it = table->topLevelItem(i);
1347 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1348 config_PutInt( p_this,
1349 qtu( it->data( 0, Qt::UserRole ).toString() ),
1350 it->data( 1, Qt::UserRole ).toInt() );
1351 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1352 config_PutInt( p_this,
1353 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1354 it->data( 2, Qt::UserRole ).toInt() );
1360 * Class KeyInputDialog
1362 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1363 const QString& keyToChange,
1366 QDialog( _parent ), keyValue(0), b_global( _b_global )
1372 setWindowTitle( b_global ? qtr( "Global" ): ""
1373 + qtr( "Hotkey for " ) + keyToChange );
1375 vLayout = new QVBoxLayout( this );
1376 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1377 vLayout->addWidget( selected , Qt::AlignCenter );
1379 warning = new QLabel;
1381 vLayout->insertWidget( 1, warning );
1383 buttonBox = new QDialogButtonBox;
1384 QPushButton *ok = new QPushButton( qtr("OK") );
1385 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1386 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1387 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1388 ok->setDefault( true );
1390 vLayout->addWidget( buttonBox );
1393 CONNECT( buttonBox, accepted(), this, accept() );
1394 CONNECT( buttonBox, rejected(), this, reject() );
1397 void KeyInputDialog::checkForConflicts( int i_vlckey )
1399 QList<QTreeWidgetItem *> conflictList =
1400 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1403 if( conflictList.size() &&
1404 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1405 /* Avoid 0 or -1 that are the "Unset" states */
1407 warning->setText( qtr("Warning: the key is already assigned to \"") +
1408 conflictList[0]->text( 0 ) + "\"" );
1417 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1419 if( e->key() == Qt::Key_Tab ||
1420 e->key() == Qt::Key_Shift ||
1421 e->key() == Qt::Key_Control ||
1422 e->key() == Qt::Key_Meta ||
1423 e->key() == Qt::Key_Alt ||
1424 e->key() == Qt::Key_AltGr )
1426 int i_vlck = qtEventToVLCKey( e );
1427 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1428 checkForConflicts( i_vlck );
1432 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1434 int i_vlck = qtWheelEventToVLCKey( e );
1435 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1436 checkForConflicts( i_vlck );
1440 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)