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 * - 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/searchlineedit.hpp"
40 #include "util/qt_dirs.hpp"
42 #include <vlc_intf_strings.h>
43 #include <vlc_modules.h>
47 #include <QGridLayout>
49 #include <QFileDialog>
51 #include <QTreeWidgetItem>
52 #include <QSignalMapper>
53 #include <QDialogButtonBox>
55 #include <QColorDialog>
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 ModuleConfigControl( p_this, p_item, parent, false,
89 case CONFIG_ITEM_MODULE_CAT:
90 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
93 case CONFIG_ITEM_MODULE_LIST:
94 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
97 case CONFIG_ITEM_MODULE_LIST_CAT:
98 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
101 case CONFIG_ITEM_STRING:
102 if( !p_item->i_list )
103 p_control = new StringConfigControl( p_this, p_item, parent,
106 p_control = new StringListConfigControl( p_this, p_item,
109 case CONFIG_ITEM_PASSWORD:
110 if( !p_item->i_list )
111 p_control = new StringConfigControl( p_this, p_item, parent,
114 p_control = new StringListConfigControl( p_this, p_item,
117 case CONFIG_ITEM_RGB:
118 p_control = new ColorConfigControl( p_this, p_item, parent, 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_LOADFILE:
132 case CONFIG_ITEM_SAVEFILE:
133 p_control = new FileConfigControl( p_this, p_item, parent, l, line);
135 case CONFIG_ITEM_DIRECTORY:
136 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
139 case CONFIG_ITEM_FONT:
140 p_control = new FontConfigControl( p_this, p_item, parent, l,
143 case CONFIG_ITEM_KEY:
144 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
146 case CONFIG_ITEM_BOOL:
147 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
149 case CONFIG_ITEM_FLOAT:
150 if( p_item->min.f || p_item->max.f )
151 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
154 p_control = new FloatConfigControl( p_this, p_item, parent,
163 /*******************************************************
165 *******************************************************/
166 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
168 setGeometry( 0, 0, 128, 100 );
169 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
172 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
174 setPreview( ( b_minimal ) ? MINIMAL : COMPLETE );
177 void InterfacePreviewWidget::setPreview( enum_style e_style )
179 QString pixmapLocationString(":/prefsmenu/");
185 pixmapLocationString += "sample_complete";
188 pixmapLocationString += "sample_minimal";
191 pixmapLocationString += "sample_skins";
195 setPixmap( QPixmap( pixmapLocationString ) );
200 /**************************************************************************
201 * String-based controls
202 *************************************************************************/
205 VStringConfigControl::doApply()
207 config_PutPsz( p_this, getName(), qtu( getValue() ) );
210 /*********** String **************/
211 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
212 module_config_t *_p_item,
213 QWidget *_parent, QGridLayout *l,
214 int line, bool pwd ) :
215 VStringConfigControl( _p_this, _p_item, _parent )
217 label = new QLabel( qtr(p_item->psz_text) );
218 text = new QLineEdit( qfu(p_item->value.psz) );
219 if( pwd ) text->setEchoMode( QLineEdit::Password );
224 QHBoxLayout *layout = new QHBoxLayout();
225 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
226 layout->addWidget( text, LAST_COLUMN );
227 widget->setLayout( layout );
231 l->addWidget( label, line, 0 );
232 l->setColumnMinimumWidth( 1, 10 );
233 l->addWidget( text, line, LAST_COLUMN );
237 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
238 module_config_t *_p_item,
239 QLabel *_label, QLineEdit *_text, bool pwd ):
240 VStringConfigControl( _p_this, _p_item )
243 if( pwd ) text->setEchoMode( QLineEdit::Password );
248 void StringConfigControl::finish()
250 text->setText( qfu(p_item->value.psz) );
251 if( p_item->psz_longtext )
253 QString tipText = qtr(p_item->psz_longtext);
254 text->setToolTip( formatTooltip(tipText) );
256 label->setToolTip( formatTooltip(tipText) );
259 label->setBuddy( text );
262 /*********** File **************/
263 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
264 module_config_t *_p_item,
265 QWidget *_parent, QGridLayout *l,
267 VStringConfigControl( _p_this, _p_item, _parent )
269 label = new QLabel( qtr(p_item->psz_text) );
270 text = new QLineEdit( qfu(p_item->value.psz) );
271 browse = new QPushButton( qtr( "Browse..." ) );
272 QHBoxLayout *textAndButton = new QHBoxLayout();
273 textAndButton->setMargin( 0 );
274 textAndButton->addWidget( text, 2 );
275 textAndButton->addWidget( browse, 0 );
277 BUTTONACT( browse, updateField() );
283 QHBoxLayout *layout = new QHBoxLayout();
284 layout->addWidget( label, 0 );
285 layout->insertSpacing( 1, 10 );
286 layout->addLayout( textAndButton, LAST_COLUMN );
287 widget->setLayout( layout );
291 l->addWidget( label, line, 0 );
292 l->setColumnMinimumWidth( 1, 10 );
293 l->addLayout( textAndButton, line, LAST_COLUMN );
298 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
299 module_config_t *_p_item,
300 QLabel *_label, QLineEdit *_text,
301 QPushButton *_button ):
302 VStringConfigControl( _p_this, _p_item )
308 BUTTONACT( browse, updateField() );
313 void FileConfigControl::updateField()
317 if (p_item->i_type == CONFIG_ITEM_SAVEFILE)
318 file = QFileDialog::getSaveFileName( NULL, qtr( "Save File" ),
319 QVLCUserDir( VLC_HOME_DIR ) );
321 file = QFileDialog::getOpenFileName( NULL, qtr( "Select File" ),
322 QVLCUserDir( VLC_HOME_DIR ) );
324 if( file.isNull() ) return;
325 text->setText( toNativeSeparators( file ) );
328 void FileConfigControl::finish()
330 text->setText( qfu(p_item->value.psz) );
331 if( p_item->psz_longtext )
333 QString tipText = qtr(p_item->psz_longtext);
334 text->setToolTip( formatTooltip(tipText) );
336 label->setToolTip( formatTooltip(tipText) );
339 label->setBuddy( text );
342 /********* String / Directory **********/
343 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
344 module_config_t *_p_item, QWidget *_p_widget,
345 QGridLayout *_p_layout, int _int ) :
346 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
349 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
350 module_config_t *_p_item, QLabel *_p_label,
351 QLineEdit *_p_line, QPushButton *_p_button ):
352 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
355 void DirectoryConfigControl::updateField()
357 QString dir = QFileDialog::getExistingDirectory( NULL,
359 text->text().isEmpty() ?
360 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
361 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
363 if( dir.isNull() ) return;
364 text->setText( toNativeSepNoSlash( dir ) );
367 /********* String / Font **********/
368 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
369 module_config_t *_p_item, QWidget *_parent,
370 QGridLayout *_p_layout, int line) :
371 VStringConfigControl( _p_this, _p_item, _parent )
373 label = new QLabel( qtr(p_item->psz_text) );
374 font = new QFontComboBox( _parent );
375 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
378 QHBoxLayout *layout = new QHBoxLayout();
379 layout->addWidget( label, 0 );
380 layout->addWidget( font, 1 );
381 widget->setLayout( layout );
385 _p_layout->addWidget( label, line, 0 );
386 _p_layout->addWidget( font, line, 1, 1, -1 );
389 if( p_item->psz_longtext )
391 label->setToolTip( formatTooltip( qtr(p_item->psz_longtext) ) );
395 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
396 module_config_t *_p_item, QLabel *_p_label,
397 QFontComboBox *_p_font):
398 VStringConfigControl( _p_this, _p_item)
402 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
404 if( p_item->psz_longtext )
406 label->setToolTip( formatTooltip( qtr(p_item->psz_longtext) ) );
410 /********* String / choice list **********/
411 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
412 module_config_t *_p_item, QWidget *_parent,
413 QGridLayout *l, int line) :
414 VStringConfigControl( _p_this, _p_item, _parent )
416 label = new QLabel( qtr(p_item->psz_text) );
417 combo = new QComboBox();
418 combo->setMinimumWidth( MINWIDTH_BOX );
419 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
421 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
423 finish( p_module_config );
426 l = new QGridLayout();
427 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
428 widget->setLayout( l );
432 l->addWidget( label, line, 0 );
433 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
436 if( p_item->i_action )
438 QSignalMapper *signalMapper = new QSignalMapper(this);
440 /* Some stringLists like Capture listings have action associated */
441 for( int i = 0; i < p_item->i_action; i++ )
443 QPushButton *button =
444 new QPushButton( qtr( p_item->ppsz_action_text[i] ));
445 CONNECT( button, clicked(), signalMapper, map() );
446 signalMapper->setMapping( button, i );
447 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
450 CONNECT( signalMapper, mapped( int ),
451 this, actionRequested( int ) );
455 void StringListConfigControl::actionRequested( int i_action )
457 /* Supplementary check for boundaries */
458 if( i_action < 0 || i_action >= p_item->i_action ) return;
460 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
461 if(!p_module_config) return;
464 val.psz_string = const_cast<char *>
465 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
467 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
469 if( p_module_config->b_dirty )
472 finish( p_module_config );
473 p_module_config->b_dirty = false;
476 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
477 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
478 bool ) : VStringConfigControl( _p_this, _p_item )
483 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
485 finish( p_module_config );
488 void StringListConfigControl::finish(module_config_t *p_module_config )
490 combo->setEditable( false );
492 if(!p_module_config) return;
494 if( p_module_config->pf_update_list )
497 val.psz_string = strdup(p_module_config->value.psz);
499 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
501 // assume in any case that dirty was set to true
502 // because lazy programmes will use the same callback for
503 // this, like the one behind the refresh push button?
504 p_module_config->b_dirty = false;
506 free( val.psz_string );
509 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
511 if( !p_module_config->ppsz_list[i_index] )
513 combo->addItem( "", QVariant(""));
514 if( !p_item->value.psz )
515 combo->setCurrentIndex( combo->count() - 1 );
518 combo->addItem( qfu((p_module_config->ppsz_list_text &&
519 p_module_config->ppsz_list_text[i_index])?
520 _(p_module_config->ppsz_list_text[i_index]) :
521 p_module_config->ppsz_list[i_index] ),
522 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
523 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
524 p_module_config->ppsz_list[i_index] ) )
525 combo->setCurrentIndex( combo->count() - 1 );
528 if( p_module_config->psz_longtext )
530 QString tipText = qtr(p_module_config->psz_longtext);
531 combo->setToolTip( formatTooltip(tipText) );
533 label->setToolTip( formatTooltip(tipText) );
536 label->setBuddy( combo );
539 QString StringListConfigControl::getValue() const
541 return combo->itemData( combo->currentIndex() ).toString();
544 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
547 module_config_t *p_config =
548 config_FindConfig( VLC_OBJECT(p_intf), configname );
552 bool string = (p_config->i_type & 0xF0) == CONFIG_ITEM_STRING;
555 def = QVariant( qfu(p_config->value.psz) );
557 def = QVariant( qlonglong( p_config->value.i ) );
559 if(p_config->pf_update_list)
562 val.i_int = p_config->value.i;
563 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
564 // assume in any case that dirty was set to true
565 // because lazy programmes will use the same callback for
566 // this, like the one behind the refresh push button?
567 p_config->b_dirty = false;
570 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
575 value = QVariant( qfu(p_config->ppsz_list[i_index]) );
577 value =QVariant( p_config->pi_list[i_index] );
578 combo->addItem( qtr(p_config->ppsz_list_text[i_index]), value );
580 combo->setCurrentIndex( i_index );
583 if( p_config->psz_longtext )
584 combo->setToolTip( qfu( p_config->psz_longtext ) );
588 /********* Module **********/
589 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
590 module_config_t *_p_item, QWidget *_parent, bool bycat,
591 QGridLayout *l, int line) :
592 VStringConfigControl( _p_this, _p_item, _parent )
594 label = new QLabel( qtr(p_item->psz_text) );
595 combo = new QComboBox();
596 combo->setMinimumWidth( MINWIDTH_BOX );
600 QHBoxLayout *layout = new QHBoxLayout();
601 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
602 widget->setLayout( layout );
606 l->addWidget( label, line, 0 );
607 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
611 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
612 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
613 bool bycat ) : VStringConfigControl( _p_this, _p_item )
620 void ModuleConfigControl::finish( bool bycat )
624 combo->setEditable( false );
626 /* build a list of available modules */
627 module_t **p_list = module_list_get( NULL );
628 combo->addItem( qtr("Default") );
629 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
633 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
636 module_config_t *p_config;
638 p_config = module_config_get (p_parser, &confsize);
639 for (size_t i = 0; i < confsize; i++)
641 /* Hack: required subcategory is stored in i_min */
642 const module_config_t *p_cfg = p_config + i;
643 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
644 p_cfg->value.i == p_item->min.i )
645 combo->addItem( qtr( module_GetLongName( p_parser )),
646 QVariant( module_get_object( p_parser ) ) );
647 if( p_item->value.psz && !strcmp( p_item->value.psz,
648 module_get_object( p_parser ) ) )
649 combo->setCurrentIndex( combo->count() - 1 );
651 module_config_free (p_config);
653 else if( module_provides( p_parser, p_item->psz_type ) )
655 combo->addItem( qtr(module_GetLongName( p_parser ) ),
656 QVariant( module_get_object( p_parser ) ) );
657 if( p_item->value.psz && !strcmp( p_item->value.psz,
658 module_get_object( p_parser ) ) )
659 combo->setCurrentIndex( combo->count() - 1 );
662 module_list_free( p_list );
664 if( p_item->psz_longtext )
666 QString tipText = qtr(p_item->psz_longtext);
667 combo->setToolTip( formatTooltip(tipText) );
669 label->setToolTip( formatTooltip(tipText) );
672 label->setBuddy( combo );
675 QString ModuleConfigControl::getValue() const
677 return combo->itemData( combo->currentIndex() ).toString();
680 /********* Module list **********/
681 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
682 module_config_t *_p_item, QWidget *_parent, bool bycat,
683 QGridLayout *l, int line) :
684 VStringConfigControl( _p_this, _p_item, _parent )
689 if( !p_item->psz_text ) return;
691 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
692 text = new QLineEdit;
693 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
698 foreach ( checkBoxListItem *it, modules )
700 layoutGroupBox->addWidget( it->checkBox, boxline / 2, boxline % 2 );
704 layoutGroupBox->addWidget( text, boxline, 0, 1, 2 );
708 QVBoxLayout *layout = new QVBoxLayout();
709 layout->addWidget( groupBox, line, 0 );
710 widget->setLayout( layout );
714 l->addWidget( groupBox, line, 0, 1, -1 );
717 if( p_item->psz_longtext )
718 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
721 ModuleListConfigControl::~ModuleListConfigControl()
723 qDeleteAll( modules );
728 #define CHECKBOX_LISTS \
730 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
731 checkBoxListItem *cbl = new checkBoxListItem; \
733 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
734 const char *help = module_get_help( p_parser ); \
736 cb->setToolTip( formatTooltip( qtr( help ) ) ); \
737 cbl->checkBox = cb; \
739 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
740 modules.append( cbl ); \
742 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
743 cbl->checkBox->setChecked( true ); \
747 void ModuleListConfigControl::finish( bool bycat )
751 /* build a list of available modules */
752 module_t **p_list = module_list_get( NULL );
753 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
757 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
760 module_config_t *p_config = module_config_get (p_parser, &confsize);
762 for (size_t i = 0; i < confsize; i++)
764 module_config_t *p_cfg = p_config + i;
765 /* Hack: required subcategory is stored in i_min */
766 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
767 p_cfg->value.i == p_item->min.i )
772 module_config_free (p_config);
774 else if( module_provides( p_parser, p_item->psz_type ) )
779 module_list_free( p_list );
781 if( p_item->psz_longtext )
783 QString tipText = qtr(p_item->psz_longtext);
785 text->setToolTip( formatTooltip(tipText) );
787 groupBox->setToolTip( formatTooltip(tipText) );
790 #undef CHECKBOX_LISTS
792 QString ModuleListConfigControl::getValue() const
798 void ModuleListConfigControl::hide()
800 foreach ( checkBoxListItem *it, modules )
801 it->checkBox->hide();
805 void ModuleListConfigControl::show()
807 foreach ( checkBoxListItem *it, modules )
808 it->checkBox->show();
813 void ModuleListConfigControl::onUpdate()
818 foreach ( checkBoxListItem *it, modules )
820 if( it->checkBox->isChecked() )
824 text->setText( text->text() + it->psz_module );
829 text->setText( text->text() + ":" + it->psz_module );
835 /**************************************************************************
836 * Integer-based controls
837 *************************************************************************/
840 VIntConfigControl::doApply()
842 config_PutInt( p_this, getName(), getValue() );
845 /*********** Integer **************/
846 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
847 module_config_t *_p_item,
848 QWidget *_parent, QGridLayout *l,
850 VIntConfigControl( _p_this, _p_item, _parent )
852 label = new QLabel( qtr(p_item->psz_text) );
853 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
854 spin->setAlignment( Qt::AlignRight );
855 spin->setMaximumWidth( MINWIDTH_BOX );
860 QHBoxLayout *layout = new QHBoxLayout();
861 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
862 widget->setLayout( layout );
866 l->addWidget( label, line, 0 );
867 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
870 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
871 module_config_t *_p_item,
872 QLabel *_label, QSpinBox *_spin ) :
873 VIntConfigControl( _p_this, _p_item )
880 void IntegerConfigControl::finish()
882 spin->setMaximum( 2000000000 );
883 spin->setMinimum( -2000000000 );
884 spin->setValue( p_item->value.i );
886 if( p_item->psz_longtext )
888 QString tipText = qtr(p_item->psz_longtext);
889 spin->setToolTip( formatTooltip(tipText) );
891 label->setToolTip( formatTooltip(tipText) );
894 label->setBuddy( spin );
897 int IntegerConfigControl::getValue() const
899 return spin->value();
902 /********* Integer range **********/
903 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
904 module_config_t *_p_item,
905 QWidget *_parent, QGridLayout *l,
907 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
912 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
913 module_config_t *_p_item,
914 QLabel *_label, QSpinBox *_spin ) :
915 IntegerConfigControl( _p_this, _p_item, _label, _spin )
920 void IntegerRangeConfigControl::finish()
922 spin->setMaximum( p_item->max.i );
923 spin->setMinimum( p_item->min.i );
926 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
927 vlc_object_t *_p_this,
928 module_config_t *_p_item,
929 QLabel *_label, QSlider *_slider ):
930 VIntConfigControl( _p_this, _p_item )
934 slider->setMaximum( p_item->max.i );
935 slider->setMinimum( p_item->min.i );
936 slider->setValue( p_item->value.i );
937 if( p_item->psz_longtext )
939 QString tipText = qtr(p_item->psz_longtext);
940 slider->setToolTip( formatTooltip(tipText) );
942 label->setToolTip( formatTooltip(tipText) );
945 label->setBuddy( slider );
948 int IntegerRangeSliderConfigControl::getValue() const
950 return slider->value();
954 /********* Integer / choice list **********/
955 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
956 module_config_t *_p_item, QWidget *_parent, bool,
957 QGridLayout *l, int line) :
958 VIntConfigControl( _p_this, _p_item, _parent )
960 label = new QLabel( qtr(p_item->psz_text) );
961 combo = new QComboBox();
962 combo->setMinimumWidth( MINWIDTH_BOX );
964 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
966 finish( p_module_config );
969 QHBoxLayout *layout = new QHBoxLayout();
970 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
971 widget->setLayout( layout );
975 l->addWidget( label, line, 0 );
976 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
979 if( p_item->i_action )
981 QSignalMapper *signalMapper = new QSignalMapper(this);
983 /* Some stringLists like Capture listings have action associated */
984 for( int i = 0; i < p_item->i_action; i++ )
986 QPushButton *button =
987 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
988 CONNECT( button, clicked(), signalMapper, map() );
989 signalMapper->setMapping( button, i );
990 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
993 CONNECT( signalMapper, mapped( int ),
994 this, actionRequested( int ) );
998 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
999 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
1000 bool ) : VIntConfigControl( _p_this, _p_item )
1005 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1007 finish( p_module_config );
1010 void IntegerListConfigControl::finish(module_config_t *p_module_config )
1012 combo->setEditable( false );
1014 if(!p_module_config) return;
1016 if( p_module_config->pf_update_list )
1019 val.i_int = p_module_config->value.i;
1021 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
1023 // assume in any case that dirty was set to true
1024 // because lazy programmes will use the same callback for
1025 // this, like the one behind the refresh push button?
1026 p_module_config->b_dirty = false;
1029 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
1031 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
1032 QVariant( p_module_config->pi_list[i_index] ) );
1033 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
1034 combo->setCurrentIndex( combo->count() - 1 );
1036 if( p_item->psz_longtext )
1038 QString tipText = qtr(p_item->psz_longtext );
1039 combo->setToolTip( formatTooltip(tipText) );
1041 label->setToolTip( formatTooltip(tipText) );
1044 label->setBuddy( combo );
1047 void IntegerListConfigControl::actionRequested( int i_action )
1049 /* Supplementary check for boundaries */
1050 if( i_action < 0 || i_action >= p_item->i_action ) return;
1052 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1053 if(!p_module_config) return;
1057 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
1059 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
1061 if( p_module_config->b_dirty )
1064 finish( p_module_config );
1065 p_module_config->b_dirty = false;
1069 int IntegerListConfigControl::getValue() const
1071 return combo->itemData( combo->currentIndex() ).toInt();
1074 /*********** Boolean **************/
1075 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1076 module_config_t *_p_item,
1077 QWidget *_parent, QGridLayout *l,
1079 VIntConfigControl( _p_this, _p_item, _parent )
1081 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1086 QHBoxLayout *layout = new QHBoxLayout();
1087 layout->addWidget( checkbox, 0 );
1088 widget->setLayout( layout );
1092 l->addWidget( checkbox, line, 0 );
1096 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1097 module_config_t *_p_item,
1099 QAbstractButton *_checkbox ) :
1100 VIntConfigControl( _p_this, _p_item )
1102 checkbox = _checkbox;
1103 VLC_UNUSED( _label );
1107 void BoolConfigControl::finish()
1109 checkbox->setChecked( p_item->value.i );
1110 if( p_item->psz_longtext )
1111 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1114 int BoolConfigControl::getValue() const
1116 return checkbox->isChecked();
1119 /************* Color *************/
1120 ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
1121 module_config_t *_p_item,
1122 QWidget *_parent, QGridLayout *l,
1124 VIntConfigControl( _p_this, _p_item, _parent )
1127 color_but = new QToolButton;
1132 QHBoxLayout *layout = new QHBoxLayout();
1133 layout->addWidget( label, 0 ); layout->addWidget( color_but, LAST_COLUMN );
1134 widget->setLayout( layout );
1138 l->addWidget( label, line, 0 );
1139 l->addWidget( color_but, line, LAST_COLUMN, Qt::AlignRight );
1143 ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
1144 module_config_t *_p_item,
1145 QLabel *_label, QAbstractButton *_color ):
1146 VIntConfigControl( _p_this, _p_item )
1153 void ColorConfigControl::finish()
1155 i_color = p_item->value.i;
1157 color_px = new QPixmap( 34, 20 );
1158 color_px->fill( QColor( i_color ) );
1159 color_but->setIcon( QIcon( *color_px ) );
1160 color_but->setMinimumWidth( 40 );
1162 label->setText( qtr(p_item->psz_text) );
1163 if( p_item->psz_longtext )
1165 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1166 color_but->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1169 BUTTONACT( color_but, selectColor() );
1172 int ColorConfigControl::getValue() const
1177 void ColorConfigControl::selectColor()
1179 QColor color = QColorDialog::getColor( QColor( i_color ) );
1180 i_color = (color.red() << 16) + (color.green() << 8) + color.blue();
1182 color_px->fill( QColor( i_color ) );
1183 color_but->setIcon( QIcon( *color_px ) );
1187 /**************************************************************************
1188 * Float-based controls
1189 *************************************************************************/
1192 VFloatConfigControl::doApply()
1194 config_PutFloat( p_this, getName(), getValue() );
1197 /*********** Float **************/
1198 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1199 module_config_t *_p_item,
1200 QWidget *_parent, QGridLayout *l,
1202 VFloatConfigControl( _p_this, _p_item, _parent )
1204 label = new QLabel( qtr(p_item->psz_text) );
1205 spin = new QDoubleSpinBox;
1206 spin->setMinimumWidth( MINWIDTH_BOX );
1207 spin->setMaximumWidth( MINWIDTH_BOX );
1208 spin->setAlignment( Qt::AlignRight );
1213 QHBoxLayout *layout = new QHBoxLayout();
1214 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1215 widget->setLayout( layout );
1219 l->addWidget( label, line, 0 );
1220 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1224 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1225 module_config_t *_p_item,
1227 QDoubleSpinBox *_spin ) :
1228 VFloatConfigControl( _p_this, _p_item )
1235 void FloatConfigControl::finish()
1237 spin->setMaximum( 2000000000. );
1238 spin->setMinimum( -2000000000. );
1239 spin->setSingleStep( 0.1 );
1240 spin->setValue( (double)p_item->value.f );
1241 if( p_item->psz_longtext )
1243 QString tipText = qtr(p_item->psz_longtext);
1244 spin->setToolTip( formatTooltip(tipText) );
1246 label->setToolTip( formatTooltip(tipText) );
1249 label->setBuddy( spin );
1252 float FloatConfigControl::getValue() const
1254 return (float)spin->value();
1257 /*********** Float with range **************/
1258 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1259 module_config_t *_p_item,
1260 QWidget *_parent, QGridLayout *l,
1262 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1267 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1268 module_config_t *_p_item,
1270 QDoubleSpinBox *_spin ) :
1271 FloatConfigControl( _p_this, _p_item, _label, _spin )
1276 void FloatRangeConfigControl::finish()
1278 spin->setMaximum( (double)p_item->max.f );
1279 spin->setMinimum( (double)p_item->min.f );
1283 /**********************************************************************
1284 * Key selector widget
1285 **********************************************************************/
1286 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1287 module_config_t *_p_item,
1288 QWidget *_parent, QGridLayout *l,
1290 ConfigControl( _p_this, _p_item, _parent )
1293 QWidget *keyContainer = new QWidget;
1294 QGridLayout *gLayout = new QGridLayout( keyContainer );
1297 qtr( "Select an action to change the associated hotkey") );
1299 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1300 actionSearch = new SearchLineEdit( keyContainer );
1302 table = new QTreeWidget;
1303 table->setColumnCount(3);
1304 table->headerItem()->setText( 0, qtr( "Action" ) );
1305 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1306 table->headerItem()->setText( 2, qtr( "Global" ) );
1307 table->setAlternatingRowColors( true );
1308 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1310 shortcutValue = new KeyShortcutEdit;
1311 shortcutValue->setReadOnly(true);
1313 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1314 QPushButton *setButton = new QPushButton( qtr( "Apply" ) );
1315 setButton->setDefault( true );
1318 gLayout->addWidget( label, 0, 0, 1, 4 );
1319 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1320 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1321 gLayout->addWidget( table, 2, 0, 1, 4 );
1322 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1323 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1324 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1326 l->addWidget( keyContainer, line, 0, 1, -1 );
1328 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1329 CONNECT( clearButton, clicked(), this, setTheKey() );
1330 BUTTONACT( setButton, setTheKey() );
1331 CONNECT( actionSearch, textChanged( const QString& ),
1332 this, filter( const QString& ) );
1335 void KeySelectorControl::finish()
1337 if( label && p_item->psz_longtext )
1338 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1340 /* Fill the table */
1342 /* Get the main Module */
1343 module_t *p_main = module_get_main();
1346 /* Access to the module_config_t */
1348 module_config_t *p_config;
1350 p_config = module_config_get (p_main, &confsize);
1352 for (size_t i = 0; i < confsize; i++)
1354 module_config_t *p_item = p_config + i;
1356 /* If we are a (non-global) key option not empty */
1357 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1358 && !strncmp( p_item->psz_name , "key-", 4 )
1359 && !EMPTY_STR( p_item->psz_text ) )
1363 - QString text in column 0
1364 - QString name in data of column 0
1365 - KeyValue in String in column 1
1367 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1368 treeItem->setText( 0, qtr( p_item->psz_text ) );
1369 treeItem->setData( 0, Qt::UserRole,
1370 QVariant( qfu( p_item->psz_name ) ) );
1372 QString keys = qfu( p_item->value.psz );
1373 treeItem->setText( 1, keys );
1374 treeItem->setData( 1, Qt::UserRole, QVariant( keys ) );
1375 table->addTopLevelItem( treeItem );
1379 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1380 && !strncmp( p_item->psz_name , "global-key", 10 )
1381 && !EMPTY_STR( p_item->psz_text ) )
1383 QList<QTreeWidgetItem *> list =
1384 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1385 if( list.count() >= 1 )
1387 QString keys = qfu( p_item->value.psz );
1388 list[0]->setText( 2, keys );
1389 list[0]->setData( 2, Qt::UserRole, keys );
1391 if( list.count() >= 2 )
1392 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1395 module_config_free (p_config);
1397 table->resizeColumnToContents( 0 );
1399 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1400 this, selectKey( QTreeWidgetItem *, int ) );
1401 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1402 this, select( QTreeWidgetItem *, int) );
1403 CONNECT( table, itemSelectionChanged(),
1404 this, select1Key() );
1406 CONNECT( shortcutValue, pressed(), this, selectKey() );
1409 void KeySelectorControl::filter( const QString &qs_search )
1411 QList<QTreeWidgetItem *> resultList =
1412 table->findItems( qs_search, Qt::MatchContains, 0 );
1413 for( int i = 0; i < table->topLevelItemCount(); i++ )
1415 table->topLevelItem( i )->setHidden(
1416 !resultList.contains( table->topLevelItem( i ) ) );
1420 void KeySelectorControl::select( QTreeWidgetItem *, int column )
1422 shortcutValue->setGlobal( column == 2 );
1425 /* Show the key selected from the table in the keySelector */
1426 void KeySelectorControl::select1Key()
1428 QTreeWidgetItem *keyItem = table->currentItem();
1429 shortcutValue->setText( keyItem->text( 1 ) );
1430 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toString() );
1431 shortcutValue->setGlobal( false );
1434 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1436 /* This happens when triggered by ClickEater */
1437 if( keyItem == NULL ) keyItem = table->currentItem();
1439 /* This can happen when nothing is selected on the treeView
1440 and the shortcutValue is clicked */
1441 if( !keyItem ) return;
1443 /* If clicked on the first column, assuming user wants the normal hotkey */
1444 if( column == 0 ) column = 1;
1446 bool b_global = ( column == 2 );
1448 /* Launch a small dialog to ask for a new key */
1449 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1452 if( d->result() == QDialog::Accepted )
1454 QString newKey = VLCKeyToString( d->keyValue );
1455 shortcutValue->setText( newKey );
1456 shortcutValue->setValue( newKey );
1457 shortcutValue->setGlobal( b_global );
1461 QTreeWidgetItem *it;
1462 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1464 it = table->topLevelItem(i);
1465 if( ( keyItem != it ) &&
1466 ( it->data( 1 + b_global, Qt::UserRole ).toString() == newKey ) )
1468 it->setData( 1 + b_global, Qt::UserRole,
1469 QVariant( qfu( "Unset" ) ) );
1470 it->setText( 1 + b_global, qtr( "Unset" ) );
1473 /* We already made an OK once. */
1480 void KeySelectorControl::setTheKey()
1482 if( !table->currentItem() ) return;
1483 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1484 shortcutValue->text() );
1485 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1486 Qt::UserRole, shortcutValue->getValue() );
1489 void KeySelectorControl::doApply()
1491 QTreeWidgetItem *it;
1492 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1494 it = table->topLevelItem(i);
1495 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1496 config_PutPsz( p_this,
1497 qtu( it->data( 0, Qt::UserRole ).toString() ),
1498 qtu( it->data( 1, Qt::UserRole ).toString() ) );
1499 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1500 config_PutPsz( p_this,
1501 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1502 qtu( it->data( 2, Qt::UserRole ).toString() ) );
1508 * Class KeyInputDialog
1510 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1511 const QString& keyToChange,
1514 QDialog( _parent ), keyValue(0), b_global( _b_global )
1520 setWindowTitle( b_global ? qtr( "Global" ): ""
1521 + qtr( "Hotkey for " ) + keyToChange );
1522 setWindowRole( "vlc-key-input" );
1524 vLayout = new QVBoxLayout( this );
1525 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1526 vLayout->addWidget( selected , Qt::AlignCenter );
1528 warning = new QLabel;
1530 vLayout->insertWidget( 1, warning );
1532 buttonBox = new QDialogButtonBox;
1533 QPushButton *ok = new QPushButton( qtr("OK") );
1534 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1535 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1536 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1537 ok->setDefault( true );
1539 vLayout->addWidget( buttonBox );
1542 CONNECT( buttonBox, accepted(), this, accept() );
1543 CONNECT( buttonBox, rejected(), this, reject() );
1546 void KeyInputDialog::checkForConflicts( int i_vlckey )
1548 QList<QTreeWidgetItem *> conflictList =
1549 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1552 if( conflictList.count() &&
1553 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1554 /* Avoid 0 or -1 that are the "Unset" states */
1556 warning->setText( qtr("Warning: the key is already assigned to \"") +
1557 conflictList[0]->text( 0 ) + "\"" );
1566 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1568 if( e->key() == Qt::Key_Tab ||
1569 e->key() == Qt::Key_Shift ||
1570 e->key() == Qt::Key_Control ||
1571 e->key() == Qt::Key_Meta ||
1572 e->key() == Qt::Key_Alt ||
1573 e->key() == Qt::Key_AltGr )
1575 int i_vlck = qtEventToVLCKey( e );
1576 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1577 checkForConflicts( i_vlck );
1581 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1583 int i_vlck = qtWheelEventToVLCKey( e );
1584 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1585 checkForConflicts( i_vlck );
1589 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)