mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-24 02:42:52 +00:00
okular: use QUrl::fromUserInput() instead of custom URL verifier
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
f4e494e8a2
commit
c206805c4f
4 changed files with 4 additions and 101 deletions
|
@ -17,9 +17,6 @@ target_link_libraries(okular-searchtest ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY}
|
|||
kde4_add_test(okular-annotationstest annotationstest.cpp )
|
||||
target_link_libraries(okular-annotationstest ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} okularcore )
|
||||
|
||||
kde4_add_test(okular-urldetecttest urldetecttest.cpp )
|
||||
target_link_libraries(okular-urldetecttest ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} )
|
||||
|
||||
kde4_add_test(okular-editannotationcontentstest editannotationcontentstest.cpp testingutils.cpp)
|
||||
target_link_libraries(okular-editannotationcontentstest ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} ${QT_QTXML_LIBRARY} okularcore )
|
||||
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2013 Jaydeep Solanki <jaydp17@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest_kde.h>
|
||||
|
||||
#include "../ui/url_utils.h"
|
||||
|
||||
namespace Okular
|
||||
{
|
||||
class UrlDetectTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void testURL();
|
||||
void testURL_data();
|
||||
};
|
||||
|
||||
void UrlDetectTest::testURL()
|
||||
{
|
||||
QFETCH( QString, selectedText );
|
||||
QFETCH( QString, url );
|
||||
QCOMPARE( UrlUtils::getUrl( selectedText ), url );
|
||||
}
|
||||
|
||||
void UrlDetectTest::testURL_data()
|
||||
{
|
||||
QTest::addColumn<QString>( "selectedText" );
|
||||
QTest::addColumn<QString>( "url" );
|
||||
QTest::newRow( "1" ) << QString( "asdfhttp://okular.org" ) << QString();
|
||||
QTest::newRow( "2" ) << QString( "google.com/index.php/" ) << QString();
|
||||
QTest::newRow( "3" ) << QString( "http://google.com)" ) << QString();
|
||||
|
||||
QTest::newRow( "4" ) << QString( "https://okular.org" ) << QString( "https://okular.org" );
|
||||
QTest::newRow( "5" ) << QString( "www.google.com" ) << QString( "http://www.google.com" );
|
||||
QTest::newRow( "6" ) << QString( "asdf http://okular.kde.org/" ) << QString( "http://okular.kde.org/" );
|
||||
QTest::newRow( "7" ) << QString( "http://www.example.com/wpstyle/?p=364" ) << QString( "http://www.example.com/wpstyle/?p=364" );
|
||||
QTest::newRow( "8" ) << QString( "asdf http://okular.org fdsa" ) << QString( "http://okular.org" );
|
||||
QTest::newRow( "9" ) << QString( "http://google.com/ø" ) << QString( "http://google.com/ø" );
|
||||
QTest::newRow( "10" ) << QString( "http://www.wolframalpha.com/input/?i=Plot[%281%2Be^%28-%282%29v%29%29^%28-2%29+%2B+%282%29+%281%2Be^v%29^%28-2%29%2C+{t%2C-0.5%2C+0.5}]" ) << QString( "http://www.wolframalpha.com/input/?i=Plot[%281%2Be^%28-%282%29v%29%29^%28-2%29+%2B+%282%29+%281%2Be^v%29^%28-2%29%2C+{t%2C-0.5%2C+0.5}]" );
|
||||
QTest::newRow( "11" ) << QString( "http://uid:pass@example.com:8080" ) << QString( "http://uid:pass@example.com:8080" );
|
||||
QTest::newRow( "12" ) << QString( "www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf" ) << QString( "http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf" );
|
||||
QTest::newRow( "13" ) << QString( "http://IISServer/nwind?template=<ROOTxmlns:sql=\"urn:schemas-microsoft-com:xml-sql\"><sql:query>SELECTTOP2*FROM[OrderDetails]WHEREUnitPrice%26lt;10FORXMLAUTO</sql:query></ROOT>" ) << QString( "http://IISServer/nwind?template=<ROOTxmlns:sql=\"urn:schemas-microsoft-com:xml-sql\"><sql:query>SELECTTOP2*FROM[OrderDetails]WHEREUnitPrice%26lt;10FORXMLAUTO</sql:query></ROOT>" );
|
||||
QTest::newRow( "14" ) << QString( "https://www.example.com/foo/?bar=baz&inga=42&quux" ) << QString( "https://www.example.com/foo/?bar=baz&inga=42&quux" );
|
||||
QTest::newRow( "15" ) << QString( "http://foo.bar/#tag" ) << QString( "http://foo.bar/#tag" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QTEST_KDEMAIN_CORE( Okular::UrlDetectTest )
|
||||
|
||||
#include "urldetecttest.moc"
|
|
@ -82,7 +82,6 @@
|
|||
#include "core/tile.h"
|
||||
#include "settings.h"
|
||||
#include "settings_core.h"
|
||||
#include "url_utils.h"
|
||||
#include "magnifierview.h"
|
||||
|
||||
static int pageflags = PagePainter::Accessibility | PagePainter::EnhanceLinks |
|
||||
|
@ -2814,10 +2813,10 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
|
|||
{
|
||||
addWebShortcutsMenu( &menu, d->selectedText() );
|
||||
}
|
||||
const QString url = UrlUtils::getUrl( d->selectedText() );
|
||||
if ( !url.isEmpty() )
|
||||
const KUrl url = KUrl::fromUserInput( d->selectedText() );
|
||||
if ( url.isValid() )
|
||||
{
|
||||
const QString squeezedText = KStringHandler::rsqueeze( url, 30 );
|
||||
const QString squeezedText = KStringHandler::rsqueeze( url.prettyUrl(), 30 );
|
||||
httpLink = menu.addAction( i18n( "Go to '%1'", squeezedText ) );
|
||||
}
|
||||
QAction *choice = menu.exec( e->globalPos() );
|
||||
|
@ -2832,7 +2831,7 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
|
|||
d->tts()->say( text );
|
||||
}
|
||||
else if ( choice == httpLink )
|
||||
new KRun( KUrl( url ), this );
|
||||
new KRun( url, this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2013 Jaydeep Solanki <jaydp17@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef URL_UTILS_H
|
||||
#define URL_UTILS_H
|
||||
|
||||
#include <QRegExp>
|
||||
|
||||
namespace UrlUtils
|
||||
{
|
||||
QString getUrl( QString txt )
|
||||
{
|
||||
// match the url
|
||||
QRegExp reg( QString( "\\b((https?|ftp)://(www\\d{0,3}[.])?[\\S]+)|((www\\d{0,3}[.])[\\S]+)" ) );
|
||||
// blocks from detecting invalid urls
|
||||
QRegExp reg1( QString( "[\\w'\"\\(\\)]+https?://|[\\w'\"\\(\\)]+ftp://|[\\w'\"\\(\\)]+www\\d{0,3}[.]" ) );
|
||||
txt = txt.remove( "\n" );
|
||||
if( reg1.indexIn( txt ) < 0 && reg.indexIn( txt ) >= 0 && QUrl( reg.cap() ).isValid() )
|
||||
{
|
||||
QString url = reg.cap();
|
||||
if( url.startsWith( "www" ) )
|
||||
url.prepend( "http://" );
|
||||
return url;
|
||||
}
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue