[vlc-commits] Qt: update QUrlValidator (fix #9932)

Francois Cartegnie git at videolan.org
Mon Dec 2 18:59:09 CET 2013


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Dec  2 18:54:55 2013 +0100| [2652d1bcc522a160b13889a1f201dce92aa1d3eb] | committer: Francois Cartegnie

Qt: update QUrlValidator (fix #9932)

somehow #3435

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2652d1bcc522a160b13889a1f201dce92aa1d3eb
---

 modules/gui/qt4/util/validators.cpp |   23 +++++++++++++++++++----
 modules/gui/qt4/util/validators.hpp |    1 +
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/modules/gui/qt4/util/validators.cpp b/modules/gui/qt4/util/validators.cpp
index 56be4e9..397f4b8 100644
--- a/modules/gui/qt4/util/validators.cpp
+++ b/modules/gui/qt4/util/validators.cpp
@@ -24,12 +24,27 @@
 
 #include "validators.hpp"
 
+#include <QUrl>
+
 QValidator::State UrlValidator::validate( QString& str, int& ) const
 {
-    str = str.trimmed();
-    if( str.contains( ' ' ) )
+    if( str.startsWith( ' ' ) )
         return QValidator::Invalid;
-    if( !str.contains( "://" ) )
+
+    if ( str.isEmpty() )
+        return QValidator::Intermediate;
+
+    QUrl url( str );
+    if ( url.scheme().isEmpty() )
         return QValidator::Intermediate;
-    return QValidator::Acceptable;
+
+    return ( url.isValid() ) ? QValidator::Acceptable : QValidator::Intermediate;
+}
+
+void UrlValidator::fixup( QString & input ) const
+{
+    while( input.startsWith( ' ' ) )
+        input.chop( 1 );
+    QUrl fixed( input, QUrl::TolerantMode );
+    input = fixed.toString();
 }
diff --git a/modules/gui/qt4/util/validators.hpp b/modules/gui/qt4/util/validators.hpp
index f40be28..4a0cece 100644
--- a/modules/gui/qt4/util/validators.hpp
+++ b/modules/gui/qt4/util/validators.hpp
@@ -29,6 +29,7 @@ class UrlValidator : public QValidator
 public:
    UrlValidator( QObject *parent ) : QValidator( parent ) { }
    virtual QValidator::State validate( QString&, int& ) const;
+   virtual void fixup ( QString & input ) const;
 };
 
 #endif // VALIDATORS_HPP



More information about the vlc-commits mailing list