SVN commit 1044094 by sebas: use mediawiki as local variable, and move the adding of matches into the same function, hopefully doesn't crash anymore, needs cleanup though. M +18 -0 mediawiki.cpp M +7 -1 mediawiki.h M +30 -14 mediawikirunner.cpp M +6 -2 mediawikirunner.h --- trunk/playground/base/plasma/runners/mediawiki/mediawiki.cpp #1044093:1044094 @@ -27,7 +27,10 @@ #include #include +#include + #include "mediawiki.h" +//#include "mediawikirunner.h" enum State { StateApiChanged, @@ -45,6 +48,8 @@ QNetworkReply *reply; int timeout; QUrl query; + //MediaWikiRunner *runner; + //Plasma::RunnerContext *context; }; MediaWiki::MediaWiki( QObject *parent ) @@ -59,6 +64,8 @@ d->maxItems = 10; d->timeout = 30 * 1000; // 30 second d->reply = 0; + //d->runner = 0; + //d->context = 0; connect( d->manager, SIGNAL(finished(QNetworkReply*)), SLOT(finished(QNetworkReply *)) ); } @@ -68,6 +75,17 @@ delete d; } +/* +void MediaWiki::setRunnerContext(Plasma::RunnerContext &context) +{ + d->context = &context; +} + +void MediaWiki::setMediaWikiRunner(MediaWikiRunner *runner) +{ + d->runner = runner; +} +*/ QList MediaWiki::results() const { return d->results; --- trunk/playground/base/plasma/runners/mediawiki/mediawiki.h #1044093:1044094 @@ -1,6 +1,6 @@ /* * Copyright 2009 by Richard Moore - * Copyright 2009 by Sebastian Kügler + * Copyright 2009 by Sebastian K?gler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -27,6 +27,9 @@ class QNetworkReply; +//namespace Plasma { class RunnerContext; } +//class MediaWikiRunner; + /** * Searches MediaWiki based wikis like wikipedia and techbase. * @@ -108,6 +111,9 @@ */ void setTimeout( int millis ); + //void setRunnerContext(Plasma::RunnerContext &context); + //void setMediaWikiRunner(MediaWikiRunner *runner); + signals: /** * Emitted when a search has been completed. --- trunk/playground/base/plasma/runners/mediawiki/mediawikirunner.cpp #1044093:1044094 @@ -1,5 +1,5 @@ /* - * Copyright 2009 Sebastian Kügler + * Copyright 2009 Sebastian K?gler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -33,8 +33,7 @@ MediaWikiRunner::MediaWikiRunner(QObject *parent, const QVariantList& args) - : Plasma::AbstractRunner(parent, args), - m_mediawiki(0) + : Plasma::AbstractRunner(parent, args) { Q_UNUSED(args); setObjectName("MediaWikiRunner"); @@ -65,7 +64,6 @@ MediaWikiRunner::~MediaWikiRunner() { - delete m_mediawiki; } @@ -84,24 +82,42 @@ m_waiter.wait(&m_mutex, 1000); m_mutex.unlock(); - m_mediawiki = new MediaWiki(); - m_mediawiki->setMaxItems(3); - m_mediawiki->setApiUrl( m_apiUrl ); - connect( m_mediawiki, SIGNAL(finished(bool)), SLOT(mediaWikiFinished(bool)) ); - connect( this, SIGNAL(done()), &loop, SLOT(quit()) ); - m_context = &context; + if (!context.isValid()) { + return; + } - m_mediawiki->search(term); + MediaWiki mediawiki; + mediawiki.setMaxItems(3); + mediawiki.setApiUrl( m_apiUrl ); + //connect( &mediawiki, SIGNAL(finished(bool)), SLOT(mediaWikiFinished(bool)) ); + connect( &mediawiki, SIGNAL(finished(bool)), &loop, SLOT(quit()) ); + //connect( this, SIGNAL(done()), &loop, SLOT(quit()) ); + + mediawiki.search(term); kDebug() << "Wikisearch:" << term; loop.exec(); - delete m_mediawiki; - m_mediawiki = 0; + if (!context.isValid()) { + return; + } + foreach(const MediaWiki::Result& res, mediawiki.results()) { + kDebug() << "Match:" << res.url << res.title; + Plasma::QueryMatch match(this); + match.setType(Plasma::QueryMatch::PossibleMatch); + match.setIcon(m_icon); + match.setText(QString("%1: %2").arg(m_name, res.title)); + match.setData(res.url); + context.addMatch(res.title, match); + } + + //emit done(); + } void MediaWikiRunner::mediaWikiFinished(bool success) { + /* kDebug() << "Wikimatches:" << success << m_mediawiki->results().count(); foreach(const MediaWiki::Result& res, m_mediawiki->results()) { @@ -113,7 +129,7 @@ match.setData(res.url); m_context->addMatch(res.title, match); } - + */ emit done(); } --- trunk/playground/base/plasma/runners/mediawiki/mediawikirunner.h #1044093:1044094 @@ -1,5 +1,5 @@ /* - * Copyright 2008 Sebastian Kügler + * Copyright 2008 Sebastian K?gler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -24,6 +24,10 @@ class KIcon; class QMutex; + +#include +#include + class QWaitCondition; #include "mediawiki.h" @@ -48,7 +52,7 @@ KIcon m_icon; QString m_name; QString m_comment; - MediaWiki* m_mediawiki; + //MediaWiki* m_mediawiki; QUrl m_apiUrl; Plasma::RunnerContext* m_context;