kleopatra
assuancommand.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __KLEOPATRA_UISERVER_ASSUANCOMMAND_H__
00034 #define __KLEOPATRA_UISERVER_ASSUANCOMMAND_H__
00035
00036 #include <crypto/controller.h>
00037
00038 #include <utils/pimpl_ptr.h>
00039
00040 #include <gpgme++/global.h>
00041 #include <gpgme++/error.h>
00042
00043 #include <kmime/kmime_header_parsing.h>
00044
00045 #include <boost/shared_ptr.hpp>
00046 #include <boost/enable_shared_from_this.hpp>
00047
00048 #include <string>
00049 #include <map>
00050 #include <vector>
00051
00052 class QVariant;
00053 class QIODevice;
00054 class QObject;
00055 class QStringList;
00056 class QDialog;
00057 class QFile;
00058
00059 struct assuan_context_s;
00060
00061 namespace Kleo {
00062
00063 class Input;
00064 class Output;
00065
00066 class AssuanCommandFactory;
00067
00208 class AssuanCommand : public Crypto::ExecutionContext, public boost::enable_shared_from_this<AssuanCommand> {
00209
00210 public:
00211 AssuanCommand();
00212 virtual ~AssuanCommand();
00213
00214 int start();
00215 void canceled();
00216
00217 virtual const char * name() const = 0;
00218
00219 class Memento {
00220 public:
00221 virtual ~Memento() {}
00222 };
00223
00224 template <typename T>
00225 class TypedMemento : public Memento {
00226 T m_t;
00227 public:
00228 explicit TypedMemento( const T & t ) : m_t( t ) {}
00229
00230 const T & get() const { return m_t; }
00231 T & get() { return m_t; }
00232 };
00233
00234 template <typename T>
00235 static boost::shared_ptr< TypedMemento<T> > make_typed_memento( const T & t ) {
00236 return boost::shared_ptr< TypedMemento<T> >( new TypedMemento<T>( t ) );
00237 }
00238
00239 static int makeError( int code );
00240
00241
00242 enum Mode { NoMode, EMail, FileManager };
00243 Mode checkMode() const;
00244
00245 enum CheckProtocolOption {
00246 AllowProtocolMissing=0x01
00247 };
00248
00249 GpgME::Protocol checkProtocol( Mode mode, int options=0 ) const;
00250
00251 void applyWindowID( QWidget* w ) const {
00252 doApplyWindowID( w );
00253 }
00254
00255 QString heuristicBaseDirectory() const;
00256
00257 void setNohup( bool on );
00258 bool isNohup() const;
00259 bool isDone() const;
00260
00261 QString sessionTitle() const;
00262
00263 bool informativeRecipients() const;
00264 bool informativeSenders() const;
00265
00266 const std::vector<KMime::Types::Mailbox> & recipients() const;
00267 const std::vector<KMime::Types::Mailbox> & senders() const;
00268
00269 bool hasMemento( const QByteArray & tag ) const;
00270 boost::shared_ptr<Memento> memento( const QByteArray & tag ) const;
00271 template <typename T>
00272 boost::shared_ptr<T> mementoAs( const QByteArray & tag ) const {
00273 return boost::dynamic_pointer_cast<T>( this->memento( tag ) );
00274 }
00275 const std::map< QByteArray, boost::shared_ptr<Memento> > & mementos() const;
00276 QByteArray registerMemento( const boost::shared_ptr<Memento> & mem );
00277 QByteArray registerMemento( const QByteArray & tag, const boost::shared_ptr<Memento> & mem );
00278 void removeMemento( const QByteArray & tag );
00279 template <typename T>
00280 T mementoContent( const QByteArray & tag ) const {
00281 if ( boost::shared_ptr< TypedMemento<T> > m = mementoAs< TypedMemento<T> >( tag ) )
00282 return m->get();
00283 else
00284 return T();
00285 }
00286
00287 bool hasOption( const char * opt ) const;
00288 QVariant option( const char * opt ) const;
00289 const std::map<std::string,QVariant> & options() const;
00290
00291 const std::vector< boost::shared_ptr<Input> > & inputs() const;
00292 const std::vector< boost::shared_ptr<Input> > & messages() const;
00293 const std::vector< boost::shared_ptr<Output> > & outputs() const;
00294
00295 QStringList fileNames() const;
00296 std::vector< boost::shared_ptr<QFile> > files() const;
00297 unsigned int numFiles() const;
00298
00299 void sendStatus( const char * keyword, const QString & text );
00300 void sendStatusEncoded( const char * keyword, const std::string & text );
00301 void sendData( const QByteArray & data, bool moreToCome=false );
00302
00303 int inquire( const char * keyword, QObject * receiver, const char * slot, unsigned int maxSize=0 );
00304
00305 void done( const GpgME::Error& err = GpgME::Error() );
00306 void done( const GpgME::Error& err, const QString & details );
00307 void done( int err ) { done( GpgME::Error(err) ); }
00308 void done( int err, const QString & details ) { done( GpgME::Error(err), details ); }
00309
00310 private:
00311 virtual void doCanceled() = 0;
00312 virtual int doStart() = 0;
00313
00314 private:
00315 void doApplyWindowID( QWidget * w ) const;
00316
00317 private:
00318 friend class ::Kleo::AssuanCommandFactory;
00319 class Private;
00320 kdtools::pimpl_ptr<Private> d;
00321 };
00322
00323 class AssuanCommandFactory {
00324 public:
00325 virtual ~AssuanCommandFactory() {}
00326
00327 virtual boost::shared_ptr<AssuanCommand> create() const = 0;
00328 virtual const char * name() const = 0;
00329
00330 typedef int(*_Handler)( assuan_context_s*, char *);
00331 virtual _Handler _handler() const = 0;
00332 protected:
00333 static int _handle( assuan_context_s*, char *, const char * );
00334 };
00335
00336 template <typename Command>
00337 class GenericAssuanCommandFactory : public AssuanCommandFactory {
00338 AssuanCommandFactory::_Handler _handler() const { return &GenericAssuanCommandFactory::_handle; }
00339 static int _handle( assuan_context_s* _ctx, char * _line ) {
00340 return AssuanCommandFactory::_handle( _ctx, _line, Command::staticName() );
00341 }
00342 boost::shared_ptr<AssuanCommand> create() const { return make(); }
00343 const char * name() const { return Command::staticName(); }
00344 public:
00345 static boost::shared_ptr<Command> make() { return boost::shared_ptr<Command>( new Command ); }
00346 };
00347
00348 template <typename Derived, typename Base=AssuanCommand>
00349 class AssuanCommandMixin : public Base {
00350 protected:
00351 const char * name() const { return Derived::staticName(); }
00352 };
00353
00354 }
00355
00356 #endif