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"
41 #include <vlc_intf_strings.h>
45 #include <QGridLayout>
47 #include <QFileDialog>
49 #include <QTreeWidgetItem>
50 #include <QSignalMapper>
51 #include <QDialogButtonBox>
54 #define MINWIDTH_BOX 90
55 #define LAST_COLUMN 10
57 QString formatTooltip(const QString & tooltip)
60 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
61 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
62 "<body style=\" font-family:'Sans Serif'; "
63 "font-style:normal; text-decoration:none;\">"
64 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
65 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
71 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
72 module_config_t *p_item,
76 return createControl( p_this, p_item, parent, NULL, i );
79 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
80 module_config_t *p_item,
82 QGridLayout *l, int &line )
84 ConfigControl *p_control = NULL;
86 switch( p_item->i_type )
88 case CONFIG_ITEM_MODULE:
89 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
92 case CONFIG_ITEM_MODULE_CAT:
93 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
96 case CONFIG_ITEM_MODULE_LIST:
97 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
100 case CONFIG_ITEM_MODULE_LIST_CAT:
101 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
104 case CONFIG_ITEM_STRING:
105 if( !p_item->i_list )
106 p_control = new StringConfigControl( p_this, p_item, parent,
109 p_control = new StringListConfigControl( p_this, p_item,
110 parent, false, l, line );
112 case CONFIG_ITEM_PASSWORD:
113 if( !p_item->i_list )
114 p_control = new StringConfigControl( p_this, p_item, parent,
117 p_control = new StringListConfigControl( p_this, p_item,
118 parent, true, l, line );
120 case CONFIG_ITEM_INTEGER:
122 p_control = new IntegerListConfigControl( p_this, p_item,
123 parent, false, l, line );
124 else if( p_item->min.i || p_item->max.i )
125 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
128 p_control = new IntegerConfigControl( p_this, p_item, parent,
131 case CONFIG_ITEM_FILE:
132 p_control = new FileConfigControl( p_this, p_item, parent, l, line);
134 case CONFIG_ITEM_DIRECTORY:
135 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,
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(), qtu( vscc->getValue() ) );
190 case CONFIG_ITEM_KEY:
192 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
199 /*******************************************************
201 *******************************************************/
202 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
204 setGeometry( 0, 0, 128, 100 );
205 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
208 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
210 setPreview( ( b_minimal )?MINIMAL:COMPLETE );
213 void InterfacePreviewWidget::setPreview( enum_style e_style )
215 QString pixmapLocationString(":/prefsmenu/");
221 pixmapLocationString += "sample_complete";
224 pixmapLocationString += "sample_minimal";
227 pixmapLocationString += "sample_skins";
231 setPixmap( QPixmap( pixmapLocationString ) );
237 /**************************************************************************
238 * String-based controls
239 *************************************************************************/
241 /*********** String **************/
242 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
243 module_config_t *_p_item,
244 QWidget *_parent, QGridLayout *l,
245 int &line, bool pwd ) :
246 VStringConfigControl( _p_this, _p_item, _parent )
248 label = new QLabel( qtr(p_item->psz_text) );
249 text = new QLineEdit( qfu(p_item->value.psz) );
250 if( pwd ) text->setEchoMode( QLineEdit::Password );
255 QHBoxLayout *layout = new QHBoxLayout();
256 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
257 layout->addWidget( text, LAST_COLUMN );
258 widget->setLayout( layout );
262 l->addWidget( label, line, 0 );
263 l->setColumnMinimumWidth( 1, 10 );
264 l->addWidget( text, line, LAST_COLUMN );
268 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
269 module_config_t *_p_item,
270 QLabel *_label, QLineEdit *_text, bool pwd ):
271 VStringConfigControl( _p_this, _p_item )
274 if( pwd ) text->setEchoMode( QLineEdit::Password );
279 void StringConfigControl::finish()
281 text->setText( qfu(p_item->value.psz) );
282 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
285 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
286 label->setBuddy( text );
290 /*********** File **************/
291 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
292 module_config_t *_p_item,
293 QWidget *_parent, QGridLayout *l,
295 VStringConfigControl( _p_this, _p_item, _parent )
297 label = new QLabel( qtr(p_item->psz_text) );
298 text = new QLineEdit( qfu(p_item->value.psz) );
299 browse = new QPushButton( qtr( "Browse..." ) );
300 QHBoxLayout *textAndButton = new QHBoxLayout();
301 textAndButton->setMargin( 0 );
302 textAndButton->addWidget( text, 2 );
303 textAndButton->addWidget( browse, 0 );
305 BUTTONACT( browse, updateField() );
311 QHBoxLayout *layout = new QHBoxLayout();
312 layout->addWidget( label, 0 );
313 layout->insertSpacing( 1, 10 );
314 layout->addLayout( textAndButton, LAST_COLUMN );
315 widget->setLayout( layout );
319 l->addWidget( label, line, 0 );
320 l->setColumnMinimumWidth( 1, 10 );
321 l->addLayout( textAndButton, line, LAST_COLUMN );
326 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
327 module_config_t *_p_item,
328 QLabel *_label, QLineEdit *_text,
329 QPushButton *_button ):
330 VStringConfigControl( _p_this, _p_item )
336 BUTTONACT( browse, updateField() );
341 void FileConfigControl::updateField()
343 QString file = QFileDialog::getOpenFileName( NULL,
344 qtr( "Select File" ), QVLCUserDir( VLC_HOME_DIR ) );
345 if( file.isNull() ) return;
346 text->setText( toNativeSeparators( file ) );
349 void FileConfigControl::finish()
351 text->setText( qfu(p_item->value.psz) );
352 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
355 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
356 label->setBuddy( text );
360 /********* String / Directory **********/
361 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
362 module_config_t *_p_item, QWidget *_p_widget,
363 QGridLayout *_p_layout, int& _int ) :
364 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
367 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
368 module_config_t *_p_item, QLabel *_p_label,
369 QLineEdit *_p_line, QPushButton *_p_button ):
370 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
373 void DirectoryConfigControl::updateField()
375 QString dir = QFileDialog::getExistingDirectory( NULL,
377 text->text().isEmpty() ?
378 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
379 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
381 if( dir.isNull() ) return;
382 text->setText( toNativeSepNoSlash( dir ) );
385 /********* String / Font **********/
386 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
387 module_config_t *_p_item, QWidget *_parent,
388 QGridLayout *_p_layout, int& line) :
389 VStringConfigControl( _p_this, _p_item, _parent )
391 label = new QLabel( qtr(p_item->psz_text) );
392 font = new QFontComboBox( _parent );
393 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
396 QHBoxLayout *layout = new QHBoxLayout();
397 layout->addWidget( label, 0 );
398 layout->addWidget( font, 1 );
399 widget->setLayout( layout );
403 _p_layout->addWidget( label, line, 0 );
404 _p_layout->addWidget( font, line, 1, 1, -1 );
408 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
409 module_config_t *_p_item, QLabel *_p_label,
410 QFontComboBox *_p_font):
411 VStringConfigControl( _p_this, _p_item)
415 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
418 /********* String / choice list **********/
419 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
420 module_config_t *_p_item, QWidget *_parent, bool bycat,
421 QGridLayout *l, int &line) :
422 VStringConfigControl( _p_this, _p_item, _parent )
424 label = new QLabel( qtr(p_item->psz_text) );
425 combo = new QComboBox();
426 combo->setMinimumWidth( MINWIDTH_BOX );
427 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
429 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
431 finish( p_module_config, bycat );
434 l = new QGridLayout();
435 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
436 widget->setLayout( l );
440 l->addWidget( label, line, 0 );
441 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
444 if( p_item->i_action )
446 QSignalMapper *signalMapper = new QSignalMapper(this);
448 /* Some stringLists like Capture listings have action associated */
449 for( int i = 0; i < p_item->i_action; i++ )
451 QPushButton *button =
452 new QPushButton( qtr( p_item->ppsz_action_text[i] ));
453 CONNECT( button, clicked(), signalMapper, map() );
454 signalMapper->setMapping( button, i );
455 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
458 CONNECT( signalMapper, mapped( int ),
459 this, actionRequested( int ) );
463 void StringListConfigControl::actionRequested( int i_action )
465 /* Supplementary check for boundaries */
466 if( i_action < 0 || i_action >= p_item->i_action ) return;
468 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
469 if(!p_module_config) return;
472 val.psz_string = const_cast<char *>
473 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
475 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
477 if( p_module_config->b_dirty )
480 finish( p_module_config, true );
481 p_module_config->b_dirty = false;
484 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
485 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
486 bool bycat ) : VStringConfigControl( _p_this, _p_item )
491 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
493 finish( p_module_config, bycat );
496 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
498 combo->setEditable( false );
500 if(!p_module_config) return;
502 if( p_module_config->pf_update_list )
505 val.psz_string = strdup(p_module_config->value.psz);
507 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
509 // assume in any case that dirty was set to true
510 // because lazy programmes will use the same callback for
511 // this, like the one behind the refresh push button?
512 p_module_config->b_dirty = false;
514 free( val.psz_string );
517 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
519 if( !p_module_config->ppsz_list[i_index] )
521 combo->addItem( qfu((p_module_config->ppsz_list_text &&
522 p_module_config->ppsz_list_text[i_index])?
523 p_module_config->ppsz_list_text[i_index] :
524 p_module_config->ppsz_list[i_index] ),
525 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
526 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
527 p_module_config->ppsz_list[i_index] ) )
528 combo->setCurrentIndex( combo->count() - 1 );
530 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
533 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
534 label->setBuddy( combo );
538 QString StringListConfigControl::getValue()
540 return combo->itemData( combo->currentIndex() ).toString();
543 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
546 module_config_t *p_config =
547 config_FindConfig( VLC_OBJECT(p_intf), configname );
550 if(p_config->pf_update_list)
553 val.i_int = p_config->value.i;
554 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
555 // assume in any case that dirty was set to true
556 // because lazy programmes will use the same callback for
557 // this, like the one behind the refresh push button?
558 p_config->b_dirty = false;
561 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
563 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
564 QVariant( p_config->pi_list[i_index] ) );
565 if( p_config->value.i == p_config->pi_list[i_index] )
567 combo->setCurrentIndex( i_index );
570 combo->setToolTip( qfu( p_config->psz_longtext ) );
574 /********* Module **********/
575 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
576 module_config_t *_p_item, QWidget *_parent, bool bycat,
577 QGridLayout *l, int &line) :
578 VStringConfigControl( _p_this, _p_item, _parent )
580 label = new QLabel( qtr(p_item->psz_text) );
581 combo = new QComboBox();
582 combo->setMinimumWidth( MINWIDTH_BOX );
586 QHBoxLayout *layout = new QHBoxLayout();
587 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
588 widget->setLayout( layout );
592 l->addWidget( label, line, 0 );
593 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
597 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
598 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
599 bool bycat ) : VStringConfigControl( _p_this, _p_item )
606 void ModuleConfigControl::finish( bool bycat )
610 combo->setEditable( false );
612 /* build a list of available modules */
613 module_t **p_list = module_list_get( NULL );
614 combo->addItem( qtr("Default") );
615 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
619 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
622 module_config_t *p_config;
624 p_config = module_config_get (p_parser, &confsize);
625 for (size_t i = 0; i < confsize; i++)
627 /* Hack: required subcategory is stored in i_min */
628 const module_config_t *p_cfg = p_config + i;
629 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
630 p_cfg->value.i == p_item->min.i )
631 combo->addItem( qtr( module_GetLongName( p_parser )),
632 QVariant( module_get_object( p_parser ) ) );
633 if( p_item->value.psz && !strcmp( p_item->value.psz,
634 module_get_object( p_parser ) ) )
635 combo->setCurrentIndex( combo->count() - 1 );
637 module_config_free (p_config);
639 else if( module_provides( p_parser, p_item->psz_type ) )
641 combo->addItem( qtr(module_GetLongName( p_parser ) ),
642 QVariant( module_get_object( p_parser ) ) );
643 if( p_item->value.psz && !strcmp( p_item->value.psz,
644 module_get_object( p_parser ) ) )
645 combo->setCurrentIndex( combo->count() - 1 );
648 module_list_free( p_list );
649 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
652 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
653 label->setBuddy( combo );
657 QString ModuleConfigControl::getValue()
659 return combo->itemData( combo->currentIndex() ).toString();
662 /********* Module list **********/
663 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
664 module_config_t *_p_item, QWidget *_parent, bool bycat,
665 QGridLayout *l, int &line) :
666 VStringConfigControl( _p_this, _p_item, _parent )
670 if( !p_item->psz_text ) return;
672 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
673 text = new QLineEdit;
674 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
679 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
680 it != modules.end(); it++ )
682 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
684 layoutGroupBox->addWidget( text, boxline, 0 );
688 QVBoxLayout *layout = new QVBoxLayout();
689 layout->addWidget( groupBox, line, 0 );
690 widget->setLayout( layout );
694 l->addWidget( groupBox, line, 0, 1, -1 );
697 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
700 ModuleListConfigControl::~ModuleListConfigControl()
702 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
703 it != modules.end(); it++ )
710 #define CHECKBOX_LISTS \
712 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
713 checkBoxListItem *cbl = new checkBoxListItem; \
715 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
716 cb->setToolTip( formatTooltip( qtr( module_get_help( p_parser ))));\
717 cbl->checkBox = cb; \
719 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
720 modules.push_back( cbl ); \
722 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
723 cbl->checkBox->setChecked( true ); \
727 void ModuleListConfigControl::finish( bool bycat )
731 /* build a list of available modules */
732 module_t **p_list = module_list_get( NULL );
733 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
737 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
740 module_config_t *p_config = module_config_get (p_parser, &confsize);
742 for (size_t i = 0; i < confsize; i++)
744 module_config_t *p_cfg = p_config + i;
745 /* Hack: required subcategory is stored in i_min */
746 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
747 p_cfg->value.i == p_item->min.i )
752 module_config_free (p_config);
754 else if( module_provides( p_parser, p_item->psz_type ) )
759 module_list_free( p_list );
760 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
762 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
764 #undef CHECKBOX_LISTS
766 QString ModuleListConfigControl::getValue()
772 void ModuleListConfigControl::hide()
774 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
775 it != modules.end(); it++ )
777 (*it)->checkBox->hide();
782 void ModuleListConfigControl::show()
784 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
785 it != modules.end(); it++ )
787 (*it)->checkBox->show();
793 void ModuleListConfigControl::onUpdate()
798 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
799 it != modules.end(); it++ )
801 if( (*it)->checkBox->isChecked() )
805 text->setText( text->text() + (*it)->psz_module );
810 text->setText( text->text() + ":" + (*it)->psz_module );
816 /**************************************************************************
817 * Integer-based controls
818 *************************************************************************/
820 /*********** Integer **************/
821 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
822 module_config_t *_p_item,
823 QWidget *_parent, QGridLayout *l,
825 VIntConfigControl( _p_this, _p_item, _parent )
827 label = new QLabel( qtr(p_item->psz_text) );
828 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
829 spin->setAlignment( Qt::AlignRight );
830 spin->setMaximumWidth( MINWIDTH_BOX );
835 QHBoxLayout *layout = new QHBoxLayout();
836 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
837 widget->setLayout( layout );
841 l->addWidget( label, line, 0 );
842 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
845 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
846 module_config_t *_p_item,
847 QLabel *_label, QSpinBox *_spin ) :
848 VIntConfigControl( _p_this, _p_item )
855 void IntegerConfigControl::finish()
857 spin->setMaximum( 2000000000 );
858 spin->setMinimum( -2000000000 );
859 spin->setValue( p_item->value.i );
860 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
863 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
864 label->setBuddy( spin );
868 int IntegerConfigControl::getValue()
870 return spin->value();
873 /********* Integer range **********/
874 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
875 module_config_t *_p_item,
876 QWidget *_parent, QGridLayout *l,
878 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
883 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
884 module_config_t *_p_item,
885 QLabel *_label, QSpinBox *_spin ) :
886 IntegerConfigControl( _p_this, _p_item, _label, _spin )
891 void IntegerRangeConfigControl::finish()
893 spin->setMaximum( p_item->max.i );
894 spin->setMinimum( p_item->min.i );
897 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
898 vlc_object_t *_p_this,
899 module_config_t *_p_item,
900 QLabel *_label, QSlider *_slider ):
901 VIntConfigControl( _p_this, _p_item )
905 slider->setMaximum( p_item->max.i );
906 slider->setMinimum( p_item->min.i );
907 slider->setValue( p_item->value.i );
908 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
911 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
912 label->setBuddy( slider );
916 int IntegerRangeSliderConfigControl::getValue()
918 return slider->value();
922 /********* Integer / choice list **********/
923 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
924 module_config_t *_p_item, QWidget *_parent, bool bycat,
925 QGridLayout *l, int &line) :
926 VIntConfigControl( _p_this, _p_item, _parent )
928 label = new QLabel( qtr(p_item->psz_text) );
929 combo = new QComboBox();
930 combo->setMinimumWidth( MINWIDTH_BOX );
932 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
934 finish( p_module_config, bycat );
937 QHBoxLayout *layout = new QHBoxLayout();
938 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
939 widget->setLayout( layout );
943 l->addWidget( label, line, 0 );
944 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
947 if( p_item->i_action )
949 QSignalMapper *signalMapper = new QSignalMapper(this);
951 /* Some stringLists like Capture listings have action associated */
952 for( int i = 0; i < p_item->i_action; i++ )
954 QPushButton *button =
955 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
956 CONNECT( button, clicked(), signalMapper, map() );
957 signalMapper->setMapping( button, i );
958 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
961 CONNECT( signalMapper, mapped( int ),
962 this, actionRequested( int ) );
966 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
967 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
968 bool bycat ) : VIntConfigControl( _p_this, _p_item )
973 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
975 finish( p_module_config, bycat );
978 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
980 combo->setEditable( false );
982 if(!p_module_config) return;
984 if( p_module_config->pf_update_list )
987 val.i_int = p_module_config->value.i;
989 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
991 // assume in any case that dirty was set to true
992 // because lazy programmes will use the same callback for
993 // this, like the one behind the refresh push button?
994 p_module_config->b_dirty = false;
997 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
999 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
1000 QVariant( p_module_config->pi_list[i_index] ) );
1001 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
1002 combo->setCurrentIndex( combo->count() - 1 );
1004 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
1007 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
1008 label->setBuddy( combo );
1012 void IntegerListConfigControl::actionRequested( int i_action )
1014 /* Supplementary check for boundaries */
1015 if( i_action < 0 || i_action >= p_item->i_action ) return;
1017 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1018 if(!p_module_config) return;
1022 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
1024 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
1026 if( p_module_config->b_dirty )
1029 finish( p_module_config, true );
1030 p_module_config->b_dirty = false;
1034 int IntegerListConfigControl::getValue()
1036 return combo->itemData( combo->currentIndex() ).toInt();
1039 /*********** Boolean **************/
1040 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1041 module_config_t *_p_item,
1042 QWidget *_parent, QGridLayout *l,
1044 VIntConfigControl( _p_this, _p_item, _parent )
1046 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1051 QHBoxLayout *layout = new QHBoxLayout();
1052 layout->addWidget( checkbox, 0 );
1053 widget->setLayout( layout );
1057 l->addWidget( checkbox, line, 0 );
1061 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1062 module_config_t *_p_item,
1064 QAbstractButton *_checkbox,
1066 VIntConfigControl( _p_this, _p_item )
1068 checkbox = _checkbox;
1069 VLC_UNUSED( _label );
1073 void BoolConfigControl::finish()
1075 checkbox->setChecked( p_item->value.i == true );
1076 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1079 int BoolConfigControl::getValue()
1081 return checkbox->isChecked();
1084 /**************************************************************************
1085 * Float-based controls
1086 *************************************************************************/
1088 /*********** Float **************/
1089 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1090 module_config_t *_p_item,
1091 QWidget *_parent, QGridLayout *l,
1093 VFloatConfigControl( _p_this, _p_item, _parent )
1095 label = new QLabel( qtr(p_item->psz_text) );
1096 spin = new QDoubleSpinBox;
1097 spin->setMinimumWidth( MINWIDTH_BOX );
1098 spin->setMaximumWidth( MINWIDTH_BOX );
1099 spin->setAlignment( Qt::AlignRight );
1104 QHBoxLayout *layout = new QHBoxLayout();
1105 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1106 widget->setLayout( layout );
1110 l->addWidget( label, line, 0 );
1111 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1115 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1116 module_config_t *_p_item,
1118 QDoubleSpinBox *_spin ) :
1119 VFloatConfigControl( _p_this, _p_item )
1126 void FloatConfigControl::finish()
1128 spin->setMaximum( 2000000000. );
1129 spin->setMinimum( -2000000000. );
1130 spin->setSingleStep( 0.1 );
1131 spin->setValue( (double)p_item->value.f );
1132 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1135 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1136 label->setBuddy( spin );
1140 float FloatConfigControl::getValue()
1142 return (float)spin->value();
1145 /*********** Float with range **************/
1146 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1147 module_config_t *_p_item,
1148 QWidget *_parent, QGridLayout *l,
1150 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1155 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1156 module_config_t *_p_item,
1158 QDoubleSpinBox *_spin ) :
1159 FloatConfigControl( _p_this, _p_item, _label, _spin )
1164 void FloatRangeConfigControl::finish()
1166 spin->setMaximum( (double)p_item->max.f );
1167 spin->setMinimum( (double)p_item->min.f );
1171 /**********************************************************************
1172 * Key selector widget
1173 **********************************************************************/
1174 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1175 module_config_t *_p_item,
1176 QWidget *_parent, QGridLayout *l,
1178 ConfigControl( _p_this, _p_item, _parent )
1181 QWidget *keyContainer = new QWidget;
1182 QGridLayout *gLayout = new QGridLayout( keyContainer );
1185 qtr( "Select an action to change the associated hotkey") );
1187 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1188 actionSearch = new SearchLineEdit( keyContainer );
1190 table = new QTreeWidget;
1191 table->setColumnCount(3);
1192 table->headerItem()->setText( 0, qtr( "Action" ) );
1193 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1194 table->headerItem()->setText( 2, qtr( "Global" ) );
1195 table->setAlternatingRowColors( true );
1196 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1198 shortcutValue = new KeyShortcutEdit;
1199 shortcutValue->setReadOnly(true);
1201 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1202 QPushButton *setButton = new QPushButton( qtr( "Apply" ) );
1203 setButton->setDefault( true );
1206 gLayout->addWidget( label, 0, 0, 1, 4 );
1207 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1208 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1209 gLayout->addWidget( table, 2, 0, 1, 4 );
1210 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1211 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1212 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1214 l->addWidget( keyContainer, line, 0, 1, -1 );
1216 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1217 CONNECT( clearButton, clicked(), this, setTheKey() );
1218 BUTTONACT( setButton, setTheKey() );
1219 CONNECT( actionSearch, textChanged( const QString& ),
1220 this, filter( const QString& ) );
1223 void KeySelectorControl::finish()
1226 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1228 /* Fill the table */
1230 /* Get the main Module */
1231 module_t *p_main = module_get_main();
1234 /* Access to the module_config_t */
1236 module_config_t *p_config;
1238 p_config = module_config_get (p_main, &confsize);
1240 for (size_t i = 0; i < confsize; i++)
1242 module_config_t *p_item = p_config + i;
1244 /* If we are a key option not empty */
1245 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1246 && strstr( p_item->psz_name , "key-" )
1247 && !strstr( p_item->psz_name , "global-key" )
1248 && !EMPTY_STR( p_item->psz_text ) )
1252 - QString text in column 0
1253 - QString name in data of column 0
1254 - KeyValue in String in column 1
1255 - KeyValue in int in column 1
1257 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1258 treeItem->setText( 0, qtr( p_item->psz_text ) );
1259 treeItem->setData( 0, Qt::UserRole,
1260 QVariant( qfu( p_item->psz_name ) ) );
1261 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1262 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1263 table->addTopLevelItem( treeItem );
1267 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1268 && strstr( p_item->psz_name , "global-key" )
1269 && !EMPTY_STR( p_item->psz_text ) )
1271 QList<QTreeWidgetItem *> list =
1272 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1273 if( list.count() >= 1 )
1275 list[0]->setText( 2, VLCKeyToString( p_item->value.i ) );
1276 list[0]->setData( 2, Qt::UserRole,
1277 QVariant( p_item->value.i ) );
1279 if( list.count() >= 2 )
1280 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1283 module_config_free (p_config);
1284 module_release (p_main);
1286 table->resizeColumnToContents( 0 );
1288 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1289 this, selectKey( QTreeWidgetItem *, int ) );
1290 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1291 this, select( QTreeWidgetItem *, int) );
1292 CONNECT( table, itemSelectionChanged(),
1293 this, select1Key() );
1295 CONNECT( shortcutValue, pressed(), this, selectKey() );
1298 void KeySelectorControl::filter( const QString &qs_search )
1300 QList<QTreeWidgetItem *> resultList =
1301 table->findItems( qs_search, Qt::MatchContains, 0 );
1302 for( int i = 0; i < table->topLevelItemCount(); i++ )
1304 table->topLevelItem( i )->setHidden(
1305 !resultList.contains( table->topLevelItem( i ) ) );
1309 void KeySelectorControl::select( QTreeWidgetItem *keyItem, int column )
1311 shortcutValue->setGlobal( column == 2 );
1314 /* Show the key selected from the table in the keySelector */
1315 void KeySelectorControl::select1Key()
1317 QTreeWidgetItem *keyItem = table->currentItem();
1318 shortcutValue->setText( keyItem->text( 1 ) );
1319 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1320 shortcutValue->setGlobal( false );
1323 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1325 /* This happens when triggered by ClickEater */
1326 if( keyItem == NULL ) keyItem = table->currentItem();
1328 /* This can happen when nothing is selected on the treeView
1329 and the shortcutValue is clicked */
1330 if( !keyItem ) return;
1332 /* If clicked on the first column, assuming user wants the normal hotkey */
1333 if( column == 0 ) column = 1;
1335 bool b_global = ( column == 2 );
1337 /* Launch a small dialog to ask for a new key */
1338 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1341 if( d->result() == QDialog::Accepted )
1343 int newValue = d->keyValue;
1344 shortcutValue->setText( VLCKeyToString( newValue ) );
1345 shortcutValue->setValue( newValue );
1346 shortcutValue->setGlobal( b_global );
1350 QTreeWidgetItem *it;
1351 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1353 it = table->topLevelItem(i);
1354 if( ( keyItem != it ) &&
1355 ( it->data( b_global ? 2: 1, Qt::UserRole ).toInt() == newValue ) )
1357 it->setData( b_global ? 2 : 1, Qt::UserRole, QVariant( -1 ) );
1358 it->setText( b_global ? 2 : 1, qtr( "Unset" ) );
1361 /* We already made an OK once. */
1368 void KeySelectorControl::setTheKey()
1370 if( !table->currentItem() ) return;
1371 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1372 shortcutValue->text() );
1373 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1374 Qt::UserRole, shortcutValue->getValue() );
1377 void KeySelectorControl::doApply()
1379 QTreeWidgetItem *it;
1380 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1382 it = table->topLevelItem(i);
1383 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1384 config_PutInt( p_this,
1385 qtu( it->data( 0, Qt::UserRole ).toString() ),
1386 it->data( 1, Qt::UserRole ).toInt() );
1387 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1388 config_PutInt( p_this,
1389 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1390 it->data( 2, Qt::UserRole ).toInt() );
1396 * Class KeyInputDialog
1398 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1399 const QString& keyToChange,
1402 QDialog( _parent ), keyValue(0), b_global( _b_global )
1408 setWindowTitle( b_global ? qtr( "Global" ): ""
1409 + qtr( "Hotkey for " ) + keyToChange );
1410 setWindowRole( "vlc-key-input" );
1412 vLayout = new QVBoxLayout( this );
1413 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1414 vLayout->addWidget( selected , Qt::AlignCenter );
1416 warning = new QLabel;
1418 vLayout->insertWidget( 1, warning );
1420 buttonBox = new QDialogButtonBox;
1421 QPushButton *ok = new QPushButton( qtr("OK") );
1422 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1423 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1424 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1425 ok->setDefault( true );
1427 vLayout->addWidget( buttonBox );
1430 CONNECT( buttonBox, accepted(), this, accept() );
1431 CONNECT( buttonBox, rejected(), this, reject() );
1434 void KeyInputDialog::checkForConflicts( int i_vlckey )
1436 QList<QTreeWidgetItem *> conflictList =
1437 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1440 if( conflictList.size() &&
1441 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1442 /* Avoid 0 or -1 that are the "Unset" states */
1444 warning->setText( qtr("Warning: the key is already assigned to \"") +
1445 conflictList[0]->text( 0 ) + "\"" );
1454 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1456 if( e->key() == Qt::Key_Tab ||
1457 e->key() == Qt::Key_Shift ||
1458 e->key() == Qt::Key_Control ||
1459 e->key() == Qt::Key_Meta ||
1460 e->key() == Qt::Key_Alt ||
1461 e->key() == Qt::Key_AltGr )
1463 int i_vlck = qtEventToVLCKey( e );
1464 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1465 checkForConflicts( i_vlck );
1469 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1471 int i_vlck = qtWheelEventToVLCKey( e );
1472 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1473 checkForConflicts( i_vlck );
1477 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)