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

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • commands
importcertificatefromclipboardcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  importcertificatefromclipboardcommand.cpp
3 
4  This clipboard is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra 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
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 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 clipboard, you may extend this exception to
28  your version of the clipboard, 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 <config-kleopatra.h>
34 
35 #include "importcertificatefromclipboardcommand.h"
36 
37 #ifndef QT_NO_CLIPBOARD
38 
39 #include "importcertificatescommand_p.h"
40 
41 #include "utils/classify.h"
42 
43 #include <gpgme++/global.h>
44 
45 #include <KLocale>
46 
47 #include <QByteArray>
48 #include <QClipboard>
49 #include <QApplication>
50 #include <QMimeData>
51 
52 using namespace GpgME;
53 using namespace Kleo;
54 
55 class ImportCertificateFromClipboardCommand::Private : public ImportCertificatesCommand::Private {
56  friend class ::ImportCertificateFromClipboardCommand;
57  ImportCertificateFromClipboardCommand * q_func() const { return static_cast<ImportCertificateFromClipboardCommand*>( q ); }
58 public:
59  explicit Private( ImportCertificateFromClipboardCommand * qq, KeyListController * c );
60  ~Private();
61 
62  bool ensureHaveClipboard();
63 
64 private:
65  QByteArray input;
66 };
67 
68 ImportCertificateFromClipboardCommand::Private * ImportCertificateFromClipboardCommand::d_func() { return static_cast<Private*>(d.get()); }
69 const ImportCertificateFromClipboardCommand::Private * ImportCertificateFromClipboardCommand::d_func() const { return static_cast<const Private*>(d.get()); }
70 
71 ImportCertificateFromClipboardCommand::Private::Private( ImportCertificateFromClipboardCommand * qq, KeyListController * c )
72  : ImportCertificatesCommand::Private( qq, c )
73 {
74 
75 }
76 
77 ImportCertificateFromClipboardCommand::Private::~Private() {}
78 
79 // static
80 bool ImportCertificateFromClipboardCommand::canImportCurrentClipboard() {
81  if ( const QClipboard * clip = QApplication::clipboard() )
82  if ( const QMimeData * mime = clip->mimeData() )
83  return mime->hasText()
84  && mayBeAnyCertStoreType( classifyContent( mime->text().toUtf8() ) );
85  return false;
86 }
87 
88 
89 #define d d_func()
90 #define q q_func()
91 
92 
93 ImportCertificateFromClipboardCommand::ImportCertificateFromClipboardCommand( KeyListController * p )
94  : ImportCertificatesCommand( new Private( this, p ) )
95 {
96 
97 }
98 
99 ImportCertificateFromClipboardCommand::ImportCertificateFromClipboardCommand( QAbstractItemView * v, KeyListController * p )
100  : ImportCertificatesCommand( v, new Private( this, p ) )
101 {
102 
103 }
104 
105 ImportCertificateFromClipboardCommand::~ImportCertificateFromClipboardCommand() {}
106 
107 void ImportCertificateFromClipboardCommand::doStart() {
108 
109  if ( !d->ensureHaveClipboard() ) {
110  emit canceled();
111  d->finished();
112  return;
113  }
114 
115  d->setWaitForMoreJobs( true );
116  const unsigned int classification = classifyContent( d->input );
117  if ( !mayBeAnyCertStoreType( classification ) ) {
118  d->error( i18n( "Clipboard contents do not look like a certificate." ),
119  i18n( "Certificate Import Failed" ) );
120  } else {
121  const GpgME::Protocol protocol = findProtocol( classification );
122  if ( protocol == GpgME::UnknownProtocol )
123  d->error( i18n( "Could not determine certificate type of clipboard contents." ), i18n( "Certificate Import Failed" ) );
124  else
125  d->startImport( protocol, d->input, i18n("Clipboard") );
126  }
127  d->setWaitForMoreJobs( false );
128 }
129 
130 bool ImportCertificateFromClipboardCommand::Private::ensureHaveClipboard() {
131  if ( input.isEmpty() )
132  if ( const QClipboard * cb = qApp->clipboard() )
133  input = cb->text().toUtf8();
134  return !input.isEmpty();
135 }
136 
137 #undef d
138 #undef q
139 
140 #include "moc_importcertificatefromclipboardcommand.cpp"
141 
142 #endif // QT_NO_CLIPBOARD
Kleo::ImportCertificatesCommand::Private
Definition: importcertificatescommand_p.h:55
q
#define q
Definition: importcertificatefromclipboardcommand.cpp:90
Kleo::KeyListController
Definition: keylistcontroller.h:55
classify.h
importcertificatescommand_p.h
Kleo::ImportCertificateFromClipboardCommand::canImportCurrentClipboard
static bool canImportCurrentClipboard()
Definition: importcertificatefromclipboardcommand.cpp:80
Kleo::ImportCertificatesCommand
Definition: importcertificatescommand.h:42
Kleo::ImportCertificateFromClipboardCommand
Definition: importcertificatefromclipboardcommand.h:44
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
Kleo::ImportCertificatesCommand::Private::Private
Private(ImportCertificatesCommand *qq, KeyListController *c)
Definition: importcertificatescommand.cpp:163
Kleo::ImportCertificateFromClipboardCommand::ImportCertificateFromClipboardCommand
ImportCertificateFromClipboardCommand(KeyListController *parent)
Definition: importcertificatefromclipboardcommand.cpp:93
Kleo::Command::canceled
void canceled()
d
#define d
Definition: importcertificatefromclipboardcommand.cpp:89
Kleo::classifyContent
unsigned int classifyContent(const QByteArray &data)
Definition: classify.cpp:183
Kleo::ImportCertificateFromClipboardCommand::~ImportCertificateFromClipboardCommand
~ImportCertificateFromClipboardCommand()
Definition: importcertificatefromclipboardcommand.cpp:105
importcertificatefromclipboardcommand.h
Kleo::findProtocol
ProtocolMask FormatMask TypeMask TypeMask TypeMask GpgME::Protocol findProtocol(const unsigned int classifcation)
Definition: classify.h:127
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • 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