• 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
verifydetachedbodypartmemento.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 "verifydetachedbodypartmemento.h"
19 
20 #include <kdebug.h>
21 #include <kleo/verifydetachedjob.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 
35 
36 VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob * job,
37  KeyListJob * klj,
38  const QByteArray & signature,
39  const QByteArray & plainText )
40  : CryptoBodyPartMemento(),
41  m_signature( signature ),
42  m_plainText( plainText ),
43  m_job( job ),
44  m_keylistjob( klj )
45 {
46  assert( m_job );
47 }
48 
49 VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() {
50  if ( m_job )
51  m_job->slotCancel();
52  if ( m_keylistjob )
53  m_keylistjob->slotCancel();
54 }
55 
56 bool VerifyDetachedBodyPartMemento::start() {
57  assert( m_job );
58 #ifdef DEBUG_SIGNATURE
59  kDebug() << "tokoe: VerifyDetachedBodyPartMemento started";
60 #endif
61  connect( m_job, SIGNAL(result(GpgME::VerificationResult)),
62  this, SLOT(slotResult(GpgME::VerificationResult)) );
63  if ( const Error err = m_job->start( m_signature, m_plainText ) ) {
64  m_vr = VerificationResult( err );
65 #ifdef DEBUG_SIGNATURE
66  kDebug() << "tokoe: VerifyDetachedBodyPartMemento stopped with error";
67 #endif
68  return false;
69  }
70  setRunning( true );
71  return true;
72 }
73 
74 void VerifyDetachedBodyPartMemento::exec() {
75  assert( m_job );
76  setRunning( true );
77 #ifdef DEBUG_SIGNATURE
78  kDebug() << "tokoe: VerifyDetachedBodyPartMemento execed";
79 #endif
80  saveResult( m_job->exec( m_signature, m_plainText ) );
81  m_job->deleteLater(); // exec'ed jobs don't delete themselves
82  m_job = 0;
83 #ifdef DEBUG_SIGNATURE
84  kDebug() << "tokoe: VerifyDetachedBodyPartMemento after execed";
85 #endif
86  if ( canStartKeyListJob() ) {
87  std::vector<GpgME::Key> keys;
88  m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys );
89  if ( !keys.empty() )
90  m_key = keys.back();
91  }
92  if ( m_keylistjob )
93  m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves
94  m_keylistjob = 0;
95  setRunning( false );
96 }
97 
98 bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const
99 {
100  if ( !m_keylistjob )
101  return false;
102  const char * const fpr = m_vr.signature( 0 ).fingerprint();
103  return fpr && *fpr;
104 }
105 
106 QStringList VerifyDetachedBodyPartMemento::keyListPattern() const
107 {
108  assert( canStartKeyListJob() );
109  return QStringList( QString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) );
110 }
111 
112 void VerifyDetachedBodyPartMemento::saveResult( const VerificationResult & vr )
113 {
114  assert( m_job );
115 #ifdef DEBUG_SIGNATURE
116  kDebug() << "tokoe: VerifyDetachedBodyPartMemento::saveResult called";
117 #endif
118  m_vr = vr;
119  setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
120 }
121 
122 void VerifyDetachedBodyPartMemento::slotResult( const VerificationResult & vr )
123 {
124 #ifdef DEBUG_SIGNATURE
125  kDebug() << "tokoe: VerifyDetachedBodyPartMemento::slotResult called";
126 #endif
127  saveResult( vr );
128  m_job = 0;
129  if ( canStartKeyListJob() && startKeyListJob() ) {
130 #ifdef DEBUG_SIGNATURE
131  kDebug() << "tokoe: VerifyDetachedBodyPartMemento: 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 VerifyDetachedBodyPartMemento::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 VerifyDetachedBodyPartMemento::slotNextKey( const GpgME::Key & key )
154 {
155 #ifdef DEBUG_SIGNATURE
156  kDebug() << "tokoe: VerifyDetachedBodyPartMemento::slotNextKey called";
157 #endif
158  m_key = key;
159 }
160 
161 void VerifyDetachedBodyPartMemento::slotKeyListJobDone()
162 {
163 #ifdef DEBUG_SIGNATURE
164  kDebug() << "tokoe: VerifyDetachedBodyPartMemento::slotKeyListJobDone called";
165 #endif
166  m_keylistjob = 0;
167  setRunning( false );
168  notify();
169 }
MessageViewer::CryptoBodyPartMemento::setAuditLog
void setAuditLog(const GpgME::Error &err, const QString &log)
Definition: cryptobodypartmemento.cpp:50
QByteArray
MessageViewer::CryptoBodyPartMemento::notify
void notify()
Definition: cryptobodypartmemento.h:53
MessageViewer::VerifyDetachedBodyPartMemento::exec
void exec()
Definition: verifydetachedbodypartmemento.cpp:74
MessageViewer::CryptoBodyPartMemento::setRunning
void setRunning(bool running)
Definition: cryptobodypartmemento.cpp:56
QStringList
MessageViewer::VerifyDetachedBodyPartMemento::start
bool start()
Definition: verifydetachedbodypartmemento.cpp:56
MessageViewer::CryptoBodyPartMemento
Definition: cryptobodypartmemento.h:33
MessageViewer::VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento
~VerifyDetachedBodyPartMemento()
Definition: verifydetachedbodypartmemento.cpp:49
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)
verifydetachedbodypartmemento.h
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