* preferences.cpp: preferences window for the kde gui
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: preferences.cpp,v 1.9 2002/12/13 01:56:29 gbazin Exp $
+ * $Id$
*
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no> Mon Aug 12 2002
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#include <qlistview.h>
#include <qnamespace.h>
#include <qobjectlist.h>
+#include <qslider.h>
#include <qspinbox.h>
#include <qtooltip.h>
#include <qvbox.h>
#include <klocale.h>
#include <knuminput.h>
#include <kurlrequester.h>
+#include <kfiledialog.h>
+#include <kcombobox.h>
#include "QConfigItem.h"
#include "pluginsbox.h"
*/
KPreferences::KPreferences(intf_thread_t *p_intf, const char *psz_module_name,
QWidget *parent, const QString &caption) :
- KDialogBase ( Tabbed, caption, Ok| Apply|Cancel|User1, Ok, parent,
- "vlc preferences", true, false, "Save")
+ KDialogBase ( TreeList, caption, Ok| Apply|Cancel|User1, Ok, parent,
+ _("vlc preferences"), true, false, i18n(_("&Save")) )
{
- module_t *p_parser;
- vlc_list_t list;
+ module_t *p_parser = NULL;
+ vlc_list_t *p_list;
module_config_t *p_item;
int i_index;
QVBox *category_table = NULL;
this->p_intf = p_intf;
/* List all modules */
- list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+ p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
- /* Look for the selected module */
- for( i_index = 0; i_index < list.i_count; i_index++ )
+ for( i_index = 0; i_index < p_list->i_count; i_index++ )
{
- p_parser = (module_t *)list.p_values[i_index].p_object ;
-
- if( psz_module_name
- && !strcmp( psz_module_name, p_parser->psz_object_name ) )
+ p_parser = (module_t *)p_list->p_values[i_index].p_object ;
+ p_item = p_parser->p_config;
+ while( p_item && p_item->i_type != CONFIG_HINT_END )
{
- break;
- }
- }
-
- if( !p_parser || i_index == list.i_count )
- {
- vlc_list_release( list );
- return;
- }
+ switch( p_item->i_type )
+ {
+ case CONFIG_HINT_CATEGORY:
+ /* force the content to the top of the page */
+ if ( category_table )
+ {
+ QWidget *space = new QWidget( category_table );
+ category_table->setStretchFactor( space, 10 );
+ category_table = NULL;
+ }
+
+ /*
+ * Now we can start taking care of the new category
+ */
+ if( p_item->i_type == CONFIG_HINT_CATEGORY )
+ {
+ category_label = new QString( p_item->psz_text );
+ QStringList path;
+ if ( strcmp( p_parser->psz_object_name, "main" ) )
+ {
+ path += _( "Plugins" );
+ path += p_parser->psz_capability;
+ path += p_parser->psz_object_name;
+ }
+ path += *category_label;
+ QFrame *page = addPage( path );
+ QVBoxLayout *toplayout = new QVBoxLayout( page);
+ QScrollView *sv = new QScrollView(page);
+ sv->setResizePolicy(QScrollView::AutoOneFit);
+ sv->setFrameStyle(QScrollView::NoFrame);
+ toplayout->addWidget(sv);
+ category_table = new QVBox(sv->viewport());
+ sv->addChild(category_table);
+ category_table->setSpacing(spacingHint());
+ }
- p_item = p_parser->p_config;
- if( p_item ) do
- {
- switch( p_item->i_type )
- {
+ break;
- case CONFIG_HINT_CATEGORY:
- case CONFIG_HINT_END:
+ case CONFIG_ITEM_MODULE:
- /*
- * Now we can start taking care of the new category
- */
- if( p_item->i_type == CONFIG_HINT_CATEGORY )
{
- category_label = new QString( p_item->psz_text );
- QFrame *page = addPage( *category_label );
- QVBoxLayout *toplayout = new QVBoxLayout( page);
- QScrollView *sv = new QScrollView(page);
- sv->setResizePolicy(QScrollView::AutoOneFit);
- sv->setFrameStyle(QScrollView::NoFrame);
- toplayout->addWidget(sv);
- category_table = new QVBox(sv->viewport());
- sv->addChild(category_table);
- toplayout->addStretch(10);
- category_table->setSpacing(spacingHint());
- }
+ vlc_mutex_lock( p_item->p_lock );
+ KPluginsBox *item_frame =
+ new KPluginsBox( p_intf, p_item->psz_text,
+ p_item->psz_value ? p_item->psz_value :"",
+ category_table,
+ spacingHint(),
+ this );
+ QConfigItem *ci = new QConfigItem(this,
+ p_item->psz_name,
+ p_item->i_type,
+ p_item->psz_value);
+ connect(item_frame, SIGNAL(selectionChanged(const QString &)),
+ ci, SLOT(setValue(const QString &)));
+
+
+ /* build a list of available plugins */
+ for( int i_index = 0; i_index < p_list->i_count; i_index++ )
+ {
+ module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object ;
+
+ if( !strcmp( p_parser->psz_capability,
+ p_item->psz_type ) )
+ {
+ new QListViewItem(item_frame->getListView(),
+ p_parser->psz_object_name,
+ p_parser->psz_longname);
+ }
+ }
+ vlc_mutex_unlock( p_item->p_lock );
+ }
break;
- case CONFIG_ITEM_MODULE:
-
- {
-
- vlc_mutex_lock( p_item->p_lock );
- KPluginsBox *item_frame =
- new KPluginsBox( p_intf, p_item->psz_text,
- p_item->psz_value ? p_item->psz_value :"",
- category_table,
- spacingHint(),
- this );
- QConfigItem *ci = new QConfigItem(this,
- p_item->psz_name,
- p_item->i_type,
- p_item->psz_value);
- connect(item_frame, SIGNAL(selectionChanged(const QString &)),
- ci, SLOT(setValue(const QString &)));
-
-
- /* build a list of available plugins */
- for( i_index = 0; i_index < list.i_count; i_index++ )
+ case CONFIG_ITEM_STRING:
{
- p_parser = (module_t *)list.p_values[i_index].p_object ;
-
- if( !strcmp( p_parser->psz_capability,
- p_item->psz_type ) )
+ QHBox *hb = new QHBox(category_table);
+ hb->setSpacing(spacingHint());
+ new QLabel(p_item->psz_text, hb);
+ /* add input box with default value */
+ vlc_mutex_lock( p_item->p_lock );
+ QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
+ p_item->i_type,
+ p_item->psz_value ?
+ p_item->psz_value : "");
+ if ( p_item->ppsz_list )
{
- new QListViewItem(item_frame->getListView(),
- p_parser->psz_object_name,
- p_parser->psz_longname);
+ char **ppsz_list = p_item->ppsz_list;
+ KComboBox *p_combobox = new KComboBox( true, hb );
+ QToolTip::add(p_combobox, p_item->psz_longtext);
+ connect(p_combobox, SIGNAL(activated ( const QString & )),
+ ci, SLOT(setValue( const QString &)));
+ while ( *ppsz_list )
+ {
+ p_combobox->insertItem( *ppsz_list );
+ if ( !strcmp( *ppsz_list, p_item->psz_value ?
+ p_item->psz_value : "" ) )
+ {
+#if KDE_VERSION_MAJOR >= 3
+ p_combobox->setCurrentText( *ppsz_list );
+#else
+ p_combobox->setCurrentItem( p_combobox->count() );
+#endif
+ }
+ ppsz_list++;
+ }
+ }
+ else
+ {
+ KLineEdit *kl = new KLineEdit( p_item->psz_value ?
+ p_item->psz_value : "", hb);
+ connect(kl, SIGNAL(textChanged ( const QString & )),
+ ci, SLOT(setValue( const QString &)));
+ QToolTip::add(kl, p_item->psz_longtext);
+ kl->setMaxLength(40);
}
- }
- vlc_mutex_unlock( p_item->p_lock );
- }
- break;
+ vlc_mutex_unlock( p_item->p_lock );
+ }
+ break;
- case CONFIG_ITEM_STRING:
- {
- QHBox *hb = new QHBox(category_table);
- hb->setSpacing(spacingHint());
- new QLabel(p_item->psz_text, hb);
- /* add input box with default value */
- vlc_mutex_lock( p_item->p_lock );
-
- KLineEdit *kl = new KLineEdit( p_item->psz_value ?
- p_item->psz_value : "", hb);
- QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
- p_item->i_type,
- p_item->psz_value ?
- p_item->psz_value : "");
- connect(kl, SIGNAL(textChanged ( const QString & )),
- ci, SLOT(setValue( const QString &)));
- QToolTip::add(kl, p_item->psz_longtext);
- kl->setMaxLength(40);
-
- vlc_mutex_unlock( p_item->p_lock );
-
- }
- break;
+ case CONFIG_ITEM_FILE:
+ case CONFIG_ITEM_DIRECTORY:
+ {
+ QHBox *hb = new QHBox(category_table);
+ hb->setSpacing(spacingHint());
+ new QLabel(p_item->psz_text, hb);
+ /* add input box with default value */
+ vlc_mutex_lock( p_item->p_lock );
- case CONFIG_ITEM_FILE:
- {
- QHBox *hb = new QHBox(category_table);
- hb->setSpacing(spacingHint());
- new QLabel(p_item->psz_text, hb);
- /* add input box with default value */
- vlc_mutex_lock( p_item->p_lock );
-
// KLineEdit *kl = new KLineEdit( p_item->psz_value ?
// p_item->psz_value : "", hb);
- QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
- p_item->i_type,
- p_item->psz_value ?
- p_item->psz_value : "");
+ QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
+ p_item->i_type,
+ p_item->psz_value ?
+ p_item->psz_value : "");
// QPushButton *bbrowse = new QPushButton( _("Browse"), hb );
- KURLRequester *kfile = new KURLRequester( p_item->psz_value ?
- p_item->psz_value : "",
- hb );
- connect(kfile, SIGNAL(textChanged ( const QString & )),
- ci, SLOT(setValue( const QString &)));
- QToolTip::add(kfile, p_item->psz_longtext);
- vlc_mutex_unlock( p_item->p_lock );
-
- }
- break;
-
- case CONFIG_ITEM_INTEGER:
- /* add input box with default value */
- {
- QHBox *hb = new QHBox(category_table);
- hb->setSpacing(spacingHint());
- new QLabel(p_item->psz_text, hb);
- QSpinBox *item_adj = new QSpinBox(-1, 99999, 1, hb);
- QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
- p_item->i_type,
- p_item->i_value);
- item_adj->setValue( p_item->i_value );
- connect(item_adj, SIGNAL(valueChanged( int)),
- ci, SLOT(setValue(int)));
- QToolTip::add(item_adj, p_item->psz_longtext);
- }
- break;
-
- case CONFIG_ITEM_FLOAT:
- {
- QHBox *hb = new QHBox(category_table);
- hb->setSpacing(spacingHint());
- new QLabel(p_item->psz_text, hb);
- KDoubleNumInput *kdi= new KDoubleNumInput(p_item->f_value, hb);
- kdi->setRange(-1, 99999, 0.01, false);
- QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
- p_item->i_type,
- p_item->f_value);
- connect(kdi, SIGNAL(valueChanged(double)),
- ci, SLOT(setValue(double)));
- QToolTip::add(kdi, p_item->psz_longtext);
-
- }
- break;
-
-
- case CONFIG_ITEM_BOOL:
+ KURLRequester *kfile = new KURLRequester( p_item->psz_value ?
+ p_item->psz_value : "",
+ hb );
+ if ( p_item->i_type == CONFIG_ITEM_DIRECTORY )
+ {
+ kfile->fileDialog()->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
+ }
+ connect(kfile, SIGNAL(textChanged ( const QString & )),
+ ci, SLOT(setValue( const QString &)));
+ QToolTip::add(kfile, p_item->psz_longtext);
+ vlc_mutex_unlock( p_item->p_lock );
+ }
+ break;
- /* add check button */
- {
- QCheckBox *bool_checkbutton =
- new QCheckBox(QString(p_item->psz_text), category_table);
- QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
- p_item->i_type,
- p_item->i_value);
- bool_checkbutton->setChecked(p_item->i_value);
- connect(bool_checkbutton, SIGNAL(stateChanged( int)),
- ci, SLOT(setValue(int)));
- QToolTip::add(bool_checkbutton, p_item->psz_longtext);
+ case CONFIG_ITEM_INTEGER:
+ /* add input box with default value */
+ {
+ QHBox *hb = new QHBox(category_table);
+ hb->setSpacing(spacingHint());
+ new QLabel(p_item->psz_text, hb);
+ QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
+ p_item->i_type,
+ p_item->i_value);
+ if ( p_item->i_min == 0 && p_item->i_max == 0 )
+ {
+ QSpinBox *item_adj = new QSpinBox(-1, 99999, 1, hb);
+ item_adj->setValue( p_item->i_value );
+ connect(item_adj, SIGNAL(valueChanged( int)),
+ ci, SLOT(setValue(int)));
+ QToolTip::add(item_adj, p_item->psz_longtext);
+ }
+ else
+ {
+ KIntNumInput *p_ii = new KIntNumInput( p_item->i_value, hb );
+ p_ii->setRange( p_item->i_min, p_item->i_max, 1, true );
+ connect( p_ii, SIGNAL( valueChanged( int ) ),
+ ci, SLOT( setValue( int ) ) );
+ QToolTip::add( p_ii, p_item->psz_longtext );
+ }
+ }
+ break;
- }
- break;
+ case CONFIG_ITEM_FLOAT:
+ {
+ QHBox *hb = new QHBox(category_table);
+ hb->setSpacing(spacingHint());
+ new QLabel(p_item->psz_text, hb);
+ KDoubleNumInput *kdi= new KDoubleNumInput(p_item->f_value, hb);
+ if ( p_item->f_min == 0 && p_item->f_max == 0 )
+ {
+ kdi->setRange(-1, 99999, 0.01, false);
+ }
+ else
+ {
+ kdi->setRange( p_item->f_min, p_item->f_max, 0.01, true );
+ }
+ QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
+ p_item->i_type,
+ p_item->f_value);
+ connect(kdi, SIGNAL(valueChanged(double)),
+ ci, SLOT(setValue(double)));
+ QToolTip::add(kdi, p_item->psz_longtext);
+ }
+ break;
- }
+ case CONFIG_ITEM_BOOL:
- p_item++;
+ /* add check button */
+ {
+ QCheckBox *bool_checkbutton =
+ new QCheckBox(QString(p_item->psz_text), category_table);
+ QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
+ p_item->i_type,
+ p_item->i_value);
+ bool_checkbutton->setChecked(p_item->i_value);
+ connect(bool_checkbutton, SIGNAL(stateChanged( int)),
+ ci, SLOT(setValue(int)));
+ QToolTip::add(bool_checkbutton, p_item->psz_longtext);
+
+ }
+ break;
+
+ }
+
+ p_item++;
+ }
}
- while( p_item->i_type != CONFIG_HINT_END );
+ /* force the content to the top of the page, even on the last page */
+ if ( category_table )
+ {
+ QWidget *space = new QWidget( category_table );
+ category_table->setStretchFactor( space, 10 );
+ category_table = NULL;
+ }
+
- vlc_list_release( &list );
+ vlc_list_release( p_list );
exec();
}
bool KPreferences::isConfigureable(QString module)
{
module_t *p_parser;
- vlc_list_t list;
+ vlc_list_t *p_list;
int i_index;
- list = vlc_list_find( this->p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+ p_list = vlc_list_find( this->p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
- for( i_index = 0; i_index < list.i_count; i_index++ )
+ for( i_index = 0; i_index < p_list->i_count; i_index++ )
{
- p_parser = (module_t *)list.p_values[i_index].p_object ;
+ p_parser = (module_t *)p_list->p_values[i_index].p_object ;
if( !module.compare( p_parser->psz_object_name ) )
{
bool ret = p_parser->i_config_items != 0;
- vlc_list_release( &list );
+ vlc_list_release( p_list );
return ret;
}
}
- vlc_list_release( &list );
+ vlc_list_release( p_list );
return false;
}
switch( p_config->getType() ) {
+ case CONFIG_ITEM_DIRECTORY:
case CONFIG_ITEM_STRING:
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_MODULE: