• 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
  • viewer
  • memento
verifyopaquebodypartmemento.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014-2015 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 "verifyopaquebodypartmemento.h"
19 
20 #include <kdebug.h>
21 #include <kleo/verifyopaquejob.h>
22 #include <kleo/keylistjob.h>
23 
24 #include <gpgme++/keylistresult.h>
25 
26 #include <qstringlist.h>
27 
28 #include <cassert>
29 
30 using namespace Kleo;
31 using namespace GpgME;
32 using namespace MessageViewer;
33 
34 VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento( VerifyOpaqueJob * job,
35  KeyListJob * klj,
36  const QByteArray & signature )
37  : CryptoBodyPartMemento(),
38  m_signature( signature ),
39  m_job( job ),
40  m_keylistjob( klj )
41 {
42  assert( m_job );
43 }
44 
45 VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() {
46  if ( m_job )
47  m_job->slotCancel();
48  if ( m_keylistjob )
49  m_keylistjob->slotCancel();
50 }
51 
52 bool VerifyOpaqueBodyPartMemento::start() {
53  assert( m_job );
54 #ifdef DEBUG_SIGNATURE
55  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento started";
56 #endif
57  if ( const Error err = m_job->start( m_signature ) ) {
58  m_vr = VerificationResult( err );
59 #ifdef DEBUG_SIGNATURE
60  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento stopped with error";
61 #endif
62  return false;
63  }
64  connect( m_job, SIGNAL(result(GpgME::VerificationResult,QByteArray)),
65  this, SLOT(slotResult(GpgME::VerificationResult,QByteArray)) );
66  setRunning( true );
67  return true;
68 }
69 
70 void VerifyOpaqueBodyPartMemento::exec() {
71  assert( m_job );
72  setRunning( true );
73  QByteArray plainText;
74 #ifdef DEBUG_SIGNATURE
75  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento execed";
76 #endif
77  saveResult( m_job->exec( m_signature, plainText ), plainText );
78 #ifdef DEBUG_SIGNATURE
79  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento after execed";
80 #endif
81  m_job->deleteLater(); // exec'ed jobs don't delete themselves
82  m_job = 0;
83  if ( canStartKeyListJob() ) {
84  std::vector<GpgME::Key> keys;
85  m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys );
86  if ( !keys.empty() )
87  m_key = keys.back();
88  }
89  if ( m_keylistjob )
90  m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves
91  m_keylistjob = 0;
92  setRunning( false );
93 }
94 
95 bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const
96 {
97  if ( !m_keylistjob )
98  return false;
99  const char * const fpr = m_vr.signature( 0 ).fingerprint();
100  return fpr && *fpr;
101 }
102 
103 QStringList VerifyOpaqueBodyPartMemento::keyListPattern() const
104 {
105  assert( canStartKeyListJob() );
106  return QStringList( QString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) );
107 }
108 
109 void VerifyOpaqueBodyPartMemento::saveResult( const VerificationResult & vr,
110  const QByteArray & plainText )
111 {
112  assert( m_job );
113 #ifdef DEBUG_SIGNATURE
114  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento::saveResult called";
115 #endif
116  m_vr = vr;
117  m_plainText = plainText;
118  setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
119 }
120 
121 void VerifyOpaqueBodyPartMemento::slotResult( const VerificationResult & vr,
122  const QByteArray & plainText )
123 {
124 #ifdef DEBUG_SIGNATURE
125  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento::slotResult called";
126 #endif
127  saveResult( vr, plainText );
128  m_job = 0;
129  if ( canStartKeyListJob() && startKeyListJob() ) {
130 #ifdef DEBUG_SIGNATURE
131  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento: canStartKeyListJob && startKeyListJob";
132 #endif
133  return;
134  }
135  if ( m_keylistjob )
136  m_keylistjob->deleteLater();
137  m_keylistjob = 0;
138  setRunning( false );
139  notify();
140 }
141 
142 bool VerifyOpaqueBodyPartMemento::startKeyListJob()
143 {
144  assert( canStartKeyListJob() );
145  if ( const GpgME::Error err = m_keylistjob->start( keyListPattern() ) )
146  return false;
147  connect( m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
148  connect( m_keylistjob, SIGNAL(nextKey(GpgME::Key)),
149  this, SLOT(slotNextKey(GpgME::Key)) );
150  return true;
151 }
152 
153 void VerifyOpaqueBodyPartMemento::slotNextKey( const GpgME::Key & key )
154 {
155 #ifdef DEBUG_SIGNATURE
156  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento::slotNextKey called";
157 #endif
158  m_key = key;
159 }
160 
161 void VerifyOpaqueBodyPartMemento::slotKeyListJobDone()
162 {
163 #ifdef DEBUG_SIGNATURE
164  kDebug() << "tokoe: VerifyOpaqueBodyPartMemento::slotKeyListJobDone called";
165 #endif
166  m_keylistjob = 0;
167  setRunning( false );
168  notify();
169 }
MessageViewer::VerifyOpaqueBodyPartMemento::exec
void exec()
Definition: verifyopaquebodypartmemento.cpp:70
MessageViewer::CryptoBodyPartMemento::setAuditLog
void setAuditLog(const GpgME::Error &err, const QString &log)
Definition: cryptobodypartmemento.cpp:50
QByteArray
verifyopaquebodypartmemento.h
MessageViewer::CryptoBodyPartMemento::notify
void notify()
Definition: cryptobodypartmemento.h:53
MessageViewer::CryptoBodyPartMemento::setRunning
void setRunning(bool running)
Definition: cryptobodypartmemento.cpp:56
MessageViewer::VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento
~VerifyOpaqueBodyPartMemento()
Definition: verifyopaquebodypartmemento.cpp:45
QStringList
MessageViewer::VerifyOpaqueBodyPartMemento::plainText
const QByteArray & plainText() const
Definition: verifyopaquebodypartmemento.h:56
MessageViewer::CryptoBodyPartMemento
Definition: cryptobodypartmemento.h:33
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
MessageViewer::VerifyOpaqueBodyPartMemento::start
bool start()
Definition: verifyopaquebodypartmemento.cpp:52
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