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

« back to all changes in this revision

Viewing changes to plugins/messageviewer/bodypartformatter/text_vcard.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:
2
2
 
3
3
  This file is part of KMail, the KDE mail client.
4
4
  Copyright (c) 2004 Till Adam <adam@kde.org>
5
 
  Copyright (c) 2010 Klar�lvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
 
5
  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
6
6
  Copyright (c) 2012 Laurent Montel <montel@kde.org>
7
7
 
8
8
  KMail is free software; you can redistribute it and/or modify it
34
34
#include "messageviewer/interfaces/bodyparturlhandler.h"
35
35
#include "messageviewer/interfaces/bodypart.h"
36
36
#include <messageviewer/nodehelper.h>
 
37
#include "updatecontactjob.h"
 
38
#include "vcardmemento.h"
37
39
 
38
40
using MessageViewer::Interface::BodyPart;
39
41
#include "messageviewer/webkitparthtmlwriter.h"
66
68
    {
67
69
    }
68
70
 
69
 
    Result format( BodyPart *bodyPart, MessageViewer::HtmlWriter *writer ) const
 
71
    Result format( BodyPart * part, MessageViewer::HtmlWriter * writer ) const
 
72
    {
 
73
      return format ( part, writer, 0 );
 
74
    }
 
75
 
 
76
    Result format( BodyPart *bodyPart, MessageViewer::HtmlWriter *writer, QObject* asyncResultObserver ) const
70
77
    {
71
78
      if ( !writer ) {
72
 
        return AsIcon;
 
79
        return Ok;
73
80
      }
74
81
 
75
82
      const QString vCard = bodyPart->asText();
78
85
      }
79
86
 
80
87
      KABC::VCardConverter vcc;
81
 
      KABC::Addressee::List al = vcc.parseVCards( vCard.toUtf8() );
 
88
      const KABC::Addressee::List al = vcc.parseVCards( vCard.toUtf8() );
 
89
 
 
90
      MessageViewer::VcardMemento *memento = dynamic_cast<MessageViewer::VcardMemento*>( bodyPart->memento() );
 
91
      QStringList lst;
82
92
 
83
93
      // Pre-count the number of non-empty addressees
84
94
      int count = 0;
86
96
        if ( a.isEmpty() ) {
87
97
          continue;
88
98
        }
 
99
        if(!memento) {
 
100
          lst.append(a.emails().first());
 
101
        }
89
102
        count++;
90
103
      }
91
104
      if ( !count ) {
99
112
      count = 0;
100
113
      static QString defaultPixmapPath = QLatin1String("file:///") + KIconLoader::global()->iconPath( "user-identity", KIconLoader::Desktop );
101
114
      static QString defaultMapIconPath = QLatin1String("file:///") + KIconLoader::global()->iconPath( "document-open-remote", KIconLoader::Small );
 
115
 
 
116
 
 
117
      if ( !memento ) {
 
118
        MessageViewer::VcardMemento *memento = new MessageViewer::VcardMemento(lst);
 
119
        bodyPart->setBodyPartMemento( memento );
 
120
 
 
121
        if ( asyncResultObserver ) {
 
122
          QObject::connect( memento, SIGNAL(update(MessageViewer::Viewer::UpdateMode)),
 
123
                            asyncResultObserver, SLOT(update(MessageViewer::Viewer::UpdateMode)) );
 
124
        }
 
125
      }
 
126
 
 
127
 
102
128
      foreach ( const KABC::Addressee &a, al ) {
103
129
        if ( a.isEmpty() ) {
104
130
          continue;
105
131
        }        
106
132
        Akonadi::StandardContactFormatter formatter;
107
133
        formatter.setContact( a );
108
 
        formatter.setDisplayQRCode(false);
 
134
        formatter.setDisplayQRCode(false);
109
135
        QString htmlStr = formatter.toHtml( Akonadi::StandardContactFormatter::EmbeddableForm );
110
 
        KABC::Picture photo = a.photo();
 
136
        const KABC::Picture photo = a.photo();
111
137
        htmlStr.replace(QLatin1String("<img src=\"map_icon\""),QString::fromLatin1("<img src=\"%1\"").arg(defaultMapIconPath));
112
138
        if(photo.isEmpty()) {
113
139
          htmlStr.replace(QLatin1String("img src=\"contact_photo\""),QString::fromLatin1("img src=\"%1\"").arg(defaultPixmapPath));
122
148
        }
123
149
        writer->queue( htmlStr );
124
150
 
125
 
        QString addToLinkText = i18n( "[Add this contact to the address book]" );
126
 
        QString op = QString::fromLatin1( "addToAddressBook:%1" ).arg( count );
127
 
        writer->queue( "<div align=\"center\"><a href=\"" +
128
 
                       bodyPart->makeLink( op ) +
129
 
                       "\">" +
130
 
                       addToLinkText +
131
 
                       "</a></div><br><br>" );
 
151
        if(!memento ||
 
152
                (memento && !memento->finished()) ||
 
153
                (memento && memento->finished() && !memento->vcardExist(count)) ) {
 
154
          const QString addToLinkText = i18n( "[Add this contact to the address book]" );
 
155
          QString op = QString::fromLatin1( "addToAddressBook:%1" ).arg( count );
 
156
          writer->queue( "<div align=\"center\"><a href=\"" +
 
157
                         bodyPart->makeLink( op ) +
 
158
                         "\">" +
 
159
                         addToLinkText +
 
160
                         "</a></div><br><br>" );
 
161
        } else {
 
162
            if(memento->address(count) != a) {
 
163
              const QString addToLinkText = i18n( "[Update this contact to the address book]" );
 
164
              QString op = QString::fromLatin1( "updateToAddressBook:%1" ).arg( count );
 
165
              writer->queue( "<div align=\"center\"><a href=\"" +
 
166
                             bodyPart->makeLink( op ) +
 
167
                             "\">" +
 
168
                             addToLinkText +
 
169
                            "</a></div><br><br>" );
 
170
            } else {
 
171
                const QString addToLinkText = i18n( "[This contact is already in addressbook]" );
 
172
                writer->queue( "<div align=\"center\">" +
 
173
                               addToLinkText +
 
174
                              "</a></div><br><br>" );
 
175
            }
 
176
        }
132
177
        count++;
133
178
      }
134
179
 
149
194
        return true;
150
195
      }
151
196
      KABC::VCardConverter vcc;
152
 
      KABC::Addressee::List al = vcc.parseVCards( vCard.toUtf8() );
153
 
      int index = path.right( path.length() - path.lastIndexOf( ":" ) - 1 ).toInt();
 
197
      const KABC::Addressee::List al = vcc.parseVCards( vCard.toUtf8() );
 
198
      const int index = path.right( path.length() - path.lastIndexOf( ":" ) - 1 ).toInt();
154
199
      if ( index == -1 || index >= al.count() ) {
155
200
        return true;
156
201
      }
157
 
      KABC::Addressee a = al[index];
 
202
      const KABC::Addressee a = al.at(index);
158
203
      if ( a.isEmpty() ) {
159
204
        return true;
160
205
      }
161
206
 
162
 
      KPIM::AddContactJob *job = new KPIM::AddContactJob( a, 0 );
163
 
      job->start();
 
207
      if(path.startsWith(QLatin1String("addToAddressBook"))) {
 
208
 
 
209
        KPIM::AddContactJob *job = new KPIM::AddContactJob( a, 0 );
 
210
        job->start();
 
211
      } else if( path.startsWith(QLatin1String("updateToAddressBook"))) {
 
212
        UpdateContactJob *job = new UpdateContactJob(a.emails().first(), a, 0);
 
213
        job->start();
 
214
      }
164
215
 
165
216
      return true;
166
217
    }
170
221
      const QString vCard = part->asText();
171
222
      if ( !vCard.isEmpty() ) {
172
223
        KABC::VCardConverter vcc;
173
 
        KABC::Addressee::List al = vcc.parseVCards( vCard.toUtf8() );
 
224
        const KABC::Addressee::List al = vcc.parseVCards( vCard.toUtf8() );
174
225
        const int index = path.right( path.length() - path.lastIndexOf( ":" ) - 1 ).toInt();
175
226
        if ( index >= 0 && index < al.count() ) {
176
 
          return al[index];
 
227
          return al.at(index);
177
228
        }
178
229
      }
179
230
      return KABC::Addressee();
209
260
    QString statusBarMessage( BodyPart *part, const QString &path ) const
210
261
    {
211
262
      KABC::Addressee a = findAddressee( part, path );
 
263
      const bool addToAddressBook = path.startsWith(QLatin1String("addToAddressBook"));
212
264
      if ( a.realName().isEmpty() ) {
213
 
        return i18n( "Add this contact to the address book." );
 
265
        return addToAddressBook ? i18n( "Add this contact to the address book." ) : i18n("Update this contact to the address book.");
214
266
      } else {
215
 
        return i18n( "Add \"%1\" to the address book.", a.realName() );
 
267
        return addToAddressBook ? i18n( "Add \"%1\" to the address book.", a.realName() ) : i18n("Update \"%1\" to the address book.", a.realName());
216
268
     }
217
269
    }
218
270