1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * - Finish implementation (see WX, there might be missing a
29 * i_action handler for IntegerLists, but I don't see any module using it...
30 * - Improvements over WX
31 * - Validator for modulelist
37 #include "components/preferences_widgets.hpp"
38 #include "util/customwidgets.hpp"
39 #include "util/searchlineedit.hpp"
40 #include "util/qt_dirs.hpp"
42 #include <vlc_intf_strings.h>
43 #include <vlc_modules.h>
47 #include <QGridLayout>
49 #include <QFileDialog>
51 #include <QTreeWidgetItem>
52 #include <QSignalMapper>
53 #include <QDialogButtonBox>
56 #define MINWIDTH_BOX 90
57 #define LAST_COLUMN 10
59 QString formatTooltip(const QString & tooltip)
61 QString text = tooltip;
62 text.replace("\n", "<br/>");
65 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
66 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
67 "<body style=\" font-family:'Sans Serif'; "
68 "font-style:normal; text-decoration:none;\">"
69 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
70 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
71 text + "</p></body></html>";
75 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
76 module_config_t *p_item,
78 QGridLayout *l, int line )
80 ConfigControl *p_control = NULL;
82 switch( p_item->i_type )
84 case CONFIG_ITEM_MODULE:
85 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
88 case CONFIG_ITEM_MODULE_CAT:
89 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
92 case CONFIG_ITEM_MODULE_LIST:
93 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
96 case CONFIG_ITEM_MODULE_LIST_CAT:
97 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
100 case CONFIG_ITEM_STRING:
101 if( !p_item->i_list )
102 p_control = new StringConfigControl( p_this, p_item, parent,
105 p_control = new StringListConfigControl( p_this, p_item,
108 case CONFIG_ITEM_PASSWORD:
109 if( !p_item->i_list )
110 p_control = new StringConfigControl( p_this, p_item, parent,
113 p_control = new StringListConfigControl( p_this, p_item,
116 case CONFIG_ITEM_INTEGER:
118 p_control = new IntegerListConfigControl( p_this, p_item,
119 parent, false, l, line );
120 else if( p_item->min.i || p_item->max.i )
121 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
124 p_control = new IntegerConfigControl( p_this, p_item, parent,
127 case CONFIG_ITEM_LOADFILE:
128 case CONFIG_ITEM_SAVEFILE:
129 p_control = new FileConfigControl( p_this, p_item, parent, l, line);
131 case CONFIG_ITEM_DIRECTORY:
132 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
135 case CONFIG_ITEM_FONT:
136 p_control = new FontConfigControl( p_this, p_item, parent, l,
139 case CONFIG_ITEM_KEY:
140 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
142 case CONFIG_ITEM_BOOL:
143 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
145 case CONFIG_ITEM_FLOAT:
146 if( p_item->min.f || p_item->max.f )
147 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
150 p_control = new FloatConfigControl( p_this, p_item, parent,
159 /*******************************************************
161 *******************************************************/
162 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
164 setGeometry( 0, 0, 128, 100 );
165 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
168 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
170 setPreview( ( b_minimal )?MINIMAL:COMPLETE );
173 void InterfacePreviewWidget::setPreview( enum_style e_style )
175 QString pixmapLocationString(":/prefsmenu/");
181 pixmapLocationString += "sample_complete";
184 pixmapLocationString += "sample_minimal";
187 pixmapLocationString += "sample_skins";
191 setPixmap( QPixmap( pixmapLocationString ) );
197 /**************************************************************************
198 * String-based controls
199 *************************************************************************/
202 VStringConfigControl::doApply()
204 config_PutPsz( p_this, getName(), qtu( getValue() ) );
207 /*********** String **************/
208 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
209 module_config_t *_p_item,
210 QWidget *_parent, QGridLayout *l,
211 int line, bool pwd ) :
212 VStringConfigControl( _p_this, _p_item, _parent )
214 label = new QLabel( qtr(p_item->psz_text) );
215 text = new QLineEdit( qfu(p_item->value.psz) );
216 if( pwd ) text->setEchoMode( QLineEdit::Password );
221 QHBoxLayout *layout = new QHBoxLayout();
222 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
223 layout->addWidget( text, LAST_COLUMN );
224 widget->setLayout( layout );
228 l->addWidget( label, line, 0 );
229 l->setColumnMinimumWidth( 1, 10 );
230 l->addWidget( text, line, LAST_COLUMN );
234 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
235 module_config_t *_p_item,
236 QLabel *_label, QLineEdit *_text, bool pwd ):
237 VStringConfigControl( _p_this, _p_item )
240 if( pwd ) text->setEchoMode( QLineEdit::Password );
245 void StringConfigControl::finish()
247 text->setText( qfu(p_item->value.psz) );
248 if( p_item->psz_longtext )
250 QString tipText = qtr(p_item->psz_longtext);
251 text->setToolTip( formatTooltip(tipText) );
253 label->setToolTip( formatTooltip(tipText) );
256 label->setBuddy( text );
259 /*********** File **************/
260 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
261 module_config_t *_p_item,
262 QWidget *_parent, QGridLayout *l,
264 VStringConfigControl( _p_this, _p_item, _parent )
266 label = new QLabel( qtr(p_item->psz_text) );
267 text = new QLineEdit( qfu(p_item->value.psz) );
268 browse = new QPushButton( qtr( "Browse..." ) );
269 QHBoxLayout *textAndButton = new QHBoxLayout();
270 textAndButton->setMargin( 0 );
271 textAndButton->addWidget( text, 2 );
272 textAndButton->addWidget( browse, 0 );
274 BUTTONACT( browse, updateField() );
280 QHBoxLayout *layout = new QHBoxLayout();
281 layout->addWidget( label, 0 );
282 layout->insertSpacing( 1, 10 );
283 layout->addLayout( textAndButton, LAST_COLUMN );
284 widget->setLayout( layout );
288 l->addWidget( label, line, 0 );
289 l->setColumnMinimumWidth( 1, 10 );
290 l->addLayout( textAndButton, line, LAST_COLUMN );
295 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
296 module_config_t *_p_item,
297 QLabel *_label, QLineEdit *_text,
298 QPushButton *_button ):
299 VStringConfigControl( _p_this, _p_item )
305 BUTTONACT( browse, updateField() );
310 void FileConfigControl::updateField()
314 if (p_item->i_type == CONFIG_ITEM_SAVEFILE)
315 file = QFileDialog::getSaveFileName( NULL, qtr( "Save File" ),
316 QVLCUserDir( VLC_HOME_DIR ) );
318 file = QFileDialog::getOpenFileName( NULL, qtr( "Select File" ),
319 QVLCUserDir( VLC_HOME_DIR ) );
321 if( file.isNull() ) return;
322 text->setText( toNativeSeparators( file ) );
325 void FileConfigControl::finish()
327 text->setText( qfu(p_item->value.psz) );
328 if( p_item->psz_longtext )
330 QString tipText = qtr(p_item->psz_longtext);
331 text->setToolTip( formatTooltip(tipText) );
333 label->setToolTip( formatTooltip(tipText) );
336 label->setBuddy( text );
339 /********* String / Directory **********/
340 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
341 module_config_t *_p_item, QWidget *_p_widget,
342 QGridLayout *_p_layout, int _int ) :
343 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
346 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
347 module_config_t *_p_item, QLabel *_p_label,
348 QLineEdit *_p_line, QPushButton *_p_button ):
349 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
352 void DirectoryConfigControl::updateField()
354 QString dir = QFileDialog::getExistingDirectory( NULL,
356 text->text().isEmpty() ?
357 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
358 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
360 if( dir.isNull() ) return;
361 text->setText( toNativeSepNoSlash( dir ) );
364 /********* String / Font **********/
365 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
366 module_config_t *_p_item, QWidget *_parent,
367 QGridLayout *_p_layout, int line) :
368 VStringConfigControl( _p_this, _p_item, _parent )
370 label = new QLabel( qtr(p_item->psz_text) );
371 font = new QFontComboBox( _parent );
372 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
375 QHBoxLayout *layout = new QHBoxLayout();
376 layout->addWidget( label, 0 );
377 layout->addWidget( font, 1 );
378 widget->setLayout( layout );
382 _p_layout->addWidget( label, line, 0 );
383 _p_layout->addWidget( font, line, 1, 1, -1 );
387 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
388 module_config_t *_p_item, QLabel *_p_label,
389 QFontComboBox *_p_font):
390 VStringConfigControl( _p_this, _p_item)
394 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
397 /********* String / choice list **********/
398 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
399 module_config_t *_p_item, QWidget *_parent,
400 QGridLayout *l, int line) :
401 VStringConfigControl( _p_this, _p_item, _parent )
403 label = new QLabel( qtr(p_item->psz_text) );
404 combo = new QComboBox();
405 combo->setMinimumWidth( MINWIDTH_BOX );
406 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
408 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
410 finish( p_module_config );
413 l = new QGridLayout();
414 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
415 widget->setLayout( l );
419 l->addWidget( label, line, 0 );
420 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
423 if( p_item->i_action )
425 QSignalMapper *signalMapper = new QSignalMapper(this);
427 /* Some stringLists like Capture listings have action associated */
428 for( int i = 0; i < p_item->i_action; i++ )
430 QPushButton *button =
431 new QPushButton( qtr( p_item->ppsz_action_text[i] ));
432 CONNECT( button, clicked(), signalMapper, map() );
433 signalMapper->setMapping( button, i );
434 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
437 CONNECT( signalMapper, mapped( int ),
438 this, actionRequested( int ) );
442 void StringListConfigControl::actionRequested( int i_action )
444 /* Supplementary check for boundaries */
445 if( i_action < 0 || i_action >= p_item->i_action ) return;
447 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
448 if(!p_module_config) return;
451 val.psz_string = const_cast<char *>
452 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
454 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
456 if( p_module_config->b_dirty )
459 finish( p_module_config );
460 p_module_config->b_dirty = false;
463 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
464 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
465 bool ) : VStringConfigControl( _p_this, _p_item )
470 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
472 finish( p_module_config );
475 void StringListConfigControl::finish(module_config_t *p_module_config )
477 combo->setEditable( false );
479 if(!p_module_config) return;
481 if( p_module_config->pf_update_list )
484 val.psz_string = strdup(p_module_config->value.psz);
486 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
488 // assume in any case that dirty was set to true
489 // because lazy programmes will use the same callback for
490 // this, like the one behind the refresh push button?
491 p_module_config->b_dirty = false;
493 free( val.psz_string );
496 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
498 if( !p_module_config->ppsz_list[i_index] )
500 combo->addItem( "", QVariant(""));
501 if( !p_item->value.psz )
502 combo->setCurrentIndex( combo->count() - 1 );
505 combo->addItem( qfu((p_module_config->ppsz_list_text &&
506 p_module_config->ppsz_list_text[i_index])?
507 _(p_module_config->ppsz_list_text[i_index]) :
508 p_module_config->ppsz_list[i_index] ),
509 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
510 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
511 p_module_config->ppsz_list[i_index] ) )
512 combo->setCurrentIndex( combo->count() - 1 );
515 if( p_module_config->psz_longtext )
517 QString tipText = qtr(p_module_config->psz_longtext);
518 combo->setToolTip( formatTooltip(tipText) );
520 label->setToolTip( formatTooltip(tipText) );
523 label->setBuddy( combo );
526 QString StringListConfigControl::getValue() const
528 return combo->itemData( combo->currentIndex() ).toString();
531 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
534 module_config_t *p_config =
535 config_FindConfig( VLC_OBJECT(p_intf), configname );
539 bool string = (p_config->i_type & 0xF0) == CONFIG_ITEM_STRING;
542 def = QVariant( qfu(p_config->value.psz) );
544 def = QVariant( qlonglong( p_config->value.i ) );
546 if(p_config->pf_update_list)
549 val.i_int = p_config->value.i;
550 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
551 // assume in any case that dirty was set to true
552 // because lazy programmes will use the same callback for
553 // this, like the one behind the refresh push button?
554 p_config->b_dirty = false;
557 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
562 value = QVariant( qfu(p_config->ppsz_list[i_index]) );
564 value =QVariant( p_config->pi_list[i_index] );
565 combo->addItem( qtr(p_config->ppsz_list_text[i_index]), value );
567 combo->setCurrentIndex( i_index );
570 if( p_config->psz_longtext )
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 );
651 if( p_item->psz_longtext )
653 QString tipText = qtr(p_item->psz_longtext);
654 combo->setToolTip( formatTooltip(tipText) );
656 label->setToolTip( formatTooltip(tipText) );
659 label->setBuddy( combo );
662 QString ModuleConfigControl::getValue() const
664 return combo->itemData( combo->currentIndex() ).toString();
667 /********* Module list **********/
668 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
669 module_config_t *_p_item, QWidget *_parent, bool bycat,
670 QGridLayout *l, int line) :
671 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 foreach ( checkBoxListItem *it, modules )
687 layoutGroupBox->addWidget( it->checkBox, boxline / 2, boxline % 2 );
691 layoutGroupBox->addWidget( text, boxline, 0, 1, 2 );
695 QVBoxLayout *layout = new QVBoxLayout();
696 layout->addWidget( groupBox, line, 0 );
697 widget->setLayout( layout );
701 l->addWidget( groupBox, line, 0, 1, -1 );
704 if( p_item->psz_longtext )
705 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
708 ModuleListConfigControl::~ModuleListConfigControl()
710 qDeleteAll( modules );
715 #define CHECKBOX_LISTS \
717 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
718 checkBoxListItem *cbl = new checkBoxListItem; \
720 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
721 const char *help = module_get_help( p_parser ); \
723 cb->setToolTip( formatTooltip( qtr( help ) ) ); \
724 cbl->checkBox = cb; \
726 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
727 modules.append( cbl ); \
729 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
730 cbl->checkBox->setChecked( true ); \
734 void ModuleListConfigControl::finish( bool bycat )
738 /* build a list of available modules */
739 module_t **p_list = module_list_get( NULL );
740 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
744 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
747 module_config_t *p_config = module_config_get (p_parser, &confsize);
749 for (size_t i = 0; i < confsize; i++)
751 module_config_t *p_cfg = p_config + i;
752 /* Hack: required subcategory is stored in i_min */
753 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
754 p_cfg->value.i == p_item->min.i )
759 module_config_free (p_config);
761 else if( module_provides( p_parser, p_item->psz_type ) )
766 module_list_free( p_list );
768 if( p_item->psz_longtext )
770 QString tipText = qtr(p_item->psz_longtext);
772 text->setToolTip( formatTooltip(tipText) );
774 groupBox->setToolTip( formatTooltip(tipText) );
777 #undef CHECKBOX_LISTS
779 QString ModuleListConfigControl::getValue() const
785 void ModuleListConfigControl::hide()
787 foreach ( checkBoxListItem *it, modules )
788 it->checkBox->hide();
792 void ModuleListConfigControl::show()
794 foreach ( checkBoxListItem *it, modules )
795 it->checkBox->show();
800 void ModuleListConfigControl::onUpdate()
805 foreach ( checkBoxListItem *it, modules )
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 *************************************************************************/
827 VIntConfigControl::doApply()
829 config_PutInt( p_this, getName(), getValue() );
832 /*********** Integer **************/
833 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
834 module_config_t *_p_item,
835 QWidget *_parent, QGridLayout *l,
837 VIntConfigControl( _p_this, _p_item, _parent )
839 label = new QLabel( qtr(p_item->psz_text) );
840 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
841 spin->setAlignment( Qt::AlignRight );
842 spin->setMaximumWidth( MINWIDTH_BOX );
847 QHBoxLayout *layout = new QHBoxLayout();
848 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
849 widget->setLayout( layout );
853 l->addWidget( label, line, 0 );
854 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
857 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
858 module_config_t *_p_item,
859 QLabel *_label, QSpinBox *_spin ) :
860 VIntConfigControl( _p_this, _p_item )
867 void IntegerConfigControl::finish()
869 spin->setMaximum( 2000000000 );
870 spin->setMinimum( -2000000000 );
871 spin->setValue( p_item->value.i );
873 if( p_item->psz_longtext )
875 QString tipText = qtr(p_item->psz_longtext);
876 spin->setToolTip( formatTooltip(tipText) );
878 label->setToolTip( formatTooltip(tipText) );
881 label->setBuddy( spin );
884 int IntegerConfigControl::getValue() const
886 return spin->value();
889 /********* Integer range **********/
890 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
891 module_config_t *_p_item,
892 QWidget *_parent, QGridLayout *l,
894 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
899 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
900 module_config_t *_p_item,
901 QLabel *_label, QSpinBox *_spin ) :
902 IntegerConfigControl( _p_this, _p_item, _label, _spin )
907 void IntegerRangeConfigControl::finish()
909 spin->setMaximum( p_item->max.i );
910 spin->setMinimum( p_item->min.i );
913 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
914 vlc_object_t *_p_this,
915 module_config_t *_p_item,
916 QLabel *_label, QSlider *_slider ):
917 VIntConfigControl( _p_this, _p_item )
921 slider->setMaximum( p_item->max.i );
922 slider->setMinimum( p_item->min.i );
923 slider->setValue( p_item->value.i );
924 if( p_item->psz_longtext )
926 QString tipText = qtr(p_item->psz_longtext);
927 slider->setToolTip( formatTooltip(tipText) );
929 label->setToolTip( formatTooltip(tipText) );
932 label->setBuddy( slider );
935 int IntegerRangeSliderConfigControl::getValue() const
937 return slider->value();
941 /********* Integer / choice list **********/
942 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
943 module_config_t *_p_item, QWidget *_parent, bool,
944 QGridLayout *l, int line) :
945 VIntConfigControl( _p_this, _p_item, _parent )
947 label = new QLabel( qtr(p_item->psz_text) );
948 combo = new QComboBox();
949 combo->setMinimumWidth( MINWIDTH_BOX );
951 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
953 finish( p_module_config );
956 QHBoxLayout *layout = new QHBoxLayout();
957 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
958 widget->setLayout( layout );
962 l->addWidget( label, line, 0 );
963 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
966 if( p_item->i_action )
968 QSignalMapper *signalMapper = new QSignalMapper(this);
970 /* Some stringLists like Capture listings have action associated */
971 for( int i = 0; i < p_item->i_action; i++ )
973 QPushButton *button =
974 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
975 CONNECT( button, clicked(), signalMapper, map() );
976 signalMapper->setMapping( button, i );
977 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
980 CONNECT( signalMapper, mapped( int ),
981 this, actionRequested( int ) );
985 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
986 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
987 bool ) : VIntConfigControl( _p_this, _p_item )
992 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
994 finish( p_module_config );
997 void IntegerListConfigControl::finish(module_config_t *p_module_config )
999 combo->setEditable( false );
1001 if(!p_module_config) return;
1003 if( p_module_config->pf_update_list )
1006 val.i_int = p_module_config->value.i;
1008 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
1010 // assume in any case that dirty was set to true
1011 // because lazy programmes will use the same callback for
1012 // this, like the one behind the refresh push button?
1013 p_module_config->b_dirty = false;
1016 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
1018 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
1019 QVariant( p_module_config->pi_list[i_index] ) );
1020 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
1021 combo->setCurrentIndex( combo->count() - 1 );
1023 if( p_item->psz_longtext )
1025 QString tipText = qtr(p_item->psz_longtext );
1026 combo->setToolTip( formatTooltip(tipText) );
1028 label->setToolTip( formatTooltip(tipText) );
1031 label->setBuddy( combo );
1034 void IntegerListConfigControl::actionRequested( int i_action )
1036 /* Supplementary check for boundaries */
1037 if( i_action < 0 || i_action >= p_item->i_action ) return;
1039 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1040 if(!p_module_config) return;
1044 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
1046 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
1048 if( p_module_config->b_dirty )
1051 finish( p_module_config );
1052 p_module_config->b_dirty = false;
1056 int IntegerListConfigControl::getValue() const
1058 return combo->itemData( combo->currentIndex() ).toInt();
1061 /*********** Boolean **************/
1062 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1063 module_config_t *_p_item,
1064 QWidget *_parent, QGridLayout *l,
1066 VIntConfigControl( _p_this, _p_item, _parent )
1068 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1073 QHBoxLayout *layout = new QHBoxLayout();
1074 layout->addWidget( checkbox, 0 );
1075 widget->setLayout( layout );
1079 l->addWidget( checkbox, line, 0 );
1083 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1084 module_config_t *_p_item,
1086 QAbstractButton *_checkbox ) :
1087 VIntConfigControl( _p_this, _p_item )
1089 checkbox = _checkbox;
1090 VLC_UNUSED( _label );
1094 void BoolConfigControl::finish()
1096 checkbox->setChecked( p_item->value.i );
1097 if( p_item->psz_longtext )
1098 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1101 int BoolConfigControl::getValue() const
1103 return checkbox->isChecked();
1106 /**************************************************************************
1107 * Float-based controls
1108 *************************************************************************/
1111 VFloatConfigControl::doApply()
1113 config_PutFloat( p_this, getName(), getValue() );
1116 /*********** Float **************/
1117 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1118 module_config_t *_p_item,
1119 QWidget *_parent, QGridLayout *l,
1121 VFloatConfigControl( _p_this, _p_item, _parent )
1123 label = new QLabel( qtr(p_item->psz_text) );
1124 spin = new QDoubleSpinBox;
1125 spin->setMinimumWidth( MINWIDTH_BOX );
1126 spin->setMaximumWidth( MINWIDTH_BOX );
1127 spin->setAlignment( Qt::AlignRight );
1132 QHBoxLayout *layout = new QHBoxLayout();
1133 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1134 widget->setLayout( layout );
1138 l->addWidget( label, line, 0 );
1139 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1143 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1144 module_config_t *_p_item,
1146 QDoubleSpinBox *_spin ) :
1147 VFloatConfigControl( _p_this, _p_item )
1154 void FloatConfigControl::finish()
1156 spin->setMaximum( 2000000000. );
1157 spin->setMinimum( -2000000000. );
1158 spin->setSingleStep( 0.1 );
1159 spin->setValue( (double)p_item->value.f );
1160 if( p_item->psz_longtext )
1162 QString tipText = qtr(p_item->psz_longtext);
1163 spin->setToolTip( formatTooltip(tipText) );
1165 label->setToolTip( formatTooltip(tipText) );
1168 label->setBuddy( spin );
1171 float FloatConfigControl::getValue() const
1173 return (float)spin->value();
1176 /*********** Float with range **************/
1177 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1178 module_config_t *_p_item,
1179 QWidget *_parent, QGridLayout *l,
1181 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1186 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1187 module_config_t *_p_item,
1189 QDoubleSpinBox *_spin ) :
1190 FloatConfigControl( _p_this, _p_item, _label, _spin )
1195 void FloatRangeConfigControl::finish()
1197 spin->setMaximum( (double)p_item->max.f );
1198 spin->setMinimum( (double)p_item->min.f );
1202 /**********************************************************************
1203 * Key selector widget
1204 **********************************************************************/
1205 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1206 module_config_t *_p_item,
1207 QWidget *_parent, QGridLayout *l,
1209 ConfigControl( _p_this, _p_item, _parent )
1212 QWidget *keyContainer = new QWidget;
1213 QGridLayout *gLayout = new QGridLayout( keyContainer );
1216 qtr( "Select an action to change the associated hotkey") );
1218 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1219 actionSearch = new SearchLineEdit( keyContainer );
1221 table = new QTreeWidget;
1222 table->setColumnCount(3);
1223 table->headerItem()->setText( 0, qtr( "Action" ) );
1224 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1225 table->headerItem()->setText( 2, qtr( "Global" ) );
1226 table->setAlternatingRowColors( true );
1227 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1229 shortcutValue = new KeyShortcutEdit;
1230 shortcutValue->setReadOnly(true);
1232 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1233 QPushButton *setButton = new QPushButton( qtr( "Apply" ) );
1234 setButton->setDefault( true );
1237 gLayout->addWidget( label, 0, 0, 1, 4 );
1238 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1239 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1240 gLayout->addWidget( table, 2, 0, 1, 4 );
1241 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1242 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1243 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1245 l->addWidget( keyContainer, line, 0, 1, -1 );
1247 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1248 CONNECT( clearButton, clicked(), this, setTheKey() );
1249 BUTTONACT( setButton, setTheKey() );
1250 CONNECT( actionSearch, textChanged( const QString& ),
1251 this, filter( const QString& ) );
1254 void KeySelectorControl::finish()
1256 if( label && p_item->psz_longtext )
1257 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1259 /* Fill the table */
1261 /* Get the main Module */
1262 module_t *p_main = module_get_main();
1265 /* Access to the module_config_t */
1267 module_config_t *p_config;
1269 p_config = module_config_get (p_main, &confsize);
1271 for (size_t i = 0; i < confsize; i++)
1273 module_config_t *p_item = p_config + i;
1275 /* If we are a (non-global) key option not empty */
1276 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1277 && !strncmp( p_item->psz_name , "key-", 4 )
1278 && !EMPTY_STR( p_item->psz_text ) )
1282 - QString text in column 0
1283 - QString name in data of column 0
1284 - KeyValue in String in column 1
1286 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1287 treeItem->setText( 0, qtr( p_item->psz_text ) );
1288 treeItem->setData( 0, Qt::UserRole,
1289 QVariant( qfu( p_item->psz_name ) ) );
1291 QString keys = qfu( p_item->value.psz );
1292 treeItem->setText( 1, keys );
1293 treeItem->setData( 1, Qt::UserRole, QVariant( keys ) );
1294 table->addTopLevelItem( treeItem );
1298 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1299 && !strncmp( p_item->psz_name , "global-key", 10 )
1300 && !EMPTY_STR( p_item->psz_text ) )
1302 QList<QTreeWidgetItem *> list =
1303 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1304 if( list.count() >= 1 )
1306 QString keys = qfu( p_item->value.psz );
1307 list[0]->setText( 2, keys );
1308 list[0]->setData( 2, Qt::UserRole, keys );
1310 if( list.count() >= 2 )
1311 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1314 module_config_free (p_config);
1316 table->resizeColumnToContents( 0 );
1318 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1319 this, selectKey( QTreeWidgetItem *, int ) );
1320 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1321 this, select( QTreeWidgetItem *, int) );
1322 CONNECT( table, itemSelectionChanged(),
1323 this, select1Key() );
1325 CONNECT( shortcutValue, pressed(), this, selectKey() );
1328 void KeySelectorControl::filter( const QString &qs_search )
1330 QList<QTreeWidgetItem *> resultList =
1331 table->findItems( qs_search, Qt::MatchContains, 0 );
1332 for( int i = 0; i < table->topLevelItemCount(); i++ )
1334 table->topLevelItem( i )->setHidden(
1335 !resultList.contains( table->topLevelItem( i ) ) );
1339 void KeySelectorControl::select( QTreeWidgetItem *, int column )
1341 shortcutValue->setGlobal( column == 2 );
1344 /* Show the key selected from the table in the keySelector */
1345 void KeySelectorControl::select1Key()
1347 QTreeWidgetItem *keyItem = table->currentItem();
1348 shortcutValue->setText( keyItem->text( 1 ) );
1349 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toString() );
1350 shortcutValue->setGlobal( false );
1353 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1355 /* This happens when triggered by ClickEater */
1356 if( keyItem == NULL ) keyItem = table->currentItem();
1358 /* This can happen when nothing is selected on the treeView
1359 and the shortcutValue is clicked */
1360 if( !keyItem ) return;
1362 /* If clicked on the first column, assuming user wants the normal hotkey */
1363 if( column == 0 ) column = 1;
1365 bool b_global = ( column == 2 );
1367 /* Launch a small dialog to ask for a new key */
1368 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1371 if( d->result() == QDialog::Accepted )
1373 QString newKey = VLCKeyToString( d->keyValue );
1374 shortcutValue->setText( newKey );
1375 shortcutValue->setValue( newKey );
1376 shortcutValue->setGlobal( b_global );
1380 QTreeWidgetItem *it;
1381 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1383 it = table->topLevelItem(i);
1384 if( ( keyItem != it ) &&
1385 ( it->data( 1 + b_global, Qt::UserRole ).toString() == newKey ) )
1387 it->setData( 1 + b_global, Qt::UserRole,
1388 QVariant( qfu( "Unset" ) ) );
1389 it->setText( 1 + b_global, qtr( "Unset" ) );
1392 /* We already made an OK once. */
1399 void KeySelectorControl::setTheKey()
1401 if( !table->currentItem() ) return;
1402 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1403 shortcutValue->text() );
1404 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1405 Qt::UserRole, shortcutValue->getValue() );
1408 void KeySelectorControl::doApply()
1410 QTreeWidgetItem *it;
1411 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1413 it = table->topLevelItem(i);
1414 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1415 config_PutPsz( p_this,
1416 qtu( it->data( 0, Qt::UserRole ).toString() ),
1417 qtu( it->data( 1, Qt::UserRole ).toString() ) );
1418 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1419 config_PutPsz( p_this,
1420 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1421 qtu( it->data( 2, Qt::UserRole ).toString() ) );
1427 * Class KeyInputDialog
1429 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1430 const QString& keyToChange,
1433 QDialog( _parent ), keyValue(0), b_global( _b_global )
1439 setWindowTitle( b_global ? qtr( "Global" ): ""
1440 + qtr( "Hotkey for " ) + keyToChange );
1441 setWindowRole( "vlc-key-input" );
1443 vLayout = new QVBoxLayout( this );
1444 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1445 vLayout->addWidget( selected , Qt::AlignCenter );
1447 warning = new QLabel;
1449 vLayout->insertWidget( 1, warning );
1451 buttonBox = new QDialogButtonBox;
1452 QPushButton *ok = new QPushButton( qtr("OK") );
1453 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1454 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1455 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1456 ok->setDefault( true );
1458 vLayout->addWidget( buttonBox );
1461 CONNECT( buttonBox, accepted(), this, accept() );
1462 CONNECT( buttonBox, rejected(), this, reject() );
1465 void KeyInputDialog::checkForConflicts( int i_vlckey )
1467 QList<QTreeWidgetItem *> conflictList =
1468 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1471 if( conflictList.count() &&
1472 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1473 /* Avoid 0 or -1 that are the "Unset" states */
1475 warning->setText( qtr("Warning: the key is already assigned to \"") +
1476 conflictList[0]->text( 0 ) + "\"" );
1485 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1487 if( e->key() == Qt::Key_Tab ||
1488 e->key() == Qt::Key_Shift ||
1489 e->key() == Qt::Key_Control ||
1490 e->key() == Qt::Key_Meta ||
1491 e->key() == Qt::Key_Alt ||
1492 e->key() == Qt::Key_AltGr )
1494 int i_vlck = qtEventToVLCKey( e );
1495 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1496 checkForConflicts( i_vlck );
1500 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1502 int i_vlck = qtWheelEventToVLCKey( e );
1503 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1504 checkForConflicts( i_vlck );
1508 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)