+ spin->setMaximum( (double)p_item->max.f );
+ spin->setMinimum( (double)p_item->min.f );
+}
+
+
+/**********************************************************************
+ * Key selector widget
+ **********************************************************************/
+KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
+ module_config_t *_p_item,
+ QWidget *_parent, QGridLayout *l,
+ int &line ) :
+ ConfigControl( _p_this, _p_item, _parent )
+
+{
+ QWidget *keyContainer = new QWidget;
+ QGridLayout *gLayout = new QGridLayout( keyContainer );
+
+ label = new QLabel(
+ qtr( "Select an action to change the associated hotkey") );
+
+ /* Deactivated for now
+ QLabel *searchLabel = new QLabel( qtr( "Search" ) );
+ QLineEdit *actionSearch = new QLineEdit;*/
+
+ table = new QTreeWidget;
+ table->setColumnCount(2);
+ table->headerItem()->setText( 0, qtr( "Action" ) );
+ table->headerItem()->setText( 1, qtr( "Shortcut" ) );
+
+ shortcutValue = new KeyShortcutEdit;
+ shortcutValue->setReadOnly(true);
+
+ QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
+ QPushButton *setButton = new QPushButton( qtr( "Set" ) );
+ setButton->setDefault( true );
+ finish();
+
+ gLayout->addWidget( label, 0, 0, 1, 4 );
+ /* deactivated for now
+ gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
+ gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
+ gLayout->addWidget( table, 2, 0, 1, 4 );
+ gLayout->addWidget( clearButton, 3, 0, 1, 1 );
+ gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
+ gLayout->addWidget( setButton, 3, 3, 1, 1 );
+
+ l->addWidget( keyContainer, line, 0, 1, 2 );
+
+ CONNECT( clearButton, clicked(), shortcutValue, clear() );
+ CONNECT( clearButton, clicked(), this, setTheKey() );
+ BUTTONACT( setButton, setTheKey() );
+}
+
+void KeySelectorControl::finish()
+{
+ if( label )
+ label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
+
+ /* Fill the table */
+ table->setColumnCount( 2 );
+ table->setAlternatingRowColors( true );
+
+ /* Get the main Module */
+ module_t *p_main = module_Find( p_this, "main" );
+ assert( p_main );
+
+ /* Access to the module_config_t */
+ unsigned confsize;
+ module_config_t *p_config;
+
+ p_config = module_GetConfig (p_main, &confsize);
+
+ for (size_t i = 0; i < confsize; i++)
+ {
+ module_config_t *p_item = p_config + i;
+
+ /* If we are a key option not empty */
+ if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
+ && strstr( p_item->psz_name , "key-" )
+ && !EMPTY_STR( p_item->psz_text ) )
+ {
+ /*
+ Each tree item has:
+ - QString text in column 0
+ - QString name in data of column 0
+ - KeyValue in String in column 1
+ - KeyValue in int in column 1
+ */
+ QTreeWidgetItem *treeItem = new QTreeWidgetItem();
+ treeItem->setText( 0, qtr( p_item->psz_text ) );
+ treeItem->setData( 0, Qt::UserRole,
+ QVariant( qfu( p_item->psz_name ) ) );
+ treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
+ treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
+ table->addTopLevelItem( treeItem );
+ }
+ }
+ module_PutConfig (p_config);
+ module_Put (p_main);
+
+ table->resizeColumnToContents( 0 );
+
+ CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
+ this, selectKey( QTreeWidgetItem * ) );
+ CONNECT( table, itemSelectionChanged (),
+ this, select1Key() );
+
+ CONNECT( shortcutValue, pressed(), this, selectKey() );
+}
+
+/* Show the key selected from the table in the keySelector */
+void KeySelectorControl::select1Key()
+{
+ QTreeWidgetItem *keyItem = table->currentItem();
+ shortcutValue->setText( keyItem->text( 1 ) );
+ shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
+}
+
+void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
+{
+ /* This happens when triggered by ClickEater */
+ if( keyItem == NULL ) keyItem = table->currentItem();
+
+ /* This can happen when nothing is selected on the treeView
+ and the shortcutValue is clicked */
+ if( !keyItem ) return;
+
+ /* Launch a small dialog to ask for a new key */
+ KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget );
+ d->exec();
+
+ if( d->result() == QDialog::Accepted )
+ {
+ int newValue = d->keyValue;
+ shortcutValue->setText( VLCKeyToString( newValue ) );
+ shortcutValue->setValue( newValue );
+
+ if( d->conflicts )
+ {
+ QTreeWidgetItem *it;
+ for( int i = 0; i < table->topLevelItemCount() ; i++ )
+ {
+ it = table->topLevelItem(i);
+ if( ( keyItem != it )
+ && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) )
+ {
+ it->setData( 1, Qt::UserRole, QVariant( -1 ) );
+ it->setText( 1, qtr( "Unset" ) );
+ }
+ }
+ /* We already made an OK once. */
+ setTheKey();
+ }
+ }
+ delete d;
+}
+
+void KeySelectorControl::setTheKey()
+{
+ table->currentItem()->setText( 1, shortcutValue->text() );
+ table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );
+}
+
+void KeySelectorControl::doApply()
+{
+ QTreeWidgetItem *it;
+ for( int i = 0; i < table->topLevelItemCount() ; i++ )
+ {
+ it = table->topLevelItem(i);
+ if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
+ config_PutInt( p_this,
+ qtu( it->data( 0, Qt::UserRole ).toString() ),
+ it->data( 1, Qt::UserRole ).toInt() );
+ }
+}
+
+KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
+ QString keyToChange,
+ QWidget *_parent ) :
+ QDialog( _parent ), keyValue(0)
+{
+ setModal( true );
+ conflicts = false;
+
+ table = _table;
+ setWindowTitle( qtr( "Hotkey for " ) + keyToChange );
+
+ vLayout = new QVBoxLayout( this );
+ selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
+ vLayout->addWidget( selected , Qt::AlignCenter );
+
+ buttonBox = new QDialogButtonBox;
+ QPushButton *ok = new QPushButton( qtr("OK") );
+ QPushButton *cancel = new QPushButton( qtr("Cancel") );
+ buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
+ buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
+ ok->setDefault( true );
+
+ vLayout->addWidget( buttonBox );
+ buttonBox->hide();
+
+ CONNECT( buttonBox, accepted(), this, accept() );
+ CONNECT( buttonBox, rejected(), this, reject() );
+}
+
+void KeyInputDialog::checkForConflicts( int i_vlckey )
+{
+ QList<QTreeWidgetItem *> conflictList =
+ table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 );
+
+ if( conflictList.size() )
+ {
+ QLabel *warning = new QLabel(
+ qtr("Warning: the key is already assigned to \"") +
+ conflictList[0]->text( 0 ) + "\"" );
+ vLayout->insertWidget( 1, warning );
+ buttonBox->show();
+
+ conflicts = true;
+ }
+ else accept();