summaryrefslogtreecommitdiffstats
path: root/kgpg/keygener.cpp
blob: 3ae05878a02329077649197ac18829f967903db0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/***************************************************************************
                          keygen.cpp  -  description
                             -------------------
    begin                : Mon Jul 8 2002
    copyright            : (C) 2002 by Jean-Baptiste Mardelle
    email                : bj@altern.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

///////////////////////////////////////////////             code for new key generation


#include <tqwhatsthis.h>
#include <layout.h>
#include <tqlabel.h>
#include <tqvbox.h>
#include <kcombobox.h>
#include <klineedit.h>
#include <tqcheckbox.h>
#include <tqbuttongroup.h>
#include <tqhbuttongroup.h>
#include <tqvbuttongroup.h>
#include <kmessagebox.h>
#include <klocale.h>

#include "keygener.h"

///////////////////////   main window
keyGenerate::keyGenerate(TQWidget *parent, const char *name):KDialogBase( parent, name, true,i18n("Key Generation"),Apply | Ok | Cancel)
{
        expert=false;
        setButtonApply(i18n("Expert Mode"));

        TQWidget *page = new TQWidget(this);
        TQVBoxLayout *vbox=new TQVBoxLayout(page);

        TQVButtonGroup *bgroup1=new TQVButtonGroup(i18n("Generate Key Pair"),page);

        (void) new TQLabel(i18n("Name:"),bgroup1);
        kname=new KLineEdit("",bgroup1);
        kname->setFocus();
        (void) new TQLabel(i18n("Email:"),bgroup1);
        mail=new KLineEdit("",bgroup1);

        (void) new TQLabel(i18n("Comment (optional):"),bgroup1);
        comment=new KLineEdit("",bgroup1);

        (void) new TQLabel(i18n("Expiration:"),bgroup1);
        TQHButtonGroup *bgroup=new  TQHButtonGroup(bgroup1);
        numb=new KLineEdit("0",bgroup);
        numb->setMaxLength(4);
        numb->setDisabled(true);
        keyexp = new KComboBox(bgroup);
        keyexp->insertItem(i18n("Never"),0);
        keyexp->insertItem(i18n("Days"),1);
        keyexp->insertItem(i18n("Weeks"),2);
        keyexp->insertItem(i18n("Months"),3);
        keyexp->insertItem(i18n("Years"),4);
        keyexp->setMinimumSize(keyexp->sizeHint());
        connect(keyexp,TQT_SIGNAL(activated(int)),this,TQT_SLOT(activateexp(int)));

        (void) new TQLabel(i18n("Key size:"),bgroup1);
        keysize = new KComboBox(bgroup1);
        keysize->insertItem("768");
        keysize->insertItem("1024");
        keysize->insertItem("2048");
        keysize->insertItem("4096");
        keysize->setCurrentItem("1024");
        keysize->setMinimumSize(keysize->sizeHint());

        (void) new TQLabel(i18n("Algorithm:"),bgroup1);
        keykind = new KComboBox(bgroup1);
        keykind->insertItem("DSA & ElGamal");
        keykind->insertItem("RSA");
        keykind->setMinimumSize(keykind->sizeHint());

        vbox->addWidget(bgroup1);
        page->show();
        page->resize(page->maximumSize());
        setMainWidget(page);
}

void keyGenerate::slotOk()
{
        if (TQString(kname->text()).stripWhiteSpace().isEmpty()) {
                KMessageBox::sorry(this,i18n("You must give a name."));
                return;
        }
        TQString vmail=mail->text();
	if (vmail.isEmpty())
	{
	if (KMessageBox::warningContinueCancel(this,i18n("You are about to create a key with no email address"))!=KMessageBox::Continue) return;
        }
	else if ((vmail.find(" ")!=-1) || (vmail.find(".")==-1) || (vmail.find("@")==-1)) {
                KMessageBox::sorry(this,i18n("Email address not valid"));
                return;
        }
        accept();
}

void keyGenerate::slotApply()
{
        expert=true;
        accept();
}

void keyGenerate::activateexp(int state)
{
        if (state==0)
                numb->setDisabled(true);
        else
                numb->setDisabled(false);
}

bool keyGenerate::getmode()
{
        return(expert);
}


TQString keyGenerate::getkeytype()
{
        return(keykind->currentText());
}

TQString keyGenerate::getkeysize()
{
        return(keysize->currentText());
}

int keyGenerate::getkeyexp()
{
        return(keyexp->currentItem());
}

TQString keyGenerate::getkeynumb()
{
        if (numb->text()!=NULL)
                return(numb->text());
        else
                return ("");
}

TQString keyGenerate::getkeyname()
{
        if (kname->text()!=NULL)
                return(kname->text());
        else
                return ("");
}

TQString keyGenerate::getkeymail()
{
        if (mail->text()!=NULL)
                return(mail->text());
        else
                return ("");
}

TQString keyGenerate::getkeycomm()
{
        if (comment->text()!=NULL)
                return(comment->text());
        else
                return ("");
}

#include "keygener.moc"