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

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
kgpgkeygenerate.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002 Jean-Baptiste Mardelle <bj@altern.org>
3  * Copyright (C) 2007,2009,2010,2012,2013,2014 Rolf Eike Beer <kde@opensource.sf-tec.de>
4  */
5 
6 /***************************************************************************
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  ***************************************************************************/
14 
15 #include "kgpgkeygenerate.h"
16 
17 #include "core/convert.h"
18 #include "core/emailvalidator.h"
19 
20 #include <KComboBox>
21 #include <KDebug>
22 #include <KHBox>
23 #include <KLineEdit>
24 #include <KLocale>
25 #include <KMessageBox>
26 #include <QGroupBox>
27 #include <QIntValidator>
28 #include <QLabel>
29 #include <QVBoxLayout>
30 #include <QWhatsThis>
31 #include <QWidget>
32 
33 using namespace KgpgCore;
34 
35 KgpgKeyGenerate::KgpgKeyGenerate(QWidget *parent)
36  : KDialog(parent),
37  m_expert(false)
38 {
39  setupUi(this);
40 
41  setButtons(User1 | Ok | Cancel);
42 
43  setButtonText(User1, i18n("&Expert Mode"));
44  setButtonToolTip(User1, i18n("Go to Expert Mode"));
45  setButtonWhatsThis(User1, i18n( "If you go to expert mode, you will use the command line to create your key." ));
46 
47  connect(m_kname, SIGNAL(textChanged(QString)), this, SLOT(slotEnableOk()));
48 
49  KHBox *hgroup = new KHBox(vgroup);
50  hgroup->setFrameShape(QFrame::StyledPanel);
51  hgroup->setMargin(marginHint());
52  hgroup->setSpacing(spacingHint());
53  m_days->setParent(hgroup);
54  QIntValidator *validator = new QIntValidator(m_days);
55  validator->setBottom(0);
56  m_days->setValidator(validator);
57  m_days->setMaxLength(4);
58  m_days->setDisabled(true);
59 
60  m_keyexp = new KComboBox(hgroup);
61  m_keyexp->addItem(i18nc("Key will not expire", "Never"), 0);
62  m_keyexp->addItem(i18n("Days"), 1);
63  m_keyexp->addItem(i18n("Weeks"), 2);
64  m_keyexp->addItem(i18n("Months"), 3);
65  m_keyexp->addItem(i18n("Years"), 4);
66  m_keyexp->setMinimumSize(m_keyexp->sizeHint());
67  connect(m_keyexp, SIGNAL(activated(int)), this, SLOT(slotEnableDays(int)));
68 
69  qobject_cast<QVBoxLayout *>(vgroup->layout())->insertWidget(7, hgroup);
70 
71  m_keysize->addItem(i18n("1024"));
72  m_keysize->addItem(i18n("2048"));
73  m_keysize->addItem(i18n("4096"));
74  m_keysize->setCurrentIndex(1); // 2048
75  m_keysize->setMinimumSize(m_keysize->sizeHint());
76 
77  m_keykind->addItem(KgpgCore::Convert::toString(KgpgCore::ALGO_DSA_ELGAMAL));
78  m_keykind->addItem(KgpgCore::Convert::toString(KgpgCore::ALGO_RSA_RSA));
79  m_keykind->addItem(KgpgCore::Convert::toString(KgpgCore::ALGO_RSA));
80  m_keykind->setCurrentIndex(1); // RSA+RSA
81  slotEnableCaps(m_keykind->currentIndex());
82  m_keykind->setMinimumSize(m_keykind->sizeHint());
83 
84  setMainWidget(vgroup);
85 
86  slotEnableOk();
87  updateGeometry();
88  show();
89 
90  connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
91  connect(this, SIGNAL(user1Clicked()), this, SLOT(slotUser1()));
92  connect(m_keykind, SIGNAL(activated(int)), SLOT(slotEnableCaps(int)));
93 }
94 
95 void KgpgKeyGenerate::slotButtonClicked(int button)
96 {
97  if (button == Ok)
98  slotOk();
99  else
100  if (button == User1)
101  slotUser1();
102  else
103  if (button == Cancel)
104  reject();
105 }
106 
107 void KgpgKeyGenerate::slotOk()
108 {
109  if (m_kname->text().simplified().isEmpty())
110  {
111  KMessageBox::sorry(this, i18n("You must give a name."));
112  return;
113  }
114 
115  if (m_kname->text().simplified().length() < 5)
116  {
117  KMessageBox::sorry(this, i18n("The name must have at least 5 characters"));
118  return;
119  }
120 
121  if (m_kname->text().simplified().at(0).isDigit())
122  {
123  KMessageBox::sorry(this, i18n("The name must not start with a digit"));
124  return;
125  }
126 
127  QString vmail = m_mail->text();
128  if (vmail.isEmpty())
129  {
130  int result = KMessageBox::warningContinueCancel(this, i18n("You are about to create a key with no email address"));
131  if (result != KMessageBox::Continue)
132  return;
133  } else {
134  int pos = 0;
135  if (EmailValidator().validate(vmail, pos) == QValidator::Invalid)
136  {
137  KMessageBox::sorry(this, i18n("Email address not valid"));
138  return;
139  }
140  }
141 
142  accept();
143 }
144 
145 void KgpgKeyGenerate::slotUser1()
146 {
147  m_expert = true;
148  accept();
149 }
150 
151 void KgpgKeyGenerate::slotEnableDays(const int state)
152 {
153  m_days->setDisabled(state == 0);
154 }
155 
156 void KgpgKeyGenerate::slotEnableCaps(const int state)
157 {
158  // currently only supported for standalone RSA keys
159  capabilities->setDisabled(state != 2);
160 }
161 
162 void KgpgKeyGenerate::slotEnableOk()
163 {
164  enableButtonOk((m_kname->text().simplified().length() >= 5) &&
165  !m_kname->text().simplified().at(0).isDigit());
166 }
167 
168 bool KgpgKeyGenerate::isExpertMode() const
169 {
170  return m_expert;
171 }
172 
173 KgpgCore::KgpgKeyAlgo KgpgKeyGenerate::algo() const
174 {
175  if (m_keykind->currentText() == KgpgCore::Convert::toString(KgpgCore::ALGO_RSA))
176  return KgpgCore::ALGO_RSA;
177  else if (m_keykind->currentText() == KgpgCore::Convert::toString(KgpgCore::ALGO_RSA_RSA))
178  return KgpgCore::ALGO_RSA_RSA;
179  else
180  return KgpgCore::ALGO_DSA_ELGAMAL;
181 }
182 
183 KgpgCore::KgpgSubKeyType KgpgKeyGenerate::caps() const
184 {
185  KgpgCore::KgpgSubKeyType ret;
186 
187  if (!capabilities->isEnabled())
188  return ret;
189 
190  if (capAuth->isChecked())
191  ret |= KgpgCore::SKT_AUTHENTICATION;
192  if (capCert->isChecked())
193  ret |= KgpgCore::SKT_CERTIFICATION;
194  if (capEncrypt->isChecked())
195  ret |= KgpgCore::SKT_ENCRYPTION;
196  if (capSign->isChecked())
197  ret |= KgpgCore::SKT_SIGNATURE;
198 
199  return ret;
200 }
201 
202 uint KgpgKeyGenerate::size() const
203 {
204  return m_keysize->currentText().toUInt();
205 }
206 
207 char KgpgKeyGenerate::expiration() const
208 {
209  switch (m_keyexp->currentIndex()) {
210  case 1:
211  return 'd';
212  case 2:
213  return 'w';
214  case 3:
215  return 'm';
216  case 4:
217  default:
218  return 'y';
219  }
220 }
221 
222 uint KgpgKeyGenerate::days() const
223 {
224  if (m_days->text().isEmpty())
225  return 0;
226  return m_days->text().toUInt();
227 }
228 
229 QString KgpgKeyGenerate::name() const
230 {
231  if (m_kname->text().isEmpty())
232  return QString();
233  return m_kname->text();
234 }
235 
236 QString KgpgKeyGenerate::email() const
237 {
238  if (m_mail->text().isEmpty())
239  return QString();
240  return m_mail->text();
241 }
242 
243 QString KgpgKeyGenerate::comment() const
244 {
245  if (m_comment->text().isEmpty())
246  return QString();
247  return m_comment->text();
248 }
249 
250 #include "kgpgkeygenerate.moc"
QWidget
KgpgKeyGenerate::expiration
char expiration() const
Definition: kgpgkeygenerate.cpp:207
KgpgCore::SKT_SIGNATURE
Definition: kgpgkey.h:73
KgpgCore::SKT_ENCRYPTION
Definition: kgpgkey.h:72
KgpgKeyGenerate::email
QString email() const
Definition: kgpgkeygenerate.cpp:236
KgpgKeyGenerate::days
uint days() const
Definition: kgpgkeygenerate.cpp:222
KgpgKeyGenerate::KgpgKeyGenerate
KgpgKeyGenerate(QWidget *parent=0)
Definition: kgpgkeygenerate.cpp:35
KDialog
KgpgKeyGenerate::caps
KgpgCore::KgpgSubKeyType caps() const
return the selected capabilities for the new key
Definition: kgpgkeygenerate.cpp:183
emailvalidator.h
KgpgKeyGenerate::name
QString name() const
Definition: kgpgkeygenerate.cpp:229
KgpgKeyGenerate::algo
KgpgCore::KgpgKeyAlgo algo() const
Definition: kgpgkeygenerate.cpp:173
KgpgKeyGenerate::size
uint size() const
Definition: kgpgkeygenerate.cpp:202
QString::isEmpty
bool isEmpty() const
KgpgKeyGenerate::isExpertMode
bool isExpertMode() const
Definition: kgpgkeygenerate.cpp:168
KgpgCore::Convert::toString
QString toString(const KgpgKeyAlgo algorithm)
Definition: convert.cpp:35
QVBoxLayout
QString
KgpgCore::SKT_CERTIFICATION
Definition: kgpgkey.h:75
QIntValidator::setBottom
void setBottom(int)
QIntValidator
KgpgKeyGenerate::comment
QString comment() const
Definition: kgpgkeygenerate.cpp:243
KgpgCore::ALGO_RSA_RSA
Definition: kgpgkey.h:40
KgpgCore::SKT_AUTHENTICATION
Definition: kgpgkey.h:74
convert.h
KgpgCore::EmailValidator
Definition: emailvalidator.h:29
kgpgkeygenerate.h
KgpgCore::ALGO_RSA
Definition: kgpgkey.h:36
KgpgCore::ALGO_DSA_ELGAMAL
Definition: kgpgkey.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

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