kleopatra
command.cpp
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 #include <config-kleopatra.h>
00034
00035 #include "command.h"
00036 #include "command_p.h"
00037
00038 #include <view/tabwidget.h>
00039
00040 #include <kdebug.h>
00041
00042 #include <QAbstractItemView>
00043
00044 using namespace Kleo;
00045 using namespace GpgME;
00046
00047 Command::Private::Private( Command * qq, KeyListController * controller )
00048 : q( qq ),
00049 autoDelete( true ),
00050 warnWhenRunningAtShutdown( true ),
00051 indexes_(),
00052 view_(),
00053 controller_( controller )
00054 {
00055
00056 }
00057
00058 Command::Private::~Private() { kDebug(); }
00059
00060 Command::Command( KeyListController * p )
00061 : QObject( p ), d( new Private( this, p ) )
00062 {
00063 if ( p )
00064 p->registerCommand( this );
00065 }
00066
00067 Command::Command( QAbstractItemView * v, KeyListController * p )
00068 : QObject( p ), d( new Private( this, p ) )
00069 {
00070 if ( p )
00071 p->registerCommand( this );
00072 if ( v )
00073 setView( v );
00074 }
00075
00076 Command::Command( Private * pp )
00077 : QObject( pp->controller_ ), d( pp )
00078 {
00079 if ( pp->controller_ )
00080 pp->controller_->registerCommand( this );
00081 }
00082
00083 Command::Command( QAbstractItemView * v, Private * pp )
00084 : QObject( pp->controller_ ), d( pp )
00085 {
00086 if ( pp->controller_ )
00087 pp->controller_->registerCommand( this );
00088 if ( v )
00089 setView( v );
00090 }
00091
00092 Command::Command( const Key & key )
00093 : QObject( 0 ), d( new Private( this, 0 ) )
00094 {
00095 d->keys_ = std::vector<Key>( 1, key );
00096 }
00097
00098 Command::Command( const std::vector<Key> & keys )
00099 : QObject( 0 ), d( new Private( this, 0 ) )
00100 {
00101 d->keys_ = keys;
00102 }
00103
00104 Command::Command( const Key & key, Private * pp )
00105 : QObject( 0 ), d( pp )
00106 {
00107 d->keys_ = std::vector<Key>( 1, key );
00108 }
00109
00110 Command::Command( const std::vector<Key> & keys, Private * pp )
00111 : QObject( 0 ), d( pp )
00112 {
00113 d->keys_ = keys;
00114 }
00115
00116 Command::~Command() { kDebug(); }
00117
00118 void Command::setAutoDelete( bool on ) {
00119 d->autoDelete = on;
00120 }
00121
00122 bool Command::autoDelete() const {
00123 return d->autoDelete;
00124 }
00125
00126 void Command::setWarnWhenRunningAtShutdown( bool on ) {
00127 d->warnWhenRunningAtShutdown = on;
00128 }
00129
00130 bool Command::warnWhenRunningAtShutdown() const {
00131 return d->warnWhenRunningAtShutdown;
00132 }
00133
00134 void Command::setParentWidget( QWidget * widget ) {
00135 d->parentWidget_ = widget;
00136 }
00137
00138 void Command::setView( QAbstractItemView * view ) {
00139 if ( view == d->view_ )
00140 return;
00141 d->view_ = view;
00142 if ( !view || !d->indexes_.empty() )
00143 return;
00144 const QItemSelectionModel * const sm = view->selectionModel();
00145 if ( !sm ) {
00146 qWarning( "Command::setView: view %p has no selectionModel!", view );
00147 return;
00148 }
00149 const QList<QModelIndex> selected = sm->selectedRows();
00150 if ( !selected.empty() ) {
00151 std::copy( selected.begin(), selected.end(), std::back_inserter( d->indexes_ ) );
00152 return;
00153 }
00154 }
00155
00156 void Command::setIndex( const QModelIndex & idx ) {
00157 d->indexes_.clear();
00158 d->indexes_.push_back( idx );
00159 }
00160
00161 void Command::setIndexes( const QList<QModelIndex> & idx ) {
00162 d->indexes_.clear();
00163 std::copy( idx.begin(), idx.end(), std::back_inserter( d->indexes_ ) );
00164 }
00165
00166 void Command::setKey( const Key & key ) {
00167 d->keys_.clear();
00168 if ( !key.isNull() )
00169 d->keys_.push_back( key );
00170 }
00171
00172 void Command::setKeys( const std::vector<Key> & keys ) {
00173 d->keys_ = keys;
00174 }
00175
00176 void Command::start() {
00177 doStart();
00178 }
00179
00180 void Command::cancel() {
00181 kDebug();
00182 doCancel();
00183 emit canceled();
00184 }
00185
00186 void Command::addTemporaryView( const QString & title, AbstractKeyListSortFilterProxyModel * proxy ) {
00187 if ( TabWidget * const tw = d->controller_ ? d->controller_->tabWidget() : 0 )
00188 if ( QAbstractItemView * const v = tw->addTemporaryView( title, proxy ) )
00189 setView( v );
00190 }
00191
00192
00193 #include "command.moc"
00194