~ubuntu-branches/ubuntu/vivid/kdepim/vivid

« back to all changes in this revision

Viewing changes to plugins/messageviewer/bodypartformatter/vcardmemento.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Rohan Garg, Scott Kitterman
  • Date: 2012-11-21 13:12:36 UTC
  • mfrom: (0.2.33)
  • Revision ID: package-import@ubuntu.com-20121121131236-32ijw9a2txrar80k
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Rohan Garg ]
* Add nepomuk-core-dev to build-deps

[ Scott Kitterman ]
* Add new package, libpimcommon4
  - Add libpimcommon4.install
  - Add to debian/control, including kdepim-dbg and kdepim-dev depends
  - Add to kdepim-dev.install
* Remove usr/bin/backupmail and related files from kmail.install as they are
  not provided by upstream anymore
* Add usr/bin/pimsettingexporter and related files to kmail.install
* Add libnepomukwidgets-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2012 Montel Laurent <montel@kde.org>
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
*/
 
17
 
 
18
#include "vcardmemento.h"
 
19
#include <Akonadi/Contact/ContactSearchJob>
 
20
 
 
21
using namespace MessageViewer;
 
22
 
 
23
VcardMemento::VcardMemento( const QStringList& emails )
 
24
  : QObject( 0 ),
 
25
    mIndex( 0 ),
 
26
    mFinished( false )
 
27
{
 
28
  Q_FOREACH(const QString& str, emails) {
 
29
      VCard vcard(str,false);
 
30
      mVCardList.append(vcard);
 
31
  }
 
32
  checkEmail();
 
33
}
 
34
 
 
35
VcardMemento::~VcardMemento()
 
36
{
 
37
 
 
38
}
 
39
 
 
40
void VcardMemento::checkEmail()
 
41
{
 
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*)) );
 
46
}
 
47
 
 
48
void VcardMemento::slotSearchJobFinished( KJob *job )
 
49
{
 
50
  Akonadi::ContactSearchJob *searchJob = static_cast<Akonadi::ContactSearchJob*>( job );
 
51
  if ( searchJob->error() ) {
 
52
    kWarning() << "Unable to fetch contact:" << searchJob->errorText();
 
53
    mIndex++;
 
54
    continueToCheckEmail();
 
55
    return;
 
56
  }
 
57
 
 
58
  const int contactSize( searchJob->contacts().size() );
 
59
  if ( contactSize == 1 ) {
 
60
    VCard vcard = mVCardList.at(mIndex);
 
61
    vcard.found = true;
 
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...
 
67
  }
 
68
  mIndex++;
 
69
  continueToCheckEmail();
 
70
}
 
71
 
 
72
void VcardMemento::continueToCheckEmail()
 
73
{
 
74
  if(mIndex == mVCardList.count()) {
 
75
    mFinished = true;
 
76
    emit update( Viewer::Delayed );
 
77
  } else {
 
78
    checkEmail();
 
79
  }
 
80
}
 
81
 
 
82
 
 
83
bool VcardMemento::finished() const
 
84
{
 
85
  return mFinished;
 
86
}
 
87
 
 
88
void VcardMemento::detach()
 
89
{
 
90
  disconnect( this, SIGNAL(update(MessageViewer::Viewer::UpdateMode)), 0, 0 );
 
91
}
 
92
 
 
93
bool VcardMemento::vcardExist(int index) const
 
94
{
 
95
  return mVCardList.at(index).found;
 
96
}
 
97
 
 
98
KABC::Addressee VcardMemento::address( int index ) const
 
99
{
 
100
  return mVCardList.at(index).address;
 
101
}
 
102
 
 
103
#include "vcardmemento.moc"