1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2011 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 * - Validator for modulelist
34 #include "components/preferences_widgets.hpp"
35 #include "util/customwidgets.hpp"
36 #include "util/searchlineedit.hpp"
37 #include "util/qt_dirs.hpp"
39 #include <vlc_intf_strings.h>
40 #include <vlc_modules.h>
41 #include <vlc_plugin.h>
45 #include <QGridLayout>
47 #include <QFileDialog>
49 #include <QTreeWidgetItem>
50 #include <QSignalMapper>
51 #include <QDialogButtonBox>
53 #include <QColorDialog>
55 #define MINWIDTH_BOX 90
56 #define LAST_COLUMN 10
58 QString formatTooltip(const QString & tooltip)
60 QString text = tooltip;
61 text.replace("\n", "<br/>");
64 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
65 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
66 "<body style=\" font-family:'Sans Serif'; "
67 "font-style:normal; text-decoration:none;\">"
68 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
69 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
70 text + "</p></body></html>";
74 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
75 module_config_t *p_item,
77 QGridLayout *l, int line )
79 ConfigControl *p_control = NULL;
81 switch( p_item->i_type )
83 case CONFIG_ITEM_MODULE:
84 p_control = new StringListConfigControl( p_this, p_item, parent );
86 case CONFIG_ITEM_MODULE_CAT:
87 p_control = new ModuleConfigControl( p_this, p_item, parent );
89 case CONFIG_ITEM_MODULE_LIST:
90 p_control = new ModuleListConfigControl( p_this, p_item, parent, false );
92 case CONFIG_ITEM_MODULE_LIST_CAT:
93 p_control = new ModuleListConfigControl( p_this, p_item, parent, true );
95 case CONFIG_ITEM_STRING:
96 if( p_item->list.psz_cb )
97 p_control = new StringListConfigControl( p_this, p_item, parent );
99 p_control = new StringConfigControl( p_this, p_item, parent, false );
101 case CONFIG_ITEM_PASSWORD:
102 p_control = new StringConfigControl( p_this, p_item, parent, true );
104 case CONFIG_ITEM_RGB:
105 p_control = new ColorConfigControl( p_this, p_item, parent );
107 case CONFIG_ITEM_INTEGER:
108 if( p_item->list.i_cb )
109 p_control = new IntegerListConfigControl( p_this, p_item, parent, false );
110 else if( p_item->min.i || p_item->max.i )
111 p_control = new IntegerRangeConfigControl( p_this, p_item, parent );
113 p_control = new IntegerConfigControl( p_this, p_item, parent );
115 case CONFIG_ITEM_LOADFILE:
116 case CONFIG_ITEM_SAVEFILE:
117 p_control = new FileConfigControl( p_this, p_item, parent );
119 case CONFIG_ITEM_DIRECTORY:
120 p_control = new DirectoryConfigControl( p_this, p_item, parent );
122 case CONFIG_ITEM_FONT:
123 p_control = new FontConfigControl( p_this, p_item, parent );
125 case CONFIG_ITEM_KEY:
126 p_control = new KeySelectorControl( p_this, p_item, parent );
128 case CONFIG_ITEM_BOOL:
129 p_control = new BoolConfigControl( p_this, p_item, parent );
131 case CONFIG_ITEM_FLOAT:
132 if( p_item->min.f || p_item->max.f )
133 p_control = new FloatRangeConfigControl( p_this, p_item, parent );
135 p_control = new FloatConfigControl( p_this, p_item, parent );
140 if ( p_control ) p_control->insertIntoExistingGrid( l, line );
144 /* Inserts controls into layouts
145 This is sub-optimal in the OO way, as controls's code still
146 depends on Layout classes. We should use layout inserters [friend]
147 classes, but it's unlikely we had to deal with a different layout.*/
148 void ConfigControl::insertInto( QBoxLayout *layout )
150 QGridLayout *sublayout = new QGridLayout();
151 fillGrid( sublayout, 0 );
152 layout->addLayout( sublayout );
155 void ConfigControl::insertIntoExistingGrid( QGridLayout *l, int line )
160 /*******************************************************
162 *******************************************************/
163 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
165 setGeometry( 0, 0, 128, 100 );
166 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
169 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
171 setPreview( ( b_minimal ) ? MINIMAL : COMPLETE );
174 void InterfacePreviewWidget::setPreview( enum_style e_style )
176 QString pixmapLocationString(":/prefsmenu/");
182 pixmapLocationString += "sample_complete";
185 pixmapLocationString += "sample_minimal";
188 pixmapLocationString += "sample_skins";
192 setPixmap( QPixmap( pixmapLocationString ) );
197 /**************************************************************************
198 * String-based controls
199 *************************************************************************/
202 VStringConfigControl::doApply()
204 config_PutPsz( p_this, getName(), qtu( getValue() ) );
207 /*********** String **************/
208 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
209 module_config_t *_p_item,
212 VStringConfigControl( _p_this, _p_item )
214 label = new QLabel( qtr(p_item->psz_text), _parent );
215 text = new QLineEdit( qfu(p_item->value.psz), _parent );
216 if( pwd ) text->setEchoMode( QLineEdit::Password );
220 void StringConfigControl::fillGrid( QGridLayout *l, int line )
222 l->addWidget( label, line, 0 );
223 l->setColumnMinimumWidth( 1, 10 );
224 l->addWidget( text, line, LAST_COLUMN, Qt::AlignRight );
227 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
228 module_config_t *_p_item,
229 QLabel *_label, QLineEdit *_text, bool pwd ):
230 VStringConfigControl( _p_this, _p_item )
233 if( pwd ) text->setEchoMode( QLineEdit::Password );
238 int VStringConfigControl::getType() const { return CONFIG_ITEM_STRING; }
240 void StringConfigControl::finish()
242 text->setText( qfu(p_item->value.psz) );
243 if( p_item->psz_longtext )
245 QString tipText = qtr(p_item->psz_longtext);
246 text->setToolTip( formatTooltip(tipText) );
248 label->setToolTip( formatTooltip(tipText) );
251 label->setBuddy( text );
254 /*********** File **************/
255 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
256 module_config_t *_p_item, QWidget *p ) :
257 VStringConfigControl( _p_this, _p_item )
259 label = new QLabel( qtr(p_item->psz_text), p );
260 text = new QLineEdit( qfu(p_item->value.psz), p );
261 browse = new QPushButton( qtr( "Browse..." ), p );
263 BUTTONACT( browse, updateField() );
268 void FileConfigControl::fillGrid( QGridLayout *l, int line )
270 l->addWidget( label, line, 0 );
271 l->setColumnMinimumWidth( 1, 10 );
272 QHBoxLayout *textAndButton = new QHBoxLayout();
273 textAndButton->setMargin( 0 );
274 textAndButton->addWidget( text, 2 );
275 textAndButton->addWidget( browse, 0 );
276 l->addLayout( textAndButton, line, LAST_COLUMN, 0 );
279 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
280 module_config_t *_p_item,
281 QLabel *_label, QLineEdit *_text,
282 QPushButton *_button ):
283 VStringConfigControl( _p_this, _p_item )
289 BUTTONACT( browse, updateField() );
294 void FileConfigControl::updateField()
298 if (p_item->i_type == CONFIG_ITEM_SAVEFILE)
299 file = QFileDialog::getSaveFileName( NULL, qtr( "Save File" ),
300 QVLCUserDir( VLC_HOME_DIR ) );
302 file = QFileDialog::getOpenFileName( NULL, qtr( "Select File" ),
303 QVLCUserDir( VLC_HOME_DIR ) );
305 if( file.isNull() ) return;
306 text->setText( toNativeSeparators( file ) );
309 void FileConfigControl::finish()
311 text->setText( qfu(p_item->value.psz) );
312 if( p_item->psz_longtext )
314 QString tipText = qtr(p_item->psz_longtext);
315 text->setToolTip( formatTooltip(tipText) );
317 label->setToolTip( formatTooltip(tipText) );
320 label->setBuddy( text );
323 /********* String / Directory **********/
324 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
325 module_config_t *_p_item, QWidget *p ) :
326 FileConfigControl( _p_this, _p_item, p )
329 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
330 module_config_t *_p_item, QLabel *_p_label,
331 QLineEdit *_p_line, QPushButton *_p_button ):
332 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
335 void DirectoryConfigControl::updateField()
337 QString dir = QFileDialog::getExistingDirectory( NULL,
339 text->text().isEmpty() ?
340 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
341 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
343 if( dir.isNull() ) return;
344 text->setText( toNativeSepNoSlash( dir ) );
347 /********* String / Font **********/
348 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
349 module_config_t *_p_item, QWidget *p ) :
350 VStringConfigControl( _p_this, _p_item )
352 label = new QLabel( qtr(p_item->psz_text), p );
353 font = new QFontComboBox( p );
354 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
356 if( p_item->psz_longtext )
358 label->setToolTip( formatTooltip( qtr(p_item->psz_longtext) ) );
362 void FontConfigControl::fillGrid( QGridLayout *l, int line )
364 l->addWidget( label, line, 0 );
365 l->addWidget( font, line, 1, 1, -1 );
368 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
369 module_config_t *_p_item, QLabel *_p_label,
370 QFontComboBox *_p_font):
371 VStringConfigControl( _p_this, _p_item)
375 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
377 if( p_item->psz_longtext )
379 label->setToolTip( formatTooltip( qtr(p_item->psz_longtext) ) );
383 /********* String / choice list **********/
384 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
385 module_config_t *_p_item, QWidget *p ) :
386 VStringConfigControl( _p_this, _p_item )
388 label = new QLabel( qtr(p_item->psz_text), p );
389 combo = new QComboBox( p );
390 combo->setMinimumWidth( MINWIDTH_BOX );
391 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
393 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
395 finish( p_module_config );
398 void StringListConfigControl::fillGrid( QGridLayout *l, int line )
400 l->addWidget( label, line, 0 );
401 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
403 foreach( QPushButton *button, buttons )
404 l->addWidget( button, line, LAST_COLUMN + i++,
408 void StringListConfigControl::comboIndexChanged( int i_index )
414 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
415 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
416 bool ) : VStringConfigControl( _p_this, _p_item )
421 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
423 finish( p_module_config );
426 void StringListConfigControl::finish(module_config_t *p_module_config )
428 combo->setEditable( false );
429 CONNECT( combo, currentIndexChanged ( int ), this, comboIndexChanged( int ) );
431 if(!p_module_config) return;
433 char **values, **texts;
434 ssize_t count = config_GetPszChoices( p_this, p_item->psz_name,
436 for( ssize_t i = 0; i < count && texts; i++ )
438 if( texts[i] == NULL || values[i] == NULL )
441 combo->addItem( qfu(texts[i]), QVariant( qfu(values[i])) );
442 if( !strcmp( p_item->value.psz ? p_item->value.psz : "", values[i] ) )
443 combo->setCurrentIndex( combo->count() - 1 );
450 if( p_module_config->psz_longtext )
452 QString tipText = qtr(p_module_config->psz_longtext);
453 combo->setToolTip( formatTooltip(tipText) );
455 label->setToolTip( formatTooltip(tipText) );
458 label->setBuddy( combo );
461 QString StringListConfigControl::getValue() const
463 return combo->itemData( combo->currentIndex() ).toString();
466 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
469 module_config_t *p_config =
470 config_FindConfig( VLC_OBJECT(p_intf), configname );
471 if( p_config == NULL )
474 if( (p_config->i_type & 0xF0) == CONFIG_ITEM_STRING )
476 char **values, **texts;
477 ssize_t count = config_GetPszChoices(VLC_OBJECT(p_intf),
478 configname, &values, &texts);
479 for( ssize_t i = 0; i < count; i++ )
481 combo->addItem( qtr(texts[i]), QVariant(qfu(values[i])) );
482 if( !strcmp(p_config->value.psz, values[i]) )
483 combo->setCurrentIndex( i );
494 ssize_t count = config_GetIntChoices(VLC_OBJECT(p_intf), configname,
496 for( ssize_t i = 0; i < count; i++ )
498 combo->addItem( qtr(texts[i]), QVariant(qlonglong(values[i])) );
499 if( p_config->value.i == values[i] )
500 combo->setCurrentIndex( i );
506 if( p_config->psz_longtext != NULL )
507 combo->setToolTip( qfu( p_config->psz_longtext ) );
510 /********* Module **********/
511 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
512 module_config_t *_p_item, QWidget *p ) :
513 VStringConfigControl( _p_this, _p_item )
515 label = new QLabel( qtr(p_item->psz_text), p );
516 combo = new QComboBox( p );
517 combo->setMinimumWidth( MINWIDTH_BOX );
521 void ModuleConfigControl::fillGrid( QGridLayout *l, int line )
523 l->addWidget( label, line, 0 );
524 l->addWidget( combo, line, LAST_COLUMN, 0 );
527 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
528 module_config_t *_p_item, QLabel *_label, QComboBox *_combo )
529 : VStringConfigControl( _p_this, _p_item )
536 void ModuleConfigControl::finish( )
538 combo->setEditable( false );
540 /* build a list of available modules */
542 module_t **p_list = module_list_get( &count );
543 combo->addItem( qtr("Default") );
544 for( size_t i = 0; i < count; i++ )
546 module_t *p_parser = p_list[i];
548 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
551 module_config_t *p_config;
553 p_config = module_config_get (p_parser, &confsize);
554 for (size_t i = 0; i < confsize; i++)
556 /* Hack: required subcategory is stored in i_min */
557 const module_config_t *p_cfg = p_config + i;
558 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
559 p_cfg->value.i == p_item->min.i )
560 combo->addItem( qtr( module_GetLongName( p_parser )),
561 QVariant( module_get_object( p_parser ) ) );
562 if( p_item->value.psz && !strcmp( p_item->value.psz,
563 module_get_object( p_parser ) ) )
564 combo->setCurrentIndex( combo->count() - 1 );
566 module_config_free (p_config);
568 module_list_free( p_list );
570 if( p_item->psz_longtext )
572 QString tipText = qtr(p_item->psz_longtext);
573 combo->setToolTip( formatTooltip(tipText) );
575 label->setToolTip( formatTooltip(tipText) );
578 label->setBuddy( combo );
581 QString ModuleConfigControl::getValue() const
583 return combo->itemData( combo->currentIndex() ).toString();
586 /********* Module list **********/
587 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
588 module_config_t *_p_item, QWidget *p, bool bycat ) :
589 VStringConfigControl( _p_this, _p_item )
594 if( !p_item->psz_text ) return;
596 groupBox = new QGroupBox ( qtr(p_item->psz_text), p );
597 text = new QLineEdit( p );
598 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
603 foreach ( checkBoxListItem *it, modules )
605 layoutGroupBox->addWidget( it->checkBox, boxline / 2, boxline % 2 );
609 layoutGroupBox->addWidget( text, boxline, 0, 1, 2 );
611 if( p_item->psz_longtext )
612 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
615 void ModuleListConfigControl::fillGrid( QGridLayout *l, int line )
617 l->addWidget( groupBox, line, 0, 1, -1 );
620 ModuleListConfigControl::~ModuleListConfigControl()
622 qDeleteAll( modules );
627 void ModuleListConfigControl::checkbox_lists( module_t *p_parser )
629 const char *help = module_get_help( p_parser );
630 checkbox_lists( qtr( module_GetLongName( p_parser ) ),
631 help != NULL ? qtr( help ): "",
632 module_get_object( p_parser ) );
635 void ModuleListConfigControl::checkbox_lists( QString label, QString help, const char* psz_module )
637 QCheckBox *cb = new QCheckBox( label );
638 checkBoxListItem *cbl = new checkBoxListItem;
640 CONNECT( cb, stateChanged( int ), this, onUpdate() );
641 if( !help.isEmpty() )
642 cb->setToolTip( formatTooltip( help ) );
645 cbl->psz_module = strdup( psz_module );
646 modules.append( cbl );
648 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) )
649 cbl->checkBox->setChecked( true );
652 void ModuleListConfigControl::finish( bool bycat )
654 /* build a list of available modules */
656 module_t **p_list = module_list_get( &count );
657 for( size_t i = 0; i < count; i++ )
659 module_t *p_parser = p_list[i];
663 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
666 module_config_t *p_config = module_config_get (p_parser, &confsize);
668 for (size_t i = 0; i < confsize; i++)
670 module_config_t *p_cfg = p_config + i;
671 /* Hack: required subcategory is stored in i_min */
672 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
673 p_cfg->value.i == p_item->min.i )
675 checkbox_lists( p_parser );
678 /* Parental Advisory HACK:
679 * Selecting HTTP, RC and Telnet interfaces is difficult now
680 * since they are just the lua interface module */
681 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
682 !strcmp( module_get_object( p_parser ), "lua" ) &&
683 !strcmp( p_item->psz_name, "extraintf" ) &&
684 p_cfg->value.i == p_item->min.i )
686 checkbox_lists( "Web", "Lua HTTP", "http" );
687 checkbox_lists( "Telnet", "Lua Telnet", "telnet" );
689 checkbox_lists( "Console", "Lua CLI", "cli" );
693 module_config_free (p_config);
695 else if( module_provides( p_parser, p_item->psz_type ) )
697 checkbox_lists(p_parser);
700 module_list_free( p_list );
702 if( p_item->psz_longtext )
704 QString tipText = qtr(p_item->psz_longtext);
706 text->setToolTip( formatTooltip(tipText) );
708 groupBox->setToolTip( formatTooltip(tipText) );
712 QString ModuleListConfigControl::getValue() const
718 void ModuleListConfigControl::changeVisibility( bool b )
720 foreach ( checkBoxListItem *it, modules )
721 it->checkBox->setVisible( b );
722 groupBox->setVisible( b );
725 void ModuleListConfigControl::onUpdate()
730 foreach ( checkBoxListItem *it, modules )
732 if( it->checkBox->isChecked() )
736 text->setText( text->text() + it->psz_module );
741 text->setText( text->text() + ":" + it->psz_module );
747 /**************************************************************************
748 * Integer-based controls
749 *************************************************************************/
752 VIntConfigControl::doApply()
754 config_PutInt( p_this, getName(), getValue() );
757 /*********** Integer **************/
758 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
759 module_config_t *_p_item, QWidget *p ) :
760 VIntConfigControl( _p_this, _p_item )
762 label = new QLabel( qtr(p_item->psz_text), p );
763 spin = new QSpinBox( p ); spin->setMinimumWidth( MINWIDTH_BOX );
764 spin->setAlignment( Qt::AlignRight );
765 spin->setMaximumWidth( MINWIDTH_BOX );
769 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
770 module_config_t *_p_item,
771 QLabel *_label, QSpinBox *_spin ) :
772 VIntConfigControl( _p_this, _p_item )
779 void IntegerConfigControl::fillGrid( QGridLayout *l, int line )
781 l->addWidget( label, line, 0 );
782 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
785 void IntegerConfigControl::finish()
787 spin->setMaximum( 2000000000 );
788 spin->setMinimum( -2000000000 );
789 spin->setValue( p_item->value.i );
791 if( p_item->psz_longtext )
793 QString tipText = qtr(p_item->psz_longtext);
794 spin->setToolTip( formatTooltip(tipText) );
796 label->setToolTip( formatTooltip(tipText) );
799 label->setBuddy( spin );
802 int IntegerConfigControl::getValue() const
804 return spin->value();
807 int VIntConfigControl::getType() const { return CONFIG_ITEM_INTEGER; }
809 /********* Integer range **********/
810 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
811 module_config_t *_p_item, QWidget *p ) :
812 IntegerConfigControl( _p_this, _p_item, p )
817 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
818 module_config_t *_p_item,
819 QLabel *_label, QSpinBox *_spin ) :
820 IntegerConfigControl( _p_this, _p_item, _label, _spin )
825 void IntegerRangeConfigControl::finish()
827 spin->setMaximum( p_item->max.i > INT_MAX ? INT_MAX : p_item->max.i );
828 spin->setMinimum( p_item->min.i < INT_MIN ? INT_MIN : p_item->min.i );
831 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
832 vlc_object_t *_p_this,
833 module_config_t *_p_item,
834 QLabel *_label, QSlider *_slider ):
835 VIntConfigControl( _p_this, _p_item )
839 slider->setMaximum( p_item->max.i > INT_MAX ? INT_MAX : p_item->max.i );
840 slider->setMinimum( p_item->min.i < INT_MIN ? INT_MIN : p_item->min.i );
841 slider->setValue( p_item->value.i );
842 if( p_item->psz_longtext )
844 QString tipText = qtr(p_item->psz_longtext);
845 slider->setToolTip( formatTooltip(tipText) );
847 label->setToolTip( formatTooltip(tipText) );
850 label->setBuddy( slider );
853 int IntegerRangeSliderConfigControl::getValue() const
855 return slider->value();
859 /********* Integer / choice list **********/
860 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
861 module_config_t *_p_item, QWidget *p, bool ) :
862 VIntConfigControl( _p_this, _p_item )
864 label = new QLabel( qtr(p_item->psz_text), p );
865 combo = new QComboBox( p );
866 combo->setMinimumWidth( MINWIDTH_BOX );
868 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
870 finish( p_module_config );
873 void IntegerListConfigControl::fillGrid( QGridLayout *l, int line )
875 l->addWidget( label, line, 0 );
876 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
878 foreach( QPushButton *button, buttons )
879 l->addWidget( button, line, LAST_COLUMN + i++,
883 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
884 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
885 bool ) : VIntConfigControl( _p_this, _p_item )
890 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
892 finish( p_module_config );
895 void IntegerListConfigControl::finish(module_config_t *p_module_config )
897 combo->setEditable( false );
899 if(!p_module_config) return;
903 ssize_t count = config_GetIntChoices( p_this, p_module_config->psz_name,
905 for( ssize_t i = 0; i < count; i++ )
907 combo->addItem( qtr(texts[i]), qlonglong(values[i]) );
908 if( p_module_config->value.i == values[i] )
909 combo->setCurrentIndex( combo->count() - 1 );
914 if( p_item->psz_longtext )
916 QString tipText = qtr(p_item->psz_longtext );
917 combo->setToolTip( formatTooltip(tipText) );
919 label->setToolTip( formatTooltip(tipText) );
922 label->setBuddy( combo );
925 int IntegerListConfigControl::getValue() const
927 return combo->itemData( combo->currentIndex() ).toInt();
930 /*********** Boolean **************/
931 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
932 module_config_t *_p_item, QWidget *p ) :
933 VIntConfigControl( _p_this, _p_item )
935 checkbox = new QCheckBox( qtr(p_item->psz_text), p );
939 void BoolConfigControl::fillGrid( QGridLayout *l, int line )
941 l->addWidget( checkbox, line, 0, 1, -1, 0 );
944 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
945 module_config_t *_p_item,
947 QAbstractButton *_checkbox ) :
948 VIntConfigControl( _p_this, _p_item )
950 checkbox = _checkbox;
951 VLC_UNUSED( _label );
955 int BoolConfigControl::getType() const { return CONFIG_ITEM_BOOL; }
957 void BoolConfigControl::finish()
959 checkbox->setChecked( p_item->value.i );
960 if( p_item->psz_longtext )
961 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
964 int BoolConfigControl::getValue() const
966 return checkbox->isChecked();
969 /************* Color *************/
970 ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
971 module_config_t *_p_item, QWidget *p ) :
972 VIntConfigControl( _p_this, _p_item )
974 label = new QLabel( p );
975 color_but = new QToolButton( p );
979 void ColorConfigControl::fillGrid( QGridLayout *l, int line )
981 l->addWidget( label, line, 0 );
982 l->addWidget( color_but, line, LAST_COLUMN, Qt::AlignRight );
985 ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
986 module_config_t *_p_item,
987 QLabel *_label, QAbstractButton *_color ):
988 VIntConfigControl( _p_this, _p_item )
995 void ColorConfigControl::finish()
997 i_color = p_item->value.i;
999 color_px = new QPixmap( 34, 20 );
1000 color_px->fill( QColor( i_color ) );
1001 color_but->setIcon( QIcon( *color_px ) );
1002 color_but->setMinimumWidth( 40 );
1004 label->setText( qtr(p_item->psz_text) );
1005 if( p_item->psz_longtext )
1007 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1008 color_but->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1011 BUTTONACT( color_but, selectColor() );
1014 int ColorConfigControl::getValue() const
1019 void ColorConfigControl::selectColor()
1021 QColor color = QColorDialog::getColor( QColor( i_color ) );
1022 if( color.isValid() )
1024 i_color = (color.red() << 16) + (color.green() << 8) + color.blue();
1026 color_px->fill( QColor( i_color ) );
1027 color_but->setIcon( QIcon( *color_px ) );
1032 /**************************************************************************
1033 * Float-based controls
1034 *************************************************************************/
1037 VFloatConfigControl::doApply()
1039 config_PutFloat( p_this, getName(), getValue() );
1042 /*********** Float **************/
1043 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1044 module_config_t *_p_item, QWidget *p ) :
1045 VFloatConfigControl( _p_this, _p_item )
1047 label = new QLabel( qtr(p_item->psz_text), p );
1048 spin = new QDoubleSpinBox( p );
1049 spin->setMinimumWidth( MINWIDTH_BOX );
1050 spin->setMaximumWidth( MINWIDTH_BOX );
1051 spin->setAlignment( Qt::AlignRight );
1055 void FloatConfigControl::fillGrid( QGridLayout *l, int line )
1057 l->addWidget( label, line, 0 );
1058 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1061 int VFloatConfigControl::getType() const { return CONFIG_ITEM_FLOAT; }
1063 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1064 module_config_t *_p_item,
1066 QDoubleSpinBox *_spin ) :
1067 VFloatConfigControl( _p_this, _p_item )
1074 void FloatConfigControl::finish()
1076 spin->setMaximum( 2000000000. );
1077 spin->setMinimum( -2000000000. );
1078 spin->setSingleStep( 0.1 );
1079 spin->setValue( (double)p_item->value.f );
1080 if( p_item->psz_longtext )
1082 QString tipText = qtr(p_item->psz_longtext);
1083 spin->setToolTip( formatTooltip(tipText) );
1085 label->setToolTip( formatTooltip(tipText) );
1088 label->setBuddy( spin );
1091 float FloatConfigControl::getValue() const
1093 return (float)spin->value();
1096 /*********** Float with range **************/
1097 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1098 module_config_t *_p_item, QWidget *p ) :
1099 FloatConfigControl( _p_this, _p_item, p )
1104 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1105 module_config_t *_p_item,
1107 QDoubleSpinBox *_spin ) :
1108 FloatConfigControl( _p_this, _p_item, _label, _spin )
1113 void FloatRangeConfigControl::finish()
1115 spin->setMaximum( (double)p_item->max.f );
1116 spin->setMinimum( (double)p_item->min.f );
1120 /**********************************************************************
1121 * Key selector widget
1122 **********************************************************************/
1123 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1124 module_config_t *_p_item, QWidget *p ) :
1125 ConfigControl( _p_this, _p_item )
1129 qtr( "Select or double click an action to change the associated "
1130 "hotkey. Use delete key to remove hotkeys"), p );
1132 searchLabel = new QLabel( qtr( "Search" ), p );
1133 actionSearch = new SearchLineEdit();
1135 table = new QTreeWidget( p );
1136 table->setColumnCount(3);
1137 table->headerItem()->setText( 0, qtr( "Action" ) );
1138 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1139 table->headerItem()->setToolTip( 1, qtr( "Application level hotkey" ) );
1140 table->headerItem()->setText( 2, qtr( "Global" ) );
1141 table->headerItem()->setToolTip( 2, qtr( "Desktop level hotkey" ) );
1142 table->setAlternatingRowColors( true );
1143 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1145 table->installEventFilter( this );
1149 CONNECT( actionSearch, textChanged( const QString& ),
1150 this, filter( const QString& ) );
1153 void KeySelectorControl::fillGrid( QGridLayout *l, int line )
1155 QGridLayout *gLayout = new QGridLayout();
1156 gLayout->addWidget( label, 0, 0, 1, 4 );
1157 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1158 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1159 gLayout->addWidget( table, 2, 0, 1, 4 );
1160 l->addLayout( gLayout, line, 0, 1, -1 );
1163 int KeySelectorControl::getType() const { return CONFIG_ITEM_KEY; }
1165 void KeySelectorControl::finish()
1167 if( label && p_item->psz_longtext )
1168 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1170 /* Fill the table */
1172 /* Get the main Module */
1173 module_t *p_main = module_get_main();
1176 /* Access to the module_config_t */
1178 module_config_t *p_config;
1180 p_config = module_config_get (p_main, &confsize);
1182 QMap<QString, QString> global_keys;
1183 for (size_t i = 0; i < confsize; i++)
1185 module_config_t *p_config_item = p_config + i;
1187 /* If we are a (non-global) key option not empty */
1188 if( CONFIG_ITEM(p_config_item->i_type) && p_config_item->psz_name != NULL
1189 && !strncmp( p_config_item->psz_name , "key-", 4 )
1190 && !EMPTY_STR( p_config_item->psz_text ) )
1194 - QString text in column 0
1195 - QString name in data of column 0
1196 - KeyValue in String in column 1
1198 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1199 treeItem->setText( 0, qtr( p_config_item->psz_text ) );
1200 treeItem->setData( 0, Qt::UserRole,
1201 QVariant( qfu( p_config_item->psz_name ) ) );
1203 QString keys = qfu( p_config_item->value.psz );
1204 treeItem->setText( 1, keys );
1205 treeItem->setToolTip( 1, qtr("Double click to change") );
1206 treeItem->setToolTip( 2, qtr("Double click to change") );
1207 treeItem->setData( 1, Qt::UserRole, QVariant( keys ) );
1208 table->addTopLevelItem( treeItem );
1212 if( CONFIG_ITEM(p_config_item->i_type) && p_config_item->psz_name != NULL
1213 && !strncmp( p_config_item->psz_name , "global-key", 10 )
1214 && !EMPTY_STR( p_config_item->psz_text )
1215 && !EMPTY_STR( p_config_item->value.psz ) )
1217 global_keys.insertMulti( qtr( p_config_item->psz_text ), qfu( p_config_item->value.psz ) );
1221 QMap<QString, QString>::const_iterator i = global_keys.constBegin();
1222 while (i != global_keys.constEnd())
1224 QList<QTreeWidgetItem *> list = table->findItems( i.key(), Qt::MatchExactly|Qt::MatchWrap, 0 );
1225 if( list.count() >= 1 )
1227 QString keys = i.value();
1228 list[0]->setText( 2, keys );
1229 list[0]->setData( 2, Qt::UserRole, keys );
1231 if( list.count() >= 2 )
1232 msg_Dbg( p_this, "This is probably wrong, %s", qtu(i.key()) );
1237 module_config_free (p_config);
1239 table->resizeColumnToContents( 0 );
1241 CONNECT( table, itemActivated( QTreeWidgetItem *, int ),
1242 this, selectKey( QTreeWidgetItem *, int ) );
1245 void KeySelectorControl::filter( const QString &qs_search )
1247 QList<QTreeWidgetItem *> resultList =
1248 table->findItems( qs_search, Qt::MatchContains, 0 );
1249 for( int i = 0; i < table->topLevelItemCount(); i++ )
1251 table->topLevelItem( i )->setHidden(
1252 !resultList.contains( table->topLevelItem( i ) ) );
1256 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1258 /* This happens when triggered by ClickEater */
1259 if( keyItem == NULL ) keyItem = table->currentItem();
1261 /* This can happen when nothing is selected on the treeView
1262 and the shortcutValue is clicked */
1263 if( !keyItem ) return;
1265 /* If clicked on the first column, assuming user wants the normal hotkey */
1266 if( column == 0 ) column = 1;
1268 bool b_global = ( column == 2 );
1270 /* Launch a small dialog to ask for a new key */
1271 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), table, b_global );
1274 if( d->result() == QDialog::Accepted )
1276 QString newKey = VLCKeyToString( d->keyValue );
1278 /* In case of conflict, reset other keys*/
1281 QTreeWidgetItem *it;
1282 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1284 it = table->topLevelItem(i);
1285 if( ( keyItem != it ) &&
1286 ( it->data( 1 + b_global, Qt::UserRole ).toString() == newKey ) )
1288 it->setData( 1 + b_global, Qt::UserRole,
1289 QVariant( qfu( "Unset" ) ) );
1290 it->setText( 1 + b_global, qtr( "Unset" ) );
1295 keyItem->setText( column, newKey );
1296 keyItem->setData( column, Qt::UserRole, newKey );
1301 void KeySelectorControl::doApply()
1303 QTreeWidgetItem *it;
1304 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1306 it = table->topLevelItem(i);
1307 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1308 config_PutPsz( p_this,
1309 qtu( it->data( 0, Qt::UserRole ).toString() ),
1310 qtu( it->data( 1, Qt::UserRole ).toString() ) );
1311 if( !it->data( 2, Qt::UserRole ).toString().isEmpty() )
1313 config_PutPsz( p_this,
1314 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1315 qtu( it->data( 2, Qt::UserRole ).toString() ) );
1321 bool KeySelectorControl::eventFilter( QObject *obj, QEvent *e )
1323 if( obj != table || e->type() != QEvent::KeyPress )
1324 return ConfigControl::eventFilter(obj, e);
1326 QKeyEvent *keyEv = static_cast<QKeyEvent*>(e);
1327 QTreeWidget *aTable = static_cast<QTreeWidget *>(obj);
1328 if( keyEv->key() == Qt::Key_Escape )
1330 aTable->clearFocus();
1333 else if( keyEv->key() == Qt::Key_Return ||
1334 keyEv->key() == Qt::Key_Enter )
1336 selectKey( aTable->currentItem(), aTable->currentColumn() );
1339 else if( keyEv->key() == Qt::Key_Delete )
1341 if( aTable->currentColumn() != 0 )
1343 aTable->currentItem()->setText( aTable->currentColumn(), NULL );
1344 aTable->currentItem()->setData( aTable->currentColumn(), Qt::UserRole, QVariant() );
1354 * Class KeyInputDialog
1356 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1357 const QString& keyToChange,
1360 QDialog( _parent ), keyValue(0), b_global( _b_global )
1366 setWindowTitle( ( b_global ? qtr( "Global" ) + QString(" ") : "" )
1367 + qtr( "Hotkey change" ) );
1368 setWindowRole( "vlc-key-input" );
1370 QVBoxLayout *vLayout = new QVBoxLayout( this );
1371 selected = new QLabel( qtr( "Press the new key or combination for " )
1372 + QString("<b>%1</b>").arg( keyToChange ) );
1373 vLayout->addWidget( selected , Qt::AlignCenter );
1375 warning = new QLabel;
1377 vLayout->insertWidget( 1, warning );
1379 buttonBox = new QDialogButtonBox;
1380 QPushButton *ok = new QPushButton( qtr("Assign") );
1381 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1382 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1383 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1384 ok->setDefault( true );
1386 vLayout->addWidget( buttonBox );
1389 CONNECT( buttonBox, accepted(), this, accept() );
1390 CONNECT( buttonBox, rejected(), this, reject() );
1393 void KeyInputDialog::checkForConflicts( int i_vlckey )
1395 QList<QTreeWidgetItem *> conflictList =
1396 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1399 if( conflictList.count() &&
1400 !conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toString().isEmpty() &&
1401 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toString() != "Unset" )
1403 warning->setText( qtr("Warning: this key or combination is already assigned to ") +
1404 QString( "\"<b>%1</b>\"" ).arg( conflictList[0]->text( 0 ) ) );
1413 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1415 if( e->key() == Qt::Key_Tab ||
1416 e->key() == Qt::Key_Shift ||
1417 e->key() == Qt::Key_Control ||
1418 e->key() == Qt::Key_Meta ||
1419 e->key() == Qt::Key_Alt ||
1420 e->key() == Qt::Key_AltGr )
1422 int i_vlck = qtEventToVLCKey( e );
1423 selected->setText( qtr( "Key or combination: " )
1424 + QString("<b>%1</b>").arg( VLCKeyToString( i_vlck ) ) );
1425 checkForConflicts( i_vlck );
1429 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1431 int i_vlck = qtWheelEventToVLCKey( e );
1432 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1433 checkForConflicts( i_vlck );