• 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
commands/command.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/command.cpp
3 
4  This file 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 file, you may extend this exception to
28  your version of the file, 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 "command.h"
36 #include "command_p.h"
37 
38 #include <view/tabwidget.h>
39 
40 #include <kdebug.h>
41 #include <KWindowSystem>
42 
43 #include <QAbstractItemView>
44 
45 using namespace Kleo;
46 using namespace GpgME;
47 
48 Command::Private::Private( Command * qq, KeyListController * controller )
49  : q( qq ),
50  autoDelete( true ),
51  warnWhenRunningAtShutdown( true ),
52  indexes_(),
53  view_(),
54  parentWId( 0 ),
55  controller_( controller )
56 {
57 
58 }
59 
60 Command::Private::~Private() { kDebug(); }
61 
62 Command::Command( KeyListController * p )
63  : QObject( p ), d( new Private( this, p ) )
64 {
65  if ( p )
66  p->registerCommand( this );
67 }
68 
69 Command::Command( QAbstractItemView * v, KeyListController * p )
70  : QObject( p ), d( new Private( this, p ) )
71 {
72  if ( p )
73  p->registerCommand( this );
74  if ( v )
75  setView( v );
76 }
77 
78 Command::Command( Private * pp )
79  : QObject( pp->controller_ ), d( pp )
80 {
81  if ( pp->controller_ )
82  pp->controller_->registerCommand( this );
83 }
84 
85 Command::Command( QAbstractItemView * v, Private * pp )
86  : QObject( pp->controller_ ), d( pp )
87 {
88  if ( pp->controller_ )
89  pp->controller_->registerCommand( this );
90  if ( v )
91  setView( v );
92 }
93 
94 Command::Command( const Key & key )
95  : QObject( 0 ), d( new Private( this, 0 ) )
96 {
97  d->keys_ = std::vector<Key>( 1, key );
98 }
99 
100 Command::Command( const std::vector<Key> & keys )
101  : QObject( 0 ), d( new Private( this, 0 ) )
102 {
103  d->keys_ = keys;
104 }
105 
106 Command::Command( const Key & key, Private * pp )
107  : QObject( 0 ), d( pp )
108 {
109  d->keys_ = std::vector<Key>( 1, key );
110 }
111 
112 Command::Command( const std::vector<Key> & keys, Private * pp )
113  : QObject( 0 ), d( pp )
114 {
115  d->keys_ = keys;
116 }
117 
118 Command::~Command() { kDebug(); }
119 
120 void Command::setAutoDelete( bool on ) {
121  d->autoDelete = on;
122 }
123 
124 bool Command::autoDelete() const {
125  return d->autoDelete;
126 }
127 
128 void Command::setWarnWhenRunningAtShutdown( bool on ) {
129  d->warnWhenRunningAtShutdown = on;
130 }
131 
132 bool Command::warnWhenRunningAtShutdown() const {
133  return d->warnWhenRunningAtShutdown;
134 }
135 
136 void Command::setParentWidget( QWidget * widget ) {
137  d->parentWidget_ = widget;
138 }
139 
140 void Command::setParentWId( WId wid ) {
141  d->parentWId = wid;
142 }
143 
144 void Command::setView( QAbstractItemView * view ) {
145  if ( view == d->view_ )
146  return;
147  d->view_ = view;
148  if ( !view || !d->indexes_.empty() )
149  return;
150  const QItemSelectionModel * const sm = view->selectionModel();
151  if ( !sm ) {
152  kWarning() << "view " << ( void*)view << " has no selectionModel!";
153  return;
154  }
155  const QList<QModelIndex> selected = sm->selectedRows();
156  if ( !selected.empty() ) {
157  std::copy( selected.begin(), selected.end(), std::back_inserter( d->indexes_ ) );
158  return;
159  }
160 }
161 
162 void Command::setIndex( const QModelIndex & idx ) {
163  d->indexes_.clear();
164  d->indexes_.push_back( idx );
165 }
166 
167 void Command::setIndexes( const QList<QModelIndex> & idx ) {
168  d->indexes_.clear();
169  std::copy( idx.begin(), idx.end(), std::back_inserter( d->indexes_ ) );
170 }
171 
172 void Command::setKey( const Key & key ) {
173  d->keys_.clear();
174  if ( !key.isNull() )
175  d->keys_.push_back( key );
176 }
177 
178 void Command::setKeys( const std::vector<Key> & keys ) {
179  d->keys_ = keys;
180 }
181 
182 void Command::start() {
183  doStart();
184 }
185 
186 void Command::cancel() {
187  kDebug();
188  doCancel();
189  emit canceled();
190 }
191 
192 void Command::addTemporaryView( const QString & title, AbstractKeyListSortFilterProxyModel * proxy, const QString & tabToolTip ) {
193  if ( TabWidget * const tw = d->controller_ ? d->controller_->tabWidget() : 0 )
194  if ( QAbstractItemView * const v = tw->addTemporaryView( title, proxy, tabToolTip ) )
195  setView( v );
196 }
197 
198 void Command::applyWindowID( QWidget * w ) const {
199  if ( w )
200  if ( d->parentWId )
201  if ( QWidget * pw = QWidget::find( d->parentWId ) )
202  w->setParent( pw, w->windowFlags() );
203  else
204  KWindowSystem::setMainWindow( w, d->parentWId );
205  else
206  w->setParent( d->parentWidgetOrView(), w->windowFlags() );
207 }
208 
209 //#include "moc_command.cpp"
210 #include "command.moc" // the above clashes with libkleopatra/core/command.cpp, since CMake/Automoc4 is too stupid to handle that situation
211 
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::TabWidget
Definition: tabwidget.h:56
Kleo::KeyListController
Definition: keylistcontroller.h:55
QWidget
Kleo::Command::autoDelete
bool autoDelete() const
Definition: commands/command.cpp:124
Kleo::Command::addTemporaryView
void addTemporaryView(const QString &title, AbstractKeyListSortFilterProxyModel *proxy=0, const QString &tabToolTip=QString())
Definition: commands/command.cpp:192
Kleo::Command::start
void start()
Definition: commands/command.cpp:182
Kleo::Command::~Command
~Command()
Definition: commands/command.cpp:118
Kleo::Command::setAutoDelete
void setAutoDelete(bool on)
Definition: commands/command.cpp:120
Kleo::Command::setView
void setView(QAbstractItemView *view)
Definition: commands/command.cpp:144
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
Kleo::Command::warnWhenRunningAtShutdown
bool warnWhenRunningAtShutdown() const
Definition: commands/command.cpp:132
Kleo::Command::setKeys
void setKeys(const std::vector< GpgME::Key > &keys)
Definition: commands/command.cpp:178
Kleo::Command::Private::parentWidgetOrView
QWidget * parentWidgetOrView() const
Definition: commands/command_p.h:61
d
#define d
Definition: adduseridcommand.cpp:90
tabwidget.h
Kleo::Command::setIndexes
void setIndexes(const QList< QModelIndex > &idx)
Definition: commands/command.cpp:167
Kleo::Command::Private::~Private
virtual ~Private()
Definition: commands/command.cpp:60
Kleo::Command::setParentWId
void setParentWId(WId wid)
Definition: commands/command.cpp:140
Kleo::KeyListController::registerCommand
void registerCommand(Command *cmd)
Definition: keylistcontroller.cpp:463
Kleo::AbstractKeyListSortFilterProxyModel
Definition: keylistsortfilterproxymodel.h:51
Kleo::Command::setIndex
void setIndex(const QModelIndex &idx)
Definition: commands/command.cpp:162
Kleo::Command::cancel
void cancel()
Definition: commands/command.cpp:186
Kleo::Command::setKey
void setKey(const GpgME::Key &key)
Definition: commands/command.cpp:172
Kleo::Command::setWarnWhenRunningAtShutdown
void setWarnWhenRunningAtShutdown(bool warn)
Definition: commands/command.cpp:128
command_p.h
Kleo::Command::Command
Command(KeyListController *parent)
Definition: commands/command.cpp:62
Kleo::Command::canceled
void canceled()
command.h
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::Command::setParentWidget
void setParentWidget(QWidget *widget)
Definition: commands/command.cpp:136
Kleo::Command::Private::Private
Private(Command *qq, KeyListController *controller)
Definition: commands/command.cpp:48
Kleo::Command
Definition: commands/command.h:58
QList
Definition: commands/command.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:40 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