void WebQueryBibSonomy::query( const QString& searchTerm, int numberOfResults ) { WebQuery::query( searchTerm, numberOfResults ); emit setTotalSteps( 1 ); BibTeX::File *bibFile = NULL; QString term = searchTerm; KURL url = KURL( QString( "http://www.bibsonomy.org/bib/search/%1?items=%2" ).arg( term.replace( "%", "%25" ).replace( " ", "+" ).replace( "?", "%3F" ).replace( "&", "%26" ) ).arg( numberOfResults ) ); QString tmpFile; if ( KIO::NetAccess::download( url, tmpFile, m_parent ) && !m_aborted ) { BibTeX::FileImporterBibTeX importer( FALSE ); importer.setIgnoreComments( TRUE ); QFile inputFile( tmpFile ); inputFile.open( IO_ReadOnly ); bibFile = importer.load( &inputFile ); inputFile.close(); KIO::NetAccess::removeTempFile( tmpFile ); emit setProgress( 1 ); for ( BibTeX::File::ElementList::iterator it = bibFile->begin(); it != bibFile->end(); ++it ) { BibTeX::Entry *entry = dynamic_cast<BibTeX::Entry*>( *it ); if ( entry != NULL ) { emit foundEntry( entry ); } } emit endSearch( false ); } else if ( !m_aborted ) { QString message = KIO::NetAccess::lastErrorString(); if ( message.isEmpty() ) message.prepend( '\n' ); message.prepend( QString( i18n( "Querying database '%1' failed." ) ).arg( title() ) ); KMessageBox::error( m_parent, message ); emit endSearch( true ); } else emit endSearch( false ); if ( bibFile != NULL ) delete bibFile; }
void WebQueryCitebase::query( const QString& searchTerm, int numberOfResults ) { WebQuery::query( searchTerm, numberOfResults ); emit setTotalSteps( 1 ); QString term = searchTerm; KURL url = KURL( QString( "http://www.citebase.org/search?submitted=Search&author=&maxrows=%2&yearfrom=&format=BibTeX&order=DESC&type=metadata&title=%1&publication=&yearuntil=&rank=paperimpact" ).arg( term.replace( "%", "%25" ).replace( " ", "+" ).replace( "?", "%3F" ).replace( "&", "%26" ) ).arg( numberOfResults ) ); QString tmpFile; if ( KIO::NetAccess::download( url, tmpFile, m_parent ) && !m_aborted ) { BibTeX::FileImporterBibTeX importer( FALSE ); importer.setIgnoreComments( TRUE ); QFile inputFile( tmpFile ); inputFile.open( IO_ReadOnly ); BibTeX::File *tmpBibFile = importer.load( &inputFile ); inputFile.close(); KIO::NetAccess::removeTempFile( tmpFile ); emit setProgress( 1 ); int count = numberOfResults; for ( BibTeX::File::ElementList::iterator it = tmpBibFile->begin(); count > 0 && it != tmpBibFile->end(); ++it ) { BibTeX::Entry *entry = dynamic_cast<BibTeX::Entry*>( *it ); if ( entry != NULL ) { emit foundEntry( new BibTeX::Entry( entry ) ); --count; } } delete tmpBibFile; emit endSearch( false ); } else if ( !m_aborted ) { QString message = KIO::NetAccess::lastErrorString(); if ( message.isEmpty() ) message.prepend( '\n' ); message.prepend( QString( i18n( "Querying database '%1' failed." ) ).arg( title() ) ); KMessageBox::error( m_parent, message ); emit endSearch( true ); } else emit endSearch( false ); }