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

kleopatra

encryptclipboardcommand.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset:4 -*-
00002     commands/encryptclipboardcommand.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2008 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #include <config-kleopatra.h>
00034 
00035 #include "encryptclipboardcommand.h"
00036 
00037 #include "command_p.h"
00038 
00039 #include <crypto/encryptemailcontroller.h>
00040 
00041 #include <utils/input.h>
00042 #include <utils/output.h>
00043 
00044 #include <KLocale>
00045 #include <KMessageBox>
00046 #include <kdebug.h>
00047 
00048 #include <QApplication>
00049 #include <QClipboard>
00050 #include <QMimeData>
00051 
00052 #include <exception>
00053 
00054 using namespace Kleo;
00055 using namespace Kleo::Commands;
00056 using namespace Kleo::Crypto;
00057 using namespace boost;
00058 
00059 namespace {
00060     struct nodelete {
00061         template <typename T>
00062         void operator()( const T * ) const {}
00063     };
00064 }
00065 
00066 class EncryptClipboardCommand::Private : public Command::Private {
00067     friend class ::Kleo::Commands::EncryptClipboardCommand;
00068     EncryptClipboardCommand * q_func() const { return static_cast<EncryptClipboardCommand*>( q ); }
00069 public:
00070     explicit Private( EncryptClipboardCommand * qq, KeyListController * c );
00071     ~Private();
00072 
00073     void init();
00074 
00075 private:
00076     void slotRecipientsResolved();
00077     void slotControllerDone() {
00078         finished();
00079     }
00080     void slotControllerError( int, const QString & ) {
00081         finished();
00082     }
00083 
00084 private:
00085     shared_ptr<const ExecutionContext> shared_qq;
00086     shared_ptr<Input> input;
00087     EncryptEMailController controller;
00088 };
00089 
00090 
00091 EncryptClipboardCommand::Private * EncryptClipboardCommand::d_func() { return static_cast<Private*>( d.get() ); }
00092 const EncryptClipboardCommand::Private * EncryptClipboardCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
00093 
00094 #define d d_func()
00095 #define q q_func()
00096 
00097 EncryptClipboardCommand::Private::Private( EncryptClipboardCommand * qq, KeyListController * c )
00098     : Command::Private( qq, c ),
00099       shared_qq( qq, nodelete() ),
00100       input(),
00101       controller( EncryptEMailController::ClipboardMode )
00102 {
00103 
00104 }
00105 
00106 EncryptClipboardCommand::Private::~Private() { kDebug(); }
00107 
00108 EncryptClipboardCommand::EncryptClipboardCommand( KeyListController * c )
00109     : Command( new Private( this, c ) )
00110 {
00111     d->init();
00112 }
00113 
00114 EncryptClipboardCommand::EncryptClipboardCommand( QAbstractItemView * v, KeyListController * c )
00115     : Command( v, new Private( this, c ) )
00116 {
00117     d->init();
00118 }
00119 
00120 void EncryptClipboardCommand::Private::init() {
00121     controller.setExecutionContext( shared_qq );
00122     connect( &controller, SIGNAL(done()), q, SLOT(slotControllerDone()) );
00123     connect( &controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString)) );
00124 }
00125 
00126 EncryptClipboardCommand::~EncryptClipboardCommand() { kDebug(); }
00127 
00128 // static
00129 bool EncryptClipboardCommand::canEncryptCurrentClipboard() {
00130     if ( const QClipboard * clip = QApplication::clipboard() )
00131         if ( const QMimeData * mime = clip->mimeData() )
00132             return mime->hasText();
00133     return false;
00134 }
00135 
00136 void EncryptClipboardCommand::doStart() {
00137 
00138     try {
00139 
00140         // snapshot clipboard content here, in case it's being changed...
00141         d->input = Input::createFromClipboard();
00142 
00143         connect( &d->controller, SIGNAL(recipientsResolved()),
00144                  this, SLOT(slotRecipientsResolved()) );
00145 
00146         d->controller.startResolveRecipients();
00147 
00148     } catch ( const std::exception & e ) {
00149         KMessageBox::information( d->view(),
00150                                   i18n("An error occurred: %1",
00151                                        QString::fromLocal8Bit( e.what() ) ),
00152                                   i18n("Encrypt Clipboard Error") );
00153         d->finished();
00154     }
00155 }
00156 
00157 void EncryptClipboardCommand::Private::slotRecipientsResolved() {
00158     try {
00159         controller.setInputAndOutput( input, Output::createFromClipboard() );
00160         input.reset(); // no longer needed, so don't keep a reference
00161         controller.start();
00162     } catch ( const std::exception & e ) {
00163         KMessageBox::information( view(),
00164                                   i18n("An error occurred: %1",
00165                                        QString::fromLocal8Bit( e.what() ) ),
00166                                   i18n("Encrypt Clipboard Error") );
00167         finished();
00168     }
00169 }
00170 
00171 void EncryptClipboardCommand::doCancel() {
00172     kDebug();
00173     d->controller.cancel();
00174 }
00175 
00176 void EncryptClipboardCommand::applyWindowID( QWidget * wid ) const {
00177     if ( wid )
00178         wid->setParent( d->view(), wid->windowFlags() );
00179 }
00180 
00181 #undef d
00182 #undef q
00183 
00184 #include "moc_encryptclipboardcommand.cpp"

kleopatra

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal