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

kgpg

kgpgkeygenerate.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           keygen.cpp  -  description
00003                              -------------------
00004     begin                : Mon Jul 8 2002
00005     copyright            : (C) 2002 by Jean-Baptiste Mardelle
00006     email                : bj@altern.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "kgpgkeygenerate.h"
00019 
00020 #include <QVBoxLayout>
00021 #include <QWhatsThis>
00022 #include <QGroupBox>
00023 #include <QWidget>
00024 #include <QLabel>
00025 #include <QIntValidator>
00026 
00027 #include <KMessageBox>
00028 #include <KComboBox>
00029 #include <KLineEdit>
00030 #include <KLocale>
00031 #include <KDebug>
00032 #include <KHBox>
00033 
00034 #include "emailvalidator.h"
00035 
00036 using namespace KgpgCore;
00037 
00038 KgpgKeyGenerate::KgpgKeyGenerate(QWidget *parent)
00039                : KDialog(parent)
00040 {
00041     setCaption(i18n("Key Generation"));
00042     setButtons(User1 | Ok | Cancel);
00043 
00044     setButtonText(User1, i18n("&Expert Mode"));
00045     setButtonToolTip(User1, i18n("Go to the expert mode"));
00046     setButtonWhatsThis(User1, "If you go to the expert mode, you will use the command line to create your key.");
00047 
00048     m_expert = false;
00049 
00050     QGroupBox *vgroup = new QGroupBox(i18n("Generate Key Pair"), this);
00051 
00052     QLabel *nameLabel = new QLabel(i18nc("Name of key owner", "&Name:"), vgroup);
00053     m_kname = new KLineEdit("", vgroup);
00054     nameLabel->setBuddy(m_kname);
00055     m_kname->setFocus();
00056     connect(m_kname, SIGNAL(textChanged(const QString&)), this, SLOT(slotEnableOk()));
00057 
00058     QLabel *emailLabel = new QLabel(i18nc("Email address of key owner", "E&mail:"), vgroup);
00059     m_mail = new KLineEdit("", vgroup);
00060     emailLabel->setBuddy(m_mail);
00061 
00062     QLabel *commentLabel = new QLabel(i18n("Commen&t (optional):"), vgroup);
00063     m_comment = new KLineEdit("", vgroup);
00064     commentLabel->setBuddy(m_comment);
00065 
00066     QLabel *expLabel = new QLabel(i18n("Expiration:"), vgroup);
00067     KHBox *hgroup = new KHBox(vgroup);
00068     hgroup->setFrameShape(QFrame::StyledPanel);
00069     hgroup->setMargin(marginHint());
00070     hgroup->setSpacing(spacingHint());
00071     m_days = new KLineEdit("0", hgroup);
00072     QIntValidator *validator = new QIntValidator(m_days);
00073     validator->setBottom(0);
00074     m_days->setValidator(validator);
00075     m_days->setMaxLength(4);
00076     m_days->setDisabled(true);
00077 
00078     m_keyexp = new KComboBox(hgroup);
00079     m_keyexp->addItem(i18nc("Key will not expire", "Never"), 0);
00080     m_keyexp->addItem(i18n("Days"), 1);
00081     m_keyexp->addItem(i18n("Weeks"), 2);
00082     m_keyexp->addItem(i18n("Months"), 3);
00083     m_keyexp->addItem(i18n("Years"), 4);
00084     m_keyexp->setMinimumSize(m_keyexp->sizeHint());
00085     connect(m_keyexp, SIGNAL(activated(int)), this, SLOT(slotEnableDays(int)));
00086 
00087     QLabel *sizeLabel = new QLabel(i18n("&Key size:"), vgroup);
00088     m_keysize = new KComboBox(vgroup);
00089     m_keysize->addItem("768");
00090     m_keysize->addItem("1024");
00091     m_keysize->addItem("2048");
00092     m_keysize->addItem("4096");
00093     m_keysize->setCurrentIndex(1); // 1024
00094     m_keysize->setMinimumSize(m_keysize->sizeHint());
00095     sizeLabel->setBuddy(m_keysize);
00096 
00097     QLabel *algoLabel = new QLabel(i18n("&Algorithm:"), vgroup);
00098     m_keykind = new KComboBox(vgroup);
00099     m_keykind->addItem("DSA & ElGamal");
00100     m_keykind->addItem("RSA");
00101     m_keykind->setMinimumSize(m_keykind->sizeHint());
00102     algoLabel->setBuddy(m_keykind);
00103 
00104     QVBoxLayout *vlayout = new QVBoxLayout(vgroup);
00105     vlayout->addWidget(nameLabel);
00106     vlayout->addWidget(m_kname);
00107     vlayout->addWidget(emailLabel);
00108     vlayout->addWidget(m_mail);
00109     vlayout->addWidget(commentLabel);
00110     vlayout->addWidget(m_comment);
00111     vlayout->addWidget(expLabel);
00112     vlayout->addWidget(hgroup);
00113     vlayout->addWidget(sizeLabel);
00114     vlayout->addWidget(m_keysize);
00115     vlayout->addWidget(algoLabel);
00116     vlayout->addWidget(m_keykind);
00117     vlayout->addStretch();
00118     vgroup->setLayout(vlayout);
00119 
00120     setMainWidget(vgroup);
00121 
00122     slotEnableOk();
00123     updateGeometry();
00124     show();
00125 
00126     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
00127     connect(this, SIGNAL(user1Clicked()), this, SLOT(slotUser1()));
00128 }
00129 
00130 void KgpgKeyGenerate::slotButtonClicked(int button)
00131 {
00132     if (button == Ok)
00133         slotOk();
00134     else
00135     if (button == User1)
00136         slotUser1();
00137     else
00138     if (button == Cancel)
00139         reject();
00140 }
00141 
00142 void KgpgKeyGenerate::slotOk()
00143 {
00144     if (m_kname->text().simplified().isEmpty())
00145     {
00146         KMessageBox::sorry(this, i18n("You must give a name."));
00147         return;
00148     }
00149 
00150     if (m_kname->text().simplified().length() < 5)
00151     {
00152         KMessageBox::sorry(this, i18n("The name must have at least 5 characters"));
00153         return;
00154     }
00155 
00156     if (m_kname->text().simplified().at(0).isDigit())
00157     {
00158         KMessageBox::sorry(this, i18n("The name must not start with a digit"));
00159         return;
00160     }
00161 
00162     QString vmail = m_mail->text();
00163     if (vmail.isEmpty())
00164     {
00165         int result = KMessageBox::warningContinueCancel(this, i18n("You are about to create a key with no email address"));
00166         if (result != KMessageBox::Continue)
00167             return;
00168     } else {
00169         int pos = 0;
00170         if (EmailValidator().validate(vmail, pos) == QValidator::Invalid)
00171         {
00172             KMessageBox::sorry(this, i18n("Email address not valid"));
00173             return;
00174         }
00175     }
00176 
00177     accept();
00178 }
00179 
00180 void KgpgKeyGenerate::slotUser1()
00181 {
00182     m_expert = true;
00183     accept();
00184 }
00185 
00186 void KgpgKeyGenerate::slotEnableDays(const int &state)
00187 {
00188     m_days->setDisabled(state == 0);
00189 }
00190 
00191 void KgpgKeyGenerate::slotEnableOk()
00192 {
00193     enableButtonOk(!m_kname->text().simplified().isEmpty());
00194 }
00195 
00196 bool KgpgKeyGenerate::isExpertMode() const
00197 {
00198     return m_expert;
00199 }
00200 
00201 KgpgCore::KgpgKeyAlgo KgpgKeyGenerate::algo() const
00202 {
00203     if (m_keykind->currentText() == "RSA")
00204         return KgpgCore::ALGO_RSA;
00205     else
00206         return KgpgCore::ALGO_DSA_ELGAMAL;
00207 }
00208 
00209 uint KgpgKeyGenerate::size() const
00210 {
00211     return m_keysize->currentText().toUInt();
00212 }
00213 
00214 uint KgpgKeyGenerate::expiration() const
00215 {
00216     return m_keyexp->currentIndex();
00217 }
00218 
00219 uint KgpgKeyGenerate::days() const
00220 {
00221     if (m_days->text().isEmpty())
00222         return 0;
00223     return m_days->text().toUInt();
00224 }
00225 
00226 QString KgpgKeyGenerate::name() const
00227 {
00228     if (m_kname->text().isEmpty())
00229         return QString();
00230     return m_kname->text();
00231 }
00232 
00233 QString KgpgKeyGenerate::email() const
00234 {
00235     if (m_mail->text().isEmpty())
00236         return QString();
00237     return m_mail->text();
00238 }
00239 
00240 QString KgpgKeyGenerate::comment() const
00241 {
00242     if (m_comment->text().isEmpty())
00243         return QString();
00244     return m_comment->text();
00245 }
00246 
00247 #include "kgpgkeygenerate.moc"

kgpg

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

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal