1 /*
2 SPDX-FileCopyrightText: 2008, 2009, 2012 Rolf Eike Beer <kde@opensource.sf-tec.de>
3 SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #include "kgpgadduid.h"
7
8 #include <KEmailAddress>
9
KGpgAddUid(QObject * parent,const QString & keyid,const QString & name,const QString & email,const QString & comment)10 KGpgAddUid::KGpgAddUid(QObject *parent, const QString &keyid, const QString &name, const QString &email, const QString &comment)
11 : KGpgEditKeyTransaction(parent, keyid, QLatin1String("adduid"), false, true)
12 {
13 setName(name);
14 setEmail(email);
15 setComment(comment);
16 }
17
~KGpgAddUid()18 KGpgAddUid::~KGpgAddUid()
19 {
20 }
21
22 bool
preStart()23 KGpgAddUid::preStart()
24 {
25 if (!KGpgEditKeyTransaction::preStart())
26 return false;
27
28 if (!m_email.isEmpty() && !KEmailAddress::isValidSimpleAddress(m_email)) {
29 setSuccess(TS_INVALID_EMAIL);
30 return false;
31 }
32
33 return true;
34 }
35
36 bool
nextLine(const QString & line)37 KGpgAddUid::nextLine(const QString &line)
38 {
39 if (!line.startsWith(QLatin1String("[GNUPG:] ")))
40 return false;
41
42 if (line.contains(QLatin1String( "GOOD_PASSPHRASE" ))) {
43 setSuccess(TS_OK);
44 } else if (line.contains(QLatin1String( "keygen.name" ))) {
45 write(m_name.toUtf8());
46 } else if (line.contains(QLatin1String( "keygen.email" ))) {
47 write(m_email.toLatin1());
48 } else if (line.contains(QLatin1String( "keygen.comment" ))) {
49 write(m_comment.toUtf8());
50 } else {
51 return KGpgEditKeyTransaction::nextLine(line);
52 }
53
54 return false;
55 }
56
57 void
setName(const QString & name)58 KGpgAddUid::setName(const QString &name)
59 {
60 m_name = name;
61 }
62
63 void
setEmail(const QString & email)64 KGpgAddUid::setEmail(const QString &email)
65 {
66 m_email = email;
67 }
68
69 void
setComment(const QString & comment)70 KGpgAddUid::setComment(const QString &comment)
71 {
72 m_comment = comment;
73 }
74