1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * - Finish implementation (see WX, there might be missing a
29 * i_action handler for IntegerLists, but I don't see any module using it...
30 * - Improvements over WX
31 * - Validator for modulelist
37 #include "components/preferences_widgets.hpp"
38 #include "util/customwidgets.hpp"
39 #include "util/qt_dirs.hpp"
41 #include <vlc_intf_strings.h>
45 #include <QGridLayout>
47 #include <QFileDialog>
49 #include <QTreeWidgetItem>
50 #include <QSignalMapper>
51 #include <QDialogButtonBox>
54 #define MINWIDTH_BOX 90
55 #define LAST_COLUMN 10
57 QString formatTooltip(const QString & tooltip)
60 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
61 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
62 "<body style=\" font-family:'Sans Serif'; "
63 "font-style:normal; text-decoration:none;\">"
64 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
65 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
71 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
72 module_config_t *p_item,
76 return createControl( p_this, p_item, parent, NULL, i );
79 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
80 module_config_t *p_item,
82 QGridLayout *l, int &line )
84 ConfigControl *p_control = NULL;
86 switch( p_item->i_type )
88 case CONFIG_ITEM_MODULE:
89 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
92 case CONFIG_ITEM_MODULE_CAT:
93 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
96 case CONFIG_ITEM_MODULE_LIST:
97 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
100 case CONFIG_ITEM_MODULE_LIST_CAT:
101 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
104 case CONFIG_ITEM_STRING:
105 if( !p_item->i_list )
106 p_control = new StringConfigControl( p_this, p_item, parent,
109 p_control = new StringListConfigControl( p_this, p_item,
110 parent, false, l, line );
112 case CONFIG_ITEM_PASSWORD:
113 if( !p_item->i_list )
114 p_control = new StringConfigControl( p_this, p_item, parent,
117 p_control = new StringListConfigControl( p_this, p_item,
118 parent, true, l, line );
120 case CONFIG_ITEM_INTEGER:
122 p_control = new IntegerListConfigControl( p_this, p_item,
123 parent, false, l, line );
124 else if( p_item->min.i || p_item->max.i )
125 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
128 p_control = new IntegerConfigControl( p_this, p_item, parent,
131 case CONFIG_ITEM_FILE:
132 p_control = new FileConfigControl( p_this, p_item, parent, l, line);
134 case CONFIG_ITEM_DIRECTORY:
135 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
138 case CONFIG_ITEM_FONT:
139 p_control = new FontConfigControl( p_this, p_item, parent, l,
142 case CONFIG_ITEM_KEY:
143 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
145 case CONFIG_ITEM_BOOL:
146 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
148 case CONFIG_ITEM_FLOAT:
149 if( p_item->min.f || p_item->max.f )
150 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
153 p_control = new FloatConfigControl( p_this, p_item, parent,
162 void ConfigControl::doApply( intf_thread_t *p_intf )
166 case CONFIG_ITEM_INTEGER:
167 case CONFIG_ITEM_BOOL:
169 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
171 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
174 case CONFIG_ITEM_FLOAT:
176 VFloatConfigControl *vfcc =
177 qobject_cast<VFloatConfigControl *>(this);
179 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
182 case CONFIG_ITEM_STRING:
184 VStringConfigControl *vscc =
185 qobject_cast<VStringConfigControl *>(this);
187 config_PutPsz( p_intf, vscc->getName(), qtu( vscc->getValue() ) );
190 case CONFIG_ITEM_KEY:
192 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
199 /*******************************************************
201 *******************************************************/
202 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
204 setGeometry( 0, 0, 128, 100 );
205 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
208 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
210 setPreview( ( b_minimal )?MINIMAL:COMPLETE );
213 void InterfacePreviewWidget::setPreview( enum_style e_style )
215 QString pixmapLocationString(":/prefsmenu/");
221 pixmapLocationString += "sample_classic";
224 pixmapLocationString += "sample_complete";
227 pixmapLocationString += "sample_minimal";
230 pixmapLocationString += "sample_skins";
234 setPixmap( QPixmap( pixmapLocationString ) );
240 /**************************************************************************
241 * String-based controls
242 *************************************************************************/
244 /*********** String **************/
245 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
246 module_config_t *_p_item,
247 QWidget *_parent, QGridLayout *l,
248 int &line, bool pwd ) :
249 VStringConfigControl( _p_this, _p_item, _parent )
251 label = new QLabel( qtr(p_item->psz_text) );
252 text = new QLineEdit( qfu(p_item->value.psz) );
253 if( pwd ) text->setEchoMode( QLineEdit::Password );
258 QHBoxLayout *layout = new QHBoxLayout();
259 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
260 layout->addWidget( text, LAST_COLUMN );
261 widget->setLayout( layout );
265 l->addWidget( label, line, 0 );
266 l->setColumnMinimumWidth( 1, 10 );
267 l->addWidget( text, line, LAST_COLUMN );
271 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
272 module_config_t *_p_item,
273 QLabel *_label, QLineEdit *_text, bool pwd ):
274 VStringConfigControl( _p_this, _p_item )
277 if( pwd ) text->setEchoMode( QLineEdit::Password );
282 void StringConfigControl::finish()
284 text->setText( qfu(p_item->value.psz) );
285 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
288 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
289 label->setBuddy( text );
293 /*********** File **************/
294 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
295 module_config_t *_p_item,
296 QWidget *_parent, QGridLayout *l,
298 VStringConfigControl( _p_this, _p_item, _parent )
300 label = new QLabel( qtr(p_item->psz_text) );
301 text = new QLineEdit( qfu(p_item->value.psz) );
302 browse = new QPushButton( qtr( "Browse..." ) );
303 QHBoxLayout *textAndButton = new QHBoxLayout();
304 textAndButton->setMargin( 0 );
305 textAndButton->addWidget( text, 2 );
306 textAndButton->addWidget( browse, 0 );
308 BUTTONACT( browse, updateField() );
314 QHBoxLayout *layout = new QHBoxLayout();
315 layout->addWidget( label, 0 );
316 layout->insertSpacing( 1, 10 );
317 layout->addLayout( textAndButton, LAST_COLUMN );
318 widget->setLayout( layout );
322 l->addWidget( label, line, 0 );
323 l->setColumnMinimumWidth( 1, 10 );
324 l->addLayout( textAndButton, line, LAST_COLUMN );
329 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
330 module_config_t *_p_item,
331 QLabel *_label, QLineEdit *_text,
332 QPushButton *_button ):
333 VStringConfigControl( _p_this, _p_item )
339 BUTTONACT( browse, updateField() );
344 void FileConfigControl::updateField()
346 QString file = QFileDialog::getOpenFileName( NULL,
347 qtr( "Select File" ), QVLCUserDir( VLC_HOME_DIR ) );
348 if( file.isNull() ) return;
349 text->setText( toNativeSeparators( file ) );
352 void FileConfigControl::finish()
354 text->setText( qfu(p_item->value.psz) );
355 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
358 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
359 label->setBuddy( text );
363 /********* String / Directory **********/
364 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
365 module_config_t *_p_item, QWidget *_p_widget,
366 QGridLayout *_p_layout, int& _int ) :
367 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
370 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
371 module_config_t *_p_item, QLabel *_p_label,
372 QLineEdit *_p_line, QPushButton *_p_button ):
373 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
376 void DirectoryConfigControl::updateField()
378 QString dir = QFileDialog::getExistingDirectory( NULL,
380 text->text().isEmpty() ?
381 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
382 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
384 if( dir.isNull() ) return;
385 text->setText( toNativeSepNoSlash( dir ) );
388 /********* String / Font **********/
389 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
390 module_config_t *_p_item, QWidget *_parent,
391 QGridLayout *_p_layout, int& line) :
392 VStringConfigControl( _p_this, _p_item, _parent )
394 label = new QLabel( qtr(p_item->psz_text) );
395 font = new QFontComboBox( _parent );
396 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
399 QHBoxLayout *layout = new QHBoxLayout();
400 layout->addWidget( label, 0 );
401 layout->addWidget( font, 1 );
402 widget->setLayout( layout );
406 _p_layout->addWidget( label, line, 0 );
407 _p_layout->addWidget( font, line, 1, 1, -1 );
411 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
412 module_config_t *_p_item, QLabel *_p_label,
413 QFontComboBox *_p_font):
414 VStringConfigControl( _p_this, _p_item)
418 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
421 /********* String / choice list **********/
422 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
423 module_config_t *_p_item, QWidget *_parent, bool bycat,
424 QGridLayout *l, int &line) :
425 VStringConfigControl( _p_this, _p_item, _parent )
427 label = new QLabel( qtr(p_item->psz_text) );
428 combo = new QComboBox();
429 combo->setMinimumWidth( MINWIDTH_BOX );
430 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
432 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
434 finish( p_module_config, bycat );
437 l = new QGridLayout();
438 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
439 widget->setLayout( l );
443 l->addWidget( label, line, 0 );
444 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
447 if( p_item->i_action )
449 QSignalMapper *signalMapper = new QSignalMapper(this);
451 /* Some stringLists like Capture listings have action associated */
452 for( int i = 0; i < p_item->i_action; i++ )
454 QPushButton *button =
455 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
456 CONNECT( button, clicked(), signalMapper, map() );
457 signalMapper->setMapping( button, i );
458 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
461 CONNECT( signalMapper, mapped( int ),
462 this, actionRequested( int ) );
466 void StringListConfigControl::actionRequested( int i_action )
468 /* Supplementary check for boundaries */
469 if( i_action < 0 || i_action >= p_item->i_action ) return;
471 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
472 if(!p_module_config) return;
475 val.psz_string = const_cast<char *>
476 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
478 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
480 if( p_module_config->b_dirty )
483 finish( p_module_config, true );
484 p_module_config->b_dirty = false;
487 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
488 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
489 bool bycat ) : VStringConfigControl( _p_this, _p_item )
494 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
496 finish( p_module_config, bycat );
499 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
501 combo->setEditable( false );
503 if(!p_module_config) return;
505 if( p_module_config->pf_update_list )
508 val.psz_string = strdup(p_module_config->value.psz);
510 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
512 // assume in any case that dirty was set to true
513 // because lazy programmes will use the same callback for
514 // this, like the one behind the refresh push button?
515 p_module_config->b_dirty = false;
517 free( val.psz_string );
520 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
522 combo->addItem( qfu((p_module_config->ppsz_list_text &&
523 p_module_config->ppsz_list_text[i_index])?
524 p_module_config->ppsz_list_text[i_index] :
525 p_module_config->ppsz_list[i_index] ),
526 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
527 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
528 p_module_config->ppsz_list[i_index] ) )
529 combo->setCurrentIndex( combo->count() - 1 );
531 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
534 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
535 label->setBuddy( combo );
539 QString StringListConfigControl::getValue()
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 );
551 if(p_config->pf_update_list)
554 val.i_int = p_config->value.i;
555 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
556 // assume in any case that dirty was set to true
557 // because lazy programmes will use the same callback for
558 // this, like the one behind the refresh push button?
559 p_config->b_dirty = false;
562 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
564 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
565 QVariant( p_config->pi_list[i_index] ) );
566 if( p_config->value.i == p_config->pi_list[i_index] )
568 combo->setCurrentIndex( i_index );
571 combo->setToolTip( qfu( p_config->psz_longtext ) );
575 /********* Module **********/
576 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
577 module_config_t *_p_item, QWidget *_parent, bool bycat,
578 QGridLayout *l, int &line) :
579 VStringConfigControl( _p_this, _p_item, _parent )
581 label = new QLabel( qtr(p_item->psz_text) );
582 combo = new QComboBox();
583 combo->setMinimumWidth( MINWIDTH_BOX );
587 QHBoxLayout *layout = new QHBoxLayout();
588 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
589 widget->setLayout( layout );
593 l->addWidget( label, line, 0 );
594 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
598 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
599 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
600 bool bycat ) : VStringConfigControl( _p_this, _p_item )
607 void ModuleConfigControl::finish( bool bycat )
611 combo->setEditable( false );
613 /* build a list of available modules */
614 module_t **p_list = module_list_get( NULL );
615 combo->addItem( qtr("Default") );
616 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
620 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
623 module_config_t *p_config;
625 p_config = module_config_get (p_parser, &confsize);
626 for (size_t i = 0; i < confsize; i++)
628 /* Hack: required subcategory is stored in i_min */
629 const module_config_t *p_cfg = p_config + i;
630 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
631 p_cfg->value.i == p_item->min.i )
632 combo->addItem( qtr( module_GetLongName( p_parser )),
633 QVariant( module_get_object( p_parser ) ) );
634 if( p_item->value.psz && !strcmp( p_item->value.psz,
635 module_get_object( p_parser ) ) )
636 combo->setCurrentIndex( combo->count() - 1 );
638 module_config_free (p_config);
640 else if( module_provides( p_parser, p_item->psz_type ) )
642 combo->addItem( qtr(module_GetLongName( p_parser ) ),
643 QVariant( module_get_object( p_parser ) ) );
644 if( p_item->value.psz && !strcmp( p_item->value.psz,
645 module_get_object( p_parser ) ) )
646 combo->setCurrentIndex( combo->count() - 1 );
649 module_list_free( p_list );
650 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
653 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
654 label->setBuddy( combo );
658 QString ModuleConfigControl::getValue()
660 return combo->itemData( combo->currentIndex() ).toString();
663 /********* Module list **********/
664 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
665 module_config_t *_p_item, QWidget *_parent, bool bycat,
666 QGridLayout *l, int &line) :
667 VStringConfigControl( _p_this, _p_item, _parent )
671 if( !p_item->psz_text ) return;
673 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
674 text = new QLineEdit;
675 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
680 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
681 it != modules.end(); it++ )
683 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
685 layoutGroupBox->addWidget( text, boxline, 0 );
689 QVBoxLayout *layout = new QVBoxLayout();
690 layout->addWidget( groupBox, line, 0 );
691 widget->setLayout( layout );
695 l->addWidget( groupBox, line, 0, 1, -1 );
698 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
701 ModuleListConfigControl::~ModuleListConfigControl()
703 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
704 it != modules.end(); it++ )
711 #define CHECKBOX_LISTS \
713 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
714 checkBoxListItem *cbl = new checkBoxListItem; \
716 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
717 cb->setToolTip( formatTooltip( qtr( module_get_help( p_parser ))));\
718 cbl->checkBox = cb; \
720 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
721 modules.push_back( cbl ); \
723 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
724 cbl->checkBox->setChecked( true ); \
728 void ModuleListConfigControl::finish( bool bycat )
732 /* build a list of available modules */
733 module_t **p_list = module_list_get( NULL );
734 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
738 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
741 module_config_t *p_config = module_config_get (p_parser, &confsize);
743 for (size_t i = 0; i < confsize; i++)
745 module_config_t *p_cfg = p_config + i;
746 /* Hack: required subcategory is stored in i_min */
747 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
748 p_cfg->value.i == p_item->min.i )
753 module_config_free (p_config);
755 else if( module_provides( p_parser, p_item->psz_type ) )
760 module_list_free( p_list );
761 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
763 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
765 #undef CHECKBOX_LISTS
767 QString ModuleListConfigControl::getValue()
773 void ModuleListConfigControl::hide()
775 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
776 it != modules.end(); it++ )
778 (*it)->checkBox->hide();
783 void ModuleListConfigControl::show()
785 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
786 it != modules.end(); it++ )
788 (*it)->checkBox->show();
794 void ModuleListConfigControl::onUpdate()
799 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
800 it != modules.end(); it++ )
802 if( (*it)->checkBox->isChecked() )
806 text->setText( text->text() + (*it)->psz_module );
811 text->setText( text->text() + ":" + (*it)->psz_module );
817 /**************************************************************************
818 * Integer-based controls
819 *************************************************************************/
821 /*********** Integer **************/
822 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
823 module_config_t *_p_item,
824 QWidget *_parent, QGridLayout *l,
826 VIntConfigControl( _p_this, _p_item, _parent )
828 label = new QLabel( qtr(p_item->psz_text) );
829 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
830 spin->setAlignment( Qt::AlignRight );
831 spin->setMaximumWidth( MINWIDTH_BOX );
836 QHBoxLayout *layout = new QHBoxLayout();
837 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
838 widget->setLayout( layout );
842 l->addWidget( label, line, 0 );
843 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
846 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
847 module_config_t *_p_item,
848 QLabel *_label, QSpinBox *_spin ) :
849 VIntConfigControl( _p_this, _p_item )
856 void IntegerConfigControl::finish()
858 spin->setMaximum( 2000000000 );
859 spin->setMinimum( -2000000000 );
860 spin->setValue( p_item->value.i );
861 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
864 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
865 label->setBuddy( spin );
869 int IntegerConfigControl::getValue()
871 return spin->value();
874 /********* Integer range **********/
875 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
876 module_config_t *_p_item,
877 QWidget *_parent, QGridLayout *l,
879 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
884 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
885 module_config_t *_p_item,
886 QLabel *_label, QSpinBox *_spin ) :
887 IntegerConfigControl( _p_this, _p_item, _label, _spin )
892 void IntegerRangeConfigControl::finish()
894 spin->setMaximum( p_item->max.i );
895 spin->setMinimum( p_item->min.i );
898 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
899 vlc_object_t *_p_this,
900 module_config_t *_p_item,
901 QLabel *_label, QSlider *_slider ):
902 VIntConfigControl( _p_this, _p_item )
906 slider->setMaximum( p_item->max.i );
907 slider->setMinimum( p_item->min.i );
908 slider->setValue( p_item->value.i );
909 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
912 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
913 label->setBuddy( slider );
917 int IntegerRangeSliderConfigControl::getValue()
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 bycat,
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, bycat );
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 bycat ) : VIntConfigControl( _p_this, _p_item )
974 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
976 finish( p_module_config, bycat );
979 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
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 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
1008 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
1009 label->setBuddy( combo );
1013 void IntegerListConfigControl::actionRequested( int i_action )
1015 /* Supplementary check for boundaries */
1016 if( i_action < 0 || i_action >= p_item->i_action ) return;
1018 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1019 if(!p_module_config) return;
1023 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
1025 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
1027 if( p_module_config->b_dirty )
1030 finish( p_module_config, true );
1031 p_module_config->b_dirty = false;
1035 int IntegerListConfigControl::getValue()
1037 return combo->itemData( combo->currentIndex() ).toInt();
1040 /*********** Boolean **************/
1041 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1042 module_config_t *_p_item,
1043 QWidget *_parent, QGridLayout *l,
1045 VIntConfigControl( _p_this, _p_item, _parent )
1047 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1052 QHBoxLayout *layout = new QHBoxLayout();
1053 layout->addWidget( checkbox, 0 );
1054 widget->setLayout( layout );
1058 l->addWidget( checkbox, line, 0 );
1062 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1063 module_config_t *_p_item,
1065 QAbstractButton *_checkbox,
1067 VIntConfigControl( _p_this, _p_item )
1069 checkbox = _checkbox;
1070 VLC_UNUSED( _label );
1074 void BoolConfigControl::finish()
1076 checkbox->setChecked( p_item->value.i == true );
1077 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1080 int BoolConfigControl::getValue()
1082 return checkbox->isChecked();
1085 /**************************************************************************
1086 * Float-based controls
1087 *************************************************************************/
1089 /*********** Float **************/
1090 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1091 module_config_t *_p_item,
1092 QWidget *_parent, QGridLayout *l,
1094 VFloatConfigControl( _p_this, _p_item, _parent )
1096 label = new QLabel( qtr(p_item->psz_text) );
1097 spin = new QDoubleSpinBox;
1098 spin->setMinimumWidth( MINWIDTH_BOX );
1099 spin->setMaximumWidth( MINWIDTH_BOX );
1100 spin->setAlignment( Qt::AlignRight );
1105 QHBoxLayout *layout = new QHBoxLayout();
1106 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1107 widget->setLayout( layout );
1111 l->addWidget( label, line, 0 );
1112 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1116 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1117 module_config_t *_p_item,
1119 QDoubleSpinBox *_spin ) :
1120 VFloatConfigControl( _p_this, _p_item )
1127 void FloatConfigControl::finish()
1129 spin->setMaximum( 2000000000. );
1130 spin->setMinimum( -2000000000. );
1131 spin->setSingleStep( 0.1 );
1132 spin->setValue( (double)p_item->value.f );
1133 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1136 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1137 label->setBuddy( spin );
1141 float FloatConfigControl::getValue()
1143 return (float)spin->value();
1146 /*********** Float with range **************/
1147 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1148 module_config_t *_p_item,
1149 QWidget *_parent, QGridLayout *l,
1151 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1156 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1157 module_config_t *_p_item,
1159 QDoubleSpinBox *_spin ) :
1160 FloatConfigControl( _p_this, _p_item, _label, _spin )
1165 void FloatRangeConfigControl::finish()
1167 spin->setMaximum( (double)p_item->max.f );
1168 spin->setMinimum( (double)p_item->min.f );
1172 /**********************************************************************
1173 * Key selector widget
1174 **********************************************************************/
1175 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1176 module_config_t *_p_item,
1177 QWidget *_parent, QGridLayout *l,
1179 ConfigControl( _p_this, _p_item, _parent )
1182 QWidget *keyContainer = new QWidget;
1183 QGridLayout *gLayout = new QGridLayout( keyContainer );
1186 qtr( "Select an action to change the associated hotkey") );
1188 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1189 actionSearch = new SearchLineEdit( keyContainer );
1191 table = new QTreeWidget;
1192 table->setColumnCount(3);
1193 table->headerItem()->setText( 0, qtr( "Action" ) );
1194 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1195 table->headerItem()->setText( 2, qtr( "Global" ) );
1196 table->setAlternatingRowColors( true );
1198 shortcutValue = new KeyShortcutEdit;
1199 shortcutValue->setReadOnly(true);
1201 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1202 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1203 setButton->setDefault( true );
1206 gLayout->addWidget( label, 0, 0, 1, 4 );
1207 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1208 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1209 gLayout->addWidget( table, 2, 0, 1, 4 );
1210 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1211 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1212 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1214 l->addWidget( keyContainer, line, 0, 1, -1 );
1216 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1217 CONNECT( clearButton, clicked(), this, setTheKey() );
1218 BUTTONACT( setButton, setTheKey() );
1219 CONNECT( actionSearch, textChanged( const QString& ),
1220 this, filter( const QString& ) );
1223 void KeySelectorControl::finish()
1226 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1228 /* Fill the table */
1230 /* Get the main Module */
1231 module_t *p_main = module_get_main();
1234 /* Access to the module_config_t */
1236 module_config_t *p_config;
1238 p_config = module_config_get (p_main, &confsize);
1240 for (size_t i = 0; i < confsize; i++)
1242 module_config_t *p_item = p_config + i;
1244 /* If we are a key option not empty */
1245 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1246 && strstr( p_item->psz_name , "key-" )
1247 && !strstr( p_item->psz_name , "global-key" )
1248 && !EMPTY_STR( p_item->psz_text ) )
1252 - QString text in column 0
1253 - QString name in data of column 0
1254 - KeyValue in String in column 1
1255 - KeyValue in int in column 1
1257 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1258 treeItem->setText( 0, qtr( p_item->psz_text ) );
1259 treeItem->setData( 0, Qt::UserRole,
1260 QVariant( qfu( p_item->psz_name ) ) );
1261 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1262 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1263 table->addTopLevelItem( treeItem );
1267 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1268 && strstr( p_item->psz_name , "global-key" )
1269 && !EMPTY_STR( p_item->psz_text ) )
1271 QList<QTreeWidgetItem *> list =
1272 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1273 if( list.count() >= 1 )
1275 list[0]->setText( 2, VLCKeyToString( p_item->value.i ) );
1276 list[0]->setData( 2, Qt::UserRole,
1277 QVariant( p_item->value.i ) );
1279 if( list.count() >= 2 )
1280 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1283 module_config_free (p_config);
1284 module_release (p_main);
1286 table->resizeColumnToContents( 0 );
1288 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1289 this, selectKey( QTreeWidgetItem *, int ) );
1290 CONNECT( table, itemSelectionChanged(),
1291 this, select1Key() );
1293 CONNECT( shortcutValue, pressed(), this, selectKey() );
1296 void KeySelectorControl::filter( const QString &qs_search )
1298 QList<QTreeWidgetItem *> resultList =
1299 table->findItems( qs_search, Qt::MatchContains, 0 );
1300 for( int i = 0; i < table->topLevelItemCount(); i++ )
1302 table->topLevelItem( i )->setHidden(
1303 !resultList.contains( table->topLevelItem( i ) ) );
1307 /* Show the key selected from the table in the keySelector */
1308 void KeySelectorControl::select1Key()
1310 QTreeWidgetItem *keyItem = table->currentItem();
1311 shortcutValue->setText( keyItem->text( 1 ) );
1312 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1313 shortcutValue->setGlobal( false );
1316 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1318 /* This happens when triggered by ClickEater */
1319 if( keyItem == NULL ) keyItem = table->currentItem();
1321 /* This can happen when nothing is selected on the treeView
1322 and the shortcutValue is clicked */
1323 if( !keyItem ) return;
1325 /* If clicked on the first column, assuming user wants the normal hotkey */
1326 if( column == 0 ) column = 1;
1328 bool b_global = ( column == 2 );
1330 /* Launch a small dialog to ask for a new key */
1331 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1334 if( d->result() == QDialog::Accepted )
1336 int newValue = d->keyValue;
1337 shortcutValue->setText( VLCKeyToString( newValue ) );
1338 shortcutValue->setValue( newValue );
1339 shortcutValue->setGlobal( b_global );
1343 QTreeWidgetItem *it;
1344 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1346 it = table->topLevelItem(i);
1347 if( ( keyItem != it ) &&
1348 ( it->data( b_global ? 2: 1, Qt::UserRole ).toInt() == newValue ) )
1350 it->setData( b_global ? 2 : 1, Qt::UserRole, QVariant( -1 ) );
1351 it->setText( b_global ? 2 : 1, qtr( "Unset" ) );
1354 /* We already made an OK once. */
1361 void KeySelectorControl::setTheKey()
1363 if( !table->currentItem() ) return;
1364 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1365 shortcutValue->text() );
1366 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1367 Qt::UserRole, shortcutValue->getValue() );
1370 void KeySelectorControl::doApply()
1372 QTreeWidgetItem *it;
1373 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1375 it = table->topLevelItem(i);
1376 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1377 config_PutInt( p_this,
1378 qtu( it->data( 0, Qt::UserRole ).toString() ),
1379 it->data( 1, Qt::UserRole ).toInt() );
1380 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1381 config_PutInt( p_this,
1382 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1383 it->data( 2, Qt::UserRole ).toInt() );
1389 * Class KeyInputDialog
1391 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1392 const QString& keyToChange,
1395 QDialog( _parent ), keyValue(0), b_global( _b_global )
1401 setWindowTitle( b_global ? qtr( "Global" ): ""
1402 + qtr( "Hotkey for " ) + keyToChange );
1403 setWindowRole( "vlc-key-input" );
1405 vLayout = new QVBoxLayout( this );
1406 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1407 vLayout->addWidget( selected , Qt::AlignCenter );
1409 warning = new QLabel;
1411 vLayout->insertWidget( 1, warning );
1413 buttonBox = new QDialogButtonBox;
1414 QPushButton *ok = new QPushButton( qtr("OK") );
1415 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1416 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1417 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1418 ok->setDefault( true );
1420 vLayout->addWidget( buttonBox );
1423 CONNECT( buttonBox, accepted(), this, accept() );
1424 CONNECT( buttonBox, rejected(), this, reject() );
1427 void KeyInputDialog::checkForConflicts( int i_vlckey )
1429 QList<QTreeWidgetItem *> conflictList =
1430 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1433 if( conflictList.size() &&
1434 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1435 /* Avoid 0 or -1 that are the "Unset" states */
1437 warning->setText( qtr("Warning: the key is already assigned to \"") +
1438 conflictList[0]->text( 0 ) + "\"" );
1447 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1449 if( e->key() == Qt::Key_Tab ||
1450 e->key() == Qt::Key_Shift ||
1451 e->key() == Qt::Key_Control ||
1452 e->key() == Qt::Key_Meta ||
1453 e->key() == Qt::Key_Alt ||
1454 e->key() == Qt::Key_AltGr )
1456 int i_vlck = qtEventToVLCKey( e );
1457 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1458 checkForConflicts( i_vlck );
1462 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1464 int i_vlck = qtWheelEventToVLCKey( e );
1465 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1466 checkForConflicts( i_vlck );
1470 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)