Remove Url::Class, add Qt4x5::Url::ensureLeadingSlash() and fix all related

This commit is contained in:
Timon Wong 2013-05-31 12:20:25 +08:00
parent f0c1aa26e7
commit f30c41dbf6
19 changed files with 88 additions and 124 deletions

View file

@ -29,7 +29,6 @@
#include "ufile.hh" #include "ufile.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "qt4x5.hh" #include "qt4x5.hh"
#include "url.hh"
namespace Aard { namespace Aard {

View file

@ -8,11 +8,12 @@
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include <limits.h> #include <limits.h>
#include <QFile> #include <QFile>
#include <QUrl>
#include "folding.hh" #include "folding.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "dprintf.hh" #include "dprintf.hh"
#include "url.hh" #include "qt4x5.hh"
using std::vector; using std::vector;
using std::string; using std::string;
@ -875,11 +876,11 @@ QPair< ArticleRequest::Words, ArticleRequest::Spacings > ArticleRequest::splitIn
string ArticleRequest::linkWord( QString const & str ) string ArticleRequest::linkWord( QString const & str )
{ {
Url::Class url; QUrl url;
url.setScheme( "gdlookup" ); url.setScheme( "gdlookup" );
url.setHost( "localhost" ); url.setHost( "localhost" );
url.setPath( str ); url.setPath( Qt4x5::Url::ensureLeadingSlash( str ) );
string escapedResult = Html::escape( str.toUtf8().data() ); string escapedResult = Html::escape( str.toUtf8().data() );
return string( "<a href=\"" ) + url.toEncoded().data() + "\">" + escapedResult +"</a>"; return string( "<a href=\"" ) + url.toEncoded().data() + "\">" + escapedResult +"</a>";

View file

@ -7,11 +7,12 @@
#include <stdint.h> #include <stdint.h>
#endif #endif
#include <QUrl>
#include "article_netmgr.hh" #include "article_netmgr.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "dprintf.hh" #include "dprintf.hh"
#include "qt4x5.hh" #include "qt4x5.hh"
#include "url.hh"
using std::string; using std::string;
@ -57,7 +58,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
{ {
// We have to override the local load policy for the qrc scheme, hence // We have to override the local load policy for the qrc scheme, hence
// we use qrcx and redirect it here back to qrc // we use qrcx and redirect it here back to qrc
Url::Class newUrl( req.url() ); QUrl newUrl( req.url() );
newUrl.setScheme( "qrc" ); newUrl.setScheme( "qrc" );
newUrl.setHost( "" ); newUrl.setHost( "" );
@ -85,7 +86,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
//DPRINTF( "Referer: %s\n", referer.data() ); //DPRINTF( "Referer: %s\n", referer.data() );
Url::Class refererUrl = QUrl::fromEncoded( referer ); QUrl refererUrl = QUrl::fromEncoded( referer );
//DPRINTF( "Considering %s vs %s\n", getHostBase( req.url() ).toUtf8().data(), //DPRINTF( "Considering %s vs %s\n", getHostBase( req.url() ).toUtf8().data(),
// getHostBase( refererUrl ).toUtf8().data() ); // getHostBase( refererUrl ).toUtf8().data() );
@ -105,8 +106,8 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
QString fileName = req.url().toLocalFile(); QString fileName = req.url().toLocalFile();
if( req.url().host().isEmpty() && articleMaker.adjustFilePath( fileName ) ) if( req.url().host().isEmpty() && articleMaker.adjustFilePath( fileName ) )
{ {
Url::Class newUrl( req.url() ); QUrl newUrl( req.url() );
newUrl.setPath( QUrl::fromLocalFile( fileName ).path() ); newUrl.setPath( Qt4x5::Url::ensureLeadingSlash( QUrl::fromLocalFile( fileName ).path() ) );
QNetworkRequest newReq( req ); QNetworkRequest newReq( req );
newReq.setUrl( newUrl ); newReq.setUrl( newUrl );
@ -232,7 +233,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
if ( url.scheme() == "gdpicture" ) if ( url.scheme() == "gdpicture" )
{ {
contentType = "text/html"; contentType = "text/html";
Url::Class imgUrl ( url ); QUrl imgUrl ( url );
imgUrl.setScheme( "bres" ); imgUrl.setScheme( "bres" );
return articleMaker.makePicturePage( imgUrl.toEncoded().data() ); return articleMaker.makePicturePage( imgUrl.toEncoded().data() );
} }

View file

@ -13,6 +13,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QFileDialog> #include <QFileDialog>
#include <QDebug> #include <QDebug>
#include <QUrl>
#include <QWebElement> #include <QWebElement>
#include <QCryptographicHash> #include <QCryptographicHash>
#include "folding.hh" #include "folding.hh"
@ -22,7 +23,6 @@
#include "dprintf.hh" #include "dprintf.hh"
#include "ffmpegaudio.hh" #include "ffmpegaudio.hh"
#include "qt4x5.hh" #include "qt4x5.hh"
#include "url.hh"
#include <assert.h> #include <assert.h>
@ -165,7 +165,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
// Load the default blank page instantly, so there would be no flicker. // Load the default blank page instantly, so there would be no flicker.
QString contentType; QString contentType;
Url::Class blankPage( "gdlookup://localhost?blank=1" ); QUrl blankPage( "gdlookup://localhost?blank=1" );
sptr< Dictionary::DataRequest > r = articleNetMgr.getResource( blankPage, sptr< Dictionary::DataRequest > r = articleNetMgr.getResource( blankPage,
contentType ); contentType );
@ -198,7 +198,7 @@ void ArticleView::showDefinition( QString const & word, unsigned group,
QString const & scrollTo, QString const & scrollTo,
Contexts const & contexts ) Contexts const & contexts )
{ {
Url::Class req; QUrl req;
req.setScheme( "gdlookup" ); req.setScheme( "gdlookup" );
req.setHost( "localhost" ); req.setHost( "localhost" );
@ -255,7 +255,7 @@ void ArticleView::showAnticipation()
void ArticleView::loadFinished( bool ) void ArticleView::loadFinished( bool )
{ {
Url::Class url = ui.definition->url(); QUrl url = ui.definition->url();
// See if we have any iframes in need of expansion // See if we have any iframes in need of expansion
@ -482,7 +482,7 @@ void ArticleView::tryMangleWebsiteClickedUrl( QUrl & url, Contexts & contexts )
contexts[ ca.mid( 7 ) ] = QString::fromLatin1( url.toEncoded() ); contexts[ ca.mid( 7 ) ] = QString::fromLatin1( url.toEncoded() );
Url::Class target; QUrl target;
QString queryWord = result.toString(); QString queryWord = result.toString();
@ -665,7 +665,7 @@ QString ArticleView::getMutedForGroup( unsigned group )
void ArticleView::linkHovered ( const QString & link, const QString & , const QString & ) void ArticleView::linkHovered ( const QString & link, const QString & , const QString & )
{ {
QString msg; QString msg;
Url::Class url(link); QUrl url(link);
if ( url.scheme() == "bres" ) if ( url.scheme() == "bres" )
{ {
@ -723,7 +723,7 @@ void ArticleView::linkClicked( QUrl const & url_ )
{ {
updateCurrentArticleFromCurrentFrame(); updateCurrentArticleFromCurrentFrame();
Url::Class url( url_ ); QUrl url( url_ );
Contexts contexts; Contexts contexts;
tryMangleWebsiteClickedUrl( url, contexts ); tryMangleWebsiteClickedUrl( url, contexts );
@ -1044,7 +1044,7 @@ vector< ResourceToSaveHandler * > ArticleView::saveResource( const QUrl & url, c
void ArticleView::updateMutedContents() void ArticleView::updateMutedContents()
{ {
Url::Class currentUrl = ui.definition->url(); QUrl currentUrl = ui.definition->url();
if ( currentUrl.scheme() != "gdlookup" ) if ( currentUrl.scheme() != "gdlookup" )
return; // Weird url -- do nothing return; // Weird url -- do nothing
@ -1164,7 +1164,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
QAction * saveImageAction = 0; QAction * saveImageAction = 0;
QAction * saveSoundAction = 0; QAction * saveSoundAction = 0;
Url::Class targetUrl( r.linkUrl() ); QUrl targetUrl( r.linkUrl() );
Contexts contexts; Contexts contexts;
tryMangleWebsiteClickedUrl( targetUrl, contexts ); tryMangleWebsiteClickedUrl( targetUrl, contexts );
@ -1193,7 +1193,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
} }
QWebElement el = r.element(); QWebElement el = r.element();
Url::Class imageUrl; QUrl imageUrl;
if( !popupView && el.tagName().compare( "img", Qt::CaseInsensitive ) == 0 ) if( !popupView && el.tagName().compare( "img", Qt::CaseInsensitive ) == 0 )
{ {
imageUrl = QUrl::fromPercentEncoding( el.attribute( "src" ).toLatin1() ); imageUrl = QUrl::fromPercentEncoding( el.attribute( "src" ).toLatin1() );
@ -1381,7 +1381,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
else else
if( result == saveImageAction || result == saveSoundAction ) if( result == saveImageAction || result == saveSoundAction )
{ {
Url::Class url = ( result == saveImageAction ) ? imageUrl : targetUrl; QUrl url = ( result == saveImageAction ) ? imageUrl : targetUrl;
QString savePath; QString savePath;
QString fileName; QString fileName;

View file

@ -6,12 +6,12 @@
#include <QWebView> #include <QWebView>
#include <QMap> #include <QMap>
#include <QUrl>
#include <list> #include <list>
#include "article_netmgr.hh" #include "article_netmgr.hh"
#include "instances.hh" #include "instances.hh"
#include "groupcombobox.hh" #include "groupcombobox.hh"
#include "ui_articleview.h" #include "ui_articleview.h"
#include "url.hh"
class ResourceToSaveHandler; class ResourceToSaveHandler;
@ -42,7 +42,7 @@ class ArticleView: public QFrame
/// a multitude of requests. /// a multitude of requests.
std::list< sptr< Dictionary::DataRequest > > resourceDownloadRequests; std::list< sptr< Dictionary::DataRequest > > resourceDownloadRequests;
/// Url of the resourceDownloadRequests /// Url of the resourceDownloadRequests
Url::Class resourceDownloadUrl; QUrl resourceDownloadUrl;
/// For resources opened via desktop services /// For resources opened via desktop services
QString desktopOpenedTempFile; QString desktopOpenedTempFile;

21
dsl.cc
View file

@ -48,7 +48,6 @@
#include <QtSvg/QSvgRenderer> #include <QtSvg/QSvgRenderer>
#include "qt4x5.hh" #include "qt4x5.hh"
#include "url.hh"
namespace Dsl { namespace Dsl {
@ -774,10 +773,10 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
( !resourceZip.isOpen() || ( !resourceZip.isOpen() ||
!resourceZip.hasFile( Utf8::decode( filename ) ) ); !resourceZip.hasFile( Utf8::decode( filename ) ) );
Url::Class url; QUrl url;
url.setScheme( "gdau" ); url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( search ? "search" : getId().c_str() ) ); url.setHost( QString::fromUtf8( search ? "search" : getId().c_str() ) );
url.setPath( QString::fromUtf8( filename.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( filename.c_str() ) ) );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";
@ -789,10 +788,10 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
else else
if ( Filetype::isNameOfPicture( filename ) ) if ( Filetype::isNameOfPicture( filename ) )
{ {
Url::Class url; QUrl url;
url.setScheme( "bres" ); url.setScheme( "bres" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::fromUtf8( filename.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( filename.c_str() ) ) );
vector< char > imgdata; vector< char > imgdata;
bool resize = false; bool resize = false;
@ -866,10 +865,10 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
{ {
// Unknown file type, downgrade to a hyperlink // Unknown file type, downgrade to a hyperlink
Url::Class url; QUrl url;
url.setScheme( "bres" ); url.setScheme( "bres" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::fromUtf8( filename.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( filename.c_str() ) ) );
result += string( "<a class=\"dsl_s\" href=\"" ) + url.toEncoded().data() result += string( "<a class=\"dsl_s\" href=\"" ) + url.toEncoded().data()
+ "\">" + processNodeChildren( node ) + "</a>"; + "\">" + processNodeChildren( node ) + "</a>";
@ -939,11 +938,11 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
else else
if ( node.tagName == GD_NATIVE_TO_WS( L"ref" ) ) if ( node.tagName == GD_NATIVE_TO_WS( L"ref" ) )
{ {
Url::Class url; QUrl url;
url.setScheme( "gdlookup" ); url.setScheme( "gdlookup" );
url.setHost( "localhost" ); url.setHost( "localhost" );
url.setPath( gd::toQString( node.renderAsText() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( gd::toQString( node.renderAsText() ) ) );
if( !node.tagAttrs.empty() ) if( !node.tagAttrs.empty() )
{ {
QString attr = gd::toQString( node.tagAttrs ).remove( '\"' ); QString attr = gd::toQString( node.tagAttrs ).remove( '\"' );
@ -963,13 +962,13 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
{ {
// Special case - insided card header was not parsed // Special case - insided card header was not parsed
Url::Class url; QUrl url;
url.setScheme( "gdlookup" ); url.setScheme( "gdlookup" );
url.setHost( "localhost" ); url.setHost( "localhost" );
wstring nodeStr = node.renderAsText(); wstring nodeStr = node.renderAsText();
ArticleDom nodeDom( nodeStr ); ArticleDom nodeDom( nodeStr );
url.setPath( gd::toQString( nodeDom.root.renderAsText() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( gd::toQString( nodeDom.root.renderAsText() ) ) );
result += string( "<a class=\"dsl_ref\" href=\"" ) + url.toEncoded().data() +"\">" + processNodeChildren( nodeDom.root ) + "</a>"; result += string( "<a class=\"dsl_ref\" href=\"" ) + url.toEncoded().data() +"\">" + processNodeChildren( nodeDom.root ) + "</a>";
} }

View file

@ -15,7 +15,6 @@
#include "utf8.hh" #include "utf8.hh"
#include "dprintf.hh" #include "dprintf.hh"
#include "qt4x5.hh" #include "qt4x5.hh"
#include "url.hh"
namespace Forvo { namespace Forvo {
@ -174,7 +173,7 @@ void ForvoArticleRequest::addQuery( QNetworkAccessManager & mgr,
else else
key = apiKey; key = apiKey;
Url::Class reqUrl = QUrl::fromEncoded( QUrl reqUrl = QUrl::fromEncoded(
QString( "http://apifree.forvo.com/key/" + key + "/format/xml/action/word-pronunciations/word/" + QString( "http://apifree.forvo.com/key/" + key + "/format/xml/action/word-pronunciations/word/" +
QString::fromLatin1( QUrl::toPercentEncoding( gd::toQString( str ) ) ) + "/language/" + languageCode QString::fromLatin1( QUrl::toPercentEncoding( gd::toQString( str ) ) ) + "/language/" + languageCode
).toUtf8() ); ).toUtf8() );
@ -261,7 +260,7 @@ void ForvoArticleRequest::requestFinished( QNetworkReply * r )
{ {
articleBody += "<tr>"; articleBody += "<tr>";
Url::Class url( mp3.toElement().text() ); QUrl url( mp3.toElement().text() );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";

View file

@ -254,7 +254,6 @@ HEADERS += folding.hh \
voiceengines.hh \ voiceengines.hh \
ffmpegaudio.hh \ ffmpegaudio.hh \
articleinspector.hh \ articleinspector.hh \
url.hh \
qt4x5.hh qt4x5.hh
FORMS += groups.ui \ FORMS += groups.ui \
@ -363,8 +362,7 @@ SOURCES += folding.cc \
mdx.cc \ mdx.cc \
voiceengines.cc \ voiceengines.cc \
ffmpegaudio.cc \ ffmpegaudio.cc \
articleinspector.cc \ articleinspector.cc
url.cc
win32 { win32 {
FORMS += texttospeechsource.ui FORMS += texttospeechsource.ui

12
lsa.cc
View file

@ -20,7 +20,9 @@
#include <vorbis/vorbisfile.h> #include <vorbis/vorbisfile.h>
#include <QDir> #include <QDir>
#include "url.hh" #include <QUrl>
#include "qt4x5.hh"
namespace Lsa { namespace Lsa {
@ -266,10 +268,10 @@ sptr< Dictionary::DataRequest > LsaDictionary::getArticle( wstring const & word,
{ {
result += "<tr>"; result += "<tr>";
Url::Class url; QUrl url;
url.setScheme( "gdau" ); url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::fromUtf8( i->second.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( i->second.c_str() ) ) );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";
@ -284,10 +286,10 @@ sptr< Dictionary::DataRequest > LsaDictionary::getArticle( wstring const & word,
{ {
result += "<tr>"; result += "<tr>";
Url::Class url; QUrl url;
url.setScheme( "gdau" ); url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::fromUtf8( i->second.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( i->second.c_str() ) ) );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";

View file

@ -11,6 +11,7 @@
#include <QDebug> #include <QDebug>
#include <QTextStream> #include <QTextStream>
#include <QDir> #include <QDir>
#include <QUrl>
#include <QMessageBox> #include <QMessageBox>
#include <QIcon> #include <QIcon>
#include <QList> #include <QList>
@ -33,7 +34,7 @@
#include "dictinfo.hh" #include "dictinfo.hh"
#include "fsencoding.hh" #include "fsencoding.hh"
#include "historypanewidget.hh" #include "historypanewidget.hh"
#include "url.hh" #include "qt4x5.hh"
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include "lionsupport.h" #include "lionsupport.h"
@ -2306,7 +2307,7 @@ void MainWindow::showTranslationFor( QString const & inWord,
updateBackForwardButtons(); updateBackForwardButtons();
#if 0 #if 0
Url::Class req; QUrl req;
req.setScheme( "gdlookup" ); req.setScheme( "gdlookup" );
req.setHost( "localhost" ); req.setHost( "localhost" );
@ -2900,7 +2901,7 @@ static void filterAndCollectResources( QString & html, QRegExp & rx, const QStri
while ( ( pos = rx.indexIn( html, pos ) ) != -1 ) while ( ( pos = rx.indexIn( html, pos ) ) != -1 )
{ {
Url::Class url( rx.cap( 1 ) ); QUrl url( rx.cap( 1 ) );
QString host = url.host(); QString host = url.host();
QString resourcePath = QString::fromLatin1( QUrl::toPercentEncoding( url.path(), "/" ) ); QString resourcePath = QString::fromLatin1( QUrl::toPercentEncoding( url.path(), "/" ) );

View file

@ -10,7 +10,6 @@
#include "dprintf.hh" #include "dprintf.hh"
#include "audiolink.hh" #include "audiolink.hh"
#include "qt4x5.hh" #include "qt4x5.hh"
#include "url.hh"
namespace MediaWiki { namespace MediaWiki {
@ -111,7 +110,7 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
livedLongEnough( false ), isCancelling( false ) livedLongEnough( false ), isCancelling( false )
{ {
DPRINTF( "request begin\n" ); DPRINTF( "request begin\n" );
Url::Class reqUrl( url + "/api.php?action=query&list=allpages&aplimit=40&format=xml" ); QUrl reqUrl( url + "/api.php?action=query&list=allpages&aplimit=40&format=xml" );
Qt4x5::Url::addQueryItem( reqUrl, "apfrom", gd::toQString( str ) ); Qt4x5::Url::addQueryItem( reqUrl, "apfrom", gd::toQString( str ) );
@ -251,7 +250,7 @@ void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr,
#endif #endif
); );
Url::Class reqUrl( url + "/api.php?action=parse&prop=text|revid&format=xml&redirects" ); QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid&format=xml&redirects" );
Qt4x5::Url::addQueryItem( reqUrl, "page", gd::toQString( str ) ); Qt4x5::Url::addQueryItem( reqUrl, "page", gd::toQString( str ) );
@ -317,8 +316,8 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
{ {
QString articleString = textNode.toElement().text(); QString articleString = textNode.toElement().text();
Url::Class wikiUrl( url ); QUrl wikiUrl( url );
wikiUrl.setPath( "" ); wikiUrl.setPath( "/" );
// Update any special index.php pages to be absolute // Update any special index.php pages to be absolute
articleString.replace( QRegExp( "<a\\shref=\"(/(\\w*/)*index.php\\?)" ), articleString.replace( QRegExp( "<a\\shref=\"(/(\\w*/)*index.php\\?)" ),

View file

@ -7,7 +7,8 @@
#include "utf8.hh" #include "utf8.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "parsecmdline.hh" #include "parsecmdline.hh"
#include "url.hh" #include "qt4x5.hh"
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
@ -85,10 +86,10 @@ sptr< Dictionary::DataRequest > ProgramsDictionary::getArticle(
result += "<table class=\"programs_play\"><tr>"; result += "<table class=\"programs_play\"><tr>";
Url::Class url; QUrl url;
url.setScheme( "gdprg" ); url.setScheme( "gdprg" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::fromUtf8( wordUtf8.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( wordUtf8.c_str() ) ) );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";

View file

@ -48,6 +48,17 @@ inline int loadAcquire( QAtomicInt const & ref )
namespace Url namespace Url
{ {
// This wrapper is created due to behavior change of the setPath() method
// See: https://bugreports.qt-project.org/browse/QTBUG-27728
// https://codereview.qt-project.org/#change,38257
inline QString ensureLeadingSlash( const QString & path )
{
QLatin1Char slash( '/' );
if ( path.startsWith( slash ) )
return path;
return slash + path;
}
inline bool hasQueryItem( QUrl const & url, QString const & key ) inline bool hasQueryItem( QUrl const & url, QString const & key )
{ {
#if IS_QT_5 #if IS_QT_5

View file

@ -12,7 +12,8 @@
#include "audiolink.hh" #include "audiolink.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "fsencoding.hh" #include "fsencoding.hh"
#include "url.hh" #include "qt4x5.hh"
#include <set> #include <set>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
@ -181,10 +182,10 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( wstring const &
{ {
result += "<tr>"; result += "<tr>";
Url::Class url; QUrl url;
url.setScheme( "gdau" ); url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::number( chain[ i->second ].articleOffset ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::number( chain[ i->second ].articleOffset ) ) );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";
@ -199,10 +200,10 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( wstring const &
{ {
result += "<tr>"; result += "<tr>";
Url::Class url; QUrl url;
url.setScheme( "gdau" ); url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::number( chain[ i->second ].articleOffset ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::number( chain[ i->second ].articleOffset ) ) );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";

17
url.cc
View file

@ -1,17 +0,0 @@
#include "url.hh"
namespace Url
{
#if IS_QT_5
void Class::setPath( const QString & path )
{
QLatin1Char slash( '/' );
if ( path.startsWith( slash ) )
QUrl::setPath( path );
else
QUrl::setPath( slash + path );
}
#endif
}

31
url.hh
View file

@ -1,31 +0,0 @@
#ifndef URL_HH
#define URL_HH
#include <QUrl>
#include "qt4x5.hh"
namespace Url
{
#if IS_QT_5
/// This class is created due to behavior change of the setPath() method
/// See: https://bugreports.qt-project.org/browse/QTBUG-27728
// https://codereview.qt-project.org/#change,38257
class Class : public QUrl
{
public:
Class() : QUrl() {}
Class( QString const & url ) : QUrl( url ) {}
Class( QUrl const & other ) : QUrl( other ) {}
Class( QString const & url, ParsingMode parsingMode ) : QUrl( url, parsingMode ) {}
void setPath( QString const & path );
};
#else
typedef QUrl Class;
#endif
}
#endif // URL_HH

View file

@ -15,7 +15,6 @@
#include <QCryptographicHash> #include <QCryptographicHash>
#include "qt4x5.hh" #include "qt4x5.hh"
#include "url.hh"
namespace VoiceEngines namespace VoiceEngines
{ {
@ -89,10 +88,10 @@ sptr< Dictionary::DataRequest > VoiceEnginesDictionary::getArticle(
result += "<table class=\"voiceengines_play\"><tr>"; result += "<table class=\"voiceengines_play\"><tr>";
Url::Class url; QUrl url;
url.setScheme( "gdtts" ); url.setScheme( "gdtts" );
url.setHost( "localhost" ); url.setHost( "localhost" );
url.setPath( QString::fromUtf8( wordUtf8.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( wordUtf8.c_str() ) ) );
QList< QPair<QString, QString> > query; QList< QPair<QString, QString> > query;
query.push_back( QPair<QString, QString>( "engine", QString::fromStdString( getId() ) ) ); query.push_back( QPair<QString, QString>( "engine", QString::fromStdString( getId() ) ) );
Qt4x5::Url::setQueryItems( url, query ); Qt4x5::Url::setQueryItems( url, query );

View file

@ -3,6 +3,7 @@
#include "xdxf2html.hh" #include "xdxf2html.hh"
#include <QtXml> #include <QtXml>
#include <Qurl>
#include "dprintf.hh" #include "dprintf.hh"
#include "utf8.hh" #include "utf8.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
@ -12,16 +13,16 @@
#include "file.hh" #include "file.hh"
#include "filetype.hh" #include "filetype.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
#include "url.hh" #include "qt4x5.hh"
namespace Xdxf2Html { namespace Xdxf2Html {
static void fixLink( QDomElement & el, string const & dictId, const char *attrName ) static void fixLink( QDomElement & el, string const & dictId, const char *attrName )
{ {
Url::Class url; QUrl url;
url.setScheme( "bres" ); url.setScheme( "bres" );
url.setHost( QString::fromStdString(dictId) ); url.setHost( QString::fromStdString(dictId) );
url.setPath( el.attribute(attrName) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( el.attribute(attrName) ) );
el.setAttribute( attrName, url.toEncoded().data() ); el.setAttribute( attrName, url.toEncoded().data() );
} }
@ -275,10 +276,10 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
if ( Filetype::isNameOfPicture( filename ) ) if ( Filetype::isNameOfPicture( filename ) )
{ {
Url::Class url; QUrl url;
url.setScheme( "bres" ); url.setScheme( "bres" );
url.setHost( QString::fromUtf8( dictPtr->getId().c_str() ) ); url.setHost( QString::fromUtf8( dictPtr->getId().c_str() ) );
url.setPath( QString::fromUtf8( filename.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( filename.c_str() ) ) );
QDomElement newEl = dd.createElement( "img" ); QDomElement newEl = dd.createElement( "img" );
newEl.setAttribute( "src", url.toEncoded().data() ); newEl.setAttribute( "src", url.toEncoded().data() );
@ -293,10 +294,10 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
} }
else if( Filetype::isNameOfSound( filename ) ) else if( Filetype::isNameOfSound( filename ) )
{ {
Url::Class url; QUrl url;
url.setScheme( "gdau" ); url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( dictPtr->getId().c_str() ) ); url.setHost( QString::fromUtf8( dictPtr->getId().c_str() ) );
url.setPath( QString::fromUtf8( filename.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( filename.c_str() ) ) );
QDomElement el_script = dd.createElement( "script" ); QDomElement el_script = dd.createElement( "script" );
QDomNode parent = el.parentNode(); QDomNode parent = el.parentNode();

View file

@ -21,7 +21,7 @@
#include <stub_msvc.h> #include <stub_msvc.h>
#endif #endif
#include "url.hh" #include "qt4x5.hh"
namespace ZipSounds { namespace ZipSounds {
@ -217,10 +217,10 @@ sptr< Dictionary::DataRequest > ZipSoundsDictionary::getArticle( wstring const &
{ {
result += "<tr>"; result += "<tr>";
Url::Class url; QUrl url;
url.setScheme( "gdau" ); url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::fromUtf8( i->second.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( i->second.c_str() ) ) );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";
@ -235,10 +235,10 @@ sptr< Dictionary::DataRequest > ZipSoundsDictionary::getArticle( wstring const &
{ {
result += "<tr>"; result += "<tr>";
Url::Class url; QUrl url;
url.setScheme( "gdau" ); url.setScheme( "gdau" );
url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setHost( QString::fromUtf8( getId().c_str() ) );
url.setPath( QString::fromUtf8( i->second.c_str() ) ); url.setPath( Qt4x5::Url::ensureLeadingSlash( QString::fromUtf8( i->second.c_str() ) ) );
string ref = string( "\"" ) + url.toEncoded().data() + "\""; string ref = string( "\"" ) + url.toEncoded().data() + "\"";