• 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
  • 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 <KLineEdit>
49 #include <KLocale>
50 
51 #include <QTreeView>
52 #include <QLayout>
53 #include <QPushButton>
54 #include <QHeaderView>
55 #include <QLabel>
56 
57 #include <boost/bind.hpp>
58 
59 #include <cassert>
60 
61 using namespace Kleo;
62 using namespace Kleo::Dialogs;
63 using namespace GpgME;
64 using namespace boost;
65 
66 static const int minimalSearchTextLength = 2; // ### TODO: make that KIOSK-able
67 
68 class LookupCertificatesDialog::Private {
69  friend class ::Kleo::Dialogs::LookupCertificatesDialog;
70  LookupCertificatesDialog * const q;
71 public:
72  explicit Private( LookupCertificatesDialog * qq );
73  ~Private();
74 
75 private:
76  void slotSelectionChanged() {
77  enableDisableWidgets();
78  }
79  void slotSearchTextChanged() {
80  enableDisableWidgets();
81  }
82  void slotSearchClicked() {
83  emit q->searchTextChanged( ui.findED->text() );
84  }
85  void slotDetailsClicked() {
86  assert( q->selectedCertificates().size() == 1 );
87  emit q->detailsRequested( q->selectedCertificates().front() );
88  }
89  void slotSaveAsClicked() {
90  emit q->saveAsRequested( q->selectedCertificates() );
91  }
92 
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 LookupCertificatesDialog::LookupCertificatesDialog( QWidget * p, Qt::WindowFlags f )
159  : QDialog( p, f ), d( new Private( this ) )
160 {
161 
162 }
163 
164 LookupCertificatesDialog::~LookupCertificatesDialog() {}
165 
166 void LookupCertificatesDialog::setCertificates( const std::vector<Key> & certs ) {
167  d->model->setKeys( certs );
168  d->ui.resultTV->header()->resizeSections( QHeaderView::ResizeToContents );
169  d->ui.resultTV->setFocus();
170 }
171 
172 std::vector<Key> LookupCertificatesDialog::selectedCertificates() const {
173  return d->proxy.keys( d->selectedIndexes() );
174 }
175 
176 void LookupCertificatesDialog::setPassive( bool on ) {
177  if ( d->passive == on )
178  return;
179  d->passive = on;
180  d->enableDisableWidgets();
181 }
182 
183 bool LookupCertificatesDialog::isPassive() const {
184  return d->passive;
185 }
186 
187 void LookupCertificatesDialog::setSearchText( const QString &text )
188 {
189  d->ui.findED->setText( text );
190 }
191 
192 QString LookupCertificatesDialog::searchText() const
193 {
194  return d->ui.findED->text();
195 }
196 
197 void LookupCertificatesDialog::accept() {
198  assert( !d->selectedIndexes().empty() );
199  emit importRequested( selectedCertificates() );
200  QDialog::accept();
201 }
202 
203 void LookupCertificatesDialog::Private::enableDisableWidgets() {
204  // enable/disable everything except 'close', based on passive:
205  Q_FOREACH( QObject * const o, q->children() )
206  if ( QWidget * const w = qobject_cast<QWidget*>( o ) )
207  w->setDisabled( passive && w != ui.closePB() && w != ui.buttonBox );
208 
209  if ( passive )
210  return;
211 
212  ui.findPB->setEnabled( searchText().length() > minimalSearchTextLength );
213 
214  const unsigned int n = numSelectedCertificates();
215 
216  ui.detailsPB->setEnabled( n == 1 );
217  ui.saveAsPB->setEnabled( n == 1 );
218  ui.importPB()->setEnabled( n != 0 );
219  ui.importPB()->setDefault( false ); // otherwise Import becomes default button if enabled and return triggers both a search and accept()
220 }
221 
222 #include "moc_lookupcertificatesdialog.cpp"
223 
Kleo::Dialogs::LookupCertificatesDialog
Definition: lookupcertificatesdialog.h:49
Kleo::Dialogs::LookupCertificatesDialog::selectedCertificates
std::vector< GpgME::Key > selectedCertificates() const
Definition: lookupcertificatesdialog.cpp:172
QDialog
Kleo::Dialogs::LookupCertificatesDialog::importRequested
void importRequested(const std::vector< GpgME::Key > &certs)
QWidget
Kleo::Dialogs::LookupCertificatesDialog::setSearchText
void setSearchText(const QString &text)
Definition: lookupcertificatesdialog.cpp:187
Kleo::HeaderView
Definition: headerview.h:44
Kleo::Dialogs::LookupCertificatesDialog::~LookupCertificatesDialog
~LookupCertificatesDialog()
Definition: lookupcertificatesdialog.cpp:164
Kleo::Dialogs::LookupCertificatesDialog::searchText
QString searchText() const
Definition: lookupcertificatesdialog.cpp:192
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Dialogs::LookupCertificatesDialog::accept
void accept()
Definition: lookupcertificatesdialog.cpp:197
keylistsortfilterproxymodel.h
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
Kleo::AbstractKeyListModel
Definition: keylistmodel.h:49
minimalSearchTextLength
static const int minimalSearchTextLength
Definition: lookupcertificatesdialog.cpp:66
keylistmodel.h
lookupcertificatesdialog.h
headerview.h
Kleo::KeyListSortFilterProxyModel
Definition: keylistsortfilterproxymodel.h:72
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::Dialogs::LookupCertificatesDialog::isPassive
bool isPassive() const
Definition: lookupcertificatesdialog.cpp:183
Kleo::Dialogs::LookupCertificatesDialog::setPassive
void setPassive(bool passive)
Definition: lookupcertificatesdialog.cpp:176
Kleo::Dialogs::LookupCertificatesDialog::setCertificates
void setCertificates(const std::vector< GpgME::Key > &certs)
Definition: lookupcertificatesdialog.cpp:166
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 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