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 #include <QKeySequence>
57 #define MINWIDTH_BOX 90
58 #define LAST_COLUMN 10
60 QString formatTooltip(const QString & tooltip)
62 QString text = tooltip;
63 text.replace("\n", "<br/>");
66 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
67 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
68 "<body style=\" font-family:'Sans Serif'; "
69 "font-style:normal; text-decoration:none;\">"
70 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
71 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
72 text + "</p></body></html>";
76 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
77 module_config_t *p_item,
79 QGridLayout *l, int line )
81 ConfigControl *p_control = NULL;
83 switch( p_item->i_type )
85 case CONFIG_ITEM_MODULE:
86 p_control = new StringListConfigControl( p_this, p_item, parent );
88 case CONFIG_ITEM_MODULE_CAT:
89 p_control = new ModuleConfigControl( p_this, p_item, parent );
91 case CONFIG_ITEM_MODULE_LIST:
92 p_control = new ModuleListConfigControl( p_this, p_item, parent, false );
94 case CONFIG_ITEM_MODULE_LIST_CAT:
95 p_control = new ModuleListConfigControl( p_this, p_item, parent, true );
97 case CONFIG_ITEM_STRING:
98 if( p_item->list.psz_cb )
99 p_control = new StringListConfigControl( p_this, p_item, parent );
101 p_control = new StringConfigControl( p_this, p_item, parent, false );
103 case CONFIG_ITEM_PASSWORD:
104 p_control = new StringConfigControl( p_this, p_item, parent, true );
106 case CONFIG_ITEM_RGB:
107 p_control = new ColorConfigControl( p_this, p_item, parent );
109 case CONFIG_ITEM_INTEGER:
110 if( p_item->list.i_cb )
111 p_control = new IntegerListConfigControl( p_this, p_item, parent, false );
112 else if( p_item->min.i || p_item->max.i )
113 p_control = new IntegerRangeConfigControl( p_this, p_item, parent );
115 p_control = new IntegerConfigControl( p_this, p_item, parent );
117 case CONFIG_ITEM_LOADFILE:
118 case CONFIG_ITEM_SAVEFILE:
119 p_control = new FileConfigControl( p_this, p_item, parent );
121 case CONFIG_ITEM_DIRECTORY:
122 p_control = new DirectoryConfigControl( p_this, p_item, parent );
124 case CONFIG_ITEM_FONT:
125 p_control = new FontConfigControl( p_this, p_item, parent );
127 case CONFIG_ITEM_KEY:
128 p_control = new KeySelectorControl( p_this, p_item, parent );
130 case CONFIG_ITEM_BOOL:
131 p_control = new BoolConfigControl( p_this, p_item, parent );
133 case CONFIG_ITEM_FLOAT:
134 if( p_item->min.f || p_item->max.f )
135 p_control = new FloatRangeConfigControl( p_this, p_item, parent );
137 p_control = new FloatConfigControl( p_this, p_item, parent );
142 if ( p_control ) p_control->insertIntoExistingGrid( l, line );
146 /* Inserts controls into layouts
147 This is sub-optimal in the OO way, as controls's code still
148 depends on Layout classes. We should use layout inserters [friend]
149 classes, but it's unlikely we had to deal with a different layout.*/
150 void ConfigControl::insertInto( QBoxLayout *layout )
152 QGridLayout *sublayout = new QGridLayout();
153 fillGrid( sublayout, 0 );
154 layout->addLayout( sublayout );
157 void ConfigControl::insertIntoExistingGrid( QGridLayout *l, int line )
162 /*******************************************************
164 *******************************************************/
165 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
167 setGeometry( 0, 0, 128, 100 );
168 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
171 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
173 setPreview( ( b_minimal ) ? MINIMAL : COMPLETE );
176 void InterfacePreviewWidget::setPreview( enum_style e_style )
178 QString pixmapLocationString(":/prefsmenu/");
184 pixmapLocationString += "sample_complete";
187 pixmapLocationString += "sample_minimal";
190 pixmapLocationString += "sample_skins";
194 setPixmap( QPixmap( pixmapLocationString ) );
199 /**************************************************************************
200 * String-based controls
201 *************************************************************************/
204 VStringConfigControl::doApply()
206 config_PutPsz( p_this, getName(), qtu( getValue() ) );
209 /*********** String **************/
210 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
211 module_config_t *_p_item,
214 VStringConfigControl( _p_this, _p_item )
216 label = new QLabel( qtr(p_item->psz_text), _parent );
217 text = new QLineEdit( qfu(p_item->value.psz), _parent );
218 if( pwd ) text->setEchoMode( QLineEdit::Password );
222 void StringConfigControl::fillGrid( QGridLayout *l, int line )
224 l->addWidget( label, line, 0 );
225 l->setColumnMinimumWidth( 1, 10 );
226 l->addWidget( text, line, LAST_COLUMN, Qt::AlignRight );
229 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
230 module_config_t *_p_item,
231 QLabel *_label, QLineEdit *_text, bool pwd ):
232 VStringConfigControl( _p_this, _p_item )
235 if( pwd ) text->setEchoMode( QLineEdit::Password );
240 int VStringConfigControl::getType() const { return CONFIG_ITEM_STRING; }
242 void StringConfigControl::finish()
244 text->setText( qfu(p_item->value.psz) );
245 if( p_item->psz_longtext )
247 QString tipText = qtr(p_item->psz_longtext);
248 text->setToolTip( formatTooltip(tipText) );
250 label->setToolTip( formatTooltip(tipText) );
253 label->setBuddy( text );
256 /*********** File **************/
257 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
258 module_config_t *_p_item, QWidget *p ) :
259 VStringConfigControl( _p_this, _p_item )
261 label = new QLabel( qtr(p_item->psz_text), p );
262 text = new QLineEdit( qfu(p_item->value.psz), p );
263 browse = new QPushButton( qtr( "Browse..." ), p );
265 BUTTONACT( browse, updateField() );
270 void FileConfigControl::fillGrid( QGridLayout *l, int line )
272 l->addWidget( label, line, 0 );
273 l->setColumnMinimumWidth( 1, 10 );
274 QHBoxLayout *textAndButton = new QHBoxLayout();
275 textAndButton->setMargin( 0 );
276 textAndButton->addWidget( text, 2 );
277 textAndButton->addWidget( browse, 0 );
278 l->addLayout( textAndButton, line, LAST_COLUMN, 0 );
281 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
282 module_config_t *_p_item,
283 QLabel *_label, QLineEdit *_text,
284 QPushButton *_button ):
285 VStringConfigControl( _p_this, _p_item )
291 BUTTONACT( browse, updateField() );
296 void FileConfigControl::updateField()
300 if (p_item->i_type == CONFIG_ITEM_SAVEFILE)
301 file = QFileDialog::getSaveFileName( NULL, qtr( "Save File" ),
302 QVLCUserDir( VLC_HOME_DIR ) );
304 file = QFileDialog::getOpenFileName( NULL, qtr( "Select File" ),
305 QVLCUserDir( VLC_HOME_DIR ) );
307 if( file.isNull() ) return;
308 text->setText( toNativeSeparators( file ) );
311 void FileConfigControl::finish()
313 text->setText( qfu(p_item->value.psz) );
314 if( p_item->psz_longtext )
316 QString tipText = qtr(p_item->psz_longtext);
317 text->setToolTip( formatTooltip(tipText) );
319 label->setToolTip( formatTooltip(tipText) );
322 label->setBuddy( text );
325 /********* String / Directory **********/
326 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
327 module_config_t *_p_item, QWidget *p ) :
328 FileConfigControl( _p_this, _p_item, p )
331 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
332 module_config_t *_p_item, QLabel *_p_label,
333 QLineEdit *_p_line, QPushButton *_p_button ):
334 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
337 void DirectoryConfigControl::updateField()
339 QString dir = QFileDialog::getExistingDirectory( NULL,
341 text->text().isEmpty() ?
342 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
343 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
345 if( dir.isNull() ) return;
346 text->setText( toNativeSepNoSlash( dir ) );
349 /********* String / Font **********/
350 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
351 module_config_t *_p_item, QWidget *p ) :
352 VStringConfigControl( _p_this, _p_item )
354 label = new QLabel( qtr(p_item->psz_text), p );
355 font = new QFontComboBox( p );
356 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
358 if( p_item->psz_longtext )
360 label->setToolTip( formatTooltip( qtr(p_item->psz_longtext) ) );
364 void FontConfigControl::fillGrid( QGridLayout *l, int line )
366 l->addWidget( label, line, 0 );
367 l->addWidget( font, line, 1, 1, -1 );
370 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
371 module_config_t *_p_item, QLabel *_p_label,
372 QFontComboBox *_p_font):
373 VStringConfigControl( _p_this, _p_item)
377 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
379 if( p_item->psz_longtext )
381 label->setToolTip( formatTooltip( qtr(p_item->psz_longtext) ) );
385 /********* String / choice list **********/
386 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
387 module_config_t *_p_item, QWidget *p ) :
388 VStringConfigControl( _p_this, _p_item )
390 label = new QLabel( qtr(p_item->psz_text), p );
391 combo = new QComboBox( p );
392 combo->setMinimumWidth( MINWIDTH_BOX );
393 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
395 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
397 finish( p_module_config );
400 void StringListConfigControl::fillGrid( QGridLayout *l, int line )
402 l->addWidget( label, line, 0 );
403 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
405 foreach( QPushButton *button, buttons )
406 l->addWidget( button, line, LAST_COLUMN + i++,
410 void StringListConfigControl::comboIndexChanged( int i_index )
416 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
417 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
418 bool ) : VStringConfigControl( _p_this, _p_item )
423 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
425 finish( p_module_config );
428 void StringListConfigControl::finish(module_config_t *p_module_config )
430 combo->setEditable( false );
431 CONNECT( combo, currentIndexChanged ( int ), this, comboIndexChanged( int ) );
433 if(!p_module_config) return;
435 char **values, **texts;
436 ssize_t count = config_GetPszChoices( p_this, p_item->psz_name,
438 for( ssize_t i = 0; i < count && texts; i++ )
440 if( texts[i] == NULL || values[i] == NULL )
443 combo->addItem( qfu(texts[i]), QVariant( qfu(values[i])) );
444 if( !strcmp( p_item->value.psz ? p_item->value.psz : "", values[i] ) )
445 combo->setCurrentIndex( combo->count() - 1 );
452 if( p_module_config->psz_longtext )
454 QString tipText = qtr(p_module_config->psz_longtext);
455 combo->setToolTip( formatTooltip(tipText) );
457 label->setToolTip( formatTooltip(tipText) );
460 label->setBuddy( combo );
463 QString StringListConfigControl::getValue() const
465 return combo->itemData( combo->currentIndex() ).toString();
468 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
471 module_config_t *p_config =
472 config_FindConfig( VLC_OBJECT(p_intf), configname );
473 if( p_config == NULL )
476 if( (p_config->i_type & 0xF0) == CONFIG_ITEM_STRING )
478 char **values, **texts;
479 ssize_t count = config_GetPszChoices(VLC_OBJECT(p_intf),
480 configname, &values, &texts);
481 for( ssize_t i = 0; i < count; i++ )
483 combo->addItem( qtr(texts[i]), QVariant(qfu(values[i])) );
484 if( !strcmp(p_config->value.psz, values[i]) )
485 combo->setCurrentIndex( i );
496 ssize_t count = config_GetIntChoices(VLC_OBJECT(p_intf), configname,
498 for( ssize_t i = 0; i < count; i++ )
500 combo->addItem( qtr(texts[i]), QVariant(qlonglong(values[i])) );
501 if( p_config->value.i == values[i] )
502 combo->setCurrentIndex( i );
508 if( p_config->psz_longtext != NULL )
509 combo->setToolTip( qfu( p_config->psz_longtext ) );
512 /********* Module **********/
513 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
514 module_config_t *_p_item, QWidget *p ) :
515 VStringConfigControl( _p_this, _p_item )
517 label = new QLabel( qtr(p_item->psz_text), p );
518 combo = new QComboBox( p );
519 combo->setMinimumWidth( MINWIDTH_BOX );
523 void ModuleConfigControl::fillGrid( QGridLayout *l, int line )
525 l->addWidget( label, line, 0 );
526 l->addWidget( combo, line, LAST_COLUMN, 0 );
529 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
530 module_config_t *_p_item, QLabel *_label, QComboBox *_combo )
531 : VStringConfigControl( _p_this, _p_item )
538 void ModuleConfigControl::finish( )
540 combo->setEditable( false );
542 /* build a list of available modules */
544 module_t **p_list = module_list_get( &count );
545 combo->addItem( qtr("Default") );
546 for( size_t i = 0; i < count; i++ )
548 module_t *p_parser = p_list[i];
550 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
553 module_config_t *p_config;
555 p_config = module_config_get (p_parser, &confsize);
556 for (size_t i = 0; i < confsize; i++)
558 /* Hack: required subcategory is stored in i_min */
559 const module_config_t *p_cfg = p_config + i;
560 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
561 p_cfg->value.i == p_item->min.i )
562 combo->addItem( qtr( module_GetLongName( p_parser )),
563 QVariant( module_get_object( p_parser ) ) );
564 if( p_item->value.psz && !strcmp( p_item->value.psz,
565 module_get_object( p_parser ) ) )
566 combo->setCurrentIndex( combo->count() - 1 );
568 module_config_free (p_config);
570 module_list_free( p_list );
572 if( p_item->psz_longtext )
574 QString tipText = qtr(p_item->psz_longtext);
575 combo->setToolTip( formatTooltip(tipText) );
577 label->setToolTip( formatTooltip(tipText) );
580 label->setBuddy( combo );
583 QString ModuleConfigControl::getValue() const
585 return combo->itemData( combo->currentIndex() ).toString();
588 /********* Module list **********/
589 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
590 module_config_t *_p_item, QWidget *p, bool bycat ) :
591 VStringConfigControl( _p_this, _p_item )
596 if( !p_item->psz_text ) return;
598 groupBox = new QGroupBox ( qtr(p_item->psz_text), p );
599 text = new QLineEdit( p );
600 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
605 foreach ( checkBoxListItem *it, modules )
607 layoutGroupBox->addWidget( it->checkBox, boxline / 2, boxline % 2 );
611 layoutGroupBox->addWidget( text, boxline, 0, 1, 2 );
613 if( p_item->psz_longtext )
614 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
617 void ModuleListConfigControl::fillGrid( QGridLayout *l, int line )
619 l->addWidget( groupBox, line, 0, 1, -1 );
622 ModuleListConfigControl::~ModuleListConfigControl()
624 qDeleteAll( modules );
629 void ModuleListConfigControl::checkbox_lists( module_t *p_parser )
631 const char *help = module_get_help( p_parser );
632 checkbox_lists( qtr( module_GetLongName( p_parser ) ),
633 help != NULL ? qtr( help ): "",
634 module_get_object( p_parser ) );
637 void ModuleListConfigControl::checkbox_lists( QString label, QString help, const char* psz_module )
639 QCheckBox *cb = new QCheckBox( label );
640 checkBoxListItem *cbl = new checkBoxListItem;
642 CONNECT( cb, stateChanged( int ), this, onUpdate() );
643 if( !help.isEmpty() )
644 cb->setToolTip( formatTooltip( help ) );
647 cbl->psz_module = strdup( psz_module );
648 modules.append( cbl );
650 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) )
651 cbl->checkBox->setChecked( true );
654 void ModuleListConfigControl::finish( bool bycat )
656 /* build a list of available modules */
658 module_t **p_list = module_list_get( &count );
659 for( size_t i = 0; i < count; i++ )
661 module_t *p_parser = p_list[i];
665 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
668 module_config_t *p_config = module_config_get (p_parser, &confsize);
670 for (size_t i = 0; i < confsize; i++)
672 module_config_t *p_cfg = p_config + i;
673 /* Hack: required subcategory is stored in i_min */
674 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
675 p_cfg->value.i == p_item->min.i )
677 checkbox_lists( p_parser );
680 /* Parental Advisory HACK:
681 * Selecting HTTP, RC and Telnet interfaces is difficult now
682 * since they are just the lua interface module */
683 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
684 !strcmp( module_get_object( p_parser ), "lua" ) &&
685 !strcmp( p_item->psz_name, "extraintf" ) &&
686 p_cfg->value.i == p_item->min.i )
688 checkbox_lists( "Web", "Lua HTTP", "http" );
689 checkbox_lists( "Telnet", "Lua Telnet", "telnet" );
691 checkbox_lists( "Console", "Lua CLI", "cli" );
695 module_config_free (p_config);
697 else if( module_provides( p_parser, p_item->psz_type ) )
699 checkbox_lists(p_parser);
702 module_list_free( p_list );
704 if( p_item->psz_longtext )
706 QString tipText = qtr(p_item->psz_longtext);
708 text->setToolTip( formatTooltip(tipText) );
710 groupBox->setToolTip( formatTooltip(tipText) );
714 QString ModuleListConfigControl::getValue() const
720 void ModuleListConfigControl::changeVisibility( bool b )
722 foreach ( checkBoxListItem *it, modules )
723 it->checkBox->setVisible( b );
724 groupBox->setVisible( b );
727 void ModuleListConfigControl::onUpdate()
732 foreach ( checkBoxListItem *it, modules )
734 if( it->checkBox->isChecked() )
738 text->setText( text->text() + it->psz_module );
743 text->setText( text->text() + ":" + it->psz_module );
749 /**************************************************************************
750 * Integer-based controls
751 *************************************************************************/
754 VIntConfigControl::doApply()
756 config_PutInt( p_this, getName(), getValue() );
759 /*********** Integer **************/
760 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
761 module_config_t *_p_item, QWidget *p ) :
762 VIntConfigControl( _p_this, _p_item )
764 label = new QLabel( qtr(p_item->psz_text), p );
765 spin = new QSpinBox( p ); spin->setMinimumWidth( MINWIDTH_BOX );
766 spin->setAlignment( Qt::AlignRight );
767 spin->setMaximumWidth( MINWIDTH_BOX );
771 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
772 module_config_t *_p_item,
773 QLabel *_label, QSpinBox *_spin ) :
774 VIntConfigControl( _p_this, _p_item )
781 void IntegerConfigControl::fillGrid( QGridLayout *l, int line )
783 l->addWidget( label, line, 0 );
784 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
787 void IntegerConfigControl::finish()
789 spin->setMaximum( 2000000000 );
790 spin->setMinimum( -2000000000 );
791 spin->setValue( p_item->value.i );
793 if( p_item->psz_longtext )
795 QString tipText = qtr(p_item->psz_longtext);
796 spin->setToolTip( formatTooltip(tipText) );
798 label->setToolTip( formatTooltip(tipText) );
801 label->setBuddy( spin );
804 int IntegerConfigControl::getValue() const
806 return spin->value();
809 int VIntConfigControl::getType() const { return CONFIG_ITEM_INTEGER; }
811 /********* Integer range **********/
812 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
813 module_config_t *_p_item, QWidget *p ) :
814 IntegerConfigControl( _p_this, _p_item, p )
819 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
820 module_config_t *_p_item,
821 QLabel *_label, QSpinBox *_spin ) :
822 IntegerConfigControl( _p_this, _p_item, _label, _spin )
827 void IntegerRangeConfigControl::finish()
829 spin->setMaximum( p_item->max.i > INT_MAX ? INT_MAX : p_item->max.i );
830 spin->setMinimum( p_item->min.i < INT_MIN ? INT_MIN : p_item->min.i );
833 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
834 vlc_object_t *_p_this,
835 module_config_t *_p_item,
836 QLabel *_label, QSlider *_slider ):
837 VIntConfigControl( _p_this, _p_item )
841 slider->setMaximum( p_item->max.i > INT_MAX ? INT_MAX : p_item->max.i );
842 slider->setMinimum( p_item->min.i < INT_MIN ? INT_MIN : p_item->min.i );
843 slider->setValue( p_item->value.i );
844 if( p_item->psz_longtext )
846 QString tipText = qtr(p_item->psz_longtext);
847 slider->setToolTip( formatTooltip(tipText) );
849 label->setToolTip( formatTooltip(tipText) );
852 label->setBuddy( slider );
855 int IntegerRangeSliderConfigControl::getValue() const
857 return slider->value();
861 /********* Integer / choice list **********/
862 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
863 module_config_t *_p_item, QWidget *p, bool ) :
864 VIntConfigControl( _p_this, _p_item )
866 label = new QLabel( qtr(p_item->psz_text), p );
867 combo = new QComboBox( p );
868 combo->setMinimumWidth( MINWIDTH_BOX );
870 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
872 finish( p_module_config );
875 void IntegerListConfigControl::fillGrid( QGridLayout *l, int line )
877 l->addWidget( label, line, 0 );
878 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
880 foreach( QPushButton *button, buttons )
881 l->addWidget( button, line, LAST_COLUMN + i++,
885 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
886 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
887 bool ) : VIntConfigControl( _p_this, _p_item )
892 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
894 finish( p_module_config );
897 void IntegerListConfigControl::finish(module_config_t *p_module_config )
899 combo->setEditable( false );
901 if(!p_module_config) return;
905 ssize_t count = config_GetIntChoices( p_this, p_module_config->psz_name,
907 for( ssize_t i = 0; i < count; i++ )
909 combo->addItem( qtr(texts[i]), qlonglong(values[i]) );
910 if( p_module_config->value.i == values[i] )
911 combo->setCurrentIndex( combo->count() - 1 );
916 if( p_item->psz_longtext )
918 QString tipText = qtr(p_item->psz_longtext );
919 combo->setToolTip( formatTooltip(tipText) );
921 label->setToolTip( formatTooltip(tipText) );
924 label->setBuddy( combo );
927 int IntegerListConfigControl::getValue() const
929 return combo->itemData( combo->currentIndex() ).toInt();
932 /*********** Boolean **************/
933 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
934 module_config_t *_p_item, QWidget *p ) :
935 VIntConfigControl( _p_this, _p_item )
937 checkbox = new QCheckBox( qtr(p_item->psz_text), p );
941 void BoolConfigControl::fillGrid( QGridLayout *l, int line )
943 l->addWidget( checkbox, line, 0, 1, -1, 0 );
946 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
947 module_config_t *_p_item,
949 QAbstractButton *_checkbox ) :
950 VIntConfigControl( _p_this, _p_item )
952 checkbox = _checkbox;
953 VLC_UNUSED( _label );
957 int BoolConfigControl::getType() const { return CONFIG_ITEM_BOOL; }
959 void BoolConfigControl::finish()
961 checkbox->setChecked( p_item->value.i );
962 if( p_item->psz_longtext )
963 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
966 int BoolConfigControl::getValue() const
968 return checkbox->isChecked();
971 /************* Color *************/
972 ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
973 module_config_t *_p_item, QWidget *p ) :
974 VIntConfigControl( _p_this, _p_item )
976 label = new QLabel( p );
977 color_but = new QToolButton( p );
981 void ColorConfigControl::fillGrid( QGridLayout *l, int line )
983 l->addWidget( label, line, 0 );
984 l->addWidget( color_but, line, LAST_COLUMN, Qt::AlignRight );
987 ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
988 module_config_t *_p_item,
989 QLabel *_label, QAbstractButton *_color ):
990 VIntConfigControl( _p_this, _p_item )
997 void ColorConfigControl::finish()
999 i_color = p_item->value.i;
1001 color_px = new QPixmap( 34, 20 );
1002 color_px->fill( QColor( i_color ) );
1003 color_but->setIcon( QIcon( *color_px ) );
1004 color_but->setMinimumWidth( 40 );
1006 label->setText( qtr(p_item->psz_text) );
1007 if( p_item->psz_longtext )
1009 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1010 color_but->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1013 BUTTONACT( color_but, selectColor() );
1016 int ColorConfigControl::getValue() const
1021 void ColorConfigControl::selectColor()
1023 QColor color = QColorDialog::getColor( QColor( i_color ) );
1024 if( color.isValid() )
1026 i_color = (color.red() << 16) + (color.green() << 8) + color.blue();
1028 color_px->fill( QColor( i_color ) );
1029 color_but->setIcon( QIcon( *color_px ) );
1034 /**************************************************************************
1035 * Float-based controls
1036 *************************************************************************/
1039 VFloatConfigControl::doApply()
1041 config_PutFloat( p_this, getName(), getValue() );
1044 /*********** Float **************/
1045 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1046 module_config_t *_p_item, QWidget *p ) :
1047 VFloatConfigControl( _p_this, _p_item )
1049 label = new QLabel( qtr(p_item->psz_text), p );
1050 spin = new QDoubleSpinBox( p );
1051 spin->setMinimumWidth( MINWIDTH_BOX );
1052 spin->setMaximumWidth( MINWIDTH_BOX );
1053 spin->setAlignment( Qt::AlignRight );
1057 void FloatConfigControl::fillGrid( QGridLayout *l, int line )
1059 l->addWidget( label, line, 0 );
1060 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1063 int VFloatConfigControl::getType() const { return CONFIG_ITEM_FLOAT; }
1065 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1066 module_config_t *_p_item,
1068 QDoubleSpinBox *_spin ) :
1069 VFloatConfigControl( _p_this, _p_item )
1076 void FloatConfigControl::finish()
1078 spin->setMaximum( 2000000000. );
1079 spin->setMinimum( -2000000000. );
1080 spin->setSingleStep( 0.1 );
1081 spin->setValue( (double)p_item->value.f );
1082 if( p_item->psz_longtext )
1084 QString tipText = qtr(p_item->psz_longtext);
1085 spin->setToolTip( formatTooltip(tipText) );
1087 label->setToolTip( formatTooltip(tipText) );
1090 label->setBuddy( spin );
1093 float FloatConfigControl::getValue() const
1095 return (float)spin->value();
1098 /*********** Float with range **************/
1099 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1100 module_config_t *_p_item, QWidget *p ) :
1101 FloatConfigControl( _p_this, _p_item, p )
1106 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1107 module_config_t *_p_item,
1109 QDoubleSpinBox *_spin ) :
1110 FloatConfigControl( _p_this, _p_item, _label, _spin )
1115 void FloatRangeConfigControl::finish()
1117 spin->setMaximum( (double)p_item->max.f );
1118 spin->setMinimum( (double)p_item->min.f );
1122 /**********************************************************************
1123 * Key selector widget
1124 **********************************************************************/
1125 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1126 module_config_t *_p_item, QWidget *p ) :
1127 ConfigControl( _p_this, _p_item )
1131 qtr( "Select or double click an action to change the associated "
1132 "hotkey. Use delete key to remove hotkeys"), p );
1134 searchLabel = new QLabel( qtr( "Search" ), p );
1135 actionSearch = new SearchLineEdit();
1137 searchOptionLabel = new QLabel( qtr("in") );
1138 searchOption = new QComboBox();
1139 searchOption->addItem( qtr("Any field"), ANY_COL );
1140 searchOption->addItem( qtr("Actions"), ACTION_COL );
1141 searchOption->addItem( qtr("Hotkeys"), HOTKEY_COL );
1142 searchOption->addItem( qtr("Global Hotkeys"), GLOBAL_HOTKEY_COL );
1144 table = new QTreeWidget( p );
1145 table->setColumnCount( ANY_COL );
1146 table->headerItem()->setText( ACTION_COL, qtr( "Action" ) );
1147 table->headerItem()->setText( HOTKEY_COL, qtr( "Hotkey" ) );
1148 table->headerItem()->setToolTip( HOTKEY_COL, qtr( "Application level hotkey" ) );
1149 table->headerItem()->setText( GLOBAL_HOTKEY_COL, qtr( "Global" ) );
1150 table->headerItem()->setToolTip( GLOBAL_HOTKEY_COL, qtr( "Desktop level hotkey" ) );
1151 table->setAlternatingRowColors( true );
1152 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1154 table->installEventFilter( this );
1156 /* Find the top most widget */
1157 QWidget *parent, *rootWidget = p;
1158 while( parent = rootWidget->parentWidget() )
1159 rootWidget = parent;
1160 buildAppHotkeysList( rootWidget );
1164 CONNECT( actionSearch, textChanged( const QString& ),
1165 this, filter( const QString& ) );
1168 void KeySelectorControl::fillGrid( QGridLayout *l, int line )
1170 QGridLayout *gLayout = new QGridLayout();
1171 gLayout->addWidget( label, 0, 0, 1, 5 );
1172 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1173 gLayout->addWidget( actionSearch, 1, 2, 1, 1 );
1174 gLayout->addWidget( searchOptionLabel, 1, 3, 1, 1 );
1175 gLayout->addWidget( searchOption, 1, 4, 1, 1 );
1176 gLayout->addWidget( table, 2, 0, 1, 5 );
1177 l->addLayout( gLayout, line, 0, 1, -1 );
1180 int KeySelectorControl::getType() const { return CONFIG_ITEM_KEY; }
1182 void KeySelectorControl::buildAppHotkeysList( QWidget *rootWidget )
1184 QList<QAction *> actionsList = rootWidget->findChildren<QAction *>();
1185 foreach( const QAction *action, actionsList )
1187 const QList<QKeySequence> shortcuts = action->shortcuts();
1188 foreach( const QKeySequence &keySequence, shortcuts )
1189 existingkeys << keySequence.toString();
1193 void KeySelectorControl::finish()
1195 if( label && p_item->psz_longtext )
1196 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1198 /* Fill the table */
1200 /* Get the main Module */
1201 module_t *p_main = module_get_main();
1204 /* Access to the module_config_t */
1206 module_config_t *p_config;
1208 p_config = module_config_get (p_main, &confsize);
1210 QMap<QString, QString> global_keys;
1211 for (size_t i = 0; i < confsize; i++)
1213 module_config_t *p_config_item = p_config + i;
1215 /* If we are a (non-global) key option not empty */
1216 if( CONFIG_ITEM(p_config_item->i_type) && p_config_item->psz_name != NULL
1217 && !strncmp( p_config_item->psz_name , "key-", 4 )
1218 && !EMPTY_STR( p_config_item->psz_text ) )
1222 - QString text in column 0
1223 - QString name in data of column 0
1224 - KeyValue in String in column 1
1226 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1227 treeItem->setText( ACTION_COL, qtr( p_config_item->psz_text ) );
1228 treeItem->setData( ACTION_COL, Qt::UserRole,
1229 QVariant( qfu( p_config_item->psz_name ) ) );
1231 QString keys = qfu( p_config_item->value.psz );
1232 treeItem->setText( HOTKEY_COL, keys );
1233 treeItem->setToolTip( HOTKEY_COL, qtr("Double click to change.\nDelete key to remove.") );
1234 treeItem->setToolTip( GLOBAL_HOTKEY_COL, qtr("Double click to change.\nDelete key to remove.") );
1235 treeItem->setData( HOTKEY_COL, Qt::UserRole, QVariant( keys ) );
1236 table->addTopLevelItem( treeItem );
1240 if( CONFIG_ITEM(p_config_item->i_type) && p_config_item->psz_name != NULL
1241 && !strncmp( p_config_item->psz_name , "global-key", 10 )
1242 && !EMPTY_STR( p_config_item->psz_text )
1243 && !EMPTY_STR( p_config_item->value.psz ) )
1245 global_keys.insertMulti( qtr( p_config_item->psz_text ), qfu( p_config_item->value.psz ) );
1249 QMap<QString, QString>::const_iterator i = global_keys.constBegin();
1250 while (i != global_keys.constEnd())
1252 QList<QTreeWidgetItem *> list =
1253 table->findItems( i.key(), Qt::MatchExactly|Qt::MatchWrap, ACTION_COL );
1254 if( list.count() >= 1 )
1256 QString keys = i.value();
1257 list[0]->setText( GLOBAL_HOTKEY_COL, keys );
1258 list[0]->setData( GLOBAL_HOTKEY_COL, Qt::UserRole, keys );
1260 if( list.count() >= 2 )
1261 msg_Dbg( p_this, "This is probably wrong, %s", qtu(i.key()) );
1266 module_config_free (p_config);
1268 table->resizeColumnToContents( 0 );
1270 CONNECT( table, itemActivated( QTreeWidgetItem *, int ),
1271 this, selectKey( QTreeWidgetItem *, int ) );
1274 void KeySelectorControl::filter( const QString &qs_search )
1276 int i_column = searchOption->itemData( searchOption->currentIndex() ).toInt();
1277 QList<QTreeWidgetItem *> resultList;
1278 if ( i_column == ANY_COL )
1280 for( int i = 0; i < ANY_COL; i++ )
1281 resultList << table->findItems( qs_search, Qt::MatchContains, i );
1285 resultList = table->findItems( qs_search, Qt::MatchContains, i_column );
1287 for( int i = 0; i < table->topLevelItemCount(); i++ )
1289 table->topLevelItem( i )->setHidden(
1290 !resultList.contains( table->topLevelItem( i ) ) );
1294 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1296 /* This happens when triggered by ClickEater */
1297 if( keyItem == NULL ) keyItem = table->currentItem();
1299 /* This can happen when nothing is selected on the treeView
1300 and the shortcutValue is clicked */
1301 if( !keyItem ) return;
1303 /* If clicked on the first column, assuming user wants the normal hotkey */
1304 if( column == ACTION_COL ) column = HOTKEY_COL;
1306 bool b_global = ( column == GLOBAL_HOTKEY_COL );
1308 /* Launch a small dialog to ask for a new key */
1309 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( ACTION_COL ),
1311 d->setExistingkeysSet( &existingkeys );
1314 if( d->result() == QDialog::Accepted )
1316 QString newKey = VLCKeyToString( d->keyValue );
1318 /* In case of conflict, reset other keys*/
1321 QTreeWidgetItem *it;
1322 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1324 it = table->topLevelItem(i);
1325 if( ( keyItem != it ) &&
1326 ( it->data( column, Qt::UserRole ).toString() == newKey ) )
1328 it->setText( column, NULL );
1329 it->setData( column, Qt::UserRole, QVariant() );
1334 keyItem->setText( column, newKey );
1335 keyItem->setData( column, Qt::UserRole, newKey );
1337 else if( d->result() == 2 )
1339 keyItem->setText( column, NULL );
1340 keyItem->setData( column, Qt::UserRole, QVariant() );
1346 void KeySelectorControl::doApply()
1348 QTreeWidgetItem *it;
1349 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1351 it = table->topLevelItem(i);
1352 if( it->data( HOTKEY_COL, Qt::UserRole ).toInt() >= 0 )
1353 config_PutPsz( p_this,
1354 qtu( it->data( ACTION_COL, Qt::UserRole ).toString() ),
1355 qtu( it->data( HOTKEY_COL, Qt::UserRole ).toString() ) );
1357 config_PutPsz( p_this,
1358 qtu( "global-" + it->data( ACTION_COL, Qt::UserRole ).toString() ),
1359 qtu( it->data( GLOBAL_HOTKEY_COL, Qt::UserRole ).toString() ) );
1363 bool KeySelectorControl::eventFilter( QObject *obj, QEvent *e )
1365 if( obj != table || e->type() != QEvent::KeyPress )
1366 return ConfigControl::eventFilter(obj, e);
1368 QKeyEvent *keyEv = static_cast<QKeyEvent*>(e);
1369 QTreeWidget *aTable = static_cast<QTreeWidget *>(obj);
1370 if( keyEv->key() == Qt::Key_Escape )
1372 aTable->clearFocus();
1375 else if( keyEv->key() == Qt::Key_Return ||
1376 keyEv->key() == Qt::Key_Enter )
1378 selectKey( aTable->currentItem(), aTable->currentColumn() );
1381 else if( keyEv->key() == Qt::Key_Delete )
1383 if( aTable->currentColumn() != ACTION_COL )
1385 aTable->currentItem()->setText( aTable->currentColumn(), NULL );
1386 aTable->currentItem()->setData( aTable->currentColumn(), Qt::UserRole, QVariant() );
1396 * Class KeyInputDialog
1398 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1399 const QString& keyToChange,
1402 QDialog( _parent ), keyValue(0), b_global( _b_global )
1406 existingkeys = NULL;
1409 setWindowTitle( ( b_global ? qtr( "Global" ) + QString(" ") : "" )
1410 + qtr( "Hotkey change" ) );
1411 setWindowRole( "vlc-key-input" );
1413 QVBoxLayout *vLayout = new QVBoxLayout( this );
1414 selected = new QLabel( qtr( "Press the new key or combination for " )
1415 + QString("<b>%1</b>").arg( keyToChange ) );
1416 vLayout->addWidget( selected , Qt::AlignCenter );
1418 warning = new QLabel;
1420 vLayout->insertWidget( 1, warning );
1422 QDialogButtonBox *buttonBox = new QDialogButtonBox;
1423 ok = new QPushButton( qtr("Assign") );
1424 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1425 unset = new QPushButton( qtr("Unset") );
1426 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1427 buttonBox->addButton( unset, QDialogButtonBox::ActionRole );
1428 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1429 ok->setDefault( true );
1431 vLayout->addWidget( buttonBox );
1434 CONNECT( buttonBox, accepted(), this, accept() );
1435 CONNECT( buttonBox, rejected(), this, reject() );
1436 BUTTONACT( unset, unsetAction() );
1439 void KeyInputDialog::setExistingkeysSet( const QSet<QString> *keyset )
1441 existingkeys = keyset;
1444 void KeyInputDialog::checkForConflicts( int i_vlckey, const QString &sequence )
1446 QList<QTreeWidgetItem *> conflictList =
1447 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1450 if( conflictList.count() &&
1451 !conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toString().isEmpty() &&
1452 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toString() != "Unset" )
1454 warning->setText( qtr("Warning: this key or combination is already assigned to ") +
1455 QString( "\"<b>%1</b>\"" ).arg( conflictList[0]->text( 0 ) ) );
1462 else if( existingkeys && !sequence.isEmpty()
1463 && existingkeys->contains( sequence ) )
1466 qtr( "Warning: <b>%1</b> is already an application menu shortcut" )
1478 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1480 if( e->key() == Qt::Key_Tab ||
1481 e->key() == Qt::Key_Shift ||
1482 e->key() == Qt::Key_Control ||
1483 e->key() == Qt::Key_Meta ||
1484 e->key() == Qt::Key_Alt ||
1485 e->key() == Qt::Key_AltGr )
1487 int i_vlck = qtEventToVLCKey( e );
1488 QKeySequence sequence( e->key() | e->modifiers() );
1489 selected->setText( qtr( "Key or combination: " )
1490 + QString("<b>%1</b>").arg( VLCKeyToString( i_vlck ) ) );
1491 checkForConflicts( i_vlck, sequence.toString() );
1495 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1497 int i_vlck = qtWheelEventToVLCKey( e );
1498 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1499 checkForConflicts( i_vlck, QString() );
1503 void KeyInputDialog::unsetAction() { done( 2 ); };