1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * - Finish implementation (see WX, there might be missing a
29 * i_action handler for IntegerLists, but I don't see any module using it...
30 * - Improvements over WX
31 * - Validator for modulelist
37 #include "components/preferences_widgets.hpp"
38 #include "util/customwidgets.hpp"
39 #include "util/searchlineedit.hpp"
40 #include "util/qt_dirs.hpp"
42 #include <vlc_intf_strings.h>
43 #include <vlc_modules.h>
47 #include <QGridLayout>
49 #include <QFileDialog>
51 #include <QTreeWidgetItem>
52 #include <QSignalMapper>
53 #include <QDialogButtonBox>
56 #define MINWIDTH_BOX 90
57 #define LAST_COLUMN 10
59 QString formatTooltip(const QString & tooltip)
62 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
63 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
64 "<body style=\" font-family:'Sans Serif'; "
65 "font-style:normal; text-decoration:none;\">"
66 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
67 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
73 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
74 module_config_t *p_item,
78 return createControl( p_this, p_item, parent, NULL, i );
81 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
82 module_config_t *p_item,
84 QGridLayout *l, int &line )
86 ConfigControl *p_control = NULL;
88 switch( p_item->i_type )
90 case CONFIG_ITEM_MODULE:
91 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
94 case CONFIG_ITEM_MODULE_CAT:
95 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
98 case CONFIG_ITEM_MODULE_LIST:
99 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
102 case CONFIG_ITEM_MODULE_LIST_CAT:
103 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
106 case CONFIG_ITEM_STRING:
107 if( !p_item->i_list )
108 p_control = new StringConfigControl( p_this, p_item, parent,
111 p_control = new StringListConfigControl( p_this, p_item,
112 parent, false, l, line );
114 case CONFIG_ITEM_PASSWORD:
115 if( !p_item->i_list )
116 p_control = new StringConfigControl( p_this, p_item, parent,
119 p_control = new StringListConfigControl( p_this, p_item,
120 parent, true, l, line );
122 case CONFIG_ITEM_INTEGER:
124 p_control = new IntegerListConfigControl( p_this, p_item,
125 parent, false, l, line );
126 else if( p_item->min.i || p_item->max.i )
127 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
130 p_control = new IntegerConfigControl( p_this, p_item, parent,
133 case CONFIG_ITEM_LOADFILE:
134 case CONFIG_ITEM_SAVEFILE:
135 p_control = new FileConfigControl( p_this, p_item, parent, l, line);
137 case CONFIG_ITEM_DIRECTORY:
138 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
141 case CONFIG_ITEM_FONT:
142 p_control = new FontConfigControl( p_this, p_item, parent, l,
145 case CONFIG_ITEM_KEY:
146 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
148 case CONFIG_ITEM_BOOL:
149 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
151 case CONFIG_ITEM_FLOAT:
152 if( p_item->min.f || p_item->max.f )
153 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
156 p_control = new FloatConfigControl( p_this, p_item, parent,
165 void ConfigControl::doApply( intf_thread_t *p_intf )
169 case CONFIG_ITEM_INTEGER:
170 case CONFIG_ITEM_BOOL:
172 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
174 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
177 case CONFIG_ITEM_FLOAT:
179 VFloatConfigControl *vfcc =
180 qobject_cast<VFloatConfigControl *>(this);
182 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
185 case CONFIG_ITEM_STRING:
187 VStringConfigControl *vscc =
188 qobject_cast<VStringConfigControl *>(this);
190 config_PutPsz( p_intf, vscc->getName(), qtu( vscc->getValue() ) );
193 case CONFIG_ITEM_KEY:
195 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
202 /*******************************************************
204 *******************************************************/
205 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
207 setGeometry( 0, 0, 128, 100 );
208 setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
211 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
213 setPreview( ( b_minimal )?MINIMAL:COMPLETE );
216 void InterfacePreviewWidget::setPreview( enum_style e_style )
218 QString pixmapLocationString(":/prefsmenu/");
224 pixmapLocationString += "sample_complete";
227 pixmapLocationString += "sample_minimal";
230 pixmapLocationString += "sample_skins";
234 setPixmap( QPixmap( pixmapLocationString ) );
240 /**************************************************************************
241 * String-based controls
242 *************************************************************************/
244 /*********** String **************/
245 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
246 module_config_t *_p_item,
247 QWidget *_parent, QGridLayout *l,
248 int &line, bool pwd ) :
249 VStringConfigControl( _p_this, _p_item, _parent )
251 label = new QLabel( qtr(p_item->psz_text) );
252 text = new QLineEdit( qfu(p_item->value.psz) );
253 if( pwd ) text->setEchoMode( QLineEdit::Password );
258 QHBoxLayout *layout = new QHBoxLayout();
259 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
260 layout->addWidget( text, LAST_COLUMN );
261 widget->setLayout( layout );
265 l->addWidget( label, line, 0 );
266 l->setColumnMinimumWidth( 1, 10 );
267 l->addWidget( text, line, LAST_COLUMN );
271 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
272 module_config_t *_p_item,
273 QLabel *_label, QLineEdit *_text, bool pwd ):
274 VStringConfigControl( _p_this, _p_item )
277 if( pwd ) text->setEchoMode( QLineEdit::Password );
282 void StringConfigControl::finish()
284 text->setText( qfu(p_item->value.psz) );
285 if( p_item->psz_longtext )
287 QString tipText = qtr(p_item->psz_longtext);
288 text->setToolTip( formatTooltip(tipText) );
290 label->setToolTip( formatTooltip(tipText) );
293 label->setBuddy( text );
296 /*********** File **************/
297 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
298 module_config_t *_p_item,
299 QWidget *_parent, QGridLayout *l,
301 VStringConfigControl( _p_this, _p_item, _parent )
303 label = new QLabel( qtr(p_item->psz_text) );
304 text = new QLineEdit( qfu(p_item->value.psz) );
305 browse = new QPushButton( qtr( "Browse..." ) );
306 QHBoxLayout *textAndButton = new QHBoxLayout();
307 textAndButton->setMargin( 0 );
308 textAndButton->addWidget( text, 2 );
309 textAndButton->addWidget( browse, 0 );
311 BUTTONACT( browse, updateField() );
317 QHBoxLayout *layout = new QHBoxLayout();
318 layout->addWidget( label, 0 );
319 layout->insertSpacing( 1, 10 );
320 layout->addLayout( textAndButton, LAST_COLUMN );
321 widget->setLayout( layout );
325 l->addWidget( label, line, 0 );
326 l->setColumnMinimumWidth( 1, 10 );
327 l->addLayout( textAndButton, line, LAST_COLUMN );
332 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
333 module_config_t *_p_item,
334 QLabel *_label, QLineEdit *_text,
335 QPushButton *_button ):
336 VStringConfigControl( _p_this, _p_item )
342 BUTTONACT( browse, updateField() );
347 void FileConfigControl::updateField()
351 if (p_item->i_type == CONFIG_ITEM_SAVEFILE)
352 file = QFileDialog::getSaveFileName( NULL, qtr( "Save File" ),
353 QVLCUserDir( VLC_HOME_DIR ) );
355 file = QFileDialog::getOpenFileName( NULL, qtr( "Select File" ),
356 QVLCUserDir( VLC_HOME_DIR ) );
358 if( file.isNull() ) return;
359 text->setText( toNativeSeparators( file ) );
362 void FileConfigControl::finish()
364 text->setText( qfu(p_item->value.psz) );
365 if( p_item->psz_longtext )
367 QString tipText = qtr(p_item->psz_longtext);
368 text->setToolTip( formatTooltip(tipText) );
370 label->setToolTip( formatTooltip(tipText) );
373 label->setBuddy( text );
376 /********* String / Directory **********/
377 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
378 module_config_t *_p_item, QWidget *_p_widget,
379 QGridLayout *_p_layout, int& _int ) :
380 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int )
383 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
384 module_config_t *_p_item, QLabel *_p_label,
385 QLineEdit *_p_line, QPushButton *_p_button ):
386 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
389 void DirectoryConfigControl::updateField()
391 QString dir = QFileDialog::getExistingDirectory( NULL,
393 text->text().isEmpty() ?
394 QVLCUserDir( VLC_HOME_DIR ) : text->text(),
395 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
397 if( dir.isNull() ) return;
398 text->setText( toNativeSepNoSlash( dir ) );
401 /********* String / Font **********/
402 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
403 module_config_t *_p_item, QWidget *_parent,
404 QGridLayout *_p_layout, int& line) :
405 VStringConfigControl( _p_this, _p_item, _parent )
407 label = new QLabel( qtr(p_item->psz_text) );
408 font = new QFontComboBox( _parent );
409 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
412 QHBoxLayout *layout = new QHBoxLayout();
413 layout->addWidget( label, 0 );
414 layout->addWidget( font, 1 );
415 widget->setLayout( layout );
419 _p_layout->addWidget( label, line, 0 );
420 _p_layout->addWidget( font, line, 1, 1, -1 );
424 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
425 module_config_t *_p_item, QLabel *_p_label,
426 QFontComboBox *_p_font):
427 VStringConfigControl( _p_this, _p_item)
431 font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
434 /********* String / choice list **********/
435 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
436 module_config_t *_p_item, QWidget *_parent, bool bycat,
437 QGridLayout *l, int &line) :
438 VStringConfigControl( _p_this, _p_item, _parent )
440 label = new QLabel( qtr(p_item->psz_text) );
441 combo = new QComboBox();
442 combo->setMinimumWidth( MINWIDTH_BOX );
443 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
445 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
447 finish( p_module_config, bycat );
450 l = new QGridLayout();
451 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
452 widget->setLayout( l );
456 l->addWidget( label, line, 0 );
457 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
460 if( p_item->i_action )
462 QSignalMapper *signalMapper = new QSignalMapper(this);
464 /* Some stringLists like Capture listings have action associated */
465 for( int i = 0; i < p_item->i_action; i++ )
467 QPushButton *button =
468 new QPushButton( qtr( p_item->ppsz_action_text[i] ));
469 CONNECT( button, clicked(), signalMapper, map() );
470 signalMapper->setMapping( button, i );
471 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
474 CONNECT( signalMapper, mapped( int ),
475 this, actionRequested( int ) );
479 void StringListConfigControl::actionRequested( int i_action )
481 /* Supplementary check for boundaries */
482 if( i_action < 0 || i_action >= p_item->i_action ) return;
484 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
485 if(!p_module_config) return;
488 val.psz_string = const_cast<char *>
489 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
491 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
493 if( p_module_config->b_dirty )
496 finish( p_module_config, true );
497 p_module_config->b_dirty = false;
500 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
501 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
502 bool bycat ) : VStringConfigControl( _p_this, _p_item )
507 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
509 finish( p_module_config, bycat );
512 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
514 combo->setEditable( false );
516 if(!p_module_config) return;
518 if( p_module_config->pf_update_list )
521 val.psz_string = strdup(p_module_config->value.psz);
523 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
525 // assume in any case that dirty was set to true
526 // because lazy programmes will use the same callback for
527 // this, like the one behind the refresh push button?
528 p_module_config->b_dirty = false;
530 free( val.psz_string );
533 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
535 if( !p_module_config->ppsz_list[i_index] )
537 combo->addItem( "", QVariant(""));
538 if( !p_item->value.psz )
539 combo->setCurrentIndex( combo->count() - 1 );
542 combo->addItem( qfu((p_module_config->ppsz_list_text &&
543 p_module_config->ppsz_list_text[i_index])?
544 _(p_module_config->ppsz_list_text[i_index]) :
545 p_module_config->ppsz_list[i_index] ),
546 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
547 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
548 p_module_config->ppsz_list[i_index] ) )
549 combo->setCurrentIndex( combo->count() - 1 );
552 if( p_module_config->psz_longtext )
554 QString tipText = qtr(p_module_config->psz_longtext);
555 combo->setToolTip( formatTooltip(tipText) );
557 label->setToolTip( formatTooltip(tipText) );
560 label->setBuddy( combo );
563 QString StringListConfigControl::getValue() const
565 return combo->itemData( combo->currentIndex() ).toString();
568 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
571 module_config_t *p_config =
572 config_FindConfig( VLC_OBJECT(p_intf), configname );
575 if(p_config->pf_update_list)
578 val.i_int = p_config->value.i;
579 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
580 // assume in any case that dirty was set to true
581 // because lazy programmes will use the same callback for
582 // this, like the one behind the refresh push button?
583 p_config->b_dirty = false;
586 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
588 combo->addItem( qtr(p_config->ppsz_list_text[i_index]),
589 QVariant( p_config->pi_list[i_index] ) );
590 if( p_config->value.i == p_config->pi_list[i_index] )
592 combo->setCurrentIndex( i_index );
596 if( p_config->psz_longtext )
597 combo->setToolTip( qfu( p_config->psz_longtext ) );
601 /********* Module **********/
602 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
603 module_config_t *_p_item, QWidget *_parent, bool bycat,
604 QGridLayout *l, int &line) :
605 VStringConfigControl( _p_this, _p_item, _parent )
607 label = new QLabel( qtr(p_item->psz_text) );
608 combo = new QComboBox();
609 combo->setMinimumWidth( MINWIDTH_BOX );
613 QHBoxLayout *layout = new QHBoxLayout();
614 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
615 widget->setLayout( layout );
619 l->addWidget( label, line, 0 );
620 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
624 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
625 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
626 bool bycat ) : VStringConfigControl( _p_this, _p_item )
633 void ModuleConfigControl::finish( bool bycat )
637 combo->setEditable( false );
639 /* build a list of available modules */
640 module_t **p_list = module_list_get( NULL );
641 combo->addItem( qtr("Default") );
642 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
646 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
649 module_config_t *p_config;
651 p_config = module_config_get (p_parser, &confsize);
652 for (size_t i = 0; i < confsize; i++)
654 /* Hack: required subcategory is stored in i_min */
655 const module_config_t *p_cfg = p_config + i;
656 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
657 p_cfg->value.i == p_item->min.i )
658 combo->addItem( qtr( module_GetLongName( p_parser )),
659 QVariant( module_get_object( p_parser ) ) );
660 if( p_item->value.psz && !strcmp( p_item->value.psz,
661 module_get_object( p_parser ) ) )
662 combo->setCurrentIndex( combo->count() - 1 );
664 module_config_free (p_config);
666 else if( module_provides( p_parser, p_item->psz_type ) )
668 combo->addItem( qtr(module_GetLongName( p_parser ) ),
669 QVariant( module_get_object( p_parser ) ) );
670 if( p_item->value.psz && !strcmp( p_item->value.psz,
671 module_get_object( p_parser ) ) )
672 combo->setCurrentIndex( combo->count() - 1 );
675 module_list_free( p_list );
677 if( p_item->psz_longtext )
679 QString tipText = qtr(p_item->psz_longtext);
680 combo->setToolTip( formatTooltip(tipText) );
682 label->setToolTip( formatTooltip(tipText) );
685 label->setBuddy( combo );
688 QString ModuleConfigControl::getValue() const
690 return combo->itemData( combo->currentIndex() ).toString();
693 /********* Module list **********/
694 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
695 module_config_t *_p_item, QWidget *_parent, bool bycat,
696 QGridLayout *l, int &line) :
697 VStringConfigControl( _p_this, _p_item, _parent )
701 if( !p_item->psz_text ) return;
703 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
704 text = new QLineEdit;
705 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
710 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
711 it != modules.end(); ++it )
713 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
715 layoutGroupBox->addWidget( text, boxline, 0 );
719 QVBoxLayout *layout = new QVBoxLayout();
720 layout->addWidget( groupBox, line, 0 );
721 widget->setLayout( layout );
725 l->addWidget( groupBox, line, 0, 1, -1 );
728 if( p_item->psz_longtext )
729 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
732 ModuleListConfigControl::~ModuleListConfigControl()
734 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
735 it != modules.end(); ++it )
742 #define CHECKBOX_LISTS \
744 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
745 checkBoxListItem *cbl = new checkBoxListItem; \
747 CONNECT( cb, stateChanged( int ), this, onUpdate() );\
748 const char *help = module_get_help( p_parser ); \
750 cb->setToolTip( formatTooltip( qtr( help ) ) ); \
751 cbl->checkBox = cb; \
753 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
754 modules.push_back( cbl ); \
756 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
757 cbl->checkBox->setChecked( true ); \
761 void ModuleListConfigControl::finish( bool bycat )
765 /* build a list of available modules */
766 module_t **p_list = module_list_get( NULL );
767 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
771 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
774 module_config_t *p_config = module_config_get (p_parser, &confsize);
776 for (size_t i = 0; i < confsize; i++)
778 module_config_t *p_cfg = p_config + i;
779 /* Hack: required subcategory is stored in i_min */
780 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
781 p_cfg->value.i == p_item->min.i )
786 module_config_free (p_config);
788 else if( module_provides( p_parser, p_item->psz_type ) )
793 module_list_free( p_list );
795 if( p_item->psz_longtext )
797 QString tipText = qtr(p_item->psz_longtext);
799 text->setToolTip( formatTooltip(tipText) );
801 groupBox->setToolTip( formatTooltip(tipText) );
804 #undef CHECKBOX_LISTS
806 QString ModuleListConfigControl::getValue() const
812 void ModuleListConfigControl::hide()
814 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
815 it != modules.end(); ++it )
817 (*it)->checkBox->hide();
822 void ModuleListConfigControl::show()
824 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
825 it != modules.end(); ++it )
827 (*it)->checkBox->show();
833 void ModuleListConfigControl::onUpdate()
838 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
839 it != modules.end(); ++it )
841 if( (*it)->checkBox->isChecked() )
845 text->setText( text->text() + (*it)->psz_module );
850 text->setText( text->text() + ":" + (*it)->psz_module );
856 /**************************************************************************
857 * Integer-based controls
858 *************************************************************************/
860 /*********** Integer **************/
861 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
862 module_config_t *_p_item,
863 QWidget *_parent, QGridLayout *l,
865 VIntConfigControl( _p_this, _p_item, _parent )
867 label = new QLabel( qtr(p_item->psz_text) );
868 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
869 spin->setAlignment( Qt::AlignRight );
870 spin->setMaximumWidth( MINWIDTH_BOX );
875 QHBoxLayout *layout = new QHBoxLayout();
876 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
877 widget->setLayout( layout );
881 l->addWidget( label, line, 0 );
882 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
885 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
886 module_config_t *_p_item,
887 QLabel *_label, QSpinBox *_spin ) :
888 VIntConfigControl( _p_this, _p_item )
895 void IntegerConfigControl::finish()
897 spin->setMaximum( 2000000000 );
898 spin->setMinimum( -2000000000 );
899 spin->setValue( p_item->value.i );
901 if( p_item->psz_longtext )
903 QString tipText = qtr(p_item->psz_longtext);
904 spin->setToolTip( formatTooltip(tipText) );
906 label->setToolTip( formatTooltip(tipText) );
909 label->setBuddy( spin );
912 int IntegerConfigControl::getValue() const
914 return spin->value();
917 /********* Integer range **********/
918 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
919 module_config_t *_p_item,
920 QWidget *_parent, QGridLayout *l,
922 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
927 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
928 module_config_t *_p_item,
929 QLabel *_label, QSpinBox *_spin ) :
930 IntegerConfigControl( _p_this, _p_item, _label, _spin )
935 void IntegerRangeConfigControl::finish()
937 spin->setMaximum( p_item->max.i );
938 spin->setMinimum( p_item->min.i );
941 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
942 vlc_object_t *_p_this,
943 module_config_t *_p_item,
944 QLabel *_label, QSlider *_slider ):
945 VIntConfigControl( _p_this, _p_item )
949 slider->setMaximum( p_item->max.i );
950 slider->setMinimum( p_item->min.i );
951 slider->setValue( p_item->value.i );
952 if( p_item->psz_longtext )
954 QString tipText = qtr(p_item->psz_longtext);
955 slider->setToolTip( formatTooltip(tipText) );
957 label->setToolTip( formatTooltip(tipText) );
960 label->setBuddy( slider );
963 int IntegerRangeSliderConfigControl::getValue() const
965 return slider->value();
969 /********* Integer / choice list **********/
970 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
971 module_config_t *_p_item, QWidget *_parent, bool bycat,
972 QGridLayout *l, int &line) :
973 VIntConfigControl( _p_this, _p_item, _parent )
975 label = new QLabel( qtr(p_item->psz_text) );
976 combo = new QComboBox();
977 combo->setMinimumWidth( MINWIDTH_BOX );
979 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
981 finish( p_module_config, bycat );
984 QHBoxLayout *layout = new QHBoxLayout();
985 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
986 widget->setLayout( layout );
990 l->addWidget( label, line, 0 );
991 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
994 if( p_item->i_action )
996 QSignalMapper *signalMapper = new QSignalMapper(this);
998 /* Some stringLists like Capture listings have action associated */
999 for( int i = 0; i < p_item->i_action; i++ )
1001 QPushButton *button =
1002 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
1003 CONNECT( button, clicked(), signalMapper, map() );
1004 signalMapper->setMapping( button, i );
1005 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
1008 CONNECT( signalMapper, mapped( int ),
1009 this, actionRequested( int ) );
1013 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
1014 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
1015 bool bycat ) : VIntConfigControl( _p_this, _p_item )
1020 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1022 finish( p_module_config, bycat );
1025 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
1027 combo->setEditable( false );
1029 if(!p_module_config) return;
1031 if( p_module_config->pf_update_list )
1034 val.i_int = p_module_config->value.i;
1036 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
1038 // assume in any case that dirty was set to true
1039 // because lazy programmes will use the same callback for
1040 // this, like the one behind the refresh push button?
1041 p_module_config->b_dirty = false;
1044 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
1046 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
1047 QVariant( p_module_config->pi_list[i_index] ) );
1048 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
1049 combo->setCurrentIndex( combo->count() - 1 );
1051 if( p_item->psz_longtext )
1053 QString tipText = qtr(p_item->psz_longtext );
1054 combo->setToolTip( formatTooltip(tipText) );
1056 label->setToolTip( formatTooltip(tipText) );
1059 label->setBuddy( combo );
1062 void IntegerListConfigControl::actionRequested( int i_action )
1064 /* Supplementary check for boundaries */
1065 if( i_action < 0 || i_action >= p_item->i_action ) return;
1067 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
1068 if(!p_module_config) return;
1072 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
1074 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
1076 if( p_module_config->b_dirty )
1079 finish( p_module_config, true );
1080 p_module_config->b_dirty = false;
1084 int IntegerListConfigControl::getValue() const
1086 return combo->itemData( combo->currentIndex() ).toInt();
1089 /*********** Boolean **************/
1090 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1091 module_config_t *_p_item,
1092 QWidget *_parent, QGridLayout *l,
1094 VIntConfigControl( _p_this, _p_item, _parent )
1096 checkbox = new QCheckBox( qtr(p_item->psz_text) );
1101 QHBoxLayout *layout = new QHBoxLayout();
1102 layout->addWidget( checkbox, 0 );
1103 widget->setLayout( layout );
1107 l->addWidget( checkbox, line, 0 );
1111 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
1112 module_config_t *_p_item,
1114 QAbstractButton *_checkbox,
1116 VIntConfigControl( _p_this, _p_item )
1118 checkbox = _checkbox;
1119 VLC_UNUSED( _label );
1123 void BoolConfigControl::finish()
1125 checkbox->setChecked( p_item->value.i );
1126 if( p_item->psz_longtext )
1127 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1130 int BoolConfigControl::getValue() const
1132 return checkbox->isChecked();
1135 /**************************************************************************
1136 * Float-based controls
1137 *************************************************************************/
1139 /*********** Float **************/
1140 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1141 module_config_t *_p_item,
1142 QWidget *_parent, QGridLayout *l,
1144 VFloatConfigControl( _p_this, _p_item, _parent )
1146 label = new QLabel( qtr(p_item->psz_text) );
1147 spin = new QDoubleSpinBox;
1148 spin->setMinimumWidth( MINWIDTH_BOX );
1149 spin->setMaximumWidth( MINWIDTH_BOX );
1150 spin->setAlignment( Qt::AlignRight );
1155 QHBoxLayout *layout = new QHBoxLayout();
1156 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1157 widget->setLayout( layout );
1161 l->addWidget( label, line, 0 );
1162 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1166 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1167 module_config_t *_p_item,
1169 QDoubleSpinBox *_spin ) :
1170 VFloatConfigControl( _p_this, _p_item )
1177 void FloatConfigControl::finish()
1179 spin->setMaximum( 2000000000. );
1180 spin->setMinimum( -2000000000. );
1181 spin->setSingleStep( 0.1 );
1182 spin->setValue( (double)p_item->value.f );
1183 if( p_item->psz_longtext )
1185 QString tipText = qtr(p_item->psz_longtext);
1186 spin->setToolTip( formatTooltip(tipText) );
1188 label->setToolTip( formatTooltip(tipText) );
1191 label->setBuddy( spin );
1194 float FloatConfigControl::getValue() const
1196 return (float)spin->value();
1199 /*********** Float with range **************/
1200 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1201 module_config_t *_p_item,
1202 QWidget *_parent, QGridLayout *l,
1204 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1209 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1210 module_config_t *_p_item,
1212 QDoubleSpinBox *_spin ) :
1213 FloatConfigControl( _p_this, _p_item, _label, _spin )
1218 void FloatRangeConfigControl::finish()
1220 spin->setMaximum( (double)p_item->max.f );
1221 spin->setMinimum( (double)p_item->min.f );
1225 /**********************************************************************
1226 * Key selector widget
1227 **********************************************************************/
1228 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1229 module_config_t *_p_item,
1230 QWidget *_parent, QGridLayout *l,
1232 ConfigControl( _p_this, _p_item, _parent )
1235 QWidget *keyContainer = new QWidget;
1236 QGridLayout *gLayout = new QGridLayout( keyContainer );
1239 qtr( "Select an action to change the associated hotkey") );
1241 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1242 actionSearch = new SearchLineEdit( keyContainer );
1244 table = new QTreeWidget;
1245 table->setColumnCount(3);
1246 table->headerItem()->setText( 0, qtr( "Action" ) );
1247 table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1248 table->headerItem()->setText( 2, qtr( "Global" ) );
1249 table->setAlternatingRowColors( true );
1250 table->setSelectionBehavior( QAbstractItemView::SelectItems );
1252 shortcutValue = new KeyShortcutEdit;
1253 shortcutValue->setReadOnly(true);
1255 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1256 QPushButton *setButton = new QPushButton( qtr( "Apply" ) );
1257 setButton->setDefault( true );
1260 gLayout->addWidget( label, 0, 0, 1, 4 );
1261 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1262 gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1263 gLayout->addWidget( table, 2, 0, 1, 4 );
1264 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1265 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1266 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1268 l->addWidget( keyContainer, line, 0, 1, -1 );
1270 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1271 CONNECT( clearButton, clicked(), this, setTheKey() );
1272 BUTTONACT( setButton, setTheKey() );
1273 CONNECT( actionSearch, textChanged( const QString& ),
1274 this, filter( const QString& ) );
1277 void KeySelectorControl::finish()
1279 if( label && p_item->psz_longtext )
1280 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1282 /* Fill the table */
1284 /* Get the main Module */
1285 module_t *p_main = module_get_main();
1288 /* Access to the module_config_t */
1290 module_config_t *p_config;
1292 p_config = module_config_get (p_main, &confsize);
1294 for (size_t i = 0; i < confsize; i++)
1296 module_config_t *p_item = p_config + i;
1298 /* If we are a (non-global) key option not empty */
1299 if( (p_item->i_type & CONFIG_ITEM) && p_item->psz_name != NULL
1300 && !strncmp( p_item->psz_name , "key-", 4 )
1301 && !EMPTY_STR( p_item->psz_text ) )
1305 - QString text in column 0
1306 - QString name in data of column 0
1307 - KeyValue in String in column 1
1309 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1310 treeItem->setText( 0, qtr( p_item->psz_text ) );
1311 treeItem->setData( 0, Qt::UserRole,
1312 QVariant( qfu( p_item->psz_name ) ) );
1314 QString keys = qfu( p_item->value.psz );
1315 treeItem->setText( 1, keys );
1316 treeItem->setData( 1, Qt::UserRole, QVariant( keys ) );
1317 table->addTopLevelItem( treeItem );
1321 if( (p_item->i_type & CONFIG_ITEM) && p_item->psz_name != NULL
1322 && !strncmp( p_item->psz_name , "global-key", 10 )
1323 && !EMPTY_STR( p_item->psz_text ) )
1325 QList<QTreeWidgetItem *> list =
1326 table->findItems( qtr( p_item->psz_text ), Qt::MatchExactly );
1327 if( list.count() >= 1 )
1329 QString keys = qfu( p_item->value.psz );
1330 list[0]->setText( 2, keys );
1331 list[0]->setData( 2, Qt::UserRole, keys );
1333 if( list.count() >= 2 )
1334 msg_Dbg( p_this, "This is probably wrong, %s", p_item->psz_text );
1337 module_config_free (p_config);
1338 module_release (p_main);
1340 table->resizeColumnToContents( 0 );
1342 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1343 this, selectKey( QTreeWidgetItem *, int ) );
1344 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1345 this, select( QTreeWidgetItem *, int) );
1346 CONNECT( table, itemSelectionChanged(),
1347 this, select1Key() );
1349 CONNECT( shortcutValue, pressed(), this, selectKey() );
1352 void KeySelectorControl::filter( const QString &qs_search )
1354 QList<QTreeWidgetItem *> resultList =
1355 table->findItems( qs_search, Qt::MatchContains, 0 );
1356 for( int i = 0; i < table->topLevelItemCount(); i++ )
1358 table->topLevelItem( i )->setHidden(
1359 !resultList.contains( table->topLevelItem( i ) ) );
1363 void KeySelectorControl::select( QTreeWidgetItem *keyItem, int column )
1365 shortcutValue->setGlobal( column == 2 );
1368 /* Show the key selected from the table in the keySelector */
1369 void KeySelectorControl::select1Key()
1371 QTreeWidgetItem *keyItem = table->currentItem();
1372 shortcutValue->setText( keyItem->text( 1 ) );
1373 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toString() );
1374 shortcutValue->setGlobal( false );
1377 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1379 /* This happens when triggered by ClickEater */
1380 if( keyItem == NULL ) keyItem = table->currentItem();
1382 /* This can happen when nothing is selected on the treeView
1383 and the shortcutValue is clicked */
1384 if( !keyItem ) return;
1386 /* If clicked on the first column, assuming user wants the normal hotkey */
1387 if( column == 0 ) column = 1;
1389 bool b_global = ( column == 2 );
1391 /* Launch a small dialog to ask for a new key */
1392 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
1395 if( d->result() == QDialog::Accepted )
1397 QString newKey = VLCKeyToString( d->keyValue );
1398 shortcutValue->setText( newKey );
1399 shortcutValue->setValue( newKey );
1400 shortcutValue->setGlobal( b_global );
1404 QTreeWidgetItem *it;
1405 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1407 it = table->topLevelItem(i);
1408 if( ( keyItem != it ) &&
1409 ( it->data( 1 + b_global, Qt::UserRole ).toString() == newKey ) )
1411 it->setData( 1 + b_global, Qt::UserRole,
1412 QVariant( qfu( "Unset" ) ) );
1413 it->setText( 1 + b_global, qtr( "Unset" ) );
1416 /* We already made an OK once. */
1423 void KeySelectorControl::setTheKey()
1425 if( !table->currentItem() ) return;
1426 table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
1427 shortcutValue->text() );
1428 table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
1429 Qt::UserRole, shortcutValue->getValue() );
1432 void KeySelectorControl::doApply()
1434 QTreeWidgetItem *it;
1435 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1437 it = table->topLevelItem(i);
1438 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1439 config_PutPsz( p_this,
1440 qtu( it->data( 0, Qt::UserRole ).toString() ),
1441 qtu( it->data( 1, Qt::UserRole ).toString() ) );
1442 if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
1443 config_PutPsz( p_this,
1444 qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1445 qtu( it->data( 2, Qt::UserRole ).toString() ) );
1451 * Class KeyInputDialog
1453 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1454 const QString& keyToChange,
1457 QDialog( _parent ), keyValue(0), b_global( _b_global )
1463 setWindowTitle( b_global ? qtr( "Global" ): ""
1464 + qtr( "Hotkey for " ) + keyToChange );
1465 setWindowRole( "vlc-key-input" );
1467 vLayout = new QVBoxLayout( this );
1468 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1469 vLayout->addWidget( selected , Qt::AlignCenter );
1471 warning = new QLabel;
1473 vLayout->insertWidget( 1, warning );
1475 buttonBox = new QDialogButtonBox;
1476 QPushButton *ok = new QPushButton( qtr("OK") );
1477 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1478 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1479 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1480 ok->setDefault( true );
1482 vLayout->addWidget( buttonBox );
1485 CONNECT( buttonBox, accepted(), this, accept() );
1486 CONNECT( buttonBox, rejected(), this, reject() );
1489 void KeyInputDialog::checkForConflicts( int i_vlckey )
1491 QList<QTreeWidgetItem *> conflictList =
1492 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1495 if( conflictList.size() &&
1496 conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
1497 /* Avoid 0 or -1 that are the "Unset" states */
1499 warning->setText( qtr("Warning: the key is already assigned to \"") +
1500 conflictList[0]->text( 0 ) + "\"" );
1509 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1511 if( e->key() == Qt::Key_Tab ||
1512 e->key() == Qt::Key_Shift ||
1513 e->key() == Qt::Key_Control ||
1514 e->key() == Qt::Key_Meta ||
1515 e->key() == Qt::Key_Alt ||
1516 e->key() == Qt::Key_AltGr )
1518 int i_vlck = qtEventToVLCKey( e );
1519 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1520 checkForConflicts( i_vlck );
1524 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1526 int i_vlck = qtWheelEventToVLCKey( e );
1527 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1528 checkForConflicts( i_vlck );
1532 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)