/*****************************************************************************
- * preferences_tree.cpp : Tree of modules for preferences
+ * preferences.cpp : "Normal preferences"
****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id$
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#include <QApplication>
+#include <QLabel>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QVariant>
+#include <QString>
+#include <QFont>
+#include <QGroupBox>
+#include <QScrollArea>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QGridLayout>
+#include <QHeaderView>
+#include <QPalette>
+#include <QColor>
+
#include "components/preferences.hpp"
#include "components/preferences_widgets.hpp"
#include "qt4.hpp"
+
#include <vlc_config_cat.h>
+#include <vlc_intf_strings.h>
#include <assert.h>
#include "pixmaps/audio.xpm"
#include "pixmaps/codec.xpm"
#include "pixmaps/intf.xpm"
-#include <QLabel>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-#include <QVariant>
-#include <QString>
-#include <QFont>
-#include <QGroupBox>
-#include <QScrollArea>
-#include <QVBoxLayout>
-#include <QHBoxLayout>
-#include <QHeaderView>
-
#define ITEM_HEIGHT 25
/*********************************************************************
PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) :
QTreeWidget( _parent ), p_intf( _p_intf )
{
- module_t *p_module;
- vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
- FIND_ANYWHERE );
- if( !p_list ) return;
-
setColumnCount( 1 );
setIconSize( QSize( ITEM_HEIGHT,ITEM_HEIGHT ) );
setAlternatingRowColors( true );
header()->hide();
-#ifndef WIN32
- // Fixme - A bit UGLY
- QFont f = font();
- int pSize = f.pointSize();
- if( pSize > 0 )
- f.setPointSize( pSize + 1 );
- else
- f.setPixelSize( f.pixelSize() + 1 );
- setFont( f );
-#endif
-
#define BI( a,b) QIcon a##_icon = QIcon( QPixmap( b##_xpm ))
BI( audio, audio );
BI( video, video );
/* Build the tree for the main module */
int i_index;
+ module_t *p_module;
+ vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
+ FIND_ANYWHERE );
+ bool found = true;
+ if( !p_list ) return;
for( i_index = 0; i_index < p_list->i_count; i_index++ )
{
p_module = (module_t *)p_list->p_values[i_index].p_object;
- if( !strcmp( p_module->psz_object_name, "main" ) )
- break;
+ if( !strcmp( p_module->psz_object_name, "main" ) ) {
+ found = true; break;
+ }
}
- if( i_index < p_list->i_count )
+ assert( found );
+
+ module_config_t *p_item = p_module->p_config;
+ PrefsItemData *data = NULL;
+ QTreeWidgetItem *current_item = NULL;
+ if( p_item ) do
{
- module_config_t *p_item = p_module->p_config;
- PrefsItemData *data = NULL;
- QTreeWidgetItem *current_item = NULL;
- if( p_item ) do
+ char *psz_help;
+ QIcon icon;
+ switch( p_item->i_type )
{
- char *psz_help;
- QIcon icon;
- switch( p_item->i_type )
+ case CONFIG_CATEGORY:
+ if( p_item->i_value == -1 ) break;
+ data = new PrefsItemData();
+ data->name = QString( qfu( config_CategoryNameGet
+ ( p_item->i_value ) ) );
+ psz_help = config_CategoryHelpGet( p_item->i_value );
+ if( psz_help )
+ data->help = QString( qfu(psz_help) );
+ else
+ data->help.clear();
+ data->i_type = TYPE_CATEGORY;
+ data->i_object_id = p_item->i_value;
+
+ switch( p_item->i_value )
{
- case CONFIG_CATEGORY:
- if( p_item->i_value == -1 ) break;
- data = new PrefsItemData();
- data->name = QString( config_CategoryNameGet
- ( p_item->i_value ) );
- psz_help = config_CategoryHelpGet( p_item->i_value );
- if( psz_help )
- data->help = QString( psz_help );
- else
- data->help.clear();
- data->i_type = TYPE_CATEGORY;
- data->i_object_id = p_item->i_value;
-
- switch( p_item->i_value )
- {
#define CI(a,b) case a: icon = b##_icon;break
- CI( CAT_AUDIO, audio );
- CI( CAT_VIDEO, video );
- CI( CAT_INPUT, input );
- CI( CAT_SOUT, sout );
- CI( CAT_ADVANCED, advanced );
- CI( CAT_PLAYLIST, playlist );
- CI( CAT_INTERFACE, interface );
+ CI( CAT_AUDIO, audio );
+ CI( CAT_VIDEO, video );
+ CI( CAT_INPUT, input );
+ CI( CAT_SOUT, sout );
+ CI( CAT_ADVANCED, advanced );
+ CI( CAT_PLAYLIST, playlist );
+ CI( CAT_INTERFACE, interface );
#undef CI
- }
+ }
- current_item = new QTreeWidgetItem();
- current_item->setText( 0, data->name );
- current_item->setIcon( 0 , icon );
- current_item->setData( 0, Qt::UserRole,
- qVariantFromValue( data ) );
- addTopLevelItem( current_item );
- break;
- case CONFIG_SUBCATEGORY:
- if( p_item->i_value == -1 ) break;
- if( data &&
- ( p_item->i_value == SUBCAT_VIDEO_GENERAL ||
- p_item->i_value == SUBCAT_ADVANCED_MISC ||
- p_item->i_value == SUBCAT_INPUT_GENERAL ||
- p_item->i_value == SUBCAT_INTERFACE_GENERAL ||
- p_item->i_value == SUBCAT_SOUT_GENERAL||
- p_item->i_value == SUBCAT_PLAYLIST_GENERAL||
- p_item->i_value == SUBCAT_AUDIO_GENERAL ) )
- {
- // Data still contains the correct thing
- data->i_type = TYPE_CATSUBCAT;
- data->i_subcat_id = p_item->i_value;
- data->name = QString( config_CategoryNameGet(
- p_item->i_value ) );
- psz_help = config_CategoryHelpGet( p_item->i_value );
- if( psz_help )
- data->help = QString( psz_help );
- else
- data->help.clear();
- current_item->setData( 0, Qt::UserRole,
- QVariant::fromValue( data ) );
- continue;
- }
- data = new PrefsItemData();
- data->name = QString( config_CategoryNameGet( p_item->i_value));
+ current_item = new QTreeWidgetItem();
+ current_item->setText( 0, data->name );
+ current_item->setIcon( 0 , icon );
+ current_item->setData( 0, Qt::UserRole,
+ qVariantFromValue( data ) );
+ addTopLevelItem( current_item );
+ break;
+ case CONFIG_SUBCATEGORY:
+ if( p_item->i_value == -1 ) break;
+ if( data &&
+ ( p_item->i_value == SUBCAT_VIDEO_GENERAL ||
+ p_item->i_value == SUBCAT_ADVANCED_MISC ||
+ p_item->i_value == SUBCAT_INPUT_GENERAL ||
+ p_item->i_value == SUBCAT_INTERFACE_GENERAL ||
+ p_item->i_value == SUBCAT_SOUT_GENERAL||
+ p_item->i_value == SUBCAT_PLAYLIST_GENERAL||
+ p_item->i_value == SUBCAT_AUDIO_GENERAL ) )
+ {
+ // Data still contains the correct thing
+ data->i_type = TYPE_CATSUBCAT;
+ data->i_subcat_id = p_item->i_value;
+ data->name = QString( qfu( config_CategoryNameGet(
+ p_item->i_value )) );
psz_help = config_CategoryHelpGet( p_item->i_value );
if( psz_help )
- data->help = QString( psz_help );
+ data->help = QString( qfu(psz_help) );
else
data->help.clear();
- data->i_type = TYPE_SUBCATEGORY;
- data->i_object_id = p_item->i_value;
-
- assert( current_item );
-
- /* TODO : Choose the image */
- QTreeWidgetItem *subcat_item = new QTreeWidgetItem();
- subcat_item->setText( 0, data->name );
- //item->setIcon( 0 , XXX );
- subcat_item->setData( 0, Qt::UserRole,
- qVariantFromValue(data) );
- subcat_item->setSizeHint( 0, QSize( -1, ITEM_HEIGHT ) );
- current_item->addChild( subcat_item );
- break;
+ current_item->setData( 0, Qt::UserRole,
+ QVariant::fromValue( data ) );
+ continue;
}
- } while( p_item->i_type != CONFIG_HINT_END && p_item++ );
- }
+ data = new PrefsItemData();
+ data->name = QString( qfu( config_CategoryNameGet(
+ p_item->i_value)) );
+ psz_help = config_CategoryHelpGet( p_item->i_value );
+ if( psz_help )
+ data->help = QString( qfu(psz_help) );
+ else
+ data->help.clear();
+ data->i_type = TYPE_SUBCATEGORY;
+ data->i_object_id = p_item->i_value;
+
+ assert( current_item );
+
+ /* TODO : Choose the image */
+ QTreeWidgetItem *subcat_item = new QTreeWidgetItem();
+ subcat_item->setText( 0, data->name );
+ //item->setIcon( 0 , XXX );
+ subcat_item->setData( 0, Qt::UserRole,
+ qVariantFromValue(data) );
+ subcat_item->setSizeHint( 0, QSize( -1, ITEM_HEIGHT ) );
+ current_item->addChild( subcat_item );
+ break;
+ }
+ } while( p_item->i_type != CONFIG_HINT_END && p_item++ );
/* Build the tree of plugins */
for( int i_index = 0; i_index < p_list->i_count; i_index++ )
module_data->help.clear();
// TODO image
QTreeWidgetItem *module_item = new QTreeWidgetItem();
- module_item->setText( 0, p_module->psz_shortname ?
- p_module->psz_shortname : p_module->psz_object_name );
+ module_item->setText( 0, qfu( p_module->psz_shortname ?
+ p_module->psz_shortname : p_module->psz_object_name) );
//item->setIcon( 0 , XXX );
module_item->setData( 0, Qt::UserRole,
QVariant::fromValue( module_data) );
PrefsTree::~PrefsTree() {}
-void PrefsTree::ApplyAll()
+void PrefsTree::applyAll()
{
- DoAll( false );
+ doAll( false );
}
-void PrefsTree::CleanAll()
+void PrefsTree::cleanAll()
{
- DoAll( true );
+ doAll( true );
}
-/// \todo When cleaning, we should remove the panel ?
-void PrefsTree::DoAll( bool doclean )
+void PrefsTree::doAll( bool doclean )
{
for( int i_cat_index = 0 ; i_cat_index < topLevelItemCount();
i_cat_index++ )
{
QTreeWidgetItem *cat_item = topLevelItem( i_cat_index );
- for( int i_sc_index = 0; i_sc_index <= cat_item->childCount();
+ for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
i_sc_index++ )
{
QTreeWidgetItem *sc_item = cat_item->child( i_sc_index );
- for( int i_module = 0 ; i_module <= sc_item->childCount();
+ for( int i_module = 0 ; i_module < sc_item->childCount();
i_module++ )
{
- PrefsItemData *data = sc_item->child( i_sc_index )->
- data( 0, Qt::UserRole ).
- value<PrefsItemData *>();
+ PrefsItemData *data = sc_item->child( i_module )->
+ data( 0, Qt::UserRole).value<PrefsItemData *>();
if( data->panel && doclean )
- data->panel->Clean();
+ {
+ delete data->panel;
+ data->panel = NULL;
+ }
else if( data->panel )
- data->panel->Apply();
+ data->panel->apply();
+ }
+ PrefsItemData *data = sc_item->data( 0, Qt::UserRole).
+ value<PrefsItemData *>();
+ if( data->panel && doclean )
+ {
+ delete data->panel;
+ data->panel = NULL;
}
+ else if( data->panel )
+ data->panel->apply();
+ }
+ PrefsItemData *data = cat_item->data( 0, Qt::UserRole).
+ value<PrefsItemData *>();
+ if( data->panel && doclean )
+ {
+ delete data->panel;
+ data->panel = NULL;
}
+ else if( data->panel )
+ data->panel->apply();
}
}
-
/*********************************************************************
* The Panel
*********************************************************************/
{}
PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
- PrefsItemData * data, bool currently_advanced ) :
+ PrefsItemData * data ) :
QWidget( _parent ), p_intf( _p_intf )
{
module_config_t *p_item;
- module_t *p_module = NULL;
- vlc_list_t *p_list = NULL;
- global_layout = new QVBoxLayout();
+ /* Find our module */
+ module_t *p_module = NULL;
if( data->i_type == TYPE_CATEGORY )
- {
- /* TODO */
- return;
- }
+ return;
else if( data->i_type == TYPE_MODULE )
- {
p_module = (module_t *) vlc_object_get( p_intf, data->i_object_id );
- }
else
{
- /* List the plugins */
- int i_index;
- vlc_bool_t b_found = VLC_FALSE;
- p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
- if( !p_list ) return;
-
- for( i_index = 0; i_index < p_list->i_count; i_index++ )
- {
- p_module = (module_t *)p_list->p_values[i_index].p_object;
- if( !strcmp( p_module->psz_object_name, "main" ) )
- {
- b_found = VLC_TRUE;
- break;
- }
- }
- if( !p_module && !b_found )
- {
- msg_Warn( p_intf, "unable to create preferences (main not found)");
- return;
- }
- if( p_module ) vlc_object_yield( p_module );
- vlc_list_release( p_list );
+ p_module = config_FindModule( VLC_OBJECT(p_intf), "main" );
+ assert( p_module );
+ vlc_object_yield( p_module );
}
if( p_module->b_submodule )
p_item->i_value == data->i_object_id ) ||
( data->i_type == TYPE_CATSUBCAT &&
p_item->i_value == data->i_subcat_id ) )
- {
break;
- }
if( p_item->i_type == CONFIG_HINT_END ) break;
} while( p_item++ );
}
+ global_layout = new QVBoxLayout();
QString head;
if( data->i_type == TYPE_SUBCATEGORY || data->i_type == TYPE_CATSUBCAT )
{
else
{
head = QString( qfu(p_module->psz_longname) );
- if( p_module->psz_help )
+ if( p_module->psz_help )
{
head.append( "\n" );
head.append( qfu( p_module->psz_help ) );
}
}
- QLabel *label = new QLabel( head, this );
- QFont font = label->font();
- font.setPointSize( font.pointSize() + 2 ); font.setBold( true );
- label->setFont( font );
+ QLabel *label = new QLabel( head );
+ global_layout->addWidget( label );
+ QFont myFont = QApplication::font( static_cast<QWidget*>(0) );
+ myFont.setPointSize( myFont.pointSize() + 3 ); myFont.setBold( true );
+
+ label->setFont( myFont );
QLabel *help = new QLabel( data->help, this );
help->setWordWrap( true );
- global_layout->addWidget( label );
global_layout->addWidget( help );
QGroupBox *box = NULL;
- QVBoxLayout *boxlayout = NULL;
+ QGridLayout *boxlayout = NULL;
QScrollArea *scroller= new QScrollArea;
scroller->setFrameStyle( QFrame::NoFrame );
QWidget *scrolled_area = new QWidget;
- QVBoxLayout *layout = new QVBoxLayout();
+ QGridLayout *layout = new QGridLayout();
+ int i_line = 0, i_boxline = 0;
+ bool has_hotkey = false;
if( p_item ) do
{
if( box )
{
box->setLayout( boxlayout );
- layout->addWidget( box, 1 );
+ layout->addWidget( box, i_line, 0, 1, 2 );
+ i_line++;
}
box = new QGroupBox( qfu(p_item->psz_text) );
- boxlayout = new QVBoxLayout();
+ boxlayout = new QGridLayout();
}
-
- ConfigControl *control = ConfigControl::createControl(
- VLC_OBJECT( p_intf ), p_item,
- NULL );
+ /* Only one hotkey control */
+ if( has_hotkey && p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
+ strstr( p_item->psz_name, "key-" ) )
+ continue;
+ if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
+ strstr( p_item->psz_name, "key-" ) )
+ has_hotkey = true;
+
+ ConfigControl *control;
+ if( ! box )
+ control = ConfigControl::createControl( VLC_OBJECT( p_intf ),
+ p_item, NULL, layout, i_line );
+ else
+ control = ConfigControl::createControl( VLC_OBJECT( p_intf ),
+ p_item, NULL, boxlayout, i_boxline );
if( !control )
- {
continue;
+
+ if( has_hotkey )
+ {
+ /* A hotkey widget takes 2 lines */
+ if( box ) i_boxline ++;
+ else i_line++;
}
- if( !box )
- layout->addWidget( control );
- else
- boxlayout->addWidget( control );
+ if( box ) i_boxline++;
+ else i_line++;
controls.append( control );
}
while( !(p_item->i_type == CONFIG_HINT_END ||
if( box )
{
box->setLayout( boxlayout );
- layout->addWidget( box, 1 );
+ layout->addWidget( box, i_line, 0, 1, 2 );
}
vlc_object_release( p_module );
scroller->setWidget( scrolled_area );
scroller->setWidgetResizable( true );
global_layout->addWidget( scroller );
-
- some_hidden_text = new QLabel( "Some options are available but hidden. "\
- "Check \"Advanced options\" to see them." );
- some_hidden_text->setWordWrap( true );
-
setLayout( global_layout );
- setAdvanced( currently_advanced, true );
}
-void PrefsPanel::Apply()
+void PrefsPanel::apply()
{
- /* todo */
QList<ConfigControl *>::Iterator i;
for( i = controls.begin() ; i != controls.end() ; i++ )
{
- VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(*i);
- if( !vicc )
- {
- VFloatConfigControl *vfcc = qobject_cast<VFloatConfigControl *>(*i);
- if( !vfcc)
- {
- VStringConfigControl *vscc =
- qobject_cast<VStringConfigControl *>(*i);
- assert( vscc );
- config_PutPsz( p_intf, vscc->getName().toAscii().data(),
- vscc->getValue().toAscii().data() );
- continue;
- }
- config_PutFloat( p_intf, vfcc->getName().toAscii().data(),
- vfcc->getValue() );
- continue;
- }
- config_PutInt( p_intf, vicc->getName().toAscii().data(),
- vicc->getValue() );
+ ConfigControl *c = qobject_cast<ConfigControl *>(*i);
+ c->doApply( p_intf );
}
}
-
-void PrefsPanel::Clean()
+void PrefsPanel::clean()
{}
-
-void PrefsPanel::setAdvanced( bool adv, bool force )
-{
- bool some_hidden = false;
- if( !force && adv == advanced ) return;
-
- advanced = adv;
- QList<ConfigControl *>::Iterator i;
- for( i = controls.begin() ; i != controls.end() ; i++ )
- {
- if( (*i)->isAdvanced() )
- {
- if( !advanced ) some_hidden = true;
- (*i)->setVisible( advanced );
- }
- }
- if( some_hidden_text )
- {
- global_layout->removeWidget( some_hidden_text );
- some_hidden_text->hide();
- }
- if( some_hidden )
- {
- global_layout->addWidget( some_hidden_text );
- some_hidden_text->show();
- }
-}