Framework for looking up contacts directly in nepomuk in addition to going through...
[kdepim.git] / messageviewer / contactphotomemento.cpp
blob024b667dbd6ff0628cdac9f8fd5a3ca522a948d1
1 /* Copyright 2010 Thomas McGuire <mcguire@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License as
5 published by the Free Software Foundation; either version 2 of
6 the License or (at your option) version 3 or any later version
7 accepted by the membership of KDE e.V. (or its successor approved
8 by the membership of KDE e.V.), which shall act as a proxy
9 defined in Section 14 of version 3 of the license.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "contactphotomemento.h"
21 #include <Akonadi/Contact/ContactSearchJob>
23 using namespace MessageViewer;
25 ContactPhotoMemento::ContactPhotoMemento( const QString &emailAddress )
26 : QObject( 0 ), mFinished( false )
28 Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob();
29 searchJob->setQuery( Akonadi::ContactSearchJob::Email, emailAddress );
30 connect( searchJob, SIGNAL(result(KJob*)),
31 this, SLOT(slotSearchJobFinished(KJob*)) );
34 void ContactPhotoMemento::slotSearchJobFinished( KJob *job )
36 mFinished = true;
37 Akonadi::ContactSearchJob *searchJob = static_cast<Akonadi::ContactSearchJob*>( job );
38 if ( searchJob->error() ) {
39 kWarning() << "Unable to fetch photo for contact:" << searchJob->errorText();
40 return;
43 if ( searchJob->contacts().size() == 1 ) {
45 KABC::Addressee addressee = searchJob->contacts().first();
46 mPhoto = addressee.photo();
47 emit update( Viewer::Delayed );
49 } else if ( searchJob->contacts().size() > 1 ) {
50 // TODO: Figure out something here...
54 bool ContactPhotoMemento::finished() const
56 return mFinished;
59 KABC::Picture ContactPhotoMemento::photo() const
61 Q_ASSERT( mFinished );
62 return mPhoto;
65 void ContactPhotoMemento::detach()
67 disconnect( this, SIGNAL(update(MessageViewer::Viewer::UpdateMode)), 0, 0 );
72 #include "contactphotomemento.moc"