1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * - Finish implementation (see WX, there might be missing a
29 * i_action handler for IntegerLists, but I don't see any module using it...
30 * - Improvements over WX
31 * - Validator for modulelist
37 #include "components/preferences_widgets.hpp"
38 #include "util/customwidgets.hpp"
39 #include "util/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>
56 #define MINWIDTH_BOX 90
57 #define LAST_COLUMN 10
59 QString formatTooltip(const QString & tooltip)
62 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
63 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
64 "<body style=\" font-family:'Sans Serif'; "
65 "font-style:normal; text-decoration:none;\">"
66 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
67 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
73 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
74 module_config_t *p_item,
76 QGridLayout *l, int line )
78 ConfigControl *p_control = NULL;
80 switch( p_item->i_type )
82 case CONFIG_ITEM_MODULE:
83 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
86 case CONFIG_ITEM_MODULE_CAT:
87 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
90 case CONFIG_ITEM_MODULE_LIST:
91 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,
98 case CONFIG_ITEM_STRING:
100 p_control = new StringConfigControl( p_this, p_item, parent,
103 p_control = new StringListConfigControl( p_this, p_item,
106 case CONFIG_ITEM_PASSWORD:
107 if( !p_item->i_list )
108 p_control = new StringConfigControl( p_this, p_item, parent,
111 p_control = new StringListConfigControl( p_this, p_item,
114 case CONFIG_ITEM_INTEGER:
116 p_control = new IntegerListConfigControl( p_this, p_item,
117 parent, false, l, line );
118 else if( p_item->min.i || p_item->max.i )
119 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
122 p_control = new IntegerConfigControl( p_this, p_item, parent,
125 case CONFIG_ITEM_LOADFILE:
126 case CONFIG_ITEM_SAVEFILE:
127 p_control = new FileConfigControl( p_this, p_item, parent, l, line);
129 case CONFIG_ITEM_DIRECTORY:
130 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
133 case CONFIG_ITEM_FONT:
134 p_control = new FontConfigControl( p_this, p_item, parent, l,
137 case CONFIG_ITEM_KEY:
138 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
140 case CONFIG_ITEM_BOOL:
141 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
143 case CONFIG_ITEM_FLOAT:
144 if( p_item->min.f || p_item->max.f )
145 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
148 p_control = new FloatConfigControl( p_this, p_item, parent,
157 /*******************************************************
159 *******************************************************/
160 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
162 setGeometry( 0, 0, 128, 100 );
163 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
166 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
168 setPreview( ( b_minimal )?MINIMAL:COMPLETE );
171 void InterfacePreviewWidget::setPreview( enum_style e_style )
173 QString pixmapLocationString(":/prefsmenu/");
179 pixmapLocationString += "sample_complete";
182 pixmapLocationString += "sample_minimal";
185 pixmapLocationString += "sample_skins";
189 setPixmap( QPixmap( pixmapLocationString ) );
195 /**************************************************************************
196 * String-based controls
197 *************************************************************************/
200 VStringConfigControl::doApply()
202 config_PutPsz( p_this, getName(), qtu( getValue() ) );
205 /*********** String **************/
206 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
207 module_config_t *_p_item,
208 QWidget *_parent, QGridLayout *l,
209 int line, bool pwd ) :
210 VStringConfigControl( _p_this, _p_item, _parent )
212 label = new QLabel( qtr(p_item->psz_text) );
213 text = new QLineEdit( qfu(p_item->value.psz) );
214 if( pwd ) text->setEchoMode( QLineEdit::Password );
219 QHBoxLayout *layout = new QHBoxLayout();
220 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
221 layout->addWidget( text, LAST_COLUMN );
222 widget->setLayout( layout );
226 l->addWidget( label, line, 0 );
227 l->setColumnMinimumWidth( 1, 10 );
228 l->addWidget( text, line, LAST_COLUMN );
232 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
233 module_config_t *_p_item,
234 QLabel *_label, QLineEdit *_text, bool pwd ):
235 VStringConfigControl( _p_this, _p_item )
238 if( pwd ) text->setEchoMode( QLineEdit::Password );
243 void StringConfigControl::finish()
245 text->setText( qfu(p_item->value.psz) );
246 if( p_item->psz_longtext )
248 QString tipText = qtr(p_item->psz_longtext);
249 text->setToolTip( formatTooltip(tipText) );
251 label->setToolTip( formatTooltip(tipText) );
254 label->setBuddy( text );
257 /*********** File **************/
258 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
259 module_config_t *_p_item,
260 QWidget *_parent, QGridLayout *l,
262 VStringConfigControl( _p_this, _p_item, _parent )
264 label = new QLabel( qtr(p_item->psz_text) );
265 text = new QLineEdit( qfu(p_item->value.psz) );
266 browse = new QPushButton( qtr( "Browse..." ) );
267 QHBoxLayout *textAndButton = new QHBoxLayout();
268 textAndButton->setMargin( 0 );
269 textAndButton->addWidget( text, 2 );
270 textAndButton->addWidget( browse, 0 );
272 BUTTONACT( browse, updateField() );
278 QHBoxLayout *layout = new QHBoxLayout();
279 layout->addWidget( label, 0 );
280 layout->insertSpacing( 1, 10 );
281 layout->addLayout( textAndButton, LAST_COLUMN );
282 widget->setLayout( layout );
286 l->addWidget( label, line, 0 );
287 l->setColumnMinimumWidth( 1, 10 );
288 l->addLayout( textAndButton, line, LAST_COLUMN );
293 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
294 module_config_t *_p_item,
295 QLabel *_label, QLineEdit *_text,
296 QPushButton *_button ):
297 VStringConfigControl( _p_this, _p_item )
303 BUTTONACT( browse, updateField() );
308 void FileConfigControl::updateField()
312 if (p_item->i_type == CONFIG_ITEM_SAVEFILE)
313 file = QFileDialog::getSaveFileName( NULL, qtr( "Save File" ),
314 QVLCUserDir( VLC_HOME_DIR ) );
316 file = QFileDialog::getOpenFileName( NULL, qtr( "Select File" ),
317 QVLCUserDir( VLC_HOME_DIR ) );
319 if( file.isNull() ) return;
320 text->setText( toNativeSeparators( file ) );
323 void FileConfigControl::finish()
325 text->setText( qfu(p_item->value.psz) );
326 if( p_item->psz_longtext )
328 QString tipText = qtr(p_item->psz_longtext);
329 text->setToolTip( formatTooltip(tipText) );
331 label->setToolTip( formatTooltip(tipText) );
334 label->setBuddy( text );
337 /********* String / Directory **********/
338 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
339 module_config_t *_p_item, QWidget *_p_widget,
340 QGridLayout *_p_layout, int _int ) :
341 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
344 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
345 module_config_t *_p_item, QLabel *_p_label,
346 QLineEdit *_p_line, QPushButton *_p_button ):
347 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
350 void DirectoryConfigControl::updateField()
352 QString dir = QFileDialog::getExistingDirectory( NULL,
354 text->text().isEmpty() ?
355 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
356 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
358 if( dir.isNull() ) return;
359 text->setText( toNativeSepNoSlash( dir ) );
362 /********* String / Font **********/
363 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
364 module_config_t *_p_item, QWidget *_parent,
365 QGridLayout *_p_layout, int line) :
366 VStringConfigControl( _p_this, _p_item, _parent )
368 label = new QLabel( qtr(p_item->psz_text) );
369 font = new QFontComboBox( _parent );
370 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
373 QHBoxLayout *layout = new QHBoxLayout();
374 layout->addWidget( label, 0 );
375 layout->addWidget( font, 1 );
376 widget->setLayout( layout );
380 _p_layout->addWidget( label, line, 0 );
381 _p_layout->addWidget( font, line, 1, 1, -1 );
385 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
386 module_config_t *_p_item, QLabel *_p_label,
387 QFontComboBox *_p_font):
388 VStringConfigControl( _p_this, _p_item)
392 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
395 /********* String / choice list **********/
396 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
397 module_config_t *_p_item, QWidget *_parent,
398 QGridLayout *l, int line) :
399 VStringConfigControl( _p_this, _p_item, _parent )
401 label = new QLabel( qtr(p_item->psz_text) );
402 combo = new QComboBox();
403 combo->setMinimumWidth( MINWIDTH_BOX );
404 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
406 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
408 finish( p_module_config );
411 l = new QGridLayout();
412 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
413 widget->setLayout( l );
417 l->addWidget( label, line, 0 );
418 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
421 if( p_item->i_action )
423 QSignalMapper *signalMapper = new QSignalMapper(this);
425 /* Some stringLists like Capture listings have action associated */
426 for( int i = 0; i < p_item->i_action; i++ )
428 QPushButton *button =
429 new QPushButton( qtr( p_item->ppsz_action_text[i] ));
430 CONNECT( button, clicked(), signalMapper, map() );
431 signalMapper->setMapping( button, i );
432 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
435 CONNECT( signalMapper, mapped( int ),
436 this, actionRequested( int ) );
440 void StringListConfigControl::actionRequested( int i_action )
442 /* Supplementary check for boundaries */
443 if( i_action < 0 || i_action >= p_item->i_action ) return;
445 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
446 if(!p_module_config) return;
449 val.psz_string = const_cast<char *>
450 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
452 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
454 if( p_module_config->b_dirty )
457 finish( p_module_config );
458 p_module_config->b_dirty = false;
461 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
462 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
463 bool ) : VStringConfigControl( _p_this, _p_item )
468 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
470 finish( p_module_config );
473 void StringListConfigControl::finish(module_config_t *p_module_config )
475 combo->setEditable( false );
477 if(!p_module_config) return;
479 if( p_module_config->pf_update_list )
482 val.psz_string = strdup(p_module_config->value.psz);
484 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
486 // assume in any case that dirty was set to true
487 // because lazy programmes will use the same callback for
488 // this, like the one behind the refresh push button?
489 p_module_config->b_dirty = false;
491 free( val.psz_string );
494 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
496 if( !p_module_config->ppsz_list[i_index] )
498 combo->addItem( "", QVariant(""));
499 if( !p_item->value.psz )
500 combo->setCurrentIndex( combo->count() - 1 );
503 combo->addItem( qfu((p_module_config->ppsz_list_text &&
504 p_module_config->ppsz_list_text[i_index])?
505 _(p_module_config->ppsz_list_text[i_index]) :
506 p_module_config->ppsz_list[i_index] ),
507 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
508 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
509 p_module_config->ppsz_list[i_index] ) )
510 combo->setCurrentIndex( combo->count() - 1 );
513 if( p_module_config->psz_longtext )
515 QString tipText = qtr(p_module_config->psz_longtext);
516 combo->setToolTip( formatTooltip(tipText) );
518 label->setToolTip( formatTooltip(tipText) );
521 label->setBuddy( combo );
524 QString StringListConfigControl::getValue() const
526 return combo->itemData( combo->currentIndex() ).toString();
529 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
532 module_config_t *p_config =
533 config_FindConfig( VLC_OBJECT(p_intf), configname );
536 if(p_config->pf_update_list)
539 val.i_int = p_config->value.i;
540 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
541 // assume in any case that dirty was set to true
542 // because lazy programmes will use the same callback for
543 // this, like the one behind the refresh push button?
544 p_config->b_dirty = false;
547 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
549 combo->addItem( qtr(p_config->ppsz_list_text[i_index]),
550 QVariant( p_config->pi_list[i_index] ) );
551 if( p_config->value.i == p_config->pi_list[i_index] )
553 combo->setCurrentIndex( i_index );
557 if( p_config->psz_longtext )
558 combo->setToolTip( qfu( p_config->psz_longtext ) );
562 /********* Module **********/
563 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
564 module_config_t *_p_item, QWidget *_parent, bool bycat,
565 QGridLayout *l, int line) :
566 VStringConfigControl( _p_this, _p_item, _parent )
568 label = new QLabel( qtr(p_item->psz_text) );
569 combo = new QComboBox();
570 combo->setMinimumWidth( MINWIDTH_BOX );
574 QHBoxLayout *layout = new QHBoxLayout();
575 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
576 widget->setLayout( layout );
580 l->addWidget( label, line, 0 );
581 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
585 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
586 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
587 bool bycat ) : VStringConfigControl( _p_this, _p_item )
594 void ModuleConfigControl::finish( bool bycat )
598 combo->setEditable( false );
600 /* build a list of available modules */
601 module_t **p_list = module_list_get( NULL );
602 combo->addItem( qtr("Default") );
603 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
607 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
610 module_config_t *p_config;
612 p_config = module_config_get (p_parser, &confsize);
613 for (size_t i = 0; i < confsize; i++)
615 /* Hack: required subcategory is stored in i_min */
616 const module_config_t *p_cfg = p_config + i;
617 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
618 p_cfg->value.i == p_item->min.i )
619 combo->addItem( qtr( module_GetLongName( p_parser )),
620 QVariant( module_get_object( p_parser ) ) );
621 if( p_item->value.psz && !strcmp( p_item->value.psz,
622 module_get_object( p_parser ) ) )
623 combo->setCurrentIndex( combo->count() - 1 );
625 module_config_free (p_config);
627 else if( module_provides( p_parser, p_item->psz_type ) )
629 combo->addItem( qtr(module_GetLongName( p_parser ) ),
630 QVariant( module_get_object( p_parser ) ) );
631 if( p_item->value.psz && !strcmp( p_item->value.psz,
632 module_get_object( p_parser ) ) )
633 combo->setCurrentIndex( combo->count() - 1 );
636 module_list_free( p_list );
638 if( p_item->psz_longtext )
640 QString tipText = qtr(p_item->psz_longtext);
641 combo->setToolTip( formatTooltip(tipText) );
643 label->setToolTip( formatTooltip(tipText) );
646 label->setBuddy( combo );
649 QString ModuleConfigControl::getValue() const
651 return combo->itemData( combo->currentIndex() ).toString();
654 /********* Module list **********/
655 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
656 module_config_t *_p_item, QWidget *_parent, bool bycat,
657 QGridLayout *l, int line) :
658 VStringConfigControl( _p_this, _p_item, _parent )
662 if( !p_item->psz_text ) return;
664 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
665 text = new QLineEdit;
666 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
671 foreach ( checkBoxListItem *it, modules )
672 layoutGroupBox->addWidget( it->checkBox, boxline++, 0 );
673 layoutGroupBox->addWidget( text, boxline, 0 );
677 QVBoxLayout *layout = new QVBoxLayout();
678 layout->addWidget( groupBox, line, 0 );
679 widget->setLayout( layout );
683 l->addWidget( groupBox, line, 0, 1, -1 );
686 if( p_item->psz_longtext )
687 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
690 ModuleListConfigControl::~ModuleListConfigControl()
692 qDeleteAll( modules );
697 #define CHECKBOX_LISTS \
699 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
700 checkBoxListItem *cbl = new checkBoxListItem; \
702 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
703 const char *help = module_get_help( p_parser ); \
705 cb->setToolTip( formatTooltip( qtr( help ) ) ); \
706 cbl->checkBox = cb; \
708 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
709 modules.push_back( cbl ); \
711 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
712 cbl->checkBox->setChecked( true ); \
716 void ModuleListConfigControl::finish( bool bycat )
720 /* build a list of available modules */
721 module_t **p_list = module_list_get( NULL );
722 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
726 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
729 module_config_t *p_config = module_config_get (p_parser, &confsize);
731 for (size_t i = 0; i < confsize; i++)
733 module_config_t *p_cfg = p_config + i;
734 /* Hack: required subcategory is stored in i_min */
735 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
736 p_cfg->value.i == p_item->min.i )
741 module_config_free (p_config);
743 else if( module_provides( p_parser, p_item->psz_type ) )
748 module_list_free( p_list );
750 if( p_item->psz_longtext )
752 QString tipText = qtr(p_item->psz_longtext);
754 text->setToolTip( formatTooltip(tipText) );
756 groupBox->setToolTip( formatTooltip(tipText) );
759 #undef CHECKBOX_LISTS
761 QString ModuleListConfigControl::getValue() const
767 void ModuleListConfigControl::hide()
769 foreach ( checkBoxListItem *it, modules )
770 it->checkBox->hide();
774 void ModuleListConfigControl::show()
776 foreach ( checkBoxListItem *it, modules )
777 it->checkBox->show();
782 void ModuleListConfigControl::onUpdate()
787 foreach ( checkBoxListItem *it, modules )
789 if( it->checkBox->isChecked() )
793 text->setText( text->text() + it->psz_module );
798 text->setText( text->text() + ":" + it->psz_module );
804 /**************************************************************************
805 * Integer-based controls
806 *************************************************************************/
809 VIntConfigControl::doApply()
811 config_PutInt( p_this, getName(), getValue() );
814 /*********** Integer **************/
815 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
816 module_config_t *_p_item,
817 QWidget *_parent, QGridLayout *l,
819 VIntConfigControl( _p_this, _p_item, _parent )
821 label = new QLabel( qtr(p_item->psz_text) );
822 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
823 spin->setAlignment( Qt::AlignRight );
824 spin->setMaximumWidth( MINWIDTH_BOX );
829 QHBoxLayout *layout = new QHBoxLayout();
830 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
831 widget->setLayout( layout );
835 l->addWidget( label, line, 0 );
836 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
839 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
840 module_config_t *_p_item,
841 QLabel *_label, QSpinBox *_spin ) :
842 VIntConfigControl( _p_this, _p_item )
849 void IntegerConfigControl::finish()
851 spin->setMaximum( 2000000000 );
852 spin->setMinimum( -2000000000 );
853 spin->setValue( p_item->value.i );
855 if( p_item->psz_longtext )
857 QString tipText = qtr(p_item->psz_longtext);
858 spin->setToolTip( formatTooltip(tipText) );
860 label->setToolTip( formatTooltip(tipText) );
863 label->setBuddy( spin );
866 int IntegerConfigControl::getValue() const
868 return spin->value();
871 /********* Integer range **********/
872 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
873 module_config_t *_p_item,
874 QWidget *_parent, QGridLayout *l,
876 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
881 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
882 module_config_t *_p_item,
883 QLabel *_label, QSpinBox *_spin ) :
884 IntegerConfigControl( _p_this, _p_item, _label, _spin )
889 void IntegerRangeConfigControl::finish()
891 spin->setMaximum( p_item->max.i );
892 spin->setMinimum( p_item->min.i );
895 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
896 vlc_object_t *_p_this,
897 module_config_t *_p_item,
898 QLabel *_label, QSlider *_slider ):
899 VIntConfigControl( _p_this, _p_item )
903 slider->setMaximum( p_item->max.i );
904 slider->setMinimum( p_item->min.i );
905 slider->setValue( p_item->value.i );
906 if( p_item->psz_longtext )
908 QString tipText = qtr(p_item->psz_longtext);
909 slider->setToolTip( formatTooltip(tipText) );
911 label->setToolTip( formatTooltip(tipText) );
914 label->setBuddy( slider );
917 int IntegerRangeSliderConfigControl::getValue() const
919 return slider->value();
923 /********* Integer / choice list **********/
924 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
925 module_config_t *_p_item, QWidget *_parent, bool,
926 QGridLayout *l, int line) :
927 VIntConfigControl( _p_this, _p_item, _parent )
929 label = new QLabel( qtr(p_item->psz_text) );
930 combo = new QComboBox();
931 combo->setMinimumWidth( MINWIDTH_BOX );
933 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
935 finish( p_module_config );
938 QHBoxLayout *layout = new QHBoxLayout();
939 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
940 widget->setLayout( layout );
944 l->addWidget( label, line, 0 );
945 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
948 if( p_item->i_action )
950 QSignalMapper *signalMapper = new QSignalMapper(this);
952 /* Some stringLists like Capture listings have action associated */
953 for( int i = 0; i < p_item->i_action; i++ )
955 QPushButton *button =
956 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
957 CONNECT( button, clicked(), signalMapper, map() );
958 signalMapper->setMapping( button, i );
959 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
962 CONNECT( signalMapper, mapped( int ),
963 this, actionRequested( int ) );
967 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
968 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
969 bool ) : VIntConfigControl( _p_this, _p_item )
974 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
976 finish( p_module_config );
979 void IntegerListConfigControl::finish(module_config_t *p_module_config )
981 combo->setEditable( false );
983 if(!p_module_config) return;
985 if( p_module_config->pf_update_list )
988 val.i_int = p_module_config->value.i;
990 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
992 // assume in any case that dirty was set to true
993 // because lazy programmes will use the same callback for
994 // this, like the one behind the refresh push button?
995 p_module_config->b_dirty = false;
998 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
1000 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
1001 QVariant( p_module_config->pi_list[i_index] ) );
1002 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
1003 combo->setCurrentIndex( combo->count() - 1 );
1005 if( p_item->psz_longtext )
1007 QString tipText = qtr(p_item->psz_longtext );
1008 combo->setToolTip( formatTooltip(tipText) );
1010 label->setToolTip( formatTooltip(tipText) );
1013 label->setBuddy( combo );
1016 void IntegerListConfigControl::actionRequested( int i_action )
1018 /* Supplementary check for boundaries */
1019 if( i_action < 0 || i_action >= p_item->i_action ) return;
1021 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1022 if(!p_module_config) return;
1026 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
1028 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
1030 if( p_module_config->b_dirty )
1033 finish( p_module_config );
1034 p_module_config->b_dirty = false;
1038 int IntegerListConfigControl::getValue() const
1040 return combo->itemData( combo->currentIndex() ).toInt();
1043 /*********** Boolean **************/
1044 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1045 module_config_t *_p_item,
1046 QWidget *_parent, QGridLayout *l,
1048 VIntConfigControl( _p_this, _p_item, _parent )
1050 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1055 QHBoxLayout *layout = new QHBoxLayout();
1056 layout->addWidget( checkbox, 0 );
1057 widget->setLayout( layout );
1061 l->addWidget( checkbox, line, 0 );
1065 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1066 module_config_t *_p_item,
1068 QAbstractButton *_checkbox ) :
1069 VIntConfigControl( _p_this, _p_item )
1071 checkbox = _checkbox;
1072 VLC_UNUSED( _label );
1076 void BoolConfigControl::finish()
1078 checkbox->setChecked( p_item->value.i );
1079 if( p_item->psz_longtext )
1080 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1083 int BoolConfigControl::getValue() const
1085 return checkbox->isChecked();
1088 /**************************************************************************
1089 * Float-based controls
1090 *************************************************************************/
1093 VFloatConfigControl::doApply()
1095 config_PutFloat( p_this, getName(), getValue() );
1098 /*********** Float **************/
1099 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1100 module_config_t *_p_item,
1101 QWidget *_parent, QGridLayout *l,
1103 VFloatConfigControl( _p_this, _p_item, _parent )
1105 label = new QLabel( qtr(p_item->psz_text) );
1106 spin = new QDoubleSpinBox;
1107 spin->setMinimumWidth( MINWIDTH_BOX );
1108 spin->setMaximumWidth( MINWIDTH_BOX );
1109 spin->setAlignment( Qt::AlignRight );
1114 QHBoxLayout *layout = new QHBoxLayout();
1115 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1116 widget->setLayout( layout );
1120 l->addWidget( label, line, 0 );
1121 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1125 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1126 module_config_t *_p_item,
1128 QDoubleSpinBox *_spin ) :
1129 VFloatConfigControl( _p_this, _p_item )
1136 void FloatConfigControl::finish()
1138 spin->setMaximum( 2000000000. );
1139 spin->setMinimum( -2000000000. );
1140 spin->setSingleStep( 0.1 );
1141 spin->setValue( (double)p_item->value.f );
1142 if( p_item->psz_longtext )
1144 QString tipText = qtr(p_item->psz_longtext);
1145 spin->setToolTip( formatTooltip(tipText) );
1147 label->setToolTip( formatTooltip(tipText) );
1150 label->setBuddy( spin );
1153 float FloatConfigControl::getValue() const
1155 return (float)spin->value();
1158 /*********** Float with range **************/
1159 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1160 module_config_t *_p_item,
1161 QWidget *_parent, QGridLayout *l,
1163 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1168 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1169 module_config_t *_p_item,
1171 QDoubleSpinBox *_spin ) :
1172 FloatConfigControl( _p_this, _p_item, _label, _spin )
1177 void FloatRangeConfigControl::finish()
1179 spin->setMaximum( (double)p_item->max.f );
1180 spin->setMinimum( (double)p_item->min.f );
1184 /**********************************************************************
1185 * Key selector widget
1186 **********************************************************************/
1187 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1188 module_config_t *_p_item,
1189 QWidget *_parent, QGridLayout *l,
1191 ConfigControl( _p_this, _p_item, _parent )
1194 QWidget *keyContainer = new QWidget;
1195 QGridLayout *gLayout = new QGridLayout( keyContainer );
1198 qtr( "Select an action to change the associated hotkey") );
1200 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1201 actionSearch = new SearchLineEdit( keyContainer );
1203 table = new QTreeWidget;
1204 table->setColumnCount(3);
1205 table->headerItem()->setText( 0, qtr( "Action" ) );
1206 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1207 table->headerItem()->setText( 2, qtr( "Global" ) );
1208 table->setAlternatingRowColors( true );
1209 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1211 shortcutValue = new KeyShortcutEdit;
1212 shortcutValue->setReadOnly(true);
1214 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1215 QPushButton *setButton = new QPushButton( qtr( "Apply" ) );
1216 setButton->setDefault( true );
1219 gLayout->addWidget( label, 0, 0, 1, 4 );
1220 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1221 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1222 gLayout->addWidget( table, 2, 0, 1, 4 );
1223 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1224 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1225 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1227 l->addWidget( keyContainer, line, 0, 1, -1 );
1229 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1230 CONNECT( clearButton, clicked(), this, setTheKey() );
1231 BUTTONACT( setButton, setTheKey() );
1232 CONNECT( actionSearch, textChanged( const QString& ),
1233 this, filter( const QString& ) );
1236 void KeySelectorControl::finish()
1238 if( label && p_item->psz_longtext )
1239 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1241 /* Fill the table */
1243 /* Get the main Module */
1244 module_t *p_main = module_get_main();
1247 /* Access to the module_config_t */
1249 module_config_t *p_config;
1251 p_config = module_config_get (p_main, &confsize);
1253 for (size_t i = 0; i < confsize; i++)
1255 module_config_t *p_item = p_config + i;
1257 /* If we are a (non-global) key option not empty */
1258 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1259 && !strncmp( p_item->psz_name , "key-", 4 )
1260 && !EMPTY_STR( p_item->psz_text ) )
1264 - QString text in column 0
1265 - QString name in data of column 0
1266 - KeyValue in String in column 1
1268 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1269 treeItem->setText( 0, qtr( p_item->psz_text ) );
1270 treeItem->setData( 0, Qt::UserRole,
1271 QVariant( qfu( p_item->psz_name ) ) );
1273 QString keys = qfu( p_item->value.psz );
1274 treeItem->setText( 1, keys );
1275 treeItem->setData( 1, Qt::UserRole, QVariant( keys ) );
1276 table->addTopLevelItem( treeItem );
1280 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1281 && !strncmp( p_item->psz_name , "global-key", 10 )
1282 && !EMPTY_STR( p_item->psz_text ) )
1284 QList<QTreeWidgetItem *> list =
1285 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1286 if( list.count() >= 1 )
1288 QString keys = qfu( p_item->value.psz );
1289 list[0]->setText( 2, keys );
1290 list[0]->setData( 2, Qt::UserRole, keys );
1292 if( list.count() >= 2 )
1293 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1296 module_config_free (p_config);
1297 module_release (p_main);
1299 table->resizeColumnToContents( 0 );
1301 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1302 this, selectKey( QTreeWidgetItem *, int ) );
1303 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1304 this, select( QTreeWidgetItem *, int) );
1305 CONNECT( table, itemSelectionChanged(),
1306 this, select1Key() );
1308 CONNECT( shortcutValue, pressed(), this, selectKey() );
1311 void KeySelectorControl::filter( const QString &qs_search )
1313 QList<QTreeWidgetItem *> resultList =
1314 table->findItems( qs_search, Qt::MatchContains, 0 );
1315 for( int i = 0; i < table->topLevelItemCount(); i++ )
1317 table->topLevelItem( i )->setHidden(
1318 !resultList.contains( table->topLevelItem( i ) ) );
1322 void KeySelectorControl::select( QTreeWidgetItem *, int column )
1324 shortcutValue->setGlobal( column == 2 );
1327 /* Show the key selected from the table in the keySelector */
1328 void KeySelectorControl::select1Key()
1330 QTreeWidgetItem *keyItem = table->currentItem();
1331 shortcutValue->setText( keyItem->text( 1 ) );
1332 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toString() );
1333 shortcutValue->setGlobal( false );
1336 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1338 /* This happens when triggered by ClickEater */
1339 if( keyItem == NULL ) keyItem = table->currentItem();
1341 /* This can happen when nothing is selected on the treeView
1342 and the shortcutValue is clicked */
1343 if( !keyItem ) return;
1345 /* If clicked on the first column, assuming user wants the normal hotkey */
1346 if( column == 0 ) column = 1;
1348 bool b_global = ( column == 2 );
1350 /* Launch a small dialog to ask for a new key */
1351 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1354 if( d->result() == QDialog::Accepted )
1356 QString newKey = VLCKeyToString( d->keyValue );
1357 shortcutValue->setText( newKey );
1358 shortcutValue->setValue( newKey );
1359 shortcutValue->setGlobal( b_global );
1363 QTreeWidgetItem *it;
1364 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1366 it = table->topLevelItem(i);
1367 if( ( keyItem != it ) &&
1368 ( it->data( 1 + b_global, Qt::UserRole ).toString() == newKey ) )
1370 it->setData( 1 + b_global, Qt::UserRole,
1371 QVariant( qfu( "Unset" ) ) );
1372 it->setText( 1 + b_global, qtr( "Unset" ) );
1375 /* We already made an OK once. */
1382 void KeySelectorControl::setTheKey()
1384 if( !table->currentItem() ) return;
1385 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1386 shortcutValue->text() );
1387 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1388 Qt::UserRole, shortcutValue->getValue() );
1391 void KeySelectorControl::doApply()
1393 QTreeWidgetItem *it;
1394 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1396 it = table->topLevelItem(i);
1397 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1398 config_PutPsz( p_this,
1399 qtu( it->data( 0, Qt::UserRole ).toString() ),
1400 qtu( it->data( 1, Qt::UserRole ).toString() ) );
1401 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1402 config_PutPsz( p_this,
1403 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1404 qtu( it->data( 2, Qt::UserRole ).toString() ) );
1410 * Class KeyInputDialog
1412 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1413 const QString& keyToChange,
1416 QDialog( _parent ), keyValue(0), b_global( _b_global )
1422 setWindowTitle( b_global ? qtr( "Global" ): ""
1423 + qtr( "Hotkey for " ) + keyToChange );
1424 setWindowRole( "vlc-key-input" );
1426 vLayout = new QVBoxLayout( this );
1427 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1428 vLayout->addWidget( selected , Qt::AlignCenter );
1430 warning = new QLabel;
1432 vLayout->insertWidget( 1, warning );
1434 buttonBox = new QDialogButtonBox;
1435 QPushButton *ok = new QPushButton( qtr("OK") );
1436 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1437 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1438 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1439 ok->setDefault( true );
1441 vLayout->addWidget( buttonBox );
1444 CONNECT( buttonBox, accepted(), this, accept() );
1445 CONNECT( buttonBox, rejected(), this, reject() );
1448 void KeyInputDialog::checkForConflicts( int i_vlckey )
1450 QList<QTreeWidgetItem *> conflictList =
1451 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1454 if( conflictList.size() &&
1455 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1456 /* Avoid 0 or -1 that are the "Unset" states */
1458 warning->setText( qtr("Warning: the key is already assigned to \"") +
1459 conflictList[0]->text( 0 ) + "\"" );
1468 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1470 if( e->key() == Qt::Key_Tab ||
1471 e->key() == Qt::Key_Shift ||
1472 e->key() == Qt::Key_Control ||
1473 e->key() == Qt::Key_Meta ||
1474 e->key() == Qt::Key_Alt ||
1475 e->key() == Qt::Key_AltGr )
1477 int i_vlck = qtEventToVLCKey( e );
1478 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1479 checkForConflicts( i_vlck );
1483 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1485 int i_vlck = qtWheelEventToVLCKey( e );
1486 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1487 checkForConflicts( i_vlck );
1491 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)