SimbadSearcher.cpp   SimbadSearcher.cpp 
skipping to change at line 25 skipping to change at line 25
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "SimbadSearcher.hpp" #include "SimbadSearcher.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include <QNetworkReply> #include <QNetworkReply>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QDebug> #include <QDebug>
#include <QTimer>
SimbadLookupReply::SimbadLookupReply(QNetworkReply* r) : reply(r), currentS tatus(SimbadLookupQuerying) SimbadLookupReply::SimbadLookupReply(const QString& aurl, QNetworkAccessMan ager* anetMgr, int delayMs) : url(aurl), reply(NULL), netMgr(anetMgr), curr entStatus(SimbadLookupQuerying)
{ {
connect(r, SIGNAL(finished()), this, SLOT(httpQueryFinished())); // First wait before starting query. This avoids sending a query for
each autocompletion letter.
QTimer::singleShot(delayMs, this, SLOT(delayTimerCompleted()));
} }
SimbadLookupReply::~SimbadLookupReply() SimbadLookupReply::~SimbadLookupReply()
{ {
disconnect(reply, SIGNAL(finished()), this, SLOT(httpQueryFinished() if (reply)
)); {
reply->abort(); disconnect(reply, SIGNAL(finished()), this, SLOT(httpQueryFi
reply->deleteLater(); nished()));
reply = NULL; reply->abort();
reply->deleteLater();
reply = NULL;
}
}
void SimbadLookupReply::delayTimerCompleted()
{
reply = netMgr->get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()), this, SLOT(httpQueryFinished()));
} }
void SimbadLookupReply::httpQueryFinished() void SimbadLookupReply::httpQueryFinished()
{ {
if (reply->error()!=QNetworkReply::NoError) if (reply->error()!=QNetworkReply::NoError)
{ {
currentStatus = SimbadLookupErrorOccured; currentStatus = SimbadLookupErrorOccured;
errorString = q_("Network error: %1").arg(reply->errorString ()); errorString = q_("Network error: %1").arg(reply->errorString ());
emit statusChanged(); emit statusChanged();
return; return;
skipping to change at line 134 skipping to change at line 145
} }
return QString(); return QString();
} }
SimbadSearcher::SimbadSearcher(QObject* parent) : QObject(parent) SimbadSearcher::SimbadSearcher(QObject* parent) : QObject(parent)
{ {
networkMgr = new QNetworkAccessManager(this); networkMgr = new QNetworkAccessManager(this);
} }
// Lookup in Simbad for the passed object name. // Lookup in Simbad for the passed object name.
SimbadLookupReply* SimbadSearcher::lookup(const QString& objectName, int ma xNbResult) SimbadLookupReply* SimbadSearcher::lookup(const QString& objectName, int ma xNbResult, int delayMs)
{ {
// Create the Simbad query // Create the Simbad query
QString url("http://simbad.u-strasbg.fr/simbad/sim-script?script=for mat object \"%COO(d;A D)\\n%IDLIST(1)\"\n"); QString url("http://simbad.u-strasbg.fr/simbad/sim-script?script=for mat object \"%COO(d;A D)\\n%IDLIST(1)\"\n");
url += QString("set epoch J2000\nset limit %1\n query id ").arg(maxN bResult); url += QString("set epoch J2000\nset limit %1\n query id ").arg(maxN bResult);
url += objectName; url += objectName;
QNetworkReply* netReply = networkMgr->get(QNetworkRequest(url)); return new SimbadLookupReply(url, networkMgr, delayMs);
SimbadLookupReply* r = new SimbadLookupReply(netReply);
return r;
} }
 End of changes. 6 change blocks. 
11 lines changed or deleted 21 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/