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

libkleo

  • sources
  • kde-4.12
  • kdepim
  • libkleo
  • backends
  • chiasmus
obtainkeysjob.cpp
Go to the documentation of this file.
1 /*
2  obtainkeysjob.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2005 Klarälvdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include "obtainkeysjob.h"
34 
35 #include "chiasmusbackend.h"
36 
37 #include "kleo/cryptoconfig.h"
38 
39 #include <klocale.h>
40 #include <kmessagebox.h>
41 #include <kshell.h>
42 
43 #include <QDir>
44 #include <QStringList>
45 #include <QVariant>
46 #include <QTimer>
47 #include <QFileInfo>
48 
49 #include <gpg-error.h>
50 
51 #include <cassert>
52 
53 Kleo::ObtainKeysJob::ObtainKeysJob( QObject * p )
54  : SpecialJob( p ),
55  mIndex( 0 ),
56  mCanceled( false )
57 {
58  assert( ChiasmusBackend::instance() );
59  assert( ChiasmusBackend::instance()->config() );
60  const CryptoConfigEntry * keypaths =
61  ChiasmusBackend::instance()->config()->entry( QLatin1String("Chiasmus"), QLatin1String("General"), QLatin1String("keydir") );
62  assert( keypaths );
63  mKeyPaths = QStringList( keypaths->urlValue().path() );
64 }
65 
66 Kleo::ObtainKeysJob::~ObtainKeysJob() {}
67 
68 GpgME::Error Kleo::ObtainKeysJob::start() {
69  QTimer::singleShot( 0, this, SLOT(slotPerform()) );
70  return mError = GpgME::Error();
71 }
72 
73 GpgME::Error Kleo::ObtainKeysJob::exec() {
74  slotPerform( false );
75  return mError;
76 }
77 
78 void Kleo::ObtainKeysJob::slotCancel() {
79  mCanceled = true;
80 }
81 
82 void Kleo::ObtainKeysJob::slotPerform() {
83  slotPerform( true );
84 }
85 
86 void Kleo::ObtainKeysJob::slotPerform( bool async ) {
87  if ( mCanceled && !mError )
88  mError = GpgME::Error::fromCode( GPG_ERR_CANCELED );
89  if ( int(mIndex) >= mKeyPaths.size() || mError ) {
90  emit done();
91  emit SpecialJob::result( mError, QVariant( mResult ) );
92  return;
93  }
94 
95  emit progress( i18n( "Scanning directory %1...", mKeyPaths[mIndex] ),
96  mIndex, mKeyPaths.size() );
97 
98  const QDir dir( KShell::tildeExpand( mKeyPaths[mIndex] ) );
99 
100  const QFileInfoList xisFiles = dir.entryInfoList( QStringList()<< QLatin1String("*.xis;*.XIS" ), QDir::Files );
101  for ( QFileInfoList::const_iterator it = xisFiles.begin(), end = xisFiles.end() ; it != end ; ++it )
102  if ( (*it).isReadable() )
103  mResult.push_back( (*it).absoluteFilePath() );
104 
105  ++mIndex;
106 
107  if ( async )
108  QTimer::singleShot( 0, this, SLOT(slotPerform()) );
109  else
110  slotPerform( false );
111 }
112 
113 void Kleo::ObtainKeysJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
114  if ( !mError )
115  return;
116  if ( mError.isCanceled() )
117  return;
118  const QString msg = QString::fromLocal8Bit( mError.asString() );
119  KMessageBox::error( parent, msg, caption );
120 }
121 
122 #include "obtainkeysjob.moc"
obtainkeysjob.h
Kleo::ChiasmusBackend::instance
static const ChiasmusBackend * instance()
Definition: chiasmusbackend.h:52
QWidget
Kleo::SpecialJob
An abstract base class for protocol-specific jobs.
Definition: specialjob.h:65
QString
QObject
Kleo::ObtainKeysJob::showErrorDialog
void showErrorDialog(QWidget *, const QString &) const
Definition: obtainkeysjob.cpp:113
Kleo::ChiasmusBackend::config
Kleo::CryptoConfig * config() const
Definition: chiasmusbackend.cpp:443
Kleo::ObtainKeysJob::slotCancel
void slotCancel()
Definition: obtainkeysjob.cpp:78
cryptoconfig.h
Kleo::ObtainKeysJob::start
GpgME::Error start()
Definition: obtainkeysjob.cpp:68
Kleo::ObtainKeysJob::exec
GpgME::Error exec()
Definition: obtainkeysjob.cpp:73
chiasmusbackend.h
Kleo::ObtainKeysJob::ObtainKeysJob
ObtainKeysJob(QObject *parent=0)
Definition: obtainkeysjob.cpp:53
Kleo::ObtainKeysJob::~ObtainKeysJob
~ObtainKeysJob()
Definition: obtainkeysjob.cpp:66
Kleo::SpecialJob::result
void result(const GpgME::Error &result, const QVariant &data)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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