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 if( p_item->psz_longtext )
285 QString tipText = qtr(p_item->psz_longtext);
286 text->setToolTip( formatTooltip(tipText) );
288 label->setToolTip( formatTooltip(tipText) );
291 label->setBuddy( text );
294 /*********** File **************/
295 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
296 module_config_t *_p_item,
297 QWidget *_parent, QGridLayout *l,
299 VStringConfigControl( _p_this, _p_item, _parent )
301 label = new QLabel( qtr(p_item->psz_text) );
302 text = new QLineEdit( qfu(p_item->value.psz) );
303 browse = new QPushButton( qtr( "Browse..." ) );
304 QHBoxLayout *textAndButton = new QHBoxLayout();
305 textAndButton->setMargin( 0 );
306 textAndButton->addWidget( text, 2 );
307 textAndButton->addWidget( browse, 0 );
309 BUTTONACT( browse, updateField() );
315 QHBoxLayout *layout = new QHBoxLayout();
316 layout->addWidget( label, 0 );
317 layout->insertSpacing( 1, 10 );
318 layout->addLayout( textAndButton, LAST_COLUMN );
319 widget->setLayout( layout );
323 l->addWidget( label, line, 0 );
324 l->setColumnMinimumWidth( 1, 10 );
325 l->addLayout( textAndButton, line, LAST_COLUMN );
330 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
331 module_config_t *_p_item,
332 QLabel *_label, QLineEdit *_text,
333 QPushButton *_button ):
334 VStringConfigControl( _p_this, _p_item )
340 BUTTONACT( browse, updateField() );
345 void FileConfigControl::updateField()
347 QString file = QFileDialog::getSaveFileName( NULL,
348 qtr( "Select File" ), QVLCUserDir( VLC_HOME_DIR ) );
349 if( file.isNull() ) return;
350 text->setText( toNativeSeparators( file ) );
353 void FileConfigControl::finish()
355 text->setText( qfu(p_item->value.psz) );
356 if( p_item->psz_longtext )
358 QString tipText = qtr(p_item->psz_longtext);
359 text->setToolTip( formatTooltip(tipText) );
361 label->setToolTip( formatTooltip(tipText) );
364 label->setBuddy( text );
367 /********* String / Directory **********/
368 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
369 module_config_t *_p_item, QWidget *_p_widget,
370 QGridLayout *_p_layout, int& _int ) :
371 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
374 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
375 module_config_t *_p_item, QLabel *_p_label,
376 QLineEdit *_p_line, QPushButton *_p_button ):
377 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
380 void DirectoryConfigControl::updateField()
382 QString dir = QFileDialog::getExistingDirectory( NULL,
384 text->text().isEmpty() ?
385 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
386 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
388 if( dir.isNull() ) return;
389 text->setText( toNativeSepNoSlash( dir ) );
392 /********* String / Font **********/
393 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
394 module_config_t *_p_item, QWidget *_parent,
395 QGridLayout *_p_layout, int& line) :
396 VStringConfigControl( _p_this, _p_item, _parent )
398 label = new QLabel( qtr(p_item->psz_text) );
399 font = new QFontComboBox( _parent );
400 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
403 QHBoxLayout *layout = new QHBoxLayout();
404 layout->addWidget( label, 0 );
405 layout->addWidget( font, 1 );
406 widget->setLayout( layout );
410 _p_layout->addWidget( label, line, 0 );
411 _p_layout->addWidget( font, line, 1, 1, -1 );
415 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
416 module_config_t *_p_item, QLabel *_p_label,
417 QFontComboBox *_p_font):
418 VStringConfigControl( _p_this, _p_item)
422 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
425 /********* String / choice list **********/
426 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
427 module_config_t *_p_item, QWidget *_parent, bool bycat,
428 QGridLayout *l, int &line) :
429 VStringConfigControl( _p_this, _p_item, _parent )
431 label = new QLabel( qtr(p_item->psz_text) );
432 combo = new QComboBox();
433 combo->setMinimumWidth( MINWIDTH_BOX );
434 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
436 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
438 finish( p_module_config, bycat );
441 l = new QGridLayout();
442 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
443 widget->setLayout( l );
447 l->addWidget( label, line, 0 );
448 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
451 if( p_item->i_action )
453 QSignalMapper *signalMapper = new QSignalMapper(this);
455 /* Some stringLists like Capture listings have action associated */
456 for( int i = 0; i < p_item->i_action; i++ )
458 QPushButton *button =
459 new QPushButton( qtr( p_item->ppsz_action_text[i] ));
460 CONNECT( button, clicked(), signalMapper, map() );
461 signalMapper->setMapping( button, i );
462 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
465 CONNECT( signalMapper, mapped( int ),
466 this, actionRequested( int ) );
470 void StringListConfigControl::actionRequested( int i_action )
472 /* Supplementary check for boundaries */
473 if( i_action < 0 || i_action >= p_item->i_action ) return;
475 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
476 if(!p_module_config) return;
479 val.psz_string = const_cast<char *>
480 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
482 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
484 if( p_module_config->b_dirty )
487 finish( p_module_config, true );
488 p_module_config->b_dirty = false;
491 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
492 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
493 bool bycat ) : VStringConfigControl( _p_this, _p_item )
498 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
500 finish( p_module_config, bycat );
503 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
505 combo->setEditable( false );
507 if(!p_module_config) return;
509 if( p_module_config->pf_update_list )
512 val.psz_string = strdup(p_module_config->value.psz);
514 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
516 // assume in any case that dirty was set to true
517 // because lazy programmes will use the same callback for
518 // this, like the one behind the refresh push button?
519 p_module_config->b_dirty = false;
521 free( val.psz_string );
524 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
526 if( !p_module_config->ppsz_list[i_index] )
528 combo->addItem( "", QVariant(""));
529 if( !p_item->value.psz )
530 combo->setCurrentIndex( combo->count() - 1 );
533 combo->addItem( qfu((p_module_config->ppsz_list_text &&
534 p_module_config->ppsz_list_text[i_index])?
535 _(p_module_config->ppsz_list_text[i_index]) :
536 p_module_config->ppsz_list[i_index] ),
537 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
538 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
539 p_module_config->ppsz_list[i_index] ) )
540 combo->setCurrentIndex( combo->count() - 1 );
543 if( p_module_config->psz_longtext )
545 QString tipText = qtr(p_module_config->psz_longtext);
546 combo->setToolTip( formatTooltip(tipText) );
548 label->setToolTip( formatTooltip(tipText) );
551 label->setBuddy( combo );
554 QString StringListConfigControl::getValue()
556 return combo->itemData( combo->currentIndex() ).toString();
559 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
562 module_config_t *p_config =
563 config_FindConfig( VLC_OBJECT(p_intf), configname );
566 if(p_config->pf_update_list)
569 val.i_int = p_config->value.i;
570 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
571 // assume in any case that dirty was set to true
572 // because lazy programmes will use the same callback for
573 // this, like the one behind the refresh push button?
574 p_config->b_dirty = false;
577 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
579 combo->addItem( qtr(p_config->ppsz_list_text[i_index]),
580 QVariant( p_config->pi_list[i_index] ) );
581 if( p_config->value.i == p_config->pi_list[i_index] )
583 combo->setCurrentIndex( i_index );
587 if( p_config->psz_longtext )
588 combo->setToolTip( qfu( p_config->psz_longtext ) );
592 /********* Module **********/
593 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
594 module_config_t *_p_item, QWidget *_parent, bool bycat,
595 QGridLayout *l, int &line) :
596 VStringConfigControl( _p_this, _p_item, _parent )
598 label = new QLabel( qtr(p_item->psz_text) );
599 combo = new QComboBox();
600 combo->setMinimumWidth( MINWIDTH_BOX );
604 QHBoxLayout *layout = new QHBoxLayout();
605 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
606 widget->setLayout( layout );
610 l->addWidget( label, line, 0 );
611 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
615 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
616 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
617 bool bycat ) : VStringConfigControl( _p_this, _p_item )
624 void ModuleConfigControl::finish( bool bycat )
628 combo->setEditable( false );
630 /* build a list of available modules */
631 module_t **p_list = module_list_get( NULL );
632 combo->addItem( qtr("Default") );
633 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
637 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
640 module_config_t *p_config;
642 p_config = module_config_get (p_parser, &confsize);
643 for (size_t i = 0; i < confsize; i++)
645 /* Hack: required subcategory is stored in i_min */
646 const module_config_t *p_cfg = p_config + i;
647 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
648 p_cfg->value.i == p_item->min.i )
649 combo->addItem( qtr( module_GetLongName( p_parser )),
650 QVariant( module_get_object( p_parser ) ) );
651 if( p_item->value.psz && !strcmp( p_item->value.psz,
652 module_get_object( p_parser ) ) )
653 combo->setCurrentIndex( combo->count() - 1 );
655 module_config_free (p_config);
657 else if( module_provides( p_parser, p_item->psz_type ) )
659 combo->addItem( qtr(module_GetLongName( p_parser ) ),
660 QVariant( module_get_object( p_parser ) ) );
661 if( p_item->value.psz && !strcmp( p_item->value.psz,
662 module_get_object( p_parser ) ) )
663 combo->setCurrentIndex( combo->count() - 1 );
666 module_list_free( p_list );
668 if( p_item->psz_longtext )
670 QString tipText = qtr(p_item->psz_longtext);
671 combo->setToolTip( formatTooltip(tipText) );
673 label->setToolTip( formatTooltip(tipText) );
676 label->setBuddy( combo );
679 QString ModuleConfigControl::getValue()
681 return combo->itemData( combo->currentIndex() ).toString();
684 /********* Module list **********/
685 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
686 module_config_t *_p_item, QWidget *_parent, bool bycat,
687 QGridLayout *l, int &line) :
688 VStringConfigControl( _p_this, _p_item, _parent )
692 if( !p_item->psz_text ) return;
694 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
695 text = new QLineEdit;
696 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
701 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
702 it != modules.end(); it++ )
704 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
706 layoutGroupBox->addWidget( text, boxline, 0 );
710 QVBoxLayout *layout = new QVBoxLayout();
711 layout->addWidget( groupBox, line, 0 );
712 widget->setLayout( layout );
716 l->addWidget( groupBox, line, 0, 1, -1 );
719 if( p_item->psz_longtext )
720 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
723 ModuleListConfigControl::~ModuleListConfigControl()
725 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
726 it != modules.end(); it++ )
733 #define CHECKBOX_LISTS \
735 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
736 checkBoxListItem *cbl = new checkBoxListItem; \
738 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
739 const char *help = module_get_help( p_parser ); \
741 cb->setToolTip( formatTooltip( qtr( help ) ) ); \
742 cbl->checkBox = cb; \
744 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
745 modules.push_back( cbl ); \
747 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
748 cbl->checkBox->setChecked( true ); \
752 void ModuleListConfigControl::finish( bool bycat )
756 /* build a list of available modules */
757 module_t **p_list = module_list_get( NULL );
758 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
762 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
765 module_config_t *p_config = module_config_get (p_parser, &confsize);
767 for (size_t i = 0; i < confsize; i++)
769 module_config_t *p_cfg = p_config + i;
770 /* Hack: required subcategory is stored in i_min */
771 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
772 p_cfg->value.i == p_item->min.i )
777 module_config_free (p_config);
779 else if( module_provides( p_parser, p_item->psz_type ) )
784 module_list_free( p_list );
786 if( p_item->psz_longtext )
788 QString tipText = qtr(p_item->psz_longtext);
790 text->setToolTip( formatTooltip(tipText) );
792 groupBox->setToolTip( formatTooltip(tipText) );
795 #undef CHECKBOX_LISTS
797 QString ModuleListConfigControl::getValue()
803 void ModuleListConfigControl::hide()
805 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
806 it != modules.end(); it++ )
808 (*it)->checkBox->hide();
813 void ModuleListConfigControl::show()
815 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
816 it != modules.end(); it++ )
818 (*it)->checkBox->show();
824 void ModuleListConfigControl::onUpdate()
829 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
830 it != modules.end(); it++ )
832 if( (*it)->checkBox->isChecked() )
836 text->setText( text->text() + (*it)->psz_module );
841 text->setText( text->text() + ":" + (*it)->psz_module );
847 /**************************************************************************
848 * Integer-based controls
849 *************************************************************************/
851 /*********** Integer **************/
852 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
853 module_config_t *_p_item,
854 QWidget *_parent, QGridLayout *l,
856 VIntConfigControl( _p_this, _p_item, _parent )
858 label = new QLabel( qtr(p_item->psz_text) );
859 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
860 spin->setAlignment( Qt::AlignRight );
861 spin->setMaximumWidth( MINWIDTH_BOX );
866 QHBoxLayout *layout = new QHBoxLayout();
867 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
868 widget->setLayout( layout );
872 l->addWidget( label, line, 0 );
873 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
876 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
877 module_config_t *_p_item,
878 QLabel *_label, QSpinBox *_spin ) :
879 VIntConfigControl( _p_this, _p_item )
886 void IntegerConfigControl::finish()
888 spin->setMaximum( 2000000000 );
889 spin->setMinimum( -2000000000 );
890 spin->setValue( p_item->value.i );
892 if( p_item->psz_longtext )
894 QString tipText = qtr(p_item->psz_longtext);
895 spin->setToolTip( formatTooltip(tipText) );
897 label->setToolTip( formatTooltip(tipText) );
900 label->setBuddy( spin );
903 int IntegerConfigControl::getValue()
905 return spin->value();
908 /********* Integer range **********/
909 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
910 module_config_t *_p_item,
911 QWidget *_parent, QGridLayout *l,
913 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
918 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
919 module_config_t *_p_item,
920 QLabel *_label, QSpinBox *_spin ) :
921 IntegerConfigControl( _p_this, _p_item, _label, _spin )
926 void IntegerRangeConfigControl::finish()
928 spin->setMaximum( p_item->max.i );
929 spin->setMinimum( p_item->min.i );
932 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
933 vlc_object_t *_p_this,
934 module_config_t *_p_item,
935 QLabel *_label, QSlider *_slider ):
936 VIntConfigControl( _p_this, _p_item )
940 slider->setMaximum( p_item->max.i );
941 slider->setMinimum( p_item->min.i );
942 slider->setValue( p_item->value.i );
943 if( p_item->psz_longtext )
945 QString tipText = qtr(p_item->psz_longtext);
946 slider->setToolTip( formatTooltip(tipText) );
948 label->setToolTip( formatTooltip(tipText) );
951 label->setBuddy( slider );
954 int IntegerRangeSliderConfigControl::getValue()
956 return slider->value();
960 /********* Integer / choice list **********/
961 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
962 module_config_t *_p_item, QWidget *_parent, bool bycat,
963 QGridLayout *l, int &line) :
964 VIntConfigControl( _p_this, _p_item, _parent )
966 label = new QLabel( qtr(p_item->psz_text) );
967 combo = new QComboBox();
968 combo->setMinimumWidth( MINWIDTH_BOX );
970 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
972 finish( p_module_config, bycat );
975 QHBoxLayout *layout = new QHBoxLayout();
976 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
977 widget->setLayout( layout );
981 l->addWidget( label, line, 0 );
982 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
985 if( p_item->i_action )
987 QSignalMapper *signalMapper = new QSignalMapper(this);
989 /* Some stringLists like Capture listings have action associated */
990 for( int i = 0; i < p_item->i_action; i++ )
992 QPushButton *button =
993 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
994 CONNECT( button, clicked(), signalMapper, map() );
995 signalMapper->setMapping( button, i );
996 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
999 CONNECT( signalMapper, mapped( int ),
1000 this, actionRequested( int ) );
1004 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
1005 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
1006 bool bycat ) : VIntConfigControl( _p_this, _p_item )
1011 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1013 finish( p_module_config, bycat );
1016 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
1018 combo->setEditable( false );
1020 if(!p_module_config) return;
1022 if( p_module_config->pf_update_list )
1025 val.i_int = p_module_config->value.i;
1027 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
1029 // assume in any case that dirty was set to true
1030 // because lazy programmes will use the same callback for
1031 // this, like the one behind the refresh push button?
1032 p_module_config->b_dirty = false;
1035 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
1037 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
1038 QVariant( p_module_config->pi_list[i_index] ) );
1039 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
1040 combo->setCurrentIndex( combo->count() - 1 );
1042 if( p_item->psz_longtext )
1044 QString tipText = qtr(p_item->psz_longtext );
1045 combo->setToolTip( formatTooltip(tipText) );
1047 label->setToolTip( formatTooltip(tipText) );
1050 label->setBuddy( combo );
1053 void IntegerListConfigControl::actionRequested( int i_action )
1055 /* Supplementary check for boundaries */
1056 if( i_action < 0 || i_action >= p_item->i_action ) return;
1058 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1059 if(!p_module_config) return;
1063 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
1065 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
1067 if( p_module_config->b_dirty )
1070 finish( p_module_config, true );
1071 p_module_config->b_dirty = false;
1075 int IntegerListConfigControl::getValue()
1077 return combo->itemData( combo->currentIndex() ).toInt();
1080 /*********** Boolean **************/
1081 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1082 module_config_t *_p_item,
1083 QWidget *_parent, QGridLayout *l,
1085 VIntConfigControl( _p_this, _p_item, _parent )
1087 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1092 QHBoxLayout *layout = new QHBoxLayout();
1093 layout->addWidget( checkbox, 0 );
1094 widget->setLayout( layout );
1098 l->addWidget( checkbox, line, 0 );
1102 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1103 module_config_t *_p_item,
1105 QAbstractButton *_checkbox,
1107 VIntConfigControl( _p_this, _p_item )
1109 checkbox = _checkbox;
1110 VLC_UNUSED( _label );
1114 void BoolConfigControl::finish()
1116 checkbox->setChecked( p_item->value.i == true );
1117 if( p_item->psz_longtext )
1118 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1121 int BoolConfigControl::getValue()
1123 return checkbox->isChecked();
1126 /**************************************************************************
1127 * Float-based controls
1128 *************************************************************************/
1130 /*********** Float **************/
1131 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1132 module_config_t *_p_item,
1133 QWidget *_parent, QGridLayout *l,
1135 VFloatConfigControl( _p_this, _p_item, _parent )
1137 label = new QLabel( qtr(p_item->psz_text) );
1138 spin = new QDoubleSpinBox;
1139 spin->setMinimumWidth( MINWIDTH_BOX );
1140 spin->setMaximumWidth( MINWIDTH_BOX );
1141 spin->setAlignment( Qt::AlignRight );
1146 QHBoxLayout *layout = new QHBoxLayout();
1147 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1148 widget->setLayout( layout );
1152 l->addWidget( label, line, 0 );
1153 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1157 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1158 module_config_t *_p_item,
1160 QDoubleSpinBox *_spin ) :
1161 VFloatConfigControl( _p_this, _p_item )
1168 void FloatConfigControl::finish()
1170 spin->setMaximum( 2000000000. );
1171 spin->setMinimum( -2000000000. );
1172 spin->setSingleStep( 0.1 );
1173 spin->setValue( (double)p_item->value.f );
1174 if( p_item->psz_longtext )
1176 QString tipText = qtr(p_item->psz_longtext);
1177 spin->setToolTip( formatTooltip(tipText) );
1179 label->setToolTip( formatTooltip(tipText) );
1182 label->setBuddy( spin );
1185 float FloatConfigControl::getValue()
1187 return (float)spin->value();
1190 /*********** Float with range **************/
1191 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1192 module_config_t *_p_item,
1193 QWidget *_parent, QGridLayout *l,
1195 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1200 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1201 module_config_t *_p_item,
1203 QDoubleSpinBox *_spin ) :
1204 FloatConfigControl( _p_this, _p_item, _label, _spin )
1209 void FloatRangeConfigControl::finish()
1211 spin->setMaximum( (double)p_item->max.f );
1212 spin->setMinimum( (double)p_item->min.f );
1216 /**********************************************************************
1217 * Key selector widget
1218 **********************************************************************/
1219 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1220 module_config_t *_p_item,
1221 QWidget *_parent, QGridLayout *l,
1223 ConfigControl( _p_this, _p_item, _parent )
1226 QWidget *keyContainer = new QWidget;
1227 QGridLayout *gLayout = new QGridLayout( keyContainer );
1230 qtr( "Select an action to change the associated hotkey") );
1232 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1233 actionSearch = new SearchLineEdit( keyContainer );
1235 table = new QTreeWidget;
1236 table->setColumnCount(3);
1237 table->headerItem()->setText( 0, qtr( "Action" ) );
1238 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1239 table->headerItem()->setText( 2, qtr( "Global" ) );
1240 table->setAlternatingRowColors( true );
1241 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1243 shortcutValue = new KeyShortcutEdit;
1244 shortcutValue->setReadOnly(true);
1246 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1247 QPushButton *setButton = new QPushButton( qtr( "Apply" ) );
1248 setButton->setDefault( true );
1251 gLayout->addWidget( label, 0, 0, 1, 4 );
1252 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1253 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1254 gLayout->addWidget( table, 2, 0, 1, 4 );
1255 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1256 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1257 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1259 l->addWidget( keyContainer, line, 0, 1, -1 );
1261 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1262 CONNECT( clearButton, clicked(), this, setTheKey() );
1263 BUTTONACT( setButton, setTheKey() );
1264 CONNECT( actionSearch, textChanged( const QString& ),
1265 this, filter( const QString& ) );
1268 void KeySelectorControl::finish()
1270 if( label && p_item->psz_longtext )
1271 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1273 /* Fill the table */
1275 /* Get the main Module */
1276 module_t *p_main = module_get_main();
1279 /* Access to the module_config_t */
1281 module_config_t *p_config;
1283 p_config = module_config_get (p_main, &confsize);
1285 for (size_t i = 0; i < confsize; i++)
1287 module_config_t *p_item = p_config + i;
1289 /* If we are a key option not empty */
1290 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1291 && strstr( p_item->psz_name , "key-" )
1292 && !strstr( p_item->psz_name , "global-key" )
1293 && !EMPTY_STR( p_item->psz_text ) )
1297 - QString text in column 0
1298 - QString name in data of column 0
1299 - KeyValue in String in column 1
1300 - KeyValue in int64_t in column 1
1302 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1303 treeItem->setText( 0, qtr( p_item->psz_text ) );
1304 treeItem->setData( 0, Qt::UserRole,
1305 QVariant( qfu( p_item->psz_name ) ) );
1306 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1307 treeItem->setData( 1, Qt::UserRole, QVariant( qlonglong( p_item->value.i ) ) );
1308 table->addTopLevelItem( treeItem );
1312 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1313 && strstr( p_item->psz_name , "global-key" )
1314 && !EMPTY_STR( p_item->psz_text ) )
1316 QList<QTreeWidgetItem *> list =
1317 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1318 if( list.count() >= 1 )
1320 list[0]->setText( 2, VLCKeyToString( p_item->value.i ) );
1321 list[0]->setData( 2, Qt::UserRole,
1322 QVariant( qlonglong( p_item->value.i ) ) );
1324 if( list.count() >= 2 )
1325 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1328 module_config_free (p_config);
1329 module_release (p_main);
1331 table->resizeColumnToContents( 0 );
1333 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1334 this, selectKey( QTreeWidgetItem *, int ) );
1335 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1336 this, select( QTreeWidgetItem *, int) );
1337 CONNECT( table, itemSelectionChanged(),
1338 this, select1Key() );
1340 CONNECT( shortcutValue, pressed(), this, selectKey() );
1343 void KeySelectorControl::filter( const QString &qs_search )
1345 QList<QTreeWidgetItem *> resultList =
1346 table->findItems( qs_search, Qt::MatchContains, 0 );
1347 for( int i = 0; i < table->topLevelItemCount(); i++ )
1349 table->topLevelItem( i )->setHidden(
1350 !resultList.contains( table->topLevelItem( i ) ) );
1354 void KeySelectorControl::select( QTreeWidgetItem *keyItem, int column )
1356 shortcutValue->setGlobal( column == 2 );
1359 /* Show the key selected from the table in the keySelector */
1360 void KeySelectorControl::select1Key()
1362 QTreeWidgetItem *keyItem = table->currentItem();
1363 shortcutValue->setText( keyItem->text( 1 ) );
1364 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1365 shortcutValue->setGlobal( false );
1368 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1370 /* This happens when triggered by ClickEater */
1371 if( keyItem == NULL ) keyItem = table->currentItem();
1373 /* This can happen when nothing is selected on the treeView
1374 and the shortcutValue is clicked */
1375 if( !keyItem ) return;
1377 /* If clicked on the first column, assuming user wants the normal hotkey */
1378 if( column == 0 ) column = 1;
1380 bool b_global = ( column == 2 );
1382 /* Launch a small dialog to ask for a new key */
1383 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1386 if( d->result() == QDialog::Accepted )
1388 int newValue = d->keyValue;
1389 shortcutValue->setText( VLCKeyToString( newValue ) );
1390 shortcutValue->setValue( newValue );
1391 shortcutValue->setGlobal( b_global );
1395 QTreeWidgetItem *it;
1396 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1398 it = table->topLevelItem(i);
1399 if( ( keyItem != it ) &&
1400 ( it->data( b_global ? 2: 1, Qt::UserRole ).toInt() == newValue ) )
1402 it->setData( b_global ? 2 : 1, Qt::UserRole, QVariant( -1 ) );
1403 it->setText( b_global ? 2 : 1, qtr( "Unset" ) );
1406 /* We already made an OK once. */
1413 void KeySelectorControl::setTheKey()
1415 if( !table->currentItem() ) return;
1416 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1417 shortcutValue->text() );
1418 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1419 Qt::UserRole, shortcutValue->getValue() );
1422 void KeySelectorControl::doApply()
1424 QTreeWidgetItem *it;
1425 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1427 it = table->topLevelItem(i);
1428 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1429 config_PutInt( p_this,
1430 qtu( it->data( 0, Qt::UserRole ).toString() ),
1431 it->data( 1, Qt::UserRole ).toInt() );
1432 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1433 config_PutInt( p_this,
1434 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1435 it->data( 2, Qt::UserRole ).toInt() );
1441 * Class KeyInputDialog
1443 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1444 const QString& keyToChange,
1447 QDialog( _parent ), keyValue(0), b_global( _b_global )
1453 setWindowTitle( b_global ? qtr( "Global" ): ""
1454 + qtr( "Hotkey for " ) + keyToChange );
1455 setWindowRole( "vlc-key-input" );
1457 vLayout = new QVBoxLayout( this );
1458 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1459 vLayout->addWidget( selected , Qt::AlignCenter );
1461 warning = new QLabel;
1463 vLayout->insertWidget( 1, warning );
1465 buttonBox = new QDialogButtonBox;
1466 QPushButton *ok = new QPushButton( qtr("OK") );
1467 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1468 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1469 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1470 ok->setDefault( true );
1472 vLayout->addWidget( buttonBox );
1475 CONNECT( buttonBox, accepted(), this, accept() );
1476 CONNECT( buttonBox, rejected(), this, reject() );
1479 void KeyInputDialog::checkForConflicts( int i_vlckey )
1481 QList<QTreeWidgetItem *> conflictList =
1482 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1485 if( conflictList.size() &&
1486 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1487 /* Avoid 0 or -1 that are the "Unset" states */
1489 warning->setText( qtr("Warning: the key is already assigned to \"") +
1490 conflictList[0]->text( 0 ) + "\"" );
1499 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1501 if( e->key() == Qt::Key_Tab ||
1502 e->key() == Qt::Key_Shift ||
1503 e->key() == Qt::Key_Control ||
1504 e->key() == Qt::Key_Meta ||
1505 e->key() == Qt::Key_Alt ||
1506 e->key() == Qt::Key_AltGr )
1508 int i_vlck = qtEventToVLCKey( e );
1509 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1510 checkForConflicts( i_vlck );
1514 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1516 int i_vlck = qtWheelEventToVLCKey( e );
1517 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1518 checkForConflicts( i_vlck );
1522 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)