2
Copyright (c) 2012 Montel Laurent <montel@kde.org>
4
This program is free software; you can redistribute it and/or modify it
5
under the terms of the GNU General Public License, version 2, as
6
published by the Free Software Foundation.
8
This program is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
General Public License for more details.
13
You should have received a copy of the GNU General Public License along
14
with this program; if not, write to the Free Software Foundation, Inc.,
15
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#include "vcardmemento.h"
19
#include <Akonadi/Contact/ContactSearchJob>
21
using namespace MessageViewer;
23
VcardMemento::VcardMemento( const QStringList& emails )
28
Q_FOREACH(const QString& str, emails) {
29
VCard vcard(str,false);
30
mVCardList.append(vcard);
35
VcardMemento::~VcardMemento()
40
void VcardMemento::checkEmail()
42
Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob();
43
searchJob->setQuery( Akonadi::ContactSearchJob::Email, mVCardList.at(mIndex).email );
44
connect( searchJob, SIGNAL(result(KJob*)),
45
this, SLOT(slotSearchJobFinished(KJob*)) );
48
void VcardMemento::slotSearchJobFinished( KJob *job )
50
Akonadi::ContactSearchJob *searchJob = static_cast<Akonadi::ContactSearchJob*>( job );
51
if ( searchJob->error() ) {
52
kWarning() << "Unable to fetch contact:" << searchJob->errorText();
54
continueToCheckEmail();
58
const int contactSize( searchJob->contacts().size() );
59
if ( contactSize == 1 ) {
60
VCard vcard = mVCardList.at(mIndex);
62
vcard.address = searchJob->contacts().first();
63
mVCardList[mIndex] = vcard;
64
} else if ( contactSize > 1 ) {
65
kDebug()<<" more than 1 contact was found";
66
// TODO: Figure out something here...
69
continueToCheckEmail();
72
void VcardMemento::continueToCheckEmail()
74
if(mIndex == mVCardList.count()) {
76
emit update( Viewer::Delayed );
83
bool VcardMemento::finished() const
88
void VcardMemento::detach()
90
disconnect( this, SIGNAL(update(MessageViewer::Viewer::UpdateMode)), 0, 0 );
93
bool VcardMemento::vcardExist(int index) const
95
return mVCardList.at(index).found;
98
KABC::Addressee VcardMemento::address( int index ) const
100
return mVCardList.at(index).address;
103
#include "vcardmemento.moc"