1
/***************************************************************************
2
* Copyright (C) 2004-2009 by Thomas Fischer *
3
* fischer@unix-ag.uni-kl.de *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
20
#include <qapplication.h>
27
#include <klineedit.h>
28
#include <kmessagebox.h>
29
#include <kio/netaccess.h>
33
#include <fileimporterbibtex.h>
34
#include "webquerybibsonomy.h"
38
WebQueryBibSonomyWidget::WebQueryBibSonomyWidget( QWidget *parent, const char *name )
39
: WebQueryWidget( parent, name )
43
Settings *settings = Settings::self();
44
QString value = settings->getWebQueryDefault( "BibSonomy" );
45
value = value == QString::null ? "" : value;
46
lineEditQuery->setText( value );
47
slotTextChanged( value, true );
51
WebQueryBibSonomy::WebQueryBibSonomy( QWidget* parent ): WebQuery( parent )
53
m_widget = new WebQueryBibSonomyWidget( parent );
56
WebQueryBibSonomy::~WebQueryBibSonomy()
61
QString WebQueryBibSonomy::title()
63
return i18n( "BibSonomy" );
66
QString WebQueryBibSonomy::disclaimer()
68
return i18n( "BibSonomy bookmark sharing system" );
71
QString WebQueryBibSonomy::disclaimerURL()
73
return "http://www.bibsonomy.org/help/about/";
76
WebQueryWidget *WebQueryBibSonomy::widget()
81
void WebQueryBibSonomy::query()
84
Settings *settings = Settings::self();
85
settings->setWebQueryDefault( "BibSonomy", m_widget->lineEditQuery->text() );
89
QString searchTerm = m_widget->lineEditQuery->text().stripWhiteSpace().replace( '$', "" );
90
if ( searchTerm.isEmpty() )
92
setEndSearch( WebQuery::statusInvalidQuery );
96
int numberOfResults = m_widget->spinBoxMaxHits->value();
98
KURL url = KURL( QString( "http://www.bibsonomy.org/bib/search/%2?items=%1" ).arg( numberOfResults ) .arg( searchTerm.replace( "%", "%25" ).replace( "+", "%2B" ).replace( " ", "%20" ).replace( "#", "%23" ).replace( "&", "%26" ).replace( "?", "%3F" ) ) );
100
BibTeX::File *bibFile = downloadBibTeXFile( url );
101
if ( bibFile != NULL && !m_aborted )
103
for ( BibTeX::File::ElementList::iterator it = bibFile->begin(); it != bibFile->end(); ++it )
105
BibTeX::Entry *entry = dynamic_cast<BibTeX::Entry*>( *it );
107
emit foundEntry( entry, false );
109
setEndSearch( WebQuery::statusSuccess );
111
else if ( !m_aborted )
113
QString message = KIO::NetAccess::lastErrorString();
114
if ( message.isEmpty() )
115
message.prepend( '\n' );
116
message.prepend( QString( i18n( "Querying database '%1' failed." ) ).arg( title() ) );
117
KMessageBox::error( m_parent, message );
118
setEndSearch( WebQuery::statusError );
121
setEndSearch( WebQuery::statusAborted );
123
if ( bibFile != NULL )