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

messageviewer

  • sources
  • kde-4.12
  • kdepim
  • messageviewer
  • header
contactdisplaymessagememento.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012,2013 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 
21 #include <Akonadi/Contact/ContactSearchJob>
22 
23 using namespace MessageViewer;
24 
25 ContactDisplayMessageMemento::ContactDisplayMessageMemento( const QString &emailAddress )
26  : QObject( 0 ),
27  mFinished( false ),
28  mMailAllowToRemoteContent( false ),
29  mForceDisplayTo( Viewer::Unknown )
30 {
31  if( !emailAddress.isEmpty() ) {
32  Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob();
33  searchJob->setQuery( Akonadi::ContactSearchJob::Email, emailAddress.toLower() );
34  connect( searchJob, SIGNAL(result(KJob*)),
35  this, SLOT(slotSearchJobFinished(KJob*)) );
36  } else {
37  mFinished = true;
38  }
39 }
40 
41 ContactDisplayMessageMemento::~ContactDisplayMessageMemento()
42 {
43 }
44 
45 void ContactDisplayMessageMemento::slotSearchJobFinished( KJob *job )
46 {
47  mFinished = true;
48  Akonadi::ContactSearchJob *searchJob = static_cast<Akonadi::ContactSearchJob*>( job );
49  if ( searchJob->error() ) {
50  kWarning() << "Unable to fetch contact:" << searchJob->errorText();
51  emit update( Viewer::Delayed );
52  return;
53  }
54 
55  const int contactSize( searchJob->contacts().size() );
56  if ( contactSize >= 1 ) {
57  searchPhoto(searchJob->contacts());
58  KABC::Addressee addressee = searchJob->contacts().first();
59  processAddress( addressee );
60  emit update( Viewer::Delayed );
61  if (contactSize>1)
62  kDebug()<<" more than 1 contact was found we return first contact";
63  }
64 }
65 
66 bool ContactDisplayMessageMemento::finished() const
67 {
68  return mFinished;
69 }
70 
71 void ContactDisplayMessageMemento::detach()
72 {
73  disconnect( this, SIGNAL(update(MessageViewer::Viewer::UpdateMode)), 0, 0 );
74  disconnect(this, SIGNAL(changeDisplayMail(Viewer::ForceDisplayTo,bool)),0 ,0 );
75 }
76 
77 bool ContactDisplayMessageMemento::allowToRemoteContent() const
78 {
79  return mMailAllowToRemoteContent;
80 }
81 
82 bool ContactDisplayMessageMemento::forceToHtml() const
83 {
84  return ( mForceDisplayTo == Viewer::Html );
85 }
86 
87 bool ContactDisplayMessageMemento::forceToText() const
88 {
89  return ( mForceDisplayTo == Viewer::Text );
90 }
91 
92 void ContactDisplayMessageMemento::searchPhoto(const KABC::AddresseeList &list)
93 {
94  Q_FOREACH (const KABC::Addressee &addressee, list) {
95  if (!addressee.photo().isEmpty()) {
96  mPhoto = addressee.photo();
97  break;
98  }
99  }
100 }
101 
102 void ContactDisplayMessageMemento::processAddress( const KABC::Addressee& addressee )
103 {
104  const QStringList customs = addressee.customs();
105  Q_FOREACH ( const QString& custom, customs ) {
106  if ( custom.contains(QLatin1String( "MailPreferedFormatting")) ) {
107  const QString value = addressee.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "MailPreferedFormatting" ) );
108  if ( value == QLatin1String( "TEXT" ) ) {
109  mForceDisplayTo = Viewer::Text;
110  } else if ( value == QLatin1String( "HTML" ) ) {
111  mForceDisplayTo = Viewer::Html;
112  } else {
113  mForceDisplayTo = Viewer::Unknown;
114  }
115  } else if ( custom.contains(QLatin1String( "MailAllowToRemoteContent")) ) {
116  const QString value = addressee.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "MailAllowToRemoteContent" ) );
117  mMailAllowToRemoteContent = ( value == QLatin1String( "TRUE" ) );
118  }
119  }
120  emit changeDisplayMail(mForceDisplayTo, mMailAllowToRemoteContent);
121 }
122 
123 KABC::Picture ContactDisplayMessageMemento::photo() const
124 {
125  return mPhoto;
126 }
127 
128 
129 #include "contactdisplaymessagememento.moc"
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
MessageViewer::Viewer
This is the main widget for the viewer.
Definition: viewer.h:80
MessageViewer::Viewer::ForceDisplayTo
ForceDisplayTo
Definition: viewer.h:108
MessageViewer::ContactDisplayMessageMemento::ContactDisplayMessageMemento
ContactDisplayMessageMemento(const QString &emailAddress)
Definition: contactdisplaymessagememento.cpp:25
contactdisplaymessagememento.h
MessageViewer::ContactDisplayMessageMemento::processAddress
void processAddress(const KABC::Addressee &addressee)
Definition: contactdisplaymessagememento.cpp:102
MessageViewer::Viewer::Unknown
Definition: viewer.h:109
MessageViewer::ContactDisplayMessageMemento::changeDisplayMail
void changeDisplayMail(Viewer::ForceDisplayTo displayAsHtml, bool remoteContent)
MessageViewer::ContactDisplayMessageMemento::~ContactDisplayMessageMemento
~ContactDisplayMessageMemento()
Definition: contactdisplaymessagememento.cpp:41
MessageViewer::ContactDisplayMessageMemento::detach
void detach()
Definition: contactdisplaymessagememento.cpp:71
MessageViewer::ContactDisplayMessageMemento::photo
KABC::Picture photo() const
Definition: contactdisplaymessagememento.cpp:123
MessageViewer::ContactDisplayMessageMemento::forceToHtml
bool forceToHtml() const
Definition: contactdisplaymessagememento.cpp:82
MessageViewer::Viewer::Text
Definition: viewer.h:110
MessageViewer::ContactDisplayMessageMemento::allowToRemoteContent
bool allowToRemoteContent() const
Definition: contactdisplaymessagememento.cpp:77
MessageViewer::ContactDisplayMessageMemento::forceToText
bool forceToText() const
Definition: contactdisplaymessagememento.cpp:87
MessageViewer::Viewer::Html
Definition: viewer.h:111
MessageViewer::Viewer::Delayed
Definition: viewer.h:134
MessageViewer::ContactDisplayMessageMemento::finished
bool finished() const
Definition: contactdisplaymessagememento.cpp:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 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

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