• 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
  • dialogs
lookupcertificatesdialog.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  dialogs/lookupcertificatesdialog.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 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 "lookupcertificatesdialog.h"
36 
37 #include "ui_lookupcertificatesdialog.h"
38 
39 #include <models/keylistmodel.h>
40 #include <models/keylistsortfilterproxymodel.h>
41 
42 #include <utils/headerview.h>
43 
44 #include <kleo/stl_util.h>
45 
46 #include <gpgme++/key.h>
47 
48 #include <KLocalizedString>
49 
50 #include <QPushButton>
51 #include <QHeaderView>
52 
53 #ifndef Q_MOC_RUN
54 #include <boost/bind.hpp>
55 #endif
56 
57 #include <cassert>
58 
59 using namespace Kleo;
60 using namespace Kleo::Dialogs;
61 using namespace GpgME;
62 using namespace boost;
63 
64 static const int minimalSearchTextLength = 2; // ### TODO: make that KIOSK-able
65 
66 class LookupCertificatesDialog::Private {
67  friend class ::Kleo::Dialogs::LookupCertificatesDialog;
68  LookupCertificatesDialog * const q;
69 public:
70  explicit Private( LookupCertificatesDialog * qq );
71  ~Private();
72 
73 private:
74  void slotSelectionChanged() {
75  enableDisableWidgets();
76  }
77  void slotSearchTextChanged() {
78  enableDisableWidgets();
79  }
80  void slotSearchClicked() {
81  emit q->searchTextChanged( ui.findED->text() );
82  }
83  void slotDetailsClicked() {
84  assert( q->selectedCertificates().size() == 1 );
85  emit q->detailsRequested( q->selectedCertificates().front() );
86  }
87  void slotSaveAsClicked() {
88  emit q->saveAsRequested( q->selectedCertificates() );
89  }
90 
91  void readConfig();
92  void writeConfig();
93  void enableDisableWidgets();
94 
95  QString searchText() const { return ui.findED->text().trimmed(); }
96  QModelIndexList selectedIndexes() const {
97  if ( const QItemSelectionModel * const sm = ui.resultTV->selectionModel() )
98  return sm->selectedRows();
99  else
100  return QModelIndexList();
101  }
102  unsigned int numSelectedCertificates() const {
103  return selectedIndexes().size();
104  }
105 private:
106  AbstractKeyListModel * model;
107  KeyListSortFilterProxyModel proxy;
108  bool passive;
109 
110  struct Ui : Ui_LookupCertificatesDialog {
111 
112  explicit Ui( LookupCertificatesDialog * q )
113  : Ui_LookupCertificatesDialog()
114  {
115  setupUi( q );
116 
117  saveAsPB->hide(); // ### not yet implemented in LookupCertificatesCommand
118 
119  findED->setClearButtonShown( true );
120 
121  importPB()->setText( i18n("Import") );
122  importPB()->setEnabled( false );
123 
124  HeaderView * hv = new HeaderView( Qt::Horizontal );
125  KDAB_SET_OBJECT_NAME( hv );
126  resultTV->setHeader( hv );
127 
128  connect( resultTV, SIGNAL(doubleClicked(QModelIndex)),
129  importPB(), SLOT(animateClick()) );
130 
131  findED->setFocus();
132  }
133 
134  QPushButton * importPB() const { return buttonBox->button( QDialogButtonBox::Save ); }
135  QPushButton * closePB() const { return buttonBox->button( QDialogButtonBox::Close ); }
136  } ui;
137 };
138 
139 LookupCertificatesDialog::Private::Private( LookupCertificatesDialog * qq )
140  : q( qq ),
141  model( AbstractKeyListModel::createFlatKeyListModel() ),
142  proxy(),
143  passive( false ),
144  ui( q )
145 {
146  KDAB_SET_OBJECT_NAME( model );
147  KDAB_SET_OBJECT_NAME( proxy );
148 
149  proxy.setSourceModel( model );
150  ui.resultTV->setModel( &proxy );
151 
152  connect( ui.resultTV->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
153  q, SLOT(slotSelectionChanged()) );
154 }
155 
156 LookupCertificatesDialog::Private::~Private() {}
157 
158 
159 void LookupCertificatesDialog::Private::readConfig()
160 {
161  KConfigGroup dialog( KGlobal::config(), "LookupCertificatesDialog" );
162  const QSize size = dialog.readEntry( "Size", QSize(600, 400) );
163  if ( size.isValid() ) {
164  q->resize( size );
165  }
166  const QByteArray headerState = dialog.readEntry( "header", QByteArray());
167  if (!headerState.isEmpty())
168  ui.resultTV->header()->restoreState(headerState);
169 }
170 
171 void LookupCertificatesDialog::Private::writeConfig()
172 {
173  KConfigGroup dialog( KGlobal::config(), "LookupCertificatesDialog" );
174  dialog.writeEntry( "header", ui.resultTV->header()->saveState());
175  dialog.writeEntry( "Size", q->size() );
176  dialog.sync();
177 }
178 
179 
180 LookupCertificatesDialog::LookupCertificatesDialog( QWidget * p, Qt::WindowFlags f )
181  : QDialog( p, f ), d( new Private( this ) )
182 {
183  d->ui.findPB->setEnabled(false);
184  d->readConfig();
185 }
186 
187 LookupCertificatesDialog::~LookupCertificatesDialog()
188 {
189  d->writeConfig();
190 }
191 
192 void LookupCertificatesDialog::setCertificates( const std::vector<Key> & certs ) {
193  d->model->setKeys( certs );
194  d->ui.resultTV->header()->resizeSections( QHeaderView::ResizeToContents );
195  d->ui.resultTV->setFocus();
196 }
197 
198 std::vector<Key> LookupCertificatesDialog::selectedCertificates() const {
199  return d->proxy.keys( d->selectedIndexes() );
200 }
201 
202 void LookupCertificatesDialog::setPassive( bool on ) {
203  if ( d->passive == on )
204  return;
205  d->passive = on;
206  d->enableDisableWidgets();
207 }
208 
209 bool LookupCertificatesDialog::isPassive() const {
210  return d->passive;
211 }
212 
213 void LookupCertificatesDialog::setSearchText( const QString &text )
214 {
215  d->ui.findED->setText( text );
216 }
217 
218 QString LookupCertificatesDialog::searchText() const
219 {
220  return d->ui.findED->text();
221 }
222 
223 void LookupCertificatesDialog::accept() {
224  assert( !d->selectedIndexes().empty() );
225  emit importRequested( selectedCertificates() );
226  QDialog::accept();
227 }
228 
229 void LookupCertificatesDialog::Private::enableDisableWidgets() {
230  // enable/disable everything except 'close', based on passive:
231  Q_FOREACH( QObject * const o, q->children() )
232  if ( QWidget * const w = qobject_cast<QWidget*>( o ) )
233  w->setDisabled( passive && w != ui.closePB() && w != ui.buttonBox );
234 
235  if ( passive )
236  return;
237 
238  ui.findPB->setEnabled( searchText().length() > minimalSearchTextLength );
239 
240  const unsigned int n = numSelectedCertificates();
241 
242  ui.detailsPB->setEnabled( n == 1 );
243  ui.saveAsPB->setEnabled( n == 1 );
244  ui.importPB()->setEnabled( n != 0 );
245  ui.importPB()->setDefault( false ); // otherwise Import becomes default button if enabled and return triggers both a search and accept()
246 }
247 
248 #include "moc_lookupcertificatesdialog.cpp"
249 
QModelIndex
QWidget
QSize::isValid
bool isValid() const
Kleo::Dialogs::LookupCertificatesDialog
Definition: lookupcertificatesdialog.h:49
Kleo::Dialogs::LookupCertificatesDialog::selectedCertificates
std::vector< GpgME::Key > selectedCertificates() const
Definition: lookupcertificatesdialog.cpp:198
QByteArray
Kleo::Dialogs::LookupCertificatesDialog::importRequested
void importRequested(const std::vector< GpgME::Key > &certs)
QByteArray::isEmpty
bool isEmpty() const
Kleo::Dialogs::LookupCertificatesDialog::setSearchText
void setSearchText(const QString &text)
Definition: lookupcertificatesdialog.cpp:213
Kleo::HeaderView
Definition: headerview.h:44
Kleo::Dialogs::LookupCertificatesDialog::~LookupCertificatesDialog
~LookupCertificatesDialog()
Definition: lookupcertificatesdialog.cpp:187
Kleo::Dialogs::LookupCertificatesDialog::searchText
QString searchText() const
Definition: lookupcertificatesdialog.cpp:218
d
#define d
Definition: adduseridcommand.cpp:89
QObject
Kleo::Dialogs::LookupCertificatesDialog::accept
void accept()
Definition: lookupcertificatesdialog.cpp:223
QString::trimmed
QString trimmed() const
keylistsortfilterproxymodel.h
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
QString
QDialog::accept
virtual void accept()
Kleo::AbstractKeyListModel
Definition: keylistmodel.h:49
QSize
minimalSearchTextLength
static const int minimalSearchTextLength
Definition: lookupcertificatesdialog.cpp:64
keylistmodel.h
lookupcertificatesdialog.h
headerview.h
QItemSelection
Kleo::KeyListSortFilterProxyModel
Definition: keylistsortfilterproxymodel.h:74
q
#define q
Definition: adduseridcommand.cpp:90
Kleo::Dialogs::LookupCertificatesDialog::isPassive
bool isPassive() const
Definition: lookupcertificatesdialog.cpp:209
QDialog
QPushButton
Qt::WindowFlags
typedef WindowFlags
QItemSelectionModel
Kleo::Dialogs::LookupCertificatesDialog::setPassive
void setPassive(bool passive)
Definition: lookupcertificatesdialog.cpp:202
Kleo::Dialogs::LookupCertificatesDialog::setCertificates
void setCertificates(const std::vector< GpgME::Key > &certs)
Definition: lookupcertificatesdialog.cpp:192
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 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