[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/akonadi/agents
From: Volker Krause <vkrause () kde ! org>
Date: 2009-09-29 10:23:22
Message-ID: 1254219802.236783.31214.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1029247 by vkrause:
Factor out the contact search and creation code. Looks like we are
finally no longer creating empty or duplicated PersonContact resources.
M +1 -28 nepomuk_calendar_feeder/nepomukcalendarfeeder.cpp
M +1 -43 nepomuk_email_feeder/nepomukemailfeeder.cpp
M +3 -5 nepomuk_email_feeder/nepomukemailfeeder.h
M +44 -1 nepomukfeeder/nepomukfeederagentbase.cpp
M +11 -0 nepomukfeeder/nepomukfeederagentbase.h
--- trunk/KDE/kdepim/akonadi/agents/nepomuk_calendar_feeder/nepomukcalendarfeeder.cpp \
#1029246:1029247 @@ -55,33 +55,6 @@
namespace Akonadi {
-static NepomukFast::Contact findOrMakeNepomukContact( const QString &name, const \
QString &email )
-{
- // find person using name and email
- SparqlBuilder::BasicGraphPattern graph;
- graph.addTriple( "?person", Vocabulary::NCO::fullname(), name );
- graph.addTriple( "?person", Vocabulary::NCO::hasEmailAddress(), \
SparqlBuilder::QueryVariable( "?email" ) );
- graph.addTriple( "?email", Vocabulary::NCO::emailAddress(), email );
- SelectSparqlBuilder qb;
- qb.addQueryVariable( "?person" );
- qb.setGraphPattern( graph );
- const QList<Soprano::Node> list = \
Nepomuk::ResourceManager::instance()->mainModel()->executeQuery( \
qb.query(),
- Soprano::Query::QueryLanguageSparql ).iterateBindings( 0 ).allNodes();
-
- foreach ( const Soprano::Node &node, list ) {
- if ( node.isResource () )
- return NepomukFast::Contact( node.uri() );
- }
-
- NepomukFast::Contact contact;
- contact.setLabel( name.isEmpty() ? email : name );
- contact.addFullname( name );
- NepomukFast::EmailAddress emailRes( QUrl( "mailto:" + email ) );
- emailRes.setEmailAddress( email );
- contact.addEmailAddress( emailRes );
- return contact;
-}
-
NepomukCalendarFeeder::NepomukCalendarFeeder( const QString &id )
: NepomukFeederAgent<NepomukFast::Calendar>( id )
{
@@ -139,7 +112,7 @@
}
foreach ( const KCal::Attendee *calAttendee, calEvent->attendees() ) {
- NepomukFast::Contact contact = findOrMakeNepomukContact( calAttendee->name(), \
calAttendee->email() ); + NepomukFast::Contact contact = findOrCreateContact( \
calAttendee->email(), calAttendee->name(), graphUri ); NepomukFast::Attendee \
attendee( QUrl(), graphUri ); attendee.addInvolvedContact( contact );
--- trunk/KDE/kdepim/akonadi/agents/nepomuk_email_feeder/nepomukemailfeeder.cpp \
#1029246:1029247 @@ -20,7 +20,6 @@
#include "nepomukemailfeeder.h"
#include "email.h"
-#include "emailaddress.h"
#include "personcontact.h"
#include "selectsqarqlbuilder.h"
@@ -120,16 +119,7 @@
foreach( const KMime::Types::Mailbox& mbox, mbs ) {
if ( mbox.hasAddress() ) {
- bool found = false;
- NepomukFast::Contact c = findContact( mbox.address(), graphUri, &found );
- if ( !found ) {
- if ( mbox.hasName() ) {
- c.addFullname( mbox.name() );
- c.setLabel( mbox.name() );
- } else {
- c.setLabel( mbox.address() );
- }
- }
+ const NepomukFast::Contact c = findOrCreateContact( QString::fromLatin1( \
mbox.address() ), mbox.name(), graphUri ); contacts << c;
}
}
@@ -137,38 +127,6 @@
return contacts;
}
-NepomukFast::PersonContact NepomukEMailFeeder::findContact( const QByteArray& \
address, const QUrl &graphUri, bool *found )
-{
- //
- // Querying with the exact address string is not perfect since email addresses
- // are case insensitive. But for the moment we stick to it and hope Nepomuk
- // alignment fixes any duplicates
- //
- SelectSparqlBuilder::BasicGraphPattern graph;
- graph.addTriple( "?r", NepomukFast::Role::emailAddressUri(), \
SparqlBuilder::QueryVariable("?a") );
- graph.addTriple( "?a", NepomukFast::EmailAddress::emailAddressUri(), \
QString::fromAscii( address ) );
- SelectSparqlBuilder qb;
- qb.setGraphPattern( graph );
- qb.addQueryVariable( "?r" );
- Soprano::QueryResultIterator it = \
Nepomuk::ResourceManager::instance()->mainModel()->executeQuery( qb.query(), \
Soprano::Query::QueryLanguageSparql );
-
- if ( it.next() ) {
- *found = true;
- const QUrl uri = it.binding( 0 ).uri();
- it.close();
- return NepomukFast::PersonContact( uri, graphUri );
- }
- else {
- *found = false;
- // create a new contact
- NepomukFast::PersonContact contact( QUrl(), graphUri );
- NepomukFast::EmailAddress email( QUrl( "mailto:" + address ), graphUri );
- email.setEmailAddress( QString::fromAscii( address ) );
- contact.addEmailAddress( email );
- return contact;
- }
-}
-
AKONADI_AGENT_MAIN( NepomukEMailFeeder )
#include "nepomukemailfeeder.moc"
--- trunk/KDE/kdepim/akonadi/agents/nepomuk_email_feeder/nepomukemailfeeder.h \
#1029246:1029247 @@ -21,15 +21,14 @@
#ifndef AKONADI_NEPOMUK_EMAIL_FEEDER_H
#define AKONADI_NEPOMUK_EMAIL_FEEDER_H
-#include <akonadi/agentbase.h>
+#include <nepomukfeederagent.h>
-#include "personcontact.h"
-#include "mailbox.h"
+#include <mailbox.h>
+#include <contact.h>
#include <QtCore/QList>
#include <kmime/kmime_header_parsing.h>
-#include <nepomukfeederagent.h>
namespace Akonadi {
@@ -44,7 +43,6 @@
private:
QList<NepomukFast::Contact> extractContactsFromMailboxes( const \
KMime::Types::Mailbox::List& mbs, const QUrl& );
- NepomukFast::PersonContact findContact( const QByteArray& address, const QUrl&, \
bool *found ); };
}
--- trunk/KDE/kdepim/akonadi/agents/nepomukfeeder/nepomukfeederagentbase.cpp \
#1029246:1029247 @@ -20,7 +20,10 @@
*/
#include "nepomukfeederagentbase.h"
-#include "nie.h"
+#include <nie.h>
+#include <nco.h>
+#include <personcontact.h>
+#include <emailaddress.h>
#include <akonadi/item.h>
#include <akonadi/changerecorder.h>
@@ -298,4 +301,44 @@
selfTest();
}
+NepomukFast::PersonContact NepomukFeederAgentBase::findOrCreateContact(const \
QString& emailAddress, const QString& name, const QUrl& graphUri, bool* found) +{
+ //
+ // Querying with the exact address string is not perfect since email addresses
+ // are case insensitive. But for the moment we stick to it and hope Nepomuk
+ // alignment fixes any duplicates
+ //
+ SelectSparqlBuilder::BasicGraphPattern graph;
+ if ( emailAddress.isEmpty() ) {
+ graph.addTriple( "?person", Vocabulary::NCO::fullname(), name );
+ } else {
+ graph.addTriple( "?person", Vocabulary::NCO::hasEmailAddress(), \
SparqlBuilder::QueryVariable( "?email" ) ); + graph.addTriple( "?email", \
Vocabulary::NCO::emailAddress(), emailAddress ); + }
+ SelectSparqlBuilder qb;
+ qb.setGraphPattern( graph );
+ qb.addQueryVariable( "?person" );
+ Soprano::QueryResultIterator it = \
Nepomuk::ResourceManager::instance()->mainModel()->executeQuery( qb.query(), \
Soprano::Query::QueryLanguageSparql ); +
+ if ( it.next() ) {
+ if ( found ) *found = true;
+ const QUrl uri = it.binding( 0 ).uri();
+ it.close();
+ return NepomukFast::PersonContact( uri, graphUri );
+ }
+ if ( found ) *found = false;
+ // create a new contact
+ kDebug() << "Did not find " << name << emailAddress << ", creating a new \
PersonContact"; + NepomukFast::PersonContact contact( QUrl(), graphUri );
+ contact.setLabel( name.isEmpty() ? emailAddress : name );
+ if ( !emailAddress.isEmpty() ) {
+ NepomukFast::EmailAddress emailRes( QUrl( "mailto:" + emailAddress ), graphUri \
); + emailRes.setEmailAddress( emailAddress );
+ contact.addEmailAddress( emailRes );
+ }
+ if ( !name.isEmpty() )
+ contact.addFullname( name );
+ return contact;
+}
+
#include "nepomukfeederagentbase.moc"
--- trunk/KDE/kdepim/akonadi/agents/nepomukfeeder/nepomukfeederagentbase.h \
#1029246:1029247 @@ -53,6 +53,11 @@
class NRLModel;
}
+namespace NepomukFast
+{
+ class PersonContact;
+}
+
class KJob;
/** Shared base class for all Nepomuk feeders. */
@@ -108,6 +113,12 @@
return graphUri;
}
+ /** Finds (or if it doesn't exist creates) a PersonContact object for the given \
name and address. + @param found Used to indicate if the contact is already \
there are was just newly created. In the latter case you might + want to add \
additional information you have available for it. + */
+ NepomukFast::PersonContact findOrCreateContact( const QString &email, const \
QString &name, const QUrl &graphUri, bool *found = 0 ); +
public slots:
/** Trigger a complete update of all items. */
void updateAll();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic