Page MenuHome GnuPG

No OneTemporary

diff --git a/commands/command.cpp b/commands/command.cpp
index 8cac775d1..a92ad8091 100644
--- a/commands/command.cpp
+++ b/commands/command.cpp
@@ -1,194 +1,194 @@
/* -*- mode: c++; c-basic-offset:4 -*-
commands/command.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2007 Klarälvdalens Datakonsult AB
Kleopatra is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include <config-kleopatra.h>
#include "command.h"
#include "command_p.h"
#include <view/tabwidget.h>
#include <kdebug.h>
#include <QAbstractItemView>
using namespace Kleo;
using namespace GpgME;
Command::Private::Private( Command * qq, KeyListController * controller )
: q( qq ),
autoDelete( true ),
warnWhenRunningAtShutdown( true ),
indexes_(),
view_(),
controller_( controller )
{
}
Command::Private::~Private() { kDebug(); }
Command::Command( KeyListController * p )
: QObject( p ), d( new Private( this, p ) )
{
if ( p )
p->registerCommand( this );
}
Command::Command( QAbstractItemView * v, KeyListController * p )
: QObject( p ), d( new Private( this, p ) )
{
if ( p )
p->registerCommand( this );
if ( v )
setView( v );
}
Command::Command( Private * pp )
: QObject( pp->controller_ ), d( pp )
{
if ( pp->controller_ )
pp->controller_->registerCommand( this );
}
Command::Command( QAbstractItemView * v, Private * pp )
: QObject( pp->controller_ ), d( pp )
{
if ( pp->controller_ )
pp->controller_->registerCommand( this );
if ( v )
setView( v );
}
Command::Command( const Key & key )
: QObject( 0 ), d( new Private( this, 0 ) )
{
d->keys_ = std::vector<Key>( 1, key );
}
Command::Command( const std::vector<Key> & keys )
: QObject( 0 ), d( new Private( this, 0 ) )
{
d->keys_ = keys;
}
Command::Command( const Key & key, Private * pp )
: QObject( 0 ), d( pp )
{
d->keys_ = std::vector<Key>( 1, key );
}
Command::Command( const std::vector<Key> & keys, Private * pp )
: QObject( 0 ), d( pp )
{
d->keys_ = keys;
}
Command::~Command() { kDebug(); }
void Command::setAutoDelete( bool on ) {
d->autoDelete = on;
}
bool Command::autoDelete() const {
return d->autoDelete;
}
void Command::setWarnWhenRunningAtShutdown( bool on ) {
d->warnWhenRunningAtShutdown = on;
}
bool Command::warnWhenRunningAtShutdown() const {
return d->warnWhenRunningAtShutdown;
}
void Command::setParentWidget( QWidget * widget ) {
d->parentWidget_ = widget;
}
void Command::setView( QAbstractItemView * view ) {
if ( view == d->view_ )
return;
d->view_ = view;
if ( !view || !d->indexes_.empty() )
return;
const QItemSelectionModel * const sm = view->selectionModel();
if ( !sm ) {
qWarning( "Command::setView: view %p has no selectionModel!", ( void* )view );
return;
}
const QList<QModelIndex> selected = sm->selectedRows();
if ( !selected.empty() ) {
std::copy( selected.begin(), selected.end(), std::back_inserter( d->indexes_ ) );
return;
}
}
void Command::setIndex( const QModelIndex & idx ) {
d->indexes_.clear();
d->indexes_.push_back( idx );
}
void Command::setIndexes( const QList<QModelIndex> & idx ) {
d->indexes_.clear();
std::copy( idx.begin(), idx.end(), std::back_inserter( d->indexes_ ) );
}
void Command::setKey( const Key & key ) {
d->keys_.clear();
if ( !key.isNull() )
d->keys_.push_back( key );
}
void Command::setKeys( const std::vector<Key> & keys ) {
d->keys_ = keys;
}
void Command::start() {
doStart();
}
void Command::cancel() {
kDebug();
doCancel();
emit canceled();
}
-void Command::addTemporaryView( const QString & title, AbstractKeyListSortFilterProxyModel * proxy ) {
+void Command::addTemporaryView( const QString & title, AbstractKeyListSortFilterProxyModel * proxy, const QString & tabToolTip ) {
if ( TabWidget * const tw = d->controller_ ? d->controller_->tabWidget() : 0 )
- if ( QAbstractItemView * const v = tw->addTemporaryView( title, proxy ) )
+ if ( QAbstractItemView * const v = tw->addTemporaryView( title, proxy, tabToolTip ) )
setView( v );
}
//#include "moc_command.cpp"
#include "command.moc" // the above clashes with libkleopatra/core/command.cpp, since CMake/Automoc4 is too stupid to handle that situation
diff --git a/commands/command.h b/commands/command.h
index c838b60cc..a6f9e1812 100644
--- a/commands/command.h
+++ b/commands/command.h
@@ -1,128 +1,128 @@
/* -*- mode: c++; c-basic-offset:4 -*-
commands/command.h
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2007 Klarälvdalens Datakonsult AB
Kleopatra is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifndef __KLEOPATRA_COMMANDS_COMMAND_H__
#define __KLEOPATRA_COMMANDS_COMMAND_H__
#include <QObject>
#include <utils/pimpl_ptr.h>
#include <vector>
class QModelIndex;
template <typename T> class QList;
class QAbstractItemView;
namespace GpgME {
class Key;
}
namespace Kleo {
class KeyListController;
class AbstractKeyListSortFilterProxyModel;
class Command : public QObject {
Q_OBJECT
public:
explicit Command( KeyListController * parent );
explicit Command( QAbstractItemView * view, KeyListController * parent );
explicit Command( const GpgME::Key & key );
explicit Command( const std::vector<GpgME::Key> & keys );
~Command();
enum Restriction {
NoRestriction = 0,
NeedSelection = 1,
OnlyOneKey = 2,
NeedSecretKey = 4,
MustNotBeSecretKey = 8,
MustBeOpenPGP = 16,
MustBeCMS = 32,
// esoteric:
MayOnlyBeSecretKeyIfOwnerTrustIsNotYetUltimate = 64, // for set-owner-trust
_AllRestrictions_Helper,
AllRestrictions = 2*(_AllRestrictions_Helper-1) - 1
};
Q_DECLARE_FLAGS( Restrictions, Restriction )
static Restrictions restrictions() { return NoRestriction; }
void setParentWidget( QWidget* widget );
void setView( QAbstractItemView * view );
void setIndex( const QModelIndex & idx );
void setIndexes( const QList<QModelIndex> & idx );
void setKey( const GpgME::Key & key );
void setKeys( const std::vector<GpgME::Key> & keys );
void setAutoDelete( bool on );
bool autoDelete() const;
void setWarnWhenRunningAtShutdown( bool warn );
bool warnWhenRunningAtShutdown() const;
public Q_SLOTS:
void start();
void cancel();
Q_SIGNALS:
void info( const QString & message, int timeout = 0 );
void progress( const QString & message, int current, int total );
void finished();
void canceled();
private:
virtual void doStart() = 0;
virtual void doCancel() = 0;
protected:
- void addTemporaryView( const QString & title, AbstractKeyListSortFilterProxyModel * proxy=0 );
+ void addTemporaryView( const QString & title, AbstractKeyListSortFilterProxyModel * proxy=0, const QString & tabToolTip=QString() );
protected:
class Private;
kdtools::pimpl_ptr<Private> d;
protected:
explicit Command( Private * pp );
explicit Command( QAbstractItemView * view, Private * pp );
explicit Command( const std::vector<GpgME::Key> & keys, Private * pp );
explicit Command( const GpgME::Key & key, Private * pp );
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS( Kleo::Command::Restrictions )
#endif /* __KLEOPATRA_COMMANDS_COMMAND_H__ */
diff --git a/commands/importcertificatescommand.cpp b/commands/importcertificatescommand.cpp
index c122e7e9d..26e58dc5f 100644
--- a/commands/importcertificatescommand.cpp
+++ b/commands/importcertificatescommand.cpp
@@ -1,328 +1,329 @@
/* -*- mode: c++; c-basic-offset:4 -*-
commands/importcertificatescommand.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2007, 2008 Klarälvdalens Datakonsult AB
Kleopatra is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include <config-kleopatra.h>
#include "importcertificatescommand.h"
#include "importcertificatescommand_p.h"
#include <models/keylistsortfilterproxymodel.h>
#include <models/predicates.h>
#include <utils/formatting.h>
#include <kleo/cryptobackendfactory.h>
#include <kleo/importjob.h>
#include <gpgme++/global.h>
#include <gpgme++/importresult.h>
#include <KLocale>
#include <KMessageBox>
#include <KConfigGroup>
#include <KDebug>
#include <QByteArray>
#include <QFile>
#include <QFileDialog>
#include <QPointer>
#include <QString>
#include <QWidget>
#include <QFileInfo>
#include <QTreeView>
#include <memory>
#include <algorithm>
#include <cassert>
using namespace GpgME;
using namespace Kleo;
namespace {
make_comparator_str( ByImportFingerprint, .fingerprint() );
class ImportResultProxyModel : public AbstractKeyListSortFilterProxyModel {
Q_OBJECT
public:
explicit ImportResultProxyModel( const ImportResult & result, QObject * parent=0 )
: AbstractKeyListSortFilterProxyModel( parent ),
m_result()
{
updateFindCache( result );
}
~ImportResultProxyModel() {}
/* reimp */ ImportResultProxyModel * clone() const {
// compiler-generated copy ctor is fine!
return new ImportResultProxyModel( *this );
}
void setImportResult( const ImportResult & result ) {
m_result = result;
updateFindCache( result );
invalidateFilter();
}
protected:
/* reimp */ QVariant data( const QModelIndex & index, int role ) const {
if ( !index.isValid() || role != Qt::ToolTipRole )
return AbstractKeyListSortFilterProxyModel::data( index, role );
// get the fingerprint:
const QModelIndex fprIndex = index.sibling( index.row(), AbstractKeyListModel::Fingerprint );
assert( fprIndex.isValid() );
const QString fpr = fprIndex.data( Qt::EditRole ).toString();
// find information:
const std::vector<Import>::const_iterator it
= qBinaryFind( m_importsByFingerprint.begin(), m_importsByFingerprint.end(),
fpr.toLatin1().constData(),
ByImportFingerprint<std::less>() );
if ( it == m_importsByFingerprint.end() )
return AbstractKeyListSortFilterProxyModel::data( index, role );
else
return Formatting::importMetaData( *it );
}
/* reimp */ bool filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const {
//
// 0. Keep parents of matching children:
//
const QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
assert( index.isValid() );
for ( int i = 0, end = sourceModel()->rowCount( index ) ; i != end ; ++i )
if ( filterAcceptsRow( i, index ) )
return true;
//
// 1. Check that this is an imported key:
//
const QModelIndex fprIndex = sourceModel()->index( source_row, AbstractKeyListModel::Fingerprint, source_parent );
assert( fprIndex.isValid() );
const QString fpr = fprIndex.data( Qt::EditRole ).toString();
return std::binary_search( m_importsByFingerprint.begin(), m_importsByFingerprint.end(),
fpr.toLatin1().constData(),
ByImportFingerprint<std::less>() );
}
private:
void updateFindCache( const ImportResult & result ) {
m_importsByFingerprint.clear();
m_result = result;
m_importsByFingerprint = result.imports();
std::sort( m_importsByFingerprint.begin(), m_importsByFingerprint.end(),
ByImportFingerprint<std::less>() );
}
private:
mutable std::vector<Import> m_importsByFingerprint;
ImportResult m_result;
};
}
ImportCertificatesCommand::Private::Private( ImportCertificatesCommand * qq, KeyListController * c )
: Command::Private( qq, c ), cmsImportJob( 0 ), pgpImportJob( 0 )
{
}
ImportCertificatesCommand::Private::~Private() {}
#define d d_func()
#define q q_func()
ImportCertificatesCommand::ImportCertificatesCommand( KeyListController * p )
: Command( new Private( this, p ) )
{
}
ImportCertificatesCommand::ImportCertificatesCommand( QAbstractItemView * v, KeyListController * p )
: Command( v, new Private( this, p ) )
{
}
ImportCertificatesCommand::~ImportCertificatesCommand() {}
void ImportCertificatesCommand::Private::setImportResultProxyModel( const ImportResult & result, const QString & id ) {
if ( result.imports().empty() )
return;
- q->addTemporaryView( id.isEmpty() ? i18n("Imported Certificates") : i18n( "Imported Certificates from %1", id ), new ImportResultProxyModel( result ) );
+ q->addTemporaryView( i18n("Imported Certificates"), new ImportResultProxyModel( result ),
+ id.isEmpty() ? QString() : i18n( "Imported Certificates from %1", id ) );
if ( QTreeView * const tv = qobject_cast<QTreeView*>( parentWidgetOrView() ) )
tv->expandAll();
}
void ImportCertificatesCommand::Private::showDetails( QWidget * parent, const ImportResult & res, const QString & id ) {
setImportResultProxyModel( res, id );
const KLocalizedString normalLine = ki18n("<tr><td align=\"right\">%1</td><td>%2</td></tr>");
const KLocalizedString boldLine = ki18n("<tr><td align=\"right\"><b>%1</b></td><td>%2</td></tr>");
QStringList lines;
lines.push_back( normalLine.subs( i18n("Total number processed:") )
.subs( res.numConsidered() ).toString() );
lines.push_back( normalLine.subs( i18n("Imported:") )
.subs( res.numImported() ).toString() );
if ( res.newSignatures() )
lines.push_back( normalLine.subs( i18n("New signatures:") )
.subs( res.newSignatures() ).toString() );
if ( res.newUserIDs() )
lines.push_back( normalLine.subs( i18n("New user IDs:") )
.subs( res.newUserIDs() ).toString() );
if ( res.numKeysWithoutUserID() )
lines.push_back( normalLine.subs( i18n("Certificates without user IDs:") )
.subs( res.numKeysWithoutUserID() ).toString() );
if ( res.newSubkeys() )
lines.push_back( normalLine.subs( i18n("New subkeys:") )
.subs( res.newSubkeys() ).toString() );
if ( res.newRevocations() )
lines.push_back( boldLine.subs( i18n("Newly revoked:") )
.subs( res.newRevocations() ).toString() );
if ( res.notImported() )
lines.push_back( boldLine.subs( i18n("Not imported:") )
.subs( res.notImported() ).toString() );
if ( res.numUnchanged() )
lines.push_back( normalLine.subs( i18n("Unchanged:") )
.subs( res.numUnchanged() ).toString() );
if ( res.numSecretKeysConsidered() )
lines.push_back( normalLine.subs( i18n("Secret keys processed:") )
.subs( res.numSecretKeysConsidered() ).toString() );
if ( res.numSecretKeysImported() )
lines.push_back( normalLine.subs( i18n("Secret keys imported:") )
.subs( res.numSecretKeysImported() ).toString() );
if ( res.numSecretKeysConsidered() - res.numSecretKeysImported() - res.numSecretKeysUnchanged() > 0 )
lines.push_back( boldLine.subs( i18n("Secret keys <em>not</em> imported:") )
.subs( res.numSecretKeysConsidered()
- res.numSecretKeysImported()
- res.numSecretKeysUnchanged() ).toString() );
if ( res.numSecretKeysUnchanged() )
lines.push_back( normalLine.subs( i18n("Secret keys unchanged:") )
.subs( res.numSecretKeysUnchanged() ).toString() );
KMessageBox::information( parent,
id.isEmpty()
? i18n( "<qt><p>Detailed results of certificate import:</p>"
"<table>%1</table></qt>",
lines.join( QString() ) )
: i18n( "<qt><p>Detailed results of importing %1:</p>"
"<table>%2</table></qt>" ,
id, lines.join( QString() ) ),
i18n( "Certificate Import Result" ) );
}
void ImportCertificatesCommand::Private::showError( QWidget * parent, const Error & err, const QString & id ) {
assert( err );
assert( !err.isCanceled() );
const QString msg = id.isEmpty()
? i18n( "<qt><p>An error occurred while trying "
"to import the certificate:</p>"
"<p><b>%1</b></p></qt>",
QString::fromLocal8Bit( err.asString() ) )
: i18n( "<qt><p>An error occurred while trying "
"to import the certificate %1:</p>"
"<p><b>%2</b></p></qt>",
id, QString::fromLocal8Bit( err.asString() ) );
KMessageBox::error( parent, msg, i18n( "Certificate Import Failed" ) );
}
void ImportCertificatesCommand::Private::importResult( const ImportResult & result ) {
if ( q->sender() == cmsImportJob )
cmsImportJob = 0;
if ( q->sender() == pgpImportJob )
pgpImportJob = 0;
// ### merge results when gpgme gains copy ctors for result objects
if ( result.error().code() ) {
setImportResultProxyModel( result );
if ( result.error().isCanceled() )
emit q->canceled();
else
showError( result.error() );
}
else
showDetails( result );
finished();
}
void ImportCertificatesCommand::Private::startImport( GpgME::Protocol protocol, const QByteArray & data, const QString & id ) {
assert( protocol != UnknownProtocol );
const Kleo::CryptoBackend::Protocol * const backend = CryptoBackendFactory::instance()->protocol( protocol );
if ( !backend ) {
setImportResultProxyModel( ImportResult(), id );
KMessageBox::error( parentWidgetOrView(),
i18n( "The type of this certificate (%1) is not supported by this Kleopatra installation.",
Formatting::displayName( protocol ) ),
i18n( "Certificate Import Failed" ) );
finished();
return;
}
std::auto_ptr<ImportJob> job( backend->importJob() );
assert( job.get() );
connect( job.get(), SIGNAL(result(GpgME::ImportResult)),
q, SLOT(importResult(GpgME::ImportResult)) );
connect( job.get(), SIGNAL(progress(QString,int,int)),
q, SIGNAL(progress(QString,int,int)) );
if ( const GpgME::Error err = job->start( data ) ) {
setImportResultProxyModel( ImportResult( err ), id );
showError( err, id );
finished();
} else if ( err.isCanceled() ) {
setImportResultProxyModel( ImportResult( err ), id );
emit q->canceled();
finished();
} else {
if ( protocol == CMS )
cmsImportJob = job.release();
else
pgpImportJob = job.release();
}
}
void ImportCertificatesCommand::doCancel() {
if ( d->cmsImportJob )
d->cmsImportJob->slotCancel();
if ( d->pgpImportJob )
d->pgpImportJob->slotCancel();
}
#undef d
#undef q
#include "moc_importcertificatescommand.cpp"
#include "importcertificatescommandc.moc"

File Metadata

Mime Type
text/x-diff
Expires
Fri, Dec 5, 5:47 PM (1 d, 20 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
54/d4/4ef3ee423a8ea00b7f1380e75fbb

Event Timeline