X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fpreferences_widgets.cpp;h=7531c77fe5864a9675ea22fd6d1e5005c4d0b7ca;hb=ef7c7e9569b302003bc93075a61c18b5f57e0c90;hp=e61d502b3f91c224daab5a3963b1e149a7528d50;hpb=b8bc19e5d1982165c6bc1db14c4fbfa7b5abf583;p=vlc diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp index e61d502b3f..7531c77fe5 100644 --- a/modules/gui/qt4/components/preferences_widgets.cpp +++ b/modules/gui/qt4/components/preferences_widgets.cpp @@ -1,11 +1,12 @@ /***************************************************************************** * preferences_widgets.cpp : Widgets for preferences displays **************************************************************************** - * Copyright (C) 2006 the VideoLAN team + * Copyright (C) 2006-2007 the VideoLAN team * $Id$ * * Authors: Clément Stenac * Antoine Cellerier + * Jean-Baptiste Kempf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,6 +44,8 @@ #include #include #include +#include +#include #include @@ -92,7 +95,7 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, if( p_item->i_list ) p_control = new IntegerListConfigControl( p_this, p_item, parent, false, l, line ); - else if( p_item->i_min || p_item->i_max ) + else if( p_item->min.i || p_item->max.i ) p_control = new IntegerRangeConfigControl( p_this, p_item, parent, l, line ); else @@ -100,10 +103,12 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, l, line ); break; case CONFIG_ITEM_FILE: - fprintf( stderr, "Todo (CONFIG_ITEM_FILE)\n" ); + p_control = new FileConfigControl( p_this, p_item, parent, l, + line, false ); break; case CONFIG_ITEM_DIRECTORY: - fprintf( stderr, "Todo (CONFIG_ITEM_DIRECTORY)\n" ); + p_control = new DirectoryConfigControl( p_this, p_item, parent, l, + line, false ); break; case CONFIG_ITEM_KEY: p_control = new KeySelectorControl( p_this, p_item, parent, l, line ); @@ -112,7 +117,7 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, p_control = new BoolConfigControl( p_this, p_item, parent, l, line ); break; case CONFIG_ITEM_FLOAT: - if( p_item->f_min || p_item->f_max ) + if( p_item->min.f || p_item->max.f ) p_control = new FloatRangeConfigControl( p_this, p_item, parent, l, line ); else @@ -173,7 +178,7 @@ StringConfigControl::StringConfigControl( vlc_object_t *_p_this, VStringConfigControl( _p_this, _p_item, _parent ) { label = new QLabel( qfu(p_item->psz_text) ); - text = new QLineEdit( qfu(p_item->psz_value) ); + text = new QLineEdit( qfu(p_item->value.psz) ); finish(); if( !l ) @@ -200,12 +205,95 @@ StringConfigControl::StringConfigControl( vlc_object_t *_p_this, void StringConfigControl::finish() { - text->setText( qfu(p_item->psz_value) ); + text->setText( qfu(p_item->value.psz) ); text->setToolTip( qfu(p_item->psz_longtext) ); if( label ) label->setToolTip( qfu(p_item->psz_longtext) ); } +/*********** File **************/ +FileConfigControl::FileConfigControl( vlc_object_t *_p_this, + module_config_t *_p_item, + QWidget *_parent, QGridLayout *l, + int &line, bool pwd ) : + VStringConfigControl( _p_this, _p_item, _parent ) +{ + label = new QLabel( qfu(p_item->psz_text) ); + text = new QLineEdit( qfu(p_item->value.psz) ); + browse = new QPushButton( qtr( "Browse" ) ); + + BUTTONACT( browse, updateField() ); + + finish(); + + if( !l ) + { + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget( label, 0 ); layout->addWidget( text, 1 ); + layout->addWidget( browse, 2 ); + widget->setLayout( layout ); + } + else + { + l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 ); + l->addWidget( browse, line, 2 ); + } +} + + +FileConfigControl::FileConfigControl( vlc_object_t *_p_this, + module_config_t *_p_item, + QLabel *_label, QLineEdit *_text, + QPushButton *_button, bool pwd ): + VStringConfigControl( _p_this, _p_item ) +{ + browse = _button; + text = _text; + label = _label; + + BUTTONACT( browse, updateField() ); + + finish( ); +} + +void FileConfigControl::updateField() +{ + QString file = QFileDialog::getOpenFileName( NULL, + qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) ); + if( file.isNull() ) return; + text->setText( file ); +} + +void FileConfigControl::finish() +{ + text->setText( qfu(p_item->value.psz) ); + text->setToolTip( qfu(p_item->psz_longtext) ); + if( label ) + label->setToolTip( qfu(p_item->psz_longtext) ); +} + +/********* String / Directory **********/ + +DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this, + module_config_t *_p_item, QWidget *_p_widget, + QGridLayout *_p_layout, int& _int, bool _pwd ) : + FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd) +{} + +DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this, + module_config_t *_p_item, QLabel *_p_label, + QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ): + FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd) +{} + + +void DirectoryConfigControl::updateField() +{ + text->setText( QFileDialog::getOpenFileName( NULL, + qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ), + NULL, 0, QFileDialog::ShowDirsOnly ) ); +} + /********* String / choice list **********/ StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QWidget *_parent, bool bycat, @@ -246,7 +334,7 @@ void StringListConfigControl::finish( bool bycat ) p_item->ppsz_list_text[i_index] : p_item->ppsz_list[i_index] ), QVariant( p_item->ppsz_list[i_index] ) ); - if( p_item->psz_value && !strcmp( p_item->psz_value, + if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) ) combo->setCurrentIndex( combo->count() - 1 ); } @@ -308,24 +396,24 @@ void ModuleConfigControl::finish( bool bycat ) { if( !strcmp( p_parser->psz_object_name, "main" ) ) continue; - module_config_t *p_config = p_parser->p_config; - if( p_config ) do + for (size_t i = 0; i < p_parser->confsize; i++) { + module_config_t *p_config = p_parser->p_config + i; /* Hack: required subcategory is stored in i_min */ if( p_config->i_type == CONFIG_SUBCATEGORY && - p_config->i_value == p_item->i_min ) + p_config->value.i == p_item->min.i ) combo->addItem( qfu(p_parser->psz_longname), QVariant( p_parser->psz_object_name ) ); - if( p_item->psz_value && !strcmp( p_item->psz_value, + if( p_item->value.psz && !strcmp( p_item->value.psz, p_parser->psz_object_name) ) combo->setCurrentIndex( combo->count() - 1 ); - } while( p_config->i_type != CONFIG_HINT_END && p_config++ ); + } } else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) ) { combo->addItem( qfu(p_parser->psz_longname), QVariant( p_parser->psz_object_name ) ); - if( p_item->psz_value && !strcmp( p_item->psz_value, + if( p_item->value.psz && !strcmp( p_item->value.psz, p_parser->psz_object_name) ) combo->setCurrentIndex( combo->count() - 1 ); } @@ -405,19 +493,19 @@ void ModuleListConfigControl::finish( bool bycat ) { if( !strcmp( p_parser->psz_object_name, "main" ) ) continue; - module_config_t *p_config = p_parser->p_config; - if( p_config ) do + for (size_t i = 0; i < p_parser->confsize; i++) { + module_config_t *p_config = p_parser->p_config + i; /* Hack: required subcategory is stored in i_min */ if( p_config->i_type == CONFIG_SUBCATEGORY && - p_config->i_value == p_item->i_min ) + p_config->value.i == p_item->min.i ) { QCheckBox *cb = new QCheckBox( qfu( p_parser->psz_object_name ) ); cb->setToolTip( qfu(p_parser->psz_longname) ); modules.push_back( cb ); } - } while( p_config->i_type != CONFIG_HINT_END && p_config++ ); + } } else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) ) { @@ -512,7 +600,7 @@ void IntegerConfigControl::finish() { spin->setMaximum( 2000000000 ); spin->setMinimum( -2000000000 ); - spin->setValue( p_item->i_value ); + spin->setValue( p_item->value.i ); spin->setToolTip( qfu(p_item->psz_longtext) ); if( label ) label->setToolTip( qfu(p_item->psz_longtext) ); @@ -543,10 +631,32 @@ IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this, void IntegerRangeConfigControl::finish() { - spin->setMaximum( p_item->i_max ); - spin->setMinimum( p_item->i_min ); + spin->setMaximum( p_item->max.i ); + spin->setMinimum( p_item->min.i ); +} + +IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl( + vlc_object_t *_p_this, + module_config_t *_p_item, + QLabel *_label, QSlider *_slider ): + VIntConfigControl( _p_this, _p_item ) +{ + slider = _slider; + label = _label; + slider->setMaximum( p_item->max.i ); + slider->setMinimum( p_item->min.i ); + slider->setValue( p_item->value.i ); + slider->setToolTip( qfu(p_item->psz_longtext) ); + if( label ) + label->setToolTip( qfu(p_item->psz_longtext) ); +} + +int IntegerRangeSliderConfigControl::getValue() +{ + return slider->value(); } + /********* Integer / choice list **********/ IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QWidget *_parent, bool bycat, @@ -585,7 +695,7 @@ void IntegerListConfigControl::finish( bool bycat ) { combo->addItem( qfu(p_item->ppsz_list_text[i_index] ), QVariant( p_item->pi_list[i_index] ) ); - if( p_item->i_value == p_item->pi_list[i_index] ) + if( p_item->value.i == p_item->pi_list[i_index] ) combo->setCurrentIndex( combo->count() - 1 ); } combo->setToolTip( qfu(p_item->psz_longtext) ); @@ -632,7 +742,7 @@ BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this, void BoolConfigControl::finish() { - checkbox->setCheckState( p_item->i_value == VLC_TRUE ? Qt::Checked + checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked : Qt::Unchecked ); checkbox->setToolTip( qfu(p_item->psz_longtext) ); } @@ -687,7 +797,7 @@ void FloatConfigControl::finish() spin->setMaximum( 2000000000. ); spin->setMinimum( -2000000000. ); spin->setSingleStep( 0.1 ); - spin->setValue( (double)p_item->f_value ); + spin->setValue( (double)p_item->value.f ); spin->setToolTip( qfu(p_item->psz_longtext) ); if( label ) label->setToolTip( qfu(p_item->psz_longtext) ); @@ -719,8 +829,8 @@ FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this, void FloatRangeConfigControl::finish() { - spin->setMaximum( (double)p_item->f_max ); - spin->setMinimum( (double)p_item->f_min ); + spin->setMaximum( (double)p_item->max.f ); + spin->setMinimum( (double)p_item->min.f ); } @@ -762,22 +872,23 @@ void KeySelectorControl::finish() module_t *p_main = config_FindModule( p_this, "main" ); assert( p_main ); - module_config_t *p_item = p_main->p_config; - if( p_item ) do + for (size_t i = 0; i < p_main->confsize; i++) { + module_config_t *p_item = p_main->p_config + i; + if( p_item->i_type & CONFIG_ITEM && p_item->psz_name && strstr( p_item->psz_name , "key-" ) ) { QTreeWidgetItem *treeItem = new QTreeWidgetItem(); treeItem->setText( 0, qfu( p_item->psz_text ) ); - treeItem->setText( 1, VLCKeyToString( p_item->i_value ) ); + treeItem->setText( 1, VLCKeyToString( p_item->value.i ) ); treeItem->setData( 0, Qt::UserRole, QVariant::fromValue( (void*)p_item ) ); values += p_item; table->addTopLevelItem( treeItem ); } - } while( p_item->i_type != CONFIG_HINT_END && p_item++ ); + } table->resizeColumnToContents( 0 ); CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ), @@ -793,7 +904,7 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) d->exec(); if( d->result() == QDialog::Accepted ) { - p_keyItem->i_value = d->keyValue; + p_keyItem->value.i = d->keyValue; if( d->conflicts ) { for( int i = 0; i < table->topLevelItemCount() ; i++ ) @@ -801,11 +912,11 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) QTreeWidgetItem *it = table->topLevelItem(i); module_config_t *p_item = static_cast (it->data( 0, Qt::UserRole ).value()); - it->setText( 1, VLCKeyToString( p_item->i_value ) ); + it->setText( 1, VLCKeyToString( p_item->value.i ) ); } } else - keyItem->setText( 1, VLCKeyToString( p_keyItem->i_value ) ); + keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) ); } delete d; } @@ -814,12 +925,12 @@ void KeySelectorControl::doApply() { foreach( module_config_t *p_current, values ) { - config_PutInt( p_this, p_current->psz_name, p_current->i_value ); + config_PutInt( p_this, p_current->psz_name, p_current->value.i ); } } KeyInputDialog::KeyInputDialog( QList& _values, - char * _keyToChange ) : + const char * _keyToChange ) : QDialog(0), keyValue(0) { setModal( true ); @@ -855,10 +966,10 @@ void KeyInputDialog::keyPressEvent( QKeyEvent *e ) module_config_t *p_current = NULL; foreach( p_current, values ) { - if( p_current->i_value == i_vlck && strcmp( p_current->psz_text, + if( p_current->value.i == i_vlck && strcmp( p_current->psz_text, keyToChange ) ) { - p_current->i_value = 0; + p_current->value.i = 0; conflicts = true; break; }