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>
42 #include <vlc_modules.h>
46 #include <QGridLayout>
48 #include <QFileDialog>
50 #include <QTreeWidgetItem>
51 #include <QSignalMapper>
52 #include <QDialogButtonBox>
55 #define MINWIDTH_BOX 90
56 #define LAST_COLUMN 10
58 QString formatTooltip(const QString & tooltip)
61 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
62 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
63 "<body style=\" font-family:'Sans Serif'; "
64 "font-style:normal; text-decoration:none;\">"
65 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
66 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
72 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
73 module_config_t *p_item,
77 return createControl( p_this, p_item, parent, NULL, i );
80 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
81 module_config_t *p_item,
83 QGridLayout *l, int &line )
85 ConfigControl *p_control = NULL;
87 switch( p_item->i_type )
89 case CONFIG_ITEM_MODULE:
90 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
93 case CONFIG_ITEM_MODULE_CAT:
94 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
97 case CONFIG_ITEM_MODULE_LIST:
98 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
101 case CONFIG_ITEM_MODULE_LIST_CAT:
102 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
105 case CONFIG_ITEM_STRING:
106 if( !p_item->i_list )
107 p_control = new StringConfigControl( p_this, p_item, parent,
110 p_control = new StringListConfigControl( p_this, p_item,
111 parent, false, l, line );
113 case CONFIG_ITEM_PASSWORD:
114 if( !p_item->i_list )
115 p_control = new StringConfigControl( p_this, p_item, parent,
118 p_control = new StringListConfigControl( p_this, p_item,
119 parent, true, l, line );
121 case CONFIG_ITEM_INTEGER:
123 p_control = new IntegerListConfigControl( p_this, p_item,
124 parent, false, l, line );
125 else if( p_item->min.i || p_item->max.i )
126 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
129 p_control = new IntegerConfigControl( p_this, p_item, parent,
132 case CONFIG_ITEM_FILE:
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 void ConfigControl::doApply( intf_thread_t *p_intf )
167 case CONFIG_ITEM_INTEGER:
168 case CONFIG_ITEM_BOOL:
170 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
172 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
175 case CONFIG_ITEM_FLOAT:
177 VFloatConfigControl *vfcc =
178 qobject_cast<VFloatConfigControl *>(this);
180 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
183 case CONFIG_ITEM_STRING:
185 VStringConfigControl *vscc =
186 qobject_cast<VStringConfigControl *>(this);
188 config_PutPsz( p_intf, vscc->getName(), qtu( vscc->getValue() ) );
191 case CONFIG_ITEM_KEY:
193 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
200 /*******************************************************
202 *******************************************************/
203 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
205 setGeometry( 0, 0, 128, 100 );
206 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
209 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
211 setPreview( ( b_minimal )?MINIMAL:COMPLETE );
214 void InterfacePreviewWidget::setPreview( enum_style e_style )
216 QString pixmapLocationString(":/prefsmenu/");
222 pixmapLocationString += "sample_complete";
225 pixmapLocationString += "sample_minimal";
228 pixmapLocationString += "sample_skins";
232 setPixmap( QPixmap( pixmapLocationString ) );
238 /**************************************************************************
239 * String-based controls
240 *************************************************************************/
242 /*********** String **************/
243 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
244 module_config_t *_p_item,
245 QWidget *_parent, QGridLayout *l,
246 int &line, bool pwd ) :
247 VStringConfigControl( _p_this, _p_item, _parent )
249 label = new QLabel( qtr(p_item->psz_text) );
250 text = new QLineEdit( qfu(p_item->value.psz) );
251 if( pwd ) text->setEchoMode( QLineEdit::Password );
256 QHBoxLayout *layout = new QHBoxLayout();
257 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
258 layout->addWidget( text, LAST_COLUMN );
259 widget->setLayout( layout );
263 l->addWidget( label, line, 0 );
264 l->setColumnMinimumWidth( 1, 10 );
265 l->addWidget( text, line, LAST_COLUMN );
269 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
270 module_config_t *_p_item,
271 QLabel *_label, QLineEdit *_text, bool pwd ):
272 VStringConfigControl( _p_this, _p_item )
275 if( pwd ) text->setEchoMode( QLineEdit::Password );
280 void StringConfigControl::finish()
282 text->setText( qfu(p_item->value.psz) );
283 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
286 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
287 label->setBuddy( text );
291 /*********** File **************/
292 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
293 module_config_t *_p_item,
294 QWidget *_parent, QGridLayout *l,
296 VStringConfigControl( _p_this, _p_item, _parent )
298 label = new QLabel( qtr(p_item->psz_text) );
299 text = new QLineEdit( qfu(p_item->value.psz) );
300 browse = new QPushButton( qtr( "Browse..." ) );
301 QHBoxLayout *textAndButton = new QHBoxLayout();
302 textAndButton->setMargin( 0 );
303 textAndButton->addWidget( text, 2 );
304 textAndButton->addWidget( browse, 0 );
306 BUTTONACT( browse, updateField() );
312 QHBoxLayout *layout = new QHBoxLayout();
313 layout->addWidget( label, 0 );
314 layout->insertSpacing( 1, 10 );
315 layout->addLayout( textAndButton, LAST_COLUMN );
316 widget->setLayout( layout );
320 l->addWidget( label, line, 0 );
321 l->setColumnMinimumWidth( 1, 10 );
322 l->addLayout( textAndButton, line, LAST_COLUMN );
327 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
328 module_config_t *_p_item,
329 QLabel *_label, QLineEdit *_text,
330 QPushButton *_button ):
331 VStringConfigControl( _p_this, _p_item )
337 BUTTONACT( browse, updateField() );
342 void FileConfigControl::updateField()
344 QString file = QFileDialog::getSaveFileName( NULL,
345 qtr( "Select File" ), QVLCUserDir( VLC_HOME_DIR ) );
346 if( file.isNull() ) return;
347 text->setText( toNativeSeparators( file ) );
350 void FileConfigControl::finish()
352 text->setText( qfu(p_item->value.psz) );
353 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
356 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
357 label->setBuddy( text );
361 /********* String / Directory **********/
362 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
363 module_config_t *_p_item, QWidget *_p_widget,
364 QGridLayout *_p_layout, int& _int ) :
365 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
368 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
369 module_config_t *_p_item, QLabel *_p_label,
370 QLineEdit *_p_line, QPushButton *_p_button ):
371 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
374 void DirectoryConfigControl::updateField()
376 QString dir = QFileDialog::getExistingDirectory( NULL,
378 text->text().isEmpty() ?
379 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
380 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
382 if( dir.isNull() ) return;
383 text->setText( toNativeSepNoSlash( dir ) );
386 /********* String / Font **********/
387 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
388 module_config_t *_p_item, QWidget *_parent,
389 QGridLayout *_p_layout, int& line) :
390 VStringConfigControl( _p_this, _p_item, _parent )
392 label = new QLabel( qtr(p_item->psz_text) );
393 font = new QFontComboBox( _parent );
394 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
397 QHBoxLayout *layout = new QHBoxLayout();
398 layout->addWidget( label, 0 );
399 layout->addWidget( font, 1 );
400 widget->setLayout( layout );
404 _p_layout->addWidget( label, line, 0 );
405 _p_layout->addWidget( font, line, 1, 1, -1 );
409 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
410 module_config_t *_p_item, QLabel *_p_label,
411 QFontComboBox *_p_font):
412 VStringConfigControl( _p_this, _p_item)
416 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
419 /********* String / choice list **********/
420 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
421 module_config_t *_p_item, QWidget *_parent, bool bycat,
422 QGridLayout *l, int &line) :
423 VStringConfigControl( _p_this, _p_item, _parent )
425 label = new QLabel( qtr(p_item->psz_text) );
426 combo = new QComboBox();
427 combo->setMinimumWidth( MINWIDTH_BOX );
428 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
430 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
432 finish( p_module_config, bycat );
435 l = new QGridLayout();
436 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
437 widget->setLayout( l );
441 l->addWidget( label, line, 0 );
442 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
445 if( p_item->i_action )
447 QSignalMapper *signalMapper = new QSignalMapper(this);
449 /* Some stringLists like Capture listings have action associated */
450 for( int i = 0; i < p_item->i_action; i++ )
452 QPushButton *button =
453 new QPushButton( qtr( p_item->ppsz_action_text[i] ));
454 CONNECT( button, clicked(), signalMapper, map() );
455 signalMapper->setMapping( button, i );
456 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
459 CONNECT( signalMapper, mapped( int ),
460 this, actionRequested( int ) );
464 void StringListConfigControl::actionRequested( int i_action )
466 /* Supplementary check for boundaries */
467 if( i_action < 0 || i_action >= p_item->i_action ) return;
469 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
470 if(!p_module_config) return;
473 val.psz_string = const_cast<char *>
474 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
476 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
478 if( p_module_config->b_dirty )
481 finish( p_module_config, true );
482 p_module_config->b_dirty = false;
485 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
486 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
487 bool bycat ) : VStringConfigControl( _p_this, _p_item )
492 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
494 finish( p_module_config, bycat );
497 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
499 combo->setEditable( false );
501 if(!p_module_config) return;
503 if( p_module_config->pf_update_list )
506 val.psz_string = strdup(p_module_config->value.psz);
508 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
510 // assume in any case that dirty was set to true
511 // because lazy programmes will use the same callback for
512 // this, like the one behind the refresh push button?
513 p_module_config->b_dirty = false;
515 free( val.psz_string );
518 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
520 if( !p_module_config->ppsz_list[i_index] )
522 combo->addItem( "", QVariant(""));
523 if( !p_item->value.psz )
524 combo->setCurrentIndex( combo->count() - 1 );
527 combo->addItem( qfu((p_module_config->ppsz_list_text &&
528 p_module_config->ppsz_list_text[i_index])?
529 p_module_config->ppsz_list_text[i_index] :
530 p_module_config->ppsz_list[i_index] ),
531 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
532 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
533 p_module_config->ppsz_list[i_index] ) )
534 combo->setCurrentIndex( combo->count() - 1 );
536 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
539 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
540 label->setBuddy( combo );
544 QString StringListConfigControl::getValue()
546 return combo->itemData( combo->currentIndex() ).toString();
549 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
552 module_config_t *p_config =
553 config_FindConfig( VLC_OBJECT(p_intf), configname );
556 if(p_config->pf_update_list)
559 val.i_int = p_config->value.i;
560 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
561 // assume in any case that dirty was set to true
562 // because lazy programmes will use the same callback for
563 // this, like the one behind the refresh push button?
564 p_config->b_dirty = false;
567 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
569 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
570 QVariant( p_config->pi_list[i_index] ) );
571 if( p_config->value.i == p_config->pi_list[i_index] )
573 combo->setCurrentIndex( i_index );
576 combo->setToolTip( qfu( p_config->psz_longtext ) );
580 /********* Module **********/
581 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
582 module_config_t *_p_item, QWidget *_parent, bool bycat,
583 QGridLayout *l, int &line) :
584 VStringConfigControl( _p_this, _p_item, _parent )
586 label = new QLabel( qtr(p_item->psz_text) );
587 combo = new QComboBox();
588 combo->setMinimumWidth( MINWIDTH_BOX );
592 QHBoxLayout *layout = new QHBoxLayout();
593 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
594 widget->setLayout( layout );
598 l->addWidget( label, line, 0 );
599 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
603 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
604 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
605 bool bycat ) : VStringConfigControl( _p_this, _p_item )
612 void ModuleConfigControl::finish( bool bycat )
616 combo->setEditable( false );
618 /* build a list of available modules */
619 module_t **p_list = module_list_get( NULL );
620 combo->addItem( qtr("Default") );
621 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
625 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
628 module_config_t *p_config;
630 p_config = module_config_get (p_parser, &confsize);
631 for (size_t i = 0; i < confsize; i++)
633 /* Hack: required subcategory is stored in i_min */
634 const module_config_t *p_cfg = p_config + i;
635 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
636 p_cfg->value.i == p_item->min.i )
637 combo->addItem( qtr( module_GetLongName( p_parser )),
638 QVariant( module_get_object( p_parser ) ) );
639 if( p_item->value.psz && !strcmp( p_item->value.psz,
640 module_get_object( p_parser ) ) )
641 combo->setCurrentIndex( combo->count() - 1 );
643 module_config_free (p_config);
645 else if( module_provides( p_parser, p_item->psz_type ) )
647 combo->addItem( qtr(module_GetLongName( p_parser ) ),
648 QVariant( module_get_object( p_parser ) ) );
649 if( p_item->value.psz && !strcmp( p_item->value.psz,
650 module_get_object( p_parser ) ) )
651 combo->setCurrentIndex( combo->count() - 1 );
654 module_list_free( p_list );
655 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
658 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
659 label->setBuddy( combo );
663 QString ModuleConfigControl::getValue()
665 return combo->itemData( combo->currentIndex() ).toString();
668 /********* Module list **********/
669 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
670 module_config_t *_p_item, QWidget *_parent, bool bycat,
671 QGridLayout *l, int &line) :
672 VStringConfigControl( _p_this, _p_item, _parent )
676 if( !p_item->psz_text ) return;
678 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
679 text = new QLineEdit;
680 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
685 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
686 it != modules.end(); it++ )
688 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
690 layoutGroupBox->addWidget( text, boxline, 0 );
694 QVBoxLayout *layout = new QVBoxLayout();
695 layout->addWidget( groupBox, line, 0 );
696 widget->setLayout( layout );
700 l->addWidget( groupBox, line, 0, 1, -1 );
703 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
706 ModuleListConfigControl::~ModuleListConfigControl()
708 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
709 it != modules.end(); it++ )
716 #define CHECKBOX_LISTS \
718 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
719 checkBoxListItem *cbl = new checkBoxListItem; \
721 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
722 cb->setToolTip( formatTooltip( qtr( module_get_help( p_parser ))));\
723 cbl->checkBox = cb; \
725 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
726 modules.push_back( cbl ); \
728 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
729 cbl->checkBox->setChecked( true ); \
733 void ModuleListConfigControl::finish( bool bycat )
737 /* build a list of available modules */
738 module_t **p_list = module_list_get( NULL );
739 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
743 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
746 module_config_t *p_config = module_config_get (p_parser, &confsize);
748 for (size_t i = 0; i < confsize; i++)
750 module_config_t *p_cfg = p_config + i;
751 /* Hack: required subcategory is stored in i_min */
752 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
753 p_cfg->value.i == p_item->min.i )
758 module_config_free (p_config);
760 else if( module_provides( p_parser, p_item->psz_type ) )
765 module_list_free( p_list );
766 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
768 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
770 #undef CHECKBOX_LISTS
772 QString ModuleListConfigControl::getValue()
778 void ModuleListConfigControl::hide()
780 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
781 it != modules.end(); it++ )
783 (*it)->checkBox->hide();
788 void ModuleListConfigControl::show()
790 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
791 it != modules.end(); it++ )
793 (*it)->checkBox->show();
799 void ModuleListConfigControl::onUpdate()
804 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
805 it != modules.end(); it++ )
807 if( (*it)->checkBox->isChecked() )
811 text->setText( text->text() + (*it)->psz_module );
816 text->setText( text->text() + ":" + (*it)->psz_module );
822 /**************************************************************************
823 * Integer-based controls
824 *************************************************************************/
826 /*********** Integer **************/
827 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
828 module_config_t *_p_item,
829 QWidget *_parent, QGridLayout *l,
831 VIntConfigControl( _p_this, _p_item, _parent )
833 label = new QLabel( qtr(p_item->psz_text) );
834 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
835 spin->setAlignment( Qt::AlignRight );
836 spin->setMaximumWidth( MINWIDTH_BOX );
841 QHBoxLayout *layout = new QHBoxLayout();
842 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
843 widget->setLayout( layout );
847 l->addWidget( label, line, 0 );
848 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
851 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
852 module_config_t *_p_item,
853 QLabel *_label, QSpinBox *_spin ) :
854 VIntConfigControl( _p_this, _p_item )
861 void IntegerConfigControl::finish()
863 spin->setMaximum( 2000000000 );
864 spin->setMinimum( -2000000000 );
865 spin->setValue( p_item->value.i );
866 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
869 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
870 label->setBuddy( spin );
874 int IntegerConfigControl::getValue()
876 return spin->value();
879 /********* Integer range **********/
880 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
881 module_config_t *_p_item,
882 QWidget *_parent, QGridLayout *l,
884 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
889 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
890 module_config_t *_p_item,
891 QLabel *_label, QSpinBox *_spin ) :
892 IntegerConfigControl( _p_this, _p_item, _label, _spin )
897 void IntegerRangeConfigControl::finish()
899 spin->setMaximum( p_item->max.i );
900 spin->setMinimum( p_item->min.i );
903 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
904 vlc_object_t *_p_this,
905 module_config_t *_p_item,
906 QLabel *_label, QSlider *_slider ):
907 VIntConfigControl( _p_this, _p_item )
911 slider->setMaximum( p_item->max.i );
912 slider->setMinimum( p_item->min.i );
913 slider->setValue( p_item->value.i );
914 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
917 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
918 label->setBuddy( slider );
922 int IntegerRangeSliderConfigControl::getValue()
924 return slider->value();
928 /********* Integer / choice list **********/
929 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
930 module_config_t *_p_item, QWidget *_parent, bool bycat,
931 QGridLayout *l, int &line) :
932 VIntConfigControl( _p_this, _p_item, _parent )
934 label = new QLabel( qtr(p_item->psz_text) );
935 combo = new QComboBox();
936 combo->setMinimumWidth( MINWIDTH_BOX );
938 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
940 finish( p_module_config, bycat );
943 QHBoxLayout *layout = new QHBoxLayout();
944 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
945 widget->setLayout( layout );
949 l->addWidget( label, line, 0 );
950 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
953 if( p_item->i_action )
955 QSignalMapper *signalMapper = new QSignalMapper(this);
957 /* Some stringLists like Capture listings have action associated */
958 for( int i = 0; i < p_item->i_action; i++ )
960 QPushButton *button =
961 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
962 CONNECT( button, clicked(), signalMapper, map() );
963 signalMapper->setMapping( button, i );
964 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
967 CONNECT( signalMapper, mapped( int ),
968 this, actionRequested( int ) );
972 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
973 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
974 bool bycat ) : VIntConfigControl( _p_this, _p_item )
979 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
981 finish( p_module_config, bycat );
984 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
986 combo->setEditable( false );
988 if(!p_module_config) return;
990 if( p_module_config->pf_update_list )
993 val.i_int = p_module_config->value.i;
995 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
997 // assume in any case that dirty was set to true
998 // because lazy programmes will use the same callback for
999 // this, like the one behind the refresh push button?
1000 p_module_config->b_dirty = false;
1003 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
1005 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
1006 QVariant( p_module_config->pi_list[i_index] ) );
1007 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
1008 combo->setCurrentIndex( combo->count() - 1 );
1010 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
1013 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
1014 label->setBuddy( combo );
1018 void IntegerListConfigControl::actionRequested( int i_action )
1020 /* Supplementary check for boundaries */
1021 if( i_action < 0 || i_action >= p_item->i_action ) return;
1023 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1024 if(!p_module_config) return;
1028 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
1030 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
1032 if( p_module_config->b_dirty )
1035 finish( p_module_config, true );
1036 p_module_config->b_dirty = false;
1040 int IntegerListConfigControl::getValue()
1042 return combo->itemData( combo->currentIndex() ).toInt();
1045 /*********** Boolean **************/
1046 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1047 module_config_t *_p_item,
1048 QWidget *_parent, QGridLayout *l,
1050 VIntConfigControl( _p_this, _p_item, _parent )
1052 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1057 QHBoxLayout *layout = new QHBoxLayout();
1058 layout->addWidget( checkbox, 0 );
1059 widget->setLayout( layout );
1063 l->addWidget( checkbox, line, 0 );
1067 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1068 module_config_t *_p_item,
1070 QAbstractButton *_checkbox,
1072 VIntConfigControl( _p_this, _p_item )
1074 checkbox = _checkbox;
1075 VLC_UNUSED( _label );
1079 void BoolConfigControl::finish()
1081 checkbox->setChecked( p_item->value.i == true );
1082 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1085 int BoolConfigControl::getValue()
1087 return checkbox->isChecked();
1090 /**************************************************************************
1091 * Float-based controls
1092 *************************************************************************/
1094 /*********** Float **************/
1095 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1096 module_config_t *_p_item,
1097 QWidget *_parent, QGridLayout *l,
1099 VFloatConfigControl( _p_this, _p_item, _parent )
1101 label = new QLabel( qtr(p_item->psz_text) );
1102 spin = new QDoubleSpinBox;
1103 spin->setMinimumWidth( MINWIDTH_BOX );
1104 spin->setMaximumWidth( MINWIDTH_BOX );
1105 spin->setAlignment( Qt::AlignRight );
1110 QHBoxLayout *layout = new QHBoxLayout();
1111 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1112 widget->setLayout( layout );
1116 l->addWidget( label, line, 0 );
1117 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1121 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1122 module_config_t *_p_item,
1124 QDoubleSpinBox *_spin ) :
1125 VFloatConfigControl( _p_this, _p_item )
1132 void FloatConfigControl::finish()
1134 spin->setMaximum( 2000000000. );
1135 spin->setMinimum( -2000000000. );
1136 spin->setSingleStep( 0.1 );
1137 spin->setValue( (double)p_item->value.f );
1138 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1141 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1142 label->setBuddy( spin );
1146 float FloatConfigControl::getValue()
1148 return (float)spin->value();
1151 /*********** Float with range **************/
1152 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1153 module_config_t *_p_item,
1154 QWidget *_parent, QGridLayout *l,
1156 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1161 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1162 module_config_t *_p_item,
1164 QDoubleSpinBox *_spin ) :
1165 FloatConfigControl( _p_this, _p_item, _label, _spin )
1170 void FloatRangeConfigControl::finish()
1172 spin->setMaximum( (double)p_item->max.f );
1173 spin->setMinimum( (double)p_item->min.f );
1177 /**********************************************************************
1178 * Key selector widget
1179 **********************************************************************/
1180 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1181 module_config_t *_p_item,
1182 QWidget *_parent, QGridLayout *l,
1184 ConfigControl( _p_this, _p_item, _parent )
1187 QWidget *keyContainer = new QWidget;
1188 QGridLayout *gLayout = new QGridLayout( keyContainer );
1191 qtr( "Select an action to change the associated hotkey") );
1193 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1194 actionSearch = new SearchLineEdit( keyContainer );
1196 table = new QTreeWidget;
1197 table->setColumnCount(3);
1198 table->headerItem()->setText( 0, qtr( "Action" ) );
1199 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1200 table->headerItem()->setText( 2, qtr( "Global" ) );
1201 table->setAlternatingRowColors( true );
1202 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1204 shortcutValue = new KeyShortcutEdit;
1205 shortcutValue->setReadOnly(true);
1207 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1208 QPushButton *setButton = new QPushButton( qtr( "Apply" ) );
1209 setButton->setDefault( true );
1212 gLayout->addWidget( label, 0, 0, 1, 4 );
1213 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1214 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1215 gLayout->addWidget( table, 2, 0, 1, 4 );
1216 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1217 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1218 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1220 l->addWidget( keyContainer, line, 0, 1, -1 );
1222 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1223 CONNECT( clearButton, clicked(), this, setTheKey() );
1224 BUTTONACT( setButton, setTheKey() );
1225 CONNECT( actionSearch, textChanged( const QString& ),
1226 this, filter( const QString& ) );
1229 void KeySelectorControl::finish()
1232 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1234 /* Fill the table */
1236 /* Get the main Module */
1237 module_t *p_main = module_get_main();
1240 /* Access to the module_config_t */
1242 module_config_t *p_config;
1244 p_config = module_config_get (p_main, &confsize);
1246 for (size_t i = 0; i < confsize; i++)
1248 module_config_t *p_item = p_config + i;
1250 /* If we are a key option not empty */
1251 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1252 && strstr( p_item->psz_name , "key-" )
1253 && !strstr( p_item->psz_name , "global-key" )
1254 && !EMPTY_STR( p_item->psz_text ) )
1258 - QString text in column 0
1259 - QString name in data of column 0
1260 - KeyValue in String in column 1
1261 - KeyValue in int64_t in column 1
1263 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1264 treeItem->setText( 0, qtr( p_item->psz_text ) );
1265 treeItem->setData( 0, Qt::UserRole,
1266 QVariant( qfu( p_item->psz_name ) ) );
1267 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1268 treeItem->setData( 1, Qt::UserRole, QVariant( qlonglong( p_item->value.i ) ) );
1269 table->addTopLevelItem( treeItem );
1273 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1274 && strstr( p_item->psz_name , "global-key" )
1275 && !EMPTY_STR( p_item->psz_text ) )
1277 QList<QTreeWidgetItem *> list =
1278 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1279 if( list.count() >= 1 )
1281 list[0]->setText( 2, VLCKeyToString( p_item->value.i ) );
1282 list[0]->setData( 2, Qt::UserRole,
1283 QVariant( qlonglong( p_item->value.i ) ) );
1285 if( list.count() >= 2 )
1286 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1289 module_config_free (p_config);
1290 module_release (p_main);
1292 table->resizeColumnToContents( 0 );
1294 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1295 this, selectKey( QTreeWidgetItem *, int ) );
1296 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1297 this, select( QTreeWidgetItem *, int) );
1298 CONNECT( table, itemSelectionChanged(),
1299 this, select1Key() );
1301 CONNECT( shortcutValue, pressed(), this, selectKey() );
1304 void KeySelectorControl::filter( const QString &qs_search )
1306 QList<QTreeWidgetItem *> resultList =
1307 table->findItems( qs_search, Qt::MatchContains, 0 );
1308 for( int i = 0; i < table->topLevelItemCount(); i++ )
1310 table->topLevelItem( i )->setHidden(
1311 !resultList.contains( table->topLevelItem( i ) ) );
1315 void KeySelectorControl::select( QTreeWidgetItem *keyItem, int column )
1317 shortcutValue->setGlobal( column == 2 );
1320 /* Show the key selected from the table in the keySelector */
1321 void KeySelectorControl::select1Key()
1323 QTreeWidgetItem *keyItem = table->currentItem();
1324 shortcutValue->setText( keyItem->text( 1 ) );
1325 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1326 shortcutValue->setGlobal( false );
1329 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1331 /* This happens when triggered by ClickEater */
1332 if( keyItem == NULL ) keyItem = table->currentItem();
1334 /* This can happen when nothing is selected on the treeView
1335 and the shortcutValue is clicked */
1336 if( !keyItem ) return;
1338 /* If clicked on the first column, assuming user wants the normal hotkey */
1339 if( column == 0 ) column = 1;
1341 bool b_global = ( column == 2 );
1343 /* Launch a small dialog to ask for a new key */
1344 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1347 if( d->result() == QDialog::Accepted )
1349 int newValue = d->keyValue;
1350 shortcutValue->setText( VLCKeyToString( newValue ) );
1351 shortcutValue->setValue( newValue );
1352 shortcutValue->setGlobal( b_global );
1356 QTreeWidgetItem *it;
1357 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1359 it = table->topLevelItem(i);
1360 if( ( keyItem != it ) &&
1361 ( it->data( b_global ? 2: 1, Qt::UserRole ).toInt() == newValue ) )
1363 it->setData( b_global ? 2 : 1, Qt::UserRole, QVariant( -1 ) );
1364 it->setText( b_global ? 2 : 1, qtr( "Unset" ) );
1367 /* We already made an OK once. */
1374 void KeySelectorControl::setTheKey()
1376 if( !table->currentItem() ) return;
1377 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1378 shortcutValue->text() );
1379 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1380 Qt::UserRole, shortcutValue->getValue() );
1383 void KeySelectorControl::doApply()
1385 QTreeWidgetItem *it;
1386 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1388 it = table->topLevelItem(i);
1389 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1390 config_PutInt( p_this,
1391 qtu( it->data( 0, Qt::UserRole ).toString() ),
1392 it->data( 1, Qt::UserRole ).toInt() );
1393 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1394 config_PutInt( p_this,
1395 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1396 it->data( 2, Qt::UserRole ).toInt() );
1402 * Class KeyInputDialog
1404 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1405 const QString& keyToChange,
1408 QDialog( _parent ), keyValue(0), b_global( _b_global )
1414 setWindowTitle( b_global ? qtr( "Global" ): ""
1415 + qtr( "Hotkey for " ) + keyToChange );
1416 setWindowRole( "vlc-key-input" );
1418 vLayout = new QVBoxLayout( this );
1419 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1420 vLayout->addWidget( selected , Qt::AlignCenter );
1422 warning = new QLabel;
1424 vLayout->insertWidget( 1, warning );
1426 buttonBox = new QDialogButtonBox;
1427 QPushButton *ok = new QPushButton( qtr("OK") );
1428 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1429 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1430 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1431 ok->setDefault( true );
1433 vLayout->addWidget( buttonBox );
1436 CONNECT( buttonBox, accepted(), this, accept() );
1437 CONNECT( buttonBox, rejected(), this, reject() );
1440 void KeyInputDialog::checkForConflicts( int i_vlckey )
1442 QList<QTreeWidgetItem *> conflictList =
1443 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1446 if( conflictList.size() &&
1447 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1448 /* Avoid 0 or -1 that are the "Unset" states */
1450 warning->setText( qtr("Warning: the key is already assigned to \"") +
1451 conflictList[0]->text( 0 ) + "\"" );
1460 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1462 if( e->key() == Qt::Key_Tab ||
1463 e->key() == Qt::Key_Shift ||
1464 e->key() == Qt::Key_Control ||
1465 e->key() == Qt::Key_Meta ||
1466 e->key() == Qt::Key_Alt ||
1467 e->key() == Qt::Key_AltGr )
1469 int i_vlck = qtEventToVLCKey( e );
1470 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1471 checkForConflicts( i_vlck );
1475 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1477 int i_vlck = qtWheelEventToVLCKey( e );
1478 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1479 checkForConflicts( i_vlck );
1483 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)