mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
optimize:wikidictionary ,remove 200ms delay.
This commit is contained in:
parent
d607079ffb
commit
84dcc1cbb1
37
mediawiki.cc
37
mediawiki.cc
|
@ -97,9 +97,6 @@ void MediaWikiDictionary::loadIcon() throw()
|
||||||
class MediaWikiWordSearchRequest: public MediaWikiWordSearchRequestSlots
|
class MediaWikiWordSearchRequest: public MediaWikiWordSearchRequestSlots
|
||||||
{
|
{
|
||||||
sptr< QNetworkReply > netReply;
|
sptr< QNetworkReply > netReply;
|
||||||
bool livedLongEnough; // Indicates that the request has lived long enough
|
|
||||||
// to be destroyed prematurely. Used to prevent excessive
|
|
||||||
// network loads when typing search terms rapidly.
|
|
||||||
bool isCancelling;
|
bool isCancelling;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -111,10 +108,6 @@ public:
|
||||||
|
|
||||||
virtual void cancel();
|
virtual void cancel();
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
virtual void timerEvent( QTimerEvent * );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
virtual void downloadFinished();
|
virtual void downloadFinished();
|
||||||
|
@ -122,8 +115,8 @@ private:
|
||||||
|
|
||||||
MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
|
MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
|
||||||
QString const & url,
|
QString const & url,
|
||||||
QNetworkAccessManager & mgr ):
|
QNetworkAccessManager & mgr ) :
|
||||||
livedLongEnough( false ), isCancelling( false )
|
isCancelling( false )
|
||||||
{
|
{
|
||||||
GD_DPRINTF( "request begin\n" );
|
GD_DPRINTF( "request begin\n" );
|
||||||
QUrl 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" );
|
||||||
|
@ -141,19 +134,6 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
|
||||||
netReply.get(), SLOT( ignoreSslErrors() ) );
|
netReply.get(), SLOT( ignoreSslErrors() ) );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We start a timer to postpone early destruction, so a rapid type won't make
|
|
||||||
// unnecessary network load
|
|
||||||
startTimer( 200 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void MediaWikiWordSearchRequest::timerEvent( QTimerEvent * ev )
|
|
||||||
{
|
|
||||||
killTimer( ev->timerId() );
|
|
||||||
livedLongEnough = true;
|
|
||||||
|
|
||||||
if ( isCancelling )
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaWikiWordSearchRequest::~MediaWikiWordSearchRequest()
|
MediaWikiWordSearchRequest::~MediaWikiWordSearchRequest()
|
||||||
|
@ -166,17 +146,12 @@ void MediaWikiWordSearchRequest::cancel()
|
||||||
// We either finish it in place, or in the timer handler
|
// We either finish it in place, or in the timer handler
|
||||||
isCancelling = true;
|
isCancelling = true;
|
||||||
|
|
||||||
if ( netReply.get() )
|
if( netReply.get() )
|
||||||
netReply.reset();
|
netReply.reset();
|
||||||
|
|
||||||
if ( livedLongEnough )
|
finish();
|
||||||
{
|
|
||||||
finish();
|
GD_DPRINTF( "cancel the request" );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GD_DPRINTF("not long enough\n" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaWikiWordSearchRequest::downloadFinished()
|
void MediaWikiWordSearchRequest::downloadFinished()
|
||||||
|
|
Loading…
Reference in a new issue