X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fcomplete_preferences.cpp;h=8c68d16b43e2b42e862b5b5291ba04c5ae946950;hb=36f0edc98752f8afa17a50cb8de086b30ba54c2e;hp=a7217f2ec45bcd19130612b23c0cfd2c86b96315;hpb=4e7e655aa94944ed4f1797d9dbb7114010c2c2a1;p=vlc diff --git a/modules/gui/qt4/components/complete_preferences.cpp b/modules/gui/qt4/components/complete_preferences.cpp index a7217f2ec4..8c68d16b43 100644 --- a/modules/gui/qt4/components/complete_preferences.cpp +++ b/modules/gui/qt4/components/complete_preferences.cpp @@ -1,7 +1,7 @@ /***************************************************************************** * preferences.cpp : "Normal preferences" **************************************************************************** - * Copyright (C) 2006 the VideoLAN team + * Copyright (C) 2006-2007 the VideoLAN team * $Id$ * * Authors: Clément Stenac @@ -20,6 +20,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include #include @@ -39,20 +42,11 @@ #include "components/complete_preferences.hpp" #include "components/preferences_widgets.hpp" -#include "qt4.hpp" #include #include #include -#include "pixmaps/audio.xpm" -#include "pixmaps/video.xpm" -#include "pixmaps/type_net.xpm" -#include "pixmaps/type_playlist.xpm" -#include "pixmaps/advanced.xpm" -#include "pixmaps/codec.xpm" -#include "pixmaps/intf.xpm" - #define ITEM_HEIGHT 25 /********************************************************************* @@ -61,59 +55,62 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) : QTreeWidget( _parent ), p_intf( _p_intf ) { + /* General Qt options */ setColumnCount( 1 ); setAlternatingRowColors( true ); header()->hide(); + setIconSize( QSize( ITEM_HEIGHT,ITEM_HEIGHT ) ); setTextElideMode( Qt::ElideNone ); - setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOn ); - -#define BI( a,b) QIcon a##_icon = QIcon( QPixmap( b##_xpm )) - BI( audio, audio ); - BI( video, video ); - BI( input, codec ); - BI( sout, type_net ); - BI( advanced, advanced ); - BI( playlist, type_playlist ); - BI( interface, intf ); + + /* Nice icons */ +#define BI( a,b) QIcon a##_icon = QIcon( QPixmap( b )) + BI( audio, ":/advprefs_audio" ); + BI( video, ":/advprefs_video" ); + BI( input, ":/advprefs_codec" ); + BI( sout, ":/advprefs_sout" ); + BI( advanced, ":/advprefs_extended" ); + BI( playlist, ":/advprefs_playlist" ); + BI( interface, ":/advprefs_intf" ); #undef BI /* Build the tree for the main module */ - module_t *p_module = NULL; - vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, - FIND_ANYWHERE ); - if( !p_list ) return; - for( int i_index = 0; p_module == NULL; i_index++ ) - { - assert (i_index < p_list->i_count); - - p_module = (module_t *)p_list->p_values[i_index].p_object; - if( strcmp( p_module->psz_object_name, "main" ) ) - p_module = NULL; - } + module_t *p_module = module_GetMainModule( p_intf ); + /* Initialisation and get the confsize */ PrefsItemData *data = NULL; + PrefsItemData *data_sub = NULL; QTreeWidgetItem *current_item = NULL; - for (size_t i = 0; i < p_module->confsize; i++) + unsigned confsize; + module_config_t *const p_config = module_GetConfig (p_module, &confsize); + + /* Go through the list of conf */ + for( size_t i = 0; i < confsize; i++ ) { - module_config_t *p_item = p_module->p_config + i; - char *psz_help; + const char *psz_help; QIcon icon; + + /* Work on a new item */ + module_config_t *p_item = p_config + i; + switch( p_item->i_type ) { + /* This is a category */ case CONFIG_CATEGORY: if( p_item->value.i == -1 ) break; + + /* PrefsItemData Init */ data = new PrefsItemData(); - data->name = QString( qfu( config_CategoryNameGet - ( p_item->value.i ) ) ); + data->name = qtr( config_CategoryNameGet( p_item->value.i ) ); psz_help = config_CategoryHelpGet( p_item->value.i ); if( psz_help ) - data->help = QString( qfu(psz_help) ); + data->help = qtr( psz_help ); else data->help.clear(); data->i_type = TYPE_CATEGORY; data->i_object_id = p_item->value.i; + /* This is a category, put a nice icon */ switch( p_item->value.i ) { #define CI(a,b) case a: icon = b##_icon;break @@ -124,9 +121,10 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) : CI( CAT_ADVANCED, advanced ); CI( CAT_PLAYLIST, playlist ); CI( CAT_INTERFACE, interface ); -#undef CI } +#undef CI + /* Create a new QTreeItem to display it in the tree at top level */ current_item = new QTreeWidgetItem(); current_item->setText( 0, data->name ); current_item->setIcon( 0 , icon ); @@ -135,8 +133,12 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) : qVariantFromValue( data ) ); addTopLevelItem( current_item ); break; + + /* This is a subcategory */ case CONFIG_SUBCATEGORY: if( p_item->value.i == -1 ) break; + + /* Special cases: move the main subcategories to the parent cat*/ if( data && ( p_item->value.i == SUBCAT_VIDEO_GENERAL || p_item->value.i == SUBCAT_ADVANCED_MISC || @@ -146,83 +148,104 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) : p_item->value.i == SUBCAT_PLAYLIST_GENERAL|| p_item->value.i == SUBCAT_AUDIO_GENERAL ) ) { - // Data still contains the correct thing + /* Data still contains the correct thing */ data->i_type = TYPE_CATSUBCAT; data->i_subcat_id = p_item->value.i; - data->name = QString( qfu( config_CategoryNameGet( - p_item->value.i )) ); + data->name = qtr( config_CategoryNameGet( p_item->value.i ) ); psz_help = config_CategoryHelpGet( p_item->value.i ); if( psz_help ) - data->help = QString( qfu(psz_help) ); + data->help = qtr( psz_help ); else data->help.clear(); current_item->setData( 0, Qt::UserRole, QVariant::fromValue( data ) ); continue; } - data = new PrefsItemData(); - data->name = QString( qfu( config_CategoryNameGet( - p_item->value.i)) ); + + /* Normal Subcategories */ + + /* Process the Data */ + data_sub = new PrefsItemData(); + data_sub->name = qtr( config_CategoryNameGet( p_item->value.i) ); psz_help = config_CategoryHelpGet( p_item->value.i ); if( psz_help ) - data->help = QString( qfu(psz_help) ); + data_sub->help = qtr( psz_help ); else - data->help.clear(); - data->i_type = TYPE_SUBCATEGORY; - data->i_object_id = p_item->value.i; - - assert( current_item ); + data_sub->help.clear(); + data_sub->i_type = TYPE_SUBCATEGORY; + data_sub->i_object_id = p_item->value.i; - /* TODO : Choose the image */ + /* Create a new TreeWidget */ QTreeWidgetItem *subcat_item = new QTreeWidgetItem(); - subcat_item->setText( 0, data->name ); - //item->setIcon( 0 , XXX ); + subcat_item->setText( 0, data_sub->name ); + /* TODO : Choose the image */ + //subcat_item->setIcon( 0 , XXX ); subcat_item->setData( 0, Qt::UserRole, - qVariantFromValue(data) ); + qVariantFromValue( data_sub ) ); subcat_item->setSizeHint( 0, QSize( -1, ITEM_HEIGHT ) ); + + /* Add it to the parent */ + assert( current_item ); current_item->addChild( subcat_item ); break; + + /* Other items don't need yet a place on the tree */ } } + module_PutConfig( p_config ); + vlc_object_release( (vlc_object_t*)p_module ); + + vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, + FIND_ANYWHERE ); /* Build the tree of plugins */ for( int i_index = 0; i_index < p_list->i_count; i_index++ ) { - int i_subcategory = -1, i_category = -1, i_options = 0; + /* Take every module */ p_module = (module_t *)p_list->p_values[i_index].p_object; // Main module excluded - if( !strcmp( p_module->psz_object_name, "main" ) ) continue; + if( module_IsMainModule( p_module) ) continue; - /* Exclude empty plugins (submodules don't have config options, they - * are stored in the parent module) */ - if( p_module->b_submodule ) continue; + unsigned i_subcategory = 0, i_category = 0, confsize; + bool b_options = false; + module_config_t *const p_config = module_GetConfig (p_module, &confsize); - for (size_t i = 0; i < p_module->confsize; i++) + /* Loop through the configurations items */ + for (size_t i = 0; i < confsize; i++) { - module_config_t *p_item = p_module->p_config + i; + const module_config_t *p_item = p_config + i; if( p_item->i_type == CONFIG_CATEGORY ) i_category = p_item->value.i; else if( p_item->i_type == CONFIG_SUBCATEGORY ) i_subcategory = p_item->value.i; + if( p_item->i_type & CONFIG_ITEM ) - i_options++; + b_options = true; - if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 ) + if( b_options && i_category && i_subcategory ) break; } - if( !i_options ) continue; // Nothing to display + module_PutConfig (p_config); + + /* Dummy item, please proceed */ + if( !b_options || i_category == 0 || i_subcategory == 0 ) continue; + // Locate the category item; QTreeWidgetItem *subcat_item = NULL; bool b_found = false; + for( int i_cat_index = 0 ; i_cat_index < topLevelItemCount(); i_cat_index++ ) { + /* Get the treeWidgetItem that correspond to the category */ QTreeWidgetItem *cat_item = topLevelItem( i_cat_index ); PrefsItemData *data = cat_item->data( 0, Qt::UserRole ). value(); + + /* If we match the good category */ if( data->i_object_id == i_category ) { for( int i_sc_index = 0; i_sc_index < cat_item->childCount(); @@ -248,17 +271,12 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) : if( !b_found ) continue; PrefsItemData *module_data = new PrefsItemData(); - module_data->b_submodule = p_module->b_submodule; module_data->i_type = TYPE_MODULE; - module_data->psz_name = strdup( p_module->psz_object_name ); - module_data->i_object_id = p_module->b_submodule ? - ((module_t *)p_module->p_parent)->i_object_id : - p_module->i_object_id; + module_data->psz_name = strdup( module_GetObjName( p_module ) ); module_data->help.clear(); // TODO image QTreeWidgetItem *module_item = new QTreeWidgetItem(); - module_item->setText( 0, qfu( p_module->psz_shortname ? - p_module->psz_shortname : p_module->psz_object_name) ); + module_item->setText( 0, qtr( module_GetName( p_module, false ) ) ); //item->setIcon( 0 , XXX ); module_item->setData( 0, Qt::UserRole, QVariant::fromValue( module_data) ); @@ -332,10 +350,10 @@ void PrefsTree::doAll( bool doclean ) /********************************************************************* * The Panel *********************************************************************/ -PrefsPanel::PrefsPanel( QWidget *_parent ) : QWidget( _parent ) +AdvPrefsPanel::AdvPrefsPanel( QWidget *_parent ) : QWidget( _parent ) {} -PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, +AdvPrefsPanel::AdvPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, PrefsItemData * data ) : QWidget( _parent ), p_intf( _p_intf ) { @@ -344,20 +362,17 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, if( data->i_type == TYPE_CATEGORY ) return; else if( data->i_type == TYPE_MODULE ) - p_module = (module_t *) vlc_object_get( p_intf, data->i_object_id ); + p_module = module_Find( p_intf, data->psz_name ); else { - p_module = config_FindModule( VLC_OBJECT(p_intf), "main" ); + p_module = module_GetMainModule( p_intf ); assert( p_module ); - vlc_object_yield( p_module ); } - module_t *p_realmodule = p_module->b_submodule - ? (module_t *)(p_module->p_parent) - : p_module; - - module_config_t *p_item = p_realmodule->p_config; - module_config_t *p_end = p_item + p_realmodule->confsize; + unsigned confsize; + module_config_t *const p_config = module_GetConfig (p_module, &confsize), + *p_item = p_config, + *p_end = p_config + confsize; if( data->i_type == TYPE_SUBCATEGORY || data->i_type == TYPE_CATSUBCAT ) { @@ -373,9 +388,14 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, } } + /* Widgets now */ global_layout = new QVBoxLayout(); global_layout->setMargin( 2 ); QString head; + QString help; + + help = QString( data->help ); + if( data->i_type == TYPE_SUBCATEGORY || data->i_type == TYPE_CATSUBCAT ) { head = QString( data->name ); @@ -383,24 +403,32 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, } else { - head = QString( qfu(p_module->psz_longname) ); - if( p_module->psz_help ) + const char *psz_help = module_GetHelp (p_module); + head = QString( qtr( module_GetLongName( p_module ) ) ); + if( psz_help ) { - head.append( "\n" ); - head.append( qfu( p_module->psz_help ) ); + help.append( "\n" ); + help.append( qtr( psz_help ) ); } } - QLabel *label = new QLabel( head ); - global_layout->addWidget( label ); - QFont myFont = QApplication::font( static_cast(0) ); - myFont.setPointSize( myFont.pointSize() + 3 ); myFont.setBold( true ); + QLabel *titleLabel = new QLabel( head ); + QFont titleFont = QApplication::font( static_cast(0) ); + titleFont.setPointSize( titleFont.pointSize() + 6 ); + titleFont.setFamily( "Verdana" ); + titleLabel->setFont( titleFont ); - label->setFont( myFont ); - QLabel *help = new QLabel( data->help, this ); - help->setWordWrap( true ); + // Title
+ QFrame *title_line = new QFrame; + title_line->setFrameShape(QFrame::HLine); + title_line->setFrameShadow(QFrame::Sunken); - global_layout->addWidget( help ); + QLabel *helpLabel = new QLabel( help, this ); + helpLabel->setWordWrap( true ); + + global_layout->addWidget( titleLabel ); + global_layout->addWidget( title_line ); + global_layout->addWidget( helpLabel ); QGroupBox *box = NULL; QGridLayout *boxlayout = NULL; @@ -422,17 +450,18 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ( p_item->i_type == CONFIG_CATEGORY || p_item->i_type == CONFIG_SUBCATEGORY ) ) break; - if( p_item->b_internal == VLC_TRUE ) continue; + if( p_item->b_internal == true ) continue; if( p_item->i_type == CONFIG_SECTION ) { if( box ) { box->setLayout( boxlayout ); - layout->addWidget( box, i_line, 0, 1, 2 ); + layout->addWidget( box, i_line, 0, 1, -1 ); i_line++; } - box = new QGroupBox( qfu(p_item->psz_text) ); + box = new QGroupBox( qtr( p_item->psz_text ) ); + box->hide(); boxlayout = new QGridLayout(); } /* Only one hotkey control */ @@ -453,13 +482,6 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, if( !control ) continue; - if( has_hotkey ) - { - /* A hotkey widget takes 2 lines */ - if( box ) i_boxline ++; - else i_line++; - } - if( box ) i_boxline++; else i_line++; controls.append( control ); @@ -473,10 +495,11 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, if( box ) { box->setLayout( boxlayout ); - layout->addWidget( box, i_line, 0, 1, 2 ); + box->show(); + layout->addWidget( box, i_line, 0, 1, -1 ); } - vlc_object_release( p_module ); + module_Put( p_module ); scrolled_area->setSizePolicy( QSizePolicy::Preferred,QSizePolicy::Fixed ); scrolled_area->setLayout( layout ); @@ -486,7 +509,7 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, setLayout( global_layout ); } -void PrefsPanel::apply() +void AdvPrefsPanel::apply() { QList::Iterator i; for( i = controls.begin() ; i != controls.end() ; i++ ) @@ -495,5 +518,12 @@ void PrefsPanel::apply() c->doApply( p_intf ); } } -void PrefsPanel::clean() + +void AdvPrefsPanel::clean() {} + +AdvPrefsPanel::~AdvPrefsPanel() +{ + qDeleteAll( controls ); controls.clear(); +} +