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

kleopatra

  • sources
  • kde-4.14
  • kdepim
  • kleopatra
  • crypto
  • gui
decryptverifyoperationwidget.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  uiserver/decryptverifyoperationwidget.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 "decryptverifyoperationwidget.h"
36 
37 #include <utils/archivedefinition.h>
38 
39 #include "libkleo/ui/filenamerequester.h"
40 
41 #include <KLocalizedString>
42 
43 #include <QLabel>
44 #include <QCheckBox>
45 #include <QStackedLayout>
46 #include <QComboBox>
47 
48 #ifndef Q_MOC_RUN
49 #include <boost/shared_ptr.hpp>
50 #endif
51 
52 using namespace Kleo;
53 using namespace Kleo::Crypto::Gui;
54 using namespace boost;
55 
56 class DecryptVerifyOperationWidget::Private {
57  friend class ::Kleo::Crypto::Gui::DecryptVerifyOperationWidget;
58  DecryptVerifyOperationWidget * const q;
59 public:
60  explicit Private( DecryptVerifyOperationWidget * qq );
61  ~Private();
62 
63  void enableDisableWidgets() {
64  const bool detached = ui.verifyDetachedCB.isChecked();
65  const bool archive = ui.archiveCB.isChecked();
66  ui.archiveCB.setEnabled( !detached );
67  ui.archivesCB.setEnabled( archive && !detached );
68  }
69 private:
70  struct UI {
71  QGridLayout glay;
72  QLabel inputLB;
73  QStackedLayout inputStack;
74  QLabel inputFileNameLB;
75  FileNameRequester inputFileNameRQ;
76  //------
77  QCheckBox verifyDetachedCB;
78  //------
79  QLabel signedDataLB;
80  QStackedLayout signedDataStack;
81  QLabel signedDataFileNameLB;
82  FileNameRequester signedDataFileNameRQ;
83  //------
84  QHBoxLayout hlay;
85  QCheckBox archiveCB;
86  QComboBox archivesCB;
87 
88  explicit UI( DecryptVerifyOperationWidget * q );
89  } ui;
90 };
91 
92 DecryptVerifyOperationWidget::Private::UI::UI( DecryptVerifyOperationWidget * q )
93  : glay( q ),
94  inputLB( i18n("Input file:"), q ),
95  inputStack(),
96  inputFileNameLB( q ),
97  inputFileNameRQ( q ),
98  verifyDetachedCB( i18n("&Input file is a detached signature"), q ),
99  signedDataLB( i18n("&Signed data:"), q ),
100  signedDataStack(),
101  signedDataFileNameLB( q ),
102  signedDataFileNameRQ( q ),
103  hlay(),
104  archiveCB( i18n("&Input file is an archive; unpack with:"), q ),
105  archivesCB( q )
106 {
107  KDAB_SET_OBJECT_NAME( glay );
108  KDAB_SET_OBJECT_NAME( inputLB );
109  KDAB_SET_OBJECT_NAME( inputStack );
110  KDAB_SET_OBJECT_NAME( inputFileNameLB );
111  KDAB_SET_OBJECT_NAME( inputFileNameRQ );
112  KDAB_SET_OBJECT_NAME( verifyDetachedCB );
113  KDAB_SET_OBJECT_NAME( signedDataLB );
114  KDAB_SET_OBJECT_NAME( signedDataStack );
115  KDAB_SET_OBJECT_NAME( signedDataFileNameLB );
116  KDAB_SET_OBJECT_NAME( signedDataFileNameRQ );
117  KDAB_SET_OBJECT_NAME( hlay );
118  KDAB_SET_OBJECT_NAME( archiveCB );
119  KDAB_SET_OBJECT_NAME( archivesCB );
120 
121  inputStack.setMargin( 0 );
122  signedDataStack.setMargin( 0 );
123 
124  signedDataLB.setEnabled( false );
125  signedDataFileNameLB.setEnabled( false );
126  signedDataFileNameRQ.setEnabled( false );
127  archivesCB.setEnabled( false );
128 
129  glay.setMargin( 0 );
130  glay.addWidget( &inputLB, 0, 0 );
131  glay.addLayout( &inputStack, 0, 1 );
132  inputStack.addWidget( &inputFileNameLB );
133  inputStack.addWidget( &inputFileNameRQ );
134 
135  glay.addWidget( &verifyDetachedCB, 1, 0, 1, 2 );
136 
137  glay.addWidget( &signedDataLB, 2, 0 );
138  glay.addLayout( &signedDataStack, 2, 1 );
139  signedDataStack.addWidget( &signedDataFileNameLB );
140  signedDataStack.addWidget( &signedDataFileNameRQ );
141 
142  glay.addLayout( &hlay, 3, 0, 1, 2 );
143  hlay.addWidget( &archiveCB );
144  hlay.addWidget( &archivesCB, 1 );
145 
146  connect( &verifyDetachedCB, SIGNAL(toggled(bool)),
147  &signedDataLB, SLOT(setEnabled(bool)) );
148  connect( &verifyDetachedCB, SIGNAL(toggled(bool)),
149  &signedDataFileNameLB, SLOT(setEnabled(bool)) );
150  connect( &verifyDetachedCB, SIGNAL(toggled(bool)),
151  &signedDataFileNameRQ, SLOT(setEnabled(bool)) );
152  connect( &verifyDetachedCB, SIGNAL(toggled(bool)),
153  q, SLOT(enableDisableWidgets()) );
154  connect( &archiveCB, SIGNAL(toggled(bool)),
155  q, SLOT(enableDisableWidgets()) );
156 }
157 
158 
159 DecryptVerifyOperationWidget::Private::Private( DecryptVerifyOperationWidget * qq )
160  : q( qq ),
161  ui( q )
162 {
163 
164 }
165 
166 DecryptVerifyOperationWidget::Private::~Private() {}
167 
168 DecryptVerifyOperationWidget::DecryptVerifyOperationWidget( QWidget * p )
169  : QWidget( p ), d( new Private( this ) )
170 {
171  setMode( DecryptVerifyOpaque );
172 }
173 
174 DecryptVerifyOperationWidget::~DecryptVerifyOperationWidget() {}
175 
176 void DecryptVerifyOperationWidget::setArchiveDefinitions( const std::vector< shared_ptr<ArchiveDefinition> > & archiveDefinitions ) {
177  d->ui.archivesCB.clear();
178  Q_FOREACH( const shared_ptr<ArchiveDefinition> & ad, archiveDefinitions )
179  d->ui.archivesCB.addItem( ad->label(), qVariantFromValue( ad ) );
180 }
181 
182 static const int Mutable = 1;
183 static const int Const = 0;
184 
185 void DecryptVerifyOperationWidget::setMode( Mode mode ) {
186  setMode( mode, shared_ptr<ArchiveDefinition>() );
187 }
188 
189 void DecryptVerifyOperationWidget::setMode( Mode mode, const shared_ptr<ArchiveDefinition> & ad ) {
190  d->ui.verifyDetachedCB.setChecked( mode != DecryptVerifyOpaque );
191 
192  QWidget * inputWidget;
193  QWidget * signedDataWidget;
194  if ( mode == VerifyDetachedWithSignedData ) {
195  inputWidget = &d->ui.inputFileNameRQ;
196  signedDataWidget = &d->ui.signedDataFileNameLB;
197  } else {
198  inputWidget = &d->ui.inputFileNameLB;
199  signedDataWidget = &d->ui.signedDataFileNameRQ;
200  }
201 
202  d->ui.inputStack.setCurrentWidget( inputWidget );
203  d->ui.signedDataStack.setCurrentWidget( signedDataWidget );
204 
205  d->ui.inputLB.setBuddy( inputWidget );
206  d->ui.signedDataLB.setBuddy( signedDataWidget );
207 
208  d->ui.archiveCB.setChecked( ad.get() != 0 );
209  for ( int i = 0, end = d->ui.archivesCB.count() ; i != end ; ++i )
210  if ( ad == d->ui.archivesCB.itemData( i ).value< shared_ptr<ArchiveDefinition> >() ) {
211  d->ui.archivesCB.setCurrentIndex( i );
212  return;
213  }
214 }
215 
216 DecryptVerifyOperationWidget::Mode DecryptVerifyOperationWidget::mode() const {
217  if ( d->ui.verifyDetachedCB.isChecked() )
218  if ( d->ui.inputStack.currentIndex() == Const )
219  return VerifyDetachedWithSignature;
220  else
221  return VerifyDetachedWithSignedData;
222  else
223  return DecryptVerifyOpaque;
224 }
225 
226 void DecryptVerifyOperationWidget::setInputFileName( const QString & name ) {
227  d->ui.inputFileNameLB.setText( name );
228  d->ui.inputFileNameRQ.setFileName( name );
229 }
230 
231 QString DecryptVerifyOperationWidget::inputFileName() const {
232  if ( d->ui.inputStack.currentIndex() == Const )
233  return d->ui.inputFileNameLB.text();
234  else
235  return d->ui.inputFileNameRQ.fileName();
236 }
237 
238 void DecryptVerifyOperationWidget::setSignedDataFileName( const QString & name ) {
239  d->ui.signedDataFileNameLB.setText( name );
240  d->ui.signedDataFileNameRQ.setFileName( name );
241 }
242 
243 QString DecryptVerifyOperationWidget::signedDataFileName() const {
244  if ( d->ui.signedDataStack.currentIndex() == Const )
245  return d->ui.signedDataFileNameLB.text();
246  else
247  return d->ui.signedDataFileNameRQ.fileName();
248 }
249 
250 shared_ptr<ArchiveDefinition> DecryptVerifyOperationWidget::selectedArchiveDefinition() const {
251  if ( mode() == DecryptVerifyOpaque && d->ui.archiveCB.isChecked() )
252  return d->ui.archivesCB.itemData( d->ui.archivesCB.currentIndex() ).value< shared_ptr<ArchiveDefinition> >();
253  else
254  return shared_ptr<ArchiveDefinition>();
255 }
256 
257 #include "moc_decryptverifyoperationwidget.cpp"
QWidget
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::DecryptVerifyOperationWidget
DecryptVerifyOperationWidget(QWidget *parent=0)
Definition: decryptverifyoperationwidget.cpp:168
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::Mode
Mode
Definition: decryptverifyoperationwidget.h:65
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::setSignedDataFileName
void setSignedDataFileName(const QString &name)
Definition: decryptverifyoperationwidget.cpp:238
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::inputFileName
QString inputFileName() const
QHBoxLayout
QGridLayout
decryptverifyoperationwidget.h
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::setInputFileName
void setInputFileName(const QString &name)
Definition: decryptverifyoperationwidget.cpp:226
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::setArchiveDefinitions
void setArchiveDefinitions(const std::vector< boost::shared_ptr< ArchiveDefinition > > &ads)
Definition: decryptverifyoperationwidget.cpp:176
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::~DecryptVerifyOperationWidget
~DecryptVerifyOperationWidget()
Definition: decryptverifyoperationwidget.cpp:174
Mutable
static const int Mutable
Definition: decryptverifyoperationwidget.cpp:182
boost::shared_ptr
Definition: encryptemailcontroller.h:51
QWidget::setEnabled
void setEnabled(bool)
d
#define d
Definition: adduseridcommand.cpp:89
QCheckBox
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::selectedArchiveDefinition
boost::shared_ptr< ArchiveDefinition > selectedArchiveDefinition() const
Definition: decryptverifyoperationwidget.cpp:250
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::mode
Mode mode() const
QString
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::VerifyDetachedWithSignature
Definition: decryptverifyoperationwidget.h:66
archivedefinition.h
Const
static const int Const
Definition: decryptverifyoperationwidget.cpp:183
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::DecryptVerifyOpaque
Definition: decryptverifyoperationwidget.h:68
QStackedLayout
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::setMode
void setMode(Mode mode, const boost::shared_ptr< ArchiveDefinition > &ad)
Definition: decryptverifyoperationwidget.cpp:189
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::signedDataFileName
QString signedDataFileName() const
q
#define q
Definition: adduseridcommand.cpp:90
Kleo::Crypto::Gui::DecryptVerifyOperationWidget
Definition: decryptverifyoperationwidget.h:55
name
const char * name
Definition: uiserver/selectcertificatecommand.cpp:113
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
Kleo::Crypto::Gui::DecryptVerifyOperationWidget::VerifyDetachedWithSignedData
Definition: decryptverifyoperationwidget.h:67
QComboBox
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:10 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
  • pimprint

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