21 #include <Akonadi/Collection>
24 #include <akonadi/contact/contactsearchjob.h>
25 #include <akonadi/item.h>
26 #include <akonadi/itemcreatejob.h>
27 #include <kabc/addressee.h>
29 #include <kmessagebox.h>
31 #include <QtCore/QPointer>
35 class AddContactJob::Private
39 : q( qq ), mContact( contact ), mParentWidget( parentWidget ), mShowMessageBox(true)
43 Private(
AddContactJob *qq,
const KABC::Addressee &contact,
const Akonadi::Collection &collection )
44 : q( qq ), mContact( contact ), mParentWidget( 0 ), mCollection( collection ), mShowMessageBox(true)
48 void slotSearchDone(
KJob *job )
51 q->setError( job->error() );
52 q->setErrorText( job->errorText() );
57 const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( job );
59 const KABC::Addressee::List contacts = searchJob->contacts();
61 if ( !contacts.isEmpty() ) {
65 "The vCard's primary email address is already in "
66 "your address book; however, you may save the vCard into "
67 "a file and import it into the address book manually." );
68 KMessageBox::information( mParentWidget, text );
70 q->setError( UserDefinedError );
75 if ( !mCollection.isValid() ) {
81 q->setError( UserDefinedError );
85 mCollection = dlg->selectedCollection();
93 if ( mCollection.isValid() ) {
96 item.setMimeType( KABC::Addressee::mimeType() );
97 item.setPayload<KABC::Addressee>( mContact );
100 Akonadi::ItemCreateJob *job =
new Akonadi::ItemCreateJob( item, mCollection );
101 q->connect( job, SIGNAL(result(
KJob*)), SLOT(slotAddContactDone(
KJob*)) );
103 q->setError( UserDefinedError );
108 void slotAddContactDone(
KJob *job )
110 if ( job->error() ) {
111 q->setError( job->error() );
112 q->setErrorText( job->errorText() );
117 if(mShowMessageBox) {
120 "The vCard was added to your address book; "
121 "you can add more information to this "
122 "entry by opening the address book." );
123 KMessageBox::information(
127 QLatin1String(
"addedtokabc") );
133 KABC::Addressee mContact;
135 Akonadi::Collection mCollection;
136 bool mShowMessageBox;
140 :
KJob( parent ), d( new Private( this, contact, parentWidget ) )
145 :
KJob( parent ), d( new Private( this, contact, collection ) )
156 d->mShowMessageBox = b;
162 Akonadi::ContactSearchJob *searchJob =
new Akonadi::ContactSearchJob(
this );
163 searchJob->setLimit( 1 );
164 searchJob->setQuery( Akonadi::ContactSearchJob::Email, d->mContact.preferredEmail().toLower(),
165 Akonadi::ContactSearchJob::ExactMatch );
167 connect( searchJob, SIGNAL(result(
KJob*)), SLOT(slotSearchDone(
KJob*)) );
170 #include "addcontactjob.moc"