mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
network manager change
This commit is contained in:
parent
4b7af3cf6c
commit
54bdf12d8d
|
@ -16,54 +16,6 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
#if QT_VERSION >= 0x050300 && QT_VERSION <= 0x050500 // Qt 5.3+
|
||||
|
||||
// SecurityWhiteList
|
||||
|
||||
SecurityWhiteList & SecurityWhiteList::operator=( SecurityWhiteList const & swl )
|
||||
{
|
||||
swlDelete();
|
||||
swlCopy( swl );
|
||||
return *this;
|
||||
}
|
||||
|
||||
QWebSecurityOrigin * SecurityWhiteList::setOrigin( QUrl const & url )
|
||||
{
|
||||
swlDelete();
|
||||
originUri = url.toString( QUrl::PrettyDecoded );
|
||||
origin = new QWebSecurityOrigin( url );
|
||||
return origin;
|
||||
}
|
||||
|
||||
void SecurityWhiteList::swlCopy( SecurityWhiteList const & swl )
|
||||
{
|
||||
if( swl.origin )
|
||||
{
|
||||
hostsToAccess = swl.hostsToAccess;
|
||||
originUri = swl.originUri;
|
||||
origin = new QWebSecurityOrigin( QUrl( originUri ) );
|
||||
|
||||
for( QSet< QPair< QString, QString > >::iterator it = hostsToAccess.begin();
|
||||
it != hostsToAccess.end(); ++it )
|
||||
origin->addAccessWhitelistEntry( it->first, it->second, QWebSecurityOrigin::AllowSubdomains );
|
||||
}
|
||||
}
|
||||
|
||||
void SecurityWhiteList::swlDelete()
|
||||
{
|
||||
if( origin )
|
||||
{
|
||||
for( QSet< QPair< QString, QString > >::iterator it = hostsToAccess.begin();
|
||||
it != hostsToAccess.end(); ++it )
|
||||
origin->removeAccessWhitelistEntry( it->first, it->second, QWebSecurityOrigin::AllowSubdomains );
|
||||
|
||||
delete origin;
|
||||
origin = 0;
|
||||
}
|
||||
hostsToAccess.clear();
|
||||
originUri.clear();
|
||||
}
|
||||
|
||||
// AllowFrameReply
|
||||
|
||||
AllowFrameReply::AllowFrameReply( QNetworkReply * _reply ) :
|
||||
|
@ -200,7 +152,6 @@ using std::string;
|
|||
return size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -255,39 +206,6 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
|
|||
return QNetworkAccessManager::createRequest( op, newReq, outgoingData );
|
||||
}
|
||||
|
||||
#if QT_VERSION >= 0x050300 && QT_VERSION<=0x050500 // Qt 5.3+
|
||||
// Workaround of same-origin policy
|
||||
if( ( req.url().scheme().startsWith( "http" ) || req.url().scheme() == "ftp" )
|
||||
&& req.hasRawHeader( "Referer" ) )
|
||||
{
|
||||
QByteArray referer = req.rawHeader( "Referer" );
|
||||
QUrl refererUrl = QUrl::fromEncoded( referer );
|
||||
|
||||
if( refererUrl.scheme().startsWith( "http") || refererUrl.scheme() == "ftp" )
|
||||
{
|
||||
// Only for pages from network resources
|
||||
if ( !req.url().host().endsWith( refererUrl.host() ) )
|
||||
{
|
||||
QUrl frameUrl;
|
||||
frameUrl.setScheme( refererUrl.scheme() );
|
||||
frameUrl.setHost( refererUrl.host() );
|
||||
QString frameStr = frameUrl.toString( QUrl::PrettyDecoded );
|
||||
|
||||
SecurityWhiteList & value = allOrigins[ frameStr ];
|
||||
if( !value.origin )
|
||||
value.setOrigin( frameUrl );
|
||||
|
||||
QPair< QString, QString > target( req.url().scheme(), req.url().host() );
|
||||
if( value.hostsToAccess.find( target ) == value.hostsToAccess.end() )
|
||||
{
|
||||
value.hostsToAccess.insert( target );
|
||||
value.origin->addAccessWhitelistEntry( target.first, target.second,
|
||||
QWebSecurityOrigin::AllowSubdomains );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
QString contentType;
|
||||
|
||||
|
@ -360,7 +278,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
|
|||
#endif
|
||||
}
|
||||
|
||||
#if QT_VERSION >= 0x050300 && QT_VERSION <= 0x050500 // Qt 5.3+
|
||||
#if QT_VERSION >= 0x050300 // Qt 5.3+
|
||||
return op == QNetworkAccessManager::GetOperation
|
||||
|| op == QNetworkAccessManager::HeadOperation ? new AllowFrameReply( reply ) : reply;
|
||||
#else
|
||||
|
|
|
@ -21,34 +21,6 @@ using std::vector;
|
|||
/// A custom QNetworkAccessManager version which fetches images from the
|
||||
/// dictionaries when requested.
|
||||
|
||||
#if QT_VERSION >= 0x050300 && QT_VERSION <= 0x050500 // Qt 5.3+
|
||||
|
||||
// White lists for QWebSecurityOrigin
|
||||
struct SecurityWhiteList
|
||||
{
|
||||
//QWebSecurityOrigin * origin;
|
||||
QString originUri;
|
||||
QSet< QPair< QString, QString > > hostsToAccess;
|
||||
|
||||
SecurityWhiteList()
|
||||
{}
|
||||
|
||||
~SecurityWhiteList()
|
||||
{ swlDelete(); }
|
||||
|
||||
SecurityWhiteList( SecurityWhiteList const & swl )
|
||||
{ swlCopy( swl ); }
|
||||
|
||||
SecurityWhiteList & operator=( SecurityWhiteList const & swl );
|
||||
//QWebSecurityOrigin * setOrigin( QUrl const & url );
|
||||
|
||||
private:
|
||||
void swlCopy( SecurityWhiteList const & swl );
|
||||
void swlDelete();
|
||||
};
|
||||
|
||||
typedef QMap< QString, SecurityWhiteList > Origins;
|
||||
|
||||
// Proxy class for QNetworkReply to remove X-Frame-Options header
|
||||
// It allow to show websites in <iframe> tag like Qt 4.x
|
||||
|
||||
|
@ -118,7 +90,7 @@ protected:
|
|||
qint64 writeData( const char * data, qint64 maxSize )
|
||||
{ return baseReply->write( data, maxSize ); }
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
class ArticleNetworkAccessManager: public QNetworkAccessManager
|
||||
{
|
||||
|
|
1
iconv.cc
1
iconv.cc
|
@ -55,7 +55,6 @@ Iconv::Result Iconv::convert( void const * & inBuf, size_t & inBytesLeft,
|
|||
|
||||
if ( result == (size_t) -1 )
|
||||
{
|
||||
qDebug("iconv convert errno:"+errno);
|
||||
switch( errno )
|
||||
{
|
||||
case EILSEQ:
|
||||
|
|
|
@ -2798,92 +2798,6 @@ void MainWindow::showTranslationFor( Config::InputPhrase const & phrase,
|
|||
|
||||
updateBackForwardButtons();
|
||||
|
||||
#if 0
|
||||
QUrl req;
|
||||
|
||||
req.setScheme( "gdlookup" );
|
||||
req.setHost( "localhost" );
|
||||
req.addQueryItem( "word", inWord );
|
||||
req.addQueryItem( "group",
|
||||
cfg.groups.empty() ? "" :
|
||||
groupInstances[ groupList->currentIndex() ].name );
|
||||
|
||||
ui.definition->load( req );
|
||||
|
||||
return;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
wstring word = inWord.trimmed().toStdWString();
|
||||
|
||||
// Where to look?
|
||||
|
||||
vector< sptr< Dictionary::Class > > const & activeDicts = getActiveDicts();
|
||||
|
||||
// Accumulate main forms
|
||||
|
||||
vector< wstring > alts;
|
||||
|
||||
{
|
||||
set< wstring > altsSet;
|
||||
|
||||
for( unsigned x = 0; x < activeDicts.size(); ++x )
|
||||
{
|
||||
vector< wstring > found = activeDicts[ x ]->findHeadwordsForSynonym( word );
|
||||
|
||||
altsSet.insert( found.begin(), found.end() );
|
||||
}
|
||||
|
||||
alts.insert( alts.begin(), altsSet.begin(), altsSet.end() );
|
||||
}
|
||||
|
||||
for( unsigned x = 0; x < alts.size(); ++x )
|
||||
{
|
||||
DPRINTF( "Alt: %ls\n", alts[ x ].c_str() );
|
||||
}
|
||||
|
||||
|
||||
string result =
|
||||
"<html><head>"
|
||||
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
|
||||
|
||||
QFile cssFile( Config::getUserCssFileName() );
|
||||
|
||||
if ( cssFile.open( QFile::ReadOnly ) )
|
||||
{
|
||||
result += "<style type=\"text/css\">\n";
|
||||
result += cssFile.readAll().data();
|
||||
result += "</style>\n";
|
||||
}
|
||||
|
||||
result += "</head><body>";
|
||||
|
||||
for( unsigned x = 0; x < activeDicts.size(); ++x )
|
||||
{
|
||||
try
|
||||
{
|
||||
string body = activeDicts[ x ]->getArticle( word, alts );
|
||||
|
||||
DPRINTF( "From %s: %s\n", activeDicts[ x ]->getName().c_str(), body.c_str() );
|
||||
|
||||
result += "<div class=\"gddictname\">From " + activeDicts[ x ]->getName() + "</div>" + body;
|
||||
}
|
||||
catch( Dictionary::exNoSuchWord & )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
result += "</body></html>";
|
||||
|
||||
ArticleMaker am( dictionaries, groupInstances );
|
||||
|
||||
string result = am.makeDefinitionFor( inWord, "En" );
|
||||
|
||||
ui.definition->setContent( result.c_str(), QString() );
|
||||
|
||||
#endif
|
||||
|
||||
//ui.tabWidget->setTabText( ui.tabWidget->indexOf(ui.tab), inWord.trimmed() );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue