Commit 0268197b authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt: open network fixes and simplifications

Close #5328
parent 972e5e45
......@@ -565,40 +565,50 @@ NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
OpenPanel( _parent, _p_intf )
{
ui.setupUi( this );
CONNECT( ui.urlComboBox, editTextChanged( const QString& ), this, updateMRL());
/* CONNECTs */
CONNECT( ui.urlComboBox->lineEdit(), textChanged( const QString& ), this, updateMRL());
CONNECT( ui.urlComboBox, currentIndexChanged( const QString& ), this, updateMRL());
/* */
if( var_InheritBool( p_intf, "qt-recentplay" ) )
{
mrlList = new QStringListModel(
getSettings()->value( "Open/netMRL" ).toStringList() );
ui.urlComboBox->setModel( mrlList );
ui.urlComboBox->clearEditText();
CONNECT( ui.urlComboBox->lineEdit(), editingFinished(), this, updateModel() );
b_recentList = true;
ui.urlComboBox->addItems( getSettings()->value( "Open/netMRL" ).toStringList() );
ui.urlComboBox->setMaxCount( 10 );
}
else
mrlList = NULL;
b_recentList = false;
/* Use a simple validator for URLs */
ui.urlComboBox->setValidator( new UrlValidator( this ) );
ui.urlComboBox->setFocus();
}
NetOpenPanel::~NetOpenPanel()
{
if( !mrlList ) return;
if( !b_recentList ) return;
QStringList tempL = mrlList->stringList();
while( tempL.count() > 8 ) tempL.removeFirst();
/* Create the list with the current items */
QStringList mrlList;
for( int i = 0; i < ui.urlComboBox->count(); i++ )
mrlList << ui.urlComboBox->itemText( i );
getSettings()->setValue( "Open/netMRL", tempL );
delete mrlList;
/* Clean the list... */
#if HAS_QT45
mrlList.removeDuplicates();
#endif
/* ...and save the 8 last entries */
getSettings()->setValue( "Open/netMRL", mrlList );
}
void NetOpenPanel::clear()
{}
{
ui.urlComboBox->clear();
}
void NetOpenPanel::onAccept()
{
if( ui.urlComboBox->findText( ui.urlComboBox->currentText() ) == -1 )
ui.urlComboBox->insertItem( 0, ui.urlComboBox->currentText());
}
void NetOpenPanel::onFocus()
{
......@@ -610,6 +620,9 @@ void NetOpenPanel::updateMRL()
{
QString url = ui.urlComboBox->lineEdit()->text();
if( url.isEmpty() )
return;
emit methodChanged( qfu( "network-caching" ) );
QStringList qsl;
......@@ -617,20 +630,6 @@ void NetOpenPanel::updateMRL()
emit mrlUpdated( qsl, "" );
}
void NetOpenPanel::updateModel()
{
assert( mrlList );
QStringList tempL = mrlList->stringList();
if( !tempL.contains( ui.urlComboBox->lineEdit()->text() ) )
tempL.append( ui.urlComboBox->lineEdit()->text() );
mrlList->setStringList( tempL );
}
void UrlValidator::fixup( QString& str ) const
{
str = str.trimmed();
}
QValidator::State UrlValidator::validate( QString& str, int& ) const
{
if( str.contains( ' ' ) )
......@@ -640,6 +639,11 @@ QValidator::State UrlValidator::validate( QString& str, int& ) const
return QValidator::Acceptable;
}
void UrlValidator::fixup( QString& str ) const
{
str = str.trimmed();
}
/**************************************************************************
* Open Capture device ( DVB, PVR, V4L, and similar ) *
**************************************************************************/
......
......@@ -73,6 +73,7 @@ public:
virtual ~OpenPanel() {};
virtual void clear() = 0;
virtual void onFocus() {}
virtual void onAccept() {}
protected:
intf_thread_t *p_intf;
public slots:
......@@ -140,13 +141,12 @@ public:
virtual ~NetOpenPanel();
virtual void clear() ;
void onFocus();
void onAccept();
private:
Ui::OpenNetwork ui;
QStringListModel *mrlList;
bool b_recentList;
public slots:
virtual void updateMRL();
private slots:
void updateModel();
};
class UrlValidator : public QValidator
......
......@@ -358,8 +358,8 @@ void OpenDialog::enqueue( bool b_enqueue )
return;
}
/* for( int i = 0; i < OPEN_TAB_MAX; i++ )
dynamic_cast<OpenPanel*>( ui.Tab->widget( i ) )->onAccept(); */
for( int i = 0; i < OPEN_TAB_MAX; i++ )
dynamic_cast<OpenPanel*>( ui.Tab->widget( i ) )->onAccept();
/* Sort alphabetically */
itemsMRL.sort();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment