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