void HostipRunner::search( const QString &searchTerm, const GeoDataLatLonBox & ) { if( !searchTerm.contains('.') ) { // Simple IP/hostname heuristic to avoid requests not needed: // String must contain at least one dot. slotNoResults(); } else { QEventLoop eventLoop; QTimer timer; timer.setSingleShot( true ); timer.setInterval( 15000 ); connect( &timer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); connect( this, SIGNAL(searchFinished(QVector<GeoDataPlacemark*>)), &eventLoop, SLOT(quit()) ); // Lookup the IP address for a hostname, or the hostname if an IP address was given QHostInfo ::lookupHost( searchTerm, this, SLOT(slotLookupFinished(QHostInfo))); timer.start(); eventLoop.exec(); } }
void HostipRunner::search( const QString &searchTerm ) { if( !searchTerm.contains('.') ) { // Simple IP/hostname heuristic to avoid requests not needed: // String must contain at least one dot. slotNoResults(); } else { // Lookup the IP address for a hostname, or the hostname if an IP address was given QHostInfo ::lookupHost( searchTerm, this, SLOT(slotLookupFinished(QHostInfo))); } }
void HostipRunner::slotLookupFinished(const QHostInfo &info) { if ( !info.addresses().isEmpty() ) { m_hostInfo = info; QString hostAddress = info.addresses().first().toString(); QString query = QString( "http://api.hostip.info/get_html.php?ip=%1&position=true" ).arg( hostAddress ); m_request.setUrl( QUrl( query ) ); // @todo FIXME Must currently be done in the main thread, see bug 257376 QTimer::singleShot( 0, this, SLOT(get()) ); } else slotNoResults(); }
void HostipRunner::get() { QNetworkReply *reply = m_networkAccessManager.get( m_request ); connect( reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotNoResults()), Qt::DirectConnection ); }