• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • header
contactdisplaymessagememento.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012-2015 Laurent Montel <montel@kde.org>
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public License
14  * along with this library; see the file COPYING.LIB. If not, write to
15  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301, USA.
17  */
18 
19 #include "contactdisplaymessagememento.h"
20 #include "pimcommon/gravatar/gravatarresolvurljob.h"
21 #include "settings/globalsettings.h"
22 #include <Akonadi/Contact/ContactSearchJob>
23 
24 using namespace MessageViewer;
25 
26 ContactDisplayMessageMemento::ContactDisplayMessageMemento( const QString &emailAddress )
27  : QObject( 0 ),
28  mForceDisplayTo( Viewer::UseGlobalSetting ),
29  mEmailAddress(emailAddress),
30  mFinished( false ),
31  mMailAllowToRemoteContent( false )
32 {
33  if( !mEmailAddress.isEmpty() ) {
34  Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob();
35  searchJob->setQuery( Akonadi::ContactSearchJob::Email, emailAddress.toLower(), Akonadi::ContactSearchJob::ExactMatch );
36  connect( searchJob, SIGNAL(result(KJob*)),
37  this, SLOT(slotSearchJobFinished(KJob*)) );
38  } else {
39  mFinished = true;
40  }
41 }
42 
43 ContactDisplayMessageMemento::~ContactDisplayMessageMemento()
44 {
45 }
46 
47 void ContactDisplayMessageMemento::slotSearchJobFinished( KJob *job )
48 {
49  mFinished = true;
50  Akonadi::ContactSearchJob *searchJob = static_cast<Akonadi::ContactSearchJob*>( job );
51  if ( searchJob->error() ) {
52  kWarning() << "Unable to fetch contact:" << searchJob->errorText();
53  emit update( Viewer::Delayed );
54  return;
55  }
56 
57  const int contactSize( searchJob->contacts().size() );
58  if ( contactSize >= 1 ) {
59  if (contactSize>1)
60  kDebug()<<" more than 1 contact was found we return first contact";
61 
62  const KABC::Addressee addressee = searchJob->contacts().at(0);
63  processAddress( addressee );
64  searchPhoto(searchJob->contacts());
65  emit update( Viewer::Delayed );
66  }
67  if (mPhoto.isEmpty() && mPhoto.url().isEmpty()) {
68  // No url, no photo => search gravatar
69  if (GlobalSettings::self()->gravatarSupportEnabled()) {
70  PimCommon::GravatarResolvUrlJob *job = new PimCommon::GravatarResolvUrlJob(this);
71  job->setEmail(mEmailAddress);
72  job->setUseDefaultPixmap(GlobalSettings::self()->gravatarUseDefaultImage());
73  if (job->canStart()) {
74  connect(job, SIGNAL(finished(PimCommon::GravatarResolvUrlJob*)), this, SLOT(slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob*)));
75  job->start();
76  }
77  }
78  }
79 }
80 
81 bool ContactDisplayMessageMemento::finished() const
82 {
83  return mFinished;
84 }
85 
86 void ContactDisplayMessageMemento::detach()
87 {
88  disconnect( this, SIGNAL(update(MessageViewer::Viewer::UpdateMode)), 0, 0 );
89  disconnect(this, SIGNAL(changeDisplayMail(Viewer::DisplayFormatMessage,bool)),0 ,0 );
90 }
91 
92 bool ContactDisplayMessageMemento::allowToRemoteContent() const
93 {
94  return mMailAllowToRemoteContent;
95 }
96 
97 bool ContactDisplayMessageMemento::searchPhoto(const KABC::AddresseeList &list)
98 {
99  bool foundPhoto = false;
100  Q_FOREACH (const KABC::Addressee &addressee, list) {
101  if (!addressee.photo().isEmpty()) {
102  mPhoto = addressee.photo();
103  foundPhoto = true;
104  break;
105  }
106  }
107  return foundPhoto;
108 }
109 QPixmap ContactDisplayMessageMemento::gravatarPixmap() const
110 {
111  return mGravatarPixmap;
112 }
113 
114 
115 void ContactDisplayMessageMemento::processAddress( const KABC::Addressee& addressee )
116 {
117  const QStringList customs = addressee.customs();
118  Q_FOREACH ( const QString& custom, customs ) {
119  if ( custom.contains(QLatin1String( "MailPreferedFormatting")) ) {
120  const QString value = addressee.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "MailPreferedFormatting" ) );
121  if ( value == QLatin1String( "TEXT" ) ) {
122  mForceDisplayTo = Viewer::Text;
123  } else if ( value == QLatin1String( "HTML" ) ) {
124  mForceDisplayTo = Viewer::Html;
125  } else {
126  mForceDisplayTo = Viewer::UseGlobalSetting;
127  }
128  } else if ( custom.contains(QLatin1String( "MailAllowToRemoteContent")) ) {
129  const QString value = addressee.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "MailAllowToRemoteContent" ) );
130  mMailAllowToRemoteContent = ( value == QLatin1String( "TRUE" ) );
131  }
132  }
133  emit changeDisplayMail(mForceDisplayTo, mMailAllowToRemoteContent);
134 }
135 
136 KABC::Picture ContactDisplayMessageMemento::photo() const
137 {
138  return mPhoto;
139 }
140 
141 void ContactDisplayMessageMemento::slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *job)
142 {
143  if (job && job->hasGravatar()) {
144  mGravatarPixmap = job->pixmap();
145  emit update( Viewer::Delayed );
146  }
147 }
MessageViewer::Viewer::DisplayFormatMessage
DisplayFormatMessage
Definition: viewer.h:108
globalsettings.h
MessageViewer::Viewer::UseGlobalSetting
Definition: viewer.h:109
MessageViewer::ContactDisplayMessageMemento::update
void update(MessageViewer::Viewer::UpdateMode)
MessageViewer::Viewer::UpdateMode
UpdateMode
The display update mode: Force updates the display immediately, Delayed updates after some time (150m...
Definition: viewer.h:132
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
MessageViewer::Viewer
This is the main widget for the viewer.
Definition: viewer.h:80
MessageViewer::ContactDisplayMessageMemento::ContactDisplayMessageMemento
ContactDisplayMessageMemento(const QString &emailAddress)
Definition: contactdisplaymessagememento.cpp:26
QObject
QString::isEmpty
bool isEmpty() const
MessageViewer::GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:34
contactdisplaymessagememento.h
QString
QStringList
QPixmap
QString::toLower
QString toLower() const
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
MessageViewer::ContactDisplayMessageMemento::processAddress
void processAddress(const KABC::Addressee &addressee)
Definition: contactdisplaymessagememento.cpp:115
MessageViewer::Viewer::Text
Definition: viewer.h:110
MessageViewer::ContactDisplayMessageMemento::~ContactDisplayMessageMemento
~ContactDisplayMessageMemento()
Definition: contactdisplaymessagememento.cpp:43
QLatin1String
MessageViewer::ContactDisplayMessageMemento::detach
void detach()
Definition: contactdisplaymessagememento.cpp:86
MessageViewer::ContactDisplayMessageMemento::photo
KABC::Picture photo() const
Definition: contactdisplaymessagememento.cpp:136
MessageViewer::ContactDisplayMessageMemento::gravatarPixmap
QPixmap gravatarPixmap() const
Definition: contactdisplaymessagememento.cpp:109
MessageViewer::ContactDisplayMessageMemento::allowToRemoteContent
bool allowToRemoteContent() const
Definition: contactdisplaymessagememento.cpp:92
MessageViewer::Viewer::Html
Definition: viewer.h:111
MessageViewer::Viewer::Delayed
Definition: viewer.h:134
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
MessageViewer::ContactDisplayMessageMemento::changeDisplayMail
void changeDisplayMail(Viewer::DisplayFormatMessage displayAsHtml, bool remoteContent)
KJob
MessageViewer::ContactDisplayMessageMemento::finished
bool finished() const
Definition: contactdisplaymessagememento.cpp:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal