From f8d5652706916e4b7471a6d40f0d1c23854a79a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Wed, 7 Jul 2010 23:56:33 +0300 Subject: [PATCH] Qt4: do not allow spaces in network URLs (fix #3870) --- modules/gui/qt4/components/open_panels.cpp | 16 ++++++++++++++++ modules/gui/qt4/components/open_panels.hpp | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/modules/gui/qt4/components/open_panels.cpp b/modules/gui/qt4/components/open_panels.cpp index 0a023c1c89..b257900bfb 100644 --- a/modules/gui/qt4/components/open_panels.cpp +++ b/modules/gui/qt4/components/open_panels.cpp @@ -551,6 +551,8 @@ NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) : } else mrlList = NULL; + + ui.urlText->setValidator( new UrlValidator( this ) ); } NetOpenPanel::~NetOpenPanel() @@ -624,6 +626,20 @@ void NetOpenPanel::updateCompleter() mrlList->setStringList( tempL ); } +void UrlValidator::fixup( QString& str ) const +{ + str = str.trimmed(); +} + +QValidator::State UrlValidator::validate( QString& str, int& pos ) const +{ + if( str.contains( ' ' ) ) + return QValidator::Invalid; + if( !str.contains( "://" ) ) + return QValidator::Intermediate; + return QValidator::Acceptable; +} + /************************************************************************** * Open Capture device ( DVB, PVR, V4L, and similar ) * **************************************************************************/ diff --git a/modules/gui/qt4/components/open_panels.hpp b/modules/gui/qt4/components/open_panels.hpp index 2999b5b518..723fe4561a 100644 --- a/modules/gui/qt4/components/open_panels.hpp +++ b/modules/gui/qt4/components/open_panels.hpp @@ -149,6 +149,15 @@ private slots: void updateCompleter(); }; +class UrlValidator : public QValidator +{ + Q_OBJECT +public: + UrlValidator( QObject *parent ) : QValidator( parent ) { } + void fixup( QString& ) const; + QValidator::State validate( QString&, int& ) const; +}; + class DiscOpenPanel: public OpenPanel { Q_OBJECT -- 2.39.5