Commit 22fecced authored by Pino Toscano's avatar Pino Toscano

Use QSharedPointer to keep SearchHandler instances

This way it simplifies their cleanup, and avoid double deletions in
some (rare) cases.
parent 70ba679a
......@@ -190,7 +190,6 @@ SearchEngine::SearchEngine( View *destination )
SearchEngine::~SearchEngine()
{
delete mRootTraverser;
qDeleteAll( mHandlers );
}
bool SearchEngine::initSearchHandlers()
......@@ -208,7 +207,7 @@ bool SearchEngine::initSearchHandlers()
for( it = resources.constBegin(); it != resources.constEnd(); ++it ) {
QString filename = *it;
khcDebug() << "SearchEngine::initSearchHandlers(): " << filename;
SearchHandler *handler = SearchHandler::initFromFile( filename );
QSharedPointer<SearchHandler> handler( SearchHandler::initFromFile( filename ) );
if ( !handler ) {
QMessageBox::warning( mView->widget(), i18n("Handler"), i18n("Unable to initialize SearchHandler from file '%1'.", filename ) );
} else {
......@@ -221,9 +220,6 @@ bool SearchEngine::initSearchHandlers()
// ones
if ( !mHandlers.contains( *it ) ) {
mHandlers.insert( *it, handler );
} else {
// not keeping "handler", delete it
delete handler;
}
}
}
......@@ -328,7 +324,8 @@ bool SearchEngine::isRunning() const
SearchHandler *SearchEngine::handler( const QString &documentType ) const
{
return mHandlers.value( documentType, 0 );
QSharedPointer<SearchHandler> ptr = mHandlers.value( documentType );
return ptr ? ptr.data() : 0;
}
QStringList SearchEngine::words() const
......
......@@ -5,6 +5,7 @@
#include <QObject>
#include <QMap>
#include <QPair>
#include <QSharedPointer>
#include "docentrytraverser.h"
......@@ -127,7 +128,7 @@ class SearchEngine : public QObject
SearchTraverser *mRootTraverser;
QMap<QString, SearchHandler *> mHandlers;
QMap<QString, QSharedPointer<SearchHandler> > mHandlers;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment