Commit bc64a682 authored by Tobias Koenig's avatar Tobias Koenig

Port Contact(Group)SearchJob to inherit ItemSearchJob

svn path=/trunk/KDE/kdepimlibs/; revision=1036695
parent 1263eff2
......@@ -21,60 +21,22 @@
#include "contactgroupsearchjob.h"
#include <akonadi/itemfetchscope.h>
#include <akonadi/itemsearchjob.h>
using namespace Akonadi;
class ContactGroupSearchJob::Private
{
public:
Private( ContactGroupSearchJob *parent )
: mParent( parent ), mCriterion( ContactGroupSearchJob::Name )
{
}
void searchResult( KJob *job )
{
ItemSearchJob *searchJob = qobject_cast<ItemSearchJob*>( job );
mItems = searchJob->items();
foreach ( const Item &item, mItems ) {
if ( item.hasPayload<KABC::ContactGroup>() )
mContactGroups.append( item.payload<KABC::ContactGroup>() );
}
mParent->emitResult();
}
ContactGroupSearchJob *mParent;
ContactGroupSearchJob::Criterion mCriterion;
QString mValue;
KABC::ContactGroup::List mContactGroups;
Item::List mItems;
};
ContactGroupSearchJob::ContactGroupSearchJob( QObject * parent )
: KJob( parent ), d( new Private( this ) )
: ItemSearchJob( QString(), parent ), d( 0 )
{
}
ContactGroupSearchJob::~ContactGroupSearchJob()
{
delete d;
}
void ContactGroupSearchJob::setQuery( Criterion criterion, const QString &value )
{
d->mCriterion = criterion;
d->mValue = value;
}
void ContactGroupSearchJob::start()
{
QString query;
if ( d->mCriterion == Name ) {
if ( criterion == Name ) {
query = QString::fromLatin1( ""
"prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>"
"SELECT ?group WHERE {"
......@@ -82,22 +44,21 @@ void ContactGroupSearchJob::start()
"}" );
}
query = query.arg( d->mValue );
query = query.arg( value );
ItemSearchJob *job = new ItemSearchJob( query, this );
job->fetchScope().fetchFullPayload();
connect( job, SIGNAL( result( KJob* ) ), this, SLOT( searchResult( KJob* ) ) );
job->start();
ItemSearchJob::setQuery( query );
}
KABC::ContactGroup::List ContactGroupSearchJob::contactGroups() const
{
return d->mContactGroups;
}
KABC::ContactGroup::List contactGroups;
Item::List ContactGroupSearchJob::items() const
{
return d->mItems;
foreach ( const Item &item, items() ) {
if ( item.hasPayload<KABC::ContactGroup>() )
contactGroups.append( item.payload<KABC::ContactGroup>() );
}
return contactGroups;
}
#include "contactgroupsearchjob.moc"
......@@ -25,8 +25,8 @@
#include "akonadi-contact_export.h"
#include <akonadi/item.h>
#include <akonadi/itemsearchjob.h>
#include <kabc/contactgroup.h>
#include <kjob.h>
namespace Akonadi {
......@@ -40,7 +40,6 @@ namespace Akonadi {
*
* Akonadi::ContactGroupSearchJob *job = new Akonadi::ContactGroupSearchJob();
* job->setQuery( Akonadi::ContactGroupSearchJob::Name, "Family Members" );
* job->start();
* connect( job, SIGNAL( result( KJob* ) ), this, SLOT( searchResult( KJob* ) ) );
*
* ...
......@@ -57,8 +56,7 @@ namespace Akonadi {
* @author Tobias Koenig <tokoe@kde.org>
* @since 4.4
*/
//TODO_AKONADI_REVIEW: inherit from ItemSearchJob
class AKONADI_CONTACT_EXPORT ContactGroupSearchJob : public KJob
class AKONADI_CONTACT_EXPORT ContactGroupSearchJob : public ItemSearchJob
{
Q_OBJECT
......@@ -93,22 +91,10 @@ class AKONADI_CONTACT_EXPORT ContactGroupSearchJob : public KJob
*/
KABC::ContactGroup::List contactGroups() const;
/**
* Returns the items that matched the search criteria.
*/
Item::List items() const;
/**
* Starts the search job.
*/
virtual void start();
private:
//@cond PRIVATE
class Private;
Private* const d;
Q_PRIVATE_SLOT( d, void searchResult( KJob* ) )
//@endcond
};
......
......@@ -21,66 +21,28 @@
#include "contactsearchjob.h"
#include <akonadi/itemfetchscope.h>
#include <akonadi/itemsearchjob.h>
using namespace Akonadi;
class ContactSearchJob::Private
{
public:
Private( ContactSearchJob *parent )
: mParent( parent ), mCriterion( ContactSearchJob::Name )
{
}
void searchResult( KJob *job )
{
ItemSearchJob *searchJob = qobject_cast<ItemSearchJob*>( job );
mItems = searchJob->items();
foreach ( const Item &item, mItems ) {
if ( item.hasPayload<KABC::Addressee>() )
mContacts.append( item.payload<KABC::Addressee>() );
}
mParent->emitResult();
}
ContactSearchJob *mParent;
ContactSearchJob::Criterion mCriterion;
QString mValue;
KABC::Addressee::List mContacts;
Item::List mItems;
};
ContactSearchJob::ContactSearchJob( QObject * parent )
: KJob( parent ), d( new Private( this ) )
: ItemSearchJob( QString(), parent ), d( 0 )
{
}
ContactSearchJob::~ContactSearchJob()
{
delete d;
}
void ContactSearchJob::setQuery( Criterion criterion, const QString &value )
{
d->mCriterion = criterion;
d->mValue = value;
}
void ContactSearchJob::start()
{
QString query;
if ( d->mCriterion == Name ) {
if ( criterion == Name ) {
query = QString::fromLatin1( ""
"prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>"
"SELECT ?r WHERE {"
" ?r nco:fullname \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>."
"}" );
} else if ( d->mCriterion == Email ) {
} else if ( criterion == Email ) {
query = QString::fromLatin1( ""
"prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>"
"SELECT ?person WHERE {"
......@@ -89,22 +51,21 @@ void ContactSearchJob::start()
" }" );
}
query = query.arg( d->mValue );
query = query.arg( value );
ItemSearchJob *job = new ItemSearchJob( query, this );
job->fetchScope().fetchFullPayload();
connect( job, SIGNAL( result( KJob* ) ), this, SLOT( searchResult( KJob* ) ) );
job->start();
ItemSearchJob::setQuery( query );
}
KABC::Addressee::List ContactSearchJob::contacts() const
{
return d->mContacts;
}
KABC::Addressee::List contacts;
Item::List ContactSearchJob::items() const
{
return d->mItems;
foreach ( const Item &item, items() ) {
if ( item.hasPayload<KABC::Addressee>() )
contacts.append( item.payload<KABC::Addressee>() );
}
return contacts;
}
#include "contactsearchjob.moc"
......@@ -25,8 +25,8 @@
#include "akonadi-contact_export.h"
#include <akonadi/item.h>
#include <akonadi/itemsearchjob.h>
#include <kabc/addressee.h>
#include <kjob.h>
namespace Akonadi {
......@@ -40,7 +40,6 @@ namespace Akonadi {
*
* Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob();
* job->setQuery( Akonadi::ContactSearchJob::Email, "tokoe@kde.org" );
* job->start();
* connect( job, SIGNAL( result( KJob* ) ), this, SLOT( searchResult( KJob* ) ) );
*
* ...
......@@ -57,8 +56,7 @@ namespace Akonadi {
* @author Tobias Koenig <tokoe@kde.org>
* @since 4.4
*/
//TODO_AKONADI_REVIEW: inherit from ItemSearchJob
class AKONADI_CONTACT_EXPORT ContactSearchJob : public KJob
class AKONADI_CONTACT_EXPORT ContactSearchJob : public ItemSearchJob
{
Q_OBJECT
......@@ -94,22 +92,10 @@ class AKONADI_CONTACT_EXPORT ContactSearchJob : public KJob
*/
KABC::Addressee::List contacts() const;
/**
* Returns the items that matched the search criteria.
*/
Item::List items() const;
/**
* Starts the search job.
*/
virtual void start();
private:
//@cond PRIVATE
class Private;
Private* const d;
Q_PRIVATE_SLOT( d, void searchResult( KJob* ) )
//@endcond
};
......
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